1 #ifndef __CPEXTENSIONS__VISUALIZATION__POLYLINEPARAMETRICPATHTOPOLYDATA__HXX__
2 #define __CPEXTENSIONS__VISUALIZATION__POLYLINEPARAMETRICPATHTOPOLYDATA__HXX__
4 #include <vtkCellArray.h>
5 #include <vtkInformation.h>
6 #include <vtkInformationVector.h>
7 #include <vtkSmartPointer.h>
9 // -------------------------------------------------------------------------
10 template< class _TPolyLine >
12 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
14 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
17 return( new Self( ) );
20 // -------------------------------------------------------------------------
21 template< class _TPolyLine >
23 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
25 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
28 return( this->m_PolyLine );
31 // -------------------------------------------------------------------------
32 template< class _TPolyLine >
34 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
36 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
37 GetReferenceImage( ) const
39 return( this->m_ReferenceImage );
42 // -------------------------------------------------------------------------
43 template< class _TPolyLine >
45 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
46 SetInput( const TPolyLine* pl )
48 if( this->m_PolyLine != pl )
50 this->m_PolyLine = pl;
56 // -------------------------------------------------------------------------
57 template< class _TPolyLine >
59 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
60 SetReferenceImage( const TImage* i )
62 if( this->m_ReferenceImage != i )
64 this->m_ReferenceImage = i;
70 // -------------------------------------------------------------------------
71 template< class _TPolyLine >
72 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
73 PolyLineParametricPathToPolyData( )
74 : vtkPolyDataAlgorithm( ),
76 m_ReferenceImage( NULL )
78 this->SetNumberOfInputPorts( 0 );
81 // -------------------------------------------------------------------------
82 template< class _TPolyLine >
83 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
84 ~PolyLineParametricPathToPolyData( )
88 // -------------------------------------------------------------------------
89 template< class _TPolyLine >
91 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
93 vtkInformation* information,
94 vtkInformationVector** input,
95 vtkInformationVector* output
98 static const unsigned int dim = _TPolyLine::PathDimension;
100 if( this->m_PolyLine == NULL )
104 vtkInformation* info = output->GetInformationObject( 0 );
105 vtkPolyData* out = vtkPolyData::SafeDownCast(
106 info->Get( vtkDataObject::DATA_OBJECT( ) )
110 auto lst = this->m_PolyLine->GetVertexList( );
113 vtkPoints* points = out->GetPoints( );
116 points = vtkPoints::New( );
117 out->SetPoints( points );
121 points->SetNumberOfPoints( lst->Size( ) );
125 vtkSmartPointer< vtkCellArray > verts =
126 vtkSmartPointer< vtkCellArray >::New( );
128 vtkSmartPointer< vtkCellArray > lines =
129 vtkSmartPointer< vtkCellArray >::New( );
131 for( unsigned int i = 0; i < lst->Size( ); ++i )
133 auto idx = lst->GetElement( i );
134 if( this->m_ReferenceImage != NULL )
136 typename TImage::PointType pnt;
137 this->m_ReferenceImage->TransformContinuousIndexToPhysicalPoint( idx, pnt );
139 points->SetPoint( i, pnt[ 0 ], 0, 0 );
141 points->SetPoint( i, pnt[ 0 ], pnt[ 1 ], 0 );
143 points->SetPoint( i, pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
148 points->SetPoint( i, idx[ 0 ], 0, 0 );
150 points->SetPoint( i, idx[ 0 ], idx[ 1 ], 0 );
152 points->SetPoint( i, idx[ 0 ], idx[ 1 ], idx[ 2 ] );
156 verts->InsertNextCell( 1 );
157 verts->InsertCellPoint( i );
161 lines->InsertNextCell( 2 );
162 lines->InsertCellPoint( i - 1 );
163 lines->InsertCellPoint( i );
168 out->SetPoints( points );
169 // TODO: out->SetVerts( verts );
170 out->SetLines( lines );
174 // -------------------------------------------------------------------------
175 template< class _TPolyLine >
177 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
179 vtkInformation* information,
180 vtkInformationVector** input,
181 vtkInformationVector* output
184 vtkInformation* info = output->GetInformationObject( 0 );
187 vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES( ), -1
191 if( this->m_PolyLine != NULL && this->m_ReferenceImage != NULL )
194 typename C::TScalar len = this->m_RGC->GetTotalLength( );
195 typename C::TScalar s0 = this->m_RGC->Gets0( );
196 typename C::TPoint p0 = this->m_RGC->Axis( s0 );
197 typename C::TPoint p1 = this->m_RGC->Axis( s0 + len );
200 vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX( ),
201 double( p0[ 0 ] ), double( p1[ 0 ] ),
202 double( p0[ 1 ] ), double( p1[ 1 ] ),
203 double( p0[ 2 ] ), double( p1[ 2 ] )
211 #endif // __CPEXTENSIONS__VISUALIZATION__POLYLINEPARAMETRICPATHTOPOLYDATA__HXX__