]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/LineSource.cxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / Visualization / LineSource.cxx
diff --git a/lib/cpExtensions/Visualization/LineSource.cxx b/lib/cpExtensions/Visualization/LineSource.cxx
new file mode 100644 (file)
index 0000000..6280cba
--- /dev/null
@@ -0,0 +1,119 @@
+#include <cpExtensions/Visualization/LineSource.h>
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::LineSource::
+Self* cpExtensions::Visualization::LineSource::
+New( )
+{
+  return( new Self( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::LineSource::
+SetPoint1( float pnt[ 3 ] )
+{
+  double p[ 3 ];
+  p[ 0 ] = pnt[ 0 ];
+  p[ 1 ] = pnt[ 1 ];
+  p[ 2 ] = pnt[ 2 ];
+  this->SetPoint1( p );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::LineSource::
+SetPoint2( float pnt[ 3 ] )
+{
+  double p[ 3 ];
+  p[ 0 ] = pnt[ 0 ];
+  p[ 1 ] = pnt[ 1 ];
+  p[ 2 ] = pnt[ 2 ];
+  this->SetPoint2( p );
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::LineSource::
+LineSource( )
+  : Superclass( )
+{
+  this->SetNumberOfInputPorts( 0 );
+  this->Point1[ 0 ] = -double( 0.5 );
+  this->Point1[ 1 ] =  double( 0.0 );
+  this->Point1[ 2 ] =  double( 0.0 );
+  this->Point2[ 0 ] =  double( 0.5 );
+  this->Point2[ 1 ] =  double( 0.0 );
+  this->Point2[ 2 ] =  double( 0.0 );
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::LineSource::
+~LineSource( )
+{
+}
+
+// -------------------------------------------------------------------------
+int cpExtensions::Visualization::LineSource::
+RequestData(
+  vtkInformation* request,
+  vtkInformationVector** inputVector,
+  vtkInformationVector* outputVector
+  )
+{
+  // Get output object
+  vtkInformation* outInfo = outputVector->GetInformationObject( 0 );
+  vtkPolyData* output =
+    vtkPolyData::SafeDownCast(
+      outInfo->Get( vtkDataObject::DATA_OBJECT( ) )
+      );
+
+  // Create points
+  vtkPoints* points = vtkPoints::New( );
+  points->SetDataType( VTK_FLOAT );
+  points->Allocate( 2 );
+
+  // Create cells
+  vtkCellArray* verts = vtkCellArray::New( );
+  vtkCellArray* lines = vtkCellArray::New( );
+  vtkCellArray* faces = vtkCellArray::New( );
+  vtkCellArray* strips = vtkCellArray::New( );
+  lines->Allocate( lines->EstimateSize( 2, 2 ) );
+
+  // Assign points
+  points->InsertPoint( 0, this->Point1 );
+  points->InsertPoint( 1, this->Point2 );
+
+  // Assign cells
+  vtkIdType cell_pts[ 2 ] = { 0, 1 };
+  lines->InsertNextCell( 2, cell_pts );
+
+  // Assign to output
+  output->SetPoints( points );
+  output->SetVerts( verts );
+  output->SetLines( lines );
+  output->SetPolys( faces );
+  output->SetStrips( strips );
+
+  // Finish and return
+  points->Delete( );
+  verts->Delete( );
+  lines->Delete( );
+  faces->Delete( );
+  strips->Delete( );
+  return( 1 );
+}
+
+// -------------------------------------------------------------------------
+int cpExtensions::Visualization::LineSource::
+RequestInformation(
+  vtkInformation* request,
+  vtkInformationVector** inputVector,
+  vtkInformationVector* outputVector
+  )
+{
+  vtkInformation* outInfo = outputVector->GetInformationObject( 0 );
+  outInfo->Set( CAN_HANDLE_PIECE_REQUEST(), 1 );
+  return( 1 );
+}
+
+// eof - $RCSfile$