From: Jose Luis Guzman Date: Tue, 17 Nov 2015 17:39:41 +0000 (+0100) Subject: sphere widget done, finally X-Git-Tag: v0.1~300 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=31e4cf1f3580efa059d3ffad14ba6a15d2372f5c;p=cpPlugins.git sphere widget done, finally --- diff --git a/appli/examples/example_SphereWidget.cxx b/appli/examples/example_SphereWidget.cxx index f96a1ed..cd6d635 100644 --- a/appli/examples/example_SphereWidget.cxx +++ b/appli/examples/example_SphereWidget.cxx @@ -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(mapper); - //vtkImageSliceMapper* imageSliceMapper = vtkImageSliceMapper::SafeDownCast(mapper); - + int axis = image_actors->GetAxis(); + vtkImageMapper3D * mapper = image_actors->GetImageActor()->GetMapper(); vtkAbstractMapper3D* abs = dynamic_cast(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::New(); sphereWidget->SetInteractor(interactor); + sphereWidget->SetAxis(image_actors->GetAxis()); //sinchronize image pane with sphere plane vtkSmartPointer myCallBack = vtkSmartPointer::New(); diff --git a/lib/cpExtensions/Interaction/SphereWidget.cxx b/lib/cpExtensions/Interaction/SphereWidget.cxx index 1778d3f..882c3ca 100644 --- a/lib/cpExtensions/Interaction/SphereWidget.cxx +++ b/lib/cpExtensions/Interaction/SphereWidget.cxx @@ -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(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(data); + self->SetAxis(axis); +} + +int cpExtensions::Interaction::SphereWidget::GetAxis() +{ + return this->m_axis; +} + +int cpExtensions::Interaction::SphereWidget::GetAxis(void* data) +{ + SphereWidget* self = reinterpret_cast(data); + return self->GetAxis(); +} + +double* cpExtensions::Interaction::SphereWidget::GetPosition() +{ + return this->SphereActor->GetPosition(); +} + +double* cpExtensions::Interaction::SphereWidget::GetPosition(void* data) +{ + SphereWidget* self = reinterpret_cast(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(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(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; diff --git a/lib/cpExtensions/Interaction/SphereWidget.h b/lib/cpExtensions/Interaction/SphereWidget.h index b1a11bd..9afae7c 100644 --- a/lib/cpExtensions/Interaction/SphereWidget.h +++ b/lib/cpExtensions/Interaction/SphereWidget.h @@ -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& );