for( auto l = lines.begin( ); l != lines.end( ); ++l )
{
auto pos = l->find_first_not_of( " " );
- char cmd = std::tolower( ( *l )[ pos ] );
+ char cmd = tolower( ( *l )[ pos ] );
commands[ cmd ].push_back(
l->substr( l->find_first_not_of( " ", pos + 1 ) )
);
return( true );
}
+// -------------------------------------------------------------------------
+void cpPlugins::BaseObjects::Widget::
+EnabledOn( )
+{
+ this->SetEnabled( true );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::BaseObjects::Widget::
+EnabledOff( )
+{
+ this->SetEnabled( false );
+}
+
// -------------------------------------------------------------------------
cpPlugins::BaseObjects::Widget::
Widget( )
virtual bool IsInteractive( ) cpPlugins_OVERRIDE;
+ virtual void EnabledOn( );
+ virtual void EnabledOff( );
+ virtual void Clear( ) = 0;
+ virtual void SetEnabled( bool v ) = 0;
+
protected:
Widget( );
virtual ~Widget( );
return( NULL );
}
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Workspace::
+TWidget* cpPlugins::Interface::Workspace::
+GetWidget( const std::string& name )
+{
+ TProcess* process = this->GetFilter( name );
+ return( dynamic_cast< TWidget* >( process ) );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Workspace::
+TWidget* cpPlugins::Interface::Workspace::
+GetWidget( const std::string& name ) const
+{
+ const TProcess* process = this->GetFilter( name );
+ return( dynamic_cast< const TWidget* >( process ) );
+}
+
// -------------------------------------------------------------------------
bool cpPlugins::Interface::Workspace::
HasFilter( const std::string& name ) const
return( this->m_Filters.find( name ) != this->m_Filters.end( ) );
}
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Workspace::
+HasWidget( const std::string& name ) const
+{
+ const TWidget* wdg = this->GetWidget( name );
+ return( wdg != NULL );
+}
+
// -------------------------------------------------------------------------
cpPlugins::Interface::Workspace::
TProcess* cpPlugins::Interface::Workspace::
#include <cpPlugins/Interface/Plugins.h>
#include <cpPlugins/BaseObjects/DataObject.h>
#include <cpPlugins/BaseObjects/ProcessObject.h>
+#include <cpPlugins/BaseObjects/Widget.h>
#include <itkObject.h>
class vtkRenderWindowInteractor;
typedef itk::SmartPointer< const Self > ConstPointer;
typedef cpPlugins::BaseObjects::ProcessObject TProcess;
+ typedef cpPlugins::BaseObjects::Widget TWidget;
typedef cpPlugins::Interface::Plugins TInterface;
typedef std::map< std::string, TProcess::Pointer > TFilters;
const TProcess* GetFilter(
const std::string& name
) const;
+ TWidget* GetWidget(
+ const std::string& name
+ );
+ const TWidget* GetWidget(
+ const std::string& name
+ ) const;
bool HasFilter( const std::string& name ) const;
+ bool HasWidget( const std::string& name ) const;
TProcess* CreateFilter(
const std::string& category,
const std::string& filter,
--- /dev/null
+#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$
--- /dev/null
+#ifndef __cpPluginsWidgets__LineWidget__h__
+#define __cpPluginsWidgets__LineWidget__h__
+
+#include <plugins/cpPluginsWidgets_Export.h>
+#include <cpPlugins/BaseObjects/Widget.h>
+#include <set>
+
+// -------------------------------------------------------------------------
+class vtkImageData;
+class vtkProp;
+
+// -------------------------------------------------------------------------
+namespace cpPluginsWidgets
+{
+ /**
+ */
+ class cpPluginsWidgets_EXPORT LineWidget
+ : public cpPlugins::BaseObjects::Widget
+ {
+ cpPluginsObject( LineWidget, cpPlugins::BaseObjects::Widget, Widgets );
+
+ public:
+ virtual void Clear( ) cpPlugins_OVERRIDE;
+ virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE;
+
+ protected:
+ typedef std::set< vtkProp* > TProps;
+ typedef std::map< vtkRenderWindowInteractor*, TProps > TValidProps;
+
+ protected:
+ TValidProps _GetValidActors( vtkObject* source );
+ void _GD_Image( vtkImageData* image );
+ };
+
+} // ecapseman
+
+#endif // __cpPluginsWidgets__LineWidget__h__
+
+// eof - $RCSfile$
#include <vtkRenderWindow.h>
#include <vtkSeedRepresentation.h>
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SeedWidget::
+Clear( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SeedWidget::
+SetEnabled( bool v )
+{
+}
+
// -------------------------------------------------------------------------
cpPluginsWidgets::SeedWidget::
SeedWidget( )
typedef cpExtensions::Interaction::ImageSlicePointPlacer TPlacer;
typedef cpExtensions::Visualization::WindowLevelImageActor TImageActor;
+ public:
+ virtual void Clear( ) cpPlugins_OVERRIDE;
+ virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE;
+
protected:
/**
*/
#include <vtkRenderer.h>
#include <vtkSplineWidget.h>
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SplineWidget::
+Clear( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SplineWidget::
+SetEnabled( bool v )
+{
+ auto wdg = this->GetVTK< vtkSplineWidget >( );
+ if( wdg != NULL )
+ {
+ wdg->SetEnabled( v );
+ wdg->GetInteractor( )->Render( );
+
+ } // fi
+}
+
// -------------------------------------------------------------------------
cpPluginsWidgets::SplineWidget::
SplineWidget( )
if( this->m_Configured )
{
wdg->GetPolyData( this->m_Contour.GetPointer( ) );
- wdg->Off( );
}
else
{
);
wdg->SetHandleSize( 0.005 );
wdg->SetNumberOfHandles( 3 );
- wdg->On( );
this->m_Configured = true;
} // fi
{
cpPluginsObject( SplineWidget, cpPlugins::BaseObjects::Widget, Widgets );
+ public:
+ virtual void Clear( ) cpPlugins_OVERRIDE;
+ virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE;
+
protected:
bool m_Configured;
vtkSmartPointer< vtkPolyData > m_Contour;