From f1c75e8efd926172e954cd5e7952622c5788b450 Mon Sep 17 00:00:00 2001 From: Jose Luis Guzman Date: Tue, 27 Oct 2015 18:34:50 +0100 Subject: [PATCH] widget sphere update: works with mouse but is still buggy with key board --- appli/ImageMPR/CMakeLists.txt | 2 +- appli/ImageMPR/MementoState.cxx | 74 -------- appli/ImageMPR/MementoState.h | 67 ------- appli/examples/CMakeLists.txt | 8 +- appli/examples/example_SphereWidget.cxx | 121 ++++++++++++ appli/examples/example_Test_Memento.cxx | 157 ++++++++++++++++ lib/cpExtensions/IO/MementoState.cxx | 123 +++++++++++++ lib/cpExtensions/IO/MementoState.h | 77 ++++++++ lib/cpExtensions/Interaction/SphereWidget.cxx | 173 ++++++++++++++++++ lib/cpExtensions/Interaction/SphereWidget.h | 58 ++++++ 10 files changed, 716 insertions(+), 144 deletions(-) delete mode 100644 appli/ImageMPR/MementoState.cxx delete mode 100644 appli/ImageMPR/MementoState.h create mode 100644 appli/examples/example_SphereWidget.cxx create mode 100644 appli/examples/example_Test_Memento.cxx create mode 100644 lib/cpExtensions/IO/MementoState.cxx create mode 100644 lib/cpExtensions/IO/MementoState.h create mode 100644 lib/cpExtensions/Interaction/SphereWidget.cxx create mode 100644 lib/cpExtensions/Interaction/SphereWidget.h diff --git a/appli/ImageMPR/CMakeLists.txt b/appli/ImageMPR/CMakeLists.txt index 3a63336..0ed90ac 100644 --- a/appli/ImageMPR/CMakeLists.txt +++ b/appli/ImageMPR/CMakeLists.txt @@ -24,7 +24,7 @@ IF(USE_QT4) ) SET( App_SOURCES - MementoState.cxx + #MementoState.cxx main.cxx ) SET( diff --git a/appli/ImageMPR/MementoState.cxx b/appli/ImageMPR/MementoState.cxx deleted file mode 100644 index cfc9b7c..0000000 --- a/appli/ImageMPR/MementoState.cxx +++ /dev/null @@ -1,74 +0,0 @@ -#include "MementoState.h" - -#include -#include - - -// ------------------------------------------------------------------------- -MementoState::MementoState() -{ - m_Id = 0; -}; - -// ------------------------------------------------------------------------- -MementoState::MementoState(long id, TPluginImage* _img) -{ - char base[] = "state"; - std::ostringstream oss; - oss << id; - std::string str = oss.str(); - auto complement = str.c_str(); - - std::string fileName(base); - fileName.append(complement); - fileName.append(".mhd"); - - std::string fileNameRaw(base); - fileNameRaw.append(complement); - fileNameRaw.append(".raw"); - save(fileName, fileNameRaw, _img); -} - -// ------------------------------------------------------------------------- -vtkSmartPointer -MementoState::getMemento(long id) -{ - char base[] = "state"; - std::ostringstream oss; - oss << id; - std::string str = oss.str(); - auto complement = str.c_str(); - - std::string fileName(base); - fileName.append(complement); - fileName.append(".mhd"); - return load(fileName); -} - -// ------------------------------------------------------------------------- -void MementoState:: -save(const std::string& filename, const std::string& filenameRaw, TPluginImage* img) { - /* TODO - vtkSmartPointer writer = - vtkSmartPointer::New(); - writer->SetInputData(img->GetVTK< vtkImageData >()); - writer->SetFileName(filename.c_str()); - writer->SetRAWFileName(filenameRaw.c_str()); - writer->Write(); - */ -} - -// ------------------------------------------------------------------------- -vtkSmartPointer -MementoState::load(const std::string& filename) { - /* TODO - vtkSmartPointer reader = - vtkSmartPointer::New(); - reader->SetFileName(filename.c_str()); - reader->Update(); - return reader; - */ -return( NULL ); -} - -// eof - $RCSfile$ diff --git a/appli/ImageMPR/MementoState.h b/appli/ImageMPR/MementoState.h deleted file mode 100644 index 35befec..0000000 --- a/appli/ImageMPR/MementoState.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef __MEMENTOSTATE__H__ -#define __MEMENTOSTATE__H__ - -#include - - -// vtk stuff -#include -#include - -// Plugins interface -#include -#include -#include -#include -#include - -#include - -// ------------------------------------------------------------------------- -namespace Ui -{ - class ImageMPR; -} - -//========================================================================== -// Plugins types -typedef cpPlugins::Interface::Interface TPluginsInterface; -typedef cpPlugins::Interface::Object TPluginObject; -typedef cpPlugins::Interface::DataObject TPluginData; -typedef cpPlugins::Interface::Image TPluginImage; -typedef cpPlugins::Interface::ImplicitFunction TPluginImplicitFunction; -typedef cpPlugins::Interface::Mesh TPluginMesh; -typedef cpPlugins::Interface::ProcessObject TPluginFilter; -typedef cpPlugins::Interface::Parameters TParameters; - -typedef cpExtensions::Visualization::MPRObjects TMPRObjects; - -class MementoState -{ -private: - long m_Id; - -public: - - MementoState(); - MementoState(long id, TPluginImage* _img); - vtkSmartPointer getMemento(long id); -private: - void save(const std::string& filename, const std::string& filenameRaw, TPluginImage* img); - vtkSmartPointer load(const std::string& filename); - -}; - -//========================================================================== - -// ------------------------------------------------------------------------- -/** - */ - - - - - -#endif // __MEMENTOSTATE__H__ - -// eof - $RCSfile$ diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index 5d197de..9b0ae6a 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -31,6 +31,8 @@ SET( example_View2DImage example_HandleWidget example_SeedWidget + example_SphereWidget + ##example_Test_Memento ##example_MarchingCubes ##example_OtsuFilter ##example_RGBImageToHSVChannels @@ -50,14 +52,16 @@ FOREACH(prog ${EXAMPLES_PROGRAMS_WITH_PLUGINS}) ${prog} cpExtensions cpPlugins_Interface + ) ENDFOREACH(prog) SET( NOPLUGINS_EXAMPLES_PROGRAMS example_BaseInteractorStyle - example_ContourWidget - example_Test_async + + ##example_ContourWidget + ##example_Test_async ## example_MacheteFilter ## example_Test_DoubleClick ## example_ExtractDICOMSeries diff --git a/appli/examples/example_SphereWidget.cxx b/appli/examples/example_SphereWidget.cxx new file mode 100644 index 0000000..ac0d27c --- /dev/null +++ b/appli/examples/example_SphereWidget.cxx @@ -0,0 +1,121 @@ +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +// type definiftions + +typedef cpPlugins::Interface::Interface TInterface; +typedef cpPlugins::Interface::ProcessObject TProcessObject; +typedef cpPlugins::Interface::DataObject TDataObject; +typedef cpPlugins::Interface::Image TImage; +typedef cpPlugins::Interface::Parameters TParameters; +typedef TInterface::TClasses TClasses; + +typedef cpExtensions::Visualization::ImageSliceActors TSliceActors; +typedef cpExtensions::Interaction::SphereWidget TSphereWidget; + +// ------------------------------------------------------------------------- + +std::string _path = "C://dev//creatis//cpPlugins//build//Debug//cpPluginsIO.dll"; +std::string _img = "C://img//SphereVolume.mhd"; + +int main(int argc, char* argv[]) +{ + if (argc >= 3) + { + _path = argv[1]; + _img = argv[2]; + } + + // Create interface + TInterface plugins; + if (!plugins.Load(_path)) + { + std::cerr << "Failed to load plugins." << std::endl; + return(1); + } + + // Create reader + TProcessObject::Pointer reader; + reader = plugins.CreateProcessObject("cpPlugins::IO::ImageReader"); + if (reader.IsNull()) + { + std::cerr + << "No suitable reader found in plugins." << std::endl + << "Reader: " << reader.GetPointer() << std::endl + << std::endl; + return(1); + } + + // Configure reader + TParameters* reader_params = reader->GetParameters(); + reader_params->AddToStringList("FileNames", _img); + + // Execute pipeline + std::string err = reader->Update(); + if (err != "") + { + std::cerr << "ERROR: " << err << std::endl; + return(1); + + } + + TImage* image = reader->GetOutput< TImage >("Output"); + + // Configure visualization objects + vtkSmartPointer< vtkRenderer > renderer = + vtkSmartPointer< vtkRenderer >::New(); + renderer->SetBackground(0.1, 0.1, 0.1); + + vtkSmartPointer< vtkRenderWindow > window = + vtkSmartPointer< vtkRenderWindow >::New(); + window->AddRenderer(renderer); + window->SetSize(600, 600); + + // Set up the interaction + vtkSmartPointer< vtkRenderWindowInteractor > interactor = + vtkSmartPointer< vtkRenderWindowInteractor >::New(); + window->SetInteractor(interactor); + + // Create slice actors + vtkSmartPointer< TSliceActors > image_actors = + vtkSmartPointer< TSliceActors >::New(); + image_actors->AddInputData(image->GetVTK< vtkImageData >(), 2); + image_actors->PushActorsInto(window); + + vtkSmartPointer< vtkImageActorPointPlacer > placer = + vtkSmartPointer< vtkImageActorPointPlacer >::New(); + placer->SetImageActor(image_actors->GetImageActor(0)); + + // Create a sphere widget + vtkSmartPointer sphereWidget = + vtkSmartPointer::New(); + sphereWidget->SetInteractor(interactor); + sphereWidget->CreateDefaultRepresentation(); + + vtkSphereRepresentation* sphereRepresentation = + vtkSphereRepresentation::SafeDownCast(sphereWidget->GetRepresentation()); + sphereRepresentation->HandleVisibilityOn(); + + // Begin interaction + renderer->ResetCamera(); + window->Render(); + sphereWidget->On(); + interactor->Start(); + + return(0); +} \ No newline at end of file diff --git a/appli/examples/example_Test_Memento.cxx b/appli/examples/example_Test_Memento.cxx new file mode 100644 index 0000000..01f3308 --- /dev/null +++ b/appli/examples/example_Test_Memento.cxx @@ -0,0 +1,157 @@ +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +typedef itk::Image ImageType; +typedef itk::ImageFileReader ReaderType; + +typedef cpPlugins::Interface::Image TPluginImage; + +int main() { + auto memento = cpExtensions::IO::MementoState(); + + //here goes the code + + + std::string filePath = "julia_mha.mhd"; + std::string filePathRaw = "julia_mha.raw"; + // Create an image + vtkSmartPointer source = + vtkSmartPointer::New(); + + vtkSmartPointer castFilter = + vtkSmartPointer::New(); + castFilter->SetOutputScalarTypeToUnsignedChar(); + castFilter->SetInputConnection(source->GetOutputPort()); + castFilter->Update(); + + vtkSmartPointer writer = + vtkSmartPointer::New(); + writer->SetInputConnection(castFilter->GetOutputPort()); + writer->SetFileName(filePath.c_str()); + writer->SetRAWFileName(filePathRaw.c_str()); + writer->Write(); + + //ReaderType::Pointer reader = ReaderType::New(); + vtkSmartPointer reader = + vtkSmartPointer::New(); + reader->SetFileName(filePath.c_str()); + reader->Update(); + + //first memento + /* auto obj = TPluginImage::New(); + + auto oo = dynamic_cast (reader->GetOutput()); + obj->SetSource(oo); + memento.SetToMemento(oo);*/ + + // filter 1 (state 2) --------------------------------------------------------------- + + typedef itk::BinaryBallStructuringElement< + ImageType::PixelType, 2> StructuringElementType; + StructuringElementType structuringElement; + structuringElement.SetRadius(10); + structuringElement.CreateStructuringElement(); + + typedef itk::VTKImageToImageFilter imgToFilter; + imgToFilter::Pointer connectorimg = imgToFilter::New(); + connectorimg->SetInput(reader->GetOutput()); + connectorimg->Update(); + + typedef itk::BinaryErodeImageFilter + BinaryErodeImageFilterType; + + BinaryErodeImageFilterType::Pointer erodeFilter + = BinaryErodeImageFilterType::New(); + erodeFilter->SetInput(connectorimg->GetOutput()); + erodeFilter->SetKernel(structuringElement); + + // filter 2 (state 3) --------------------------------------------------------------- + + typedef itk::BinaryThresholdImageFilter + BinaryThresholdImageFilterType; + + BinaryThresholdImageFilterType::Pointer thresholdFilter + = BinaryThresholdImageFilterType::New(); + thresholdFilter->SetInput(erodeFilter->GetOutput()); + thresholdFilter->SetLowerThreshold(10); + thresholdFilter->SetUpperThreshold(30); + thresholdFilter->SetInsideValue(255); + thresholdFilter->SetOutsideValue(0); + + + // filter 3 (state 4) --------------------------------------------------------------- + + typedef itk::InvertIntensityImageFilter + InvertIntensityImageFilterType; + + InvertIntensityImageFilterType::Pointer invertIntensityFilter + = InvertIntensityImageFilterType::New(); + invertIntensityFilter->SetInput(thresholdFilter->GetOutput()); + invertIntensityFilter->SetMaximum(255); + + // undo (state 3) --------------------------------------------------------------- + + // undo (state 2) --------------------------------------------------------------- + + // redo (state 3) --------------------------------------------------------------- + + // visualization -- just for test + + typedef itk::ImageToVTKImageFilter ConnectorType; + ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(invertIntensityFilter->GetOutput()); + connector->Update(); + + vtkSmartPointer actor = + vtkSmartPointer::New(); + actor->GetMapper()->SetInputData(connector->GetOutput()); + + vtkSmartPointer renderer = + vtkSmartPointer::New(); + vtkSmartPointer renderWindow = + vtkSmartPointer::New(); + renderWindow->AddRenderer(renderer); + vtkSmartPointer renderWindowInteractor = + vtkSmartPointer::New(); + renderWindowInteractor->SetRenderWindow(renderWindow); + + renderer->AddActor(actor); + renderer->SetBackground(.2, .3, .4); + + renderWindow->Render(); + renderWindowInteractor->Start(); + + + +//#ifdef _DEBUG +// auto i = 0; +// std::cout << "wait for close"; +// std::cin >> i; +//#endif + + return 0; + +} diff --git a/lib/cpExtensions/IO/MementoState.cxx b/lib/cpExtensions/IO/MementoState.cxx new file mode 100644 index 0000000..12045c3 --- /dev/null +++ b/lib/cpExtensions/IO/MementoState.cxx @@ -0,0 +1,123 @@ +#include + + +#include +#include + + +// ------------------------------------------------------------------------- +cpExtensions::IO::MementoState::MementoState() +{ + m_Id = 0; +}; + +// ------------------------------------------------------------------------- +//cpExtensions::IO::MementoState::MementoState(long id, TPluginImage* _img) +//{ +// SetToMemento(_img); +//} +// +//bool +//cpExtensions::IO::MementoState::SetToMemento(TPluginObject * _do) +//{ +// char base[] = "state"; +// std::ostringstream oss; +// this->m_Id++; +// oss << this->m_Id; +// std::string str = oss.str(); +// auto complement = str.c_str(); +// +// std::string fileName(base); +// fileName.append(complement); +// fileName.append(".mhd"); +// +// std::string fileNameRaw(base); +// fileNameRaw.append(complement); +// fileNameRaw.append(".raw"); +//// save(fileName, fileNameRaw, _img); +// +// +// vtkSmartPointer writer = +// vtkSmartPointer::New(); +// +// auto img = TPluginImage::New(); +// img->SetSource(_do); +// +// // writer->SetInputData(_do->GetVTK()); +// writer->SetInputData(img->GetVTK()); +// +// writer->SetFileName(fileName.c_str()); +// writer->SetRAWFileName(fileNameRaw.c_str()); +// writer->Write(); +// +// return true; +//} +// +// +bool +cpExtensions::IO::MementoState::SetToMemento(cpPlugins::Interface::Image* _img) +{ + char base[] = "state"; + std::ostringstream oss; + this->m_Id++; + oss << this->m_Id; + std::string str = oss.str(); + auto complement = str.c_str(); + + std::string fileName(base); + fileName.append(complement); + fileName.append(".mhd"); + + std::string fileNameRaw(base); + fileNameRaw.append(complement); + fileNameRaw.append(".raw"); + save(fileName, fileNameRaw, _img); + + return true; +} +// +// +//// ------------------------------------------------------------------------- +//vtkSmartPointer +//cpExtensions::IO::MementoState::getMemento(long id) +//{ +// char base[] = "state"; +// std::ostringstream oss; +// oss << id; +// std::string str = oss.str(); +// auto complement = str.c_str(); +// +// std::string fileName(base); +// fileName.append(complement); +// fileName.append(".mhd"); +// return load(fileName); +//} +// +// ------------------------------------------------------------------------- +void +cpExtensions::IO::MementoState:: +save(const std::string& filename, const std::string& filenameRaw, cpPlugins::Interface::Image* img) { + + vtkSmartPointer writer = + vtkSmartPointer::New(); + writer->SetInputData(img->GetVTK< vtkImageData >()); + writer->SetFileName(filename.c_str()); + writer->SetRAWFileName(filenameRaw.c_str()); + writer->Write(); + +} + +// ------------------------------------------------------------------------- +vtkSmartPointer +cpExtensions::IO::MementoState::load(const std::string& filename) { + + vtkSmartPointer reader = + vtkSmartPointer::New(); + reader->SetFileName(filename.c_str()); + reader->Update(); + return reader; + +//return( NULL ); +} + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/IO/MementoState.h b/lib/cpExtensions/IO/MementoState.h new file mode 100644 index 0000000..13a7a4b --- /dev/null +++ b/lib/cpExtensions/IO/MementoState.h @@ -0,0 +1,77 @@ +#ifndef __CPEXTENSIONS__IO__MEMENTOSTATE__H__ +#define __CPEXTENSIONS__IO__MEMENTOSTATE__H__ + +#include + + +#include + + +// vtk stuff +#include +#include + +// Plugins interface +#include +#include +#include +#include +#include + +#include + +// ------------------------------------------------------------------------- + + + +namespace cpExtensions +{ + namespace IO + { + //========================================================================== +// Plugins types +//typedef cpPlugins::Interface::Interface TPluginsInterface; +//typedef cpPlugins::Interface::Object TPluginObject; +//typedef cpPlugins::Interface::DataObject TPluginData; +//typedef cpPlugins::Interface::Image TPluginImage; +//typedef cpPlugins::Interface::ImplicitFunction TPluginImplicitFunction; +//typedef cpPlugins::Interface::Mesh TPluginMesh; +//typedef cpPlugins::Interface::ProcessObject TPluginFilter; +//typedef cpPlugins::Interface::Parameters TParameters; +// +//typedef cpExtensions::Visualization::MPRObjects TMPRObjects; + + class cpExtensions_EXPORT MementoState + { + private: + long m_Id; + + public: + + MementoState(); +// MementoState(long id, cpPlugins::Interface::Image * _img); + + bool SetToMemento(cpPlugins::Interface::Image* _img); +// bool SetToMemento(itk::ProcessObject po); + +// vtkSmartPointer getMemento(long id); + private: + void save(const std::string& filename, const std::string& filenameRaw, cpPlugins::Interface::Image* img); + vtkSmartPointer load(const std::string& filename); + + }; + } +} +//========================================================================== + +// ------------------------------------------------------------------------- +/** + */ + + + + + +#endif // __CPEXTENSIONS__IO__MEMENTOSTATE__H__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Interaction/SphereWidget.cxx b/lib/cpExtensions/Interaction/SphereWidget.cxx new file mode 100644 index 0000000..7c326e3 --- /dev/null +++ b/lib/cpExtensions/Interaction/SphereWidget.cxx @@ -0,0 +1,173 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// ------------------------------------------------------------------------- +cpExtensions::Interaction::SphereWidget:: +Self* cpExtensions::Interaction::SphereWidget:: +New() +{ + return(new Self); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::SphereWidget:: +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); + } // fi +} + +// ------------------------------------------------------------------------- +cpExtensions::Interaction::SphereWidget:: +SphereWidget() +: Superclass() +{ + vtkSmartPointer sphereRepresentation = + vtkSphereRepresentation::SafeDownCast(this->GetRepresentation()); + + //sphereRepresentation->SetHandleSize(0); + sphereRepresentation->SetRadialLine(2); + sphereRepresentation->SetRadius(7); + + sphereRepresentation->SetPhiResolution(10); + sphereRepresentation->SetThetaResolution(20); + + //sphereRepresentation->HandleVisibilityOff(); + //sphereRepresentation->SetHandleText(0); + sphereRepresentation->SetRepresentationToWireframe(); + + // Remove default translations + /* vtkWidgetEventTranslator* t = this->GetEventTranslator(); + t->RemoveTranslation(vtkCommand::LeftButtonPressEvent); + t->RemoveTranslation(vtkCommand::MiddleButtonPressEvent); + t->RemoveTranslation(vtkCommand::RightButtonPressEvent);*/ +} + +// ------------------------------------------------------------------------- +cpExtensions::Interaction::SphereWidget:: +~SphereWidget() +{ +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::SphereWidget:: +_Click( +void* data, const TBaseStyle::ButtonID& button, +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 +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::SphereWidget:: +_DoubleClick( +void* data, const TBaseStyle::ButtonID& button, +int* idx, double* pos, bool alt, bool ctr, bool sft +) +{ + +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key) +{ + SphereWidget* self = reinterpret_cast(data); + + double handlePosition[3]; + vtkSphereRepresentation* sphereRepresentation = + vtkSphereRepresentation::SafeDownCast(self->GetRepresentation()); + + + + auto center = sphereRepresentation->GetCenter(); + self->Superclass::StartInteraction(); + switch (key) + { + case 122: // Z & z + case 90: + sphereRepresentation->SetRadius(sphereRepresentation->GetRadius() + 0.1); + break; + case 88: // X & x + case 120: + sphereRepresentation->SetRadius(sphereRepresentation->GetRadius() - 0.1); + break; + case 119: // W & w + case 87: + center[0] += 1; + sphereRepresentation->SetCenter(center); + break; + case 83: // S & s + case 115: + center[0] -= 1; + sphereRepresentation->SetCenter(center); + break; + case 65: // A & a + case 97: + center[1] += 1; + sphereRepresentation->SetCenter(center); + break; + case 100: // D & d + case 68: + center[1] -= 1; + sphereRepresentation->SetCenter(center); + break; + case 81: // Q & q + case 113: + center[2] += 1; + sphereRepresentation->SetCenter(center); + break; + case 69: // E & e + case 101: + center[2] -= 1; + sphereRepresentation->SetCenter(center); + break; + + default: + break; + } + self->SetKeyPressActivation(1); + self->Render(); + +} + + + + + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Interaction/SphereWidget.h b/lib/cpExtensions/Interaction/SphereWidget.h new file mode 100644 index 0000000..dd6a499 --- /dev/null +++ b/lib/cpExtensions/Interaction/SphereWidget.h @@ -0,0 +1,58 @@ +#ifndef __CPEXTENSIONS__INTERACTION__SphereWidget__H__ +#define __CPEXTENSIONS__INTERACTION__SphereWidget__H__ + +#include +#include +#include + +namespace cpExtensions +{ + namespace Interaction + { + /** + */ + class cpExtensions_EXPORT SphereWidget + : public vtkSphereWidget2 + { + public: + typedef SphereWidget Self; + vtkTypeMacro( SphereWidget, vtkSphereWidget2 ); + + typedef cpExtensions::Interaction::BaseInteractorStyle TBaseStyle; + typedef TBaseStyle::TMouseCommand TMouseCommand; + typedef TBaseStyle::TKeyCommand TKeyCommand; + + public: + static Self* New( ); + + virtual void SetInteractor( vtkRenderWindowInteractor* rwi ); + + + + protected: + SphereWidget( ); + virtual ~SphereWidget( ); + + static void _Click( + void* data, const TBaseStyle::ButtonID& button, + int* idx, double* pos, bool alt, bool ctr, bool sft + ); + static void _DoubleClick( + void* data, const TBaseStyle::ButtonID& button, + int* idx, double* pos, bool alt, bool ctr, bool sft + ); + static void _KeyPress(void* data, const char& key); + + private: + // Purposely not implemented + SphereWidget( const Self& ); + Self& operator=( const Self& ); + }; + + } // ecapseman + +} // ecapseman + +#endif // __CPEXTENSIONS__INTERACTION__SphereWidget__H__ + +// eof - $RCSfile$ -- 2.47.1