28 #include <QVTKOpenGLWidget.h>
31 #include <vtkAssemblyPath.h>
33 #include <vtkCommand.h>
34 #include <vtkGlyph3D.h>
35 #include <vtkInteractorStyleSwitch.h>
37 #include <vtkLightCollection.h>
38 #include <vtkLineSource.h>
39 #include <vtkLineWidget.h>
40 #include <vtkObjectFactory.h>
41 #include <vtkPoints.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>
51 #include <vtkTubeFilter.h>
73 virtual void Execute(vtkObject *caller,
unsigned long event,
void *)
78 if(event == vtkCommand::InteractionEvent) {
80 observerData_lineSource->Update();
81 observerData_lineSource->Modified();
86 if(caller == lineWidget) {
140 class axlActorLinePrivate
144 vtkLineSource *lineSource;
145 vtkLineWidget *lineWidget;
147 QVTKOpenGLWidget *widget;
150 vtkSmartPointer<vtkTubeFilter> lineTubeFilter;
153 #if (VTK_MAJOR_VERSION <= 5)
166 return d->lineSource;
179 this->
setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
180 this->
setActor(vtkSmartPointer<vtkActor>::New());
182 d->lineSource = vtkLineSource::New();
186 d->lineSource->SetResolution(200);
196 if (!d->lineObserver) {
199 this->
getInteractor()->AddObserver(vtkCommand::InteractionEvent, d->lineObserver);
200 this->
getInteractor()->AddObserver(vtkCommand::MouseMoveEvent, d->lineObserver);
202 d->lineObserver->observerDataAssembly =
this;
204 d->lineObserver->observerData_lineSource = d->lineSource;
205 d->lineObserver->observerData_line = d->line;
209 QColor color = d->line->color();
210 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
212 QString shader = d->line->shader();
213 if (!shader.isEmpty())
224 connect(d->line, SIGNAL(modifiedGeometry()),
this, SLOT(
onUpdateGeometry()));
225 connect(d->line, SIGNAL(modifiedProperty()),
this, SLOT(
onUpdateProperty()));
228 qDebug()<<
"no axlLine available";
235 if(display && d->lineWidget){
239 if(!display && d->lineWidget){
247 qDebug() <<
"No tet actor computed for this axlActorLine.";
252 d->lineWidget->SetEnabled(1);
256 d->lineWidget->SetEnabled(0);
263 if (!d->lineWidget) {
266 d->lineWidget = vtkLineWidget::New();
268 d->lineWidget->SetProp3D(this->
getActor());
269 d->lineWidget->PlaceWidget();
270 d->lineWidget->SetPoint1(d->line->firstPoint()->coordinates());
271 d->lineWidget->SetPoint2(d->line->secondPoint()->coordinates());
276 d->lineWidget->AddObserver(vtkCommand::InteractionEvent, d->lineObserver);
277 d->lineObserver->lineWidget = d->lineWidget;
281 d->lineWidget->SetEnabled(
true);
289 d->lineWidget->RemoveAllObservers();
290 d->lineWidget->SetEnabled(
false);
291 d->lineWidget->Delete();
292 d->lineWidget = NULL;
297 d->lineObserver->lineWidget = d->lineWidget;
304 qDebug() <<
"No tet actor computed for this axlActorBSpline.";
308 return d->lineWidget->GetEnabled();
328 QColor color =
data->color();
329 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
340 vtkProperty *prop = this->
getActor()->GetProperty();
344 QColor color =
data->color();
345 qreal *h =
new qreal(0.0);
346 qreal *s =
new qreal(0.0);
347 qreal *l =
new qreal(0.0);
348 color.getHslF(h, s, l);
349 color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
350 prop->SetColor(color.redF(), color.greenF(), color.blueF());
362 vtkProperty *prop = this->
getActor()->GetProperty();
365 QColor color =
data->color();
366 qreal *h =
new qreal(0.0);
367 qreal *s =
new qreal(0.0);
368 qreal *l =
new qreal(0.0);
369 color.getHslF(h, s, l);
370 color.setHslF(*h, *s, *l + (1.0 - *l)/2.0);
371 prop->SetColor(color.redF(), color.greenF(), color.blueF());
389 if(d->lineObserver) {
390 this->
getInteractor()->RemoveObservers(vtkCommand::InteractionEvent, d->lineObserver);
391 this->
getInteractor()->RemoveObservers(vtkCommand::MouseMoveEvent, d->lineObserver);
392 d->lineObserver->observerDataAssembly = NULL;
394 d->lineObserver->observerData_lineSource = NULL;
395 d->lineObserver->observerData_line = NULL;
396 d->lineObserver->axlInteractorStyle = NULL;
397 d->lineObserver->Delete();
398 d->lineObserver = NULL;
404 d->lineSource->Delete();
405 d->lineSource = NULL;
416 d->lineWidget = NULL;
420 this->RemoveAllObservers();
422 this->
getActor()->RemoveAllObservers();
425 actorComposite->removeActorReference(
this);
430 d->lineSource->SetPoint1(d->line->firstPoint()->coordinates());
431 d->lineSource->SetPoint2(d->line->secondPoint()->coordinates());
433 d->lineSource->Update();
434 d->lineSource->Modified();
437 d->lineWidget->SetPoint1(d->line->firstPoint()->coordinates());
438 d->lineWidget->SetPoint2(d->line->secondPoint()->coordinates());
449 #if (VTK_MAJOR_VERSION <= 5)
450 if(d->line->size() < 0.001) {
451 this->
getMapper()->SetInput(d->lineSource->GetOutput());
453 d->lineTubeFilter->SetInput(d->lineSource->GetOutput());
454 this->
getMapper()->SetInput(d->lineTubeFilter->GetOutput());
455 d->lineTubeFilter->SetRadius(d->line->size());
456 d->lineTubeFilter->Update();
459 if(d->line->size() < 0.001) {
460 this->
getMapper()->SetInputData(d->lineSource->GetOutput());
462 d->lineTubeFilter->SetInputData(d->lineSource->GetOutput());
463 this->
getMapper()->SetInputData(d->lineTubeFilter->GetOutput());
464 d->lineTubeFilter->SetRadius(d->line->size());
465 d->lineTubeFilter->Update();
472 if(!d->line->fields().isEmpty())
473 d->line->touchField();
475 if(d->line->updateView())
486 d->line->setSize(size);
487 #if (VTK_MAJOR_VERSION <= 5)
488 if(d->line->size() < 0.001) {
489 this->
getMapper()->SetInput(d->lineSource->GetOutput());
491 d->lineTubeFilter->SetInput(d->lineSource->GetOutput());
492 this->
getMapper()->SetInput(d->lineTubeFilter->GetOutput());
493 d->lineTubeFilter->SetRadius(d->line->size());
494 d->lineTubeFilter->Update();
497 if(d->line->size() < 0.001) {
498 this->
getMapper()->SetInputData(d->lineSource->GetOutput());
500 d->lineTubeFilter->SetInputData(d->lineSource->GetOutput());
501 this->
getMapper()->SetInputData(d->lineTubeFilter->GetOutput());
502 d->lineTubeFilter->SetRadius(d->line->size());
503 d->lineTubeFilter->Update();
508 if(!d->line->fields().isEmpty())
509 d->line->touchField();
516 d->lineTubeFilter = vtkSmartPointer<vtkTubeFilter>::New();
517 d->lineTubeFilter->SetNumberOfSides(8);
519 d->lineWidget = NULL;
521 d->lineObserver = NULL;
virtual void setData(dtkAbstractData *line1)
Class axlLine defines 3D lines.
virtual void setDisplay(bool display)
axlActorLine * observerDataAssembly
void showLineWidget(bool show)
void stateChanged(dtkAbstractData *data, int mode)
dtkAbstractData * data(void)
axlLine * observerData_line
void onModeChanged(int state)
bool isShowLineWidget(void)
virtual void setState(int state)
void setQVTKWidget(QVTKOpenGLWidget *widget)
virtual int getState(void)
static axlActorLine * New(void)
vtkCxxRevisionMacro(axlActorLine,"$Revision: 0.0.1 $")
axlAbstractActor * createAxlActorLine(void)
axlInteractorStyleSwitch * axlInteractorStyle
virtual void setShader(QString vsfile)
virtual axlAbstractActor * parent(void)
virtual void setOpacity(double opacity)
void setSecondPoint(axlPoint *p2)
Change second point of this line.
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
void setFirstPoint(axlPoint *p1)
Change first point of this line.
vtkStandardNewMacro(axlActorLine)
vtkLineSource * line(void)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
vtkLineWidget * lineWidget
virtual void onUpdateProperty(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
static axlActorLineObserver * New(void)
void setSize(double size)
void setDisplay(bool display)
virtual vtkRenderWindowInteractor * getInteractor(void)
void setLineWidget(bool lineWidget)
vtkLineSource * observerData_lineSource
Class axlAbstractData defines an API for all type of axel data.
virtual void Execute(vtkObject *caller, unsigned long event, void *)