<div dir="ltr"><br clear="all"><div>Please can anyone explain the following problem, or is this a bug? This is with VTK 6.0.</div><div><br></div><div>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)? </div>
<div><br></div><div>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.</div><div><br></div><div>Many thanks for your assistance, Richard</div>
<div><div><br></div><div><br></div><div><br></div><div>const std::string FILENAME = "xxx.tif"; // a 16-bit multi-page TIFF</div><div><br></div><div>double F = 1000.0; // for good image; set to 1, ghostly; set to 1000000 opaque</div>
<div>double XY_RESOLUTION = F * 0.004;</div><div>double Z_RESOLUTION = F * 0.1;</div><div><br></div><div><br></div><div>int main(int argc, char* argv[])</div><div>{</div><div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkTIFFReader> reader = vtkSmartPointer<vtkTIFFReader>::New();</div>
<div><span class="" style="white-space:pre"> </span>reader->SetFileName(FILENAME.c_str());</div><div><span class="" style="white-space:pre"> </span>reader->SetFileDimensionality(3);</div><div><br></div><div><span class="" style="white-space:pre"> </span>reader->SetDataSpacing(XY_RESOLUTION, XY_RESOLUTION, Z_RESOLUTION);</div>
<div><span class="" style="white-space:pre"> </span>reader->SpacingSpecifiedFlagOn(); // to make SetDataSpacing work!!!</div><div><br></div><div><span class="" style="white-space:pre"> </span>reader->SetOrientationType( ORIENTATION_BOTLEFT ); // otherwise it comes out upside down</div>
<div><span class="" style="white-space:pre"> </span>reader->Update();</div><div><br></div><div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();</div>
<div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkRenderer>ren1 = vtkSmartPointer<vtkRenderer>::New();</div><div><br></div><div><span class="" style="white-space:pre"> </span>renWin->AddRenderer(ren1);</div>
<div><br></div><div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkRenderWindowInteractor>iren = <span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkRenderWindowInteractor>::New();</div>
<div><span class="" style="white-space:pre"> </span>iren->SetRenderWindow(renWin);</div><div><br></div><div><span class="" style="white-space:pre"> </span>renWin->Render(); // make sure we have an OpenGL context.</div>
<div><br></div><div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkSmartVolumeMapper> volumeMapper = vtkSmartPointer<vtkSmartVolumeMapper>::New();</div><div><span class="" style="white-space:pre"> </span>volumeMapper->SetBlendModeToComposite();</div>
<div><span class="" style="white-space:pre"> </span>volumeMapper->SetInputConnection(reader->GetOutputPort());</div><div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkVolumeProperty> volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New();</div>
<div><span class="" style="white-space:pre"> </span>volumeProperty->ShadeOff();</div><div><span class="" style="white-space:pre"> </span>volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);</div><div><br>
</div><div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New();</div><div><span class="" style="white-space:pre"> </span>compositeOpacity->AddPoint(0.0, 0.0);</div>
<div><span class="" style="white-space:pre"> </span>compositeOpacity->AddPoint(12000.0, 0.001);</div><div><span class="" style="white-space:pre"> </span>compositeOpacity->AddPoint(65535.0, 1.0);</div><div><span class="" style="white-space:pre"> </span>volumeProperty->SetScalarOpacity(compositeOpacity);</div>
<div><br></div><div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkColorTransferFunction> color = vtkSmartPointer<vtkColorTransferFunction>::New();</div><div><span class="" style="white-space:pre"> </span>color->AddRGBPoint(0.0,<span class="" style="white-space:pre"> </span>0.0,0.0,0.0);</div>
<div><span class="" style="white-space:pre"> </span>color->AddRGBPoint(65535.0,<span class="" style="white-space:pre"> </span>1.0,1.0,1.0);</div><div><span class="" style="white-space:pre"> </span>volumeProperty->SetColor(color);</div>
<div><span class="" style="white-space:pre"> </span></div><div><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New();</div><div><span class="" style="white-space:pre"> </span>volume->SetMapper(volumeMapper);</div>
<div><span class="" style="white-space:pre"> </span>volume->SetProperty(volumeProperty);</div><div><span class="" style="white-space:pre"> </span>ren1->AddViewProp(volume);</div><div><span class="" style="white-space:pre"> </span>ren1->ResetCamera();</div>
<div><br></div><div><span class="" style="white-space:pre"> </span>renWin->SetSize(500,500);</div><div><span class="" style="white-space:pre"> </span>renWin->SetPosition(0,0);</div><div><br></div><div><span class="" style="white-space:pre"> </span>ren1->SetBackground(0.25, 0.25, 0.5);</div>
<div><span class="" style="white-space:pre"> </span>ren1->GetActiveCamera()->Elevation( 30 );</div><div><br></div><div><span class="" style="white-space:pre"> </span>renWin->Render();</div><div><br></div><div><span class="" style="white-space:pre"> </span>iren->Start();</div>
<div><br></div><div><span class="" style="white-space:pre"> </span>return EXIT_SUCCESS;</div><div>}</div></div>
</div>