[vtkusers] [Insight-users] vtkPolyData is required??

董辉 dhjimy at 126.com
Mon Jun 17 22:34:09 EDT 2013


Hello David Doria:
      I see this letter just ago. Frist thank you for you help.  In my project  ,I take use of  GDCMImageIO reader a DICOM series,then used the class "itkBinaryMask3DMeshSource" to produre the TriangleMesh, the class " itkTriangleMeshToBinaryImageFilter" was used to make the TriangleMesh to BinaryImage,      
then,display the image in the vtk, then the error appeared.  this code is follow;

int main( int argc, char* argv[] )
{
  if( argc < 3 )
    {
    std::cerr << "Usage: " << argv[0] << " DicomDirectory " << std::endl;
    return EXIT_FAILURE;
    }
  typedef float         PixelType;
  const unsigned int    Dimension = 3;
  typedef itk::Image< PixelType, Dimension >      ImageType;
  typedef itk::ImageSeriesReader< ImageType >     ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  typedef itk::GDCMImageIO       ImageIOType; 
  ImageIOType::Pointer dicomIO = ImageIOType::New();
  reader->SetImageIO( dicomIO );
  typedef itk::GDCMSeriesFileNames     NamesGeneratorType;
  NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
  nameGenerator->SetInputDirectory( argv[1] );//"e://mi/pic/111"
  typedef std::vector<std::string>    FileNamesContainer;
  FileNamesContainer fileNames = nameGenerator->GetInputFileNames();
  reader->SetFileNames( fileNames );
 try
    {
    reader->Update();
    }
  catch (itk::ExceptionObject &ex)
    {
    std::cout << ex << std::endl;
    return EXIT_FAILURE;
    }


  typedef itk::DefaultStaticMeshTraits<double, 3, 3, double, double, double> TriangleMeshTraits;
  typedef itk::Mesh<double,3,TriangleMeshTraits> TriangleMeshType;
 // typedef itkMeshTovtkPolyData::TriangleMeshType MeshType;
  typedef itk::BinaryMask3DMeshSource< ImageType,TriangleMeshType> MeshSourceType; 
  MeshSourceType::Pointer mesh = MeshSourceType::New(); 
  const PixelType objectValue = static_cast<PixelType>( atof( argv[2] ) ); 
  mesh->SetObjectValue( objectValue ); 
  mesh->SetInput( reader->GetOutput() ); 
  mesh->ReleaseDataFlagOn();
  mesh->Update();

  try 
    { 
    mesh->Update(); 
    } 
  catch( itk::ExceptionObject & exp ) 
    { 
    std::cerr << "Exception thrown during Update() " << std::endl; 
    std::cerr << exp << std::endl; 
    return EXIT_FAILURE; 
    } 
  std::cout << "Nodes = " << mesh->GetNumberOfNodes() << std::endl; 
  std::cout << "Cells = " << mesh->GetNumberOfCells() << std::endl; 

    ImageType::Pointer Image = reader->GetOutput();
    const ImageType::PointType &Origin = Image->GetOrigin();
    const ImageType::SizeType &Size = Image->GetLargestPossibleRegion().GetSize();
    const ImageType::SpacingType &Spacing = Image->GetSpacing();
    const ImageType::IndexType &Index =Image->GetLargestPossibleRegion().GetIndex();

    typedef itk::TriangleMeshToBinaryImageFilter <TriangleMeshType, ImageType> itkTriangleMeshToBinaryImageFilterType;
    itkTriangleMeshToBinaryImageFilterType::Pointer meshFilter =itkTriangleMeshToBinaryImageFilterType::New();
     meshFilter->SetTolerance (1.0);
     meshFilter->SetOrigin(Origin);
	 meshFilter->SetSize(Size);
     meshFilter->SetSpacing(Spacing);
	 meshFilter->SetIndex(Index);
	 meshFilter->SetInput(mesh->GetOutput());
     try
    {
        meshFilter->Update();
    }
    catch ( itk::ExceptionObject &err )
    {
        std::cout << "ExceptionObject caught !" << std::endl;
        std::cout << err << std::endl;
        return -1;
    }

  typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
	ConnectorType::Pointer meshConnector= ConnectorType::New();
	meshConnector->SetInput(meshFilter->GetOutput() );

    vtkImageCast* meshImageCast=vtkImageCast::New();
    meshImageCast->SetInput(meshConnector->GetOutput());
    meshImageCast->SetOutputScalarTypeToUnsignedShort();
    meshImageCast->ClampOverflowOn();



	vtkPolyDataNormals *meshNormals = vtkPolyDataNormals::New();
	meshNormals->SetInputConnection(meshImageCast->GetOutputPort());
	meshNormals->SetFeatureAngle(60.0);
    vtkStripper *meshStripper = vtkStripper::New();
    meshStripper->SetInputConnection(meshNormals->GetOutputPort());
    vtkPolyDataMapper *meshMapper = vtkPolyDataMapper::New();
	meshMapper->SetInputConnection(meshStripper->GetOutputPort());
	meshMapper->ScalarVisibilityOff();
	vtkActor * meshActor= vtkActor::New();
	meshActor->SetMapper(meshMapper);
    meshActor->GetProperty()->SetDiffuseColor(1.0,1.0,0.9412);
	meshActor->GetProperty()->SetSpecular( .5);
	meshActor->GetProperty()->SetSpecularPower(70);
	meshActor->GetProperty()->SetOpacity(1.0);

    vtkRenderer *meshRenderer=vtkRenderer::New();
	meshRenderer->AddActor(meshActor);
	meshRenderer->SetBackground(.1,0.2,0.4);

	vtkRenderWindow *renWin=vtkRenderWindow::New();
	renWin->SetSize(400,400);
	renWin->AddRenderer(meshRenderer);

	vtkRenderWindowInteractor *interactor=vtkRenderWindowInteractor::New();
	interactor->SetRenderWindow(renWin);
.
在 2013-06-14 19:49:14,"David Doria" <daviddoria at gmail.com> 写道:
>On Fri, Jun 14, 2013 at 4:13 AM, 董辉 <dhjimy at 126.com> wrote:
>> Hello  all,
>>    There is a Problem in  my  project  “ERROR: In ..\..\VTK
>> 5.8.0\vtk-5.8.0\Filtering\vtkDemandDrivenPipeline.cxx, line 827
>> vtkStreamingDemandDrivenPipeline (0AA3DA80): Input for connection index 0 on
>> input port index 0 for algorithm vtkPolyDataNormals(0A9B3498) is of type
>> vtkImageData, but a vtkPolyData is required.”  How can I solve it . Please
>> gei me a idea or suggest.
>
>This might help:
>
>http://www.vtk.org/Wiki/VTK/Examples/Cxx/ImageData/ImageDataGeometryFilter
>
>However, you would need to give us much more information before we can
>say for sure. What are you trying to do exactly?
>
>David




More information about the vtkusers mailing list