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 <vtkCylinderSource.h>
38 #include <vtkLineWidget.h>
39 #include <vtkObjectFactory.h>
40 #include <vtkPoints.h>
41 #include <vtkPointWidget.h>
42 #include <vtkPolyData.h>
43 #include <vtkPolyDataMapper.h>
44 #include <vtkProperty.h>
45 #include <vtkRenderer.h>
46 #include <vtkRendererCollection.h>
47 #include <vtkRenderWindow.h>
48 #include <vtkRenderWindowInteractor.h>
49 #include <vtkSmartPointer.h>
50 #include <vtkTransform.h>
61 virtual void Execute(vtkObject *caller,
unsigned long event,
void *)
66 if(event == vtkCommand::InteractionEvent)
91 double pv = (mp3.x() * p1p2.
x() + mp3.y() * p1p2.
y() + mp3.z() * p1p2.
z());
96 axlPoint c = p3 - (ps /= (norm*norm));
168 class axlActorCylinderPrivate
172 vtkCylinderSource *cylinderSource;
173 vtkPointWidget *radiusWidget;
174 vtkLineWidget *lineWidget;
176 QVTKOpenGLWidget *widget;
181 #if (VTK_MAJOR_VERSION <= 5)
194 return d->cylinderSource;
209 this->
setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
210 this->
setActor(vtkSmartPointer<vtkActor>::New());
212 d->cylinderSource = vtkCylinderSource::New();
216 d->cylinderSource->SetResolution(200);
223 #if (VTK_MAJOR_VERSION <= 5)
224 this->
getMapper()->SetInput(d->cylinderSource->GetOutput());
226 this->
getMapper()->SetInputData(d->cylinderSource->GetOutput());
233 if(!d->cylinderObserver)
237 this->
getInteractor()->AddObserver(vtkCommand::InteractionEvent, d->cylinderObserver);
238 this->
getInteractor()->AddObserver(vtkCommand::MouseMoveEvent, d->cylinderObserver);
241 d->cylinderObserver->observerDataAssembly =
this;
243 d->cylinderObserver->observerData_cylinderSource = d->cylinderSource;
244 d->cylinderObserver->observerData_cylinder = d->cylinder;
248 QColor color = d->cylinder->color();
249 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
251 QString shader = d->cylinder->shader();
252 if(!shader.isEmpty())
259 connect(d->cylinder,SIGNAL(modifiedGeometry()),
this,SLOT(
onUpdateGeometry()));
260 connect(d->cylinder,SIGNAL(modifiedProperty()),
this,SLOT(
onUpdateProperty()));
263 qDebug()<<
"no axlCylinder available";
272 if(display && d->lineWidget){
276 if(!display && d->lineWidget){
283 if(!d->lineWidget || !d->radiusWidget) {
284 qDebug() <<
"No tet actor computed for this axlActorCylinder.";
289 d->lineWidget->SetEnabled(1);
290 d->radiusWidget->SetEnabled(1);
294 d->lineWidget->SetEnabled(0);
295 d->radiusWidget->SetEnabled(0);
304 if(!d->lineWidget || !d->radiusWidget)
308 d->lineWidget = vtkLineWidget::New();
310 d->lineWidget->SetProp3D(this->
getActor());
311 d->lineWidget->PlaceWidget();
312 d->lineWidget->SetPoint1(d->cylinder->firstPoint()->coordinates());
313 d->lineWidget->SetPoint2(d->cylinder->secondPoint()->coordinates());
315 d->radiusWidget = vtkPointWidget::New();
317 d->radiusWidget->SetProp3D(this->
getActor());
318 d->radiusWidget->PlaceWidget();
319 d->radiusWidget->AllOff();
320 d->radiusWidget->SetTranslationMode(1);
333 axlPoint center = (*(d->cylinder->firstPoint())+(*(d->cylinder->secondPoint()))) / 2.0;
334 axlPoint p1p2 = (*(d->cylinder->secondPoint())-(*(d->cylinder->firstPoint())));
338 pv *= d->cylinder->radius();
343 if(d->cylinderObserver)
345 d->lineWidget->AddObserver(vtkCommand::InteractionEvent, d->cylinderObserver);
346 d->radiusWidget->AddObserver(vtkCommand::InteractionEvent, d->cylinderObserver);
349 d->cylinderObserver->lineWidget = d->lineWidget;
350 d->cylinderObserver->radiusWidget = d->radiusWidget;
354 d->lineWidget->SetEnabled(
true);
355 d->radiusWidget->SetEnabled(
true);
368 d->lineWidget->RemoveAllObservers();
369 d->lineWidget->SetEnabled(
false);
370 d->lineWidget->Delete();
371 d->lineWidget = NULL;
376 d->radiusWidget->RemoveAllObservers();
377 d->radiusWidget->SetEnabled(
false);
378 d->radiusWidget->Delete();
379 d->radiusWidget = NULL;
383 if (d->cylinderObserver){
384 d->cylinderObserver->lineWidget = d->lineWidget;
385 d->cylinderObserver->radiusWidget = d->radiusWidget;
392 if(!d->lineWidget || !d->radiusWidget) {
393 qDebug() <<
"No tet actor computed for this axlActorBSpline.";
397 return d->lineWidget->GetEnabled() && d->radiusWidget->GetEnabled();
417 QColor color =
data->color();
418 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
429 vtkProperty *prop = this->
getActor()->GetProperty();
433 QColor color =
data->color();
434 qreal *h =
new qreal(0.0);
435 qreal *s =
new qreal(0.0);
436 qreal *l =
new qreal(0.0);
437 color.getHslF(h, s, l);
438 color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
439 prop->SetColor(color.redF(), color.greenF(), color.blueF());
451 vtkProperty *prop = this->
getActor()->GetProperty();
454 QColor color =
data->color();
455 qreal *h =
new qreal(0.0);
456 qreal *s =
new qreal(0.0);
457 qreal *l =
new qreal(0.0);
458 color.getHslF(h, s, l);
459 color.setHslF(*h, *s, *l + (1.0 - *l)/2.0);
460 prop->SetColor(color.redF(), color.greenF(), color.blueF());
478 if(d->cylinderObserver)
480 this->
getInteractor()->RemoveObservers(vtkCommand::InteractionEvent, d->cylinderObserver);
481 this->
getInteractor()->RemoveObservers(vtkCommand::MouseMoveEvent, d->cylinderObserver);
482 d->cylinderObserver->observerDataAssembly = NULL;
484 d->cylinderObserver->observerData_cylinderSource = NULL;
485 d->cylinderObserver->observerData_cylinder = NULL;
486 d->cylinderObserver->axlInteractorStyle = NULL;
487 d->cylinderObserver->Delete();
488 d->cylinderObserver = NULL;
494 if(d->cylinderSource)
496 d->cylinderSource->Delete();
497 d->cylinderSource = NULL;
507 if(d->lineWidget && d->radiusWidget)
510 d->lineWidget = NULL;
511 d->radiusWidget = NULL;
515 this->RemoveAllObservers();
517 this->
getActor()->RemoveAllObservers();
520 actorComposite->removeActorReference(
this);
525 d->cylinderSource->SetHeight(
axlPoint::distance(d->cylinder->firstPoint(), d->cylinder->secondPoint()));
526 d->cylinderSource->SetRadius(d->cylinder->radius());
527 d->cylinderSource->Modified();
528 d->cylinderSource->Update();
531 d->lineWidget->SetPoint1(d->cylinder->firstPoint()->coordinates());
532 d->lineWidget->SetPoint2(d->cylinder->secondPoint()->coordinates());
535 axlPoint center = (*(d->cylinder->firstPoint())+(*(d->cylinder->secondPoint()))) / 2.0;
538 axlPoint v = *(d->cylinder->firstPoint()) - center;
543 if(!(fabs(n.x()) < 0.00001 && fabs(n.z()) < 0.0001))
547 this->
getActor()->SetOrientation(0.0, 0.0, 0.0);
548 this->
getActor()->RotateWXYZ(-acos(v.
y()) * 180 / 3.14159, n.x(), 0.0, n.z());
551 if(d->radiusWidget) {
552 axlPoint p1p2 = (*(d->cylinder->secondPoint())-(*(d->cylinder->firstPoint())));
558 pv *= d->cylinder->radius();
567 if(!d->cylinder->fields().isEmpty())
568 d->cylinder->touchField();
570 if(d->cylinder->updateView())
577 d->lineWidget = NULL;
578 d->radiusWidget = NULL;
580 d->cylinderObserver = NULL;
581 d->cylinderSource =NULL;
Class axlPoint defines 3D points.
dtkAbstractData * data(void)
void setFirstPoint(axlPoint *p1)
Change first point of this cylinder.
static axlActorCylinder * New(void)
virtual void touchField(void)
virtual void setDisplay(bool display)
void setCylinderWidget(bool cylinderWidget)
void setRadius(double radius)
Change radius of this cylinder.
double * coordinates(void) const
Returns coordinates of this point.
void stateChanged(dtkAbstractData *data, int mode)
vtkStandardNewMacro(axlActorCylinder)
bool isShowCylinderWidget(void)
axlPoint * secondPoint(void) const
Returns second point of the cylinder.
Class axlCylinder defines 3D cylinders.
static axlActorCylinderObserver * New(void)
void setSecondPoint(axlPoint *p2)
Change second point of this cylinder.
virtual void setState(int state)
vtkCylinderSource * observerData_cylinderSource
axlPoint * firstPoint(void) const
Returns first point of the cylinder.
virtual int getState(void)
axlActorCylinder * observerDataAssembly
double length(void) const
Returns length of the cylinder.
axlInteractorStyleSwitch * axlInteractorStyle
virtual void setShader(QString vsfile)
virtual void setData(dtkAbstractData *cylinder1)
void onModeChanged(int state)
virtual axlAbstractActor * parent(void)
vtkLineWidget * lineWidget
virtual void setOpacity(double opacity)
void setQVTKWidget(QVTKOpenGLWidget *widget)
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
vtkCylinderSource * cylinder(void)
virtual void Execute(vtkObject *caller, unsigned long event, void *)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
vtkCxxRevisionMacro(axlActorCylinder,"$Revision: 0.0.1 $")
virtual void onUpdateProperty(void)
vtkPointWidget * radiusWidget
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
axlAbstractActor * createAxlActorCylinder(void)
QList< axlAbstractField * > fields(void)
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.
void setDisplay(bool display)
virtual vtkRenderWindowInteractor * getInteractor(void)
void showCylinderWidget(bool show)
Class axlAbstractData defines an API for all type of axel data.
axlCylinder * observerData_cylinder