]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/PolyLineParametricPathToPolyDataFilter.hxx
7dd4cb1793f3fa523a90fc25ca58a16065cd701b
[FrontAlgorithms.git] / lib / fpa / Image / PolyLineParametricPathToPolyDataFilter.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #ifndef __fpa__Image__PolyLineParametricPathToPolyDataFilter__hxx__
7 #define __fpa__Image__PolyLineParametricPathToPolyDataFilter__hxx__
8
9 #ifdef USE_VTK
10 #  include <vtkCellArray.h>
11 #  include <vtkInformation.h>
12 #  include <vtkInformationVector.h>
13 #  include <vtkPointData.h>
14 #  include <vtkUnsignedIntArray.h>
15 #  include <vtkSmartPointer.h>
16 #endif // USE_VTK
17
18 // -------------------------------------------------------------------------
19 template< class _TPolyLineParametricPath >
20 typename fpa::Image::PolyLineParametricPathToPolyDataFilter< _TPolyLineParametricPath >::
21 Self* fpa::Image::PolyLineParametricPathToPolyDataFilter< _TPolyLineParametricPath >::
22 New( )
23 {
24   return( new Self( ) );
25 }
26
27 // -------------------------------------------------------------------------
28 template< class _TPolyLineParametricPath >
29 const typename
30 fpa::Image::PolyLineParametricPathToPolyDataFilter< _TPolyLineParametricPath >::
31 TPolyLineParametricPath* fpa::Image::PolyLineParametricPathToPolyDataFilter< _TPolyLineParametricPath >::
32 GetInput( ) const
33 {
34   return( this->m_PolyLineParametricPath );
35 }
36
37 // -------------------------------------------------------------------------
38 template< class _TPolyLineParametricPath >
39 void fpa::Image::PolyLineParametricPathToPolyDataFilter< _TPolyLineParametricPath >::
40 SetInput( const TPolyLineParametricPath* path )
41 {
42   if( this->m_PolyLineParametricPath != path )
43   {
44     this->m_PolyLineParametricPath = path;
45 #ifdef USE_VTK
46     this->Modified( );
47 #endif // USE_VTK
48
49   } // fi
50 }
51
52 // -------------------------------------------------------------------------
53 template< class _TPolyLineParametricPath >
54 fpa::Image::PolyLineParametricPathToPolyDataFilter< _TPolyLineParametricPath >::
55 PolyLineParametricPathToPolyDataFilter( )
56 #ifdef USE_VTK
57   : vtkPolyDataAlgorithm( ),
58     m_PolyLineParametricPath( NULL )
59 #endif // USE_VTK
60 {
61 #ifdef USE_VTK
62   this->SetNumberOfInputPorts( 0 );
63 #endif // USE_VTK
64 }
65
66 // -------------------------------------------------------------------------
67 template< class _TPolyLineParametricPath >
68 fpa::Image::PolyLineParametricPathToPolyDataFilter< _TPolyLineParametricPath >::
69 ~PolyLineParametricPathToPolyDataFilter( )
70 {
71 }
72
73 #ifdef USE_VTK
74 // -------------------------------------------------------------------------
75 template< class _TPolyLineParametricPath >
76 int fpa::Image::PolyLineParametricPathToPolyDataFilter< _TPolyLineParametricPath >::
77 RequestData(
78   vtkInformation* information,
79   vtkInformationVector** input,
80   vtkInformationVector* output
81   )
82 {
83   static const unsigned int dim = TPolyLineParametricPath::PathDimension;
84   if( this->m_PolyLineParametricPath == NULL )
85     return( 0 );
86
87   // Get output
88   vtkInformation* info = output->GetInformationObject( 0 );
89   vtkPolyData* out = vtkPolyData::SafeDownCast(
90     info->Get( vtkDataObject::DATA_OBJECT( ) )
91     );
92
93   // Prepare data
94   out->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
95   out->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
96   out->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
97   out->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
98   out->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
99   vtkSmartPointer< vtkUnsignedIntArray > darray =
100     vtkSmartPointer< vtkUnsignedIntArray >::New( );
101   darray->SetNumberOfComponents( 1 );
102   out->GetPointData( )->SetScalars( darray );
103   vtkPoints* points = out->GetPoints( );
104   vtkCellArray* lines = out->GetLines( );
105
106   // Assign all data
107   const TPolyLineParametricPath* path = this->GetInput( );
108   for( unsigned long i = 0; i < path->GetSize( ); ++i )
109   {
110     auto pnt = path->GetPoint( i );
111     if( dim == 1 )
112       points->InsertNextPoint( pnt[ 0 ], 0, 0 );
113     else if( dim == 2 )
114       points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], 0 );
115     else
116       points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
117     darray->InsertNextTuple1( double( i ) );
118     if( i > 0 )
119     {
120       lines->InsertNextCell( 2 );
121       lines->InsertCellPoint( points->GetNumberOfPoints( ) - 2 );
122       lines->InsertCellPoint( points->GetNumberOfPoints( ) - 1 );
123
124     } // fi
125
126   } // rof
127   return( 1 );
128 }
129
130 // -------------------------------------------------------------------------
131 template< class _TPolyLineParametricPath >
132 int fpa::Image::PolyLineParametricPathToPolyDataFilter< _TPolyLineParametricPath >::
133 RequestInformation(
134   vtkInformation* information,
135   vtkInformationVector** input,
136   vtkInformationVector* output
137   )
138 {
139   return( 1 );
140 }
141 #endif // USE_VTK
142
143 #endif // __fpa__Image__PolyLineParametricPathToPolyDataFilterFilter__hxx__
144
145 // eof - $RCSfile$