#include "vtkDatasetToImageGenerator.h" #include "vtkObjectFactory.h" #include vtkCxxRevisionMacro(vtkDatasetToImageGenerator, "$Revision: 1.1 $"); vtkStandardNewMacro(vtkDatasetToImageGenerator); vtkDatasetToImageGenerator::vtkDatasetToImageGenerator() { this->Input = 0; this->Output = vtkImageData::New(); } vtkDatasetToImageGenerator::~vtkDatasetToImageGenerator() { this->Output->Delete(); } void vtkDatasetToImageGenerator::Update() { if (!this->Input || !this->Output) return; double bounds[6]; this->Input->GetBounds(bounds); int dim[3] = {128, 128, 128}; double spacing[3] = {1,1,1}; spacing[0] = (bounds[1] - bounds[0])/(double)dim[0]; spacing[1] = (bounds[3] - bounds[2])/(double)dim[1]; spacing[2] = (bounds[5] - bounds[4])/(double)dim[2]; std::cout<<"bounds : " <Output->SetScalarTypeToUnsignedChar(); this->Output->SetDimensions (dim[0], dim[1], dim[2] ); this->Output->SetOrigin (bounds[0], bounds[2], bounds[4] ); this->Output->SetSpacing (spacing[0], spacing[1], spacing[2] ); this->Output->AllocateScalars(); this->Output->Update(); }