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

Luis Ibanez luis.ibanez at kitware.com
Thu Sep 14 09:32:04 EDT 2006


Hi Vivian,

1) When you say:

    "But the first step does not work"

   Do you mean:

      1) It didn't compiled ?
      2) It seg faulted at run time ?
      3) It throws and exception ?
      4) It produces an empty images ?
      5) It produces an image of a tube with wrong dimensions ?


   Please be kind and share more details with us.



2) Where is the "lum" filter defined ?

  The input that you are passing to the vtkExporter filter
  is the Output() of the "lum" object, but this object doesn't
  appear in the rest of the code snippet that you posted.


     vtkExporter ->SetInput (lum-> GetOutput());



3) BTW, note that you can build a tube model directly in ITK
   using the TubeSpatial Object, and then rasterize it into
   an itkImage using the SpatialObject to Image filter:

http://www.itk.org/Insight/Doxygen/html/classitk_1_1TubeSpatialObject.html

http://www.itk.org/Insight/Doxygen/html/classitk_1_1SpatialObjectToImageFilter.html




  Regards,




     Luis



----------------
fyy5581 wrote:
> 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
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users




More information about the Insight-users mailing list