[vtkusers] How to set opacity of a certain color to 0?
Andrew Maclean
andrew.amaclean at gmail.com
Sun Jul 24 22:19:16 EDT 2016
Hi Magnus,
These examples may help:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/NamedColors
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/AssignColorsFromLUT
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/ElevationBandsWithGlyphs
For example in the first link,a colour called "My Red" is created with an
alpha of 0.5.
////////////
double rgba[4];
// Test setting and getting colors here.
// We are also modifying alpha.
namedColors->GetColor("Red",rgba);
rgba[3] = 0.5;
namedColors->SetColor("My Red",rgba);
namedColors->GetColor("My Red",rgba);
////////////
In the lookup table "My Red" is added, then "DarkGreen"with an opacity of
0.3.
You could create a colour called "My Black"in a similar fashion with an
alpha of 0.
Then that example and the other ones should demonstrate how to create
lookup tables.
I hope this helps.
Regards
Andrew
> ---------- Forwarded message ----------
> From: Magnus Elden <magnus_elden at hotmail.com>
> To: <vtkusers at vtk.org>
> Cc:
> Date: Sun, 24 Jul 2016 06:36:46 +0200
> Subject: [vtkusers] How to set opacity of a certain color to 0?
>
> I am cutting a volume using vtkCutter and I want to remove everything that
> is black or close to black. Normally this would be done using a transfer
> function, but I can not seem to find where to put it.
>
> This is the flow of my program(shortened):
>
>
>
> vtkPiecewiseFunction *opacityFun = vtkPiecewiseFunction::New();
>
>
>
> vtkDataSet *dataSet;
>
> vtkSmartPointer<vtkXMLImageDataReader> reader =
>
> vtkSmartPointer<vtkXMLImageDataReader>::New();
>
> dataSet = vtkDataSet::SafeDownCast(reader->GetOutput());
>
>
>
>
>
> reader->GetOutput()->GetBounds(bounds);
>
>
>
> vtkSmartPointer<vtkPlane> plane =
>
> vtkSmartPointer<vtkPlane>::New();
>
>
>
>
>
> // Create cutter
>
> double high = plane->EvaluateFunction((bounds[1] + bounds[0]) /
> 2.0,
>
> (bounds[3] + bounds[2]) / 2.0,
>
> bounds[5]);
>
>
>
> vtkSmartPointer<vtkCutter> cutter =
>
> vtkSmartPointer<vtkCutter>::New();
>
> cutter->SetInputConnection(reader->GetOutputPort());
>
> cutter->SetCutFunction(plane);
>
> cutter->GenerateValues(
>
> numberOfCuts,
>
> 0.9,
>
> 0.9*high);
>
>
>
> vtkSmartPointer<vtkPolyDataMapper> cutterMapper =
>
> vtkSmartPointer<vtkPolyDataMapper>::New();
>
> cutterMapper->SetInputConnection(cutter->GetOutputPort());
>
>
>
>
>
> // Create cut actor
>
> vtkSmartPointer<vtkActor> cutterActor =
>
> vtkSmartPointer<vtkActor>::New();
>
> cutterActor->GetProperty()->SetLineWidth(2);
>
> cutterActor->SetMapper(cutterMapper);
>
>
>
> // Create renderers and add actors of plane and model
>
> vtkSmartPointer<vtkRenderer> renderer =
>
> vtkSmartPointer<vtkRenderer>::New();
>
> renderer->AddActor(cutterActor);
>
>
>
> //Code to render and interact with the cuts.
>
>
>
>
>
> Where in this code do I apply the transfer function? Do I use a lookup
> table? For now I want all colours to have opacity of 1 except for black
> that should have opacity = 0. How can this be done? I am using C++ and none
> of the examples seem to fit with the flow of my program. They either work
> only on volumes, which my poly data cut is not, or the function they use
> does not exist in any of the classes I am using. I tried setting a
> lookuptable with opacity ranges, I tried using a vtkPiecewiseFunction, but
> nothing seems to work.
>
>
>
> Thank you for your help.
>
> Yours,
>
> Magnus Elden
>
>
> --
___________________________________________
Andrew J. P. Maclean
___________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160725/608abe03/attachment.html>
More information about the vtkusers
mailing list