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

Dumont Nicolas NIC.Dumont at student.ulg.ac.be
Thu Apr 29 10:07:11 EDT 2004


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;
}







More information about the vtkusers mailing list