#include <vtkSphere.h>
#include <vtkSphereRepresentation.h>
#include <vtkSphereWidget2.h>
+#include <vtkCommand.h>
+#include <vtkCallbackCommand.h>
// -------------------------------------------------------------------------
// type definiftions
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)
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);
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();
#include <vtkSphereRepresentation.h>
#include <vtkSmartPointer.h>
#include <vtkSphere.h>
+#include <vtkProperty.h>
// -------------------------------------------------------------------------
cpExtensions::Interaction::SphereWidget::
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
}
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);*/
}
// -------------------------------------------------------------------------
)
{
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();
+
+
}
// -------------------------------------------------------------------------
}
+// -------------------------------------------------------------------------
+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$