]> Creatis software - cpPlugins.git/blobdiff - plugins/VTKWidgets/SplineWidget.cxx
Moved to version 1.0
[cpPlugins.git] / plugins / VTKWidgets / SplineWidget.cxx
diff --git a/plugins/VTKWidgets/SplineWidget.cxx b/plugins/VTKWidgets/SplineWidget.cxx
deleted file mode 100644 (file)
index 5f82c7e..0000000
+++ /dev/null
@@ -1,253 +0,0 @@
-#include <VTKWidgets/SplineWidget.h>
-#include <cpInstances/DataObjects/Image.h>
-#include <cpInstances/DataObjects/Mesh.h>
-#include <cpExtensions/Visualization/WindowLevelImageActor.h>
-
-#include <itkVector.h>
-
-#include <vtkImageData.h>
-#include <vtkPolyData.h>
-#include <vtkRenderer.h>
-#include <vtkSplineWidget.h>
-#include <vtkParametricSpline.h>
-
-// -------------------------------------------------------------------------
-void cpPluginsVTKWidgets::SplineWidget::
-Clear( )
-{
-}
-
-// -------------------------------------------------------------------------
-void cpPluginsVTKWidgets::SplineWidget::
-SetEnabled( bool v )
-{
-  auto wdg = this->GetVTK< vtkSplineWidget >( );
-  if( wdg != NULL )
-  {
-    wdg->SetEnabled( v );
-    wdg->GetInteractor( )->Render( );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-bool cpPluginsVTKWidgets::SplineWidget::
-GetEnabled( ) const
-{
-  auto wdg = this->GetVTK< const vtkSplineWidget >( );
-  if( wdg != NULL )
-  {
-    vtkSplineWidget* w = const_cast< vtkSplineWidget* >( wdg );
-    return( w->GetEnabled( ) != 0 );
-  }
-  else
-    return( false );
-}
-
-// -------------------------------------------------------------------------
-cpPluginsVTKWidgets::SplineWidget::
-SplineWidget( )
-  : Superclass( ),
-    m_Configured( false )
-{
-  typedef cpPlugins::Pipeline::DataObject _TData;
-  typedef cpInstances::DataObjects::Mesh       _TMesh;
-
-  this->_ConfigureInput< _TData >( "Input", false, false );
-  this->_ConfigureOutput< _TMesh >( "Output" );
-  this->m_Contour = vtkSmartPointer< vtkPolyData >::New( );
-  this->m_Contour->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
-  this->m_Contour->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
-  this->m_Contour->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
-  this->m_Contour->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
-  this->m_Contour->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
-  this->GetOutput( "Output" )->SetVTK( this->m_Contour );
-
-  this->m_Parameters.ConfigureAsBool( "Extend", false );
-}
-
-// -------------------------------------------------------------------------
-cpPluginsVTKWidgets::SplineWidget::
-~SplineWidget( )
-{
-}
-
-// -------------------------------------------------------------------------
-void cpPluginsVTKWidgets::SplineWidget::
-_GenerateData( )
-{
-  typedef cpExtensions::Visualization::WindowLevelImageActor _TActor;
-
-  auto image = this->GetInputData< vtkImageData >( "Input" );
-  if( image == NULL )
-    this->_Error( "Invalid input image." );
-  if( this->m_Interactors.size( ) == 0 )
-    this->_Error( "Give at least one interactor." );
-
-  auto wdg = this->_CreateVTK< vtkSplineWidget >( );
-  if( this->m_Configured )
-  {
-    if( this->m_Parameters.GetBool( "Extend" ) )
-    {
-      wdg->GetPolyData( this->m_Contour.GetPointer( ) );
-
-      typedef itk::Vector< double, 3 > _TVector;
-      typedef std::vector< _TVector > _TVectors;
-
-      unsigned long nPoints = this->m_Contour->GetNumberOfPoints( );
-      unsigned long support = nPoints / 10;
-      _TVectors pp, qp;
-      for( unsigned long i = 0; i < support; ++i )
-      {
-        double p[ 3 ], q[ 3 ];
-        this->m_Contour->GetPoint( i, p );
-        this->m_Contour->GetPoint( nPoints - 1 - i, q );
-
-        _TVector pv, qv;
-        pv[ 0 ] = p[ 0 ];
-        pv[ 1 ] = p[ 1 ];
-        pv[ 2 ] = p[ 2 ];
-        qv[ 0 ] = q[ 0 ];
-        qv[ 1 ] = q[ 1 ];
-        qv[ 2 ] = q[ 2 ];
-        pp.push_back( pv );
-        qp.push_back( qv );
-
-      } // rof
-
-      _TVectors pt, qt;
-      pt.push_back( pp[ 1 ] - pp[ 0 ] );
-      qt.push_back( qp[ 1 ] - qp[ 0 ] );
-      for( unsigned long i = 1; i < support - 1; ++i )
-      {
-        pt.push_back( pp[ i + 1 ] - pp[ i - 1 ] );
-        qt.push_back( qp[ i + 1 ] - qp[ i - 1 ] );
-
-      } // rof
-      pt.push_back( pp[ support - 1 ] - pp[ support - 2 ] );
-      qt.push_back( qp[ support - 1 ] - qp[ support - 2 ] );
-
-      _TVector t0( double( 0 ) ), t1( double( 0 ) );
-      long real0 = 0, real1 = 0;
-      for( unsigned long i = 0; i < support; ++i )
-      {
-        double n0 = pt[ i ].GetNorm( );
-        if( n0 > double( 0 ) )
-        {
-          t0 += pt[ i ] / n0;
-          real0++;
-
-        } // fi
-
-        double n1 = qt[ i ].GetNorm( );
-        if( n1 > double( 0 ) )
-        {
-          t1 += qt[ i ] / n1;
-          real1++;
-
-        } // fi
-
-      } // rof
-
-      if( real0 > 0 )
-        t0 /= double( -real0 );
-      if( real1 > 0 )
-        t1 /= double( -real1 );
-
-      t0 *= ( pp[ 0 ] - qp[ 0 ] ).GetNorm( );
-      t1 *= ( pp[ 0 ] - qp[ 0 ] ).GetNorm( );
-
-      _TVector p0 = pp[ 0 ] + t0;
-      _TVector p1 = qp[ 0 ] + t1;
-
-      vtkSmartPointer< vtkPolyData > cnt = this->m_Contour;
-      this->m_Contour = vtkSmartPointer< vtkPolyData >::New( );
-      this->m_Contour->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
-      this->m_Contour->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
-      this->m_Contour->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
-      this->m_Contour->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
-      this->m_Contour->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
-      this->GetOutput( "Output" )->SetVTK( this->m_Contour );
-
-      this->m_Contour->GetPoints( )->
-        InsertNextPoint( p0[ 0 ], p0[ 1 ], p0[ 2 ] );
-      for( unsigned long i = 0; i < nPoints; ++i )
-      {
-        double p[ 3 ];
-        cnt->GetPoints( )->GetPoint( i, p );
-        this->m_Contour->GetPoints( )->InsertNextPoint( p );
-
-      } // rof
-      this->m_Contour->GetPoints( )->
-        InsertNextPoint( p1[ 0 ], p1[ 1 ], p1[ 2 ] );
-      this->m_Contour->Modified( );
-    }
-    else
-      wdg->GetPolyData( this->m_Contour.GetPointer( ) );
-  }
-  else
-  {
-    auto iIt = this->m_Interactors.begin( );
-    vtkRenderWindowInteractor* iren = NULL;
-    vtkRenderer* ren = NULL;
-    _TActor* actor = NULL;
-    for( ; iIt != this->m_Interactors.end( ); ++iIt )
-    {
-      auto r = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
-      if( r != NULL )
-      {
-        auto props = r->GetViewProps( );
-        if( props != NULL )
-        {
-          props->InitTraversal( );
-          while( vtkProp* prop = props->GetNextProp( ) )
-          {
-            auto a = dynamic_cast< _TActor* >( prop );
-            if( a != NULL )
-              if( a->GetImage( ) == image )
-              {
-                iren = *iIt;
-                actor = a;
-                ren = r;
-
-              } // fi
-
-          } // elihw
-
-        } // fi
-
-      } // fi
-
-    } // rof
-    if( actor == NULL || ren == NULL || iren == NULL )
-      this->_Error( "Invalid actor and/or renderer." );
-
-    // Widget configuration
-    wdg->SetCurrentRenderer( ren );
-    wdg->SetDefaultRenderer( ren );
-    wdg->SetInputData( image );
-    wdg->SetProp3D( actor );
-    wdg->SetInteractor( iren );
-    double bnds[ 6 ];
-    image->GetBounds( bnds );
-    wdg->PlaceWidget(
-      bnds[ 0 ], bnds[ 1 ],
-      bnds[ 2 ], bnds[ 3 ],
-      bnds[ 4 ], bnds[ 5 ]
-      );
-    wdg->ProjectToPlaneOn( );
-    wdg->SetProjectionNormalToZAxes( );
-    wdg->SetProjectionPosition(
-      (
-        actor->GetBounds( )[ 4 ] +
-        actor->GetBounds( )[ 5 ]
-        ) / double( 2 )
-      );
-    wdg->SetHandleSize( 0.005 );
-    wdg->SetNumberOfHandles( 3 );
-    this->m_Configured = true;
-
-  } // fi
-}
-
-// eof - $RCSfile$