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 <vtkLineWidget.h>
40 #include <vtkPolyData.h>
41 #include <vtkPolyDataMapper.h>
42 #include <vtkProperty.h>
43 #include <vtkRenderer.h>
44 #include <vtkRendererCollection.h>
45 #include <vtkRenderWindowInteractor.h>
46 #include <vtkRenderWindow.h>
47 #include <vtkSmartPointer.h>
48 #include <vtkParametricEllipsoid.h>
49 #include <vtkParametricFunctionSource.h>
50 #include <vtkTransform.h>
59 virtual void Execute(vtkObject *caller,
unsigned long event,
void *) {
62 if (event == vtkCommand::InteractionEvent) {
77 axlPoint lXCenter = (lXP1 + lXP2) / 2.0;
88 axlPoint lYCenter = (lYP1 + lYP2) / 2.0;
99 axlPoint lZCenter = (lZP1 + lZP2) / 2.0;
164 class axlActorEllipsoidPrivate
168 vtkParametricFunctionSource *ellipsoidSource;
169 vtkParametricEllipsoid *vtkEllipsoid;
170 vtkLineWidget *lineXWidget;
171 vtkLineWidget *lineYWidget;
172 vtkLineWidget *lineZWidget;
174 QVTKOpenGLWidget *widget;
179 #if (VTK_MAJOR_VERSION <= 5)
190 return d->vtkEllipsoid;
205 double radiusX = d->ellipsoid->semiX()->norm();
206 double radiusY = d->ellipsoid->semiY()->norm();
207 double radiusZ = d->ellipsoid->semiZ()->norm();
209 this->
setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
210 this->
setActor(vtkSmartPointer<vtkActor>::New());
212 d->ellipsoidSource = vtkParametricFunctionSource::New();
214 d->vtkEllipsoid = vtkParametricEllipsoid::New();
215 d->vtkEllipsoid->SetXRadius(radiusX);
216 d->vtkEllipsoid->SetYRadius(radiusY);
217 d->vtkEllipsoid->SetZRadius(radiusZ);
218 d->ellipsoidSource->SetParametricFunction(d->vtkEllipsoid);
221 #if (VTK_MAJOR_VERSION <= 5)
222 this->
getMapper()->SetInput(d->ellipsoidSource->GetOutput());
224 this->
getMapper()->SetInputData(d->ellipsoidSource->GetOutput());
230 if (!d->ellipsoidObserver) {
233 this->
getInteractor()->AddObserver(vtkCommand::InteractionEvent, d->ellipsoidObserver);
234 this->
getInteractor()->AddObserver(vtkCommand::MouseMoveEvent, d->ellipsoidObserver);
236 d->ellipsoidObserver->observerDataAssembly =
this;
238 d->ellipsoidObserver->observerData_ellipsoidSource = d->ellipsoidSource;
239 d->ellipsoidObserver->observerData_ellipsoid = d->ellipsoid;
244 QColor color = d->ellipsoid->color();
245 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
247 QString shader = d->ellipsoid->shader();
248 if(!shader.isEmpty())
253 connect(d->ellipsoid,SIGNAL(modifiedGeometry()),
this,SLOT(
onUpdateGeometry()));
254 connect(d->ellipsoid,SIGNAL(modifiedProperty()),
this,SLOT(
onUpdateProperty()));
257 qDebug()<<
"no axlEllipsoid available";
263 if (display && d->lineXWidget) {
267 if (!display && d->lineXWidget) {
273 if (!d->lineXWidget || !d->lineYWidget || !d->lineZWidget) {
274 qDebug() <<
"No tet actor computed for this axlActorCylinder.";
279 d->lineXWidget->SetEnabled(1);
280 d->lineYWidget->SetEnabled(1);
281 d->lineZWidget->SetEnabled(1);
285 d->lineXWidget->SetEnabled(0);
286 d->lineYWidget->SetEnabled(0);
287 d->lineZWidget->SetEnabled(0);
293 if (ellipsoidWidget) {
294 if (!d->lineXWidget || !d->lineYWidget || !d->lineZWidget) {
297 d->lineXWidget = vtkLineWidget::New();
299 d->lineXWidget->SetProp3D(this->
getActor());
300 d->lineXWidget->PlaceWidget();
302 d->lineYWidget = vtkLineWidget::New();
304 d->lineYWidget->SetProp3D(this->
getActor());
305 d->lineYWidget->PlaceWidget();
307 d->lineZWidget = vtkLineWidget::New();
309 d->lineZWidget->SetProp3D(this->
getActor());
310 d->lineZWidget->PlaceWidget();
312 axlPoint center = *(d->ellipsoid->center());
318 axlPoint orientationX(this->
getActor()->GetMatrix()->GetElement(0,0), this->
getActor()->GetMatrix()->GetElement(1,0), this->
getActor()->GetMatrix()->GetElement(2,0));
319 axlPoint orientationY(this->
getActor()->GetMatrix()->GetElement(0,1), this->
getActor()->GetMatrix()->GetElement(1,1), this->
getActor()->GetMatrix()->GetElement(2,1)) ;
320 axlPoint orientationZ(this->
getActor()->GetMatrix()->GetElement(0,2), this->
getActor()->GetMatrix()->GetElement(1,2), this->
getActor()->GetMatrix()->GetElement(2,2)) ;
326 d->lineXWidget->SetPoint1((center - (orientationX * d->ellipsoid->semiX()->norm())).coordinates());
327 d->lineXWidget->SetPoint2((center + (orientationX * d->ellipsoid->semiX()->norm())).coordinates());
329 d->lineYWidget->SetPoint1((center - (orientationY * d->ellipsoid->semiY()->norm())).coordinates());
330 d->lineYWidget->SetPoint2((center + (orientationY * d->ellipsoid->semiY()->norm())).coordinates());
332 d->lineZWidget->SetPoint1((center - (orientationZ * d->ellipsoid->semiZ()->norm())).coordinates());
333 d->lineZWidget->SetPoint2((center + (orientationZ * d->ellipsoid->semiZ()->norm())).coordinates());
336 if (d->ellipsoidObserver) {
337 d->lineXWidget->AddObserver(vtkCommand::InteractionEvent, d->ellipsoidObserver);
338 d->lineYWidget->AddObserver(vtkCommand::InteractionEvent, d->ellipsoidObserver);
339 d->lineZWidget->AddObserver(vtkCommand::InteractionEvent, d->ellipsoidObserver);
342 d->ellipsoidObserver->lineXWidget = d->lineXWidget;
343 d->ellipsoidObserver->lineYWidget = d->lineYWidget;
344 d->ellipsoidObserver->lineZWidget = d->lineZWidget;
348 d->lineXWidget->SetEnabled(
true);
349 d->lineYWidget->SetEnabled(
true);
350 d->lineZWidget->SetEnabled(
true);
355 if (d->lineXWidget) {
356 d->lineXWidget->RemoveAllObservers();
357 d->lineXWidget->SetEnabled(
false);
358 d->lineXWidget->Delete();
359 d->lineXWidget = NULL;
362 if (d->lineYWidget) {
363 d->lineYWidget->RemoveAllObservers();
364 d->lineYWidget->SetEnabled(
false);
365 d->lineYWidget->Delete();
366 d->lineYWidget = NULL;
369 if (d->lineZWidget) {
370 d->lineZWidget->RemoveAllObservers();
371 d->lineZWidget->SetEnabled(
false);
372 d->lineZWidget->Delete();
373 d->lineZWidget = NULL;
377 if (d->ellipsoidObserver){
378 d->ellipsoidObserver->lineXWidget = d->lineXWidget;
379 d->ellipsoidObserver->lineYWidget = d->lineYWidget;
380 d->ellipsoidObserver->lineZWidget = d->lineZWidget;
385 if (!d->lineXWidget || !d->lineYWidget || !d->lineZWidget) {
386 qDebug() <<
"No tet actor computed for this axlActorBSpline.";
390 return d->lineXWidget->GetEnabled() && d->lineYWidget->GetEnabled() && d->lineZWidget->GetEnabled();
405 QColor color =
data->color();
406 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
410 }
else if (state == 1) {
413 vtkProperty *prop = this->
getActor()->GetProperty();
416 QColor color =
data->color();
417 qreal *h =
new qreal(0.0);
418 qreal *s =
new qreal(0.0);
419 qreal *l =
new qreal(0.0);
420 color.getHslF(h, s, l);
421 color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
422 prop->SetColor(color.redF(), color.greenF(), color.blueF());
428 }
else if (state == 2) {
431 vtkProperty *prop = this->
getActor()->GetProperty();
434 QColor color =
data->color();
435 qreal *h =
new qreal(0.0);
436 qreal *s =
new qreal(0.0);
437 qreal *l =
new qreal(0.0);
438 color.getHslF(h, s, l);
439 color.setHslF(*h, *s, *l + (1.0 - *l)/2.0);
440 prop->SetColor(color.redF(), color.greenF(), color.blueF());
459 if (d->ellipsoidObserver) {
460 this->
getInteractor()->RemoveObservers(vtkCommand::InteractionEvent, d->ellipsoidObserver);
461 this->
getInteractor()->RemoveObservers(vtkCommand::MouseMoveEvent, d->ellipsoidObserver);
462 d->ellipsoidObserver->observerDataAssembly = NULL;
464 d->ellipsoidObserver->observerData_ellipsoidSource = NULL;
465 d->ellipsoidObserver->observerData_ellipsoid = NULL;
466 d->ellipsoidObserver->axlInteractorStyle = NULL;
467 d->ellipsoidObserver->Delete();
468 d->ellipsoidObserver = NULL;
473 if (d->ellipsoidSource) {
474 d->ellipsoidSource->Delete();
475 d->ellipsoidSource = NULL;
483 if (d->lineXWidget && d->lineYWidget && d->lineZWidget) {
485 d->lineXWidget = NULL;
486 d->lineYWidget = NULL;
487 d->lineZWidget = NULL;
491 this->RemoveAllObservers();
493 this->
getActor()->RemoveAllObservers();
496 actorComposite->removeActorReference(
this);
500 d->ellipsoidSource->Modified();
501 d->ellipsoidSource->Update();
503 d->vtkEllipsoid->SetXRadius(d->ellipsoid->semiX()->norm());
504 d->vtkEllipsoid->SetYRadius(d->ellipsoid->semiY()->norm());
505 d->vtkEllipsoid->SetZRadius(d->ellipsoid->semiZ()->norm());
507 vtkMatrix4x4 *actorMatrix = vtkMatrix4x4::New();
509 actorMatrix->SetElement(0, 0, d->ellipsoid->semiX()->x());
511 actorMatrix->SetElement(0, 1, d->ellipsoid->semiY()->x());
513 actorMatrix->SetElement(0, 2, d->ellipsoid->semiZ()->x());
516 actorMatrix->SetElement(1, 0, d->ellipsoid->semiX()->y());
518 actorMatrix->SetElement(1, 1, d->ellipsoid->semiY()->y());
520 actorMatrix->SetElement(1, 2, d->ellipsoid->semiZ()->y());
523 actorMatrix->SetElement(2, 0, d->ellipsoid->semiX()->z());
525 actorMatrix->SetElement(2, 1, d->ellipsoid->semiY()->z());
527 actorMatrix->SetElement(2, 2, d->ellipsoid->semiZ()->z());
529 vtkTransform::GetOrientation(orient, actorMatrix);
530 this->
getActor()->SetOrientation(orient);
532 this->
getActor()->SetPosition(d->ellipsoid->center()->coordinates());
534 if(d->lineXWidget && d->lineYWidget && d->lineZWidget) {
535 axlPoint center = *(d->ellipsoid->center());
541 axlPoint orientationX(this->
getActor()->GetMatrix()->GetElement(0,0), this->
getActor()->GetMatrix()->GetElement(1,0), this->
getActor()->GetMatrix()->GetElement(2,0));
542 axlPoint orientationY(this->
getActor()->GetMatrix()->GetElement(0,1), this->
getActor()->GetMatrix()->GetElement(1,1), this->
getActor()->GetMatrix()->GetElement(2,1)) ;
543 axlPoint orientationZ(this->
getActor()->GetMatrix()->GetElement(0,2), this->
getActor()->GetMatrix()->GetElement(1,2), this->
getActor()->GetMatrix()->GetElement(2,2)) ;
549 d->lineXWidget->SetPoint1((center - (orientationX * (d->ellipsoid->semiX()->norm()))).coordinates());
550 d->lineXWidget->SetPoint2((center + (orientationX * (d->ellipsoid->semiX()->norm()))).coordinates());
552 d->lineYWidget->SetPoint1((center - (orientationY * (d->ellipsoid->semiY()->norm()))).coordinates());
553 d->lineYWidget->SetPoint2((center + (orientationY * (d->ellipsoid->semiY()->norm()))).coordinates());
555 d->lineZWidget->SetPoint1((center - (orientationZ * (d->ellipsoid->semiZ()->norm()))).coordinates());
556 d->lineZWidget->SetPoint2((center + (orientationZ * (d->ellipsoid->semiZ()->norm()))).coordinates());
559 if(!d->ellipsoid->fields().isEmpty())
560 d->ellipsoid->touchField();
562 if(d->ellipsoid->updateView())
568 d->lineXWidget = NULL;
569 d->lineYWidget = NULL;
570 d->lineZWidget = NULL;
572 d->ellipsoidObserver = NULL;
573 d->ellipsoidSource =NULL;
584 return axlActorEllipsoid::New();
Class axlPoint defines 3D points.
void modifyCenter(double *center)
modify Center of this Ellipsoid.
void setEllipsoidWidget(bool ellipsoidWidget)
virtual void setDisplay(bool display)
axlInteractorStyleSwitch * axlInteractorStyle
double * coordinates(void) const
Returns coordinates of this point.
void stateChanged(dtkAbstractData *data, int mode)
axlAbstractActor * createAxlActorEllipsoid(void)
virtual void setState(int state)
vtkParametricEllipsoid * vtkEllipsoid
void setQVTKWidget(QVTKOpenGLWidget *widget)
axlEllipsoid * observerData_ellipsoid
virtual int getState(void)
vtkParametricEllipsoid * ellipsoid(void)
void modifySemiX(double *semiX)
modify SemiX of this Ellipsoid.
vtkLineWidget * lineYWidget
vtkParametricFunctionSource * observerData_ellipsoidSource
vtkCxxRevisionMacro(axlActorEllipsoid,"$Revision: 0.0.1 $")
void modifySemiY(double *semiY)
modify SemiY of this Ellipsoid.
virtual void setShader(QString vsfile)
vtkLineWidget * lineZWidget
virtual axlAbstractActor * parent(void)
virtual void setOpacity(double opacity)
void setDisplay(bool display)
virtual void Execute(vtkObject *caller, unsigned long event, void *)
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
virtual void onUpdateProperty(void)
vtkLineWidget * lineXWidget
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
void onUpdateGeometry(void)
virtual void setData(dtkAbstractData *ellipsoid1)
axlActorEllipsoid * observerDataAssembly
vtkStandardNewMacro(axlActorEllipsoid)
void showEllipsoidWidget(bool ellipsoidWidget)
void modifySemiZ(double *semiZ)
modify SemiZ of this Ellipsoid.
dtkAbstractData * data(void)
void onModeChanged(int state)
virtual vtkRenderWindowInteractor * getInteractor(void)
Class axlEllipsoid defines 3D ellipsoids.
Class axlAbstractData defines an API for all type of axel data.
bool isShowEllipsoidWidget(void)
static axlActorEllipsoidObserver * New(void)