vtk_image->SetInput( input_image );
vtk_image->Update( );
- /* TODO
- vtkSmartPointer< vtkSphereSource > seed =
- vtkSmartPointer< vtkSphereSource >::New( );
- seed->SetCenter( seed_pnt[ 0 ], seed_pnt[ 1 ], seed_pnt[ 2 ] );
- seed->SetRadius( min_spac * double( 5 ) );
- seed->Update( );
- */
-
fpa::VTK::ImageMPR view;
view.SetBackground( 0.3, 0.2, 0.8 );
view.SetSize( 800, 800 );
view.SetImage( vtk_image->GetOutput( ) );
- // TODO: view.AddPolyData( seed->GetOutput( ), 1, 0, 0 );
- view.Start( );
+
+ // Wait for a seed to be given
+ while( view.GetNumberOfSeeds( ) == 0 )
+ view.Start( );
+
+ // Convert seed
+ double seed[ 3 ];
+ view.GetSeed( 0, seed );
+ TImage::PointType seed_pnt;
+ seed_pnt[ 0 ] = seed[ 0 ];
+ seed_pnt[ 1 ] = seed[ 1 ];
+ seed_pnt[ 2 ] = seed[ 2 ];
+ TImage::IndexType seed_idx;
+ input_image->TransformPhysicalPointToIndex( seed_pnt, seed_idx );
// Configure observer
- /* TODO
- TObserver::Pointer obs = TObserver::New( );
- obs->SetImage( input_image, view.GetWindow( ) );
-
- // Configure algorithm
- TFrontAlgorithm::Pointer algorithm = TFrontAlgorithm::New( );
- algorithm->AddThresholds( thr_0, thr_1, n_samples );
-
- TImage::IndexType seed_idx;
- input_image->TransformPhysicalPointToIndex( seed_pnt, seed_idx );
- algorithm->AddSeed( seed_idx, 0 );
-
- algorithm->AddObserver( itk::AnyEvent( ), obs );
- algorithm->ThrowEventsOn( );
- algorithm->SetInput( input_image );
- algorithm->SetNeighborhoodOrder( 1 );
- algorithm->SetDerivativeThreshold( double( 3 ) );
- algorithm->Update( );
-
- view.Start( );
- */
+ TObserver::Pointer obs = TObserver::New( );
+ obs->SetImage( input_image, view.GetWindow( ) );
+
+ // Configure algorithm
+ TFrontAlgorithm::Pointer algorithm = TFrontAlgorithm::New( );
+ algorithm->AddThresholds( thr_0, thr_1, n_samples );
+ algorithm->AddSeed( seed_idx, 0 );
+ algorithm->AddObserver( itk::AnyEvent( ), obs );
+ algorithm->ThrowEventsOn( );
+ algorithm->SetInput( input_image );
+ algorithm->SetNeighborhoodOrder( 1 );
+ algorithm->SetDerivativeThreshold( double( 3 ) );
+ algorithm->Update( );
+
+ // Let some interaction and close program
+ view.Start( );
return( 0 );
}
void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
_BeforeLoop( )
{
- this->_BeforeLoop( );
+ this->Superclass::_BeforeLoop( );
this->m_ActualFunction = this->m_Functions.begin( );
}
{
*/
TPixel v = img->GetPixel( idx );
+ std::cout
+ << v << " "
+ << this->m_LowerThreshold << " "
+ << this->m_UpperThreshold << std::endl;
return(
- this->m_LowerThreshold <= v &&
- v <= this->m_UpperThreshold
+ this->m_LowerThreshold <= v && v < this->m_UpperThreshold
);
// TODO: } // fi
#define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__H__
#include <map>
+#include <set>
#include <fpa/Image/RegionGrowWithMultipleCriteria.h>
+#include <fpa/Image/Functors/RegionGrowThresholdFunction.h>
namespace fpa
{
typedef typename Superclass::TMembershipFunction TMembershipFunction;
typedef typename Superclass::TFunctions TFunctions;
+ typedef std::set< TPixel > TThresholds;
+ typedef fpa::Image::Functors::RegionGrowThresholdFunction< I > TFunction;
+
protected:
typedef typename TBaseAlgorithm::_TNode _TNode;
void operator=( const Self& ); // Not impl.
protected:
+ TThresholds m_Thresholds;
double m_DerivativeThreshold;
THistogram m_Histogram;
};
#define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
#include <limits>
-#include <fpa/Image/Functors/RegionGrowThresholdFunction.h>
// -------------------------------------------------------------------------
template< class I >
void fpa::Image::RegionGrowWithMultipleThresholds< I >::
AddThreshold( const TPixel& v )
{
- typedef
- fpa::Image::Functors::RegionGrowThresholdFunction< I >
- TFunction;
- typename TFunction::Pointer function = TFunction::New( );
-
- if( this->GetNumberOfMembershipFunctions( ) > 0 )
- {
- }
- else
- function->SetLowerThreshold( std::numeric_limits< TPixel >::min( ) );
- std::cout
- << typeid( TPixel ).name( ) << " <<<----->>> "
- << function->GetLowerThreshold( )
- << std::endl;
- std::exit( 1 );
- function->SetUpperThreshold( v );
- this->AddMembershipFunction( function );
-
- /* TODO
- this->m_Histogram[ v ] = 0;
-
- TFunction* function =
- dynamic_cast< TFunction* >( this->GetMembershipFunction( ) );
- if( function != NULL )
- {
- function->SetLowerThreshold( this->m_Histogram.begin( )->first );
-
- } // fi
- this->Modified( );
- */
+ this->m_Thresholds.insert( v );
+ this->Modified( );
}
// -------------------------------------------------------------------------
_UpdateResult( _TNode& n )
{
bool ret = this->Superclass::_UpdateResult( n );
+ std::cout << "Image:UpdateResult " << ret << std::endl;
+
/* TODO
if( ret )
{
void fpa::Image::RegionGrowWithMultipleThresholds< I >::
_BeforeLoop( )
{
- std::cout << "**1" << std::endl;
const I* img = this->GetInput( );
- std::cout << "**2" << std::endl;
- typename TFunctions::iterator fIt = this->m_Functions.begin( );
- for( ; fIt != this->m_Functions.end( ); ++fIt )
+
+ this->ClearMembershipFunctions( );
+ typename TThresholds::const_iterator tIt = this->m_Thresholds.begin( );
+ typename TThresholds::const_iterator prev_tIt = tIt;
+ for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt, ++prev_tIt )
{
- TMembershipFunction* f =
- dynamic_cast< TMembershipFunction* >( fIt->GetPointer( ) );
- if( f != NULL )
- f->SetInputImage( this->GetInput( ) );
+ typename TFunction::Pointer function = TFunction::New( );
+ function->SetInputImage( img );
+ function->SetLowerThreshold( *prev_tIt );
+ function->SetUpperThreshold( *tIt );
+ this->AddMembershipFunction( function );
+ std::cout << *prev_tIt << " " << *tIt << std::endl;
} // rof
+
this->Superclass::_BeforeLoop( );
}
#include <vtkCommand.h>
#include <vtkInteractorStyleSwitch.h>
-#include <vtkPickingManager.h>
-class vtkUpdateCallback
+#include <fpa/VTK/SeedWidgetCorrector.h>
+
+/**
+ */
+class fpa_VTK_InteractionModeCallback
: public vtkCommand
{
public:
- static vtkUpdateCallback *New()
+ static fpa_VTK_InteractionModeCallback* New( )
{
- return new vtkUpdateCallback;
+ return( new fpa_VTK_InteractionModeCallback );
}
- virtual void Execute(vtkObject *caller, unsigned long eventId, void*
- arguments)
+ virtual void Execute(
+ vtkObject* caller, unsigned long eventId, void* arguments )
{
- vtkRenderWindowInteractor* iren =
- static_cast< vtkRenderWindowInteractor* >( caller );
- if( caller == NULL )
- return;
-
- switch( iren->GetKeyCode( ) )
+ if( eventId == vtkCommand::KeyPressEvent )
{
- case 'x':
- case 'X':
- {
- bool eSeed = ( this->SeedWidget->GetProcessEvents( ) == 1 );
- if( eSeed )
+ vtkRenderWindowInteractor* iren =
+ static_cast< vtkRenderWindowInteractor* >( caller );
+ if( caller == NULL )
+ return;
+
+ switch( iren->GetKeyCode( ) )
{
- this->SeedWidget->ProcessEventsOff( );
- this->WidgetX->InteractionOn( );
- this->WidgetY->InteractionOn( );
- this->WidgetZ->InteractionOn( );
- }
- else
+ case 'x':
+ case 'X':
{
- this->SeedWidget->ProcessEventsOn( );
- this->WidgetX->InteractionOff( );
- this->WidgetY->InteractionOff( );
- this->WidgetZ->InteractionOff( );
-
- } // fi
- }
- break;
- default:
+ bool eSeed = ( this->SeedWidget->GetProcessEvents( ) == 1 );
+ if( eSeed )
+ {
+ this->SeedWidget->ProcessEventsOff( );
+ this->WidgetX->InteractionOn( );
+ this->WidgetY->InteractionOn( );
+ this->WidgetZ->InteractionOn( );
+ }
+ else
+ {
+ this->SeedWidget->ProcessEventsOn( );
+ this->WidgetX->InteractionOff( );
+ this->WidgetY->InteractionOff( );
+ this->WidgetZ->InteractionOff( );
+
+ } // fi
+ }
break;
+ default:
+ break;
+
+ } // hctiws
- } // hctiws
+ } // fi
}
public:
vtkImagePlaneWidget* WidgetX;
vtkImagePlaneWidget* WidgetY;
vtkImagePlaneWidget* WidgetZ;
- vtkSeedWidget2* SeedWidget;
+ vtkSeedWidget* SeedWidget;
};
// -------------------------------------------------------------------------
this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( );
this->m_Window = vtkSmartPointer< vtkRenderWindow >::New( );
this->m_Interactor = vtkSmartPointer< vtkRenderWindowInteractor >::New( );
+ this->m_SeedHandleRepresentation =
+ vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
+ this->m_SeedRepresentation =
+ vtkSmartPointer< vtkSeedRepresentation >::New( );
+ this->m_SeedWidget = vtkSmartPointer<vtkSeedWidget>::New();
-
-
-
-
-
- handlePointRep3D =
- vtkSmartPointer<vtkPointHandleRepresentation3D>::New();
- //handlePointRep3D->AllOn();
- handlePointRep3D->GetProperty()->SetColor(1.,0.,1.);
- seedRep =
- vtkSmartPointer<vtkSeedRepresentation>::New();
- seedRep->SetHandleRepresentation(handlePointRep3D);
- seedWidget = vtkSmartPointer<vtkSeedWidget2>::New();
-
- seedWidget->SetRepresentation(seedRep);
+ this->m_SeedHandleRepresentation->GetProperty()->SetColor( 1, 0, 1 );
+ this->m_SeedRepresentation->
+ SetHandleRepresentation( this->m_SeedHandleRepresentation );
+ this->m_SeedWidget->SetRepresentation( this->m_SeedRepresentation );
this->m_WidgetX->KeyPressActivationOff( );
this->m_WidgetY->KeyPressActivationOff( );
this->m_WidgetZ->KeyPressActivationOff( );
- seedWidget->KeyPressActivationOff( );
-
- // this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker );
-
-
- vtkUpdateCallback* onUpdate = vtkUpdateCallback::New();
- onUpdate->WidgetX = this->m_WidgetX;
- onUpdate->WidgetY = this->m_WidgetY;
- onUpdate->WidgetZ = this->m_WidgetZ;
- onUpdate->SeedWidget = this->seedWidget;
-
- this->m_Interactor->AddObserver(vtkCommand::KeyPressEvent, onUpdate);
+ this->m_SeedWidget->KeyPressActivationOff( );
+
+ vtkSmartPointer< fpa_VTK_InteractionModeCallback > int_cb =
+ vtkSmartPointer< fpa_VTK_InteractionModeCallback >::New( );
+ int_cb->WidgetX = this->m_WidgetX;
+ int_cb->WidgetY = this->m_WidgetY;
+ int_cb->WidgetZ = this->m_WidgetZ;
+ int_cb->SeedWidget = this->m_SeedWidget;
+ this->m_Interactor->AddObserver( vtkCommand::KeyPressEvent, int_cb );
+
+ vtkSmartPointer< fpa::VTK::SeedWidgetCorrector > corr_cb =
+ vtkSmartPointer< fpa::VTK::SeedWidgetCorrector >::New( );
+ corr_cb->Configure( this->m_Picker );
+ this->m_SeedWidget->AddObserver( vtkCommand::PlacePointEvent, corr_cb );
}
-
+
// -------------------------------------------------------------------------
fpa::VTK::ImageMPR::
~ImageMPR( )
this->m_WidgetX->SetInteractor( this->m_Interactor );
this->m_WidgetY->SetInteractor( this->m_Interactor );
this->m_WidgetZ->SetInteractor( this->m_Interactor );
- seedWidget->SetInteractor(this->m_Interactor);
+ this->m_SeedWidget->SetInteractor( this->m_Interactor );
this->m_WidgetX->On( );
this->m_WidgetY->On( );
this->m_WidgetZ->On( );
- seedWidget->On( );
- seedWidget->ProcessEventsOff( );
+ this->m_SeedWidget->On( );
+ this->m_SeedWidget->ProcessEventsOff( );
this->m_Interactor->SetPicker( this->m_Picker );
- this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker );
- this->m_Interactor->GetPickingManager( )->EnabledOn( );
+ /*
+ this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker );
+ this->m_Interactor->GetPickingManager( )->EnabledOn( );
+ */
}
// -------------------------------------------------------------------------
this->m_Renderer->AddActor( this->m_Actors[ i ] );
}
+// -------------------------------------------------------------------------
+unsigned int fpa::VTK::ImageMPR::
+GetNumberOfSeeds( ) const
+{
+ return( this->m_SeedRepresentation->GetNumberOfSeeds( ) );
+}
+
+// -------------------------------------------------------------------------
+void fpa::VTK::ImageMPR::
+GetSeed( int n, double* s ) const
+{
+ vtkHandleWidget* hWdg = this->m_SeedWidget->GetSeed( n );
+ if( hWdg == NULL )
+ return;
+ vtkHandleRepresentation* hRep =
+ dynamic_cast< vtkHandleRepresentation* >( hWdg->GetRepresentation( ) );
+ if( hRep == NULL )
+ return;
+ hRep->GetWorldPosition( s );
+}
+
// -------------------------------------------------------------------------
vtkRenderWindow* fpa::VTK::ImageMPR::
GetWindow( ) const
#include <vtkActor.h>
#include <vtkCellPicker.h>
+#include <vtkHandleWidget.h>
#include <vtkImageData.h>
#include <vtkImagePlaneWidget.h>
#include <vtkOutlineSource.h>
+#include <vtkPointHandleRepresentation3D.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
+#include <vtkSeedRepresentation.h>
+#include <vtkSeedWidget.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
-#include <vtkSeedWidget.h>
-#include <vtkSeedRepresentation.h>
-#include <vtkHandleWidget.h>
-#include <vtkPointHandleRepresentation3D.h>
-
-class vtkSeedWidget2
- : public vtkSeedWidget
-{
-public:
- // Description:
- // Instantiate this class.
- static vtkSeedWidget2 *New()
- {
- return new vtkSeedWidget2;
- }
-
- // Description:
- // Standard methods for a VTK class.
- vtkTypeMacro(vtkSeedWidget2, vtkSeedWidget);
-
- virtual vtkPickingManager* GetPickingManager( )
- {
- return( this->Superclass::GetPickingManager( ) );
- }
-
-protected:
- vtkSeedWidget2()
- : Superclass( )
- {
- }
- virtual ~vtkSeedWidget2()
- {
- }
-
-private:
- vtkSeedWidget2(const vtkSeedWidget2&); //Not implemented
- void operator=(const vtkSeedWidget2&); //Not implemented
-};
-
namespace fpa
{
namespace VTK
void AddPolyData( vtkPolyData* pd, double r, double g, double b );
+ unsigned int GetNumberOfSeeds( ) const;
+ void GetSeed( int n, double* s ) const;
+
vtkRenderWindow* GetWindow( ) const;
vtkRenderer* GetRenderer( ) const;
void Start( );
protected:
- vtkSmartPointer< vtkImageData > m_Image;
- vtkSmartPointer< vtkOutlineSource > m_Outline;
- vtkSmartPointer< vtkPolyDataMapper > m_OutlineMapper;
- vtkSmartPointer< vtkActor > m_OutlineActor;
- vtkSmartPointer< vtkCellPicker > m_Picker;
- vtkSmartPointer< vtkImagePlaneWidget > m_WidgetX;
- vtkSmartPointer< vtkImagePlaneWidget > m_WidgetY;
- vtkSmartPointer< vtkImagePlaneWidget > m_WidgetZ;
- vtkSmartPointer< vtkRenderer > m_Renderer;
- vtkSmartPointer< vtkRenderWindow > m_Window;
+ vtkSmartPointer< vtkImageData > m_Image;
+ vtkSmartPointer< vtkOutlineSource > m_Outline;
+ vtkSmartPointer< vtkPolyDataMapper > m_OutlineMapper;
+ vtkSmartPointer< vtkActor > m_OutlineActor;
+ vtkSmartPointer< vtkCellPicker > m_Picker;
+ vtkSmartPointer< vtkImagePlaneWidget > m_WidgetX;
+ vtkSmartPointer< vtkImagePlaneWidget > m_WidgetY;
+ vtkSmartPointer< vtkImagePlaneWidget > m_WidgetZ;
+ vtkSmartPointer< vtkRenderer > m_Renderer;
+ vtkSmartPointer< vtkRenderWindow > m_Window;
vtkSmartPointer< vtkRenderWindowInteractor > m_Interactor;
- std::vector< vtkSmartPointer< vtkPolyData > > m_PolyDatas;
+ std::vector< vtkSmartPointer< vtkPolyData > > m_PolyDatas;
std::vector< vtkSmartPointer< vtkPolyDataMapper > > m_Mappers;
- std::vector< vtkSmartPointer< vtkActor > > m_Actors;
-
+ std::vector< vtkSmartPointer< vtkActor > > m_Actors;
// Create the widget and its representation
- vtkSmartPointer<vtkPointHandleRepresentation3D> handlePointRep3D;
- vtkSmartPointer<vtkSeedRepresentation> seedRep;
- vtkSmartPointer<vtkSeedWidget2> seedWidget;
-
+ vtkSmartPointer< vtkPointHandleRepresentation3D >
+ m_SeedHandleRepresentation;
+ vtkSmartPointer< vtkSeedRepresentation > m_SeedRepresentation;
+ vtkSmartPointer< vtkSeedWidget > m_SeedWidget;
};
} // ecapseman
--- /dev/null
+#include <fpa/VTK/SeedWidgetCorrector.h>
+
+#include <vtkCellPicker.h>
+#include <vtkSeedWidget.h>
+
+#include <vtkHandleRepresentation.h>
+#include <vtkHandleWidget.h>
+#include <vtkRenderWindowInteractor.h>
+
+// -------------------------------------------------------------------------
+fpa::VTK::SeedWidgetCorrector*
+fpa::VTK::SeedWidgetCorrector::
+New( )
+{
+ return( new fpa::VTK::SeedWidgetCorrector );
+}
+
+// -------------------------------------------------------------------------
+void fpa::VTK::SeedWidgetCorrector::
+Configure( vtkCellPicker* picker )
+{
+ this->m_Picker = picker;
+}
+
+// -------------------------------------------------------------------------
+void fpa::VTK::SeedWidgetCorrector::
+Execute( vtkObject* caller, unsigned long eventId, void* arguments )
+{
+ vtkSeedWidget* wdg = dynamic_cast< vtkSeedWidget* >( caller );
+ if( wdg == NULL || this->m_Picker == NULL )
+ return;
+
+ if( eventId == vtkCommand::PlacePointEvent )
+ {
+ // Get newly added handle and its associated objects
+ int hId = *( reinterpret_cast< int* >( arguments ) );
+ vtkHandleWidget* hWdg = wdg->GetSeed( hId );
+ if( hWdg == NULL )
+ return;
+ vtkHandleRepresentation* hRep =
+ dynamic_cast< vtkHandleRepresentation* >( hWdg->GetRepresentation( ) );
+ if( hRep == NULL )
+ return;
+
+ // Get clicked point and 3D scene
+ double p[ 3 ];
+ hRep->GetDisplayPosition( p );
+ vtkRenderWindowInteractor* iren = wdg->GetInteractor( );
+ if( iren == NULL )
+ return;
+ vtkRenderer* ren =
+ iren->FindPokedRenderer( int( p[ 0 ] ), int( p[ 1 ] ) );
+ if( ren == NULL )
+ return;
+
+ // Correct point with given picker
+ double q[ 3 ];
+ this->m_Picker->Pick( p[ 0 ], p[ 1 ], p[ 2 ], ren );
+ this->m_Picker->GetPickPosition( q );
+ hRep->SetWorldPosition( q );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+fpa::VTK::SeedWidgetCorrector::
+SeedWidgetCorrector( )
+ : vtkCommand( ),
+ m_Picker( NULL )
+{
+}
+
+// -------------------------------------------------------------------------
+fpa::VTK::SeedWidgetCorrector::
+~SeedWidgetCorrector( )
+{
+}
+
+// eof - $RCSfile$
--- /dev/null
+#ifndef __FPA__VTK__SEEDWIDGETCORRECTOR__H__
+#define __FPA__VTK__SEEDWIDGETCORRECTOR__H__
+
+#include <fpa/FrontAlgorithms_Export.h>
+#include <vtkCommand.h>
+
+class vtkCellPicker;
+class vtkSeedWidget;
+
+namespace fpa
+{
+ namespace VTK
+ {
+ /**
+ */
+ class FrontAlgorithms_EXPORT SeedWidgetCorrector
+ : public vtkCommand
+ {
+ public:
+ static SeedWidgetCorrector* New( );
+
+ void Configure( vtkCellPicker* picker );
+
+ virtual void Execute(
+ vtkObject* caller,
+ unsigned long eventId,
+ void* arguments
+ );
+
+ protected:
+ SeedWidgetCorrector( );
+ virtual ~SeedWidgetCorrector( );
+
+ protected:
+ vtkCellPicker* m_Picker;
+ };
+
+ } // ecapseman
+
+} // ecapseman
+
+#endif // __FPA__VTK__SEEDWIDGETCORRECTOR__H__
+
+// eof - $RCSfile$