1 #ifndef __CPEXTENSIONS__VISUALIZATION__POLYLINEPARAMETRICPATHTOPOLYDATA__HXX__
2 #define __CPEXTENSIONS__VISUALIZATION__POLYLINEPARAMETRICPATHTOPOLYDATA__HXX__
4 #include <vtkInformation.h>
5 #include <vtkInformationVector.h>
6 #include <vtkSmartPointer.h>
8 // -------------------------------------------------------------------------
9 template< class _TPolyLine >
11 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
13 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
16 return( new Self( ) );
19 // -------------------------------------------------------------------------
20 template< class _TPolyLine >
22 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
24 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
27 return( this->m_PolyLine );
30 // -------------------------------------------------------------------------
31 template< class _TPolyLine >
33 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
35 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
36 GetReferenceImage( ) const
38 return( this->m_ReferenceImage );
41 // -------------------------------------------------------------------------
42 template< class _TPolyLine >
44 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
45 SetInput( const TPolyLine* pl )
47 if( this->m_PolyLine != pl )
49 this->m_PolyLine = pl;
55 // -------------------------------------------------------------------------
56 template< class _TPolyLine >
58 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
59 SetReferenceImage( const TImage* i )
61 if( this->m_ReferenceImage != i )
63 this->m_ReferenceImage = i;
69 // -------------------------------------------------------------------------
70 template< class _TPolyLine >
71 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
72 PolyLineParametricPathToPolyData( )
73 : vtkPolyDataAlgorithm( ),
75 m_ReferenceImage( NULL )
77 this->SetNumberOfInputPorts( 0 );
80 // -------------------------------------------------------------------------
81 template< class _TPolyLine >
82 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
83 ~PolyLineParametricPathToPolyData( )
87 // -------------------------------------------------------------------------
88 template< class _TPolyLine >
90 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
92 vtkInformation* information,
93 vtkInformationVector** input,
94 vtkInformationVector* output
97 static const unsigned int dim = _TPolyLine::PathDimension;
99 if( this->m_PolyLine == NULL )
103 vtkInformation* info = output->GetInformationObject( 0 );
104 vtkPolyData* out = vtkPolyData::SafeDownCast(
105 info->Get( vtkDataObject::DATA_OBJECT( ) )
109 auto lst = this->m_PolyLine->GetVertexList( );
112 vtkPoints* points = out->GetPoints( );
115 points = vtkPoints::New( );
116 out->SetPoints( points );
120 points->SetNumberOfPoints( lst->Size( ) );
124 vtkSmartPointer< vtkCellArray > verts =
125 vtkSmartPointer< vtkCellArray >::New( );
127 vtkSmartPointer< vtkCellArray > lines =
128 vtkSmartPointer< vtkCellArray >::New( );
130 for( unsigned int i = 0; i < lst->Size( ); ++i )
132 auto idx = lst->GetElement( i );
133 if( this->m_ReferenceImage != NULL )
135 typename TImage::PointType pnt;
136 this->m_ReferenceImage->TransformContinuousIndexToPhysicalPoint( idx, pnt );
138 points->SetPoint( i, pnt[ 0 ], 0, 0 );
140 points->SetPoint( i, pnt[ 0 ], pnt[ 1 ], 0 );
142 points->SetPoint( i, pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
147 points->SetPoint( i, idx[ 0 ], 0, 0 );
149 points->SetPoint( i, idx[ 0 ], idx[ 1 ], 0 );
151 points->SetPoint( i, idx[ 0 ], idx[ 1 ], idx[ 2 ] );
155 verts->InsertNextCell( 1 );
156 verts->InsertCellPoint( i );
160 lines->InsertNextCell( 2 );
161 lines->InsertCellPoint( i - 1 );
162 lines->InsertCellPoint( i );
167 out->SetPoints( points );
168 // TODO: out->SetVerts( verts );
169 out->SetLines( lines );
173 // -------------------------------------------------------------------------
174 template< class _TPolyLine >
176 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
178 vtkInformation* information,
179 vtkInformationVector** input,
180 vtkInformationVector* output
183 vtkInformation* info = output->GetInformationObject( 0 );
186 vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES( ), -1
190 if( this->m_PolyLine != NULL && this->m_ReferenceImage != NULL )
193 typename C::TScalar len = this->m_RGC->GetTotalLength( );
194 typename C::TScalar s0 = this->m_RGC->Gets0( );
195 typename C::TPoint p0 = this->m_RGC->Axis( s0 );
196 typename C::TPoint p1 = this->m_RGC->Axis( s0 + len );
199 vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX( ),
200 double( p0[ 0 ] ), double( p1[ 0 ] ),
201 double( p0[ 1 ] ), double( p1[ 1 ] ),
202 double( p0[ 2 ] ), double( p1[ 2 ] )
210 #endif // __CPEXTENSIONS__VISUALIZATION__POLYLINEPARAMETRICPATHTOPOLYDATA__HXX__