+#include <plugins/Widgets/LineWidget.h>
+#include <cpPlugins/DataObjects/Image.h>
+#include <cpPlugins/DataObjects/Mesh.h>
+#include <cpExtensions/Visualization/WindowLevelImageActor.h>
+
+#include <vtkLineWidget2.h>
+#include <vtkImageData.h>
+#include <vtkImageMapper3D.h>
+#include <vtkInteractorObserver.h>
+#include <vtkLineRepresentation.h>
+#include <vtkMapper.h>
+#include <vtkRenderer.h>
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::LineWidget::
+Clear( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::LineWidget::
+SetEnabled( bool v )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPluginsWidgets::LineWidget::
+LineWidget( )
+ : Superclass( )
+{
+ typedef cpPlugins::BaseObjects::DataObject _TData;
+ typedef cpPlugins::DataObjects::Mesh _TMesh;
+
+ this->_ConfigureInput< _TData >( "Input", false, false );
+ this->_ConfigureOutput< _TMesh >( "Output" );
+ auto line = vtkSmartPointer< vtkPolyData >::New( );
+ line->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
+ line->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
+ line->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
+ line->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
+ line->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
+ this->GetOutput( "Output" )->SetVTK( line );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsWidgets::LineWidget::
+~LineWidget( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::LineWidget::
+_GenerateData( )
+{
+ if( this->m_Interactors.size( ) == 0 )
+ this->_Error( "Give at least one valid interactor." );
+
+ auto image = this->GetInputData< vtkImageData >( "Input" );
+ if( image != NULL ) this->_GD_Image( image );
+ else this->_Error( "Do not know how to create this widget." );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsWidgets::LineWidget::
+TValidProps cpPluginsWidgets::LineWidget::
+_GetValidActors( vtkObject* source )
+{
+ TValidProps valid_props;
+ auto iIt = this->m_Interactors.begin( );
+ 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 image_actor = dynamic_cast< vtkImageSlice* >( prop );
+ auto mesh_actor = dynamic_cast< vtkActor* >( prop );
+ vtkObject* input = NULL;
+ if( image_actor != NULL )
+ {
+ auto mapper = image_actor->GetMapper( );
+ if( mapper != NULL )
+ input = mapper->GetInput( );
+ }
+ else if( mesh_actor != NULL )
+ {
+ auto mapper = mesh_actor->GetMapper( );
+ if( mapper != NULL )
+ input = mapper->GetInput( );
+
+ } // fi
+ if( input != NULL )
+ valid_props[ *iIt ].insert( prop );
+
+ } // elihw
+
+ } // fi
+
+ } // fi
+
+ } // rof
+ return( valid_props );
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::LineWidget::
+_GD_Image( vtkImageData* image )
+{
+ auto valid_props = this->_GetValidActors( image );
+ if( valid_props.size( ) == 0 )
+ this->_Error( "Given image does not have a valid associated actor." );
+
+ vtkSmartPointer< vtkLineWidget2 > wdg = this->GetVTK< vtkLineWidget2 >( );
+ if( wdg.GetPointer( ) == NULL )
+ {
+ auto rep = vtkSmartPointer< vtkLineRepresentation >::New( );
+
+ /* TODO
+ p[ 0 ] = 0.0; p[ 1 ] = -1.0; p[ 2 ] = 0.0;
+ rep->SetPoint1WorldPosition( p );
+ p[ 0 ] = 0.0; p[ 1 ] = 1.0; p[ 2 ] = 0.0;
+ rep->SetPoint2WorldPosition( p );
+ rep->PlaceWidget( pl3d_block0->GetBounds( ) );
+ rep->GetPolyData( seeds );
+ rep->DistanceAnnotationVisibilityOn( );
+ */
+
+ wdg = this->_CreateVTK< vtkLineWidget2 >( );
+ wdg->SetInteractor( valid_props.begin( )->first );
+ wdg->SetRepresentation( rep );
+ wdg->EnabledOn( );
+ }
+ else
+ dynamic_cast< vtkLineRepresentation* >( wdg->GetRepresentation( ) )->
+ GetPolyData( this->GetOutputData< vtkPolyData >( "Output" ) );
+}
+
+// eof - $RCSfile$