Developer documentation | Axl-2.5.1

axlVtkView.cpp
Go to the documentation of this file.
1 /* axlVtkView.cpp ---
2  *
3  * Author: Julien Wintz
4  * Copyright (C) 2008 - Julien Wintz, Inria.
5  * Created: Wed Mar 30 09:19:37 2011 (+0200)
6  * Version: $Id$
7  * Last-Updated: Mon Dec 17 16:52:43 2012 (+0100)
8  * By: Julien Wintz
9  * Update #: 172
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlActorDataDynamic.h"
21 #include "axlActorComposite.h"
22 #include "axlActorCone.h"
23 #include "axlActorCylinder.h"
24 #include "axlActorTorus.h"
25 //#include "axlActorCircleArc.h"
26 #include "axlActorEllipsoid.h"
27 #include "axlActorFieldDiscrete.h"
28 #include "axlActorFieldSpatial.h"
30 #include "axlActorMesh.h"
31 #include "axlActorLine.h"
32 #include "axlActorPlane.h"
33 #include "axlActorPoint.h"
34 #include "axlActorPointSet.h"
35 #include "axlActorCurveBSpline.h"
36 #include "axlActorSphere.h"
37 #include "axlActorSurfaceBSpline.h"
38 #include "axlActorVolumeBSpline.h"
39 #include "axlActorShapeBSpline.h"
40 #include "axlActorSurfaceTrimmed.h"
43 #include "axlLightsWidget.h"
45 #include "axlActorVolumeDiscrete.h"
46 #include "axlVolumeDiscrete.h"
47 
48 #include "axlVtkView.h"
49 #include "axlVtkViewPlugin.h"
50 
51 #include <dtkCoreSupport/dtkAbstractViewFactory.h>
52 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
53 #include <dtkCoreSupport/dtkGlobal.h>
54 
55 #include <axlCore/axlDataDynamic.h>
59 //#include "axlFieldDiscrete.h"
67 #include <axlCore/axlCone.h>
68 #include <axlCore/axlCylinder.h>
69 #include <axlCore/axlTorus.h>
70 #include <axlCore/axlCircleArc.h>
71 #include <axlCore/axlEllipsoid.h>
72 #include <axlCore/axlLine.h>
73 #include <axlCore/axlPlane.h>
74 //#include <axlCore/axlPointSet.h>
75 #include <axlCore/axlMesh.h>
76 #include <axlCore/axlSphere.h>
77 
78 #include <vtkActor.h>
79 #include <vtkActorCollection.h>
80 #include <vtkAssemblyNode.h>
81 #include <vtkAssemblyPath.h>
82 #include <vtkAxesActor.h>
83 #include <vtkCamera.h>
84 #include <vtkCellPicker.h>
85 #include <vtkImageData.h>
86 #include <vtkInteractorStyleTrackballCamera.h>
87 #include <vtkInteractorStyleJoystickCamera.h>
88 #include <vtkInteractorStyleRubberBandPick.h>
89 #include <vtkInteractorStyleJoystickActor.h>
90 #include <vtkInteractorStyleTrackballActor.h>
91 #include <vtkLight.h>
92 #include <vtkLightActor.h>
93 #include <vtkLightKit.h>
94 #include <vtkLightCollection.h>
95 #include <vtkPlaneSource.h>
96 #include <vtkPolyDataMapper.h>
97 #include <vtkDataSetMapper.h>
98 #include <vtkProp3DCollection.h>
99 #include <vtkRenderer.h>
100 #include <vtkRendererCollection.h>
101 #include <vtkRenderWindow.h>
102 #include <vtkRenderWindowInteractor.h>
103 #include <vtkSmartPointer.h>
104 #include <vtkTexture.h>
105 #include <vtkTimerLog.h>
106 #include <vtkCallbackCommand.h>
107 #include <vtkVersion.h>
108 #include <vtkStripper.h>
109 #include <vtkPointData.h>
110 #include <vtkTriangleFilter.h>
111 #include <vtkPNGReader.h>
112 #include <vtkFloatArray.h>
113 #include <vtkGenericOpenGLRenderWindow.h>
114 //#include <vtkOpenGLHardwareSupport.h>
115 #include <vtkOpenGLRenderWindow.h>
116 //#include <vtkPainterPolyDataMapper.h>
117 #include <vtkProperty.h>
118 
119 #include <QtOpenGL>
120 #include <QVTKOpenGLWidget.h>
121 #include <QVTKInteractor.h>
122 
123 #include "axlVtkViewPlugin.h"
124 
125 class vtkViewObserver : public vtkCommand
126 {
127 public:
128  static vtkViewObserver *New(void)
129  {
130  return new vtkViewObserver;
131  }
132 
133  virtual void Execute(vtkObject *caller, unsigned long event, void *)
134  {
135  //qDebug()<<"axlVtkView Execute : "<<observerRenderer->GetNumberOfPropsRendered();
136  if(event == vtkCommand::LeftButtonPressEvent && observerInteractor->GetShiftKey())
137  {
138  //first try to pick an actor
139 
140  vtkAssemblyPath *path;
141  vtkRenderWindow *renderWindow = observerInteractor->GetRenderWindow();
142  vtkRendererCollection * rendererCollection = renderWindow->GetRenderers();
143  vtkRenderer *render = rendererCollection->GetFirstRenderer();
144  int X = observerInteractor->GetEventPosition()[0];
145  int Y = observerInteractor->GetEventPosition()[1];
146 
147  if (!render || !render->IsInViewport(X, Y))
148  {
149  qDebug()<<" No renderer or bad cursor coordonates in axlVtkView";
150  }
151 
152  observerViewerPicker->Pick(X,Y,0.0,render);
153 
154  path = observerViewerPicker->GetPath();
155 
156  // we need to iterate on the actors of the renderer
157 
158  if (path != NULL)
159  {
160 
161  vtkPropCollection *actorCollection = observerRenderer->GetViewProps();
162  actorCollection->InitTraversal();
163 
164  for(int i = 0; i < actorCollection->GetNumberOfItems(); i++)
165  {
166  vtkProp *currentActor = actorCollection->GetNextProp();
167  if(path->GetFirstNode()->GetViewProp() == currentActor)
168  {
169  if(axlAbstractActor *actorProp = dynamic_cast<axlAbstractActor *>(currentActor))
170  {/*qDebug()<<"vtkViewObserver::Execute";*/
171  if(actorProp->getState() == axlActorComposite::passive)
172  actorProp->setMode(axlActorComposite::selection);
173  else if(actorProp->getState() == axlActorComposite::selection)
174  actorProp->setMode(axlActorComposite::passive);
175  }
176  }
177  }
178  }
179  }
180 
181  if(event == vtkCommand::RightButtonPressEvent && observerInteractor->GetShiftKey())
182  {
183 
184  //first try to pick an actor
185 
186  vtkAssemblyPath *path;
187  vtkRenderWindow *renderWindow = observerInteractor->GetRenderWindow();
188  vtkRendererCollection * rendererCollection = renderWindow->GetRenderers();
189  vtkRenderer *render = rendererCollection->GetFirstRenderer();
190  int X = observerInteractor->GetEventPosition()[0];
191  int Y = observerInteractor->GetEventPosition()[1];
192 
193  if (!render || !render->IsInViewport(X, Y))
194  {
195  //qDebug()<<" No renderer or bad cursor coordonates";
196  }
197 
198  observerViewerPicker->Pick(X,Y,0.0,render);
199 
200  path = observerViewerPicker->GetPath();
201 
202  // we need to iterate on the actors of the renderer
203 
204  if (path == NULL)
205  {
206  vtkPropCollection *actorCollection = observerRenderer->GetViewProps();
207  actorCollection->InitTraversal();
208 
209  for(int i = 0; i < actorCollection->GetNumberOfItems(); i++)
210  {
211  vtkProp *currentActor = actorCollection->GetNextProp();
212  if(axlAbstractActor *actorProp = dynamic_cast<axlAbstractActor *>(currentActor))
213  actorProp->setMode(axlActor::passive);
214 
215  }
216  }
217  }
218 
219  if(event == vtkCommand::KeyPressEvent)
220  {
221  QString modifier(observerInteractor->GetKeySym());
222  if(modifier.compare("x") == 0 && observerAxesActor)
223  {
224  observerAxesActor->SetVisibility(!observerAxesActor->GetVisibility());
225 
226  // update view
227  widget->update();
228  widget->GetRenderWindow()->Render();
229  }
230  else if(modifier.compare("e") || modifier.compare("u"))
231  {
232  vtkPropCollection *actorCollection = observerRenderer->GetViewProps();
233  actorCollection->InitTraversal();
234  for(int i = 0; i < actorCollection->GetNumberOfItems(); i++)
235  {
236  vtkProp *currentActor = actorCollection->GetNextProp();
237  if(axlAbstractActor *actorProp = dynamic_cast<axlAbstractActor *>(currentActor))
238  {
239  if(modifier.compare("e") == 0 && actorProp->getState()==axlActor::selection)//Tab Active : mode editable change
240  actorProp->setMode(axlActor::edition);
241 
242  if(modifier.compare("u") == 0 && actorProp->getState()==axlActor::edition)//Tab Active : mode editable change
243  actorProp->setMode(axlActor::selection);
244  }
245 
246  }
247  }
248  }
249 
250 // if(event =mmit= vtkCommand::MouseMoveEvent)
251 // {
252 // qDebug()<< "axlVtkView Execute Mouse Move" ;
253 // }
254 
255  }
256 
257  vtkSmartPointer<vtkCellPicker> observerViewerPicker;
258  vtkRenderWindowInteractor *observerInteractor;
259  vtkSmartPointer<vtkRenderer> observerRenderer;
260  vtkSmartPointer<vtkAxesActor> observerAxesActor;
261  QVTKOpenGLWidget *widget;
262 };
263 
264 // /////////////////////////////////////////////////////////////////
265 // vtkViewPrivate
266 // /////////////////////////////////////////////////////////////////
267 
268 class vtkViewPrivate
269 {
270 public:
271  vtkSmartPointer<axlInteractorStyleSwitch> style;
272  vtkSmartPointer<vtkCellPicker> viewerPicker;
273 
274  vtkRenderer *renderer;
275 
276 // vtkSmartPointer<vtkGenericOpenGLRenderWindow> window;
277  vtkNew<vtkGenericOpenGLRenderWindow> window;
278  vtkSmartPointer<vtkViewObserver> observer;
279 
280  QVTKOpenGLWidget *widget;
281 
282  vtkSmartPointer<vtkLightKit> lightKit;
283  vtkSmartPointer<vtkLight> firstLight;
284 
285  axlLightsWidget *lightWidget;
286 
287  vtkSmartPointer<vtkLightActor> lightActor;
288 
289  double camera_center[3];
290  double camera_focal[3];
291  double camera_view_up[3];
292 
293  bool lastCameraIsDefault;
294 
295  vtkSmartPointer<vtkActor> actorX;
296  vtkSmartPointer<vtkActor> actorY;
297  vtkSmartPointer<vtkActor> actorZ;
298  vtkSmartPointer<vtkAxesActor> axesActor;
299  vtkSmartPointer<vtkPlaneSource> planeSourceX;
300  vtkSmartPointer<vtkPlaneSource> planeSourceY;
301  vtkSmartPointer<vtkPlaneSource> planeSourceZ;
302 
303  bool isGridX;
304  bool isGridY;
305  bool isGridZ;
306 };
307 
308 // /////////////////////////////////////////////////////////////////
309 // axlVtkView
310 // /////////////////////////////////////////////////////////////////
311 
312 axlVtkView::axlVtkView(void) : axlAbstractView(), d(new vtkViewPrivate)
313 {
314 
315  d->renderer = vtkRenderer::New();
316  d->renderer->SetGradientBackground(true);
317  d->renderer->SetBackground (0.90, 0.90, 0.90);
318  d->renderer->SetBackground2(0.64, 0.64, 0.64);
319 
320  QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
321  d->widget = new QVTKOpenGLWidget;
322  d->widget->SetRenderWindow(d->window.Get());
323 //#if (VTK_MAJOR_VERSION <= 5)
324 // d->window = vtkSmartPointer<vtkRenderWindow>::New();
325 //#else
326 // d->window = d->widget->GetRenderWindow();
327 //#endif
328 
329  d->window->SetPointSmoothing(1);
330  d->window->SetLineSmoothing(1);
331  // Uncommenting shows edges on top of objects with certain graphic cards
332  // d->window->SetPolygonSmoothing(1);
333  d->window->StereoCapableWindowOn();
334 
335  // stereo mode
336  if(qApp->arguments().contains("--stereo")) {
337  QString stereoMode = dtkApplicationArgumentsValue(qApp,"--stereo");
338  //--stereo ANAGLYPHIC | QUAD_BUFFER | HORIZONTAL_SPLIT | HORIZONTAL_INTERLACE
339  if (stereoMode == "QUAD_BUFFER") {
340  d->window->SetStereoTypeToCrystalEyes();
341  } else if (stereoMode == "HORIZONTAL_SPLIT") {
342  d->window->SetStereoTypeToSplitViewportHorizontal();
343  } else if (stereoMode == "HORIZONTAL_INTERLACE") {
344  d->window->SetStereoTypeToInterlaced();
345  } else if (stereoMode == "ANAGLYPHIC") {
346  d->window->SetStereoTypeToAnaglyph();
347  } else {
348  qDebug() << "WARNING: Unknown stereo mode ("<< stereoMode << "), will use QUAD BUFFER" ;
349  d->window->SetStereoTypeToCrystalEyes();
350  }
351  d->window->SetStereoRender(1);
352  }
353 
354  d->window->AddRenderer(d->renderer);
355 
356 #if (VTK_MAJOR_VERSION <= 5)
357  d->widget->SetRenderWindow(d->window);
358 #endif
359 
360  d->observer = NULL;
361 
362  d->viewerPicker = vtkSmartPointer<vtkCellPicker>::New();
363  d->viewerPicker->SetTolerance(0.001);
364 
365  d->style = vtkSmartPointer<axlInteractorStyleSwitch>::New();
366  d->style->SetDefaultRenderer(d->renderer);
367 
368  d->axesActor = vtkSmartPointer<vtkAxesActor>::New();
369  d->axesActor->AxisLabelsOff();
370  d->axesActor->SetConeRadius(0.3);
371  d->axesActor->SetNormalizedTipLength(0.1, 0.1, 0.1);
372  d->axesActor->SetNormalizedShaftLength(0.9, 0.9, 0.9);
373  d->axesActor->SetShaftTypeToCylinder();
374  d->axesActor->SetCylinderRadius(0.005);
375 
376  d->renderer->AddActor(d->axesActor);
377  d->renderer->ResetCamera();
378 
379  //grid
380  d->isGridX = false;
381  d->isGridY = false;
382  d->isGridZ = false;
383 
384  //lightKit->AddLightsToRenderer(d->renderer);
385 
386  vtkCamera *camera = d->renderer->GetActiveCamera();
387  camera->GetPosition(d->camera_center);
388  camera->GetFocalPoint(d->camera_focal);
389  camera->GetViewUp(d->camera_view_up);
390  d->lastCameraIsDefault = true;
391 
392  d->lightWidget=NULL;
393  d->lightActor= NULL;
394 
395  //observer
396  d->observer = vtkViewObserver::New();
397  d->observer->observerViewerPicker = d->viewerPicker;
398  d->observer->observerRenderer = d->renderer;
399  d->observer->observerInteractor = d->widget->GetInteractor();
400  d->observer->observerAxesActor = d->axesActor;
401  d->observer->widget = d->widget;
402 
403  d->widget->GetInteractor()->AddObserver(vtkCommand::LeftButtonPressEvent, d->observer);
404  d->widget->GetInteractor()->AddObserver(vtkCommand::RightButtonPressEvent, d->observer);
405  d->widget->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent, d->observer);
406 
407  d->widget->setFocusPolicy(Qt::StrongFocus);
408 }
409 
411 {
412 
413  if(d->lightWidget)
414  d->lightWidget->Delete();
415 
416 
417  d->widget->GetInteractor()->RemoveObservers(vtkCommand::LeftButtonPressEvent, d->observer);
418  d->widget->GetInteractor()->RemoveObservers(vtkCommand::RightButtonPressEvent, d->observer);
419  d->widget->GetInteractor()->RemoveObservers(vtkCommand::KeyPressEvent, d->observer);
420 
421  d->observer->observerViewerPicker = NULL;
422  d->observer->observerRenderer = NULL;
423  d->observer->observerInteractor = NULL;
424 
425  d->observer->Delete();
426  d->observer = NULL;
427 
428  d->renderer->Delete();
429  d->renderer = NULL;
430 
431  delete d;
432 
433  d = NULL;
434 }
435 
437 {
438  //qDebug()<< "axlVtkView::registered"<<dtkAbstractDataFactory::instance()<<vtkViewPlugin::viewFactSingleton;
439  return axlVtkViewPlugin::viewFactSingleton->registerViewType("axlVtkView", createVtkView);
440 }
441 
442 QString axlVtkView::description(void) const
443 {
444  return "axlVtkView";
445 }
446 
448 {
449  if(dynamic_cast<vtkInteractorStyleJoystickActor *> (d->style->GetCurrentStyle()))
450  d->style->SetCurrentStyleToJoystickCamera();
451 
452  if(dynamic_cast<vtkInteractorStyleTrackballActor *> (d->style->GetCurrentStyle()))
453  d->style->SetCurrentStyleToTrackballCamera();
454 }
455 
457 {
458  if(dynamic_cast<vtkInteractorStyleJoystickCamera *> (d->style->GetCurrentStyle()))
459  d->style->SetCurrentStyleToJoystickActor();
460 
461  if(dynamic_cast<vtkInteractorStyleTrackballCamera *> (d->style->GetCurrentStyle()))
462  d->style->SetCurrentStyleToTrackballActor();
463 }
464 
466 {
467  if(dynamic_cast<vtkInteractorStyleJoystickActor *> (d->style->GetCurrentStyle()))
468  d->style->SetCurrentStyleToTrackballActor();
469 
470  if(dynamic_cast<vtkInteractorStyleJoystickCamera *> (d->style->GetCurrentStyle()))
471  d->style->SetCurrentStyleToTrackballCamera();
472 }
473 
475 {
476  if(dynamic_cast<vtkInteractorStyleTrackballActor *> (d->style->GetCurrentStyle()))
477  d->style->SetCurrentStyleToJoystickActor();
478 
479  if(dynamic_cast<vtkInteractorStyleTrackballCamera *> (d->style->GetCurrentStyle()))
480  d->style->SetCurrentStyleToJoystickCamera();
481 }
482 
483 void axlVtkView::bounds(float& xmin, float& xmax, float& ymin, float& ymax, float& zmin, float& zmax)
484 {
485  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
486 
487  xmin = bounds[0];
488  xmax = bounds[1];
489  ymin = bounds[2];
490  ymax = bounds[3];
491  zmin = bounds[4];
492  zmax = bounds[5];
493 }
494 
495 void axlVtkView::cameraUp(double *coordinates)
496 {
497  vtkCamera *camera = d->renderer->GetActiveCamera();
498 
499  camera->GetViewUp(coordinates);
500 }
501 
502 void axlVtkView::cameraPosition(double *coordinates)
503 {
504  vtkCamera *camera = d->renderer->GetActiveCamera();
505 
506  camera->GetPosition(coordinates);
507 }
508 
509 void axlVtkView::cameraFocalPoint(double *coordinates)
510 {
511  vtkCamera *camera = d->renderer->GetActiveCamera();
512 
513  camera->GetFocalPoint(coordinates);
514 }
515 
516 void axlVtkView::setCameraPosition(double x, double y, double z)
517 {
518  vtkCamera *camera = d->renderer->GetActiveCamera();
519 
520  camera->SetPosition(x, y, z);
521 
522  d->renderer->ResetCameraClippingRange();
523 }
524 
525 QList<axlAbstractActor *> axlVtkView::insertSet(QList<axlAbstractData *> dataSet)
526 {
527  vtkRenderWindowInteractor *iren = d->widget->GetInteractor();
528  d->widget->GetInteractor()->SetInteractorStyle(d->style);
529 
530  // Move before
531 
532  QList<axlAbstractActor *> result;
533 
534  double currentTime = vtkTimerLog::GetCPUTime();
535  //double start = clock();
536  //qDebug()<<"axlVtkView cpu time "<<start;
537  dtkWarn()<<"Start time"<<currentTime;
538  QList<axlAbstractData *>::Iterator data;
539 
540  for(data = dataSet.begin(); data != dataSet.end(); data++)
541  {
542  if (axlPoint *point = dynamic_cast<axlPoint *>(*data)) {
543 
545 
546  actor->setInteractor(iren);
547  actor->setQVTKWidget(d->widget);
548  actor->setData(point);
549 
550  actor->setDisplay(true);
551 
552  d->renderer->AddActor(actor);
553 
554  axlAbstractView::insert(point, actor);
555  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
556  connect(actor, SIGNAL(updated()), this, SLOT(update()));
557  result.push_back(actor);
558  }
559  else if (axlCone *cone = dynamic_cast<axlCone *>(*data)) {
560 
562 
563  actor->setInteractor(iren);
564  actor->setQVTKWidget(d->widget);
565  actor->setData(cone);
566 
567  //actor->setDisplay(true);
568 
569  d->renderer->AddActor(actor);
570 
571  axlAbstractView::insert(cone, actor);
572  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
573  connect(actor, SIGNAL(updated()), this, SLOT(update()));
574  result.push_back(actor);
575  }
576  else if (axlCylinder *cylinder = dynamic_cast<axlCylinder *>(*data)) {
577 
579 
580  actor->setInteractor(iren);
581  actor->setQVTKWidget(d->widget);
582  actor->setData(cylinder);
583 
584  //actor->setDisplay(true);
585 
586  d->renderer->AddActor(actor);
587 
588  axlAbstractView::insert(cylinder, actor);
589  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
590  connect(actor, SIGNAL(updated()), this, SLOT(update()));
591  result.push_back(actor);
592  }
593  else if (axlTorus *torus = dynamic_cast<axlTorus *>(*data)) {
594 
596 
597  actor->setInteractor(iren);
598  actor->setQVTKWidget(d->widget);
599  actor->setData(torus);
600 
601  //actor->setDisplay(true);
602 
603  d->renderer->AddActor(actor);
604 
605  axlAbstractView::insert(torus, actor);
606  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
607  connect(actor, SIGNAL(updated()), this, SLOT(update()));
608  result.push_back(actor);
609  }
610  // else if (axlCircleArc *arc = dynamic_cast<axlCircleArc *>(*data)) {
611 
612  // axlActorCircleArc *actor = axlActorCircleArc::New();
613 
614  // actor->setInteractor(iren);
615  // actor->setQVTKWidget(d->widget);
616  // actor->setCircleArc(arc);
617 
618  // //actor->setDisplay(true);
619 
620  // d->renderer->AddActor(actor);
621 
622  // axlAbstractView::insert(arc, actor);
623  // connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
624  // result.push_back(actor);
625  // }
626  else if (axlEllipsoid *ellipsoid = dynamic_cast<axlEllipsoid *>(*data)) {
627 
628  axlActorEllipsoid *actor = axlActorEllipsoid::New();
629 
630  actor->setInteractor(iren);
631  actor->setQVTKWidget(d->widget);
632  actor->setData(ellipsoid);
633 
634  //actor->setDisplay(true);
635 
636  d->renderer->AddActor(actor);
637 
638  axlAbstractView::insert(ellipsoid, actor);
639  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
640  connect(actor, SIGNAL(updated()), this, SLOT(update()));
641  result.push_back(actor);
642  }
643  else if (axlLine *line = dynamic_cast<axlLine *>(*data)) {
644 
646 
647  actor->setInteractor(iren);
648  actor->setQVTKWidget(d->widget);
649  actor->setData(line);
650 
651  //actor->setDisplay(true);
652 
653  d->renderer->AddActor(actor);
654 
655  axlAbstractView::insert(line, actor);
656  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
657  connect(actor, SIGNAL(updated()), this, SLOT(update()));
658  result.push_back(actor);
659  }
660  else if (axlPlane *plane = dynamic_cast<axlPlane *>(*data)) {
661 
663 
664  actor->setInteractor(iren);
665  actor->setQVTKWidget(d->widget);
666  actor->setRenderer(d->renderer);
667  actor->setData(plane);
668 
669  //actor->setDisplay(true);
670 
671  d->renderer->AddActor(actor);
672 
673  axlAbstractView::insert(plane, actor);
674  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
675  connect(actor, SIGNAL(updated()), this, SLOT(update()));
676  result.push_back(actor);
677  }
678  else if (axlSphere *sphere = dynamic_cast<axlSphere *>(*data)) {
679 
681 
682  actor->setInteractor(iren);
683  actor->setData(sphere);
684 
685  actor->setDisplay(true);
686 
687  d->renderer->AddActor(actor);
688 
689  axlAbstractView::insert(sphere, actor);
690  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
691  connect(actor, SIGNAL(updated()), this, SLOT(update()));
692  result.push_back(actor);
693  }
694  else if (axlAbstractCurveBSpline *spline_curve = dynamic_cast<axlAbstractCurveBSpline *>(*data)) {
695 
697 
698  actor->setInteractor(iren);
699  actor->setData(spline_curve);
700 
701  d->renderer->AddActor(actor);
702 
703  axlAbstractView::insert(spline_curve, actor);
704  connect(actor, SIGNAL(stateChanged(dtkAbstractData *, int)), this, SIGNAL(stateChanged(dtkAbstractData *, int)));
705  connect(spline_curve, SIGNAL(samplingChanged()), actor, SLOT(onSamplingChanged()));
706  connect(actor, SIGNAL(updated()), this, SLOT(update()));
707  result.push_back(actor);;
708  }
709  else if (axlAbstractSurfaceTrimmed *spline_surface = dynamic_cast<axlAbstractSurfaceTrimmed *>(*data)) {
710 
712  actor->setInteractor(iren);
713 
714  actor->setSurface(spline_surface);
715  d->renderer->AddActor(actor);
716 
717  axlAbstractView::insert(spline_surface, actor);
718  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
719  connect(spline_surface,SIGNAL(samplingChanged()),actor,SLOT(onSamplingChanged()));
720 
721  result.push_back(actor);
722  }
723  else if (axlAbstractSurfaceBSpline *spline_surface = dynamic_cast<axlAbstractSurfaceBSpline *>(*data)) {
724 
726  actor->setInteractor(iren);
727 
728  actor->setData(spline_surface);
729  d->renderer->AddActor(actor);
730 
731  axlAbstractView::insert(spline_surface, actor);
732  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
733  connect(spline_surface,SIGNAL(samplingChanged()),actor,SLOT(onSamplingChanged()));
734  connect(actor, SIGNAL(updated()), this, SLOT(update()));
735  //connect(spline_surface, SIGNAL(touch()), this, SLOT(update()));
736 
737  //this->insertFields(spline_surface, actor);
738 
739  result.push_back(actor);
740  }
741  else if (axlAbstractVolumeBSpline *spline_volume = dynamic_cast<axlAbstractVolumeBSpline *>(*data)) {
742 
744  actor->setInteractor(iren);
745 
746  actor->setData(spline_volume);
747  d->renderer->AddActor(actor);
748 
749  axlAbstractView::insert(spline_volume, actor);
750  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
751  connect(spline_volume,SIGNAL(samplingChanged()),actor,SLOT(onSamplingChanged()));
752  connect(actor, SIGNAL(updated()), this, SLOT(update()));
753  //this->insertFields(spline_volume, actor);
754 
755 
756  result.push_back(actor);
757 
758  }
759  else if (axlShapeBSpline *spline_surface = dynamic_cast<axlShapeBSpline *>(*data)) {
760 
762  actor->setInteractor(iren);
763 
764  actor->setData(spline_surface);
765  d->renderer->AddActor(actor);
766 
767  axlAbstractView::insert(spline_surface, actor);
768  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
769  connect(spline_surface,SIGNAL(samplingChanged()),actor,SLOT(onSamplingChanged()));
770  //connect(spline_surface, SIGNAL(touch()), this, SLOT(update()));
771 
772  //this->insertFields(spline_surface, actor);
773 
774  result.push_back(actor);
775  }
776  else if(axlDataDynamic *dynamicData = dynamic_cast<axlDataDynamic *>(*data)) {
778  actor->setInteractor(iren);
779  actor->setView(this); // need for the insertion of the composite child
780  actor->setRenderer(d->renderer);
781 
782  actor->setData(dynamicData);
783  d->renderer->AddActor(actor);
784 
785 
786  axlAbstractView::insert(dynamicData, actor);
787  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
788 
789  result.push_back(actor);
790 
791  }
792  else if(axlAbstractDataComposite *composite = dynamic_cast<axlAbstractDataComposite *>(*data)) {
794  actor->setInteractor(iren);
795  actor->setView(this); // need for the insertion of the composite child
796  actor->setRenderer(d->renderer);
797 
798  actor->setData(composite);
799  d->renderer->AddActor(actor);
800 
801  axlAbstractView::insert(composite, actor);
802  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
803  connect(composite,SIGNAL(samplingChanged()),actor,SLOT(onSamplingChanged()));
804 
805  result.push_back(actor);
806 
807  }
808  else if(axlVolumeDiscrete *vol = dynamic_cast<axlVolumeDiscrete *>(*data)) {
809 
811  actor->setInteractor(iren);
812 
813  actor->setData(vol);
814  actor->setDisplay(true);
815  d->renderer->AddActor(actor);
816 
817  axlAbstractView::insert(vol, actor);
818  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
819 
820  result.push_back(actor);
821  }
822 
823  else {
824 
826 
827  actor->setInteractor(iren);
828  actor->setData(*data);
829 
830  actor->setDisplay(true);
831 
832  d->renderer->AddActor(actor);
833 
834  axlAbstractView::insert(*data, actor);
835  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
836  connect(actor, SIGNAL(updated()), this, SLOT(update()));
837  result.push_back(actor);
838 
839  //this->insertFields(*data, actor);
840  }
841  }// for each
842 
843  d->renderer->ResetCamera();
844 
845  iren = NULL;
846 
847  dtkWarn()<<"End Time "<<vtkTimerLog::GetCPUTime()<< vtkTimerLog::GetCPUTime() - currentTime;
848  //double end = clock();
849  //double cpuTime = difftime(end, start)/CLOCKS_PER_SEC;
850  //qDebug()<<"axlVtkView cpu time "<<end <<cpuTime; //d->widget->update() ;
851  return result;
852 }
853 
854 void axlVtkView::removeSetFields(QList<axlAbstractActorField *> actorSet)
855 {
856 
857  for(int i = 0; i < actorSet.size() ; i++)
858  {
859  axlAbstractView::removeField(actorSet.at(i)->data());
860  if(axlActorFieldSpatial *currentactor = dynamic_cast<axlActorFieldSpatial *>(actorSet.value(i))){
861 
862  disconnect(currentactor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
863  //currentactor->onRemoved(); // a construire
864  if(currentactor->scalarBar()){
865  d->renderer->RemoveActor2D(currentactor->scalarBar());
866  }
867  d->renderer->RemoveActor(currentactor);
868  currentactor->setInteractor(NULL);
869  currentactor->Delete();
870 
871  currentactor = NULL;
872 
873  }else if(axlActorFieldParametric *currentactor = dynamic_cast<axlActorFieldParametric *>(actorSet.value(i))){
874 
875  disconnect(currentactor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
876  //currentactor->onRemoved(); // a construire
877  if(currentactor->scalarBar()){
878  d->renderer->RemoveActor2D(currentactor->scalarBar());
879  }
880  d->renderer->RemoveActor(currentactor);
881  currentactor->setInteractor(NULL);
882 
883  currentactor->Delete();
884 
885  currentactor = NULL;
886 
887  }else if(axlActorFieldDiscrete *currentactor = dynamic_cast<axlActorFieldDiscrete *>(actorSet.value(i))){
888 
889  disconnect(currentactor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
890  //currentactor->onRemoved(); // a construire
891  if(currentactor->scalarBar()){
892  d->renderer->RemoveActor2D(currentactor->scalarBar());
893  }
894  d->renderer->RemoveActor(currentactor);
895  currentactor->setInteractor(NULL);
896 
897  currentactor->Delete();
898 
899  currentactor = NULL;
900 
901  }
902 
903 
904  }
905 
906  d->renderer->ResetCamera();
907  this->update();
908 }
909 
910 
911 
912 void axlVtkView::removeSet(QList<axlAbstractActor *> actorSet)
913 {
914 
915  for(int i = 0; i < actorSet.size() ; i++)
916 
917  {
918 
919  axlAbstractView::removeData(actorSet.at(i)->data());
920 
921  if(axlActor *currentactor = dynamic_cast<axlActor *>(actorSet.value(i)))
922 
923  {
924  // qDebug()<<currentactor->GetReferenceCount();
925 
926  // qDebug()<<"numnber of reference 0"<<currentactor->GetReferenceCount();
927 
928  if(axlActorBSpline *actorBSlpine = dynamic_cast<axlActorBSpline *>(currentactor))
929  disconnect(actorBSlpine->data(),SIGNAL(samplingChanged()),actorBSlpine,SLOT(onSamplingChanged()));
930  // qDebug()<<"numnber of reference 1"<<currentactor->GetReferenceCount();
931 
932 
933  disconnect(currentactor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
934  if(currentactor->parent() == NULL || dynamic_cast<axlActorDataDynamic *>(currentactor)){
935  currentactor->onRemoved();
936  d->renderer->RemoveActor(currentactor);
937  currentactor->setInteractor(NULL);
938  // qDebug()<<"numnber of reference 2"<<currentactor->GetReferenceCount();
939  currentactor->Delete();
940  //int i = 0;
941  // qDebug()<<currentactor->GetReferenceCount();
942  // qDebug()<<"numnber of reference 3"<<currentactor->GetReferenceCount();
943  currentactor = NULL;
944  }
945 
946  }
947 
948  else if(axlActorComposite *currentactor = dynamic_cast<axlActorComposite *>(actorSet.value(i)))
949 
950  {
951 
952  disconnect(currentactor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
953  currentactor->onRemoved();
954 
955 
956  if(currentactor->getState() == (axlActorComposite::selection | axlActorComposite::passive))
957  d->renderer->RemoveActor(currentactor);
958 
959  currentactor->Delete();
960  currentactor = NULL;
961  }
962  }
963 
964  d->renderer->ResetCamera();
965  this->update();
966 
967 }
968 
970 {
971  vtkRenderWindowInteractor *iren = d->widget->GetInteractor();
972  d->widget->GetInteractor()->SetInteractorStyle(d->style);
973 
974  if (axlPoint *point = dynamic_cast<axlPoint *>(data)) {
975 
977 
978  actor->setInteractor(iren);
979  actor->setQVTKWidget(d->widget);
980  actor->setData(point);
981 
982  // actor->setDisplay(true);
983 
984  d->renderer->AddActor(actor);
985 
986  axlAbstractView::insert(point, actor);
987  connect(actor, SIGNAL(stateChanged(dtkAbstractData*,int)), this, SIGNAL(stateChanged(dtkAbstractData*,int)));
988  connect(actor, SIGNAL(updated()), this, SLOT(update()));
989  d->renderer->ResetCamera();
990 
991  iren = NULL;
992  return actor;
993  }
994 
995  else if (axlCone *cone = dynamic_cast<axlCone *>(data)) {
996 
998 
999  actor->setInteractor(iren);
1000  actor->setQVTKWidget(d->widget);
1001  actor->setData(cone);
1002 
1003  //actor->setDisplay(true);
1004 
1005  d->renderer->AddActor(actor);
1006 
1007  axlAbstractView::insert(cone, actor);
1008  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
1009  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1010  return actor;
1011  }
1012 
1013  else if (axlCylinder *cylinder = dynamic_cast<axlCylinder *>(data)) {
1014 
1016 
1017  actor->setInteractor(iren);
1018  actor->setQVTKWidget(d->widget);
1019  actor->setData(cylinder);
1020 
1021  //actor->setDisplay(true);
1022 
1023  d->renderer->AddActor(actor);
1024  iren = NULL;
1025 
1026 
1027  axlAbstractView::insert(cylinder, actor);
1028  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
1029  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1030  return actor;
1031  }
1032 
1033  else if (axlTorus *torus = dynamic_cast<axlTorus *>(data)) {
1034 
1036 
1037  actor->setInteractor(iren);
1038  actor->setQVTKWidget(d->widget);
1039  actor->setData(torus);
1040 
1041  //actor->setDisplay(true);
1042 
1043  d->renderer->AddActor(actor);
1044  iren = NULL;
1045 
1046 
1047  axlAbstractView::insert(torus, actor);
1048  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
1049  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1050  return actor;
1051  }
1052 
1053  // else if (axlCircleArc *arc = dynamic_cast<axlCircleArc *>(data)) {
1054 
1055  // axlActorCircleArc *actor = axlActorCircleArc::New();
1056 
1057  // actor->setInteractor(iren);
1058  // actor->setQVTKWidget(d->widget);
1059  // actor->setCircleArc(arc);
1060 
1061  // //actor->setDisplay(true);
1062 
1063  // d->renderer->AddActor(actor);
1064 
1065  // axlAbstractView::insert(arc, actor);
1066  // connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
1067  // return actor;
1068  // }
1069 
1070  else if (axlEllipsoid *ellipsoid = dynamic_cast<axlEllipsoid *>(data)) {
1071 
1072  axlActorEllipsoid *actor = axlActorEllipsoid::New();
1073 
1074  actor->setInteractor(iren);
1075  actor->setQVTKWidget(d->widget);
1076  actor->setData(ellipsoid);
1077 
1078  //actor->setDisplay(true);
1079 
1080  d->renderer->AddActor(actor);
1081  iren = NULL;
1082 
1083  axlAbstractView::insert(ellipsoid, actor);
1084  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
1085  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1086  return actor;
1087  }
1088 
1089 
1090  else if (axlLine *line = dynamic_cast<axlLine *>(data)) {
1091 
1093 
1094  actor->setInteractor(iren);
1095  actor->setQVTKWidget(d->widget);
1096  actor->setData(line);
1097 
1098  //actor->setDisplay(true);
1099 
1100  d->renderer->AddActor(actor);
1101  iren = NULL;
1102 
1103  axlAbstractView::insert(line, actor);
1104  connect(actor, SIGNAL(stateChanged(dtkAbstractData*,int)), this, SIGNAL(stateChanged(dtkAbstractData*,int)));
1105  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1106  d->renderer->ResetCamera();
1107 
1108  return actor;
1109  }
1110  else if (axlPlane *plane = dynamic_cast<axlPlane *>(data)) {
1111 
1113 
1114  actor->setInteractor(iren);
1115  actor->setQVTKWidget(d->widget);
1116  actor->setRenderer(d->renderer);
1117  actor->setData(plane);
1118 
1119  actor->setDisplay(true);
1120 
1121  d->renderer->AddActor(actor);
1122  iren = NULL;
1123 
1124  axlAbstractView::insert(plane, actor);
1125  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
1126  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1127  d->renderer->ResetCamera();
1128  }
1129  // else if (axlPointSet *pointSet = dynamic_cast<axlPointSet *>(data)) {
1130 
1131  // axlActorPointSet *actor = axlActorPointSet::New();
1132 
1133  // actor->setInteractor(iren);
1134  // actor->setPointSet(pointSet);
1135 
1136  // //actor->setDisplay(true);
1137 
1138  // d->renderer->AddActor(actor);
1139 
1140  // axlAbstractView::insert(pointSet, actor);
1141  // connect(actor, SIGNAL(stateChanged(dtkAbstractData*,int)), this, SIGNAL(stateChanged(dtkAbstractData*,int)));
1142  // d->renderer->ResetCamera();
1143 
1144 
1145  // return actor;
1146  // }
1147  else if (axlSphere *sphere = dynamic_cast<axlSphere *>(data)) {
1148 
1150 
1151  actor->setInteractor(iren);
1152  actor->setQVTKWidget(d->widget);
1153  actor->setData(sphere);
1154 
1155  actor->setDisplay(true);
1156 
1157  d->renderer->AddActor(actor);
1158  iren = NULL;
1159 
1160  axlAbstractView::insert(sphere, actor);
1161  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
1162  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1163  d->renderer->ResetCamera();
1164 
1165  return actor;
1166  }
1167 
1168  else if (axlAbstractCurveBSpline *spline_curve = dynamic_cast<axlAbstractCurveBSpline *>(data)) {
1169 
1171 
1172  actor->setInteractor(iren);
1173  actor->setData(spline_curve);
1174 
1175  d->renderer->AddActor(actor);
1176  iren = NULL;
1177 
1178  axlAbstractView::insert(spline_curve, actor);
1179  connect(actor, SIGNAL(stateChanged(dtkAbstractData *, int)), this, SIGNAL(stateChanged(dtkAbstractData *, int)));
1180  connect(spline_curve, SIGNAL(samplingChanged()), actor, SLOT(onSamplingChanged()));
1181  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1182  d->renderer->ResetCamera();
1183 
1184  return actor;
1185  }
1186 
1187  else if(axlAbstractSurfaceBSpline *spline_surface = dynamic_cast<axlAbstractSurfaceBSpline *>(data)) {
1188 
1190 
1191  actor->setInteractor(iren);
1192  actor->setData(spline_surface);
1193 
1194  d->renderer->AddActor(actor);
1195  iren = NULL;
1196 
1197  axlAbstractView::insert(spline_surface, actor);
1198  connect(actor, SIGNAL(stateChanged(dtkAbstractData*,int)), this, SIGNAL(stateChanged(dtkAbstractData*,int)));
1199  connect(spline_surface,SIGNAL(samplingChanged()),actor,SLOT(onSamplingChanged()));
1200  connect(spline_surface, SIGNAL(updated()), this, SLOT(update()));
1201  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1202  //this->insertFields(spline_surface, actor);
1203 
1204  d->renderer->ResetCamera();
1205 
1206  return actor;
1207  }
1208  else if(axlAbstractVolumeBSpline *spline_volume = dynamic_cast<axlAbstractVolumeBSpline *>(data)) {
1209 
1211 
1212  actor->setInteractor(iren);
1213  actor->setData(spline_volume);
1214 
1215  d->renderer->AddActor(actor);
1216  iren = NULL;
1217 
1218  axlAbstractView::insert(spline_volume, actor);
1219  connect(actor, SIGNAL(stateChanged(dtkAbstractData*,int)), this, SIGNAL(stateChanged(dtkAbstractData*,int)));
1220  connect(spline_volume,SIGNAL(samplingChanged()),actor,SLOT(onSamplingChanged()));
1221  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1222  //this->insertFields(spline_volume, actor);
1223 
1224 
1225  d->renderer->ResetCamera();
1226 
1227  return actor;
1228  }
1229  else if(axlShapeBSpline *spline_surface = dynamic_cast<axlShapeBSpline *>(data)) {
1230 
1232 
1233  actor->setInteractor(iren);
1234  actor->setData(spline_surface);
1235 
1236  d->renderer->AddActor(actor);
1237  iren = NULL;
1238 
1239  axlAbstractView::insert(spline_surface, actor);
1240  connect(actor, SIGNAL(stateChanged(dtkAbstractData*,int)), this, SIGNAL(stateChanged(dtkAbstractData*,int)));
1241  connect(spline_surface,SIGNAL(samplingChanged()),actor,SLOT(onSamplingChanged()));
1242  connect(spline_surface, SIGNAL(updated()), this, SLOT(update()));
1243 
1244  //this->insertFields(spline_surface, actor);
1245 
1246  d->renderer->ResetCamera();
1247 
1248  return actor;
1249  }
1250 
1251  else if (axlDataDynamic *line = dynamic_cast<axlDataDynamic *>(data)) {
1252 
1254 
1255  actor->setInteractor(iren);
1256  actor->setQVTKWidget(d->widget);
1257  actor->setView(this); // need for the insertion of the composite child
1258  actor->setRenderer(d->renderer);
1259 
1260  actor->setData(line);
1261 
1262  d->renderer->AddActor(actor);
1263  iren = NULL;
1264 
1265  axlAbstractView::insert(line, actor);
1266  connect(actor, SIGNAL(stateChanged(dtkAbstractData*,int)), this, SIGNAL(stateChanged(dtkAbstractData*,int)));
1267 
1268  d->renderer->ResetCamera();
1269 
1270  return actor;
1271  }
1272  else if(axlAbstractDataComposite *composite = dynamic_cast<axlAbstractDataComposite *>(data))
1273  {
1275 
1276  actor->setInteractor(iren);
1277  actor->setView(this); // need for the insertion of the composite child
1278  actor->setRenderer(d->renderer);
1279 
1280  actor->setData(composite);
1281 
1282  d->renderer->AddActor(actor);
1283  iren = NULL;
1284 
1285  axlAbstractView::insert(composite, actor);
1286  connect(actor, SIGNAL(stateChanged(dtkAbstractData*,int)), this, SIGNAL(stateChanged(dtkAbstractData*,int)));
1287  //connect(composite,SIGNAL(samplingChanged()),actor,SLOT(onSamplingChanged()));
1288 
1289  d->renderer->ResetCamera();
1290 
1291 
1292  return actor;
1293  }else if (axlVolumeDiscrete *vol = dynamic_cast<axlVolumeDiscrete *>(data)) {
1295  actor->setInteractor(iren);
1296 
1297  actor->setData(vol);
1298 
1299  actor->setDisplay(true);
1300 
1301  d->renderer->AddActor(actor);
1302  iren = NULL;
1303 
1304  axlAbstractView::insert(vol, actor);
1305  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
1306  }
1307  else
1308  {
1310  actor->setInteractor(iren);
1311  actor->setData(data);
1312 
1313  d->renderer->AddActor(actor);
1314  iren = NULL;
1315 
1316  axlAbstractView::insert(data, actor);
1317  connect(actor, SIGNAL(stateChanged(dtkAbstractData*, int)), this, SIGNAL(stateChanged(dtkAbstractData*, int)));
1318  connect(actor, SIGNAL(updated()), this, SLOT(update()));
1319  //this->insertFields(data, actor);
1320 
1321  d->renderer->ResetCamera();
1322 
1323  return actor;
1324  }
1325  iren = NULL;
1326 
1327  return NULL;
1328 }
1329 
1331  if(d->renderer)
1332  d->renderer->SetGradientBackground(gradient);
1333 
1334  this->update();
1335 }
1336 
1337 void axlVtkView::setParallelScale(double parallelScale){
1338  d->renderer->GetActiveCamera()->SetParallelScale(parallelScale);
1339 }
1340 
1342  return d->renderer->GetActiveCamera()->GetParallelScale();
1343 }
1344 
1346  return d->renderer->GetGradientBackground();
1347 }
1348 
1350  return d->renderer->GetActiveCamera()->GetPosition();
1351 }
1352 
1354  return d->axesActor->GetVisibility();
1355 }
1356 
1358  return d->renderer->GetActiveCamera()->GetParallelProjection();
1359 }
1360 
1362  return d->renderer->GetActiveCamera()->GetFocalPoint();
1363 }
1364 
1365 void axlVtkView::setCameraFocalPoint(double x, double y, double z){
1366  d->renderer->GetActiveCamera()->SetFocalPoint(x, y, z);
1367 }
1368 
1370  return d->renderer->GetActiveCamera()->GetViewUp();
1371 }
1372 
1373 void axlVtkView::setCameraUp(double x, double y, double z){
1374  d->renderer->GetActiveCamera()->SetViewUp(x, y, z);
1375 }
1376 
1378  return d->renderer->GetActiveCamera()->GetViewAngle();
1379 }
1380 
1382  d->renderer->GetActiveCamera()->SetViewAngle(angle);
1383 }
1384 
1386  return d->renderer->GetBackground();
1387 }
1388 
1389 void axlVtkView::setBackgroundColor(double red, double green, double blue)
1390 {
1391  if(d->renderer)
1392  d->renderer->SetBackground (red, green, blue);
1393 
1394  this->update();
1395 
1396  // vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
1397 
1398  // unsigned int dim = 20;
1399 
1400  // image->SetNumberOfScalarComponents(3);
1401  // image->SetScalarTypeToUnsignedChar();
1402  // image->SetDimensions(dim, dim, 1);
1403 
1404  // image->AllocateScalars();
1405 
1406  // for(unsigned int x = 0; x < dim; x++)
1407  // {
1408  // for(unsigned int y = 0; y < dim; y++)
1409  // {
1410  // unsigned char* pixel = static_cast<unsigned char*>(image->GetScalarPointer(x,y,0));
1411  // if(x < dim/2)
1412  // {
1413  // pixel[0] = 255;
1414  // }
1415  // else
1416  // {
1417  // pixel[0] = 0;
1418  // }
1419  // pixel[1] = 0;
1420  // pixel[2] = 255;
1421  // }
1422  // }
1423 
1424  // image->Modified();
1425 
1426 
1427  // vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
1428  // texture->SetInputConnection(image->GetProducerPort());
1429 
1430  // d->renderer->SetBackgroundTexture(texture);
1431  // d->renderer->TexturedBackgroundOn();
1432 
1433 
1434 }
1435 
1436 void axlVtkView::activeDefaultLigh(bool useDefaultLight)
1437 {
1438  if(useDefaultLight)
1439  {
1440  if(d->lightWidget != NULL)
1441  {
1442  d->lightWidget->SetEnabled(0);
1443  d->lightWidget->Delete();
1444  d->lightWidget = NULL;
1445  }
1446  d->renderer->RemoveAllLights();
1447  d->lightKit = vtkSmartPointer<vtkLightKit>::New();
1448  d->lightKit->AddLightsToRenderer(d->renderer);
1449 
1450 // d->widget->update();
1451 
1452  }
1453  else
1454  {
1455 
1456  //test with axlLightsWidgets
1457  d->renderer->RemoveAllLights();
1458  d->firstLight = vtkSmartPointer<vtkLight>::New();
1459  d->firstLight->SetAmbientColor(1.0, 1.0, 1.0);
1460  d->firstLight->SetDiffuseColor(1.0, 1.0, 1.0);
1461  d->firstLight->SetSpecularColor(1.0, 1.0, 1.0);
1462  d->firstLight->SetExponent(50);
1463  d->firstLight->SetIntensity(1);
1464  // d->firstLight->SetConeAngle(170);
1465  d->firstLight->SetPosition(0.0, 0.0, 0.0);
1466 
1467  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1468  double center[3];
1469  center[0] = (bounds[1]+bounds[0])/2;
1470  center[1] = (bounds[3]+bounds[2])/2;
1471  center[2] = (bounds[5]+bounds[4])/2;
1472  d->firstLight->SetFocalPoint(center);
1473  d->firstLight->SetLightTypeToSceneLight();
1474  d->firstLight->SetPositional(1);
1475  d->renderer->AddLight(d->firstLight);
1476  if(d->lightWidget == NULL)
1477  {
1478  d->lightWidget = axlLightsWidget::New();
1479  d->lightWidget->setView(this);
1480  d->lightWidget->SetInteractor(d->widget->GetInteractor());
1481  d->lightWidget->initializePoints();
1482 
1483  d->lightWidget->ptsActors()->InitTraversal();
1484 
1485  for(vtkIdType i = 0; i < d->lightWidget->ptsActors()->GetNumberOfItems(); i++)
1486  {
1487  d->renderer->AddActor(d->lightWidget->ptsActors()->GetNextActor());
1488  }
1489 
1490  d->lightWidget->SetEnabled(1);
1491 
1492  }
1493 
1494 // d->widget->update();
1495 
1496 
1497  }
1498 
1499  this->update();
1500 
1501  // if(useDefaultLight)
1502  // {
1503  // if(d->lightActor != NULL)
1504  // {
1505  // d->renderer->RemoveActor(d->lightActor);
1506  // //d->lightActor->Delete();
1507  // d->lightActor = NULL;
1508  // }
1509  // d->renderer->RemoveAllLights();
1510  // d->lightKit = vtkSmartPointer<vtkLightKit>::New();
1511  // d->lightKit->AddLightsToRenderer(d->renderer);
1512 
1513  // d->widget->update();
1514 
1515  // }
1516  // else
1517  // {
1518 
1519  // //test with axlLightsWidgets
1520  // d->renderer->RemoveAllLights();
1521  // d->firstLight = vtkSmartPointer<vtkLight>::New();
1522  // d->firstLight->SetAmbientColor(1.0, 1.0, 1.0);
1523  // d->firstLight->SetDiffuseColor(1.0, 1.0, 1.0);
1524  // d->firstLight->SetSpecularColor(1.0, 1.0, 1.0);
1525  // d->firstLight->SetExponent(50);
1526  // d->firstLight->SetPosition(0.0, 0.0, 0.0);
1527  // d->firstLight->SetFocalPoint(d->renderer->GetActiveCamera()->GetFocalPoint());
1528  // d->firstLight->SetLightTypeToSceneLight();
1529  // d->firstLight->SetPositional(1);
1530  // d->renderer->AddLight(d->firstLight);
1531 
1532  // if(d->lightActor == NULL)
1533  // {
1534  // d->lightActor = vtkSmartPointer<vtkLightActor>::New();
1535  // d->lightActor->SetLight(d->firstLight);
1536  // d->renderer->AddActor(d->lightActor);
1537  // }
1538 
1539 
1540 
1541  // d->widget->update();
1542 
1543 
1544  // }
1545 
1546 }
1547 
1548 void axlVtkView::setLight(int i, bool hide, double *position, double *ambiant, double *diffuse, double *specular, int exponent)
1549 {
1550  Q_UNUSED(i); // be used later for select the good light
1551 
1552  d->firstLight->SetAmbientColor(ambiant);
1553  d->firstLight->SetDiffuseColor(diffuse);
1554  d->firstLight->SetSpecularColor(specular);
1555  d->firstLight->SetExponent(exponent);
1556  d->firstLight->SetPosition(position);
1557 
1558  d->firstLight->Modified();
1559 
1560  d->lightWidget->update();
1561 
1562  d->lightWidget->SetEnabled(!hide);
1563 
1564 // d->widget->update();
1565  this->update();
1566 }
1567 
1569 {
1570  d->lastCameraIsDefault = true;
1571 
1572  vtkCamera *camera = d->renderer->GetActiveCamera();
1573  camera->SetParallelProjection(false);
1574  camera->SetPosition(d->camera_center);
1575  camera->SetFocalPoint(d->camera_focal);
1576  camera->SetViewUp(d->camera_view_up);
1577 
1578  d->renderer->ResetCamera();
1579 
1580  this->update();
1581 
1582 }
1583 
1585 {
1586  vtkCamera *camera = d->renderer->GetActiveCamera();
1587  camera->SetParallelProjection(true);
1588 
1589  if(d->lastCameraIsDefault)
1590  {
1591  camera->GetPosition(d->camera_center);
1592  camera->GetFocalPoint(d->camera_focal);
1593  camera->GetViewUp(d->camera_view_up);
1594  d->lastCameraIsDefault = false;
1595  }
1596 
1597  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1598 
1599  double side = qAbs(bounds[1]-bounds[0]);
1600 
1601  double center[3];
1602  center[0] = (bounds[1]+bounds[0])/2;
1603  center[1] = (bounds[3]+bounds[2])/2;
1604  center[2] = (bounds[5]+bounds[4])/2;
1605 
1606  camera->SetPosition(center[0]+side, center[1], center[2]);
1607  camera->SetFocalPoint(center[0], center[1], center[2]);
1608  camera->SetViewUp(0, 1, 0);
1609 
1610  d->renderer->ResetCamera();
1611 
1612  this->update();
1613 }
1614 
1616 {
1617  vtkCamera *camera = d->renderer->GetActiveCamera();
1618  camera->SetParallelProjection(true);
1619 
1620  if(d->lastCameraIsDefault)
1621  {
1622  camera->GetPosition(d->camera_center);
1623  camera->GetFocalPoint(d->camera_focal);
1624  camera->GetViewUp(d->camera_view_up);
1625  d->lastCameraIsDefault = false;
1626  }
1627 
1628  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1629 
1630  double side = qAbs(bounds[1]-bounds[0]);
1631 
1632  double center[3];
1633  center[0] = (bounds[1]+bounds[0])/2;
1634  center[1] = (bounds[3]+bounds[2])/2;
1635  center[2] = (bounds[5]+bounds[4])/2;
1636 
1637  camera->SetPosition(center[0]-side, center[1], center[2]);
1638  camera->SetFocalPoint(center[0], center[1], center[2]);
1639  camera->SetViewUp(0, 1, 0);
1640 
1641  d->renderer->ResetCamera();
1642 
1643  this->update();
1644 }
1645 
1647 {
1648  vtkCamera *camera = d->renderer->GetActiveCamera();
1649  camera->SetParallelProjection(true);
1650 
1651  if(d->lastCameraIsDefault)
1652  {
1653  camera->GetPosition(d->camera_center);
1654  camera->GetFocalPoint(d->camera_focal);
1655  camera->GetViewUp(d->camera_view_up);
1656  d->lastCameraIsDefault = false;
1657  }
1658 
1659  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1660 
1661  double side = qAbs(bounds[3]-bounds[2]);
1662 
1663  double center[3];
1664  center[0] = (bounds[1]+bounds[0])/2;
1665  center[1] = (bounds[3]+bounds[2])/2;
1666  center[2] = (bounds[5]+bounds[4])/2;
1667 
1668  camera->SetPosition(center[0], center[1]+side, center[2]);
1669  camera->SetFocalPoint(center[0], center[1], center[2]);
1670  camera->SetViewUp(0, 0, 1);
1671 
1672  d->renderer->ResetCamera();
1673 
1674  this->update();
1675 }
1676 
1678 {
1679  vtkCamera *camera = d->renderer->GetActiveCamera();
1680  camera->SetParallelProjection(true);
1681 
1682  if(d->lastCameraIsDefault)
1683  {
1684  camera->GetPosition(d->camera_center);
1685  camera->GetFocalPoint(d->camera_focal);
1686  camera->GetViewUp(d->camera_view_up);
1687  d->lastCameraIsDefault = false;
1688  }
1689 
1690  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1691 
1692  double side = qAbs(bounds[3]-bounds[2]);
1693 
1694  double center[3];
1695  center[0] = (bounds[1]+bounds[0])/2;
1696  center[1] = (bounds[3]+bounds[2])/2;
1697  center[2] = (bounds[5]+bounds[4])/2;
1698 
1699  camera->SetPosition(center[0], center[1]-side, center[2]);
1700  camera->SetFocalPoint(center[0], center[1], center[2]);
1701  camera->SetViewUp(0, 0, 1);
1702 
1703  d->renderer->ResetCamera();
1704 
1705  this->update();
1706 }
1707 
1709 {
1710  vtkCamera *camera = d->renderer->GetActiveCamera();
1711  camera->SetParallelProjection(true);
1712 
1713  if(d->lastCameraIsDefault)
1714  {
1715  camera->GetPosition(d->camera_center);
1716  camera->GetFocalPoint(d->camera_focal);
1717  camera->GetViewUp(d->camera_view_up);
1718  d->lastCameraIsDefault = false;
1719  }
1720 
1721  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1722 
1723  double side = qAbs(bounds[5]-bounds[4]);
1724 
1725  double center[3];
1726  center[0] = (bounds[1]+bounds[0])/2;
1727  center[1] = (bounds[3]+bounds[2])/2;
1728  center[2] = (bounds[5]+bounds[4])/2;
1729 
1730  camera->SetPosition(center[0], center[1], center[2]+side);
1731  camera->SetFocalPoint(center[0], center[1], center[2]);
1732  camera->SetViewUp(0, 1, 0);
1733 
1734  d->renderer->ResetCamera();
1735 
1736  this->update();
1737 }
1738 
1740 {
1741  vtkCamera *camera = d->renderer->GetActiveCamera();
1742  camera->SetParallelProjection(true);
1743 
1744  if(d->lastCameraIsDefault)
1745  {
1746  camera->GetPosition(d->camera_center);
1747  camera->GetFocalPoint(d->camera_focal);
1748  camera->GetViewUp(d->camera_view_up);
1749  d->lastCameraIsDefault = false;
1750  }
1751 
1752  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1753 
1754  double side = qAbs(bounds[5]-bounds[4]);
1755 
1756  double center[3];
1757  center[0] = (bounds[1]+bounds[0])/2;
1758  center[1] = (bounds[3]+bounds[2])/2;
1759  center[2] = (bounds[5]+bounds[4])/2;
1760 
1761  camera->SetPosition(center[0], center[1], center[2]-side);
1762  camera->SetFocalPoint(center[0], center[1], center[2]);
1763  camera->SetViewUp(0, 1, 0);
1764 
1765  d->renderer->ResetCamera();
1766 
1767  this->update();
1768 }
1769 
1770 void axlVtkView::setGrid(bool isGridX, bool isGridY, bool isGridZ)
1771 {
1772 
1773  //axis
1774 
1775  if(!d->isGridX)
1776  {
1777  //vtkSmartPointer<vtkPNGReader> imageReaderRedX;
1778  vtkSmartPointer<vtkPolyData> polyDataX;
1779  // vtkSmartPointer<vtkFloatArray> TCoordsX;
1780  // vtkSmartPointer<vtkTexture> textureRedX;
1781  vtkSmartPointer<vtkPolyDataMapper> mapperX;
1782 
1783  // char* fname1 = vtkTestUtilities::ExpandDataFileName(1, new char*(), "Data/ground.png");
1784 
1785  // imageReaderRedX = vtkPNGReader::New();
1786  // imageReaderRedX->SetFileName(fname1);
1787  // imageReaderRedX->Update();
1788 
1789  d->planeSourceX = vtkSmartPointer<vtkPlaneSource>::New();
1790 
1791  polyDataX = d->planeSourceX->GetOutput();
1792  // TCoordsX = vtkFloatArray::New();
1793  // textureRedX = vtkTexture::New();
1794 
1795  mapperX = vtkSmartPointer<vtkPolyDataMapper>::New();
1796  d->actorX = vtkSmartPointer<vtkActor>::New();
1797 
1798  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1799 
1800  d->planeSourceX->SetPoint1(bounds[1], bounds[2], 0);
1801  d->planeSourceX->SetPoint2(bounds[0], bounds[3], 0);
1802  d->planeSourceX->SetOrigin(bounds[0], bounds[2], 0);
1803  d->planeSourceX->SetResolution(1, 1);
1804  d->planeSourceX->Update();
1805 
1806  polyDataX->Register(NULL);
1807  polyDataX->GetPointData()->SetNormals(NULL);
1808 
1809  // TCoordsX->SetNumberOfComponents(2);
1810  // TCoordsX->SetNumberOfTuples(4);
1811  // TCoordsX->SetTuple2(0, 0.0, 0.0);
1812  // TCoordsX->SetTuple2(1, 0.0, 10.0);
1813  // TCoordsX->SetTuple2(2, 10.0, 0.0);
1814  // TCoordsX->SetTuple2(3, 10.0, 10.0);
1815  // TCoordsX->SetName("MultTCoordsX");
1816 
1817  // polyDataX->GetPointData()->SetTCoords(TCoordsX);
1818 
1819  // textureRedX->SetInputConnection(imageReaderRedX->GetOutputPort());
1820  // textureRedX->RepeatOn();
1821 
1822 #if (VTK_MAJOR_VERSION <= 5)
1823  mapperX->SetInput(polyDataX);
1824 #else
1825  mapperX->SetInputData(polyDataX);
1826 #endif
1827  d->actorX->SetMapper(mapperX);
1828  d->actorX->SetUseBounds(false);
1829 
1830  // no multitexturing just show the green texture.
1831  //d->actorX->SetTexture(textureRedX);
1832  d->renderer->AddActor(d->actorX);
1833  d->isGridX = true;
1834  }
1835 
1836  if(!d->isGridY)
1837  {
1838  // vtkSmartPointer<vtkPNGReader> imageReaderRedY;
1839  vtkSmartPointer<vtkPolyData> polyDataY;
1840  // vtkSmartPointer<vtkFloatArray> TCoordsY;
1841  // vtkSmartPointer<vtkTexture> textureRedY;
1842  vtkSmartPointer<vtkPolyDataMapper> mapperY;
1843 
1844  // char* fname1 = vtkTestUtilities::ExpandDataFileName(1, new char*(), "Data/ground.png");
1845 
1846  // imageReaderRedY = vtkPNGReader::New();
1847  // imageReaderRedY->SetFileName(fname1);
1848  // imageReaderRedY->Update();
1849 
1850  d->planeSourceY = vtkSmartPointer<vtkPlaneSource>::New();
1851  polyDataY = d->planeSourceY->GetOutput();
1852  // TCoordsY = vtkFloatArray::New();
1853  // textureRedY = vtkTexture::New();
1854 
1855  mapperY = vtkSmartPointer<vtkPolyDataMapper>::New();
1856  d->actorY = vtkSmartPointer<vtkActor>::New();
1857 
1858  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1859 
1860  d->planeSourceY->SetPoint1(0, bounds[2], bounds[5]);
1861  d->planeSourceY->SetPoint2(0, bounds[3], bounds[4]);
1862  d->planeSourceY->SetOrigin(0, bounds[2], bounds[4]);
1863  d->planeSourceY->SetResolution(1, 1);
1864  d->planeSourceY->Update();
1865 
1866  polyDataY->Register(NULL);
1867  polyDataY->GetPointData()->SetNormals(NULL);
1868 
1869  // TCoordsY->SetNumberOfComponents(2);
1870  // TCoordsY->SetNumberOfTuples(4);
1871  // TCoordsY->SetTuple2(0, 0.0, 0.0);
1872  // TCoordsY->SetTuple2(1, 0.0, 10.0);
1873  // TCoordsY->SetTuple2(2, 10.0, 0.0);
1874  // TCoordsY->SetTuple2(3, 10.0, 10.0);
1875  // TCoordsY->SetName("MultTCoordsY");
1876 
1877  // polyDataY->GetPointData()->SetTCoords(TCoordsY);
1878 
1879  // textureRedY->SetInputConnection(imageReaderRedY->GetOutputPort());
1880  // textureRedY->RepeatOn();
1881 
1882 #if (VTK_MAJOR_VERSION <= 5)
1883  mapperY->SetInput(polyDataY);
1884 #else
1885  mapperY->SetInputData(polyDataY);
1886 #endif
1887  d->actorY->SetMapper(mapperY);
1888  d->actorY->SetUseBounds(false);
1889 
1890  // no multitexturing just show the green texture.
1891  //d->actorY->SetTexture(textureRedY);
1892  d->renderer->AddActor(d->actorY);
1893  d->isGridY = true;
1894  }
1895 
1896  if(!d->isGridZ)
1897  {
1898  // vtkSmartPointer<vtkPNGReader> imageReaderRedZ;
1899  vtkSmartPointer<vtkPolyData> polyDataZ;
1900  // vtkSmartPointer<vtkFloatArray> TCoordsZ;
1901  // vtkSmartPointer<vtkTexture> textureRedZ;
1902  vtkSmartPointer<vtkPolyDataMapper> mapperZ;
1903 
1904  // char* fname1 = vtkTestUtilities::ExpandDataFileName(1, new char*(), "Data/ground.png");
1905 
1906  // imageReaderRedZ = vtkPNGReader::New();
1907  // imageReaderRedZ->SetFileName(fname1);
1908  // imageReaderRedZ->Update();
1909 
1910  d->planeSourceZ = vtkSmartPointer<vtkPlaneSource>::New();
1911  polyDataZ = d->planeSourceZ->GetOutput();
1912  // TCoordsZ = vtkFloatArray::New();
1913  // textureRedZ = vtkTexture::New();
1914 
1915  mapperZ = vtkSmartPointer<vtkPolyDataMapper>::New();
1916  d->actorZ = vtkSmartPointer<vtkActor>::New();
1917 
1918  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1919 
1920  d->planeSourceZ->SetPoint1(bounds[1], 0, bounds[4]);
1921  d->planeSourceZ->SetPoint2(bounds[0], 0, bounds[5]);
1922  d->planeSourceZ->SetOrigin(bounds[0], 0, bounds[4]);
1923  d->planeSourceZ->SetResolution(1, 1);
1924  d->planeSourceZ->Update();
1925 
1926  polyDataZ->Register(NULL);
1927  polyDataZ->GetPointData()->SetNormals(NULL);
1928 
1929  // TCoordsZ->SetNumberOfComponents(2);
1930  // TCoordsZ->SetNumberOfTuples(4);
1931  // TCoordsZ->SetTuple2(0, 0.0, 0.0);
1932  // TCoordsZ->SetTuple2(1, 0.0, 10.0);
1933  // TCoordsZ->SetTuple2(2, 10.0, 0.0);
1934  // TCoordsZ->SetTuple2(3, 10.0, 10.0);
1935  // TCoordsZ->SetName("MultTCoordsZ");
1936 
1937  // polyDataZ->GetPointData()->SetTCoords(TCoordsZ);
1938 
1939  // textureRedZ->SetInputConnection(imageReaderRedZ->GetOutputPort());
1940  // textureRedZ->RepeatOn();
1941 
1942 #if (VTK_MAJOR_VERSION <= 5)
1943  mapperZ->SetInput(polyDataZ);
1944 #else
1945  mapperZ->SetInputData(polyDataZ);
1946 #endif
1947  d->actorZ->SetMapper(mapperZ);
1948  d->actorZ->SetUseBounds(false);
1949 
1950  // no multitexturing just show the green texture.
1951  //d->actorZ->SetTexture(textureRedZ);
1952  d->renderer->AddActor(d->actorZ);
1953  d->isGridZ = true;
1954  }
1955 
1956 
1957  if(d->isGridX)
1958  {
1959  if(isGridX)
1960  {
1961  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1962 
1963 
1964  d->planeSourceX->SetPoint1(bounds[1], bounds[2], 0);
1965  d->planeSourceX->SetPoint2(bounds[0], bounds[3], 0);
1966  d->planeSourceX->SetOrigin(bounds[0], bounds[2], 0);
1967  d->planeSourceX->Update();
1968  d->actorX->SetVisibility(true);
1969  }
1970  else
1971  d->actorX->SetVisibility(false);
1972  }
1973 
1974 
1975  if(d->isGridY)
1976  {
1977  if(isGridY)
1978  {
1979  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1980 
1981  d->planeSourceY->SetPoint1(0, bounds[2], bounds[5]);
1982  d->planeSourceY->SetPoint2(0, bounds[3], bounds[4]);
1983  d->planeSourceY->SetOrigin(0, bounds[2], bounds[4]);
1984  d->planeSourceY->Update();
1985  d->actorY->SetVisibility(true);
1986  }
1987  else
1988  d->actorY->SetVisibility(false);
1989  }
1990 
1991  if(d->isGridZ)
1992  {
1993  if(isGridZ)
1994  {
1995  double bounds[6]; d->renderer->ComputeVisiblePropBounds(bounds);
1996 
1997  d->planeSourceZ->SetPoint1(bounds[1], 0, bounds[4]);
1998  d->planeSourceZ->SetPoint2(bounds[0], 0, bounds[5]);
1999  d->planeSourceZ->SetOrigin(bounds[0], 0, bounds[4]);
2000  d->planeSourceZ->Update();
2001  d->actorZ->SetVisibility(true);
2002  }
2003  else
2004  d->actorZ->SetVisibility(false);
2005  }
2006 
2007  this->update();
2008 
2009 }
2010 
2012 {
2013  // if conditions true, we assumed that grid actor and source are already instancied
2014  if(d->isGridX)
2015  d->planeSourceX->SetResolution(resolution, resolution);
2016 
2017  if(d->isGridY)
2018  d->planeSourceY->SetResolution(resolution, resolution);
2019 
2020  if(d->isGridZ)
2021  d->planeSourceZ->SetResolution(resolution, resolution);
2022 
2023  this->update();
2024 
2025 }
2026 
2027 void axlVtkView::onShowAxis(bool show)
2028 {
2029  if(d->axesActor)
2030  d->axesActor->SetVisibility(show);
2031 
2032  this->update();
2033 }
2034 
2036 {
2037  vtkCamera *camera = d->renderer->GetActiveCamera();
2038 
2039  camera->SetParallelProjection(parallel);
2040 
2041  this->update();
2042 }
2043 
2044 
2046 {
2047  d->widget->update();
2048  d->widget->GetRenderWindow()->Render();
2049 }
2050 
2051 QWidget *axlVtkView::widget(void)
2052 {
2053  //qDebug() << DTK_PRETTY_FUNCTION << (d->widget != NULL);
2054 
2055  return d->widget;
2056 }
2057 
2058 
2059 // Update field considering data is already created
2060 void axlVtkView::onUpdateActorField(QList<axlAbstractData *> axlDataSet, QString fieldName)
2061 {
2062  //Q_UNUSED(fieldName);
2063 
2064  foreach(axlAbstractData *axlData, axlDataSet)
2065  {
2066  foreach(axlAbstractField *field, axlData->fields())
2067  {
2068  axlAbstractActorField *actorField = dynamic_cast<axlAbstractActorField *> (axlAbstractView::actor(field));
2069 
2070  if(!actorField)// new field detected : lets create the actor
2071  {
2073 
2074  if(dynamic_cast<axlAbstractFieldSpatial *>(field)){
2075  axlAbstractFieldSpatial *spatialField = dynamic_cast<axlAbstractFieldSpatial *>(field);
2077  fieldActor->setActorField(axlActor);
2078  fieldActor->setData(spatialField);
2079  fieldActor->setInteractor(d->widget->GetInteractor());
2080  axlAbstractView::insert(spatialField, fieldActor);
2081  connect(spatialField, SIGNAL(updated()), fieldActor, SLOT(update()));
2082  connect(axlData, SIGNAL(modifiedField()),fieldActor, SLOT(update()));
2083  d->renderer->AddActor(fieldActor);
2084  if(fieldActor->scalarBar()){
2085  // Add the scalar bar actor to the scene
2086  d->renderer->AddActor2D(fieldActor->scalarBar());
2087  }
2088  // if(field == axlData->fields().at(0)){
2089  // axlAbstractField::Kind kind = field->kind();
2090  // if(kind == axlAbstractField::Scalar){
2091  // fieldActor->displayAsColor();
2092  // }else if(kind == axlAbstractField::Vector){
2093  // fieldActor->displayAsGlyph();
2094  // }
2095  // }
2096  }else if(dynamic_cast<axlAbstractFieldParametric *>(field)){
2097  axlAbstractFieldParametric *parametricField = dynamic_cast<axlAbstractFieldParametric *>(field);
2099  fieldActor->setActorField(axlActor);
2100  fieldActor->setData(parametricField);
2101  fieldActor->setInteractor(d->widget->GetInteractor());
2102  axlAbstractView::insert(parametricField, fieldActor);
2103  connect(parametricField, SIGNAL(updated()), fieldActor, SLOT(update()));
2104  connect(axlData, SIGNAL(modifiedField()),fieldActor, SLOT(update()));
2105  d->renderer->AddActor(fieldActor);
2106  if(fieldActor->scalarBar()){
2107  // Add the scalar bar actor to the scene
2108  d->renderer->AddActor2D(fieldActor->scalarBar());
2109  }
2110 
2111  // if(field == axlData->fields().at(0)){
2112  // axlAbstractField::Kind kind = field->kind();
2113  // if(kind == axlAbstractField::Scalar){
2114  // fieldActor->displayAsColor();
2115  // }else if(kind == axlAbstractField::Vector){
2116  // fieldActor->displayAsGlyph();
2117  // }
2118  // }
2119  }else{
2121  fieldActor->setActorField(axlActor);
2122  fieldActor->setData(field);
2123  fieldActor->setInteractor(d->widget->GetInteractor());
2124  axlAbstractView::insert(field, fieldActor);
2125  connect(field, SIGNAL(updated()), fieldActor, SLOT(update()));
2126  connect(fieldActor, SIGNAL(updated()), this, SLOT(update()));
2127  connect(axlData, SIGNAL(modifiedField()),fieldActor, SLOT(update()));
2128  d->renderer->AddActor(fieldActor);
2129  if(fieldActor->scalarBar()){
2130  // Add the scalar bar actor to the scene
2131  d->renderer->AddActor2D(fieldActor->scalarBar());
2132  }
2133  // if(field == axlData->fields().at(0)){
2134  // axlAbstractField::Kind kind = field->kind();
2135  // if(kind == axlAbstractField::Scalar){
2136  // fieldActor->displayAsColor();
2137  // }else if(kind == axlAbstractField::Vector){
2138  // fieldActor->displayAsGlyph();
2139  // }
2140  // }
2141  }
2142  }
2143  else{
2144  actorField->update();
2145  }
2146  }
2147  }
2148 }
2149 
2151 
2152 // When creating data, we need to check if it contains fields
2153 
2154 void axlVtkView::insertFields(axlAbstractData *data, axlAbstractActor *actor)
2155 {
2156  foreach(axlAbstractField *field, data->fields())
2157  {
2159 
2160  if(dynamic_cast<axlAbstractFieldSpatial *>(field)){
2161  axlAbstractFieldSpatial *spatialField = dynamic_cast<axlAbstractFieldSpatial *>(field);
2163  fieldActor->setActorField(axlActor);
2164  fieldActor->setData(spatialField);
2165  fieldActor->setInteractor(d->widget->GetInteractor());
2166  axlAbstractView::insert(spatialField, fieldActor);
2167  connect(spatialField, SIGNAL(updated()), fieldActor, SLOT(update()));
2168  connect(data, SIGNAL(modifiedField()),fieldActor, SLOT(update()));
2169  d->renderer->AddActor(fieldActor);
2170  if(fieldActor->scalarBar()){
2171  // Add the scalar bar actor to the scene
2172  d->renderer->AddActor2D(fieldActor->scalarBar());
2173  }
2174 
2175  }else if(dynamic_cast<axlAbstractFieldParametric *>(field)){
2176  axlAbstractFieldParametric *parametricField = dynamic_cast<axlAbstractFieldParametric *>(field);
2178  fieldActor->setActorField(axlActor);
2179  fieldActor->setData(parametricField);
2180  fieldActor->setInteractor(d->widget->GetInteractor());
2181  axlAbstractView::insert(parametricField, fieldActor);
2182  connect(parametricField, SIGNAL(updated()), fieldActor, SLOT(update()));
2183  connect(data, SIGNAL(modifiedField()),fieldActor, SLOT(update()));
2184  d->renderer->AddActor(fieldActor);
2185  if(fieldActor->scalarBar()){
2186  // Add the scalar bar actor to the scene
2187  d->renderer->AddActor2D(fieldActor->scalarBar());
2188  }
2189 
2190  }else{
2192  fieldActor->setActorField(axlActor);
2193  fieldActor->setData(field);
2194  fieldActor->setInteractor(d->widget->GetInteractor());
2195  axlAbstractView::insert(field, fieldActor);
2196  connect(field, SIGNAL(updated()), fieldActor, SLOT(update()));
2197  connect(data, SIGNAL(modifiedField()),fieldActor, SLOT(update()));
2198  d->renderer->AddActor(fieldActor);
2199  if(fieldActor->scalarBar()){
2200  // Add the scalar bar actor to the scene
2201  d->renderer->AddActor2D(fieldActor->scalarBar());
2202  }
2203  }
2204  }
2205 }
2206 
2207 void axlVtkView::updateFieldActor(dtkAbstractData *data)
2208 {
2209  if(axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(data))
2210  {
2211  foreach(axlAbstractField *field, axlData->fields())
2212  {
2213  axlActorFieldDiscrete *actorField = dynamic_cast<axlActorFieldDiscrete *> (axlAbstractView::actor(field));
2214 
2215  if(!actorField)// new field detected : lets create the actor
2216  {
2217  axlAbstractActor *axlActor = axlAbstractView::actor(data);
2218 
2219  if(dynamic_cast<axlAbstractFieldSpatial *>(field)){
2220  qDebug() << Q_FUNC_INFO << field->identifier();
2221  axlAbstractFieldSpatial *spatialField = dynamic_cast<axlAbstractFieldSpatial *>(field);
2223  fieldActor->setActorField(axlActor);
2224  fieldActor->setData(spatialField);
2225  fieldActor->setInteractor(d->widget->GetInteractor());
2226  axlAbstractView::insert(spatialField, fieldActor);
2227  connect(spatialField, SIGNAL(updated()), fieldActor, SLOT(update()));
2228  connect(data, SIGNAL(modifiedField()),fieldActor, SLOT(update()));
2229  d->renderer->AddActor(fieldActor);
2230  if(fieldActor->scalarBar()){
2231  // Add the scalar bar actor to the scene
2232  d->renderer->AddActor2D(fieldActor->scalarBar());
2233  }
2234 
2235  }else if(dynamic_cast<axlAbstractFieldParametric *>(field)){
2236  axlAbstractFieldParametric *parametricField = dynamic_cast<axlAbstractFieldParametric *>(field);
2238  fieldActor->setActorField(axlActor);
2239  fieldActor->setData(parametricField);
2240  fieldActor->setInteractor(d->widget->GetInteractor());
2241  axlAbstractView::insert(parametricField, fieldActor);
2242  connect(parametricField, SIGNAL(updated()), fieldActor, SLOT(update()));
2243  connect(data, SIGNAL(modifiedField()),fieldActor, SLOT(update()));
2244  d->renderer->AddActor(fieldActor);
2245  if(fieldActor->scalarBar()){
2246  // Add the scalar bar actor to the scene
2247  d->renderer->AddActor2D(fieldActor->scalarBar());
2248  }
2249 
2250  }else{
2252  fieldActor->setActorField(axlActor);
2253  fieldActor->setData(field);
2254  fieldActor->setInteractor(d->widget->GetInteractor());
2255  axlAbstractView::insert(field, fieldActor);
2256  connect(field, SIGNAL(updated()), fieldActor, SLOT(update()));
2257  connect(data, SIGNAL(modifiedField()),fieldActor, SLOT(update()));
2258  d->renderer->AddActor(fieldActor);
2259  if(fieldActor->scalarBar()){
2260  // Add the scalar bar actor to the scene
2261  d->renderer->AddActor2D(fieldActor->scalarBar());
2262  }
2263 
2264  }
2265  }
2266  }
2267  }
2268  else
2269  qDebug()<< " data is not an axlAbstractData *";
2270 }
2271 
2272 
2273 // /////////////////////////////////////////////////////////////////
2274 // Type instanciation
2275 // /////////////////////////////////////////////////////////////////
2276 
2277 dtkAbstractView *createVtkView(void)
2278 {
2279  return new axlVtkView;
2280 }
void onShowAxis(bool show)
static axlActorFieldParametric * New(void)
static axlActorSphere * New(void)
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void cameraUp(double *coordinates)
Definition: axlVtkView.cpp:495
Class axlAbstractFieldParametric defines an API for parametric field.
void setParallelCamera(bool parallel)
virtual void setData(dtkAbstractData *line1)
QList< axlAbstractActor * > insertSet(QList< axlAbstractData * > dataSet)
Definition: axlVtkView.cpp:525
void setCameraViewPositiveZ(void)
dtkAbstractView * createVtkView(void)
Class axlLine defines 3D lines.
Definition: axlLine.h:35
static axlActorCylinder * New(void)
void setCameraViewDefaut(void)
void cameraFocalPoint(double *coordinates)
Definition: axlVtkView.cpp:509
virtual void setDisplay(bool display)
Definition: axlActor.cpp:440
void setCameraViewNegativeX(void)
void setLight(int i, bool hide, double *position, double *ambiant, double *diffuse, double *specular, int exponent)
bool getBackgroundGradient(void)
void setCameraFocalPoint(double x, double y, double z)
virtual void setData(dtkAbstractData *spline_Surface1)
vtkSmartPointer< vtkAxesActor > observerAxesActor
Definition: axlVtkView.cpp:260
double * getCameraFocalPoint(void)
void setInteractor(void *interactor)
virtual void setInteractor(void *interactor)
double * getWorldCameraPosition(void)
double * getBackgroundColor(void)
void setActorField(axlAbstractActor *actor)
void setQVTKWidget(QVTKOpenGLWidget *widget)
static vtkViewObserver * New(void)
Definition: axlVtkView.cpp:128
Class axlCylinder defines 3D cylinders.
Definition: axlCylinder.h:33
static axlActorCone * New(void)
bool getAxesVisibility(void)
Class axlPlane defines 3D planes.
Definition: axlPlane.h:34
static axlActorVolumeDiscrete * New(void)
virtual void setData(dtkAbstractData *spline_curve1)
virtual ~axlVtkView(void)
Definition: axlVtkView.cpp:410
static axlActorVolumeBSpline * New(void)
virtual void setData(dtkAbstractData *point1)
void setCameraViewPositiveX(void)
virtual void setData(dtkAbstractData *spline_Volume1)
static axlActorShapeBSpline * New(void)
virtual void setData(dtkAbstractData *data1)
virtual QString description(void) const
Definition: axlVtkView.cpp:442
void setGrid(bool isGridX, bool isGridY, bool isGridZ)
void setQVTKWidget(QVTKOpenGLWidget *widget)
virtual void removeField(dtkAbstractData *data)
virtual QString identifier(void) const
void setActorField(axlAbstractActor *actor)
void setWorldCamera(void)
Definition: axlVtkView.cpp:447
void setQVTKWidget(QVTKOpenGLWidget *widget)
static axlActorFieldDiscrete * New(void)
void setCameraPosition(double x, double y, double z)
Definition: axlVtkView.cpp:516
static axlActorPlane * New(void)
void setData(dtkAbstractData *volume)
void setInteractor(void *interactor)
void setView(axlAbstractView *view)
virtual void setInteractor(void *interactor)
Definition: axlActor.cpp:254
virtual void removeData(dtkAbstractData *data)
static axlActorCurveBSpline * New(void)
void setView(axlAbstractView *view)
void onUpdateActorField(QList< axlAbstractData * > axlDataSet, QString fieldName)
virtual void setData(dtkAbstractData *data1)
void cameraPosition(double *coordinates)
Definition: axlVtkView.cpp:502
static axlActorLine * New(void)
Class axlDataDynamic defines a dynamic object.
virtual void Execute(vtkObject *caller, unsigned long event, void *)
Definition: axlVtkView.cpp:133
void updateFieldActor(dtkAbstractData *data)
Use view as input to update fields actors on a data.
void setDisplay(bool display)
vtkScalarBarActor * scalarBar(void)
static axlActorSurfaceBSpline * New(void)
void setData(dtkAbstractData *data)
vtkSmartPointer< vtkCellPicker > observerViewerPicker
Definition: axlVtkView.cpp:257
void setQVTKWidget(QVTKOpenGLWidget *widget)
Class axlSphere defines 3D spheres.
Definition: axlSphere.h:33
vtkSmartPointer< vtkRenderer > observerRenderer
Definition: axlVtkView.cpp:259
virtual void setData(dtkAbstractData *field)
virtual void setData(dtkAbstractData *cylinder1)
vtkScalarBarActor * scalarBar(void)
void setObjectCamera(void)
Definition: axlVtkView.cpp:456
void setActorField(axlAbstractActor *actor)
virtual axlAbstractActor * actor(dtkAbstractData *data)
Class axlAbstractFieldSpatial defines an API for spatial field.
virtual void setData(dtkAbstractData *cone1)
void setJoystickInteractor(void)
Definition: axlVtkView.cpp:474
virtual void setData(dtkAbstractData *torus1)
void setRenderer(vtkRenderer *renderer)
vtkRenderWindowInteractor * observerInteractor
Definition: axlVtkView.cpp:258
void onBackgroundGradientChange(bool gradient)
void setQVTKWidget(QVTKOpenGLWidget *widget)
void setDisplay(bool display)
virtual void setData(dtkAbstractData *sphere1)
void setCameraViewPositiveY(void)
Class axlAbstractField defines an API for arrays of numeric data.
double * getCameraUp(void)
virtual void setData(dtkAbstractData *spline_shape1)
void setRenderer(vtkRenderer *renderer)
void setQVTKWidget(QVTKOpenGLWidget *widget)
static axlLightsWidget * New()
virtual void setData(dtkAbstractData *field)
void setQVTKWidget(QVTKOpenGLWidget *widget)
static axlActorComposite * New(void)
void setRenderer(vtkRenderer *renderer)
void activeDefaultLigh(bool useDefaultLight)
void bounds(float &xmin, float &xmax, float &ymin, float &ymax, float &zmin, float &zmax)
Definition: axlVtkView.cpp:483
virtual axlAbstractActor * insert(axlAbstractData *data)
void removeSetFields(QList< axlAbstractActorField * > actorSet)
Definition: axlVtkView.cpp:854
virtual void setData(dtkAbstractData *plane1)
void setBackgroundColor(double red, double green, double blue)
virtual void setData(dtkAbstractData *ellipsoid1)
void setDisplay(bool display)
void setParallelScale(double parallelScale)
double getCameraViewAngle(void)
bool getParallelProjection(void)
Class axlShapeBSpline defines a set of boundary curves (Edges) and bspline surface patches (Face)...
Class axlCone defines 3D cones.
Definition: axlCone.h:34
void setCameraUp(double x, double y, double z)
static axlActorMesh * New(void)
void setQVTKWidget(QVTKOpenGLWidget *widget)
void setCameraViewNegativeZ(void)
void onGridResolutionChanged(int resolution)
static axlActorSurfaceTrimmed * New(void)
void setCameraViewNegativeY(void)
QList< axlAbstractField * > fields(void)
axlVtkView(void)
Definition: axlVtkView.cpp:312
vtkScalarBarActor * scalarBar(void)
void setSurface(axlAbstractSurfaceTrimmed *Surface)
void setInteractor(void *interactor)
QVTKOpenGLWidget * widget
Definition: axlVtkView.cpp:261
QWidget * widget(void)
void setTrackballInteractor(void)
Definition: axlVtkView.cpp:465
static dtkAbstractViewFactory * viewFactSingleton
double getParallelScale(void)
axlAbstractActor * insert(axlAbstractData *data)
Definition: axlVtkView.cpp:969
virtual void setData(dtkAbstractData *field)
void stateChanged(dtkAbstractData *data, int mode)
static axlActorPoint * New(void)
Class axlEllipsoid defines 3D ellipsoids.
Definition: axlEllipsoid.h:35
void update(void)
static bool registered(void)
Definition: axlVtkView.cpp:436
Class axlAbstractData defines an API for all type of axel data.
void removeSet(QList< axlAbstractActor * > actorSet)
Definition: axlVtkView.cpp:912
static axlActorTorus * New(void)
void setQVTKWidget(QVTKOpenGLWidget *widget)
static axlActorFieldSpatial * New(void)
double angle(axlPoint vCompute, axlPoint vRef, axlPoint normal)
static axlActorDataDynamic * New(void)
void setCameraViewAngle(double angle)