[vtkusers] Volume Rendering with Voxel Specific Color

Cory Jones cjayjones at gmail.com
Mon Jun 30 16:08:59 EDT 2014

Thank you for the feedback. That fixed the color problem. I am not sure I
understand the use of component 4 though. I am trying to use it to set the
opacity of the volume using the volume property SetScalarOpacity with a
vtkPiecewiseFunction. The code I am using is:

  vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity =

I set the portions of the volume I want to have not visible to 0 on the
fourth channel of the volume (component 3) and then am trying to set the
opacity to 0 for those positions using the code above. I am not getting a
change in the opacity using this. Is there another way to accomplish this,
or have I just made an error in the above?


On Thu, Jun 26, 2014 at 12:42 PM, Lisa Avila <lisa.avila at kitware.com> wrote:

> Hello Cory,
> In the volume property you'll need to indicate that you don't have
> independent components. That is, by default this is set to true and
> therefore VTK assumes you are representing separate properties which each
> of the scalar components (for example pressure and density). In that case,
> each scalar is passed through its own lookup tables for color and opacity
> and the resulting values are merged based on the weightings of the
> components.
> VTK also supports IA (intensity / alpha) and RGBA data. This must be 2 or
> 4 component unsigned char data. Once you set it so that your components are
> not independent, the last component will be considered a scalar lookup into
> your opacity transfer function, and the first one or three components will
> be used to represent your color. In the case of 2 component data (IA), that
> first component will be passed through the color transfer function. In the
> case of 4 component data (RGBA) those first three components will be
> directly considered the RGB color of that voxel.
> Note that if you have 3 component RGB data you'll need to do something to
> create a 4th component (otherwise you have no concept of alpha and you just
> have a solid block of color). Typical methods of generating that fourth
> component include assigning it to be the hue or intensity of the RGB value.
> For example, with the visible human data we usually assign the fourth
> component to be hue since the body was encased in a blue gel (we can then
> set the opacity of the blue hue to be zero, thereby seeing the human inside
> the cube).
> Hope this helps.
> Lisa
> On Wed, Jun 25, 2014 at 1:49 PM, Cory Jones <cjayjones at gmail.com> wrote:
>> I am trying to render a volume from 3D ImageData and I want to be able to
>> control the color of each voxel independently using the color channels. I
>> am able to set the number of scalar components in my ImageData to 3 and set
>> each channel separately. I am rendering using vtkSmartVolumeMapper. Is
>> there a way to set the vtkVolumeProperty so that the image renders the 3
>> channels as RGB? I have tried using the vtkColorTransferFunction
>> SetColorSpaceToRGB(), but this does not work. Again, I don't want to do
>> scalar color mapping. My current code is:
>>   vtkSmartPointer<vtkSmartVolumeMapper> volumeMapper =
>>               vtkSmartPointer<vtkSmartVolumeMapper>::New();
>>   volumeMapper->SetBlendModeToComposite();
>>   volumeMapper->SetInputConnection(outputImageData->GetProducerPort());
>>   vtkSmartPointer<vtkVolumeProperty> volumeProperty =
>>     vtkSmartPointer<vtkVolumeProperty>::New();
>>   volumeProperty->ShadeOff();
>>   volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
>>   vtkSmartPointer<vtkColorTransferFunction> color =
>>     vtkSmartPointer<vtkColorTransferFunction>::New();
>>   color->SetColorSpaceToRGB();
>>   volumeProperty->SetColor(color);
>>   vtkSmartPointer<vtkVolume> volume =
>>     vtkSmartPointer<vtkVolume>::New();
>>   volume->SetMapper(volumeMapper);
>>   volume->SetProperty(volumeProperty);
>> _______________________________________________
>> 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
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140630/2018e638/attachment.html>

More information about the vtkusers mailing list