]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageIndexesContainerToPolyData.hxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageIndexesContainerToPolyData.hxx
diff --git a/lib/cpExtensions/Visualization/ImageIndexesContainerToPolyData.hxx b/lib/cpExtensions/Visualization/ImageIndexesContainerToPolyData.hxx
new file mode 100644 (file)
index 0000000..a1403ce
--- /dev/null
@@ -0,0 +1,188 @@
+#ifndef __CPEXTENSIONS__VISUALIZATION__IMAGEINDEXESCONTAINERTOPOLYDATA__HXX__
+#define __CPEXTENSIONS__VISUALIZATION__IMAGEINDEXESCONTAINERTOPOLYDATA__HXX__
+
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+
+// -------------------------------------------------------------------------
+template< class _TIndexes >
+typename cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+Self* cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+New( )
+{
+  return( new Self( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TIndexes >
+const typename cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+TIndexes* cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+GetInput( ) const
+{
+  return( this->m_Indexes );
+}
+
+// -------------------------------------------------------------------------
+template< class _TIndexes >
+const typename cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+TImage* cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+GetReferenceImage( ) const
+{
+  return( this->m_ReferenceImage );
+}
+
+// -------------------------------------------------------------------------
+template< class _TIndexes >
+void cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+SetInput( const TIndexes* c )
+{
+  if( this->m_Indexes != c )
+  {
+    this->m_Indexes = c;
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TIndexes >
+void cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+SetReferenceImage( const TImage* i )
+{
+  if( this->m_ReferenceImage != i )
+  {
+    this->m_ReferenceImage = i;
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TIndexes >
+cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+ImageIndexesContainerToPolyData( )
+  : vtkPolyDataAlgorithm( ),
+    m_Indexes( NULL ),
+    m_ReferenceImage( NULL )
+{
+  this->SetNumberOfInputPorts( 0 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TIndexes >
+cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+~ImageIndexesContainerToPolyData( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TIndexes >
+int cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+RequestData(
+  vtkInformation* information,
+  vtkInformationVector** input,
+  vtkInformationVector* output
+  )
+{
+  static const unsigned int dim = TIndex::Dimension;
+
+  if( this->m_Indexes == NULL )
+    return( 0 );
+
+  // Get output
+  vtkInformation* info = output->GetInformationObject( 0 );
+  vtkPolyData* out = vtkPolyData::SafeDownCast(
+    info->Get( vtkDataObject::DATA_OBJECT( ) )
+    );
+
+  // Get input data
+  auto& lst = this->m_Indexes->Get( );
+
+  // Prepare points
+  vtkPoints* points = out->GetPoints( );
+  if( points == NULL )
+  {
+    points = vtkPoints::New( );
+    out->SetPoints( points );
+    points->Delete( );
+
+  } // fi
+  points->SetNumberOfPoints( lst.size( ) );
+
+  // Prepare cells
+  vtkSmartPointer< vtkCellArray > verts =
+    vtkSmartPointer< vtkCellArray >::New( );
+
+  for( unsigned int i = 0; i < lst.size( ); ++i )
+  {
+    auto idx = lst[ i ];
+    if( this->m_ReferenceImage != NULL )
+    {
+      typename TImage::PointType pnt;
+      this->m_ReferenceImage->TransformIndexToPhysicalPoint( idx, pnt );
+      if( dim == 1 )
+        points->SetPoint( i, pnt[ 0 ], 0, 0 );
+      else if( dim == 2 )
+        points->SetPoint( i, pnt[ 0 ], pnt[ 1 ], 0 );
+      else
+        points->SetPoint( i, pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
+    }
+    else
+    {
+      if( dim == 1 )
+        points->SetPoint( i, idx[ 0 ], 0, 0 );
+      else if( dim == 2 )
+        points->SetPoint( i, idx[ 0 ], idx[ 1 ], 0 );
+      else
+        points->SetPoint( i, idx[ 0 ], idx[ 1 ], idx[ 2 ] );
+
+    } // fi
+    verts->InsertNextCell( 1 );
+    verts->InsertCellPoint( i );
+
+  } // rof
+  out->SetPoints( points );
+  out->SetVerts( verts );
+  return( 1 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TIndexes >
+int
+cpExtensions::Visualization::ImageIndexesContainerToPolyData< _TIndexes >::
+RequestInformation(
+  vtkInformation* information,
+  vtkInformationVector** input,
+  vtkInformationVector* output
+  )
+{
+  vtkInformation* info = output->GetInformationObject( 0 );
+  /* TODO
+     info->Set(
+     vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES( ), -1
+     );
+  */
+
+  if( this->m_Indexes != NULL && this->m_ReferenceImage != NULL )
+  {
+    /* TODO
+       typename C::TScalar len = this->m_RGC->GetTotalLength( );
+       typename C::TScalar s0 = this->m_RGC->Gets0( );
+       typename C::TPoint p0 = this->m_RGC->Axis( s0 );
+       typename C::TPoint p1 = this->m_RGC->Axis( s0 + len );
+
+       info->Set(
+       vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX( ),
+       double( p0[ 0 ] ), double( p1[ 0 ] ),
+       double( p0[ 1 ] ), double( p1[ 1 ] ),
+       double( p0[ 2 ] ), double( p1[ 2 ] )
+       );
+    */
+
+  } // fi
+  return( 1 );
+}
+
+#endif //  __CPEXTENSIONS__VISUALIZATION__IMAGEINDEXESCONTAINERTOPOLYDATA__HXX__
+
+// eof - $RCSfile$