[Insight-users] itkImageToVTKImageFilter
Luis Ibanez
luis.ibanez at kitware.com
Mon Mar 23 08:37:15 EDT 2009
Hi
Thanks for posting your code.
Please replace:
vtkStructuredPointsReader *vreader = vtkStructuredPointsReader::New();
vreader->SetInputConnection( connector->GetOutput() );
vtkMarchingCubes *iso = vtkMarchingCubes::New();
iso->SetInputConnection(vreader->GetOutputPort());
iso->SetValue( 0, IntesityLevel);
With:
vtkMarchingCubes *iso = vtkMarchingCubes::New();
iso->SetInputConnection( connector->GetOutput() );
iso->SetValue( 0, IntesityLevel);
That is:
You don't need the vtkStructuredPointReader at all
in this pipeline.
Regards,
Luis
-----------------------
Árpád Szamosi wrote:
> Thanks Luis, here is the code:
>
> #include "itkOrientedImage.h"
> #include "itkGDCMImageIO.h"
> #include "itkGDCMSeriesFileNames.h"
> #include "itkImageSeriesReader.h"
> #include "itkImageFileWriter.h"
>
> #include "itkImageToVTKImageFilter.h"
>
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkActor.h"
> #include "vtkCamera.h"
> #include "vtkPolyDataNormals.h"
> #include "vtkStructuredPointsReader.h"
> #include "vtkMarchingCubes.h"
> #include "vtkProperty.h"
> #include "vtkCleanPolyData.h"
>
>
>
> int main( int argc, char* argv[] )
> {
>
> long int size[3];
> double IntesityLevel=atof(argv[2]);
>
> typedef signed short PixelType;
> const unsigned int Dimension = 3;
>
> typedef itk::OrientedImage< 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->SetUseSeriesDetails( true );
> nameGenerator->AddSeriesRestriction("0008|0021" );
>
> nameGenerator->SetDirectory( argv[1] );
>
>
>
> std::cout << std::endl << "The directory: " << std::endl;
> std::cout << std::endl << argv[1] << std::endl << std::endl;
> std::cout << "Contains the following DICOM Series: ";
> std::cout << std::endl << std::endl;
>
> typedef std::vector< std::string > SeriesIdContainer;
>
> const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
>
> SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
> SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
> while( seriesItr != seriesEnd )
> {
> std::cout << seriesItr->c_str() << std::endl;
> seriesItr++;
> }
>
> std::string seriesIdentifier;
>
>
> seriesIdentifier = seriesUID.begin()->c_str();
>
>
> std::cout << std::endl << std::endl;
> std::cout << "Now reading series: " << std::endl << std::endl;
> std::cout << seriesIdentifier << std::endl;
> std::cout << std::endl << std::endl;
>
>
> typedef std::vector< std::string > FileNamesContainer;
> FileNamesContainer fileNames;
>
> fileNames = nameGenerator->GetFileNames( seriesIdentifier );
>
> reader->SetFileNames( fileNames );
>
> try
> {
> reader->Update();
> }
> catch (itk::ExceptionObject &ex)
> {
> std::cout << ex << std::endl;
> return EXIT_FAILURE;
> }
>
> size[0] = reader->GetOutput()->GetRequestedRegion().GetSize()[0] ;
> size[1] = reader->GetOutput()->GetRequestedRegion().GetSize()[1] ;
> size[2] = reader->GetOutput()->GetRequestedRegion().GetSize()[2] ;
> std::cout << "A térfogat méretei:" << std::endl;
> std::cout << "x:" << size[0] << std::endl;
> std::cout << "y:" << size[1] << std::endl;
> std::cout << "z:" << size[2] << std::endl;
>
> ///////////////////////////////////////// ITK
> ///////////////////////////////////////////////////////////////////
>
> typedef itk::ImageToVTKImageFilter< ImageType> ConnectorType;
> ConnectorType::Pointer connector = ConnectorType::New();
> connector->SetInput( reader->GetOutput() );
>
> ///////////////////////////////////////// VTK
> ////////////////////////////////////////////////////////////////////
>
> vtkRenderer *renderer = vtkRenderer::New();
> vtkRenderWindow *window = vtkRenderWindow::New();
> window->AddRenderer(renderer);
> vtkRenderWindowInteractor *interactor =
> vtkRenderWindowInteractor::New();
> interactor->SetRenderWindow(window);
>
>
>
> vtkStructuredPointsReader *vreader =
> vtkStructuredPointsReader::New();
> vreader->SetInputConnection( connector->GetOutput() );
> //reader->SetFileName(argv[1]);
>
> vtkMarchingCubes *iso = vtkMarchingCubes::New();
> iso->SetInputConnection(vreader->GetOutputPort());
> iso->SetValue( 0, IntesityLevel);
>
> vtkCleanPolyData *clean = vtkCleanPolyData::New();
> clean->SetInputConnection(iso->GetOutputPort());
>
> vtkPolyDataNormals *normal = vtkPolyDataNormals::New();
> normal->SetInputConnection(clean->GetOutputPort());
> normal->SetFeatureAngle(60.0);
>
> vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
> mapper->SetInputConnection(normal->GetOutputPort());
> mapper->ScalarVisibilityOff();
>
> vtkActor *isoactor = vtkActor::New();
> isoactor->SetMapper(mapper);
> isoactor->GetProperty()->SetColor(1,1,0);
>
> vtkCamera *camera = vtkCamera::New();
> camera->SetViewUp (0, 0, 1);
> camera->SetPosition (0, -1, 0);
> /* camera->SetFocalPoint (0, 0, 0);*/
> camera->ComputeViewPlaneNormal();
>
>
> renderer->AddActor(isoactor);
> renderer->SetActiveCamera(camera);
> renderer->ResetCamera ();
> camera->Dolly(1);
>
>
> renderer->SetBackground(1,1,1);
> window->SetSize(640, 480);
>
>
> renderer->ResetCameraClippingRange ();
>
> interactor->Initialize();
> window->SetWindowName( "Koponya" ); //azert itt mert bugos
> interactor->Start();
>
> std::cout << "Kész" << std::endl;
>
>
> reader->Delete();
> dicomIO->Delete();
> nameGenerator->Delete();
> connector->Delete();
> renderer->Delete();
> window->Delete();
> interactor->Delete();
> vreader->Delete();
> iso->Delete();
> clean->Delete();
> normal->Delete();
> mapper->Delete();
> isoactor->Delete();
> camera->Delete();
>
>
> return EXIT_SUCCESS;
>
> }
>
>
> 2009/3/22 Luis Ibanez <luis.ibanez at kitware.com
> <mailto:luis.ibanez at kitware.com>>
>
> Hi Arepi,
>
> Please post your code...
>
> It doesn't makes much sense to connect the output of an importer
> as the input of a reader. (maybe you meant to say a "writer" ?).
>
> Source code will be better that a verbal description of the source
> code :-)
>
> Thanks
>
> Luis
>
>
> ------------------------------------------
> On Sun, Mar 22, 2009 at 11:07 AM, Arepi <szamosi.arpad at gmail.com
> <mailto:szamosi.arpad at gmail.com>> wrote:
> >
> > Hi,
> >
> > I tried connect itk to vtk whit itkImageToVTKImageFilter. The
> first part is
> > itk and read a DICOM series(see
> > Examples/IO/DicomSeriesReadImageWrite2.cxx.), but I would the
> reader input
> > connect to vtk, instead write to a .vtk file. The second part is
> vtk and I
> > tried connect the itkImageToVTKImageFilter output to en
> > vtkStructuredPointsReader(and than MarchingCubes, DataNormal etc)
> but came
> > back whit following error:
> >
> > error C2664: 'void
> vtkAlgorithm::SetInputConnection(vtkAlgorithmOutput *)'
> > : cannot convert parameter 1 from 'vtkImageData *' to
> 'vtkAlgorithmOutput *'
> > Types pointed to are unrelated; conversion requires
> > reinterpret_cast, C-style cast or function-style cast
> >
> > I choossed a wrong reader or what should I do to works it fine?
> >
> > Thanks!
> >
> > Arepi
> > --
> > View this message in context:
> http://www.nabble.com/itkImageToVTKImageFilter-tp22646859p22646859.html
> > Sent from the ITK - Users mailing list archive at Nabble.com.
> >
> > _____________________________________
> > Powered by www.kitware.com <http://www.kitware.com>
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.itk.org/mailman/listinfo/insight-users
> >
>
>
More information about the Insight-users
mailing list