]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/PolyLineParametricPathToPolyData.cxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / Visualization / PolyLineParametricPathToPolyData.cxx
1 #include <cpExtensions/Visualization/PolyLineParametricPathToPolyData.h>
2
3 #include <vtkCellArray.h>
4 #include <vtkInformation.h>
5 #include <vtkInformationVector.h>
6 #include <vtkSmartPointer.h>
7
8 // -------------------------------------------------------------------------
9 template< class _TPolyLine >
10 typename
11 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
12 Self*
13 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
14 New( )
15 {
16   return( new Self( ) );
17 }
18
19 // -------------------------------------------------------------------------
20 template< class _TPolyLine >
21 const typename
22 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
23 TPolyLine*
24 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
25 GetInput( ) const
26 {
27   return( this->m_PolyLine );
28 }
29
30 // -------------------------------------------------------------------------
31 template< class _TPolyLine >
32 void
33 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
34 SetInput( const TPolyLine* pl )
35 {
36   if( this->m_PolyLine != pl )
37   {
38     this->m_PolyLine = pl;
39     this->Modified( );
40
41   } // fi
42 }
43
44 // -------------------------------------------------------------------------
45 template< class _TPolyLine >
46 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
47 PolyLineParametricPathToPolyData( )
48   : vtkPolyDataAlgorithm( ),
49     m_PolyLine( NULL )
50 {
51   this->SetNumberOfInputPorts( 0 );
52 }
53
54 // -------------------------------------------------------------------------
55 template< class _TPolyLine >
56 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
57 ~PolyLineParametricPathToPolyData( )
58 {
59 }
60
61 // -------------------------------------------------------------------------
62 template< class _TPolyLine >
63 int
64 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
65 RequestData(
66   vtkInformation* information,
67   vtkInformationVector** input,
68   vtkInformationVector* output
69   )
70 {
71   static const unsigned int dim = _TPolyLine::PathDimension;
72
73   if( this->m_PolyLine == NULL )
74     return( 0 );
75
76   // Get output
77   vtkInformation* info = output->GetInformationObject( 0 );
78   vtkPolyData* out = vtkPolyData::SafeDownCast(
79     info->Get( vtkDataObject::DATA_OBJECT( ) )
80     );
81
82   // Prepare data
83   out->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
84   out->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
85   out->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
86   out->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
87   out->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
88   vtkPoints* points = out->GetPoints( );
89   vtkCellArray* lines = out->GetLines( );
90
91   // Get data
92   for( unsigned long i = 0; i < this->m_PolyLine->GetSize( ); ++i )
93   {
94     typename _TPolyLine::TPoint pnt = this->m_PolyLine->GetPoint( i );
95     if( dim == 1 )      points->InsertNextPoint( pnt[ 0 ], 0, 0 );
96     else if( dim == 2 ) points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], 0 );
97     else                points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
98     if( i > 0 )
99     {
100       lines->InsertNextCell( 2 );
101       lines->InsertCellPoint( i - 1 );
102       lines->InsertCellPoint( i );
103
104     } // fi
105
106   } // rof
107   return( 1 );
108 }
109
110 // -------------------------------------------------------------------------
111 template< class _TPolyLine >
112 int
113 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
114 RequestInformation(
115   vtkInformation* information,
116   vtkInformationVector** input,
117   vtkInformationVector* output
118   )
119 {
120   return( 1 );
121 }
122
123 // -------------------------------------------------------------------------
124 #include <cpExtensions/DataStructures/PolyLineParametricPath.h>
125
126 template class cpExtensions::Visualization::PolyLineParametricPathToPolyData< cpExtensions::DataStructures::PolyLineParametricPath< 1 > >;
127 template class cpExtensions::Visualization::PolyLineParametricPathToPolyData< cpExtensions::DataStructures::PolyLineParametricPath< 2 > >;
128 template class cpExtensions::Visualization::PolyLineParametricPathToPolyData< cpExtensions::DataStructures::PolyLineParametricPath< 3 > >;
129 template class cpExtensions::Visualization::PolyLineParametricPathToPolyData< cpExtensions::DataStructures::PolyLineParametricPath< 4 > >;
130
131 // eof - $RCSfile$