Reverse color in vtkScalarsToColors?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Reverse color in vtkScalarsToColors?

BBerco
This post was updated on .
Hi all,

I am using a vtkColorBarActor provided with an instance of vtkScalarsToColors obtained from a vtkPolyDataMapper to display a range of scalar values shown on the vtkPolyData connected to the mapper.

My problem is that the maximum scalar value (i.e the max in "surface_data" below) corresponds to the blue end of the colorbar, while the minimum scalar value is associated with its red end.

I have been looking for a way to reverse this behavior (so as to have the maximum value matched with the red and the minimum with the blue), to no avail. I thought I had found what I was looking for there , but this was unsuccessful as the GetLookupTable method returns an instance of vtkScalarsToColors and not vtkLookUpTable...

Any suggestions?

Thanks!

ps: below is how I construct the colorbar from the input data / mapper


        vtkSmartPointer<vtkActor> shape_actor = this -> parent -> get_actor_vector()[0];

        shape_actor -> GetMapper() -> SetScalarRange(min_magnitude, max_magnitude);

        shape_actor -> GetMapper() -> GetInput() -> GetCellData() -> SetScalars(surface_data);
        shape_actor -> GetMapper() -> ScalarVisibilityOn();
        shape_actor -> GetMapper() -> SetScalarModeToUseCellData();

        vtkSmartPointer<vtkScalarBarActor> scalarBar =
            vtkSmartPointer<vtkScalarBarActor>::New();

        scalarBar -> SetLookupTable(shape_actor -> GetMapper() -> GetLookupTable());
        scalarBar -> SetTitle("Orthonormal acceleration magnitude (m/s^2)");
        scalarBar -> SetUnconstrainedFontSize (true);
        scalarBar -> GetTitleTextProperty() -> SetFontSize(10);
        scalarBar -> GetLabelTextProperty() -> SetFontSize(10);
        scalarBar -> SetNumberOfLabels(4);

        this -> parent -> get_renderer() -> AddActor2D(scalarBar);
        this -> parent -> qvtkWidget -> GetRenderWindow() -> Render();
Reply | Threaded
Open this post in threaded view
|

Re: Reverse color in vtkScalarsToColors?

Bill Lorensen
Set the hue range of the lookup table to
.667,0

On Dec 4, 2016 7:33 PM, "BBerco" <[hidden email]> wrote:
Hi all,

I am using a vtkColorBarActor provided with an instance of
vtkScalarsToColors obtained from a vtkPolyDataMapper to display a range of
scalar values shown on the vtkPolyData connected to the mapper.

My problem is that the maximum scalar value (i.e the max in "surface_data"
below) corresponds to the blue end of the colorbar, while the minimum scalar
value is associated with its red end.

I have been looking for a way to reverse this behavior (so as to have the
maximum value matched with the red and the minimum with the blue), to no
avail. I thought I had found what I was looking for  there
<http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/ElevationBandsWithGlyphs>
, but this was unsuccessful as the GetLookupTable method returns an instance
of vtkScalarsToColors and not vtkLookUpTable...

Any suggestions?

Thanks!

ps: below is how I construct the colorbar from the input data mapper
associated with the polydata
the data corresponds to


        vtkSmartPointer<vtkActor> shape_actor = this -> parent ->
get_actor_vector()[0];

        shape_actor -> GetMapper() -> SetScalarRange(min_magnitude, max_magnitude);

        shape_actor -> GetMapper() -> GetInput() -> GetCellData() ->
SetScalars(surface_data);
        shape_actor -> GetMapper() -> ScalarVisibilityOn();
        shape_actor -> GetMapper() -> SetScalarModeToUseCellData();

        vtkSmartPointer<vtkScalarBarActor> scalarBar =
            vtkSmartPointer<vtkScalarBarActor>::New();

        scalarBar -> SetLookupTable(shape_actor -> GetMapper() ->
GetLookupTable());
        scalarBar -> SetTitle("Orthonormal acceleration magnitude (m/s^2)");
        scalarBar -> SetUnconstrainedFontSize (true);
        scalarBar -> GetTitleTextProperty() -> SetFontSize(10);
        scalarBar -> GetLabelTextProperty() -> SetFontSize(10);
        scalarBar -> SetNumberOfLabels(4);

        this -> parent -> get_renderer() -> AddActor2D(scalarBar);
        this -> parent -> qvtkWidget -> GetRenderWindow() -> Render();



--
View this message in context: http://vtk.1045678.n5.nabble.com/Reverse-color-in-vtkScalarsToColors-tp5741412.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Reverse color in vtkScalarsToColors?

BBerco
Bill,

the issue is that SetHueRange is a method of vtkLookUpTable and not vtkScalarsToColors. I am getting an instance of the latter with shape_actor -> GetMapper() ->GetLookupTable(), which is rather counter-intuitive.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse color in vtkScalarsToColors?

Cory Quammen-2
vtkScalarsToColors is the base class for color maps. Try
SafeDownCasting the pointer returned by the mapper to vtkLookupTable.
If the returned color map is not an instance of vtkLookupTable, try
setting your own lookup table with something like

vtkSmartPointer<vtkLookupTable> myTable =
vtkSmartPointer<vtkLookupTable>::New();
myTable->SetHueRange(...);
// other lookup table setup here.
shape_actor->GetMapper->SetLookupTable(myTable);

HTH,
Cory

On Sun, Dec 4, 2016 at 11:33 PM, BBerco <[hidden email]> wrote:

> Bill,
>
> the issue is that SetHueRange is a method of vtkLookUpTable and not
> vtkScalarsToColors. I am getting an instance of the latter with *shape_actor
> -> GetMapper() ->GetLookupTable()*, which is rather counter-intuitive.
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/Reverse-color-in-vtkScalarsToColors-tp5741412p5741414.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers



--
Cory Quammen
Staff R&D Engineer
Kitware, Inc.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Reverse color in vtkScalarsToColors?

BBerco
The SafeDownCast worked, thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Reverse color in vtkScalarsToColors?

andyjk
I have a strange bug related to this.

If I create a custom vtkLookupTable as suggested above, it all works - as
long as I compile in ReleaseWithDebugInfo

If I build with Release the software crashes when I try to use the custom
look up table.

Identical code. Windows with VS2017.

The fact it works in RelWithDebug makes it hard to debug!

Anyone have any ideas?



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Reverse color in vtkScalarsToColors?

Andras Lasso
Most common root cause of different behavior in Release/Debug mode is that in Debug mode variables are initialized to 0, while in Release mode there is no value initialization.

Try to use AppVerifier tool. It can often help the software crash in Debug or RelWithDebInfo mode that otherwise would just crash in Release mode.

Andras

-----Original Message-----
From: vtkusers <[hidden email]> On Behalf Of andyjk
Sent: Sunday, September 23, 2018 2:24 PM
To: [hidden email]
Subject: Re: [vtkusers] Reverse color in vtkScalarsToColors?

I have a strange bug related to this.

If I create a custom vtkLookupTable as suggested above, it all works - as long as I compile in ReleaseWithDebugInfo

If I build with Release the software crashes when I try to use the custom look up table.

Identical code. Windows with VS2017.

The fact it works in RelWithDebug makes it hard to debug!

Anyone have any ideas?



--
Sent from: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvtk.1045678.n5.nabble.com%2FVTK-Users-f1224199.html&amp;data=02%7C01%7Classo%40queensu.ca%7Cf6bc45fe40694e37f3ae08d62181ce18%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636733238726404349&amp;sdata=ScBS9pm2%2BoRwaJqGlyLUJQE7Q52BgpEi0IIB%2Fp4JRXo%3D&amp;reserved=0
_______________________________________________
Powered by https://na01.safelinks.protection.outlook.com/?url=www.kitware.com&amp;data=02%7C01%7Classo%40queensu.ca%7Cf6bc45fe40694e37f3ae08d62181ce18%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636733238726404349&amp;sdata=35cgI6JnYjWoOVVx5RsU4evbDuVqYmeQQiLBPoZiV4o%3D&amp;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&amp;data=02%7C01%7Classo%40queensu.ca%7Cf6bc45fe40694e37f3ae08d62181ce18%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636733238726404349&amp;sdata=v4XyrBSzVnaPiBib6T4WQ6bNtttk9FWUSIkGf%2B55yiU%3D&amp;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&amp;data=02%7C01%7Classo%40queensu.ca%7Cf6bc45fe40694e37f3ae08d62181ce18%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636733238726404349&amp;sdata=6tsI9fJuY7Yo0M34FaPyfYxgdkuc0GCkiTA2LyYrTIU%3D&amp;reserved=0

Search the list archives at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmarkmail.org%2Fsearch%2F%3Fq%3Dvtkusers&amp;data=02%7C01%7Classo%40queensu.ca%7Cf6bc45fe40694e37f3ae08d62181ce18%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636733238726404349&amp;sdata=Aswx6xkPEutnoJyHRRMwCuaepR5Fsv6rdo0fsgtCseg%3D&amp;reserved=0

Follow this link to subscribe/unsubscribe:
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fvtkusers&amp;data=02%7C01%7Classo%40queensu.ca%7Cf6bc45fe40694e37f3ae08d62181ce18%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636733238726404349&amp;sdata=AAwitM2SMsghl%2BPazSbwZPj9%2BhVZ7OUMlPd4%2BALy5R0%3D&amp;reserved=0
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers