[vtkusers] Out of range colors in LookupTable in VTK 5.10

Fernando Nellmeldin f.nellmeldin at open-engineering.com
Fri Mar 31 04:07:27 EDT 2017


Hello and thank you for your answers.
I implemented what Cory said and it is working as expected!
I used two LUTs, one with the original range of colors, and one where I
added two values for the out of range values.
Finally, I attach the full LUT to the color vtkActor but the original LUT
to the vtkScalarBarActor.

Here's the relevant part of my code, with some comments.
Hope this is useful for someone in the future. Thank you very much.

// m_configuration has all the parameters to display the color field
int numColors = static_cast<int>(m_configuration.numOfColors);
double rangeForTable[2]; // range of values in the Point Data
rangeForTable[0] =
m_configuration.currentRange[m_configuration.componentToUse*2];
rangeForTable[1] =
m_configuration.currentRange[m_configuration.componentToUse*2+1];

// Generate a table only for the colors with our full range
vtkSmartPointer<vtkLookupTable> tempLUT =
vtkSmartPointer<vtkLookupTable>::New();
tempLUT->SetTableRange (rangeForTable);
tempLUT->SetNumberOfTableValues(numColors);
tempLUT->SetHueRange (m_configuration.rangeHue[0],
m_configuration.rangeHue[1]);
tempLUT->SetSaturationRange (m_configuration.rangeSaturation[0],
m_configuration.rangeSaturation[1]);
tempLUT->SetValueRange (m_configuration.rangeValue[0],
m_configuration.rangeValue[1]);
tempLUT->Build();

// Calculate the new range as the previous range plus the two new values.
double newRange[2];
double deltaColor = (rangeForTable[1]-rangeForTable[0])/double(numColors+1);
// Redefine the range to include below and above values.
newRange[0] = rangeForTable[0]-deltaColor;
newRange[1] = rangeForTable[1]+deltaColor;

m_scalarBarLUT->SetTableRange(newRange);
m_scalarBarLUT->SetNumberOfTableValues(numColors+2); // two more for the
below and above range

m_scalarBarLUT->SetTableValue(0, 0.3, 0.3, 0.3, 1.0); // below color, first

// Copy the values from one LUT to the other (displaced one because I added
one value at the beginning).
for (int i = 0; i < numColors; ++i)
{
double colorRGBA[4];
tempLUT->GetTableValue(i, colorRGBA);
m_scalarBarLUT->SetTableValue(i+1, colorRGBA);
}
m_scalarBarLUT->SetTableValue(numColors+1, 0.3, 0.3, 0.3, 1.0); //above
color, last.
m_scalarBarLUT->Build();

// Edit the number of different values on the scalar bar
m_scalarBarActor->SetMaximumNumberOfColors(numColors);
m_scalarBarActor->SetNumberOfLabels(numColors+1); // We have one more label
to align the labels to the lines of separation between colors.

// Important here: I attach the full LUT to the color actor (with the new
range), but the incomplete (without the out of range values) to the scalar
bar
m_mapperForActor->SetScalarRange(newRange); // vtkMapper
m_mapperForActor->SetLookupTable(m_scalarBarLUT);

m_scalarBarActor->SetLookupTable(tempLUT); // vtkScalarBarActor



On 30 March 2017 at 22:24, Kimmel, Jason <jason.kimmel at albint.com> wrote:

> Hi,
>
> We were able to do something in 5.10 similar to what Cory suggests, but
> using a single lookuptable.  See the code sample below, it's been edited a
> bit for clarity as the actual code uses other objects:
>
>    //setup lookup table
>    m_lut = vtkLookupTable::New();
>    m_lut->SetRampToLinear();
>    m_lut->SetRange(0,1);
>    m_lut->SetNumberOfTableValues(LUT_SIZE);
>    m_lut->SetValueRange(1,1);
>    m_lut->SetHueRange(0,2.0/3.0);
>    m_lut->SetSaturationRange(1,1);
>    m_lut->ForceBuild();
>
>    //reserve 10% for special values
>    m_lut->SetRange(0,1.1);
>    m_lut->SetNumberOfTableValues(LUT_SIZE*1.1);
>
>    //set up special values
>    m_lut->SetTableValue(LUT_SIZE,m_lut->GetTableValue(LUT_SIZE-1));
>    int idx = m_lut->GetIndex(1.01);
>    m_lut->SetTableValue(idx,.85,.85,.85);
>
> I think the biggest trick is to make sure that the lookuptable is not
> updated (built) again after setting up the special values.  Note the above
> only adds an extra color above the range, but it would be easy to extend to
> add a color below the original range as well.
>
> Hope that helps,
> Jason
>
> -----Original Message-----
> From: vtkusers [mailto:vtkusers-bounces at vtk.org] On Behalf Of Cory Quammen
> Sent: Thursday, March 30, 2017 8:11 AM
> To: Fernando Nellmeldin <f.nellmeldin at open-engineering.com>
> Cc: vtk-users <vtkusers at vtk.org>
> Subject: Re: [vtkusers] Out of range colors in LookupTable in VTK 5.10
>
> Fernando,
>
> It should be possible with a little work. You will need to set the color
> table values yourself. For illustration, let's say you have 4 colors in
> your color table with data range [0, 8]. You'll need to add one color at
> the bottom of the table for the below range color and one at the top for
> the above range color for a total of 6 table colors.
> You'll need to adjust your range so that 0 still gets mapped to the
> previously lowest color and 8 to the previously highest color. In this
> example, your new range should be [-2, 10]. Now, anything below 0 should
> map to your below range color in the table and anything about 7 should map
> to your above range color.
>
> To set table values explicitly, you can use vtkLookupTable::SetTableValue
> (vtkIdType indx, double rgba[4]). The trick will be to maintain the lookup
> table generation of the colors via HSV range while setting table values
> explicitly - you can't do both in the same vtkLookupTable instance. You
> might want to use two vtkLookupTables in this case, one that generates the
> colors via the HSV range, and then use that to build a second
> vtkLookupTable in which you modify the range and add the above/below range
> colors.
>
> HTH,
> Cory
>
> On Thu, Mar 30, 2017 at 7:56 AM, Fernando Nellmeldin <f.nellmeldin at open-
> engineering.com> wrote:
> > Hello.
> > I have an unstructuredgrid with point data which I display as a color
> > map in the model.
> > Let's say the range of the values is [100, 500] and I map blue to 100
> > and red to 500. I create a lookuptable with the range of HSV values
> > for the colors I want, and everything works as expected.
> > Problem is, I would like to have a special color for values below 100
> > and values over 500 (gray, for example).
> >
> > I do know that this feature exist from VTK 6 as
> > vtkLookupTable::setBelowRangeColor and vtkLookupTable::
> setAboveRangeColor.
> > But, for compatibility reasons, we are stuck -for the moment- with VTK
> 5.10.
> >
> > Is there an easy way to accomplish this with VTK 5.10? I've seen the
> > code inside vtkLookupTable but there were a lot of changes and I can't
> > find the way to do it by myself without modifying my own version of
> > VTK (by editing vtkLookupTable in VTK 5.10 with the code added in VTK 6).
> >
> > Thank you.
> >
> > --
> > Fernando NELLMELDIN
> > Software Engineer
> > _______________________________________________________________
> >
> > Open Engineering s.a.
> >
> > Rue Bois Saint-Jean 15/1
> > B-4102 Seraing (Belgium)
> > Tel: +32.4.353.30.34
> >
> > https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.op
> > en-engineering.com&data=01%7C01%7CJason.Kimmel%40albint.com%7C5ad9f51d
> > f86140fca50108d47765d6d4%7Cff3d33ae31364152812675e51f4a1404%7C0&sdata=
> > zI0EH%2FVLnc2TBtypv7qFz0C4JR2Cvs4qG465i4rVP3M%3D&reserved=0
> > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.l
> > inkedin.com%2Fcompany%2Fopen-engineering%3Ftrk%3Dbiz-companies-cym&dat
> > a=01%7C01%7CJason.Kimmel%40albint.com%7C5ad9f51df86140fca50108d47765d6
> > d4%7Cff3d33ae31364152812675e51f4a1404%7C0&sdata=ldlzw0LT%2BMgFVnxEPmGV
> > ZARlta85na7LQiGdhZMBb%2B4%3D&reserved=0
> > ______________________________________________________________________
> > ___
> >
> > _______________________________________________
> > Powered by
> > https://na01.safelinks.protection.outlook.com/?url=www.kitware.com&dat
> > a=01%7C01%7CJason.Kimmel%40albint.com%7C5ad9f51df86140fca50108d47765d6
> > d4%7Cff3d33ae31364152812675e51f4a1404%7C0&sdata=Qc1VRMLblcX3z7p9LzDrA8
> > hS2PkPgyxcpC%2F0J40VZzQ%3D&reserved=0
> >
> > Visit other Kitware open-source projects at
> > https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.ki
> > tware.com%2Fopensource%2Fopensource.html&data=01%7C01%7CJason.Kimmel%4
> > 0albint.com%7C5ad9f51df86140fca50108d47765d6d4%7Cff3d33ae3136415281267
> > 5e51f4a1404%7C0&sdata=JooMrwa5BojD%2Bpe78RcbyglmPQNWMTGEr5V18ySgIFw%3D
> > &reserved=0
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> > https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.vt
> > k.org%2FWiki%2FVTK_FAQ&data=01%7C01%7CJason.Kimmel%40albint.com%7C5ad9
> > f51df86140fca50108d47765d6d4%7Cff3d33ae31364152812675e51f4a1404%7C0&sd
> > ata=IRTZ9qReZgvxlmLGnA1CFgSuz1S9QdmdowqVV%2FwBbfI%3D&reserved=0
> >
> > Search the list archives at:
> > https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmarkma
> > il.org%2Fsearch%2F%3Fq%3Dvtkusers&data=01%7C01%7CJason.Kimmel%40albint
> > .com%7C5ad9f51df86140fca50108d47765d6d4%7Cff3d33ae31364152812675e51f4a
> > 1404%7C0&sdata=ai%2Fv3gOrF5vGV2bHn6bnJsNY5YQJfwzbtn%2BOu8crerg%3D&rese
> > rved=0
> >
> > Follow this link to subscribe/unsubscribe:
> > https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpublic
> > .kitware.com%2Fmailman%2Flistinfo%2Fvtkusers&data=01%7C01%7CJason.Kimm
> > el%40albint.com%7C5ad9f51df86140fca50108d47765d6d4%7Cff3d33ae313641528
> > 12675e51f4a1404%7C0&sdata=J05L%2FEc%2BbEXeIGHX%2FeJHpGbaXS8W0jXvNx40hu
> > 3%2Fxxc%3D&reserved=0
> >
>
>
>
> --
> Cory Quammen
> Staff R&D Engineer
> Kitware, Inc.
> _______________________________________________
> Powered by https://na01.safelinks.protection.outlook.com/?url=
> www.kitware.com&data=01%7C01%7CJason.Kimmel%40albint.com%
> 7C5ad9f51df86140fca50108d47765d6d4%7Cff3d33ae31364152812675e51f4a
> 1404%7C0&sdata=Qc1VRMLblcX3z7p9LzDrA8hS2PkPgyxcpC%2F0J40VZzQ%3D&reserved=0
>
> Visit other Kitware open-source projects at https://na01.safelinks.
> protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%
> 2Fopensource%2Fopensource.html&data=01%7C01%7CJason.Kimmel%40albint.com%
> 7C5ad9f51df86140fca50108d47765d6d4%7Cff3d33ae31364152812675e51f4a
> 1404%7C0&sdata=JooMrwa5BojD%2Bpe78RcbyglmPQNWMTGEr5V18ySgIFw%3D&reserved=0
>
> Please keep messages on-topic and check the VTK FAQ at:
> https://na01.safelinks.protection.outlook.com/?url=
> http%3A%2F%2Fwww.vtk.org%2FWiki%2FVTK_FAQ&data=01%7C01%
> 7CJason.Kimmel%40albint.com%7C5ad9f51df86140fca50108d47765d6d4%
> 7Cff3d33ae31364152812675e51f4a1404%7C0&sdata=
> IRTZ9qReZgvxlmLGnA1CFgSuz1S9QdmdowqVV%2FwBbfI%3D&reserved=0
>
> Search the list archives at: https://na01.safelinks.
> protection.outlook.com/?url=http%3A%2F%2Fmarkmail.org%
> 2Fsearch%2F%3Fq%3Dvtkusers&data=01%7C01%7CJason.Kimmel%40albint.com%
> 7C5ad9f51df86140fca50108d47765d6d4%7Cff3d33ae31364152812675e51f4a
> 1404%7C0&sdata=ai%2Fv3gOrF5vGV2bHn6bnJsNY5YQJfwz
> btn%2BOu8crerg%3D&reserved=0
>
> Follow this link to subscribe/unsubscribe:
> https://na01.safelinks.protection.outlook.com/?url=
> http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%
> 2Fvtkusers&data=01%7C01%7CJason.Kimmel%40albint.com%
> 7C5ad9f51df86140fca50108d47765d6d4%7Cff3d33ae31364152812675e51f4a
> 1404%7C0&sdata=J05L%2FEc%2BbEXeIGHX%2FeJHpGbaXS8W0jXvNx40hu3%
> 2Fxxc%3D&reserved=0
>



-- 
*Fernando NELLMELDIN*
Software Engineer
*_______________________________________________________________*

*Open Engineering s.a.*

Rue Bois Saint-Jean 15/1
B-4102 Seraing (Belgium)
Tel: +32.4.353.30.34

http://www.open-engineering.com
https://www.linkedin.com/company/open-engineering?trk=biz-companies-cym

*_________________________________________________________________________*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170331/10c6e97b/attachment.html>


More information about the vtkusers mailing list