Developer documentation | Axl-2.5.1

axlActorComposite.cpp
Go to the documentation of this file.
1 /* axlActorComposite.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Fri Dec 17 10:59:21 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Mon Dec 17 15:03:36 2012 (+0100)
8  * By: Julien Wintz
9  * Update #: 28
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlActorComposite.h"
21 #include "axlActorCone.h"
22 #include "axlActorCylinder.h"
23 #include "axlActorTorus.h"
24 //#include "axlActorCircleArc.h"
25 #include "axlActorEllipsoid.h"
26 #include "axlActorFieldDiscrete.h"
27 #include "axlActorMesh.h"
28 #include "axlActorLine.h"
29 #include "axlActorPlane.h"
30 #include "axlActorPoint.h"
31 #include "axlActorPointSet.h"
32 #include "axlActorCurveBSpline.h"
33 #include "axlActorSphere.h"
34 #include "axlActorSurfaceBSpline.h"
35 #include "axlActorVolumeBSpline.h"
36 #include "axlActorSurfaceTrimmed.h"
43 #include <axlCore/axlPoint.h>
44 #include <axlCore/axlCone.h>
45 #include <axlCore/axlCylinder.h>
46 #include <axlCore/axlTorus.h>
47 //#include <axlCore/axlCircleArc.h>
48 #include <axlCore/axlEllipsoid.h>
49 #include <axlCore/axlLine.h>
50 #include <axlCore/axlPlane.h>
51 //#include <axlCore/axlPointSet.h>
52 #include <axlCore/axlMesh.h>
53 #include <axlCore/axlSphere.h>
54 
55 
56 #include <vtkActor.h>
57 #include <vtkAssemblyNode.h>
58 #include <vtkAssemblyPath.h>
59 #include <vtkCellArray.h>
60 #include <vtkCellPicker.h>
61 #include <vtkDoubleArray.h>
62 #include <vtkCommand.h>
63 #include <vtkMatrix4x4.h>
64 #include <vtkObjectFactory.h>
65 #include <vtkPoints.h>
66 #include <vtkPointData.h>
67 #include <vtkPolyData.h>
68 #include <vtkPolyDataMapper.h>
69 #include <vtkProp3DCollection.h>
70 #include <vtkProperty.h>
71 #include <vtkRenderer.h>
72 #include <vtkRendererCollection.h>
73 #include <vtkRenderWindow.h>
74 #include <vtkRenderWindowInteractor.h>
75 #include <vtkSmartPointer.h>
76 #include <vtkTimerLog.h>
77 
78 class axlActorCompositeObserver : public vtkCommand
79 {
80 public:
82  {
83  return new axlActorCompositeObserver;
84  }
85 
86  virtual void Execute(vtkObject *caller, unsigned long event, void *)
87  {
88 
89  }//execute
90 };
91 
92 
93 
94 // /////////////////////////////////////////////////////////////////
95 // axlActorCompositePrivate
96 // /////////////////////////////////////////////////////////////////
97 
98 class axlActorCompositePrivate
99 {
100 public:
101  vtkSmartPointer<vtkPoints> points;
102  vtkSmartPointer<vtkPolyData> polyData;
103  vtkSmartPointer<vtkCellArray> cellArray;
104  vtkSmartPointer<vtkActor> actor;
105  vtkSmartPointer<vtkPolyDataMapper> mapper;
106  vtkSmartPointer<vtkRenderWindowInteractor> interactor;
107  vtkSmartPointer<vtkCellPicker> CpCursorPicker;
108  vtkSmartPointer<axlActorCompositeObserver> observer;
109  vtkSmartPointer<vtkRenderer> renderer;
110 
111  axlAbstractView *view;
112  axlAbstractDataComposite *composite;
113 
114  QList<axlAbstractActor *> listCompositeActorChild;
115 
116  int State;
117 };
118 
119 #if (VTK_MAJOR_VERSION <= 5)
120 vtkCxxRevisionMacro(axlActorComposite, "$Revision: 0.0.1 $");
121 #endif
122 
124 
125 dtkAbstractData *axlActorComposite::data(void)
126 {
127  return d->composite;
128 }
129 
131 {
132  return d->listCompositeActorChild.removeOne(actor);
133 }
134 
135 void axlActorComposite::setData(dtkAbstractData *data1)
136 {
137  axlAbstractDataComposite *data = dynamic_cast<axlAbstractDataComposite *>(data1);
138  d->composite = data;
139 
140  for (int i = 0; i < d->composite->count(); i++)
141  {
142  if(axlAbstractDataComposite *currentData = dynamic_cast<axlAbstractDataComposite *>(d->composite->get(i)))
143  {
144  axlActorComposite *currentComposite = axlActorComposite::New();
145  currentComposite->setParent(this);
146  currentComposite->setData(currentData);
147  d->view->insert(currentData, currentComposite);
148  this->AddPart(currentComposite);
149  connect(currentData,SIGNAL(samplingChanged()),currentComposite,SLOT(onSamplingChanged()));
150  d->listCompositeActorChild << currentComposite;
151 
152  }
153  else if(axlAbstractCurveBSpline *currentData = dynamic_cast<axlAbstractCurveBSpline *>(d->composite->get(i)))
154  {
155  axlActorCurveBSpline *currentComposite = axlActorCurveBSpline::New();
156  currentComposite->setParent(this);
157  currentComposite->setInteractor(d->interactor);
158  currentComposite->setData(currentData);
159  d->view->insert(currentData, currentComposite);
160  this->AddPart(currentComposite);
161  connect(currentData,SIGNAL(samplingChanged()),currentComposite,SLOT(onSamplingChanged()));
162  d->listCompositeActorChild << currentComposite;
163  }
164  else if(axlAbstractSurfaceBSpline *currentData = dynamic_cast<axlAbstractSurfaceBSpline *>(d->composite->get(i)))
165  {
167  currentComposite->setParent(this);
168  currentComposite->setInteractor(d->interactor);
169  currentComposite->setData(currentData);
170  d->view->insert(currentData, currentComposite);
171  this->AddPart(currentComposite);
172  connect(currentData,SIGNAL(samplingChanged()),currentComposite,SLOT(onSamplingChanged()));
173  d->listCompositeActorChild << currentComposite;
174  }
175  else if(axlAbstractVolumeBSpline *currentData = dynamic_cast<axlAbstractVolumeBSpline *>(d->composite->get(i)))
176  {
178  currentComposite->setParent(this);
179  currentComposite->setInteractor(d->interactor);
180  currentComposite->setData(currentData);
181  d->view->insert(currentData, currentComposite);
182  this->AddPart(currentComposite);
183  connect(currentData,SIGNAL(samplingChanged()),currentComposite,SLOT(onSamplingChanged()));
184  d->listCompositeActorChild << currentComposite;
185  }
186  else if(axlAbstractSurfaceTrimmed *currentData = dynamic_cast<axlAbstractSurfaceTrimmed *>(d->composite->get(i)))
187  {
189  currentComposite->setParent(this);
190  currentComposite->setInteractor(d->interactor);
191  currentComposite->setSurface(currentData);
192  d->view->insert(currentData, currentComposite);
193  this->AddPart(currentComposite);
194  connect(currentData,SIGNAL(samplingChanged()),currentComposite,SLOT(onSamplingChanged()));
195  d->listCompositeActorChild << currentComposite;
196  }
197  else if(axlCone *currentData = dynamic_cast<axlCone *>(d->composite->get(i)))
198  {
199  axlActorCone *currentComposite = axlActorCone::New();
200  currentComposite->setParent(this);
201  currentComposite->setInteractor(d->interactor);
202  currentComposite->setData(currentData);
203  d->view->insert(currentData, currentComposite);
204  this->AddPart(currentComposite);
205  d->listCompositeActorChild << currentComposite;
206 
207  }
208  else if(axlCylinder *currentData = dynamic_cast<axlCylinder *>(d->composite->get(i)))
209  {
210  axlActorCylinder *currentComposite = axlActorCylinder::New();
211  currentComposite->setParent(this);
212  currentComposite->setInteractor(d->interactor);
213  currentComposite->setData(currentData);
214  d->view->insert(currentData, currentComposite);
215  this->AddPart(currentComposite);
216  d->listCompositeActorChild << currentComposite;
217 
218  }
219  else if(axlTorus *currentData = dynamic_cast<axlTorus *>(d->composite->get(i)))
220  {
221  axlActorTorus *currentComposite = axlActorTorus::New();
222  currentComposite->setParent(this);
223  currentComposite->setInteractor(d->interactor);
224  currentComposite->setData(currentData);
225  d->view->insert(currentData, currentComposite);
226  this->AddPart(currentComposite);
227  d->listCompositeActorChild << currentComposite;
228 
229  }
230 // else if(axlCircleArc *currentData = dynamic_cast<axlCircleArc *>(d->composite->get(i)))
231 // {
232 // axlActorCircleArc *currentComposite = axlActorCircleArc::New();
233 // currentComposite->setParent(this);
234 // currentComposite->setInteractor(d->interactor);
235 // currentComposite->setCircleArc(currentData);
236 // d->view->insert(currentData, currentComposite);
237 // this->AddPart(currentComposite);
238 // d->listCompositeActorChild << currentComposite;
239 
240 // }
241  else if(axlEllipsoid *currentData = dynamic_cast<axlEllipsoid *>(d->composite->get(i)))
242  {
243  axlActorEllipsoid *currentComposite = axlActorEllipsoid::New();
244  currentComposite->setParent(this);
245  currentComposite->setInteractor(d->interactor);
246  currentComposite->setData(currentData);
247  d->view->insert(currentData, currentComposite);
248  this->AddPart(currentComposite);
249  d->listCompositeActorChild << currentComposite;
250 
251  }
252  else if(axlLine *currentData = dynamic_cast<axlLine *>(d->composite->get(i)))
253  {
254  axlActorLine *currentComposite = axlActorLine::New();
255  currentComposite->setParent(this);
256  currentComposite->setInteractor(d->interactor);
257  currentComposite->setData(currentData);
258  d->view->insert(currentData, currentComposite);
259  this->AddPart(currentComposite);
260  d->listCompositeActorChild << currentComposite;
261 
262  }
263  else if(axlPlane *currentData = dynamic_cast<axlPlane *>(d->composite->get(i)))
264  {
265  axlActorPlane *currentComposite = axlActorPlane::New();
266  currentComposite->setParent(this);
267  currentComposite->setInteractor(d->interactor);
268  currentComposite->setData(currentData);
269  d->view->insert(currentData, currentComposite);
270  this->AddPart(currentComposite);
271  d->listCompositeActorChild << currentComposite;
272 
273  }
274 // else if(axlPlane *currentData = dynamic_cast<axlPlane *>(d->composite->get(i)))
275 // {
276 // axlActorPlane *currentComposite = axlActorPlane::New();
277 // currentComposite->setParent(this);
278 // currentComposite->setInteractor(d->interactor);
279 // currentComposite->setData(currentData);
280 // d->view->insert(currentData, currentComposite);
281 // this->AddPart(currentComposite);
282 // d->listCompositeActorChild << currentComposite;
283 
284 // }
285  else if(axlSphere *currentData = dynamic_cast<axlSphere *>(d->composite->get(i)))
286  {
287  axlActorSphere *currentComposite = axlActorSphere::New();
288  currentComposite->setParent(this);
289  currentComposite->setData(currentData);
290  currentComposite->setInteractor(d->interactor);
291 
292  d->view->insert(currentData, currentComposite);
293  this->AddPart(currentComposite);
294  d->listCompositeActorChild << currentComposite;
295 
296  }
297 // else if(axlPointSet *currentData = dynamic_cast<axlPointSet *>(d->composite->get(i)))
298 // {
299 // axlActorPointSet *currentComposite = axlActorPointSet::New();
300 // currentComposite->setParent(this);
301 // currentComposite->setPointSet(currentData);
302 // d->view->insert(currentData, currentComposite);
303 // this->AddPart(currentComposite);
304 // d->listCompositeActorChild << currentComposite;
305 // }
306  else
307  {
308  axlActorMesh *currentComposite = axlActorMesh::New();
309  currentComposite->setParent(this);
310  currentComposite->setData(d->composite->get(i));
311  d->view->insert(d->composite->get(i), currentComposite);
312  this->AddPart(currentComposite);
313  d->listCompositeActorChild << currentComposite;
314  }
315  }
316 }
317 
318 
320 {
321 
322  vtkProp3DCollection *actors2 = this->GetParts();
323  actors2->InitTraversal();
324  for(int i = 0; i<actors2->GetNumberOfPaths(); i++)
325  {
326  vtkProp *path = actors2->GetNextProp();
327 
328  if (path != NULL)
329  {
330  if(axlAbstractActor *actorProp = dynamic_cast<axlAbstractActor *>(path))
331  {
332  actorProp->onControlPointChanged();
333  }
334  }
335  }
336 }
338 {
339  this->onModeChanged(state);
340 
341  emit stateChanged(this->data(), state);
342 }
343 
344 
346 {
347  if(state == 0)
348  {
350 
351  vtkSmartPointer<vtkPropCollection> actors = vtkSmartPointer<vtkPropCollection>::New();
352  this->GetActors(actors);
353  actors->InitTraversal();
354  QColor color;
355  if(axlAbstractDataComposite *composite = dynamic_cast<axlAbstractDataComposite *>(this->data()))
356  color = composite->color();
357  else
358  color.setRgb(1.0, 1.0, 1.0);
359 
360  for(int i = 0; i< actors->GetNumberOfItems(); i++)
361  {
362  vtkProp *prop = actors->GetNextProp();
363  if(vtkActor *actor = dynamic_cast<vtkActor *>(prop))
364  {
365  actor->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
366  }
367  }
368 
369  // we need to add renderer the axlActorComposite
370  // and to remove from the renderer and the all of the axlActor child of the axlActorComposite
371  d->renderer->AddActor(this);
372 
373  foreach(axlAbstractActor *abstractActor, d->listCompositeActorChild)
374  {
375  if(axlActor *actorProp = dynamic_cast<axlActor *>(abstractActor))
376  {
377  disconnect(actorProp, SIGNAL(stateChanged(dtkAbstractData*,int)), d->view, SIGNAL(stateChanged(dtkAbstractData*,int)));
378  d->renderer->RemoveActor(actorProp);
379  // this->AddPart(actorProp);
380  }
381  if(axlActorComposite *actorProp = dynamic_cast<axlActorComposite *>(abstractActor))
382  {
383  disconnect(actorProp, SIGNAL(stateChanged(dtkAbstractData*,int)), d->view, SIGNAL(stateChanged(dtkAbstractData*,int)));
384  d->renderer->RemoveActor(actorProp);
385  // this->AddPart(actorProp);
386  }
387  }
388 
389  // QList<axlActor *> listActorProp;
390 
391  // vtkProp3DCollection *actors2 = this->GetParts();
392  // actors2->InitTraversal();
393  // for(int i = 0; i<actors2->GetNumberOfPaths(); i++)
394  // {
395  // vtkProp *path = actors2->GetNextProp();
396 
397  // if (path != NULL)
398  // {
399  // if(axlActor *actorProp = dynamic_cast<axlActor *>(path))
400  // {
401  // disconnect(actorProp, SIGNAL(stateChanged(dtkAbstractData*,int)), d->view, SIGNAL(stateChanged(dtkAbstractData*,int)));
402  // d->renderer->RemoveActor(actorProp);
403  // listActorProp << actorProp;
404  // }
405  // }
406  // }
407 
408  // foreach (axlActor *actorProp, listActorProp)
409  // this->AddPart(actorProp);
410  }
411  else if(state == 1)
412  {
413  qDebug()<<"avant selection";
414  // mat = this->GetMatrix();
415  // mat->Identity();
416  // vtkMatrix4x4 *mat2 =this->GetMatrix();
417  //mat2->Identity();
418  // for(int j = 0; j <4 ; j ++)
419  // for(int i = 0; i <4 ; i ++)
420  // qDebug()<<j<< i << mat2->GetElement(j, i);
421 
423 
424  vtkSmartPointer<vtkPropCollection> actors = vtkSmartPointer<vtkPropCollection>::New();
425  this->GetActors(actors);
426  actors->InitTraversal();
427 
428  QColor color;
429  if(axlAbstractDataComposite *composite = dynamic_cast<axlAbstractDataComposite *>(this->data()))
430  {
431  color = composite->color();
432  qreal *h = new qreal(0.0);
433  qreal *s = new qreal(0.0);
434  qreal *l = new qreal(0.0);
435  color.getHslF(h, s, l);
436  color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
437  }
438  else
439  color.setRgb(0.0, 0.0, 1.0);
440 
441  for(int i = 0; i< actors->GetNumberOfItems(); i++)
442  {
443  vtkProp *prop = actors->GetNextProp();
444  if(vtkActor *actor = dynamic_cast<vtkActor *>(prop))
445  actor->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
446  }
447 
448  if(!d->renderer->HasViewProp(this))
449  {
450  d->renderer->AddActor(this);
451 
452  foreach(axlAbstractActor *abstractActor, d->listCompositeActorChild)
453  {
454  if(axlActor *actorProp = dynamic_cast<axlActor *>(abstractActor))
455  {
456  disconnect(actorProp, SIGNAL(stateChanged(dtkAbstractData*,int)), d->view, SIGNAL(stateChanged(dtkAbstractData*,int)));
457  d->renderer->RemoveActor(actorProp);
458  // this->AddPart(actorProp);
459  }
460  if(axlActorComposite *actorProp = dynamic_cast<axlActorComposite *>(abstractActor))
461  {
462  disconnect(actorProp, SIGNAL(stateChanged(dtkAbstractData*,int)), d->view, SIGNAL(stateChanged(dtkAbstractData*,int)));
463  d->renderer->RemoveActor(actorProp);
464  // this->AddPart(actorProp);
465  }
466  }
467 
468  // QList<axlActor *> listActorProp;
469 
470 
471  // vtkProp3DCollection *actors2 = this->GetParts();
472  // actors2->InitTraversal();
473  // for(int i = 0; i<actors2->GetNumberOfPaths(); i++)
474  // {
475  // vtkProp *path = actors2->GetNextProp();
476 
477  // if (path != NULL)
478  // {
479  // if(axlActor *actorProp = dynamic_cast<axlActor *>(path))
480  // {
481  // disconnect(actorProp, SIGNAL(stateChanged(dtkAbstractData*,int)), d->view, SIGNAL(stateChanged(dtkAbstractData*,int)));
482  // d->renderer->RemoveActor(actorProp);
483  // listActorProp << actorProp;
484  // }
485  // }
486  // }
487 
488  // foreach (axlActor *actorProp, listActorProp)
489  // this->AddPart(actorProp);
490  }
491  }
492  else if(state == 2)
493  {
495  vtkSmartPointer<vtkPropCollection> actors = vtkSmartPointer<vtkPropCollection>::New();
496  this->GetActors(actors);
497  actors->InitTraversal();
498 
499  QColor color;
500  if(axlAbstractDataComposite *composite = dynamic_cast<axlAbstractDataComposite *>(this->data()))
501  {
502  color = composite->color();
503  qreal *h = new qreal(0.0);
504  qreal *s = new qreal(0.0);
505  qreal *l = new qreal(0.0);
506  color.getHslF(h, s, l);
507  color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
508  }
509  else
510  color.setRgb(0.0, 0.0, 1.0);
511 
512  for(int i = 0; i< actors->GetNumberOfItems(); i++)
513  {
514 
515  vtkProp *prop = actors->GetNextProp();
516  if(vtkActor *actor = dynamic_cast<vtkActor *>(prop))
517  {
518  actor->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
519  }
520  };
521 
522  //vtkMatrix4x4 *mat = this->GetMatrix();
523 
524  qDebug()<<"avant";
525  // for(int j = 0; j <4 ; j ++)
526  // for(int i = 0; i <4 ; i ++)
527  // qDebug()<<j<< i << mat->GetElement(j, i);
528 
529  // we need to add renderer all of the axlActor composing the composite
530  // and to remove from the renderer the axlActorComposite
531  d->renderer->RemoveActor(this);
532 
533  vtkProp3DCollection *actors2 = this->GetParts();
534  actors2->InitTraversal();
535 
536  for(int i = 0 ; i < d->composite->count() ; i ++)
537  {
538  axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(d->composite->get(i));
539  axlData->setColor(d->composite->color());
540  }
541 
542  foreach(axlAbstractActor *abstractActor, d->listCompositeActorChild)
543  {
544  if(axlActor *actorProp = dynamic_cast<axlActor *>(abstractActor))
545  {
546  connect(actorProp, SIGNAL(stateChanged(dtkAbstractData*,int)), d->view, SIGNAL(stateChanged(dtkAbstractData*,int)));
547  d->renderer->AddActor(actorProp);
548  //this->RemovePart(actorProp);
549 
550  //setUp the vtkPropMatrix
551  // vtkMatrix4x4 *b = actorProp->GetMatrix();
552 
553  // vtkMatrix4x4::Multiply4x4(mat, b, b);
554  // vtkMatrix4x4 *c = actorProp->GetMatrix();
555  // qDebug()<<"avant";
556  // for(int j = 0; j <4 ; j ++)
557  // for(int i = 0; i <4 ; i ++)
558  // qDebug()<<j<< i << b->GetElement(j, i);
559  // qDebug()<<"avant c";
560  // for(int j = 0; j <4 ; j ++)
561  // for(int i = 0; i <4 ; i ++)
562  // qDebug()<<j<< i << c->GetElement(j, i);
563  }
564  if(axlActorComposite *actorProp = dynamic_cast<axlActorComposite *>(abstractActor))
565  {
566  connect(actorProp, SIGNAL(stateChanged(dtkAbstractData*,int)), d->view, SIGNAL(stateChanged(dtkAbstractData*,int)));
567  d->renderer->AddActor(actorProp);
568  // this->RemovePart(actorProp);
569  }
570  }
571 
572  // qDebug()<<"apres edition";
573  // mat = this->GetMatrix();
574  // mat->Identity();
575  // vtkMatrix4x4 *mat2 =this->GetMatrix();
576  //mat2->Identity();
577  // for(int j = 0; j <4 ; j ++)
578  // for(int i = 0; i <4 ; i ++)
579  // qDebug()<<j<< i << mat2->GetElement(j, i);
580 
581 
582  }
583 }
584 
585 void axlActorComposite::setColor(double red, double green, double blue)
586 {
587  Q_UNUSED(red);
588  Q_UNUSED(green);
589  Q_UNUSED(blue);
590 
591  if(axlAbstractData *data = dynamic_cast<axlAbstractData *>(this->data()))
592  {
593  QColor color = data->color();
594  vtkSmartPointer<vtkPropCollection> actors = vtkSmartPointer<vtkPropCollection>::New();
595  this->GetActors(actors);
596  actors->InitTraversal();
597 
598  if(this->getState() == axlActor::passive)
599  {
600  for(int i = 0; i< actors->GetNumberOfItems(); i++)
601  {
602  vtkProp *prop = actors->GetNextProp();
603  if(vtkActor *actor = dynamic_cast<vtkActor *>(prop))
604  {
605  actor->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
606  }
607  }
608  }
609 
610  else if(this->getState() == axlActor::selection || this->getState() == axlActor::edition)
611  {
612  qreal *h = new qreal(0.0);
613  qreal *s = new qreal(0.0);
614  qreal *l = new qreal(0.0);
615  color.getHslF(h, s, l);
616  color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
617 
618  for(int i = 0; i< actors->GetNumberOfItems(); i++)
619  {
620  vtkProp *prop = actors->GetNextProp();
621  if(vtkActor *actor = dynamic_cast<vtkActor *>(prop))
622  {
623  actor->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
624  }
625  }
626  }
627  }
628 }
629 
631 {
632  d->view = view;
633 }
634 
635 void axlActorComposite::setRenderer(vtkRenderer *renderer)
636 {
637  d->renderer = renderer;
638 }
639 
641 {
642  return (bool)(this->GetVisibility());
643 }
644 
645 void axlActorComposite::setInteractor(void *interactor)
646 {
647  d->interactor = static_cast<vtkRenderWindowInteractor *>(interactor);
648 
649 }
650 
651 vtkRenderWindowInteractor *axlActorComposite::getInteractor(void)
652 {
653  return d->interactor;
654 }
655 
657 {
658  if(d->observer == NULL)
659  {
660  d->observer = axlActorCompositeObserver::New();
661 
662  this->getInteractor()->AddObserver(vtkCommand::LeftButtonPressEvent, d->observer);
663  this->getInteractor()->AddObserver(vtkCommand::RightButtonPressEvent, d->observer);
664  this->getInteractor()->AddObserver(vtkCommand::InteractionEvent, d->observer);
665  this->getInteractor()->AddObserver(vtkCommand::KeyPressEvent, d->observer);
666  }
667  else
668  qDebug()<<"WARNING : You try to create an observer that it's already created";
669 }
670 
672 {
673  if(d->observer != NULL)
674  {
675  this->getInteractor()->RemoveObservers(vtkCommand::LeftButtonPressEvent, d->observer);
676  this->getInteractor()->RemoveObservers(vtkCommand::RightButtonPressEvent, d->observer);
677  this->getInteractor()->RemoveObservers(vtkCommand::InteractionEvent, d->observer);
678  this->getInteractor()->RemoveObservers(vtkCommand::KeyPressEvent, d->observer);
679 
680  d->observer->Delete();
681  d->observer = NULL;
682 
683  }
684  else
685  qDebug()<<"WARNING : You try to delete an observer that it's not initialized";
686 
687 }
688 
690 {
691  return d->State;
692 }
693 
695 {
696  d->State = state;
697 }
698 
699 
701 {
702  if(!d->actor) {
703  qDebug() << "No tet actor computed for this axlActorComposite";
704  return;
705  }
706 
707  if(display){
708  if(!this->GetParts()->IsItemPresent(d->actor)){
709  this->VisibilityOn();
710  }
711  }
712 
713  if(!display){
714  if (this->GetParts()->IsItemPresent(d->actor)!=0){
715  this->VisibilityOff();
716  }
717  }
718 }
719 
721 {
722  vtkProp3DCollection *actors2 = this->GetParts();
723  actors2->InitTraversal();
724  for(int i = 0; i<actors2->GetNumberOfPaths(); i++)
725  {
726  vtkProp *path = actors2->GetNextProp();
727 
728  if (path != NULL)
729  {
730  if(axlAbstractActor *actorProp = dynamic_cast<axlAbstractActor *>(path))
731  {
732  actorProp->onSamplingChanged();
733  }
734  }
735  }
736 }
737 
738 
739 
740 void axlActorComposite::setOpacity(double opacity)
741 {
742  if(axlAbstractDataComposite *composite = dynamic_cast<axlAbstractDataComposite *>(this->data()))
743  {
744  double opacity = composite->opacity();
745 
746  vtkSmartPointer<vtkPropCollection> actors = vtkSmartPointer<vtkPropCollection>::New();
747  this->GetActors(actors);
748  actors->InitTraversal();
749 
750  for(int i = 0; i< actors->GetNumberOfItems(); i++)
751  {
752  vtkProp *prop = actors->GetNextProp();
753  if(vtkActor *actor = dynamic_cast<vtkActor *>(prop))
754  {
755  actor->GetProperty()->SetOpacity(opacity);
756  }
757  }
758  }
759  this->Modified();
760 }
761 
762 void axlActorComposite::setShader(QString xmlfile)
763 {
764  if(QFile::exists(xmlfile))
765  {
766  vtkSmartPointer<vtkPropCollection> actors = vtkSmartPointer<vtkPropCollection>::New();
767  this->GetActors(actors);
768  actors->InitTraversal();
769 
770  for(int i = 0; i< actors->GetNumberOfItems(); i++)
771  {
772 
773  vtkProp *prop = actors->GetNextProp();
774  if(vtkActor *actor = dynamic_cast<vtkActor *>(prop))
775  {
776  vtkProperty *prop = actor->GetProperty();
777  if(QFile::exists(xmlfile))
778  {
779  QString currentShader = dtkReadFile(xmlfile);
780  this->setShaderFromString(currentShader);
781  prop->GetShading();
782 
783  }
784  else
785  {
786  prop->vtkProperty::ShadingOff();
787  }
788  }
789  }
790 
791  this->Modified();
792 
793  }
794 }
795 
797 { vtkSmartPointer<vtkPropCollection> actors = vtkSmartPointer<vtkPropCollection>::New();
798  this->GetActors(actors);
799  actors->InitTraversal();
800 
801  for(int i = 0; i< actors->GetNumberOfItems(); i++)
802  {
803 
804  vtkProp *prop = actors->GetNextProp();
805  if(vtkActor *actor = dynamic_cast<vtkActor *>(prop))
806  {
807  vtkProperty *prop = actor->GetProperty();
808  if(xmlfile != "")
809  {
810  //prop->vtkProperty::LoadMaterialFromString(xmlfile.toStdString().c_str());
811  prop->GetShading();
812  prop->vtkProperty::ShadingOn();
813  }
814  else
815  {
816  prop->vtkProperty::ShadingOff();
817  }
818  }
819  }
820 
821  this->Modified();
822 }
823 
824 
825 // slots---------------------------
826 
828 {
829  this->VisibilityOff();
830  this->Modified();
831 }
832 
834 {
835  this->VisibilityOn();
836  this->Modified();
837 }
838 
840 {
841  this->Modified();
842 }
843 
844 
846 {
847  this->getInteractor()->RemoveObservers(vtkCommand::LeftButtonPressEvent, d->observer);
848  this->getInteractor()->RemoveObservers(vtkCommand::RightButtonPressEvent, d->observer);
849  this->getInteractor()->RemoveObservers(vtkCommand::InteractionEvent, d->observer);
850  this->getInteractor()->RemoveObservers(vtkCommand::KeyPressEvent, d->observer);
851  this->RemoveObserver(d->observer);
852 
853  if(this->getState() == axlActorComposite::edition)
854  {
855  foreach (axlAbstractActor *abstracActor, d->listCompositeActorChild)
856  {
857  if(abstracActor)
858  {
859  if(axlActor *actor = dynamic_cast<axlActor *>(abstracActor))
860  d->renderer->RemoveActor(actor);
861  else if(axlActorComposite *actorComposite = dynamic_cast<axlActorComposite *>(abstracActor))
862  d->renderer->RemoveActor(actorComposite);
863 
864  d->view->removeData(abstracActor->data());
865 
866  }
867  }
868  }
869 
870  foreach (axlAbstractActor *abstracActor, d->listCompositeActorChild)
871  {
872  if(abstracActor)
873  {
874  abstracActor->onRemoved();
875  if(axlActor *actor = dynamic_cast<axlActor *>(abstracActor))
876  {
877  if(axlActorBSpline *actorBSlpine = dynamic_cast<axlActorBSpline *>(abstracActor))
878  disconnect(actorBSlpine->data(),SIGNAL(samplingChanged()),actorBSlpine,SLOT(onSamplingChanged()));
879  this->RemovePart(actor);
880  actor->Delete();
881  }
882  else if(axlActorComposite *actorComposite = dynamic_cast<axlActorComposite *>(abstracActor))
883  {
884  this->RemovePart(actorComposite);
885  actorComposite->Delete();
886  }
887  abstracActor=NULL;
888  d->listCompositeActorChild.removeOne(abstracActor);
889  }
890  }
891 
892  //this->getActor()->RemoveAllObservers();
893  //this->Delete();
894 }
895 axlActorComposite::axlActorComposite(void) : axlAbstractActor(),vtkAssembly(), d(new axlActorCompositePrivate)
896 {
897  d->State = axlActorComposite::passive;
898  d->CpCursorPicker = vtkSmartPointer<vtkCellPicker>::New();
899  d->CpCursorPicker->SetTolerance(0.001);
900  d->observer = NULL;
901 }
902 
904 {
905  delete d;
906 
907  d = NULL;
908 }
909 
911 
912  return axlActorComposite::New();
913 }
static axlActorSphere * New(void)
virtual void setData(dtkAbstractData *line1)
Class axlLine defines 3D lines.
Definition: axlLine.h:35
static axlActorCylinder * New(void)
virtual dtkAbstractData * data(void)=0
void stateChanged(dtkAbstractData *data, int mode)
virtual void setData(dtkAbstractData *spline_Surface1)
virtual void setInteractor(void *interactor)
virtual bool isVisible(void)
Class axlCylinder defines 3D cylinders.
Definition: axlCylinder.h:33
static axlActorCone * New(void)
Class axlPlane defines 3D planes.
Definition: axlPlane.h:34
virtual void setData(dtkAbstractData *spline_curve1)
virtual void onRemoved(void)
static axlActorCompositeObserver * New(void)
static axlActorVolumeBSpline * New(void)
virtual dtkAbstractData * data(void)
virtual void setData(dtkAbstractData *spline_Volume1)
virtual void setData(dtkAbstractData *data1)
axlAbstractActor * createAxlActorComposite(void)
static axlActorPlane * New(void)
void setView(axlAbstractView *view)
virtual void setInteractor(void *interactor)
Definition: axlActor.cpp:254
virtual void update(void)
virtual void onRemoved(void)
static axlActorCurveBSpline * New(void)
static axlActorLine * New(void)
virtual void setParent(axlAbstractActor *parent)
static axlActorSurfaceBSpline * New(void)
void setData(dtkAbstractData *data)
Class axlSphere defines 3D spheres.
Definition: axlSphere.h:33
virtual void setData(dtkAbstractData *cylinder1)
bool removeActorReference(axlAbstractActor *actor)
virtual void setColor(double red, double green, double blue)
virtual void setData(dtkAbstractData *cone1)
virtual void setData(dtkAbstractData *torus1)
virtual void setShaderFromString(QString xmlfile)
virtual void show(void)
virtual void setData(dtkAbstractData *sphere1)
void setRenderer(vtkRenderer *renderer)
static axlActorComposite * New(void)
virtual void setMode(int state)
virtual void setState(int state)
virtual void setOpacity(double opacity)
virtual void setData(dtkAbstractData *plane1)
virtual void setData(dtkAbstractData *ellipsoid1)
virtual void Execute(vtkObject *caller, unsigned long event, void *)
virtual vtkRenderWindowInteractor * getInteractor(void)
vtkStandardNewMacro(axlActorComposite)
virtual void hide(void)
Class axlCone defines 3D cones.
Definition: axlCone.h:34
static axlActorMesh * New(void)
static axlActorSurfaceTrimmed * New(void)
void setSurface(axlAbstractSurfaceTrimmed *Surface)
virtual void onControlPointChanged()
virtual void onSamplingChanged(void)
void setColor(double r, double g, double b)
vtkCxxRevisionMacro(axlActorComposite,"$Revision: 0.0.1 $")
Class axlEllipsoid defines 3D ellipsoids.
Definition: axlEllipsoid.h:35
virtual void onModeChanged(int state)
Class axlAbstractData defines an API for all type of axel data.
static axlActorTorus * New(void)
virtual int getState(void)
virtual void setShader(QString xmlfile)
virtual void setDisplay(bool display)