[Insight-users] Questions about transferring 3D model from vtk to itk.

fyy5581 fyy5581 at 163.com
Tue Sep 12 10:05:09 EDT 2006


Hi all ,
I have questions about transferring 3D model from vtk to itk.
In fact,I want to draw a tube in vtk, and then transfer it into itk,thus I can use raycasting to project it into an image.But the first step does not work,which means I cannot transfer the tube I draw into itk.Can anybody help me?Thanks a lot!!!

Vivian

Here are my code:

    //--------------------VTK pipeline-----------------------
vtkLineSource* line3D = vtkLineSource::New();
 line3D->SetPoint1(0,0,0);
 line3D->SetPoint2(100,100,100); 
 line3D->Update();

 vtkTubeFilter* LineTube = vtkTubeFilter::New();
 LineTube->SetInput(line3D->GetOutput());
 LineTube->SetNumberOfSides(8);
 LineTube->SetRadius(2);

vtkImageData* image = vtkImageData::New();
 image->SetOrigin(0,0,0);
 image->SetSpacing(0.2,0.2,0.2);
 image->SetDimensions(50,50,50);
 image->SetScalarTypeToUnsignedChar();//double to unsighned Char
 image->AllocateScalars();
 image->Update();
 for (int n=0; n<image->GetNumberOfPoints(); n++){
  image->GetPointData()->GetScalars()->SetTuple1(n, 127);
 }

 vtkPolyDataToImageStencil * dataToStencil = vtkPolyDataToImageStencil::New(); 
 dataToStencil->SetInput(LineTube->GetOutput());

 vtkImageStencil* stencil = vtkImageStencil::New();
 stencil->SetInput(image);
 stencil->SetStencil(dataToStencil->GetOutput());
 stencil->ReverseStencilOff();
 stencil->SetBackgroundValue(0); 
 stencil->Update();

// ----------------VTK-ITK-------------------------
vtkImageExport* vtkExporter = vtkImageExport::New();
 vtkExporter ->SetInput (lum-> GetOutput());

 typedef itk::Image<unsigned char, 3> ImageType;
 typedef itk::VTKImageImport<ImageType> ImageImportType; 
 ImageImportType::Pointer itkImporter = ImageImportType::New(); 

 ConnectPipelines(vtkExporter, itkImporter);  //it's code comes from connectPipelines in VTKUtility.h  in 
                                                            // insightApplication

    //--------------------ITK pipeline-----------------------
 typedef itk::RescaleIntensityImageFilter< ImageType, ImageType > rescalefilterType;
 rescalefilterType::Pointer itkrescaler = rescalefilterType::New(); 
 itkrescaler->SetInput(itkImporter->GetOutput());
 itkrescaler->SetOutputMinimum(0);
 itkrescaler->SetOutputMaximum(65535);

 typedef itk::ImageFileWriter< ImageType > WriterType;
 WriterType::Pointer writer = WriterType::New();

 typedef itk::VTKImageIO    ImageIOType;
 ImageIOType::Pointer vtkIO = ImageIOType::New();

 writer->SetFileName(".\tubelineOutput.vtk");
 writer->SetInput(itkrescaler->GetOutput());  

 vtkIO->SetFileTypeToASCII();
 writer->SetImageIO( vtkIO );

  writer->Update();

...




fyy5581
2006-09-12
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060912/957ffdfb/attachment.html


More information about the Insight-users mailing list