From: Jose Luis Guzman Date: Wed, 4 Nov 2015 13:55:45 +0000 (+0100) Subject: sphere widget update X-Git-Tag: v0.1~307 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=64ee1e8924a88841c1c943fef576860402e0777c;p=cpPlugins.git sphere widget update --- diff --git a/appli/ImageMPR/CMakeLists.txt b/appli/ImageMPR/CMakeLists.txt index 7d3c3d8..3a9ab89 100644 --- a/appli/ImageMPR/CMakeLists.txt +++ b/appli/ImageMPR/CMakeLists.txt @@ -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 diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index 8a9d5df..79d2338 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -59,7 +59,7 @@ SET( NOPLUGINS_EXAMPLES_PROGRAMS example_BaseInteractorStyle - ##example_ContourWidget + example_ContourWidget ##example_Test_async ## example_MacheteFilter ## example_Test_DoubleClick diff --git a/appli/examples/example_SphereWidget.cxx b/appli/examples/example_SphereWidget.cxx index 4079b3a..db3626f 100644 --- a/appli/examples/example_SphereWidget.cxx +++ b/appli/examples/example_SphereWidget.cxx @@ -14,6 +14,8 @@ #include #include #include +#include +#include // ------------------------------------------------------------------------- // 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 image_actors; + +void WheelCallbackFunction(vtkObject* caller, long unsigned int eventId, void* clientData, void* vtkNotUsed(callData)) +{ + std::cout << "WheelCallbackFunction callback" << std::endl; + + vtkSmartPointer sphere = + reinterpret_cast(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 <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 sphereWidget = vtkSmartPointer::New(); sphereWidget->SetInteractor(interactor); -// sphereWidget->CreateDefaultRepresentation(); - /* vtkSphereRepresentation* sphereRepresentation = - vtkSphereRepresentation::SafeDownCast(sphereWidget->GetRepresentation()); - sphereRepresentation->HandleVisibilityOn();*/ + vtkSmartPointer myCallBack = + vtkSmartPointer::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(); diff --git a/lib/cpExtensions/Interaction/SphereWidget.cxx b/lib/cpExtensions/Interaction/SphereWidget.cxx index 07d778f..0b94465 100644 --- a/lib/cpExtensions/Interaction/SphereWidget.cxx +++ b/lib/cpExtensions/Interaction/SphereWidget.cxx @@ -10,6 +10,7 @@ #include #include #include +#include // ------------------------------------------------------------------------- cpExtensions::Interaction::SphereWidget:: @@ -26,10 +27,10 @@ SetInteractor(vtkRenderWindowInteractor* rwi) this->Superclass::SetInteractor(rwi); TBaseStyle* s = dynamic_cast(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 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(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(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(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(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 sphere = vtkSmartPointer::New(); - - self->InvokeEvent(vtkCommand::ModifiedEvent, NULL); - + self->SetRadius(radius); + self->SetCenter(data, center); self->Modified(); self->GetInteractor()->Render(); - self->ReleaseFocus(); + self->EndInteraction(); } + + // eof - $RCSfile$ diff --git a/lib/cpExtensions/Interaction/SphereWidget.h b/lib/cpExtensions/Interaction/SphereWidget.h index 11ce916..b1a11bd 100644 --- a/lib/cpExtensions/Interaction/SphereWidget.h +++ b/lib/cpExtensions/Interaction/SphereWidget.h @@ -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& );