[vtkusers] vtkSmartVolumeMapper opacity rendering changing drastically with data scaling
Richard Whitehead
richard.whitehead at vivosight.com
Mon Mar 10 13:02:50 EDT 2014
Please can anyone explain the following problem, or is this a bug? This is
with VTK 6.0.
Rendering a volume in 3D using vtkSmartVolumeMapper with opacity set, if
the data's spacing is approximately 1 then I get the picture I expect; if
much smaller then the image is nearly transparent; if much larger than 1
then the image is opaque. It appears that the data scaling is affecting
the opacity calculation; is opacity in units per cubic spacing or something
(I was assuming that 1.0 meant opaque and I can't see any documentation
that tells me its units)?
Note that I have had to fix a couple of bugs (raised in Mantis) in order to
get multi-page TIFF reading to work but I don't see that this can be
relevant.
Many thanks for your assistance, Richard
const std::string FILENAME = "xxx.tif"; // a 16-bit multi-page TIFF
double F = 1000.0; // for good image; set to 1, ghostly; set to 1000000
opaque
double XY_RESOLUTION = F * 0.004;
double Z_RESOLUTION = F * 0.1;
int main(int argc, char* argv[])
{
vtkSmartPointer<vtkTIFFReader> reader =
vtkSmartPointer<vtkTIFFReader>::New();
reader->SetFileName(FILENAME.c_str());
reader->SetFileDimensionality(3);
reader->SetDataSpacing(XY_RESOLUTION, XY_RESOLUTION, Z_RESOLUTION);
reader->SpacingSpecifiedFlagOn(); // to make SetDataSpacing work!!!
reader->SetOrientationType( ORIENTATION_BOTLEFT ); // otherwise it comes
out upside down
reader->Update();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderer>ren1 = vtkSmartPointer<vtkRenderer>::New();
renWin->AddRenderer(ren1);
vtkSmartPointer<vtkRenderWindowInteractor>iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
renWin->Render(); // make sure we have an OpenGL context.
vtkSmartPointer<vtkSmartVolumeMapper> volumeMapper =
vtkSmartPointer<vtkSmartVolumeMapper>::New();
volumeMapper->SetBlendModeToComposite();
volumeMapper->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkVolumeProperty> volumeProperty =
vtkSmartPointer<vtkVolumeProperty>::New();
volumeProperty->ShadeOff();
volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity =
vtkSmartPointer<vtkPiecewiseFunction>::New();
compositeOpacity->AddPoint(0.0, 0.0);
compositeOpacity->AddPoint(12000.0, 0.001);
compositeOpacity->AddPoint(65535.0, 1.0);
volumeProperty->SetScalarOpacity(compositeOpacity);
vtkSmartPointer<vtkColorTransferFunction> color =
vtkSmartPointer<vtkColorTransferFunction>::New();
color->AddRGBPoint(0.0, 0.0,0.0,0.0);
color->AddRGBPoint(65535.0, 1.0,1.0,1.0);
volumeProperty->SetColor(color);
vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
ren1->AddViewProp(volume);
ren1->ResetCamera();
renWin->SetSize(500,500);
renWin->SetPosition(0,0);
ren1->SetBackground(0.25, 0.25, 0.5);
ren1->GetActiveCamera()->Elevation( 30 );
renWin->Render();
iren->Start();
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140310/826b429e/attachment.html>
More information about the vtkusers
mailing list