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

Kimmel, Jason jason.kimmel at albint.com
Thu Mar 30 16:24:34 EDT 2017


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%7Cff3d33ae31364152812675e51f4a1404%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%7Cff3d33ae31364152812675e51f4a1404%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%7Cff3d33ae31364152812675e51f4a1404%7C0&sdata=ai%2Fv3gOrF5vGV2bHn6bnJsNY5YQJfwzbtn%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%7Cff3d33ae31364152812675e51f4a1404%7C0&sdata=J05L%2FEc%2BbEXeIGHX%2FeJHpGbaXS8W0jXvNx40hu3%2Fxxc%3D&reserved=0


More information about the vtkusers mailing list