]> Creatis software - cpPlugins.git/commitdiff
sphere widget done, finally
authorJose Luis Guzman <cycopepe@gmail.com>
Tue, 17 Nov 2015 17:39:41 +0000 (18:39 +0100)
committerJose Luis Guzman <cycopepe@gmail.com>
Tue, 17 Nov 2015 17:39:41 +0000 (18:39 +0100)
appli/examples/example_SphereWidget.cxx
lib/cpExtensions/Interaction/SphereWidget.cxx
lib/cpExtensions/Interaction/SphereWidget.h

index f96a1ed613ce85b497b8ba600004286c5d41501a..cd6d63550aba8ef6b4ec9d2e0822bcdd1cf28aff 100644 (file)
@@ -43,17 +43,37 @@ void WheelCallbackFunction(vtkObject* caller, long unsigned int eventId, void* v
 {
   std::cout << "WheelCallbackFunction callback" << std::endl;
 
-  vtkMapper * mapper = image_actors->GetPlaneActor()->GetMapper();
-  //vtkImageSliceMapper* imageSliceMapper = dynamic_cast<vtkImageSliceMapper*>(mapper);
-  //vtkImageSliceMapper* imageSliceMapper = vtkImageSliceMapper::SafeDownCast(mapper);
-  
+  int axis = image_actors->GetAxis();
+  vtkImageMapper3D * mapper = image_actors->GetImageActor()->GetMapper();
   vtkAbstractMapper3D* abs = dynamic_cast<vtkAbstractMapper3D*>(mapper);
   auto imgSliceMap = vtkImageSliceMapper::SafeDownCast(abs);
-  auto center = imgSliceMap->GetCenter();
+ // auto centerImg = imgSliceMap->GetCenter();  
   
+  auto center = image_actors->GetPlaneActor()->GetCenter();
+
+  std::cout << "plane: {" << center[0] << " , " << center[1] << " , " << center[2] << "} " << std::endl;
+  //std::cout << "slice: {" << centerImg[0] << " , " << centerImg[1] << " , " << centerImg[2] << "} " << std::endl;
+
+  switch (axis)
+  {
+  case 0: // X
+    center[1] = sphereWidget->GetPosition()[1];
+    center[2] = sphereWidget->GetPosition()[2];
+    break;                    
+  case 1: // Y                
+    center[0] = sphereWidget->GetPosition()[0];
+    center[2] = sphereWidget->GetPosition()[2];
+    break;                    
+  case 2: // Z                
+    center[1] = sphereWidget->GetPosition()[1];
+    center[0] = sphereWidget->GetPosition()[0];
+    break;
+  default: 
+    break;
+  }
+
   sphereWidget->SetCenter(center);
-  //actor mapper -> cast image slice mapper -> cast dynamic plane 
 }
 
 
@@ -120,7 +140,7 @@ int main(int argc, char* argv[])
   // Create slice actors
   image_actors = vtkSmartPointer< TSliceActors >::New();
   image_actors->SetInputImage(image->GetVTK< vtkImageData >());
-  image_actors->SetAxis(2);
+  image_actors->SetAxis(0);
   image_actors->PushActorsInto(window);
 
   vtkSmartPointer< vtkImageActorPointPlacer > placer =
@@ -131,6 +151,7 @@ int main(int argc, char* argv[])
   sphereWidget =
     vtkSmartPointer<TSphereWidget>::New();
   sphereWidget->SetInteractor(interactor);
+  sphereWidget->SetAxis(image_actors->GetAxis()); //sinchronize image pane with sphere plane
 
   vtkSmartPointer<vtkCallbackCommand> myCallBack =
     vtkSmartPointer<vtkCallbackCommand>::New();
index 1778d3fbfa26996a1e27e9854e83a4e94508730f..882c3ca7aa39111fc1f5f909ca960c16278a5844 100644 (file)
@@ -39,6 +39,8 @@ cpExtensions::Interaction::SphereWidget::
 SphereWidget()
 : Superclass()
 {
+  //this->SetAxis(0);
+
   this->SetTranslation(0);
   this->SetRadius(7);
 
@@ -63,8 +65,6 @@ int* idx, double* pos, bool alt, bool ctr, bool sft
 {
   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
   self->Superclass::EndInteraction();
-
-
 }
 
 // -------------------------------------------------------------------------
@@ -88,9 +88,43 @@ int* idx, double* pos, bool alt, bool ctr, bool sft
   self->Superclass::StartInteraction();*/
 }
 
+void cpExtensions::Interaction::SphereWidget::SetAxis(int axis)
+{
+  this->m_axis = axis;
+}
+
+
+void cpExtensions::Interaction::SphereWidget::SetAxis(void* data, int axis)
+{
+  SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
+  self->SetAxis(axis);
+}
+
+int cpExtensions::Interaction::SphereWidget::GetAxis()
+{
+  return this->m_axis;
+}
+
+int cpExtensions::Interaction::SphereWidget::GetAxis(void* data)
+{
+  SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
+  return self->GetAxis();
+}
+
+double* cpExtensions::Interaction::SphereWidget::GetPosition()
+{
+  return this->SphereActor->GetPosition();
+}
+
+double* cpExtensions::Interaction::SphereWidget::GetPosition(void* data)
+{
+  SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
+  return self->GetPosition();
+}
+
 void cpExtensions::Interaction::SphereWidget::SetCenter(double * center)
 {
-  this->Superclass::SetCenter(center);
+  //this->Superclass::SetCenter(center);
   this->SphereActor->SetPosition(center);
   this->SphereActor->Modified();
   this->Modified();
@@ -101,7 +135,7 @@ void cpExtensions::Interaction::SphereWidget::SetCenter(void* data, double * cen
 {
   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
   
-  self->Superclass::SetCenter(center);
+  //self->Superclass::SetCenter(center);
   self->SphereActor->SetPosition(center);
   self->SphereActor->Modified();
   self->Modified();
@@ -116,10 +150,12 @@ void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char&
   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
   self->Superclass::StartInteraction();
 
-  double * center = self->GetCenter();
+  double * center = self->SphereActor->GetPosition();
 
   auto radius = self->GetRadius();
 
+  auto axis = self->GetAxis();
+
   switch (key)
   {
   case 122: // Z & z
@@ -134,34 +170,77 @@ void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char&
     break;
   case 119: // W & w
   case 87:
-    center[0] += 1;
+    if (axis == 0)
+    {
+      center[2] += 1;
+    } else if (axis == 1)
+    {
+      center[2] += 1;
+    } else
+    {
+      center[1] -= 1;
+    }
+   
    
     break;
   case 83: // S & s
   case 115:
-    center[0] -= 1;
+    if (axis == 0)
+    {
+      center[2] -= 1;
+    }
+    else if (axis == 1)
+    {
+      center[2] -= 1;
+    }
+    else
+    {
+      center[1] += 1;
+    }
    
     break;
   case 65: // A & a
   case 97:
-    center[1] += 1;
+    if (axis == 0)
+    {
+      center[1] -= 1;
+    }
+    else if (axis == 1)
+    {
+      center[0] -= 1;
+    }
+    else
+    {
+      center[0] += 1;
+    }
    
     break;
   case 100: // D & d
   case 68:
-    center[1] -= 1;
+    if (axis == 0)
+    {
+      center[1] += 1;
+    }
+    else if (axis == 1)
+    {
+      center[0] += 1;
+    }
+    else
+    {
+      center[0] -= 1;
+    }
    
     break;
-  case 81: // Q & q
-  case 113:
-    center[2] += 1;
-  
-    break;
-  case 69: // E & e
-  case 101:
-    center[2] -= 1;
-  
-    break;
+  //case 81: // Q & q
+  //case 113:
+  //  center[2] += 1;
+  //
+  //  break;
+  //case 69: // E & e
+  //case 101:
+  //  center[2] -= 1;
+  //
+  //  break;
 
   default:
     break;
index b1a11bdf485c4dfbd629780f2282e8318f1c8976..9afae7c894be0b89f454a7efeef73b84d9f027cb 100644 (file)
@@ -27,8 +27,9 @@ namespace cpExtensions
 
       virtual void SetInteractor( vtkRenderWindowInteractor* rwi );
       void SetCenter(double* center);
-      
-
+      void SetAxis(int axis);
+      int GetAxis();
+      double * GetPosition();
     protected:
       SphereWidget( );
       virtual ~SphereWidget( );
@@ -50,7 +51,12 @@ namespace cpExtensions
        
       static void SetCenter(void* data, double* center);
 
+      static void SetAxis(void* data, int axis);
+      static int GetAxis(void* data);
+      static double * GetPosition(void* data);
     private:
+      int m_axis;
+
       // Purposely not implemented
       SphereWidget( const Self& );
       Self& operator=( const Self& );