]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/LineSource.cxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / Visualization / LineSource.cxx
1 #include <cpExtensions/Visualization/LineSource.h>
2 #include <vtkInformation.h>
3 #include <vtkInformationVector.h>
4
5 // -------------------------------------------------------------------------
6 cpExtensions::Visualization::LineSource::
7 Self* cpExtensions::Visualization::LineSource::
8 New( )
9 {
10   return( new Self( ) );
11 }
12
13 // -------------------------------------------------------------------------
14 void cpExtensions::Visualization::LineSource::
15 SetPoint1( float pnt[ 3 ] )
16 {
17   double p[ 3 ];
18   p[ 0 ] = pnt[ 0 ];
19   p[ 1 ] = pnt[ 1 ];
20   p[ 2 ] = pnt[ 2 ];
21   this->SetPoint1( p );
22 }
23
24 // -------------------------------------------------------------------------
25 void cpExtensions::Visualization::LineSource::
26 SetPoint2( float pnt[ 3 ] )
27 {
28   double p[ 3 ];
29   p[ 0 ] = pnt[ 0 ];
30   p[ 1 ] = pnt[ 1 ];
31   p[ 2 ] = pnt[ 2 ];
32   this->SetPoint2( p );
33 }
34
35 // -------------------------------------------------------------------------
36 cpExtensions::Visualization::LineSource::
37 LineSource( )
38   : Superclass( )
39 {
40   this->SetNumberOfInputPorts( 0 );
41   this->Point1[ 0 ] = -double( 0.5 );
42   this->Point1[ 1 ] =  double( 0.0 );
43   this->Point1[ 2 ] =  double( 0.0 );
44   this->Point2[ 0 ] =  double( 0.5 );
45   this->Point2[ 1 ] =  double( 0.0 );
46   this->Point2[ 2 ] =  double( 0.0 );
47 }
48
49 // -------------------------------------------------------------------------
50 cpExtensions::Visualization::LineSource::
51 ~LineSource( )
52 {
53 }
54
55 // -------------------------------------------------------------------------
56 int cpExtensions::Visualization::LineSource::
57 RequestData(
58   vtkInformation* request,
59   vtkInformationVector** inputVector,
60   vtkInformationVector* outputVector
61   )
62 {
63   // Get output object
64   vtkInformation* outInfo = outputVector->GetInformationObject( 0 );
65   vtkPolyData* output =
66     vtkPolyData::SafeDownCast(
67       outInfo->Get( vtkDataObject::DATA_OBJECT( ) )
68       );
69
70   // Create points
71   vtkPoints* points = vtkPoints::New( );
72   points->SetDataType( VTK_FLOAT );
73   points->Allocate( 2 );
74
75   // Create cells
76   vtkCellArray* verts = vtkCellArray::New( );
77   vtkCellArray* lines = vtkCellArray::New( );
78   vtkCellArray* faces = vtkCellArray::New( );
79   vtkCellArray* strips = vtkCellArray::New( );
80   lines->Allocate( lines->EstimateSize( 2, 2 ) );
81
82   // Assign points
83   points->InsertPoint( 0, this->Point1 );
84   points->InsertPoint( 1, this->Point2 );
85
86   // Assign cells
87   vtkIdType cell_pts[ 2 ] = { 0, 1 };
88   lines->InsertNextCell( 2, cell_pts );
89
90   // Assign to output
91   output->SetPoints( points );
92   output->SetVerts( verts );
93   output->SetLines( lines );
94   output->SetPolys( faces );
95   output->SetStrips( strips );
96
97   // Finish and return
98   points->Delete( );
99   verts->Delete( );
100   lines->Delete( );
101   faces->Delete( );
102   strips->Delete( );
103   return( 1 );
104 }
105
106 // -------------------------------------------------------------------------
107 int cpExtensions::Visualization::LineSource::
108 RequestInformation(
109   vtkInformation* request,
110   vtkInformationVector** inputVector,
111   vtkInformationVector* outputVector
112   )
113 {
114   vtkInformation* outInfo = outputVector->GetInformationObject( 0 );
115   outInfo->Set( CAN_HANDLE_PIECE_REQUEST(), 1 );
116   return( 1 );
117 }
118
119 // eof - $RCSfile$