[ITK] [ITK-users] Vector field not shown correctly on VTK
Nicolas Gallego
nicgallego at gmail.com
Tue May 13 03:50:02 EDT 2014
Hi Jose Ignacio
Have you visualized your data on paraview for example?
hope that helps
--
Nicolás Gallego Ortiz
2014-05-12 21:50 GMT+02:00 Jose Ignacio Prieto <joseignacio.prieto at gmail.com
>:
> Hi all, I am sending this to both lists, ITK and VTK. I have trouble
> loading three velocity dicom images (X, Y and Z axis). The problem is that
> when displaying the vector field as a Glyph3D, the arrows are aligned only
> in one axis. I have tried to check through iterators after the itk to vtk
> filter and the output shows the vector is fine. Then I don't know if the
> problem is in the glyph3d config or in the vtk data type. I attach all my
> code if someone could give me a hand.
>
> Thank you very much.
>
>
>
>
> typedef short ShortPixelType;
> typedef itk::Image<ShortPixelType, 4> ImageType4D; // ITK Image
> typedef itk::Image<ShortPixelType, 3> ImageType3D; // ITK Image
> typedef itk::Image< itk::CovariantVector< ShortPixelType, 3>, 4 >
> VectorImageType4D;
> typedef itk::Image< itk::CovariantVector< ShortPixelType, 3>, 3 >
> VectorImageType3D;
> typedef itk::itkImageSeriesReader< ImageType4D> ReaderType;
> typedef itk::ImageFileWriter< VectorImageType3D> WriterType3D;
> typedef itk::ImageFileWriter< VectorImageType4D> WriterType4D;
> typedef itk::ExtractImageFilter<VectorImageType4D, VectorImageType3D>
> ReductorType;
> typedef itk::ImageToVTKImageFilter<VectorImageType3D> ConnectorType;
> typedef itk::ComposeImageFilter< ImageType4D, VectorImageType4D >
> Vector4DComposer;
> typedef itk::ImageFileReader< VectorImageType4D> ReaderType4D;
>
>
>
> std::vector< ReaderType::Pointer > reader;
> std::vector< NamesGeneratorType::Pointer > nameGenerator;
> std::vector< ImageIOType::Pointer > dicomIO;
> reader.resize(3);
> nameGenerator.resize(3);
> dicomIO.resize(3);
> Vector4DComposer::Pointer vecComposer = Vector4DComposer::New();
> VectorImageType4D::Pointer m_vectorImage;
>
> for (int i = 0 ; i < 3 ; i++)
> {
> reader[i] = ReaderType::New();
> nameGenerator[i] = NamesGeneratorType::New();
> dicomIO[i] = ImageIOType::New();
> nameGenerator[i]->SetDirectory( argv[i + 1]);
> reader[i]->SetFileNames(nameGenerator[i]->GetInputFileNames());
> reader[i]->SetImageIO( dicomIO[i] );
> reader[i]->Update();
> vecComposer->SetInput(i,reader[i]->GetOutput());
> }
>
> vecComposer->UpdateLargestPossibleRegion();
> ImageType4D::SizeType size =
> vecComposer->GetOutput()->GetLargestPossibleRegion().GetSize();
>
> int nframes =
> vecComposer->GetOutput()->GetLargestPossibleRegion().GetSize()[3];
> int dim_eliminada=3;
> size[dim_eliminada]=0;
> VectorImageType4D::IndexType start =
> vecComposer->GetOutput()->GetLargestPossibleRegion().GetIndex();
> start[dim_eliminada] = 30;
> VectorImageType4D::RegionType desiredRegion;
> desiredRegion.SetSize( size );
> desiredRegion.SetIndex( start );
>
> ReductorType::Pointer reductor = ReductorType::New();
> reductor->InPlaceOn();
> reductor->SetDirectionCollapseToSubmatrix();
> reductor->SetExtractionRegion( desiredRegion );
> reductor->SetInput(vecComposer->GetOutput());
> reductor->Update();
>
>
> ConnectorType::Pointer m_connector = ConnectorType::New();
> m_connector->SetInput(reductor->GetOutput());
> m_connector->UpdateLargestPossibleRegion();
> m_connector->Update();
>
> std::cout << "image start " << std::endl;
> for (int i = 0; i < m_connector->GetOutput()->GetDimensions()[0]; i++)
> {
> for (int j = 0; j < m_connector->GetOutput()->GetDimensions()[1];
> j++)
> {
> for (int k = 0; k <
> m_connector->GetOutput()->GetDimensions()[2]; k++)
> {
> myfile<< "On point " << "i, j, k: " << i<<", "<< j<<", "<<
> k<<
> " Component 0: "<<
> m_connector->GetOutput()->GetScalarComponentAsDouble(i, j, k, 0) <<
> " Component 1: "<<
> m_connector->GetOutput()->GetScalarComponentAsDouble(i, j, k, 1) <<
> " Component 2: "<<
> m_connector->GetOutput()->GetScalarComponentAsDouble(i, j, k, 2) <<
> "\n";
> }
> }
> }
>
> vtkSmartPointer< vtkImageDataGeometryFilter > vtkConverter =
> vtkSmartPointer< vtkImageDataGeometryFilter >::New();
> vtkConverter->SetInput(m_connector->GetOutput());
> vtkConverter->UpdateWholeExtent();
>
> vtkSmartPointer< vtkArrowSource > m_arrows = vtkSmartPointer<
> vtkArrowSource >::New();
> m_arrows->SetTipLength(.1);
> m_arrows->SetTipResolution(5);
> m_arrows->SetTipRadius(.05);
> m_arrows->SetShaftResolution(5);
> m_arrows->SetShaftRadius(.015);
> m_arrows->Update();
>
> vtkSmartPointer< vtkGlyph3D > m_glyphs = vtkSmartPointer< vtkGlyph3D
> >::New();
> // m_glyphs->SetSourceConnection(m_connector->GetOutput());
> // m_glyphs->SetInput(m_connector->GetOutput());
> // m_glyphs->SetInputConnection(m_connector->GetOutput() ());
> m_glyphs->SetInputConnection(vtkConverter->GetOutputPort());
> // m_glyphs->SetSource(m_arrows->GetOutput());
> m_glyphs->SetSourceConnection(m_arrows->GetOutputPort());
> m_glyphs->OrientOn();
> // m_glyphs->OrientOff();
> // m_glyphs->SetVectorModeToVectorRotationOff();
> m_glyphs->SetVectorModeToUseVector();
> // m_glyphs->SetVectorModeToUseNormal();
> // m_glyphs->SetScaleModeToDataScalingOn();
> // m_glyphs->SetScaleModeToDataScalingOff();
> // m_glyphs->SetColorModeToColorByVector();
> // m_glyphs->SetScaleModeToScaleByVector();
> // m_glyphs->SetColorModeToColorByScalar();
> m_glyphs->SetColorModeToColorByScale();
> m_glyphs->SetScaleFactor(0.2);
> // m_glyphs->SetIndexModeToVector();
> // m_glyphs->SetScaleModeToDataScalingOff();
> // m_glyphs->SetScaleFactor(.5);
> m_glyphs->Update();
>
> vtkSmartPointer< vtkOpenGLPolyDataMapper > glyphPolyData =
> vtkSmartPointer< vtkOpenGLPolyDataMapper >::New();
> glyphPolyData->SetInputConnection(m_glyphs->GetOutputPort());
> vtkSmartPointer< vtkOpenGLActor > glyphActor = vtkSmartPointer<
> vtkOpenGLActor >::New();
> glyphActor->SetMapper(glyphPolyData);
>
> vtkSmartPointer< vtkWin32OpenGLRenderWindow > renWin =
> vtkSmartPointer< vtkWin32OpenGLRenderWindow>::New();
>
> vtkSmartPointer< vtkOpenGLRenderer> ren1 = vtkSmartPointer<
> vtkOpenGLRenderer> ::New();
> renWin->AddRenderer(ren1);
> ren1->AddActor(glyphActor);
>
> vtkSmartPointer< vtkRenderWindowInteractor > rwi = vtkSmartPointer<
> vtkRenderWindowInteractor >::New();
> vtkSmartPointer<MouseInteractorStyle> styleActor =
> vtkSmartPointer<MouseInteractorStyle>::New();
> rwi->SetInteractorStyle(styleActor);
>
> rwi->SetRenderWindow(renWin);
> rwi->SetSize(640, 480);
> rwi->Initialize();
> renWin->Render();
> rwi->Start();
>
>
> --
> José Ignacio Prieto
> Software developer
> Biomedical Imaging Center
> Pontificia Universidad Catolica de Chile
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> 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
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/cgi-bin/mailman/listinfo/community
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140513/e54b85b4/attachment-0002.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
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 Community
mailing list