[vtkusers] Unwanted blending with transparent voxels in volume

zmanvortex donny.zimmerman at willowpointsoftware.com
Fri Nov 29 16:55:31 EST 2013


I have created a vtkImageCanvasSource2D object and reset all single component
scalars to 0 using FillBox (iterating through each z spacing using
SetDefaultZ). I then draw triangles to the image using DrawTriangle after
using SetDefaultZ to the correct triangle z spacing level.

I am using vtkFixedPointVolumeRayCastMapper to render the volume.

I have an opacity transfer function that sets scalars of value 0 to an
opacity of 0.0 and scalar values of 1 to 255 to opacity 1.0. The problem I
am having is that I have voxels that should be transparent that are visible
when they are close to the opaque voxels. It appears the mapper is blending
the transparent voxels with the opaque ones when they border each other. How
can I prevent this from happening.

By the way, if I draw all of my triangles on the closest z spacing to the
camera then the volume renders correctly as long as I don't look at the
other side of the volume which shows the blending.

Here is the code snippet:

vtkSmartPointer<vtkImageCanvasSource2D> imgdat =
vtkSmartPointer<vtkImageCanvasSource2D>::New();
        imgdat->SetNumberOfScalarComponents(1);
        imgdat->SetScalarTypeToUnsignedChar(); 
        imgdat->SetExtent(0, 4000, 0, 4000, 0, 14);
        imgdat->SetDrawColor(0.0); 

        for(int i = 0; i <= 14; i++)
        {
            imgdat->SetDefaultZ(i);
            imgdat->FillBox(0,4000,0,4000);
        }

for ( int i = 0; i < data->PointCells->Count; i++ )
        {

            RpgPointCell^ cell = data->PointCells[i];

            if(cell->CellColor > 0)
            {
                x1 = (int)((cell->P1->X / 250.0) + 2000.0);
                y1 = (int)((cell->P1->Y / 250.0) + 2000.0);
                z1 = (int)(cell->P1->Z / 250.0);

                x2 = (int)((cell->P2->X / 250.0) + 2000.0);
                y2 = (int)((cell->P2->Y / 250.0) + 2000.0);
                z2 = (int)(cell->P2->Z / 250.0);

                x3 = (int)((cell->P3->X / 250.0) + 2000.0);
                y3 = (int)((cell->P3->Y / 250.0) + 2000.0);
                z3 = (int)(cell->P3->Z / 250.0);

                x4 = (int)((cell->P4->X / 250.0) + 2000.0);
                y4 = (int)((cell->P4->Y / 250.0) + 2000.0);
                z4 = (int)(cell->P4->Z / 250.0);

                imgdat->SetDrawColor(static_cast<double>(cell->CellColor));
                imgdat->SetDefaultZ(z1);
                    
                imgdat->FillTriangle(x3,y3,x2,y2,x1,y1);
                imgdat->FillTriangle(x1,y1,x4,y4,x3,y3);
            }
         }

        vtkSmartPointer<vtkPiecewiseFunction> opacityTransferFunction =
vtkSmartPointer<vtkPiecewiseFunction>::New();
        opacityTransferFunction->AddPoint(  0 ,  0.0 );
        opacityTransferFunction->AddPoint(  1 , 1.0 );
        opacityTransferFunction->AddPoint(  255 , 1.0 );

        // Create transfer mapping scalar value to color
        vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction =          
vtkSmartPointer<vtkColorTransferFunction>::New();

        for (int tblid = 0; tblid < data->Colors->Count; tblid++)
        {
            // Set the ref bin colors
            double r, g, b;			

            r = data->Colors[tblid]->Red;
            g = data->Colors[tblid]->Green;
            b = data->Colors[tblid]->Blue;                
            colorTransferFunction->AddRGBPoint(static_cast<double>(tblid),r,
g, b);
        }

        // The property describes how the data will look
        vtkSmartPointer<vtkVolumeProperty> volumeProperty =
vtkSmartPointer<vtkVolumeProperty>::New();
        volumeProperty->SetColor( colorTransferFunction );
        volumeProperty->SetScalarOpacity( opacityTransferFunction );
        volumeProperty->SetInterpolationTypeToLinear();
        volumeProperty->ShadeOff();
        volumeProperty->SetAmbient(0.1);
        volumeProperty->SetDiffuse(0.9);
        volumeProperty->SetSpecular(0.2);
        volumeProperty->SetSpecularPower(10.0);
        volumeProperty->SetScalarOpacityUnitDistance(0.8919);
        volumeProperty->DisableGradientOpacityOn();

vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> volmapper =
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New();

        volmapper->SetInput(imgdat->GetOutput());

vtkVolume* volume = vtkVolume::New();
        volume->SetMapper( volmapper );
        volume->SetProperty( volumeProperty );

        return volume;



--
View this message in context: http://vtk.1045678.n5.nabble.com/Unwanted-blending-with-transparent-voxels-in-volume-tp5724731.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list