[vtkusers] to make a rectangular hole in volume rendering of quarter.1-93

Amy Henderson amy.henderson at kitware.com
Thu Apr 29 10:49:15 EDT 2004


Hi Nicolas,

You want to use cropping in the volume mapper. Set the CroppingRegionPlanes 
to the boundaries of the rectangular hole you want to create. You will also 
need to set the CroppingRegionFlags. In the 27 regions, a bit set to 1 
indicates a region to keep, and a bit set to 0 is a region to not display. 
 From vtkVolumeMapper.h:

   // Description:
   // Set the flags for the cropping regions. The clipping planes divide the
   // volume into 27 regions - there is one bit for each region. The regions
   // start from the one containing voxel (0,0,0), moving along the x axis
   // fastest, the y axis next, and the z axis slowest. These are represented
   // from the lowest bit to bit number 27 in the integer containing the
   // flags. There are several convenience functions to set some common
   // configurations - subvolume (the default), fence (between any of the
   // clip plane pairs), inverted fence, cross (between any two of the
   // clip plane pairs) and inverted cross.

- Amy

At 10:07 AM 4/29/2004, Dumont Nicolas wrote:
>Hello!!!
>
>I wish to make a rectangular hole in a volume rendering of the CT head.
>
>I first tried defining 6 clipping planes and using
>volumeMapper->SetClippingPlanes->planes
>but i can only manage to just clip out the part i want to keep (the planes
>must define a convex surface ????)
>
>I also tried using vtkClipVolume with an implicit function but that filter
>produce unstructuredgrid data so i cannot use the output for
>volumeMapper->SetInput( vtkimagedata *);
>
>My last idea is to duplicate v16->GetOutput() (by creating a new object
>vtkImageData, and copying in it v16->GetOutput() )
>Then I would put value 0 on the right voxels. (in my transfer function,
>value 0 map to opacity 0).
>My problem is I cannot manage to read and copy the value contained in a
>voxel of volume16reader->GetOuput()....
>I join the code I tried.
>
>Pleaaaaaaaase, any help would be greatly appreciated, i am really short of
>ideas,
>Nicolas Dumont,
>Belgium, Ulg.
>
>
>#include "vtkRenderer.h"
>#include "vtkRenderWindow.h"
>#include "vtkRenderWindowInteractor.h"
>#include "vtkVolume16Reader.h"
>#include "vtkVolumeRayCastCompositeFunction.h"
>#include "vtkVolumeRayCastMapper.h"
>#include "vtkVolumeRayCastCompositeFunction.h"
>#include "vtkPiecewiseFunction.h"
>#include "vtkColorTransferFunction.h"
>#include "vtkVolumeProperty.h"
>#include "vtkVolume.h"
>#include "vtkOutlineFilter.h"
>#include "vtkPolyDataMapper.h"
>#include "vtkActor.h"
>#include "vtkCamera.h"
>#include "vtkProperty.h"
>#include "vtkInteractorStyleTrackballCamera.h"
>
>
>#include "vtkImageData.h"
>#include "vtkPointData.h"
>#include "vtkCellData.h"
>#include "vtkDataSetAttributes.h"
>
>
>
>
>int main (int argc, char **argv)
>{
>   if (argc < 2)
>     {
>       cout << "Usage: " << argv[0] << " DATADIR/headsq/quarter " << endl;
>     return 1;
>     }
>
>
>vtkVolume16Reader *v16 = vtkVolume16Reader::New();
>     v16->SetDataDimensions(64,64);
>     v16->SetDataByteOrderToLittleEndian();
>     v16->SetFilePrefix (argv[1]);
>     v16->SetImageRange(1, 93);
>     v16->SetDataSpacing (3.2, 3.2, 1.5);
>
>
>vtkImageData *imageData = vtkImageData::New();
>         imageData->SetDimensions(64,64,93);
>         imageData->SetSpacing(3.2,3.2,1.5);
>         imageData->SetOrigin(0.0,0.0,0.0);
>         imageData->SetScalarTypeToUnsignedChar();
>         imageData->SetNumberOfScalarComponents(1);
>         imageData->AllocateScalars();
>
>
>
>unsigned char *ptr2=(unsigned char *) v16->GetOutput()->GetScalarPointer();
>unsigned char *ptr =(unsigned char *) imageData->GetScalarPointer();
>
>
>for (int i=0; i<64*64*93; i++)
>{
>         *ptr = *ptr2;
>         ptr++;
>         ptr2++;
>}
>// compile but fault on line *ptr = *ptr2;
>
>
>/*
>for (int i=0; i<64*64*93; i++)
>{
>imageData->GetPointData()->CopyData(v16->GetOutput()->GetPointData(),i,i);
>}
>
>// gives a black/transparent volume !!!!!! just the ouline is visible
>*/
>
>vtkVolumeRayCastCompositeFunction  *compositeFunction=
>vtkVolumeRayCastCompositeFunction::New();
>
>
>vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
>     volumeMapper->SetInput(imageData);
>     volumeMapper->SetVolumeRayCastFunction(compositeFunction);
>
>
>vtkPiecewiseFunction *tfun = vtkPiecewiseFunction::New();
>     tfun->AddPoint(399.0,0.0);
>     tfun->AddPoint(400.0,0.2);
>     tfun->AddPoint(700.0,0.2);
>     tfun->AddPoint(701.0,0.05);
>     tfun->AddPoint(1199,0.05);
>     tfun->AddPoint(1200,0.2);
>     tfun->AddPoint(2649,0.2);
>     tfun->AddPoint(2650,0.2);
>
>vtkColorTransferFunction *ctfun = vtkColorTransferFunction::New();
>     ctfun->AddRGBPoint(350,  1.0,  1.0,  1.0);
>     ctfun->AddRGBPoint(500,  1.0,  0.5,  0.5);
>     ctfun->AddRGBPoint(650,  1.0,  0.5,  0.5);
>     ctfun->AddRGBPoint(800,  0.6,  0.5,  0.3);
>     ctfun->AddRGBPoint(1000, 0.6,  0.5,  0.3);
>     ctfun->AddRGBPoint(1500, 1.0,  1.0,  1.0);
>     ctfun->AddRGBPoint(2000, 1.0,  0.1,  0.1);
>     ctfun->AddRGBPoint(2700, 0.0,  1.0,  0.0);
>
>
>
>vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
>     volumeProperty->SetColor(ctfun);
>     volumeProperty->SetScalarOpacity(tfun);
>     volumeProperty->SetInterpolationTypeToLinear();
>     volumeProperty->ShadeOn();
>
>
>vtkVolume *newvol = vtkVolume::New();
>     newvol->SetMapper(volumeMapper);
>     newvol->SetProperty(volumeProperty);
>
>
>
>vtkOutlineFilter *outline = vtkOutlineFilter::New();
>     outline->SetInput((vtkDataSet *) v16->GetOutput());
>
>
>vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
>     outlineMapper->SetInput(outline->GetOutput());
>
>vtkActor *outlineActor = vtkActor::New();
>     outlineActor->SetMapper(outlineMapper);
>     outlineActor->GetProperty()->SetColor(1,1,1);
>
>
>
>vtkCamera *Camera = vtkCamera::New();
>     Camera->SetViewUp (0, 0, -1);
>     Camera->SetPosition (140, 600, -100);
>     Camera->SetFocalPoint (100, 100, 75);
>     Camera->ComputeViewPlaneNormal();
>
>
>vtkRenderer *ren = vtkRenderer::New();
>     ren->AddActor(outlineActor);
>     ren->AddVolume(newvol);
>     ren->SetBackground(0,0,0);
>     ren->SetActiveCamera(Camera);
>
>
>vtkRenderWindow *renWin = vtkRenderWindow::New();
>     renWin->AddRenderer(ren);
>     renWin->SetSize(640,480);
>
>
>vtkInteractorStyleTrackballCamera *style =
>vtkInteractorStyleTrackballCamera::New();
>
>vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>     iren->SetRenderWindow(renWin);
>     iren->SetInteractorStyle(style);
>     iren->Initialize();
>     iren->Start();
>
>
>
>
>     v16->Delete();
>     compositeFunction->Delete();
>     volumeMapper->Delete();
>     tfun->Delete();
>     ctfun->Delete();
>     volumeProperty->Delete();
>     newvol->Delete();
>     outline->Delete();
>     outlineMapper->Delete();
>     outlineActor->Delete();
>     Camera->Delete();
>     ren->Delete();
>     renWin->Delete();
>     iren->Delete();
>     style->Delete();
>
>   return 0;
>}
>
>
>
>
>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at: 
><http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers






More information about the vtkusers mailing list