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 <vtkConeSource.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 <vtkDataSetMapper.h>
45 #include <vtkProperty.h>
46 #include <vtkRenderer.h>
47 #include <vtkRendererCollection.h>
48 #include <vtkRenderWindow.h>
49 #include <vtkRenderWindowInteractor.h>
50 #include <vtkSmartPointer.h>
51 #include <vtkTransform.h>
61 virtual void Execute(vtkObject *caller,
unsigned long event,
void *)
65 if(event == vtkCommand::InteractionEvent)
92 double pv = (mp3.x() * p1p2.
x() + mp3.y() * p1p2.
y() + mp3.z() * p1p2.
z());
97 axlPoint c = p3 - (ps /= (norm*norm));
128 class axlActorConePrivate
132 vtkConeSource *coneSource;
133 vtkPointWidget *radiusWidget;
134 vtkLineWidget *lineWidget;
136 QVTKOpenGLWidget *widget;
141 #if (VTK_MAJOR_VERSION <= 5)
154 return d->coneSource;
158 return d->coneSource->GetOutput();
174 this->
setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
176 this->
setActor(vtkSmartPointer<vtkActor>::New());
178 d->coneSource = vtkConeSource::New();
182 d->coneSource->SetResolution(200);
183 d->coneSource->SetDirection(0.0, 1.0, 0.0);
192 #if (VTK_MAJOR_VERSION <= 5)
193 this->
getMapper()->SetInput(d->coneSource->GetOutput());
196 this->
getMapper()->SetInputData(d->coneSource->GetOutput());
208 this->
getInteractor()->AddObserver(vtkCommand::InteractionEvent, d->coneObserver);
209 this->
getInteractor()->AddObserver(vtkCommand::MouseMoveEvent, d->coneObserver);
212 d->coneObserver->observerDataAssembly =
this;
214 d->coneObserver->observerData_coneSource = d->coneSource;
215 d->coneObserver->observerData_cone = d->cone;
219 QColor color = d->cone->color();
220 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
222 QString shader = d->cone->shader();
223 if(!shader.isEmpty())
234 qDebug()<<
"no axlCone available";
243 if(display && d->lineWidget){
247 if(!display && d->lineWidget){
254 if(!d->lineWidget || !d->radiusWidget) {
255 qDebug() <<
"No tet actor computed for this axlActorCone.";
260 d->lineWidget->SetEnabled(1);
261 d->radiusWidget->SetEnabled(1);
265 d->lineWidget->SetEnabled(0);
266 d->radiusWidget->SetEnabled(0);
275 if(!d->lineWidget || !d->radiusWidget)
279 d->lineWidget = vtkLineWidget::New();
281 d->lineWidget->SetProp3D(this->
getActor());
282 d->lineWidget->PlaceWidget();
283 d->lineWidget->SetPoint1(d->cone->apex()->coordinates());
284 d->lineWidget->SetPoint2(d->cone->basePoint()->coordinates());
286 d->radiusWidget = vtkPointWidget::New();
288 d->radiusWidget->SetProp3D(this->
getActor());
289 d->radiusWidget->PlaceWidget();
290 d->radiusWidget->AllOff();
291 d->radiusWidget->SetTranslationMode(1);
304 axlPoint center = (*(d->cone->apex())+(*(d->cone->basePoint()))) / 2.0;
305 axlPoint p1p2 = (*(d->cone->basePoint())-(*(d->cone->apex())));
310 pv *= (1 * d->cone->radius());
317 d->lineWidget->AddObserver(vtkCommand::InteractionEvent, d->coneObserver);
318 d->radiusWidget->AddObserver(vtkCommand::InteractionEvent, d->coneObserver);
321 d->coneObserver->lineWidget = d->lineWidget;
322 d->coneObserver->radiusWidget = d->radiusWidget;
326 d->lineWidget->SetEnabled(
true);
327 d->radiusWidget->SetEnabled(
true);
340 d->lineWidget->RemoveAllObservers();
341 d->lineWidget->SetEnabled(
false);
342 d->lineWidget->Delete();
343 d->lineWidget = NULL;
348 d->radiusWidget->RemoveAllObservers();
349 d->radiusWidget->SetEnabled(
false);
350 d->radiusWidget->Delete();
351 d->radiusWidget = NULL;
355 if (d->coneObserver){
356 d->coneObserver->lineWidget = d->lineWidget;
357 d->coneObserver->radiusWidget = d->radiusWidget;
364 if(!d->lineWidget || !d->radiusWidget) {
365 qDebug() <<
"No tet actor computed for this axlActorBSpline.";
369 return d->lineWidget->GetEnabled() && d->radiusWidget->GetEnabled();
389 QColor color =
data->color();
390 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
401 vtkProperty *prop = this->
getActor()->GetProperty();
405 QColor color =
data->color();
406 qreal *h =
new qreal(0.0);
407 qreal *s =
new qreal(0.0);
408 qreal *l =
new qreal(0.0);
409 color.getHslF(h, s, l);
410 color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
411 prop->SetColor(color.redF(), color.greenF(), color.blueF());
423 vtkProperty *prop = this->
getActor()->GetProperty();
426 QColor color =
data->color();
427 qreal *h =
new qreal(0.0);
428 qreal *s =
new qreal(0.0);
429 qreal *l =
new qreal(0.0);
430 color.getHslF(h, s, l);
431 color.setHslF(*h, *s, *l + (1.0 - *l)/2.0);
432 prop->SetColor(color.redF(), color.greenF(), color.blueF());
452 this->
getInteractor()->RemoveObservers(vtkCommand::InteractionEvent, d->coneObserver);
453 this->
getInteractor()->RemoveObservers(vtkCommand::MouseMoveEvent, d->coneObserver);
454 d->coneObserver->observerDataAssembly = NULL;
456 d->coneObserver->observerData_coneSource = NULL;
457 d->coneObserver->observerData_cone = NULL;
458 d->coneObserver->axlInteractorStyle = NULL;
459 d->coneObserver->Delete();
460 d->coneObserver = NULL;
468 d->coneSource->Delete();
469 d->coneSource = NULL;
479 if(d->lineWidget && d->radiusWidget)
482 d->lineWidget = NULL;
483 d->radiusWidget = NULL;
487 this->RemoveAllObservers();
489 this->
getActor()->RemoveAllObservers();
492 actorComposite->removeActorReference(
this);
499 d->coneSource->SetRadius(d->cone->radius());
501 d->coneSource->Modified();
502 d->coneSource->Update();
506 d->lineWidget->SetPoint1(d->cone->apex()->coordinates());
507 d->lineWidget->SetPoint2(d->cone->basePoint()->coordinates());
510 axlPoint center = (*(d->cone->apex())+(*(d->cone->basePoint()))) / 2.0;
513 axlPoint v = *(d->cone->apex()) - center;
518 if(!(fabs(n.x()) < 0.00001 && fabs(n.z()) < 0.0001))
522 this->
getActor()->SetOrientation(0.0, 0.0, 0.0);
523 this->
getActor()->RotateWXYZ(-acos(v.
y()) * 180 / 3.14159, n.x(), 0.0, n.z());
526 if(d->radiusWidget) {
527 axlPoint p1p2 = (*(d->cone->basePoint())-(*(d->cone->apex())));
533 pv *= d->cone->radius();
543 if(!d->cone->fields().isEmpty())
544 d->cone->touchField();
546 if(d->cone->updateView())
553 d->lineWidget = NULL;
554 d->radiusWidget = NULL;
556 d->coneObserver = NULL;
Class axlPoint defines 3D points.
vtkConeSource * observerData_coneSource
virtual void touchField(void)
virtual void setDisplay(bool display)
double * coordinates(void) const
Returns coordinates of this point.
static axlActorConeObserver * New(void)
void stateChanged(dtkAbstractData *data, int mode)
void showConeWidget(bool show)
void setQVTKWidget(QVTKOpenGLWidget *widget)
static axlActorCone * New(void)
void setApex(axlPoint *apex)
Change apex of this cone.
axlAbstractActor * createAxlActorCone(void)
virtual void setState(int state)
void setRadius(double radius)
Change radius of this cone.
virtual void Execute(vtkObject *caller, unsigned long event, void *)
void setConeWidget(bool coneWidget)
virtual int getState(void)
vtkPointWidget * radiusWidget
bool isShowConeWidget(void)
vtkStandardNewMacro(axlActorCone)
virtual void setShader(QString vsfile)
double length(void) const
Returns length of the cone.
virtual axlAbstractActor * parent(void)
virtual void setOpacity(double opacity)
virtual void setData(dtkAbstractData *cone1)
axlInteractorStyleSwitch * axlInteractorStyle
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
virtual void onUpdateProperty(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
dtkAbstractData * data(void)
vtkConeSource * cone(void)
vtkSmartPointer< vtkPolyData > getPolyData()
Class axlCone defines 3D cones.
void setDisplay(bool display)
void onModeChanged(int state)
vtkLineWidget * lineWidget
vtkCxxRevisionMacro(axlActorCone,"$Revision: 0.0.1 $")
QList< axlAbstractField * > fields(void)
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
void setBasePoint(axlPoint *basePoint)
Change base point of this cone.
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.
virtual vtkRenderWindowInteractor * getInteractor(void)
Class axlAbstractData defines an API for all type of axel data.
axlActorCone * observerDataAssembly
axlCone * observerData_cone