<div dir="ltr"><font color="#000000">I should have mentioned that in the example code, IndependentComponents is set to 1 - hence the four components of the data set are considered separate properties that are rendered independently then combined using the component weights. This would be useful, for example, if you have confocal microscopy data that was scanned using multiple different <span style="line-height:18.2px">fluorescent dyes to produce a stack of color tiff images (where red = the first scan, green = the second scan, etc.) In this case the ColorTransferFunctions are used (but in IndependentComponents is set to 0, the first three components are used directly as RGB).</span></font><div><font color="#000000"><span style="line-height:18.2px"><br></span></font></div><div><font color="#000000"><span style="line-height:18.2px">Lisa</span></font></div><div><font color="#000000"><span style="line-height:18.2px"><br></span></font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 14, 2016 at 10:26 AM, Lisa Avila <span dir="ltr"><<a href="mailto:lisa.avila@kitware.com" target="_blank">lisa.avila@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">If you set IndependentComponents to 0, and you have unsigned char data, you can render RGBA data. The ScalarOpacity transfer function will be used to map the 4th component to opacity. You can set this to a linear ramp from 0 to 1 to directly render the A channel if you want, but sometimes we derive the 4th component from something like hue (useful for the visible human data for example) and then the transfer function is helpful to eliminate all the "blue" regions. <span class="HOEnZb"><font color="#888888"><div><br></div><div>Lisa</div><div><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 14, 2016 at 9:25 AM, Cory Quammen <span dir="ltr"><<a href="mailto:cory.quammen@kitware.com" target="_blank">cory.quammen@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The poly data mappers have support for directly mapping color data,<br>
but looking just now it doesn't seem that the volume mappers do.<br>
<br>
Lisa and Aashish, can you volume render RGB data directly without<br>
going through the color map?<br>
<br>
Thanks,<br>
Cory<br>
<div><div><br>
On Tue, Apr 12, 2016 at 11:26 AM, abenchaaben <<a href="mailto:abenchaaben@histalim.com" target="_blank">abenchaaben@histalim.com</a>> wrote:<br>
> Hello,<br>
><br>
> I have a 2D RGB serie that i want to render it with VTK. I created the<br>
> volume with the help of ITK and i have now a vti file.<br>
><br>
> I used an example of rendering that i found online:<br>
><br>
><br>
> double opacityWindow = 4096;<br>
> double opacityLevel = 2048;<br>
> int blendType = 6;<br>
> int clip = 0;<br>
> double reductionFactor = 1.0;<br>
> double frameRate = 10.0;<br>
> char *fileName = (char*)VolumePath.c_str();<br>
><br>
> bool independentComponents=true;<br>
><br>
> // Create the renderer, render window and interactor<br>
> vtkRenderer *renderer = vtkRenderer::New();<br>
> uinw->qvtkWidget->GetRenderWindow()->AddRenderer(renderer);<br>
><br>
> QVTKInteractor *iren=uinw->qvtkWidget->GetInteractor();<br>
> vtkInteractorStyle *s= static_cast<vtkInteractorStyle<br>
> *>(iren->GetInteractorStyle());<br>
> vtkTDxInteractorStyleCamera *t=<br>
> static_cast<vtkTDxInteractorStyleCamera *>(s->GetTDxStyle());<br>
> const double angleSensitivity=0.02;<br>
> const double translationSensitivity=0.001;<br>
> t->GetSettings()->SetAngleSensitivity(angleSensitivity);<br>
><br>
> t->GetSettings()->SetTranslationXSensitivity(translationSensitivity);<br>
><br>
> t->GetSettings()->SetTranslationYSensitivity(translationSensitivity);<br>
><br>
> t->GetSettings()->SetTranslationZSensitivity(translationSensitivity);<br>
><br>
> iren->SetRenderWindow(uinw->qvtkWidget->GetRenderWindow());<br>
> iren->SetDesiredUpdateRate(frameRate / (1+clip) );<br>
><br>
> iren->GetInteractorStyle()->SetDefaultRenderer(renderer);<br>
><br>
> // Read the data<br>
> vtkAlgorithm *reader3=0;<br>
> vtkImageData *input2=0;<br>
><br>
> vtkXMLImageDataReader *xmlReader = vtkXMLImageDataReader::New();<br>
> xmlReader->SetFileName(fileName);<br>
> xmlReader->Update();<br>
> input2=xmlReader->GetOutput();<br>
> reader3=xmlReader;<br>
><br>
><br>
> // Verify that we actually have a volume<br>
> int dim[3];<br>
> input2->GetDimensions(dim);<br>
> if ( dim[0] < 2 ||<br>
> dim[1] < 2 ||<br>
> dim[2] < 2 )<br>
> {<br>
> cout << "Error loading data!" << endl;<br>
> exit(EXIT_FAILURE);<br>
> }<br>
><br>
> vtkImageResample *resample = vtkImageResample::New();<br>
> if ( reductionFactor < 1.0 )<br>
> {<br>
> resample->SetInputConnection( reader3->GetOutputPort() );<br>
> resample->SetAxisMagnificationFactor(0, reductionFactor);<br>
> resample->SetAxisMagnificationFactor(1, reductionFactor);<br>
> resample->SetAxisMagnificationFactor(2, reductionFactor);<br>
> }<br>
><br>
> // Create our volume and mapper<br>
> vtkVolume *volume = vtkVolume::New();<br>
> vtkFixedPointVolumeRayCastMapper *mapper =<br>
> vtkFixedPointVolumeRayCastMapper::New();<br>
><br>
> if ( reductionFactor < 1.0 )<br>
> {<br>
> mapper->SetInputConnection( resample->GetOutputPort() );<br>
> }<br>
> else<br>
> {<br>
> mapper->SetInputConnection( reader3->GetOutputPort() );<br>
> }<br>
><br>
><br>
> // Set the sample distance on the ray to be 1/2 the average spacing<br>
> double spacing[3];<br>
> if ( reductionFactor < 1.0 )<br>
> {<br>
> resample->GetOutput()->GetSpacing(spacing);<br>
> }<br>
> else<br>
> {<br>
> input2->GetSpacing(spacing);<br>
> }<br>
><br>
> // mapper->SetSampleDistance(<br>
> (spacing[0]+spacing[1]+spacing[2])/6.0 );<br>
> // mapper->SetMaximumImageSampleDistance(10.0);<br>
><br>
><br>
> // Create our transfer function<br>
> vtkColorTransferFunction *colorFun =<br>
> vtkColorTransferFunction::New();<br>
> vtkPiecewiseFunction *opacityFun = vtkPiecewiseFunction::New();<br>
><br>
> // Create the property and attach the transfer functions<br>
> vtkVolumeProperty *property = vtkVolumeProperty::New();<br>
> property->SetIndependentComponents(independentComponents);<br>
> property->SetColor( colorFun );<br>
> property->SetScalarOpacity( opacityFun );<br>
> property->SetInterpolationTypeToLinear();<br>
><br>
> // connect up the volume to the property and the mapper<br>
> volume->SetProperty( property );<br>
> volume->SetMapper( mapper );<br>
><br>
> // Depending on the blend type selected as a command line option,<br>
> // adjust the transfer function<br>
> switch ( blendType )<br>
> {<br>
> // MIP<br>
> // Create an opacity ramp from the window and level values.<br>
> // Color is white. Blending is MIP.<br>
> case 0:<br>
> colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0 );<br>
> opacityFun->AddSegment( opacityLevel - 0.5*opacityWindow, 0.0,<br>
> opacityLevel + 0.5*opacityWindow, 1.0 );<br>
> mapper->SetBlendModeToMaximumIntensity();<br>
> break;<br>
><br>
> // CompositeRamp<br>
> // Create a ramp from the window and level values. Use compositing<br>
> // without shading. Color is a ramp from black to white.<br>
> case 1:<br>
> colorFun->AddRGBSegment(opacityLevel - 0.5*opacityWindow, 0.0, 0.0,<br>
> 0.0,<br>
> opacityLevel + 0.5*opacityWindow, 1.0, 1.0, 1.0 );<br>
> opacityFun->AddSegment( opacityLevel - 0.5*opacityWindow, 0.0,<br>
> opacityLevel + 0.5*opacityWindow, 1.0 );<br>
> mapper->SetBlendModeToComposite();<br>
> property->ShadeOff();<br>
> break;<br>
><br>
> // CompositeShadeRamp<br>
> // Create a ramp from the window and level values. Use compositing<br>
> // with shading. Color is white.<br>
> case 2:<br>
> colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0 );<br>
> opacityFun->AddSegment( opacityLevel - 0.5*opacityWindow, 0.0,<br>
> opacityLevel + 0.5*opacityWindow, 1.0 );<br>
> mapper->SetBlendModeToComposite();<br>
> property->ShadeOn();<br>
> break;<br>
><br>
> // CT_Skin<br>
> // Use compositing and functions set to highlight skin in CT data<br>
> // Not for use on RGB data<br>
> case 3:<br>
> colorFun->AddRGBPoint( -3024, 0, 0, 0, 0.5, 0.0 );<br>
> colorFun->AddRGBPoint( -1000, .62, .36, .18, 0.5, 0.0 );<br>
> colorFun->AddRGBPoint( -500, .88, .60, .29, 0.33, 0.45 );<br>
> colorFun->AddRGBPoint( 3071, .83, .66, 1, 0.5, 0.0 );<br>
><br>
> opacityFun->AddPoint(-3024, 0, 0.5, 0.0 );<br>
> opacityFun->AddPoint(-1000, 0, 0.5, 0.0 );<br>
> opacityFun->AddPoint(-500, 1.0, 0.33, 0.45 );<br>
> opacityFun->AddPoint(3071, 1.0, 0.5, 0.0);<br>
><br>
> mapper->SetBlendModeToComposite();<br>
> property->ShadeOn();<br>
> property->SetAmbient(0.1);<br>
> property->SetDiffuse(0.9);<br>
> property->SetSpecular(0.2);<br>
> property->SetSpecularPower(10.0);<br>
> property->SetScalarOpacityUnitDistance(0.8919);<br>
> break;<br>
><br>
> // CT_Bone<br>
> // Use compositing and functions set to highlight bone in CT data<br>
> // Not for use on RGB data<br>
> case 4:<br>
> colorFun->AddRGBPoint( -3024, 0, 0, 0, 0.5, 0.0 );<br>
> colorFun->AddRGBPoint( -16, 0.73, 0.25, 0.30, 0.49, .61 );<br>
> colorFun->AddRGBPoint( 641, .90, .82, .56, .5, 0.0 );<br>
> colorFun->AddRGBPoint( 3071, 1, 1, 1, .5, 0.0 );<br>
><br>
> opacityFun->AddPoint(-3024, 0, 0.5, 0.0 );<br>
> opacityFun->AddPoint(-16, 0, .49, .61 );<br>
> opacityFun->AddPoint(641, .72, .5, 0.0 );<br>
> opacityFun->AddPoint(3071, .71, 0.5, 0.0);<br>
><br>
> mapper->SetBlendModeToComposite();<br>
> property->ShadeOn();<br>
> property->SetAmbient(0.1);<br>
> property->SetDiffuse(0.9);<br>
> property->SetSpecular(0.2);<br>
> property->SetSpecularPower(10.0);<br>
> property->SetScalarOpacityUnitDistance(0.8919);<br>
> break;<br>
><br>
> // CT_Muscle<br>
> // Use compositing and functions set to highlight muscle in CT data<br>
> // Not for use on RGB data<br>
> case 5:<br>
> colorFun->AddRGBPoint( -3024, 0, 0, 0, 0.5, 0.0 );<br>
> colorFun->AddRGBPoint( -155, .55, .25, .15, 0.5, .92 );<br>
> colorFun->AddRGBPoint( 217, .88, .60, .29, 0.33, 0.45 );<br>
> colorFun->AddRGBPoint( 420, 1, .94, .95, 0.5, 0.0 );<br>
> colorFun->AddRGBPoint( 3071, .83, .66, 1, 0.5, 0.0 );<br>
><br>
> opacityFun->AddPoint(-3024, 0, 0.5, 0.0 );<br>
> opacityFun->AddPoint(-155, 0, 0.5, 0.92 );<br>
> opacityFun->AddPoint(217, .68, 0.33, 0.45 );<br>
> opacityFun->AddPoint(420,.83, 0.5, 0.0);<br>
> opacityFun->AddPoint(3071, .80, 0.5, 0.0);<br>
><br>
> mapper->SetBlendModeToComposite();<br>
> property->ShadeOn();<br>
> property->SetAmbient(0.1);<br>
> property->SetDiffuse(0.9);<br>
> property->SetSpecular(0.2);<br>
> property->SetSpecularPower(10.0);<br>
> property->SetScalarOpacityUnitDistance(0.8919);<br>
> break;<br>
><br>
> // RGB_Composite<br>
> // Use compositing and functions set to highlight red/green/blue<br>
> regions<br>
> // in RGB data. Not for use on single component data<br>
> case 6:<br>
> opacityFun->AddPoint(0, 0.0);<br>
> opacityFun->AddPoint(5.0, 0.0);<br>
> opacityFun->AddPoint(30.0, 0.05);<br>
> opacityFun->AddPoint(31.0, 0.0);<br>
> opacityFun->AddPoint(90.0, 0.0);<br>
> opacityFun->AddPoint(100.0, 0.3);<br>
> opacityFun->AddPoint(110.0, 0.0);<br>
> opacityFun->AddPoint(190.0, 0.0);<br>
> opacityFun->AddPoint(200.0, 0.4);<br>
> opacityFun->AddPoint(210.0, 0.0);<br>
> opacityFun->AddPoint(245.0, 0.0);<br>
> opacityFun->AddPoint(255.0, 0.5);<br>
><br>
> mapper->SetBlendModeToComposite();<br>
> property->ShadeOff();<br>
> property->SetScalarOpacityUnitDistance(1.0);<br>
> break;<br>
> default:<br>
> vtkGenericWarningMacro("Unknown blend type.");<br>
> break;<br>
> }<br>
><br>
> // Set the default window size<br>
> uinw->qvtkWidget->GetRenderWindow()->Render();<br>
><br>
> // Add the volume to the scene<br>
> renderer->AddVolume( volume );<br>
><br>
> renderer->ResetCamera();<br>
><br>
> // interact with data<br>
> uinw->qvtkWidget->GetRenderWindow()->Render();<br>
><br>
> opacityFun->Delete();<br>
> colorFun->Delete();<br>
> property->Delete();<br>
><br>
> volume->Delete();<br>
> mapper->Delete();<br>
> reader3->Delete();<br>
> resample->Delete();<br>
> renderer->Delete();<br>
><br>
> The problem is that nwith this example it give me the volume with color<br>
> transformation and i want to display the volume with the true RGB color from<br>
> the images serie that i use when i start.<br>
><br>
> Does VTK support such operation??<br>
><br>
><br>
><br>
> --<br>
> View this message in context: <a href="http://vtk.1045678.n5.nabble.com/VTK-RGB-rendering-Volume-tp5737641.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/VTK-RGB-rendering-Volume-tp5737641.html</a><br>
> Sent from the VTK - Users mailing list archive at Nabble.com.<br>
> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br>
<br>
<br>
</div></div><span><font color="#888888">--<br>
Cory Quammen<br>
R&D Engineer<br>
Kitware, Inc.<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>