27 #include <QVTKOpenGLWidget.h>
30 #include <vtkAssemblyPath.h>
32 #include <vtkCommand.h>
33 #include <vtkGlyph3D.h>
34 #include <vtkInteractorStyleSwitch.h>
36 #include <vtkLightCollection.h>
37 #include <vtkObjectFactory.h>
38 #include <vtkPoints.h>
39 #include <vtkPointWidget.h>
40 #include <vtkPolyData.h>
41 #include <vtkPolyDataMapper.h>
42 #include <vtkProperty.h>
43 #include <vtkRenderer.h>
44 #include <vtkRendererCollection.h>
45 #include <vtkRenderWindow.h>
46 #include <vtkRenderWindowInteractor.h>
47 #include <vtkSmartPointer.h>
48 #include <vtkSphereSource.h>
49 #include <vtkTransform.h>
60 virtual void Execute(vtkObject *caller,
unsigned long event,
void *)
64 if(event == vtkCommand::InteractionEvent)
163 class axlActorSpherePrivate
167 vtkSphereSource *sphereSource;
168 vtkPointWidget *pointWidget;
169 vtkPointWidget *radiusWidget;
171 QVTKOpenGLWidget *widget;
176 #if (VTK_MAJOR_VERSION <= 5)
189 return d->sphereSource;
204 this->
setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
205 this->
setActor(vtkSmartPointer<vtkActor>::New());
207 d->sphereSource = vtkSphereSource::New();
208 d->sphereSource->SetPhiResolution(20);
209 d->sphereSource->SetThetaResolution(20);
210 d->sphereSource->SetRadius(d->sphere->radius());
211 d->sphereSource->SetCenter( d->sphere->coordinates());
215 #if (VTK_MAJOR_VERSION <= 5)
216 this->
getMapper()->SetInput(d->sphereSource->GetOutput());
218 this->
getMapper()->SetInputData(d->sphereSource->GetOutput());
224 if(!d->sphereObserver)
228 this->
getInteractor()->AddObserver(vtkCommand::InteractionEvent, d->sphereObserver);
229 this->
getInteractor()->AddObserver(vtkCommand::MouseMoveEvent, d->sphereObserver);
231 d->sphereObserver->observerDataAssembly =
this;
233 d->sphereObserver->observerData_sphereSource = d->sphereSource;
234 d->sphereObserver->observerData_sphere = d->sphere;
239 QColor color = d->sphere->color();
240 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
242 QString shader = d->sphere->shader();
243 if(!shader.isEmpty())
254 connect(d->sphere, SIGNAL(modifiedGeometry()),
this, SLOT(
onUpdateGeometry()));
255 connect(d->sphere, SIGNAL(modifiedProperty()),
this, SLOT(
onUpdateProperty()));
258 qDebug()<<
"no axlSphere available";
267 if(display && d->pointWidget){
271 if(!display && d->pointWidget){
278 if(!d->pointWidget || !d->radiusWidget) {
279 qDebug() <<
"No tet actor computed for this axlActorCylinder.";
284 d->pointWidget->SetEnabled(1);
285 d->radiusWidget->SetEnabled(1);
290 d->pointWidget->SetEnabled(0);
291 d->radiusWidget->SetEnabled(1);
300 if(!d->pointWidget || !d->radiusWidget)
303 d->pointWidget = vtkPointWidget::New();
305 d->pointWidget->SetProp3D(this->
getActor());
306 d->pointWidget->PlaceWidget();
307 d->pointWidget->AllOff();
308 d->pointWidget->SetTranslationMode(1);
310 d->pointWidget->SetPosition(d->sphereSource->GetCenter());
312 d->radiusWidget = vtkPointWidget::New();
314 d->radiusWidget->SetProp3D(this->
getActor());
315 d->radiusWidget->PlaceWidget();
316 d->radiusWidget->AllOff();
317 d->radiusWidget->SetTranslationMode(1);
320 d->radiusWidget->SetPosition(d->pointWidget->GetPosition()[0] + d->sphere->radius() * 1.1 , d->pointWidget->GetPosition()[1], d->pointWidget->GetPosition()[2]);
324 if(d->sphereObserver)
326 d->pointWidget->AddObserver(vtkCommand::InteractionEvent, d->sphereObserver);
327 d->radiusWidget->AddObserver(vtkCommand::InteractionEvent, d->sphereObserver);
329 d->sphereObserver->pointWidget = d->pointWidget;
330 d->sphereObserver->radiusWidget = d->radiusWidget;
335 d->pointWidget->SetEnabled(
true);
336 d->radiusWidget->SetEnabled(
true);
346 d->pointWidget->RemoveAllObservers();
347 d->pointWidget->SetEnabled(
false);
348 d->pointWidget->Delete();
349 d->pointWidget = NULL;
354 d->radiusWidget->RemoveAllObservers();
355 d->radiusWidget->SetEnabled(
false);
356 d->radiusWidget->Delete();
357 d->radiusWidget = NULL;
361 if (d->sphereObserver){
362 d->sphereObserver->pointWidget = d->pointWidget;
363 d->sphereObserver->radiusWidget = d->radiusWidget;
370 if(!d->pointWidget || !d->radiusWidget) {
371 qDebug() <<
"No tet actor computed for this axlActorBSpline.";
375 return d->pointWidget->GetEnabled() && d->radiusWidget->GetEnabled();
395 QColor color =
data->color();
396 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
406 vtkProperty *prop = this->
getActor()->GetProperty();
410 QColor color =
data->color();
411 qreal *h =
new qreal(0.0);
412 qreal *s =
new qreal(0.0);
413 qreal *l =
new qreal(0.0);
414 color.getHslF(h, s, l);
415 color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
416 prop->SetColor(color.redF(), color.greenF(), color.blueF());
427 vtkProperty *prop = this->
getActor()->GetProperty();
430 QColor color =
data->color();
431 qreal *h =
new qreal(0.0);
432 qreal *s =
new qreal(0.0);
433 qreal *l =
new qreal(0.0);
434 color.getHslF(h, s, l);
435 color.setHslF(*h, *s, *l + (1.0 - *l)/2.0);
436 prop->SetColor(color.redF(), color.greenF(), color.blueF());
455 if(d->sphereObserver)
457 this->
getInteractor()->RemoveObservers(vtkCommand::InteractionEvent, d->sphereObserver);
458 this->
getInteractor()->RemoveObservers(vtkCommand::MouseMoveEvent, d->sphereObserver);
459 d->sphereObserver->observerDataAssembly = NULL;
461 d->sphereObserver->observerData_sphereSource = NULL;
462 d->sphereObserver->observerData_sphere = NULL;
463 d->sphereObserver->axlInteractorStyle = NULL;
464 d->sphereObserver->Delete();
465 d->sphereObserver = NULL;
473 d->sphereSource->Delete();
474 d->sphereSource = NULL;
484 if(d->pointWidget && d->radiusWidget)
487 d->pointWidget = NULL;
488 d->radiusWidget = NULL;
492 this->RemoveAllObservers();
494 this->
getActor()->RemoveAllObservers();
497 actorComposite->removeActorReference(
this);
502 d->sphereSource->SetCenter(d->sphere->coordinates());
503 d->sphereSource->SetRadius(d->sphere->radius());
504 d->sphereSource->Modified();
505 d->sphereSource->Update();
507 d->pointWidget->SetPosition(d->sphereSource->GetCenter());
509 if(!d->sphere->fields().isEmpty())
510 d->sphere->touchField();
512 if(d->sphere->updateView())
520 d->pointWidget = NULL;
521 d->radiusWidget = NULL;
523 d->sphereObserver = NULL;
524 d->sphereSource =NULL;
static axlActorSphere * New(void)
Class axlPoint defines 3D points.
bool isShowSphereWidget(void)
void setSphereWidget(bool sphereWidget)
vtkPointWidget * radiusWidget
virtual void touchField(void)
virtual void setDisplay(bool display)
void stateChanged(dtkAbstractData *data, int mode)
virtual void setState(int state)
void setCenter(double x, double y, double z)
axlActorSphere * observerDataAssembly
void onUpdateGeometry(void)
axlInteractorStyleSwitch * axlInteractorStyle
static axlActorSphereObserver * New(void)
axlAbstractActor * createAxlActorSphere(void)
virtual int getState(void)
double * coordinates(void) const
Returns coordinates of this sphere.
vtkPointWidget * pointWidget
void setRadius(double radius)
Class axlSphere defines 3D spheres.
virtual void setShader(QString vsfile)
vtkCxxRevisionMacro(axlActorSphere,"$Revision: 0.0.1 $")
virtual axlAbstractActor * parent(void)
virtual void setOpacity(double opacity)
dtkAbstractData * data(void)
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
virtual void setData(dtkAbstractData *sphere1)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
virtual void onUpdateProperty(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
void setDisplay(bool display)
axlSphere * observerData_sphere
void showSphereWidget(bool sphereWidget)
QList< axlAbstractField * > fields(void)
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.
void onModeChanged(int state)
virtual vtkRenderWindowInteractor * getInteractor(void)
vtkSphereSource * sphere(void)
virtual void Execute(vtkObject *caller, unsigned long event, void *)
Class axlAbstractData defines an API for all type of axel data.
vtkStandardNewMacro(axlActorSphere)
void setQVTKWidget(QVTKOpenGLWidget *widget)
vtkSphereSource * observerData_sphereSource