[vtkusers] How to convert an VTKImageData to a binary matrix?

silversurfer l_o_lo at msn.com
Wed Sep 5 19:17:01 EDT 2007


Hi everybody,

We initially had a 3d-object and we've inserted it in a VTKPolydata; this
VTKPolydata was passed as input to a VTKPolyDataToImageStencil. Further in
the process we've passed this VTKPolyDataToImageStencil both with an empty
VTKImageData and created a new VTKImageData.

We'd like to know how to convert this VTKImageData (the one obtained from
the first VTKImageData plus the empty image) into a binary occupancy
3d-matrix, i.e. each point being a zero if there's nothing in it, and a one
if there is. Our final goal is to extract 2d-slices from this matrix; We've
been told before to use the VTKVoxelModeller but how exactly is this class
used?. 

Every help is very appreciated, we understand Spanish, French, and English
:working:


Source code:

		unsigned char *** aaatVolumen = NULL;
			
		
		int dimx = object->sizeX();
		int dimy = object->sizeY();
		int dimz = object->sizeZ();

		double spacing[3];
		spacing[0] = object->pixelDimX()*1000.0;
		spacing[1] = object->pixelDimY()*1000.0;
		spacing[2] = object->pixelDimZ()*1000.0;

		double origin[3];
		origin[0] = object->getOrigin().x;
		origin[1] = object->getOrigin().y;
		origin[2] = object->getOrigin().z;


	            vtkImageData* image = vtkImageData::New();
		image->SetOrigin(origin);
		image->SetSpacing(spacing);
		image->SetScalarTypeToUnsignedChar();
		image->SetNumberOfScalarComponents(1);
		image->SetDimensions(dimx,dimy,dimz);
		image->AllocateScalars();


		vtkPolyDataToImageStencil* PolyDataToStencil =
vtkPolyDataToImageStencil::New();
		PolyDataToStencil->SetInput(polyData);

		vtkImageStencil* stencil = vtkImageStencil::New();

		vtkImageStencilData * imageStencilData = PolyDataToStencil->GetOutput();

		stencil->SetInput(image); 
		stencil->SetStencil(imageStencilData);
		stencil->ReverseStencilOff(); 
		stencil->SetBackgroundValue(0); 
		stencil->Update();

		vtkImageData * vtkImage = stencil->GetOutput();
		int dimensiones[3];
		vtkImage->GetDimensions(dimensiones);

		aaatVolumen= (unsigned char ***)malloc(512*512*512*sizeof(unsigned char));

-- 
View this message in context: http://www.nabble.com/How-to-convert-an-VTKImageData-to-a-binary-matrix--tf4376873.html#a12475658
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list