]> Creatis software - cpPlugins.git/commitdiff
WARNING: It does not compile yet git status!
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 6 Oct 2015 23:05:03 +0000 (18:05 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 6 Oct 2015 23:05:03 +0000 (18:05 -0500)
CMakeLists.txt
appli/examples/CMakeLists.txt
appli/examples/example_BaseInteractorStyle.cxx [new file with mode: 0644]
lib/cpExtensions/Visualization/BaseInteractorStyle.cxx [new file with mode: 0644]
lib/cpExtensions/Visualization/BaseInteractorStyle.h [new file with mode: 0644]
lib/cpPlugins/Interface/Instances_itkImage.cxx
lib/cpPlugins/Interface/Object.cxx
lib/cpPlugins/Interface/Object.h

index 797b910181a8bb3916e337d60f784520e85b3cf7..c15e1286d6f72ea8aa4a09aa2ed9595b83fca595 100644 (file)
@@ -47,6 +47,17 @@ ENDIF(BUILD_SHARED_LIBRARIES)
 ## = Packages and options =
 ## ========================
 
+INCLUDE(CheckCXXCompilerFlag)
+CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
+CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
+IF(COMPILER_SUPPORTS_CXX11)
+  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+ELSEIF(COMPILER_SUPPORTS_CXX0X)
+  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+ELSE()
+  MESSAGE(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
+ENDIF()
+
 # Prepare header to build shared libs (windows)
 INCLUDE(GenerateExportHeader)
 
index 8d8a49fa3680a2d0968dd7e0731293df9824387f..794346030772213185f36ca56d19bfa0b3c8620f 100644 (file)
@@ -33,6 +33,7 @@ ENDFOREACH(prog)
 
 SET(
   NOPLUGINS_EXAMPLES_PROGRAMS
+  example_BaseInteractorStyle
   example_ContourWidget
   example_Test_DoubleClick
   ## example_ExtractDICOMSeries
diff --git a/appli/examples/example_BaseInteractorStyle.cxx b/appli/examples/example_BaseInteractorStyle.cxx
new file mode 100644 (file)
index 0000000..8ec545a
--- /dev/null
@@ -0,0 +1,39 @@
+
+#include <vtkSmartPointer.h>
+
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+#include <cpExtensions/Visualization/BaseInteractorStyle.h>
+
+int main( int argc, char* argv[] )
+{
+  // Configure visualization objects
+  vtkSmartPointer< vtkRenderer > renderer =
+    vtkSmartPointer< vtkRenderer >::New( );
+  renderer->SetBackground( 0.1, 0.3, 0.5 );
+
+  vtkSmartPointer< vtkRenderWindow > window =
+    vtkSmartPointer< vtkRenderWindow >::New( );
+  window->AddRenderer( renderer );
+  window->SetSize( 600, 600 );
+
+  // Set up interaction style
+  typedef cpExtensions::Visualization::BaseInteractorStyle TInteractorStyle;
+  vtkSmartPointer< TInteractorStyle > style =
+    vtkSmartPointer< TInteractorStyle >::New( );
+
+  // Set up the interaction
+  vtkSmartPointer< vtkRenderWindowInteractor > interactor =
+    vtkSmartPointer< vtkRenderWindowInteractor >::New( );
+  interactor->SetInteractorStyle( style );
+  window->SetInteractor( interactor );
+
+  // Begin interaction
+  window->Render( );
+  interactor->Start( );
+
+  return( 0 );
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpExtensions/Visualization/BaseInteractorStyle.cxx b/lib/cpExtensions/Visualization/BaseInteractorStyle.cxx
new file mode 100644 (file)
index 0000000..bf395a8
--- /dev/null
@@ -0,0 +1,236 @@
+#include <cpExtensions/Visualization/BaseInteractorStyle.h>
+
+/*
+  Compile ITK and VTK with: cmake -DCMAKE_CXX_FLAGS="-std=c++11" /dir/to/source
+*/
+/*
+  typedef std::chrono::time_point< std::chrono::system_clock > TTime;
+  typedef std::chrono::duration< long, std::ratio< 1, 1000 > > TTimeDiff;
+*/
+
+#include <chrono>
+
+#include <vtkCallbackCommand.h>
+
+// -------------------------------------------------------------------------
+/*
+  const cpExtensions::Visualization::BaseInteractorStyle::TTime
+  cpExtensions::Visualization::BaseInteractorStyle::MinTime =
+  cpExtensions::Visualization::BaseInteractorStyle::TTime::min( );
+*/
+
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::BaseInteractorStyle::
+Self* cpExtensions::Visualization::BaseInteractorStyle::
+New( )
+{
+  return( new Self );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+DelegateTDxEvent( unsigned long event, void* calldata )
+{
+  // TODO
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::BaseInteractorStyle::
+BaseInteractorStyle( )
+  : Superclass( )
+{
+  this->LastButton = Self::ButtonID_None;
+  this->LastButtonUp = 0;
+  this->LastButtonHeld = 0;
+  this->LastButtonDown = -1;
+  this->EventCallbackCommand->SetCallback( Self::_ProcessEvents );
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::BaseInteractorStyle::
+~BaseInteractorStyle( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+_ProcessEvents(
+  vtkObject* object,
+  unsigned long event,
+  void* clientdata,
+  void* calldata
+  )
+{
+  // Get active style
+  Self* s = reinterpret_cast< Self* >( clientdata );
+  if( s == NULL )
+    return;
+
+  // Process events
+  switch( event )
+  {
+  case vtkCommand::MouseMoveEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::MouseMoveEvent ) )
+      s->InvokeEvent( vtkCommand::MouseMoveEvent, NULL );
+    else
+      s->OnMouseMove( );
+  }
+  break;
+  case vtkCommand::LeftButtonPressEvent:
+  {
+    /*
+    if( s->LastButton != Self::ButtonID_Left )
+    {
+      s->LastButton = Self::ButtonID_Left;
+      s->LastButtonClicks = 1;
+      s->LastButtonTime = std::chrono::system_clock::now( );
+    }
+    else if( s->LastButton == Self::ButtonID_Left )
+      s->LastButtonClicks++;
+    */
+  }
+  break;
+  case vtkCommand::LeftButtonReleaseEvent:
+  {
+    long count =
+      std::chrono::duration_cast< std::chrono::milliseconds >(
+        std::chrono::system_clock::now( )
+        ).count( );
+    s->LastButtonUp = count;
+    s->LastButtonHeld = count - s->LastButtonDown;
+    s->LastButtonDown = -1;
+
+    /*
+    if( s->LastButton == Self::ButtonID_Left )
+    {
+      long d = std::chrono::duration_cast< std::chrono::milliseconds >(
+        std::chrono::system_clock::now( ) - s->LastButtonTime
+        ).count( );
+      if( d < 500 )
+      {
+      } // fi
+
+    } // fi
+    */
+  }
+  break;
+  case vtkCommand::MiddleButtonPressEvent:
+  {
+  }
+  break;
+  case vtkCommand::MiddleButtonReleaseEvent:
+  {
+  }
+  break;
+  case vtkCommand::RightButtonPressEvent:
+  {
+  }
+  break;
+  case vtkCommand::RightButtonReleaseEvent:
+  {
+  }
+  break;
+  case vtkCommand::MouseWheelForwardEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::MouseWheelForwardEvent ) )
+      s->InvokeEvent( vtkCommand::MouseWheelForwardEvent, NULL );
+    else
+      s->OnMouseWheelForward( );
+  }
+  break;
+  case vtkCommand::MouseWheelBackwardEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::MouseWheelBackwardEvent ) )
+      s->InvokeEvent( vtkCommand::MouseWheelBackwardEvent, NULL );
+    else
+      s->OnMouseWheelBackward( );
+  }
+  break;
+  case vtkCommand::KeyPressEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::KeyPressEvent ) )
+      s->InvokeEvent( vtkCommand::KeyPressEvent, NULL );
+    else
+    {
+      s->OnKeyDown( );
+      s->OnKeyPress( );
+
+    } // fi
+  }
+  break;
+  case vtkCommand::KeyReleaseEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::KeyReleaseEvent ) )
+      s->InvokeEvent( vtkCommand::KeyReleaseEvent, NULL );
+    else
+    {
+      s->OnKeyUp( );
+      s->OnKeyRelease( );
+
+    } // fi
+  }
+  break;
+  case vtkCommand::CharEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::CharEvent ) )
+      s->InvokeEvent( vtkCommand::CharEvent, NULL );
+    else
+      s->OnChar( );
+  }
+  break;
+  case vtkCommand::ExposeEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::ExposeEvent ) )
+      s->InvokeEvent( vtkCommand::ExposeEvent, NULL );
+    else
+      s->OnExpose( );
+  }
+  break;
+  case vtkCommand::ConfigureEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::ConfigureEvent ) )
+      s->InvokeEvent( vtkCommand::ConfigureEvent, NULL );
+    else
+      s->OnConfigure( );
+  }
+  break;
+  case vtkCommand::EnterEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::EnterEvent ) )
+      s->InvokeEvent( vtkCommand::EnterEvent, NULL );
+    else
+      s->OnEnter( );
+  }
+  break;
+  case vtkCommand::LeaveEvent:
+  {
+    if( s->HandleObservers && s->HasObserver( vtkCommand::LeaveEvent ) )
+      s->InvokeEvent( vtkCommand::LeaveEvent, NULL );
+    else
+      s->OnLeave( );
+  }
+  break;
+  case vtkCommand::TimerEvent:
+  {
+    // Do nothing
+  }
+  break;
+  case vtkCommand::DeleteEvent:
+  {
+    s->SetInteractor( 0 );
+  }
+  break;
+  case vtkCommand::TDxMotionEvent:
+  case vtkCommand::TDxButtonPressEvent:
+  case vtkCommand::TDxButtonReleaseEvent:
+  {
+    s->DelegateTDxEvent( event, calldata );
+  }
+  break;
+  default:
+    break;
+  } // hctiws
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpExtensions/Visualization/BaseInteractorStyle.h b/lib/cpExtensions/Visualization/BaseInteractorStyle.h
new file mode 100644 (file)
index 0000000..849e386
--- /dev/null
@@ -0,0 +1,118 @@
+#ifndef __CPEXTENSIONS__VISUALIZATION__BASEINTERACTORSTYLE__H__
+#define __CPEXTENSIONS__VISUALIZATION__BASEINTERACTORSTYLE__H__
+
+#include <cpExtensions/cpExtensions_Export.h>
+
+#include <vtkInteractorStyle.h>
+
+namespace cpExtensions
+{
+  namespace Visualization
+  {
+    /**
+     */
+    class cpExtensions_EXPORT BaseInteractorStyle
+      : public vtkInteractorStyle
+    {
+    public:
+      typedef BaseInteractorStyle Self;
+      vtkTypeMacro( BaseInteractorStyle, vtkInteractorStyle );
+
+      enum ButtonID
+      {
+        ButtonID_None   = 0x00,
+        ButtonID_Left   = 0x01,
+        ButtonID_Middle = 0x02,
+        ButtonID_Right  = 0x03
+      };
+
+    public:
+      static Self* New( );
+
+      void DelegateTDxEvent( unsigned long event, void* calldata );
+
+      // Possible mouse motion events
+      virtual void OnMouseMove( ) { }
+      virtual void OnMouseWheelForward( ) { }
+      virtual void OnMouseWheelBackward( ) { }
+
+      // Possible mouse click-related events
+      virtual void OnLeftButtonDown( ) { }
+      virtual void OnLeftButtonUp( ) { }
+      virtual void OnLeftClick( ) { }
+      virtual void OnLeftDoubleClick( ) { }
+      virtual void OnMiddleButtonDown( ) { }
+      virtual void OnMiddleButtonUp( ) { }
+      virtual void OnMiddleClick( ) { }
+      virtual void OnMiddleDoubleClick( ) { }
+      virtual void OnRightButtonDown( ) { }
+      virtual void OnRightButtonUp( ) { }
+      virtual void OnRightClick( ) { }
+      virtual void OnRightDoubleClick( ) { }
+
+      // Keyboard-related events
+      virtual void OnChar( ) { }
+      virtual void OnKeyDown( ) { }
+      virtual void OnKeyUp( ) { }
+      virtual void OnKeyPress( ) { }
+      virtual void OnKeyRelease( ) { }
+
+      // Other events
+      virtual void OnExpose( ) { }
+      virtual void OnConfigure( ) { }
+      virtual void OnEnter( ) { }
+      virtual void OnLeave( ) { }
+
+      // Unused methods
+      inline void StartState( int newstate ) { }
+      inline void StopState( ) { }
+      inline void StartAnimate( ) { }
+      inline void StopAnimate( ) { }
+      inline void StartRotate( ) { }
+      inline void EndRotate( ) { }
+      inline void StartZoom( ) { }
+      inline void EndZoom( ) { }
+      inline void StartPan( ) { }
+      inline void EndPan( ) { }
+      inline void StartSpin( ) { }
+      inline void EndSpin( ) { }
+      inline void StartDolly( ) { }
+      inline void EndDolly( ) { }
+      inline void StartUniformScale( ) { }
+      inline void EndUniformScale( ) { }
+      inline void StartTimer( ) { }
+      inline void EndTimer( ) { }
+      inline void StartTwoPointer( ) { }
+      inline void EndTwoPointer( ) { }
+      inline void OnTimer( ) { }
+
+    protected:
+      BaseInteractorStyle( );
+      virtual ~BaseInteractorStyle( );
+
+      static void _ProcessEvents(
+        vtkObject* object,
+        unsigned long event,
+        void* clientdata,
+        void* calldata
+        );
+
+    private:
+      // Purposely not implemented
+      BaseInteractorStyle( const Self& );
+      Self& operator=( const Self& );
+
+    protected:
+      ButtonID LastButton;
+      long LastButtonUp;
+      long LastButtonHeld;
+      long LastButtonDown;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPEXTENSIONS__VISUALIZATION__BASEINTERACTORSTYLE__H__
+
+// eof - $RCSfile$
index b9229dd4849ea8f9b05c99b27755e301cfe40945..855c2f673903beb144b5c7c4dcac09dfacad26ba 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <complex>
 
+#undef ITK_MANUAL_INSTANTIATION
 #include <itkImage.h>
 #include <itkImageToVTKImageFilter.h>
 
index b4768faab5971f845db0c385bf7bddb7d74b7383..4ca6286c25c8b1049d8f01922e296fe906b76026 100644 (file)
@@ -5,8 +5,6 @@ cpPlugins::Interface::Object::
 Object( )
   : Superclass( )
 {
-  this->m_ClassName = "cpPlugins::Interface::Object";
-  this->m_ClassCategory = "BasicObject";
 }
 
 // -------------------------------------------------------------------------
index 6e273f174264f5fe3ea7f822c5254a76102557e8..5b0ebd6de87f9e79dd152d6465e3d1043ab06187 100644 (file)
@@ -51,6 +51,12 @@ public:                                                         \
     }                                                                   \
   };
 
+// -------------------------------------------------------------------------
+#define cpPlugins_Id_Macro( name, category )                            \
+  public:                                                               \
+  static std::string GetClassName( ) { return( #name ); }               \
+  static std::string GetClassCategory( ) { return( category ); }
+
 namespace cpPlugins
 {
   namespace Interface
@@ -69,10 +75,10 @@ namespace cpPlugins
     public:
       itkNewMacro( Self );
       itkTypeMacro( Object, itkObject );
+      cpPlugins_Id_Macro( cpPlugins::Interface::Object, "BaseObject" );
 
-    public:
-      itkGetConstMacro( ClassName, std::string );
-      itkGetConstMacro( ClassCategory, std::string );
+      itkGetStringMacro( Name );
+      itkSetStringMacro( Name );
 
     protected:
       Object( );
@@ -84,8 +90,7 @@ namespace cpPlugins
       Self& operator=( const Self& );
 
     protected:
-      std::string m_ClassName;
-      std::string m_ClassCategory;
+      std::string m_Name;
     };
 
     /**