[Insight-users] ITK to VTK for itk::vectorimage
Jose Ignacio Prieto
joseignacio.prieto at gmail.com
Mon Aug 12 16:54:47 EDT 2013
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?
I attach the code and the error I am getting.
Thank you very much
typedef unsigned short PixelType;
typedef float InternalPixelType;
typedef itk::Image< InternalPixelType, 4> InternalImageType;
typedef itk::Image< PixelType, 3> ImageType3D;
typedef itk::Image< PixelType, 4 > ImageType;
typedef itk::VectorImage<PixelType,4> VectorImageType;
typedef itk::VectorImage<PixelType,3> VectorImageType3D;
typedef itk::ComposeImageFilter <ImageType> ImageToVectorImageFilter;
typedef jip::jipItkImageSeriesReader< ImageType > ReaderType;
typedef VectorImageType InputImageType;
typedef VectorImageType3D OutputImageType;
typedef itk::ExtractImageFilter<InputImageType, OutputImageType>
ReductorType;
typedef itk::ImageToVTKImageFilter<VectorImageType3D> ConnectorType;
typedef itk::DCMTKSeriesFileNames NamesGeneratorType;
typedef itk::DCMTKImageIO ImageIOType;
int main( int argc, char *argv[] )
{
if( argc != 5 )
{
PrintCommandLineUsage(argc, argv);
return EXIT_FAILURE;
}
ImageType::Pointer vectorImage[4];
ReaderType::Pointer vectorReader[4];
ImageToVectorImageFilter::Pointer imagetovec;
imagetovec=ImageToVectorImageFilter::New();
NamesGeneratorType::Pointer nameGenerator[4];
ImageIOType::Pointer dicomIO[4];
for (int i=0;i<4;i++)
{
nameGenerator[i]= NamesGeneratorType::New();
vectorImage[i]=ImageType::New();
vectorReader[i]=ReaderType::New();
dicomIO[i]= ImageIOType::New();
nameGenerator[i]->SetDirectory( argv[1+i]);
vectorReader[i]->SetFileNames(nameGenerator[i]->GetInputFileNames());
vectorReader[i]->SetImageIO( dicomIO[i] );
imagetovec->SetInput(i,vectorReader[i]->GetOutput());
}
VectorImageType::Pointer vectorim2= imagetovec->GetOutput();
vectorim2->Update();
VectorImageType::RegionType region
=vectorim2->GetLargestPossibleRegion();
VectorImageType::SizeType size = region.GetSize();
ReductorType::Pointer reductor=ReductorType::New();
reductor->InPlaceOn();
reductor->SetDirectionCollapseToSubmatrix();
int nframes=size[3];
int dim_eliminada=3;
size[dim_eliminada]=0;
InputImageType::IndexType start = region.GetIndex();
unsigned int sliceNumber = 0;
start[dim_eliminada] = sliceNumber;
InputImageType::RegionType desiredRegion;
desiredRegion.SetSize( size );
desiredRegion.SetIndex( start );
reductor->SetExtractionRegion( desiredRegion );
reductor->SetInput(imagetovec->GetOutput());
reductor->Update();
int nrenderers=1;
ConnectorType::Pointer connector[nrenderers];
for ( int i =0;i<nrenderers ;i++ )
{
connector[i]= ConnectorType::New();
connector[i]->SetInput(reductor->GetOutput());
connector[i]->Update();
}
vtkSmartPointer<vtkArrowSource> arrowSource =
vtkSmartPointer<vtkArrowSource>::New();
arrowSource->Update();
vtkSmartPointer<vtkGlyph3D> glyphFilter =
vtkSmartPointer<vtkGlyph3D>::New();
glyphFilter->SetSourceConnection(arrowSource->GetOutputPort());
glyphFilter->OrientOn();
glyphFilter->SetVectorModeToUseVector();
glyphFilter->SetInput(connector[0]->GetOutput());
// vtkSmartPointer<vtkGlyph3DMapper> glyph3DMapper
=vtkSmartPointer<vtkGlyph3DMapper>::New();
// glyph3DMapper->SetInputConnection(glyphFilter->GetOutput());
vtkSmartPointer<vtkPolyDataMapper> vectorMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
vectorMapper->SetInputConnection(glyphFilter->GetOutputPort());
vtkSmartPointer<vtkActor> vectorActor =
vtkSmartPointer<vtkActor>::New();
vectorActor->SetMapper(vectorMapper);
// vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
// actor->SetMapper(glyph3DMapper);
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor
= vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actor to the scene
// renderer->AddActor(actor);
renderer->AddViewProp(vectorActor);
// Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
16:43:07: Running build steps for project Vector4DFlow...
16:43:07: Starting: "/usr/bin/make" -j 8
Scanning dependencies of target Vector4DFlow
[ 20%] Building CXX object CMakeFiles/Vector4DFlow.dir/Vector4DFlow.cxx.o
In file included from
/opt/itk/vtk5/debug8/include/ITK-4.5/itkConceptChecking.h:31:0,
from /opt/itk/vtk5/debug8/include/ITK-4.5/itkMath.h:33,
from /opt/itk/vtk5/debug8/include/ITK-4.5/itkIndex.h:23,
from /opt/itk/vtk5/debug8/include/ITK-4.5/itkContinuousIndex.h:22,
from /opt/itk/vtk5/debug8/include/ITK-4.5/itkImageRegion.h:34,
from /opt/itk/vtk5/debug8/include/ITK-4.5/itkImage.h:21,
from /home/cib/ejemplos/EjemplosItk/IO/Vector4DFlow/Vector4DFlow.cxx:36:
/opt/itk/vtk5/debug8/include/ITK-4.5/itkPixelTraits.h: In instantiation of
‘itk::PixelTraits<itk::VariableLengthVector<short unsigned int> >’:
/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>]’
/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> > >]’
/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>]’
/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> > >]’
/home/cib/ejemplos/EjemplosItk/IO/Vector4DFlow/Vector4DFlow.cxx:386:38:
instantiated from here
/opt/itk/vtk5/debug8/include/ITK-4.5/itkPixelTraits.h:49:3: error: ‘Length’
is not a member of ‘itk::VariableLengthVector<short unsigned int>’
make[2]: *** [CMakeFiles/Vector4DFlow.dir/Vector4DFlow.cxx.o] Error 1
make[1]: *** [CMakeFiles/Vector4DFlow.dir/all] Error 2
make: *** [all] Error 2
16:43:10: The process "/usr/bin/make" exited with code 2.
Error while building project Vector4DFlow (target: Desktop)
When executing build step 'Make'
--
José Ignacio Prieto
celular(nuevo): 94348182
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130812/a75f029b/attachment.htm>
More information about the Insight-users
mailing list