]> Creatis software - cpPlugins.git/commitdiff
sphere widget update
authorJose Luis Guzman <cycopepe@gmail.com>
Wed, 4 Nov 2015 13:55:45 +0000 (14:55 +0100)
committerJose Luis Guzman <cycopepe@gmail.com>
Wed, 4 Nov 2015 13:55:45 +0000 (14:55 +0100)
appli/ImageMPR/CMakeLists.txt
appli/examples/CMakeLists.txt
appli/examples/example_SphereWidget.cxx
lib/cpExtensions/Interaction/SphereWidget.cxx
lib/cpExtensions/Interaction/SphereWidget.h

index 7d3c3d85d2bddfefbbd290372175a2b9b08d6873..3a9ab89bd1331fba9cb86a0fc8cbf0c307753c3b 100644 (file)
@@ -277,10 +277,10 @@ include(InstallRequiredSystemLibraries)
 set(CPACK_PACKAGE_NAME "cpPluginsMprViewer")
 set(CPACK_PACKAGE_VENDOR "Creatis & Pontificia Universidad Javeriana")
 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "cpPlugins - MPR-Viewer")
-set(CPACK_PACKAGE_VERSION "0.0.2")
+set(CPACK_PACKAGE_VERSION "0.0.3")
 set(CPACK_PACKAGE_VERSION_MAJOR "0")
 set(CPACK_PACKAGE_VERSION_MINOR "0")
-set(CPACK_PACKAGE_VERSION_PATCH "2")
+set(CPACK_PACKAGE_VERSION_PATCH "3")
 set(CPACK_PACKAGE_INSTALL_DIRECTORY "MPR-Viewer")
 
 install(TARGETS ImageMPR
index 8a9d5dfc262615fd906595826fdd8e7dccc3084b..79d2338f00d2db3dd0e5b9c69ddd05a8aca81018 100644 (file)
@@ -59,7 +59,7 @@ SET(
   NOPLUGINS_EXAMPLES_PROGRAMS
   example_BaseInteractorStyle
   
-  ##example_ContourWidget
+  example_ContourWidget
   ##example_Test_async
   ## example_MacheteFilter
   ## example_Test_DoubleClick
index 4079b3a3edbd8c7f701c81b2e437b61cd43ed0d9..db3626f4f9298af27b3d5c6eac7a5a57ddfbcbf0 100644 (file)
@@ -14,6 +14,8 @@
 #include <vtkSphere.h>
 #include <vtkSphereRepresentation.h>
 #include <vtkSphereWidget2.h>
+#include <vtkCommand.h>
+#include <vtkCallbackCommand.h>
 
 // -------------------------------------------------------------------------
 // type definiftions
@@ -33,6 +35,27 @@ typedef cpExtensions::Interaction::SphereWidget       TSphereWidget;
 std::string _pathIOplugin = "C://dev//creatis//cpPlugins//build//Debug//cpPluginsIO.dll";
 std::string _img = "C://img//SphereVolume.mhd";
 
+vtkSmartPointer<cpExtensions::Visualization::ImageSliceActors> image_actors;
+
+void WheelCallbackFunction(vtkObject* caller, long unsigned int eventId, void* clientData, void* vtkNotUsed(callData))
+{
+  std::cout << "WheelCallbackFunction callback" << std::endl;
+
+  vtkSmartPointer<TSphereWidget> sphere =
+    reinterpret_cast<TSphereWidget*>(clientData);
+
+ // double * center = image_actors->GetImageActor()->GetCenter();
+  double * center = image_actors->GetPlaneActor()->GetCenter();
+  auto slice = image_actors->GetSliceNumber();
+  std::cout << "plane: [" << center[0] << " , " << center[1] + slice << " , " << (center[2] + 19)*(-1) << "] " << std::endl;
+  std::cout << "slice #. " << slice <<std::endl;
+
+  sphere->SetCenter(center);
+  
+}
+
+
+
 int main(int argc, char* argv[])
 {
   if (argc >= 3)
@@ -92,8 +115,7 @@ int main(int argc, char* argv[])
   window->SetInteractor(interactor);
 
   // Create slice actors
-  vtkSmartPointer< TSliceActors > image_actors =
-    vtkSmartPointer< TSliceActors >::New();
+  image_actors = vtkSmartPointer< TSliceActors >::New();
   image_actors->AddInputData(image->GetVTK< vtkImageData >());
   image_actors->SetAxis(2);
   image_actors->PushActorsInto(window);
@@ -106,14 +128,18 @@ int main(int argc, char* argv[])
   vtkSmartPointer<TSphereWidget> sphereWidget =
     vtkSmartPointer<TSphereWidget>::New();
   sphereWidget->SetInteractor(interactor);
-//  sphereWidget->CreateDefaultRepresentation();
 
- /* vtkSphereRepresentation* sphereRepresentation =
-    vtkSphereRepresentation::SafeDownCast(sphereWidget->GetRepresentation());
-  sphereRepresentation->HandleVisibilityOn();*/
+  vtkSmartPointer<vtkCallbackCommand> myCallBack =
+    vtkSmartPointer<vtkCallbackCommand>::New();
+  myCallBack->SetCallback(WheelCallbackFunction);
+  myCallBack->SetClientData(sphereWidget);
+  
+  interactor->AddObserver(vtkCommand::MouseWheelForwardEvent, myCallBack);
+  interactor->AddObserver(vtkCommand::MouseWheelBackwardEvent, myCallBack);
 
   // Begin interaction
-  renderer->ResetCamera();
+  renderer->ResetCamera(); 
   window->Render();
   sphereWidget->On();
   interactor->Start();
index 07d778f84041a39e58e8308ff12dcf697c38b9aa..0b944654f0915fd173ce77d050a0c77001d9cb98 100644 (file)
@@ -10,6 +10,7 @@
 #include <vtkSphereRepresentation.h>
 #include <vtkSmartPointer.h>
 #include <vtkSphere.h>
+#include <vtkProperty.h>
 
 // -------------------------------------------------------------------------
 cpExtensions::Interaction::SphereWidget::
@@ -26,10 +27,10 @@ SetInteractor(vtkRenderWindowInteractor* rwi)
   this->Superclass::SetInteractor(rwi);
   TBaseStyle* s = dynamic_cast<TBaseStyle*>(rwi->GetInteractorStyle());
   if (s != NULL)
-  {
-    s->AddMouseClickCommand(Self::_Click, this);
-    //s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
+  {    
     s->AddKeyCommand(Self::_KeyPress, this);
+    s->AddMouseMoveCommand(Self::_MouseMove, this);
+
   } // fi
 }
 
@@ -38,25 +39,13 @@ cpExtensions::Interaction::SphereWidget::
 SphereWidget()
 : Superclass()
 {
-  /*vtkSmartPointer<vtkself> self =
-    vtkself::SafeDownCast(this->GetRepresentation());*/
-
-  //self->SetHandleSize(0);
-  //self->SetRadialLine(2);
+  this->SetTranslation(0);
   this->SetRadius(7);
-  
+
   this->SetPhiResolution(10);
   this->SetThetaResolution(20);
 
-  //self->HandleVisibilityOff();
-  //self->SetHandleText(0);
   this->SetRepresentationToWireframe();
-
-  // Remove default translations
-  /* vtkWidgetEventTranslator* t = this->GetEventTranslator();
-   t->RemoveTranslation(vtkCommand::LeftButtonPressEvent);
-   t->RemoveTranslation(vtkCommand::MiddleButtonPressEvent);
-   t->RemoveTranslation(vtkCommand::RightButtonPressEvent);*/
 }
 
 // -------------------------------------------------------------------------
@@ -73,24 +62,9 @@ int* idx, double* pos, bool alt, bool ctr, bool sft
 )
 {
   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
-  self->Superclass::StartInteraction();
-  self->InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
-  //if( self->WidgetState == vtkSphereWidget2::MovingSeed )
-  //  return;
-
-  //int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
-  //if( st == vtkSeedRepresentation::NearSeed )
-  //{
-  //  self->WidgetState = vtkSphereWidget2::MovingSeed;
-
-  //  // Invoke an event on ourself for the handles
-  //  self->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL );
-  //  self->Superclass::StartInteraction( );
-  //  self->InvokeEvent( vtkCommand::StartInteractionEvent, NULL );
-  //  self->EventCallbackCommand->SetAbortFlag( 1 );
-  //  self->Render( );
-
-  //} // fi
+  self->Superclass::EndInteraction();
+
+
 }
 
 // -------------------------------------------------------------------------
@@ -103,82 +77,105 @@ int* idx, double* pos, bool alt, bool ctr, bool sft
 
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::SphereWidget::
+_MouseMove(
+void* data, const TBaseStyle::ButtonID& button,
+int* idx, double* pos, bool alt, bool ctr, bool sft
+)
+{
+  /*SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
+  self->Superclass::StartInteraction();*/
+}
+
+void cpExtensions::Interaction::SphereWidget::SetCenter(double * center)
+{
+  this->Superclass::SetCenter(center);
+  this->SphereActor->SetPosition(center);
+  this->SphereActor->Modified();
+  this->GetInteractor()->Render();
+}
+
+void cpExtensions::Interaction::SphereWidget::SetCenter(void* data, double * center)
+{
+  SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
+  
+  self->Superclass::SetCenter(center);
+  self->SphereActor->SetPosition(center);
+  self->SphereActor->Modified();
+
+  std::cout << "sphere: {" << center[0] << " , " << center[1] << " , " << center[2] + 19 << "} " << std::endl;
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key)
 {
   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
+  self->Superclass::StartInteraction();
+
+  double * center = self->GetCenter();
 
-  double handlePosition[3];
- /* vtkself* self =
-    vtkself::SafeDownCast(self->GetRepresentation());
-  */
-  auto center = self->GetCenter();
-  auto center2 = self->GetCenter();
   auto radius = self->GetRadius();
 
-  self->Superclass::StartInteraction();
   switch (key)
   {
   case 122: // Z & z
   case 90:
     radius += 0.1;
-    //self->SetRadius(radius);
+   
     break;
   case 88:  // X & x
   case 120:
     radius -= 0.1;
-    //self->SetRadius(radius);
+   
     break;
   case 119: // W & w
   case 87:
     center[0] += 1;
-    self->Translate(center, center2);
+   
     break;
   case 83: // S & s
-  case 115: 
+  case 115:
     center[0] -= 1;
-    self->Translate(center, center2);
+   
     break;
   case 65: // A & a
   case 97:
     center[1] += 1;
-    self->SetCenter(center);
+   
     break;
   case 100: // D & d
   case 68:
     center[1] -= 1;
-    self->SetCenter(center);
+   
     break;
   case 81: // Q & q
   case 113:
     center[2] += 1;
-    self->SetCenter(center);
+  
     break;
   case 69: // E & e
   case 101:
     center[2] -= 1;
-    self->SetCenter(center);
+  
     break;
 
   default:
     break;
   }
 
-  self->SetRadius(radius);
-  self->Translate(center, center2);
-
-  vtkSmartPointer<vtkSphere> sphere = vtkSmartPointer<vtkSphere>::New();
-  
 
-  self->InvokeEvent(vtkCommand::ModifiedEvent, NULL);
-  
+  self->SetRadius(radius);
+  self->SetCenter(data, center);
   self->Modified();
   self->GetInteractor()->Render();
-  self->ReleaseFocus();
+  self->EndInteraction();
 }
 
 
 
 
 
+
+
 // eof - $RCSfile$
index 11ce916c814bc236c29c3345b67b0fe8b0ff4e04..b1a11bdf485c4dfbd629780f2282e8318f1c8976 100644 (file)
@@ -26,7 +26,7 @@ namespace cpExtensions
       static Self* New( );
 
       virtual void SetInteractor( vtkRenderWindowInteractor* rwi );
-
+      void SetCenter(double* center);
       
 
     protected:
@@ -41,8 +41,15 @@ namespace cpExtensions
         void* data, const TBaseStyle::ButtonID& button,
         int* idx, double* pos, bool alt, bool ctr, bool sft
         );
+      static void _MouseMove(
+        void* data, const TBaseStyle::ButtonID& button,
+        int* idx, double* pos, bool alt, bool ctr, bool sft
+        );
+     
       static void _KeyPress(void* data, const char& key);
        
+      static void SetCenter(void* data, double* center);
+
     private:
       // Purposely not implemented
       SphereWidget( const Self& );