<div dir="ltr"><div><div>Hi all, I solved my previous post about ExtractImageFilter with vectors, but now I have trouble building this code. I load a 4 different 4d objects in iTK, then transform them to a vector using ComposeImageFilter, then I select one time frame of the 4d objects ( getting a 3D vector of 4 components image). Finally I want to cast it to VTK to show it as a glyph, but it seems that the connector ImageToVTKImageFilter only works for scalar images, because it cannot create the object I am asking through the New macro. What can I do?<br>
</div>I attach the code and the error I am getting.<br><br></div>Thank you very much<br><div><div><div><br>typedef unsigned short PixelType;<br>typedef float InternalPixelType;<br>typedef itk::Image< InternalPixelType, 4> InternalImageType;<br>
typedef itk::Image< PixelType, 3> ImageType3D;<br>typedef itk::Image< PixelType, 4 > ImageType;<br>typedef itk::VectorImage<PixelType,4> VectorImageType;<br>typedef itk::VectorImage<PixelType,3> VectorImageType3D;<br>
typedef itk::ComposeImageFilter <ImageType> ImageToVectorImageFilter;<br>typedef jip::jipItkImageSeriesReader< ImageType > ReaderType;<br>typedef VectorImageType InputImageType;<br>typedef VectorImageType3D OutputImageType;<br>
typedef itk::ExtractImageFilter<InputImageType, OutputImageType> ReductorType;<br>typedef itk::ImageToVTKImageFilter<VectorImageType3D> ConnectorType;<br>typedef itk::DCMTKSeriesFileNames NamesGeneratorType;<br>
typedef itk::DCMTKImageIO ImageIOType;<br><br><br><br><br><br>int main( int argc, char *argv[] )<br>{<br> if( argc != 5 )<br> {<br> PrintCommandLineUsage(argc, argv);<br> return EXIT_FAILURE;<br>
}<br><br> ImageType::Pointer vectorImage[4];<br> ReaderType::Pointer vectorReader[4];<br> ImageToVectorImageFilter::Pointer imagetovec;<br> imagetovec=ImageToVectorImageFilter::New();<br> NamesGeneratorType::Pointer nameGenerator[4];<br>
ImageIOType::Pointer dicomIO[4];<br><br><br> for (int i=0;i<4;i++)<br> {<br> nameGenerator[i]= NamesGeneratorType::New();<br> vectorImage[i]=ImageType::New();<br> vectorReader[i]=ReaderType::New();<br>
dicomIO[i]= ImageIOType::New();<br><br><br> nameGenerator[i]->SetDirectory( argv[1+i]);<br> vectorReader[i]->SetFileNames(nameGenerator[i]->GetInputFileNames());<br> vectorReader[i]->SetImageIO( dicomIO[i] );<br>
<br><br><br> imagetovec->SetInput(i,vectorReader[i]->GetOutput());<br> <br> }<br><br> VectorImageType::Pointer vectorim2= imagetovec->GetOutput();<br> vectorim2->Update();<br> VectorImageType::RegionType region =vectorim2->GetLargestPossibleRegion();<br>
VectorImageType::SizeType size = region.GetSize();<br><br> ReductorType::Pointer reductor=ReductorType::New();<br> reductor->InPlaceOn();<br> reductor->SetDirectionCollapseToSubmatrix();<br><br> int nframes=size[3];<br>
int dim_eliminada=3;<br> size[dim_eliminada]=0;<br><br> InputImageType::IndexType start = region.GetIndex();<br> unsigned int sliceNumber = 0;<br> start[dim_eliminada] = sliceNumber;<br><br> InputImageType::RegionType desiredRegion;<br>
desiredRegion.SetSize( size );<br> desiredRegion.SetIndex( start );<br><br> reductor->SetExtractionRegion( desiredRegion );<br> reductor->SetInput(imagetovec->GetOutput());<br><br> reductor->Update();<br>
<br> int nrenderers=1;<br> ConnectorType::Pointer connector[nrenderers];<br> for ( int i =0;i<nrenderers ;i++ )<br> {<br> connector[i]= ConnectorType::New();<br> connector[i]->SetInput(reductor->GetOutput());<br>
connector[i]->Update();<br> }<br><br> vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New();<br> arrowSource->Update();<br><br> vtkSmartPointer<vtkGlyph3D> glyphFilter = vtkSmartPointer<vtkGlyph3D>::New();<br>
glyphFilter->SetSourceConnection(arrowSource->GetOutputPort());<br> glyphFilter->OrientOn();<br> glyphFilter->SetVectorModeToUseVector();<br><br><br> glyphFilter->SetInput(connector[0]->GetOutput());<br>
<br>// vtkSmartPointer<vtkGlyph3DMapper> glyph3DMapper =vtkSmartPointer<vtkGlyph3DMapper>::New();<br>// glyph3DMapper->SetInputConnection(glyphFilter->GetOutput());<br><br> vtkSmartPointer<vtkPolyDataMapper> vectorMapper = vtkSmartPointer<vtkPolyDataMapper>::New();<br>
vectorMapper->SetInputConnection(glyphFilter->GetOutputPort());<br> vtkSmartPointer<vtkActor> vectorActor = vtkSmartPointer<vtkActor>::New();<br> vectorActor->SetMapper(vectorMapper);<br><br>
<br>// vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();<br>// actor->SetMapper(glyph3DMapper);<br><br> // Create a renderer, render window, and interactor<br> vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();<br>
<br> vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();<br> renderWindow->AddRenderer(renderer);<br> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
renderWindowInteractor->SetRenderWindow(renderWindow);<br><br> // Add the actor to the scene<br>// renderer->AddActor(actor);<br> renderer->AddViewProp(vectorActor);<br> // Render and interact<br>
renderWindow->Render();<br> renderWindowInteractor->Start();<br><br> return EXIT_SUCCESS;<br><br><br><br><br>
<style type="text/css">
p, li { white-space: pre-wrap; }
</style>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(20,20,190)">16:43:07: Running build steps for project Vector4DFlow...</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(20,20,190)">16:43:07: Starting: "/usr/bin/make" -j 8</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(60,60,60)">Scanning dependencies of target Vector4DFlow</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(60,60,60)">[ 20%] Building CXX object CMakeFiles/Vector4DFlow.dir/Vector4DFlow.cxx.o</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">In file included from /opt/itk/vtk5/debug8/include/ITK-4.5/itkConceptChecking.h:31:0,</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)"> from /opt/itk/vtk5/debug8/include/ITK-4.5/itkMath.h:33,</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)"> from /opt/itk/vtk5/debug8/include/ITK-4.5/itkIndex.h:23,</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)"> from /opt/itk/vtk5/debug8/include/ITK-4.5/itkContinuousIndex.h:22,</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)"> from /opt/itk/vtk5/debug8/include/ITK-4.5/itkImageRegion.h:34,</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)"> from /opt/itk/vtk5/debug8/include/ITK-4.5/itkImage.h:21,</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)"> from /home/cib/ejemplos/EjemplosItk/IO/Vector4DFlow/Vector4DFlow.cxx:36:</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">/opt/itk/vtk5/debug8/include/ITK-4.5/itkPixelTraits.h: In instantiation of ‘itk::PixelTraits<itk::VariableLengthVector<short unsigned int> >’:</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">/opt/itk/vtk5/debug8/include/ITK-4.5/itkVTKImageExport.hxx:35:56: instantiated from ‘itk::VTKImageExport<TInputImage>::VTKImageExport() [with TInputImage = itk::VectorImage<short unsigned int, 3u>]’</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">/opt/itk/vtk5/debug8/include/ITK-4.5/itkVTKImageExport.h:69:3: instantiated from ‘static itk::VTKImageExport<TInputImage>::Pointer itk::VTKImageExport<TInputImage>::New() [with TInputImage = itk::VectorImage<short unsigned int, 3u>, itk::VTKImageExport<TInputImage>::Pointer = itk::SmartPointer<itk::VTKImageExport<itk::VectorImage<short unsigned int, 3u> > >]’</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">/opt/itk/vtk5/debug8/include/ITK-4.5/itkImageToVTKImageFilter.hxx:34:3: instantiated from ‘itk::ImageToVTKImageFilter<TInputImage>::ImageToVTKImageFilter() [with TInputImage = itk::VectorImage<short unsigned int, 3u>]’</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">/opt/itk/vtk5/debug8/include/ITK-4.5/itkImageToVTKImageFilter.h:56:3: instantiated from ‘static itk::ImageToVTKImageFilter<TInputImage>::Pointer itk::ImageToVTKImageFilter<TInputImage>::New() [with TInputImage = itk::VectorImage<short unsigned int, 3u>, itk::ImageToVTKImageFilter<TInputImage>::Pointer = itk::SmartPointer<itk::ImageToVTKImageFilter<itk::VectorImage<short unsigned int, 3u> > >]’</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">/home/cib/ejemplos/EjemplosItk/IO/Vector4DFlow/Vector4DFlow.cxx:386:38: instantiated from here</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">/opt/itk/vtk5/debug8/include/ITK-4.5/itkPixelTraits.h:49:3: error: ‘Length’ is not a member of ‘itk::VariableLengthVector<short unsigned int>’</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">make[2]: *** [CMakeFiles/Vector4DFlow.dir/Vector4DFlow.cxx.o] Error 1</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">make[1]: *** [CMakeFiles/Vector4DFlow.dir/all] Error 2</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">make: *** [all] Error 2</span></p>
<p style="margin:0px;text-indent:0px"><span style="font-weight:600;color:rgb(190,20,20)">16:43:10: The process "/usr/bin/make" exited with code 2.</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">Error while building project Vector4DFlow (target: Desktop)</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(190,20,20)">When executing build step 'Make'</span></p><br clear="all"><br>-- <br>José Ignacio Prieto<br>celular(nuevo): 94348182
</div></div></div></div>