Developer documentation | Axl-2.5.1

axlControlPointsWidget.cpp
Go to the documentation of this file.
1 /* axlControlPointsWidget.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Fri Feb 18 17:29:04 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Mon Dec 17 14:40:31 2012 (+0100)
8  * By: Julien Wintz
9  * Update #: 130
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlActorCurveBSpline.h"
21 #include "axlActorSurfaceBSpline.h"
22 #include "axlActorShapeBSpline.h"
23 #include "axlControlPointsWidget.h"
25 
26 #include <axlCore/axlPoint.h>
31 
32 
33 #include <vtkActor.h>
34 #include <vtkAssemblyNode.h>
35 #include <vtkAssemblyPath.h>
36 #include <vtkCallbackCommand.h>
37 #include <vtkCamera.h>
38 #include <vtkCellArray.h>
39 #include <vtkCellPicker.h>
40 #include <vtkAreaPicker.h>
41 #include <vtkDoubleArray.h>
42 #include <vtkFloatArray.h>
43 #include <vtkLine.h>
44 #include <vtkObjectFactory.h>
45 #include <vtkPlanes.h>
46 #include <vtkPoints.h>
47 #include <vtkPolyData.h>
48 #include <vtkPolyDataMapper.h>
49 #include <vtkDataSetMapper.h>
50 #include <vtkMapper.h>
51 #include <vtkUnstructuredGrid.h>
52 #include <vtkDataSetMapper.h>
53 #include <vtkProperty.h>
54 #include <vtkRenderWindowInteractor.h>
55 #include <vtkRenderer.h>
56 #include <vtkRendererCollection.h>
57 #include <vtkRenderWindow.h>
58 #include <vtkSphereSource.h>
59 #include <vtkTransform.h>
60 #include <vtkGlyph3D.h>
61 #include <vtkSmartPointer.h>
62 #include <vtkTransform.h>
63 #include <vtkCursor3D.h>
64 #include <vtkProp3DCollection.h>
65 #include <vtkProp.h>
66 #include <vtkPropAssembly.h>
67 #include <vtkCollectionIterator.h>
68 #include <vtkCommand.h>
69 
70 #include <vtkRenderWindow.h>
71 
72 #include <vtkDistanceToCamera.h>
73 #include <vtkArrowSource.h>
74 #include <vtkPointSource.h>
75 
77 
78 class axlControlPointsWidgetPrivate
79 {
80 public:
81 
82  vtkActor **CpActor;
83  vtkPolyDataMapper **CpMapper;
84  vtkDataSetMapper ** CpMapper3D;
85  vtkSphereSource **CpSphere;
86 
87  vtkActor *CpCurrentActor;
88  int CpCurrentActorIndex;
89  vtkPoints *CpPoints; //used by others as well
90  vtkCellPicker *CpCursorPicker;
91  vtkAreaPicker *CpRectanglePicker;
92  axlInteractorStyleRubberBandPick *CpRubberBanPick;
93  vtkProperty *CpHandleProperty;
94  vtkProperty *CpSelectedHandleProperty;
95  dtkAbstractData *CpSpline;
96 
97  vtkAssemblyNode *CpCurrentAssemblyNode;
98 
99  vtkActorCollection *CpActorCollection;
100 
101  // Number of control points
102  int numCps;
103  // control points size scale
104  double radiusScaleCps;
105 
106  // rectangle behavior
107  int XStartPosition;
108  int YStartPosition;
109 
110  //lines between points
111  vtkCellArray *CpCellAray;
112  vtkPolyData *CpPolyData;
113  vtkPolyDataMapper *CpPolyDataMapper;
114  vtkUnstructuredGrid *CpUnstructuredGrid;
115  vtkDataSetMapper *CpDataSetMapper;
116  vtkActor *CpPolyDataActor;
117 
118  //the 3dCursor
119  vtkPolyDataMapper *CpCursorPolyDataMapper;
120  vtkActor *CpCursorActor;
121 
122 public:
123 
124  ~axlControlPointsWidgetPrivate()
125  {
126 
127  CpPoints->Delete();
128  CpCellAray->Delete();
129  CpPolyData->Delete();
130  CpUnstructuredGrid->Delete();
131 
132  CpPolyDataMapper->Delete();
133 
134  CpPolyDataActor->Delete();
135  CpCursorPicker->Delete();
136  CpRectanglePicker->Delete();
137 
138  CpActorCollection->InitTraversal();
139  vtkObject * o = CpActorCollection->GetNextItem();
140  int k = 0;// .. to numCps
141  while(o!=NULL)
142  {
143  CpSphere[k]->Delete();
144  CpActor[k]->Delete();
145  //CpMapper3D[k]->Delete();// ! only for volumes
146 
147  ++k;// Next
148  o = CpActorCollection->GetNextItem();
149  }
150 
151  CpActorCollection->Delete();
152 
153  // delete CpActor;
154  // delete CpMapper3D;
155  // delete CpSphere;
156  }
157 
158 };
159 
160 axlControlPointsWidget::axlControlPointsWidget() :d(new axlControlPointsWidgetPrivate)
161 {
163  this->EventCallbackCommand->SetCallback(axlControlPointsWidget::ProcessEvents);
164  // Set up the initial properties
165  this->CreateDefaultProperties();
166 
167  // connection for the cursor
168  d->CpCursorPolyDataMapper = vtkPolyDataMapper::New();
169  d->CpCursorActor = vtkActor::New();
170  d->CpCursorActor->VisibilityOff();
171  d->CpCursorActor->SetMapper(d->CpCursorPolyDataMapper);
172 
173 
174  // Define the point coordinates
175  double bounds[6];
176  bounds[0] = -0.5;
177  bounds[1] = 0.5;
178  bounds[2] = -0.5;
179  bounds[3] = 0.5;
180  bounds[4] = -0.5;
181  bounds[5] = 0.5;
182 
183  d->XStartPosition =-1;
184  d->YStartPosition =-1;
185 
186  this->PlaceWidget(bounds);
187 }
188 
190 {
191  delete d;
192 
193  d = NULL;
194 }
195 
196 void axlControlPointsWidget::setSpline(dtkAbstractData *spline)
197 {
198  d->CpSpline = spline;
199  d->numCps = 0;
200  d->radiusScaleCps = 1.15;
201  if(axlAbstractCurveBSpline *spl = dynamic_cast<axlAbstractCurveBSpline *>(d->CpSpline))
202  {
203  d->numCps = spl->countControlPoints();
204  }
205  if(axlAbstractSurfaceBSpline *spl = dynamic_cast<axlAbstractSurfaceBSpline *>(d->CpSpline))
206  {
207  d->numCps = spl->countControlPoints();
208  }
209  if(axlAbstractVolumeBSpline *spl= dynamic_cast<axlAbstractVolumeBSpline *>(d->CpSpline))
210  {
211  d->numCps = spl->countControlPoints();
212  }
213  if(axlShapeBSpline *spl= dynamic_cast<axlShapeBSpline *>(d->CpSpline))
214  {
215  d->numCps = spl->countControlPoints();
216  }
217 }
218 
220 {
221  d->CpCurrentActor = NULL;
222 
223  // construct initial points CellAray and PolyData or UnstructuredGrid
224  d->CpPoints = vtkPoints::New();
225  d->CpCellAray = vtkCellArray::New();
226  d->CpPolyData = vtkPolyData::New();
227  d->CpUnstructuredGrid = vtkUnstructuredGrid::New();
228 
229  // connection for the line
230  d->CpPolyDataMapper = vtkPolyDataMapper::New();
231 #if (VTK_MAJOR_VERSION <= 5)
232  d->CpPolyDataMapper->SetInput(d->CpPolyData);
233 #else
234  d->CpPolyDataMapper->SetInputData(d->CpPolyData);
235 #endif
236  d->CpDataSetMapper = vtkDataSetMapper::New();
237 #if (VTK_MAJOR_VERSION <= 5)
238  d->CpDataSetMapper->SetInput(d->CpUnstructuredGrid);
239 #else
240  d->CpDataSetMapper->SetInputData(d->CpUnstructuredGrid);
241 #endif
242  d->CpPolyDataActor = vtkActor::New();
243  if(dynamic_cast<axlAbstractVolumeBSpline*> (d->CpSpline))
244  {
245  d->CpPolyDataActor->SetMapper(d->CpDataSetMapper);
246  }else {
247  d->CpPolyDataActor->SetMapper(d->CpPolyDataMapper);
248  }
249  d->CpPolyDataActor->SetPickable(0);
250 
251  //Manage the picking stuff
252  d->CpCursorPicker = vtkCellPicker::New();
253  d->CpRectanglePicker = vtkAreaPicker::New();
254  //d->CpRubberBanPick = dynamic_cast<axlInteractorStyleRubberBandPick *>(this->Interactor->GetInteractorStyle());//axlInteractorStyleRubberBandPick::New();
255  this->Interactor->SetPicker(d->CpRectanglePicker);
256 
257  //compute side of controlPoints
258  double bounds[6];this->Prop3D->GetBounds(bounds);
259  double side = qAbs(bounds[1]-bounds[0]);
260  side += qAbs(bounds[3]-bounds[2]);
261  side += qAbs(bounds[5]-bounds[4]);
262 
263  side/=600;
264 
265  // Storage of the control Points depend of the kind of Spline
266  if(axlAbstractCurveBSpline *splineCurve = dynamic_cast<axlAbstractCurveBSpline *>(d->CpSpline))
267  {
268  d->CpMapper = new vtkPolyDataMapper *[splineCurve->numCoefs()];
269  d->CpSphere = new vtkSphereSource *[splineCurve->numCoefs()];
270  d->CpActor = new vtkActor *[splineCurve->numCoefs()];
271  d->CpActorCollection = vtkActorCollection::New();
272 
273  side = (((splineCurve->size()*d->radiusScaleCps)>side) ? (splineCurve->size()*d->radiusScaleCps):side);
274 
275  for (int i = 0; i < splineCurve->numCoefs(); i++)
276  {
277  //storage of points
278  axlPoint pointCourant = splineCurve->getCoef(i + 1);
279  d->CpPoints->InsertNextPoint(pointCourant.x(), pointCourant.y(), pointCourant.z());
280 
281  // Construct the poly data representing control points
282  d->CpMapper[i] = vtkPolyDataMapper::New();
283  d->CpSphere[i] =vtkSphereSource::New();
284  d->CpSphere[i]->SetPhiResolution(15);
285  d->CpSphere[i]->SetThetaResolution(15);
286  d->CpSphere[i]->SetRadius(side);
287  d->CpSphere[i]->SetCenter(d->CpPoints->GetPoint(i));
288 #if (VTK_MAJOR_VERSION <= 5)
289  d->CpMapper[i]->SetInput( d->CpSphere[i]->GetOutput());
290 #else
291  d->CpMapper[i]->SetInputData( d->CpSphere[i]->GetOutput());
292 #endif
293  d->CpActor[i] = vtkActor::New();
294  d->CpActor[i]->SetMapper(d->CpMapper[i]);
295  d->CpActor[i]->VisibilityOn();
296 
297  d->CpSphere[i]->Modified();
298  d->CpSphere[i]->Update();
299 
303 
304 // //Calculate the distance to the camera of each CpSphere.
305 // vtkSmartPointer<vtkDistanceToCamera> distanceToCamera = vtkSmartPointer<
306 // vtkDistanceToCamera>::New();
307 // distanceToCamera->SetInputConnection(d->CpSphere[i]->GetOutputPort());
308 // distanceToCamera->SetScreenSize(10.0);
309 
310 
311 // // Glyph each point with a sphere.
312 // vtkSmartPointer<vtkSphereSource> spheres =
313 // vtkSmartPointer<vtkSphereSource>::New();
314 // vtkSmartPointer<vtkGlyph3D> fixedGlyph = vtkSmartPointer<vtkGlyph3D>::New();
315 // fixedGlyph->SetInputConnection(distanceToCamera->GetOutputPort());
316 // fixedGlyph->SetSourceConnection(spheres->GetOutputPort());
317 
318 // // Scale each point.
319 // fixedGlyph->SetScaleModeToScaleByScalar();
320 // fixedGlyph->SetInputArrayToProcess(0, 0, 0,
321 // vtkDataObject::FIELD_ASSOCIATION_POINTS, "DistanceToCamera");
322 
323 // // Create a mapper.
324 // vtkSmartPointer<vtkPolyDataMapper> fixedMapper = vtkSmartPointer<
325 // vtkPolyDataMapper>::New();
326 // fixedMapper->SetInputConnection(fixedGlyph->GetOutputPort());
327 // fixedMapper->SetScalarVisibility(false);
328 
329 // //create a renderer if NULL
330 // if(!this->CurrentRenderer){
331 // this->SetCurrentRenderer(this->Interactor->FindPokedRenderer(
332 // this->Interactor->GetLastEventPosition()[0],
333 // this->Interactor->GetLastEventPosition()[1]));
334 // }
335 // distanceToCamera->SetRenderer(this->CurrentRenderer);
336 
337 // d->CpActor[i]->SetMapper(fixedMapper);
339 
340  d->CpActorCollection->AddItem(d->CpActor[i]);
341 
342 
343  }
344 
345  //Here are made the line connection, there is one and only way to connect points together. We can just connect neighbors.
346  //That's what we will have to change
347  // for(int i = 0; i < splineCurve->numCoefs() - 1; i++)
348  // {
349  // vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
350  // currentline->GetPointIds()->SetId(0, i);
351  // currentline->GetPointIds()->SetId(1, i + 1);
352  // d->CpCellAray->InsertNextCell(currentline);
353  // }
354  for(int i = 0; i < splineCurve->numCoefs() - 1; i++)
355  {
356  if(splineCurve->connectionsAreDefined()){
357  QList<int> connections = splineCurve->getControlPointConnection(i);
358  foreach(int value, connections){
359  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
360  currentline->GetPointIds()->SetId(0, i);
361  currentline->GetPointIds()->SetId(1, value);
362  d->CpCellAray->InsertNextCell(currentline);
363  }
364  }else{
365  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
366  currentline->GetPointIds()->SetId(0, i);
367  currentline->GetPointIds()->SetId(1, i + 1);
368  d->CpCellAray->InsertNextCell(currentline);
369  }
370  }
371 
372  // association of the glyph and the control Points
373  d->CpPolyData->SetPoints(d->CpPoints);
374  d->CpPolyData->SetLines(d->CpCellAray);
375  }
376 
377  if(axlAbstractSurfaceBSpline *splineSurface =dynamic_cast<axlAbstractSurfaceBSpline *>(d->CpSpline))
378  {
379  d->CpMapper = new vtkPolyDataMapper *[d->numCps];
380  d->CpSphere = new vtkSphereSource *[d->numCps];
381  d->CpActor = new vtkActor *[d->numCps];
382  d->CpActorCollection = vtkActorCollection::New();
383 
384  // for(int i = 0; i < splineSurface->countControlPoints_v(); i++)
385  // {
386  // for(int j = 0; j < nbCoeffs_u; j++)
387  // {
388  // axlPoint pointCourant = splineSurface->getCoef(j + 1, i + 1);
389  // d->CpPoints->InsertNextPoint(pointCourant.x(), pointCourant.y(), pointCourant.z());
390 
391  // // Construct the poly data representing control points
392  // d->CpMapper[i * nbCoeffs_u + j] = vtkPolyDataMapper::New();
393  // d->CpSphere[i * nbCoeffs_u + j] =vtkSphereSource::New();
394  // d->CpSphere[i * nbCoeffs_u + j]->SetPhiResolution(15);
395  // d->CpSphere[i * nbCoeffs_u + j]->SetThetaResolution(15);
396  // d->CpSphere[i * nbCoeffs_u + j]->SetRadius(side);
397  // d->CpSphere[i * nbCoeffs_u + j]->SetCenter(d->CpPoints->GetPoint(i * nbCoeffs_u + j));
398  //#if (VTK_MAJOR_VERSION <= 5)
399  // d->CpMapper[i * nbCoeffs_u + j]->SetInput( d->CpSphere[i * nbCoeffs_u + j]->GetOutput());
400  //#else
401  // d->CpMapper[i * nbCoeffs_u + j]->SetInputData( d->CpSphere[i * nbCoeffs_u + j]->GetOutput());
402  //#endif
403  // d->CpActor[i * nbCoeffs_u + j] = vtkActor::New();
404  // d->CpActor[i * nbCoeffs_u + j]->SetMapper(d->CpMapper[i * nbCoeffs_u + j]);
405  // d->CpActor[i * nbCoeffs_u + j]->VisibilityOn();
406  // // d->CpCursorPicker->AddPickList(d->CpActor[i*nbCoeffs_u+j]);
407  // // d->CpRectanglePicker->AddPickList(d->CpActor[i*nbCoeffs_u+j]);
408  // d->CpCursorPicker->SetTolerance(0.001); //need some fluff
409 
410  // d->CpActorCollection->AddItem(d->CpActor[i * nbCoeffs_u + j]);
411  // }
412  // }
413 
414  side = (splineSurface->size()>side ? splineSurface->size():side);
415 
416  //To generalize.
417  for(int i = 0; i < d->numCps; i++)
418  {
419 
420  axlPoint pointCourant = splineSurface->getCoef(i+1);
421  d->CpPoints->InsertNextPoint(pointCourant.x(), pointCourant.y(), pointCourant.z());
422 
423  // Construct the poly data representing control points
424  d->CpMapper[i] = vtkPolyDataMapper::New();
425  d->CpSphere[i] =vtkSphereSource::New();
426  d->CpSphere[i]->SetPhiResolution(15);
427  d->CpSphere[i]->SetThetaResolution(15);
428  d->CpSphere[i]->SetRadius(side);
429  d->CpSphere[i]->SetCenter(d->CpPoints->GetPoint(i));
430 #if (VTK_MAJOR_VERSION <= 5)
431  d->CpMapper[i]->SetInput( d->CpSphere[i]->GetOutput());
432 #else
433  d->CpMapper[i]->SetInputData( d->CpSphere[i]->GetOutput());
434 #endif
435  d->CpActor[i] = vtkActor::New();
436  d->CpActor[i]->SetMapper(d->CpMapper[i]);
437  d->CpActor[i]->VisibilityOn();
438  // d->CpCursorPicker->AddPickList(d->CpActor[i*nbCoeffs_u+j]);
439  // d->CpRectanglePicker->AddPickList(d->CpActor[i*nbCoeffs_u+j]);
440  d->CpCursorPicker->SetTolerance(0.001); //need some fluff
441 
442  d->CpSphere[i]->Modified();
443  d->CpSphere[i]->Update();
444 
445 
446 
450 
451 // //Calculate the distance to the camera of each CpSphere.
452 // vtkSmartPointer<vtkDistanceToCamera> distanceToCamera = vtkSmartPointer<
453 // vtkDistanceToCamera>::New();
454 // distanceToCamera->SetInputConnection(d->CpSphere[i]->GetOutputPort());
455 // distanceToCamera->SetScreenSize(10.0);
456 
457 
458 // // Glyph each point with a sphere.
459 // vtkSmartPointer<vtkSphereSource> spheres =
460 // vtkSmartPointer<vtkSphereSource>::New();
461 // vtkSmartPointer<vtkGlyph3D> fixedGlyph = vtkSmartPointer<vtkGlyph3D>::New();
462 // fixedGlyph->SetInputConnection(distanceToCamera->GetOutputPort());
463 // fixedGlyph->SetSourceConnection(spheres->GetOutputPort());
464 
465 // // Scale each point.
466 // fixedGlyph->SetScaleModeToScaleByScalar();
467 // fixedGlyph->SetInputArrayToProcess(0, 0, 0,
468 // vtkDataObject::FIELD_ASSOCIATION_POINTS, "DistanceToCamera");
469 
470 // // Create a mapper.
471 // vtkSmartPointer<vtkPolyDataMapper> fixedMapper = vtkSmartPointer<
472 // vtkPolyDataMapper>::New();
473 // fixedMapper->SetInputConnection(fixedGlyph->GetOutputPort());
474 // fixedMapper->SetScalarVisibility(false);
475 
476 // //create a renderer if NULL
477 // if(!this->CurrentRenderer){
478 // this->SetCurrentRenderer(this->Interactor->FindPokedRenderer(
479 // this->Interactor->GetLastEventPosition()[0],
480 // this->Interactor->GetLastEventPosition()[1]));
481 // }
482 // distanceToCamera->SetRenderer(this->CurrentRenderer);
483 
484 // d->CpActor[i]->SetMapper(fixedMapper);
486 
487  d->CpActorCollection->AddItem(d->CpActor[i]);
488 
489  }
490 
491  if(!splineSurface->connectionsAreDefined()){
492  //Default display is a grid.
493  int nbCoeffs_u = splineSurface->countControlPoints_u();// little optimization;
494 
495  for(int i = 0; i < splineSurface->countControlPoints_v() - 1; i++)
496  {
497 
498  for(int j = 0; j < nbCoeffs_u - 1; j++)
499  {
500  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
501  currentline->GetPointIds()->SetId(0, i * nbCoeffs_u + j);
502  currentline->GetPointIds()->SetId(1, i * nbCoeffs_u + j + 1);
503 
504  vtkSmartPointer<vtkLine> currentline2 = vtkSmartPointer<vtkLine>::New();
505  currentline2->GetPointIds()->SetId(0, i * nbCoeffs_u + j);
506  currentline2->GetPointIds()->SetId(1, (i + 1) * nbCoeffs_u + j);
507 
508  d->CpCellAray->InsertNextCell(currentline);
509  d->CpCellAray->InsertNextCell(currentline2);
510  }
511 
512  // we had some boundary lines
513  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
514  currentline->GetPointIds()->SetId(0, i * nbCoeffs_u + nbCoeffs_u - 1);
515  currentline->GetPointIds()->SetId(1,(i + 1) * nbCoeffs_u + nbCoeffs_u - 1);
516  d->CpCellAray->InsertNextCell(currentline);
517  }
518 
519  // had of the boundary lines of the other side
520  for(int i = 0; i < nbCoeffs_u - 1; i++)
521  {
522  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
523  currentline->GetPointIds()->SetId(0, (splineSurface->countControlPoints_v() - 1) * nbCoeffs_u + i);
524  currentline->GetPointIds()->SetId(1, (splineSurface->countControlPoints_v() - 1) * nbCoeffs_u + i + 1);
525  d->CpCellAray->InsertNextCell(currentline);
526  }
527  }
528  else
529  {
530  for(int i = 0 ; i < d->numCps; i++){
531  QList<int> connection = splineSurface->getControlPointConnection(i);
532  foreach(int value, connection){
533  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
534  currentline->GetPointIds()->SetId(0, i);
535  currentline->GetPointIds()->SetId(1, value);
536  d->CpCellAray->InsertNextCell(currentline);
537  }
538  }
539  }
540 
541  // association of the glyph and the control Points
542  d->CpPolyData->SetPoints(d->CpPoints);
543  d->CpPolyData->SetLines(d->CpCellAray);
544  // d->CpCursorPicker->PickFromListOn();
545  // d->CpRectanglePicker->PickFromListOn();
546  }
547 
548  if(axlShapeBSpline *splineShape =dynamic_cast<axlShapeBSpline *>(d->CpSpline))
549  {
550  d->CpMapper = new vtkPolyDataMapper *[d->numCps];
551  d->CpSphere = new vtkSphereSource *[d->numCps];
552  d->CpActor = new vtkActor *[d->numCps];
553  d->CpActorCollection = vtkActorCollection::New();
554 
555  //To generalize.
556  for(int i = 0; i < d->numCps; i++)
557  {
558 
559  axlPoint pointCourant = splineShape->getCoef(i+1);
560  d->CpPoints->InsertNextPoint(pointCourant.x(), pointCourant.y(), pointCourant.z());
561 
562  // Construct the poly data representing control points
563  d->CpMapper[i]= vtkPolyDataMapper::New();
564  d->CpSphere[i]= vtkSphereSource::New();
565  d->CpSphere[i]->SetPhiResolution(15);
566  d->CpSphere[i]->SetThetaResolution(15);
567  d->CpSphere[i]->SetRadius(side);
568  d->CpSphere[i]->SetCenter(d->CpPoints->GetPoint(i));
569 #if (VTK_MAJOR_VERSION <= 5)
570  d->CpMapper[i]->SetInput( d->CpSphere[i]->GetOutput());
571 #else
572  d->CpMapper[i]->SetInputData( d->CpSphere[i]->GetOutput());
573 #endif
574  d->CpActor[i] = vtkActor::New();
575  d->CpActor[i]->SetMapper(d->CpMapper[i]);
576  d->CpActor[i]->VisibilityOn();
577  // d->CpCursorPicker->AddPickList(d->CpActor[i*nbCoeffs_u+j]);
578  // d->CpRectanglePicker->AddPickList(d->CpActor[i*nbCoeffs_u+j]);
579  d->CpCursorPicker->SetTolerance(0.001); //need some fluff
580 
581  d->CpSphere[i]->Modified();
582  d->CpSphere[i]->Update();
583 
584  d->CpActorCollection->AddItem(d->CpActor[i]);
585 
586  }
587 
588  if(!splineShape->connectionsAreDefined()){
589  //Default display is a grid.
590  int nbCoeffs_u = splineShape->countControlPoints_u();// little optimization;
591 
592  for(int i = 0; i < splineShape->countControlPoints_v() - 1; i++)
593  {
594 
595  for(int j = 0; j < nbCoeffs_u - 1; j++)
596  {
597  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
598  currentline->GetPointIds()->SetId(0, i * nbCoeffs_u + j);
599  currentline->GetPointIds()->SetId(1, i * nbCoeffs_u + j + 1);
600 
601  vtkSmartPointer<vtkLine> currentline2 = vtkSmartPointer<vtkLine>::New();
602  currentline2->GetPointIds()->SetId(0, i * nbCoeffs_u + j);
603  currentline2->GetPointIds()->SetId(1, (i + 1) * nbCoeffs_u + j);
604 
605  d->CpCellAray->InsertNextCell(currentline);
606  d->CpCellAray->InsertNextCell(currentline2);
607  }
608 
609  // we had some boundary lines
610  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
611  currentline->GetPointIds()->SetId(0, i * nbCoeffs_u + nbCoeffs_u - 1);
612  currentline->GetPointIds()->SetId(1,(i + 1) * nbCoeffs_u + nbCoeffs_u - 1);
613  d->CpCellAray->InsertNextCell(currentline);
614  }
615 
616  // had of the boundary lines of the other side
617  for(int i = 0; i < nbCoeffs_u - 1; i++)
618  {
619  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
620  currentline->GetPointIds()->SetId(0, (splineShape->countControlPoints_v() - 1) * nbCoeffs_u + i);
621  currentline->GetPointIds()->SetId(1, (splineShape->countControlPoints_v() - 1) * nbCoeffs_u + i + 1);
622  d->CpCellAray->InsertNextCell(currentline);
623  }
624  }
625  else
626  {
627  for(int i = 0 ; i < d->numCps; i++){
628  QList<int> connection = splineShape->getControlPointConnection(i);
629  foreach(int value, connection){
630  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
631  currentline->GetPointIds()->SetId(0, i);
632  currentline->GetPointIds()->SetId(1, value);
633  d->CpCellAray->InsertNextCell(currentline);
634  }
635  }
636  }
637 
638  // association of the glyph and the control Points
639  d->CpPolyData->SetPoints(d->CpPoints);
640  d->CpPolyData->SetLines(d->CpCellAray);
641  // d->CpCursorPicker->PickFromListOn();
642  // d->CpRectanglePicker->PickFromListOn();
643  }
644 
645  if(axlAbstractVolumeBSpline *splineVolume =dynamic_cast<axlAbstractVolumeBSpline *>(d->CpSpline))
646  {
647  d->CpMapper3D = new vtkDataSetMapper *[d->numCps];
648  d->CpSphere = new vtkSphereSource *[d->numCps];
649  d->CpActor = new vtkActor *[d->numCps];
650  d->CpActorCollection = vtkActorCollection::New();
651 
652 
653  // for(int k = 0; k < nbCoeffs_w; k++)
654  // {
655  // for(int i = 0; i < nbCoeffs_v; i++)
656  // {
657  // for(int j = 0; j < nbCoeffs_u; j++)
658  // {
659  // axlPoint pointCourant = splineVolume->getCoef(j + 1, i + 1, k+1);
660  // d->CpPoints->InsertNextPoint(pointCourant.x(), pointCourant.y(), pointCourant.z());
661 
662  // // Construct the unstructured grid representing control points
663  // d->CpMapper3D[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j] = vtkDataSetMapper::New();
664  // d->CpSphere[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j] =vtkSphereSource::New();
665  // d->CpSphere[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->SetPhiResolution(15);
666  // d->CpSphere[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->SetThetaResolution(15);
667  // d->CpSphere[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->SetRadius(side);
668  // d->CpSphere[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->SetCenter(d->CpPoints->GetPoint(k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j));
669  //#if (VTK_MAJOR_VERSION <= 5)
670  // d->CpMapper3D[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->SetInput( d->CpSphere[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->GetOutput());
671  //#else
672  // d->CpMapper3D[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->SetInputData( d->CpSphere[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->GetOutput());
673  //#endif
674  // d->CpActor[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j] = vtkActor::New();
675  // d->CpActor[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->SetMapper(d->CpMapper3D[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]);
676  // d->CpActor[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]->VisibilityOn();
677  // d->CpCursorPicker->SetTolerance(0.001);
678 
679  // d->CpActorCollection->AddItem(d->CpActor[k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j]);
680  // }
681  // }
682  // }
683 
684  side = (splineVolume->size()>side ? splineVolume->size():side);
685 
686  for(int k = 0; k < d->numCps; k++)
687  {
688 
689  axlPoint pointCourant = splineVolume->getCoef(k+1);
690  d->CpPoints->InsertNextPoint(pointCourant.x(), pointCourant.y(), pointCourant.z());
691 
692  // Construct the unstructured grid representing control points
693  d->CpMapper3D[k] = vtkDataSetMapper::New();
694  d->CpSphere[k ] =vtkSphereSource::New();
695  d->CpSphere[k ]->SetPhiResolution(15);
696  d->CpSphere[k ]->SetThetaResolution(15);
697  d->CpSphere[k ]->SetRadius(side);
698  d->CpSphere[k ]->SetCenter(d->CpPoints->GetPoint(k));
699 #if (VTK_MAJOR_VERSION <= 5)
700  d->CpMapper3D[k]->SetInput( d->CpSphere[k]->GetOutput());
701 #else
702  d->CpMapper3D[k]->SetInputData( d->CpSphere[k]->GetOutput());
703 #endif
704  d->CpActor[k] = vtkActor::New();
705  d->CpActor[k]->SetMapper(d->CpMapper3D[k]);
706  d->CpActor[k]->VisibilityOn();
707  d->CpCursorPicker->SetTolerance(0.001);
708 
709  d->CpSphere[k]->Modified();
710  d->CpSphere[k]->Update();
711 
715 
716 // //Calculate the distance to the camera of each CpSphere.
717 // vtkSmartPointer<vtkDistanceToCamera> distanceToCamera = vtkSmartPointer<
718 // vtkDistanceToCamera>::New();
719 // distanceToCamera->SetInputConnection(d->CpSphere[k]->GetOutputPort());
720 // distanceToCamera->SetScreenSize(10.0);
721 
722 
723 // // Glyph each point with a sphere.
724 // vtkSmartPointer<vtkSphereSource> spheres =
725 // vtkSmartPointer<vtkSphereSource>::New();
726 // vtkSmartPointer<vtkGlyph3D> fixedGlyph = vtkSmartPointer<vtkGlyph3D>::New();
727 // fixedGlyph->SetInputConnection(distanceToCamera->GetOutputPort());
728 // fixedGlyph->SetSourceConnection(spheres->GetOutputPort());
729 
730 // // Scale each point.
731 // fixedGlyph->SetScaleModeToScaleByScalar();
732 // fixedGlyph->SetInputArrayToProcess(0, 0, 0,
733 // vtkDataObject::FIELD_ASSOCIATION_POINTS, "DistanceToCamera");
734 
735 // // Create a mapper.
736 // vtkSmartPointer<vtkPolyDataMapper> fixedMapper = vtkSmartPointer<
737 // vtkPolyDataMapper>::New();
738 // fixedMapper->SetInputConnection(fixedGlyph->GetOutputPort());
739 // fixedMapper->SetScalarVisibility(false);
740 
741 // //create a renderer if NULL
742 // if(!this->CurrentRenderer){
743 // this->SetCurrentRenderer(this->Interactor->FindPokedRenderer(
744 // this->Interactor->GetLastEventPosition()[0],
745 // this->Interactor->GetLastEventPosition()[1]));
746 // }
747 // distanceToCamera->SetRenderer(this->CurrentRenderer);
748 
749 // d->CpActor[k]->SetMapper(fixedMapper);
751 
752 
753  d->CpActorCollection->AddItem(d->CpActor[k]);
754  }
755 
756  if(!splineVolume->connectionsAreDefined()){
757  //Default display is a grid.
758  int nbCoeffs_u = splineVolume->countControlPoints_u();// little optimization;
759  int nbCoeffs_v = splineVolume->countControlPoints_v();
760  int nbCoeffs_w = splineVolume->countControlPoints_w();
761 
762  for(int k = 0; k < nbCoeffs_w - 1; k++)
763  {
764  for(int i = 0; i < nbCoeffs_v - 1; i++)
765  {
766  for(int j = 0; j < nbCoeffs_u - 1; j++)
767  {
768  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
769  currentline->GetPointIds()->SetId(0, k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j);
770  currentline->GetPointIds()->SetId(1, k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j+1);
771 
772  vtkSmartPointer<vtkLine> currentline2 = vtkSmartPointer<vtkLine>::New();
773  currentline2->GetPointIds()->SetId(0, k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j);
774  currentline2->GetPointIds()->SetId(1, k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j+ nbCoeffs_u);
775 
776  vtkSmartPointer<vtkLine> currentline3 = vtkSmartPointer<vtkLine>::New();
777  currentline3->GetPointIds()->SetId(0, k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j);
778  currentline3->GetPointIds()->SetId(1, k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + j + nbCoeffs_u* nbCoeffs_v);
779 
780  d->CpCellAray->InsertNextCell(currentline);
781  d->CpCellAray->InsertNextCell(currentline2);
782  d->CpCellAray->InsertNextCell(currentline3);
783  }
784 
785  // we had some boundary lines
786  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
787  currentline->GetPointIds()->SetId(0, k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + nbCoeffs_u - 1);
788  currentline->GetPointIds()->SetId(1,k *nbCoeffs_u *nbCoeffs_v + (i+1) * nbCoeffs_u + nbCoeffs_u - 1);
789 
790  vtkSmartPointer<vtkLine> currentline2 = vtkSmartPointer<vtkLine>::New();
791  currentline2->GetPointIds()->SetId(0, k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + nbCoeffs_u - 1 );
792  currentline2->GetPointIds()->SetId(1,k *nbCoeffs_u *nbCoeffs_v + i * nbCoeffs_u + nbCoeffs_u - 1+ nbCoeffs_u* nbCoeffs_v);
793 
794  d->CpCellAray->InsertNextCell(currentline);
795  d->CpCellAray->InsertNextCell(currentline2);
796  }
797 
798  // we had some boundary lines
799  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
800  currentline->GetPointIds()->SetId(0, k *nbCoeffs_u *nbCoeffs_v + (nbCoeffs_v - 1) * nbCoeffs_u + nbCoeffs_u - 1 );
801  currentline->GetPointIds()->SetId(1,(k+1) *nbCoeffs_u *nbCoeffs_v + (nbCoeffs_v - 1) * nbCoeffs_u + nbCoeffs_u - 1);
802  d->CpCellAray->InsertNextCell(currentline);
803  }
804 
805  // had of the boundary lines of the other side
806  for(int j = 0; j < nbCoeffs_v - 1; j++)
807  {
808  for(int i = 0; i < nbCoeffs_u - 1; i++)
809  {
810  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
811  currentline->GetPointIds()->SetId(0, ( (nbCoeffs_w -1 ) *nbCoeffs_u *nbCoeffs_v + j * nbCoeffs_u + i));
812  currentline->GetPointIds()->SetId(1, ((nbCoeffs_w -1 ) *nbCoeffs_u *nbCoeffs_v + j * nbCoeffs_u + i +1));
813 
814  vtkSmartPointer<vtkLine> currentline2 = vtkSmartPointer<vtkLine>::New();
815  currentline2->GetPointIds()->SetId(0, ((nbCoeffs_w -1 ) *nbCoeffs_u *nbCoeffs_v + j * nbCoeffs_u + i));
816  currentline2->GetPointIds()->SetId(1, ((nbCoeffs_w -1 ) *nbCoeffs_u *nbCoeffs_v + (j+1) * nbCoeffs_u + i));
817 
818  d->CpCellAray->InsertNextCell(currentline);
819  d->CpCellAray->InsertNextCell(currentline2);
820  }
821 
822  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
823  currentline->GetPointIds()->SetId(0, ((nbCoeffs_w -1 ) *nbCoeffs_u *nbCoeffs_v + j * nbCoeffs_u + nbCoeffs_u -1));
824  currentline->GetPointIds()->SetId(1, ((nbCoeffs_w -1 ) *nbCoeffs_u *nbCoeffs_v + (j+1) * nbCoeffs_u + nbCoeffs_u -1));
825 
826  d->CpCellAray->InsertNextCell(currentline);
827  }
828 
829  // had of the boundary lines of the other side
830  for(int i = 0; i < nbCoeffs_u - 1; i++)
831  {
832  for(int k = 0; k < nbCoeffs_w - 1; k++)
833  {
834  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
835  currentline->GetPointIds()->SetId(0, ( k *nbCoeffs_u *nbCoeffs_v + (nbCoeffs_v -1) * nbCoeffs_u + i));
836  currentline->GetPointIds()->SetId(1, (k *nbCoeffs_u *nbCoeffs_v + (nbCoeffs_v -1) * nbCoeffs_u + i+1));
837 
838  vtkSmartPointer<vtkLine> currentline2 = vtkSmartPointer<vtkLine>::New();
839  currentline2->GetPointIds()->SetId(0, (k *nbCoeffs_u *nbCoeffs_v + (nbCoeffs_v -1) * nbCoeffs_u + i));
840  currentline2->GetPointIds()->SetId(1, ((k+1) *nbCoeffs_u *nbCoeffs_v + (nbCoeffs_v -1) * nbCoeffs_u + i));
841 
842  d->CpCellAray->InsertNextCell(currentline);
843  d->CpCellAray->InsertNextCell(currentline2);
844  }
845 
846  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
847  currentline->GetPointIds()->SetId(0, ((nbCoeffs_w -1 ) *nbCoeffs_u *nbCoeffs_v + (nbCoeffs_v -1) * nbCoeffs_u + i));
848  currentline->GetPointIds()->SetId(1, ((nbCoeffs_w -1 ) *nbCoeffs_u *nbCoeffs_v + (nbCoeffs_v -1) * nbCoeffs_u + i+1));
849 
850  d->CpCellAray->InsertNextCell(currentline);
851  }
852 
853  } else{
854  for(int i = 0 ; i < d->numCps; i++){
855  QList<int> connection = splineVolume->getControlPointConnection(i);
856  foreach(int value, connection){
857  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
858  currentline->GetPointIds()->SetId(0, i);
859  currentline->GetPointIds()->SetId(1, value);
860  d->CpCellAray->InsertNextCell(currentline);
861  }
862  }
863  }
864 
865  // association of the glyph and the control Points
866  d->CpUnstructuredGrid->SetPoints(d->CpPoints);
867  d->CpUnstructuredGrid->SetCells(VTK_LINE, d->CpCellAray); //A REVOIR
868  }
869 }
870 
872 {
873  for (int i=0; i< d->numCps; i++)
874  {
875  d->CpActor[i]->SetProperty(d->CpHandleProperty);
876  }
877 }
878 
880 {
881  return d->CpPolyDataActor;
882 }
883 
884 vtkActorCollection *axlControlPointsWidget::ptsActors(void)
885 {
886  return d->CpActorCollection;
887 }
888 
890 {
891 
892  if ( ! this->Interactor )
893  {
894  vtkErrorMacro(<<"The interactor must be set prior to enabling/disabling widget");
895  return;
896  }
897 
898  if ( enabling ) //------------------------------------------------------------
899  {
900  vtkDebugMacro(<<"Enabling widget");
901 
902  if ( this->Enabled ) //already enabled, just return
903  {
904  return;
905  }
906 
907  if ( ! this->CurrentRenderer )
908  {
909  this->SetCurrentRenderer(this->Interactor->FindPokedRenderer(
910  this->Interactor->GetLastEventPosition()[0],
911  this->Interactor->GetLastEventPosition()[1]));
912  if (this->CurrentRenderer == NULL)
913  {
914  return;
915  }
916  }
917 
918  this->Enabled = 1;
919 
920  // listen to the following events
921  vtkRenderWindowInteractor *i = this->Interactor;
922  i->AddObserver(vtkCommand::MouseMoveEvent, this->EventCallbackCommand,
923  this->Priority);
924  i->AddObserver(vtkCommand::LeftButtonPressEvent,
925  this->EventCallbackCommand, this->Priority);
926  i->AddObserver(vtkCommand::LeftButtonReleaseEvent,
927  this->EventCallbackCommand, this->Priority);
928 
929  for (int i=0; i< d->numCps; i++)
930  {
931  d->CpActor[i]->SetVisibility(true);
932  }
933 
934  d->CpPolyDataActor->SetVisibility(true);
935  d->CpCurrentActorIndex =-1;
936  d->XStartPosition =-1;
937  d->YStartPosition =-1;
938 
939 
940  this->InvokeEvent(vtkCommand::EnableEvent,NULL);
941  }
942 
943  else //disabling-------------------------------------------------------------
944  {
945  vtkDebugMacro(<<"Disabling widget");
946 
947  if ( ! this->Enabled ) //already disabled, just return
948  {
949  return;
950  }
951 
952  this->Enabled = 0;
953 
954  // don't listen for events any more
955  this->Interactor->RemoveObserver(this->EventCallbackCommand);
956 
957  // remove CpActor
958  for (int i=0; i<d->numCps; i++)
959  {
960  d->CpActor[i]->SetVisibility(false);
961  }
962 
963  d->CpPolyDataActor->SetVisibility(false);
964 
965  d->CpCurrentActorIndex =-1;
966  d->XStartPosition =-1;
967  d->YStartPosition =-1;
968 
969  this->InvokeEvent(vtkCommand::DisableEvent,NULL);
970  this->SetCurrentRenderer(NULL);
971  }
972 
973  this->Interactor->Render();
974 }
975 
977 
978  double bounds[6];this->Prop3D->GetBounds(bounds);
979  double side = qAbs(bounds[1]-bounds[0]);
980  side += qAbs(bounds[3]-bounds[2]);
981  side += qAbs(bounds[5]-bounds[4]);
982 
983  side/=600;
984 
985  if(dynamic_cast<axlAbstractCurveBSpline *>(d->CpSpline))
986  side = ((cpSize*d->radiusScaleCps)>side ? (cpSize*d->radiusScaleCps):side);
987  else
988  side = (cpSize>side ? cpSize:side);
989 
990  for(int i = 0 ; i < d->numCps; i++){
991  d->CpSphere[i]->SetRadius(side);
992 
993  d->CpSphere[i]->Modified();
994  d->CpSphere[i]->Update();
995  }
996 }
997 
999 {
1000  // if(d->CpRubberBanPick->getCurrentMode()==0)
1001  // {//We select point with the cursor
1002  // first unhighlight anything picked
1003  this->resetProperty();
1004 
1005  vtkActor *currentActor = static_cast<vtkActor *>(prop);
1006 
1007  if ( currentActor )
1008  {
1009 
1010 
1011  for (int i=0; i<d->numCps; i++)
1012  {
1013  if ( currentActor == d->CpActor[i] )
1014  {
1015  currentActor->SetProperty(d->CpSelectedHandleProperty);
1016  d->CpCursorPicker->GetPickPosition(this->LastPickPosition);
1017  d->CpRectanglePicker->GetPickPosition(this->LastPickPosition);
1018  return i;
1019  }
1020  }
1021  }
1022 
1023  // }
1024  // else// we select points with rectangle
1025  // {
1026  // d->CpCurrentActor = static_cast<vtkActor *>(prop);
1027  // if(d->CpCurrentActor->GetProperty()!=d->CpSelectedHandleProperty)
1028  // {
1029  // this->resetProperty();
1030  // this->State = axlControlPointsWidget::Outside;
1031  // }
1032  // }
1033 
1034 
1035  return -1;
1036 }
1037 
1038 
1039 
1040 void axlControlPointsWidget::ProcessEvents(vtkObject* vtkNotUsed(object), unsigned long event, void *clientdata, void *vtkNotUsed(calldata))
1041 {
1042  axlControlPointsWidget* self = reinterpret_cast<axlControlPointsWidget *>( clientdata );
1043 
1044  //okay, let's do the right thing
1045  switch(event)
1046  {
1047  case vtkCommand::LeftButtonPressEvent:
1048  self->OnLeftButtonDown();
1049  break;
1050  case vtkCommand::LeftButtonReleaseEvent:
1051  self->OnLeftButtonUp();
1052  break;
1053  case vtkCommand::MouseMoveEvent:
1054  self->OnMouseMove();
1055  break;
1056  }
1057 }
1058 
1060 {
1061  int i;
1062  double bounds[6], center[3];
1063 
1064  this->AdjustBounds(bds, bounds, center);
1065 
1066  for (i=0; i<6; i++)
1067  {
1068  this->InitialBounds[i] = bounds[i];
1069  }
1070 
1071  this->InitialLength = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
1072  (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
1073  (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
1074 }
1075 
1076 void axlControlPointsWidget::PrintSelf(ostream& os, vtkIndent indent)
1077 {
1078  this->Superclass::PrintSelf(os,indent);
1079 }
1080 
1081 #define VTK_AVERAGE(a,b,c) \
1082  c[0] = (a[0] + b[0])/2.0; \
1083  c[1] = (a[1] + b[1])/2.0; \
1084  c[2] = (a[2] + b[2])/2.0;
1085 
1086 #undef VTK_AVERAGE
1087 
1089 {
1090  // d->interaction = true;
1091  int X = this->Interactor->GetEventPosition()[0];
1092  int Y = this->Interactor->GetEventPosition()[1];
1093 
1094  // Okay, we can process this. Try to pick handles first;
1095  // if no handles picked, then pick the bounding box.
1096  if (!this->CurrentRenderer || !this->CurrentRenderer->IsInViewport(X, Y))
1097  {
1099  return;
1100  }
1101 
1102  d->XStartPosition = X;
1103  d->YStartPosition = Y;
1104 
1105  vtkAssemblyPath *path = NULL;
1106  d->CpCursorPicker->Pick(X, Y, 0.0, this->CurrentRenderer);
1107 
1108  path = d->CpCursorPicker->GetPath();
1109 
1110  if ( path != NULL)
1111  {
1113  d->CpCurrentActorIndex=this->HighlightHandle(path->GetLastNode()->GetViewProp());
1114  d->CpCurrentAssemblyNode = path->GetLastNode();
1115  d->CpCursorPicker->GetPickPosition(this->LastPickPosition);
1116 
1117  if( d->CpCurrentActorIndex == -1)
1118  {
1119  this->resetProperty();
1121  return;
1122  }
1123 
1124 
1125  }
1126  else
1127  {
1128  this->resetProperty();
1130  return;
1131  }
1132  this->EventCallbackCommand->SetAbortFlag(1);
1133  this->StartInteraction();
1134  //this->InvokeEvent(vtkCommand::StartInteractionEvent, NULL);
1135  //this->Interactor->Render();
1136 
1137 
1138  // G+Smo : giving back the control point index
1139  //d->CpSpline->setParameter(d->CpCurrentActorIndex);
1140  if (axlAbstractCurveBSpline *splineCurve =dynamic_cast<axlAbstractCurveBSpline *>(d->CpSpline)) {
1141  splineCurve->selectIndex(d->CpCurrentActorIndex);
1142  }
1143  else if (axlAbstractSurfaceBSpline *splineSurface =dynamic_cast<axlAbstractSurfaceBSpline *>(d->CpSpline)) {
1144  splineSurface->selectIndex(d->CpCurrentActorIndex);
1145  }
1146  else if (axlAbstractVolumeBSpline *splineVolume =dynamic_cast<axlAbstractVolumeBSpline *>(d->CpSpline))
1147  {
1148  splineVolume->selectIndex(d->CpCurrentActorIndex);
1149  }
1150  else if (axlShapeBSpline *splineSurface = dynamic_cast<axlShapeBSpline *>(d->CpSpline)) {
1151  splineSurface->selectIndex(d->CpCurrentActorIndex);
1152  }
1153 }
1154 
1156 {
1157  // d->interaction = true;
1158  int X = this->Interactor->GetEventPosition()[0];
1159  int Y = this->Interactor->GetEventPosition()[1];
1160  // Okay, we can process this. Try to pick handles first;
1161  // if no handles picked, then pick the bounding box.
1162  if (!this->CurrentRenderer || !this->CurrentRenderer->IsInViewport(X, Y))
1163  {
1165  return;
1166  }
1167 
1168  /*if(d->CpRubberBanPick->getCurrentMode()==1)// mode rectangle selection activated
1169  {
1170  vtkProp3DCollection *listProp;
1171  d->CpRectanglePicker->AreaPick(d->CpRubberBanPick->getStartPositionX(),d->CpRubberBanPick->getStartPositionY(),d->CpRubberBanPick->getEndPositionX(),d->CpRubberBanPick->getEndPositionY(),this->CurrentRenderer);
1172  listProp = d->CpRectanglePicker->GetProp3Ds();
1173  if ( listProp != NULL )
1174  {
1175  vtkCollectionIterator *listPropIterator =listProp->NewIterator();
1176  listPropIterator->InitTraversal();
1177  while(!listPropIterator->IsDoneWithTraversal())
1178  {
1179  static_cast<vtkActor *>(listPropIterator->GetCurrentObject())->SetProperty(d->CpSelectedHandleProperty);
1180  listPropIterator->GoToNextItem();
1181  }
1182  }
1183 
1184  }*/
1185 
1187  {
1188  return;
1189  }
1190 
1191 
1193 
1194  this->EventCallbackCommand->SetAbortFlag(0);
1195  this->EndInteraction();
1196  this->InvokeEvent(vtkCommand::EndInteractionEvent, NULL);
1197  //this->Interactor->Render();
1198 }
1199 
1201 {
1202  // See whether we're active
1203  if ( this->State == axlControlPointsWidget::Outside ||
1205  {
1206  return;
1207  }
1208 
1209  int X = this->Interactor->GetEventPosition()[0];
1210  int Y = this->Interactor->GetEventPosition()[1];
1211 
1212  // Do different things depending on state
1213  // Calculations everybody does
1214  double focalPoint[4], pickPoint[4], prevPickPoint[4], motionVector[4];
1215  double z;
1216 
1217  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
1218  if ( !camera )
1219  {
1220  return;
1221  }
1222 
1223  // Compute the two points defining the motion vector
1224  this->ComputeWorldToDisplay(this->LastPickPosition[0], this->LastPickPosition[1], this->LastPickPosition[2], focalPoint);
1225  z = focalPoint[2];
1226  this->ComputeDisplayToWorld(double(this->Interactor->GetLastEventPosition()[0]),double(this->Interactor->GetLastEventPosition()[1]),
1227  z, prevPickPoint);
1228  this->ComputeDisplayToWorld(double(X), double(Y), z, pickPoint);
1229  for(int i=0;i<4;i++)
1230  {
1231  motionVector[i]=pickPoint[i]-prevPickPoint[i];
1232  }
1233 
1234  vtkMatrix4x4 *motion = vtkMatrix4x4::New();
1235 
1236  if(d->CpCurrentAssemblyNode)
1237  motion->DeepCopy(d->CpCurrentAssemblyNode->GetMatrix());
1238  motion->Invert();
1239 
1240 
1241  if ( this->State == axlControlPointsWidget::Moving )
1242  { // Okay to process
1243  if(axlAbstractCurveBSpline *splineCurve =dynamic_cast<axlAbstractCurveBSpline *>(d->CpSpline))
1244  {
1245  double *newMotion = motion->MultiplyDoublePoint(motionVector);
1246  double newPosition[4];
1247  for(int j = 0; j < 4; j++)
1248  {
1249  newPosition[j]=d->CpPoints->GetPoint(d->CpCurrentActorIndex)[j]+newMotion[j];
1250  }
1251  d->CpPoints->SetPoint(d->CpCurrentActorIndex, newPosition[0], newPosition[1], newPosition[2]);
1252  d->CpPoints->Modified();
1253  d->CpSphere[d->CpCurrentActorIndex]->SetCenter(d->CpPoints->GetPoint(d->CpCurrentActorIndex));
1254  d->CpSphere[d->CpCurrentActorIndex]->Update();
1255  d->CpSphere[d->CpCurrentActorIndex]->Modified();
1256  //modification on the spline
1257  splineCurve->setCoef(d->CpCurrentActorIndex + 1,newPosition);
1258 
1259  }
1260 
1261  if(axlAbstractSurfaceBSpline *splineSurface =dynamic_cast<axlAbstractSurfaceBSpline *>(d->CpSpline))
1262  {
1263 
1264  double *newMotion = motion->MultiplyDoublePoint(motionVector);
1265  double newPosition[4];
1266  for(int j = 0 ;j < 4; j++)
1267  {
1268  newPosition[j]=d->CpPoints->GetPoint(d->CpCurrentActorIndex)[j]+newMotion[j];
1269  }
1270  d->CpPoints->SetPoint(d->CpCurrentActorIndex, newPosition[0], newPosition[1], newPosition[2]);
1271  d->CpPoints->Modified();
1272  d->CpSphere[d->CpCurrentActorIndex]->SetCenter(d->CpPoints->GetPoint(d->CpCurrentActorIndex));
1273  d->CpSphere[d->CpCurrentActorIndex]->Update();
1274  d->CpSphere[d->CpCurrentActorIndex]->Modified();
1275  //modification on the spline
1276  splineSurface->setCoef(d->CpCurrentActorIndex + 1,newPosition);
1277  }
1278 
1279  if(axlShapeBSpline *splineShape = dynamic_cast<axlShapeBSpline *>(d->CpSpline))
1280  {
1281 
1282  double *newMotion = motion->MultiplyDoublePoint(motionVector);
1283  double newPosition[4];
1284  for(int j = 0 ;j < 4; j++)
1285  {
1286  newPosition[j]=d->CpPoints->GetPoint(d->CpCurrentActorIndex)[j]+newMotion[j];
1287  }
1288  d->CpPoints->SetPoint(d->CpCurrentActorIndex, newPosition[0], newPosition[1], newPosition[2]);
1289  d->CpPoints->Modified();
1290  d->CpSphere[d->CpCurrentActorIndex]->SetCenter(d->CpPoints->GetPoint(d->CpCurrentActorIndex));
1291  d->CpSphere[d->CpCurrentActorIndex]->Update();
1292  d->CpSphere[d->CpCurrentActorIndex]->Modified();
1293  //modification on the spline
1294  splineShape->setCoef(d->CpCurrentActorIndex + 1,newPosition);
1295  }
1296 
1297  if(axlAbstractVolumeBSpline *splineVolume =dynamic_cast<axlAbstractVolumeBSpline *>(d->CpSpline))
1298  {
1299 
1300  double *newMotion = motion->MultiplyDoublePoint(motionVector);
1301  double newPosition[4];
1302  for(int j = 0 ;j < 4; j++)
1303  {
1304  newPosition[j]=d->CpPoints->GetPoint(d->CpCurrentActorIndex)[j]+newMotion[j];
1305  }
1306  d->CpPoints->SetPoint(d->CpCurrentActorIndex, newPosition[0], newPosition[1], newPosition[2]);
1307  d->CpPoints->Modified();
1308  d->CpSphere[d->CpCurrentActorIndex]->SetCenter(d->CpPoints->GetPoint(d->CpCurrentActorIndex));
1309  d->CpSphere[d->CpCurrentActorIndex]->Update();
1310  d->CpSphere[d->CpCurrentActorIndex]->Modified();
1311  //modification on the spline
1312  splineVolume->setCoef(d->CpCurrentActorIndex + 1,newPosition);
1313  }
1314  }
1315  else
1316  {
1317  return; //avoid the extra render
1318  }
1319 
1320  motion->Delete();
1321 
1322  this->EventCallbackCommand->SetAbortFlag(1);
1323  this->InvokeEvent(vtkCommand::InteractionEvent,NULL);
1324  this->Interactor->Render();
1325 }
1326 
1328 {
1329  // Handle properties
1330  d->CpHandleProperty = vtkProperty::New();
1331  d->CpHandleProperty->SetColor(1,1,1);
1332 
1333  d->CpSelectedHandleProperty = vtkProperty::New();
1334  d->CpSelectedHandleProperty->SetColor(1,0,0);
1335 }
void PlaceWidget(void) override
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
vtkActorCollection * ptsActors(void)
static void ProcessEvents(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
vtkStandardNewMacro(axlControlPointsWidget)
double y
Definition: axlPoint.h:37
void PrintSelf(ostream &os, vtkIndent indent)
double z
Definition: axlPoint.h:38
Class axlShapeBSpline defines a set of boundary curves (Edges) and bspline surface patches (Face)...
int HighlightHandle(vtkProp *prop)
void SetControlPointRadius(double cpSize)
double x
Definition: axlPoint.h:37
void setSpline(dtkAbstractData *spline)