Developer documentation | Axl-2.5.1

axlActorSurfaceBSpline.cpp
Go to the documentation of this file.
1 /* axlActorSurfaceBSpline.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Fri Dec 17 11:06:08 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Mon Dec 17 15:04:10 2012 (+0100)
8  * By: Julien Wintz
9  * Update #: 78
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlActorSurfaceBSpline.h"
21 #include "axlControlPointsWidget.h"
22 
25 
26 #include <dtkMathSupport/dtkVector3D.h>
27 
28 #include <vtkActor.h>
29 #include <vtkActorCollection.h>
30 #include <vtkCellArray.h>
31 #include <vtkCellData.h>
32 #include <vtkCommand.h>
33 #include <vtkDoubleArray.h>
34 #include <vtkLookupTable.h>
35 #include <vtkObjectFactory.h>
36 //#include <vtkPainterPolyDataMapper.h>
37 #include <vtkPoints.h>
38 #include <vtkPointData.h>
39 #include <vtkPolyData.h>
40 #include <vtkPolyVertex.h>
41 #include <vtkPolygon.h>
42 #include <vtkPolyDataMapper.h>
43 #include <vtkPolyDataNormals.h>
44 #include <vtkProperty.h>
45 #include <vtkProp.h>
46 #include <vtkQuad.h>
47 #include <vtkTexture.h>
48 //#include <vtkTriangle.h>
49 #include <vtkTriangleStrip.h>
50 #include <vtkTimerLog.h>
51 #include <vtkSmartPointer.h>
52 #include <vtkStripper.h>
53 #include <vtkPointData.h>
54 #include <vtkTriangleFilter.h>
55 #include <vtkPNGReader.h>
56 #include <vtkFloatArray.h>
57 //#include <vtkOpenGLHardwareSupport.h>
58 #include <vtkOpenGLRenderWindow.h>
59 //#include <vtkPainterPolyDataMapper.h>
60 #include <vtkProperty.h>
61 
62 #include <vtkFeatureEdges.h>
63 #include <vtkExtractEdges.h>
64 #include <vtkRenderWindowInteractor.h>
65 #include <vtkRendererCollection.h>
66 
67 
68 //for meshing and create poly data structure.
70 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
71 #include <axlCore/axlMesh.h>
72 
73 #include <vtkLine.h>
74 #include <vtkTriangle.h>
75 
76 // /////////////////////////////////////////////////////////////////
77 // axlActorSurfaceBSplinePrivate
78 // /////////////////////////////////////////////////////////////////
79 
80 class axlActorSurfaceBSplinePrivate
81 {
82 public:
83  axlAbstractSurfaceBSpline *splineSurface;
84  vtkSmartPointer<vtkActor> edgeActor;
85 
86  vtkSmartPointer<vtkCellArray> lines;
87 };
88 
89 #if (VTK_MAJOR_VERSION <= 5)
90 vtkCxxRevisionMacro(axlActorSurfaceBSpline, "$Revision: 0.0.1 $");
91 #endif
92 
94 
95 dtkAbstractData *axlActorSurfaceBSpline::data(void)
96 {
97  return d->splineSurface;
98 }
99 
100 void axlActorSurfaceBSpline::setData(dtkAbstractData *spline_Surface1)
101 {
102  axlAbstractSurfaceBSpline *spline_Surface = dynamic_cast<axlAbstractSurfaceBSpline *>(spline_Surface1);
103  // we compute here points, triangles, and normals
104  d->splineSurface = spline_Surface;
105 
106  this->setPoints(vtkSmartPointer<vtkPoints>::New());
107 
108  this->setNormals(vtkSmartPointer<vtkDoubleArray>::New());
109 
110  // qDebug()<<"axlActorSurfaceBSpline::setSurface 2"<<vtkTimerLog::GetCPUTime()<<vtkTimerLog::GetCPUTime()-currentTime;
111 
112  this->setActor(vtkSmartPointer<vtkActor>::New());
113  this->setCellArray(vtkSmartPointer<vtkCellArray>::New());
114  this->setPolyData(vtkSmartPointer<vtkPolyData>::New());
115  this->setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
116 
117  //this->pointsUpdate();
118  this->normalsUpdate();
119  this->polyDataUpdate();
120 
121  this->getPolyData()->SetPoints(this->getPoints());
122  //this->getPolyData()->SetLines(d->lines);
123  this->getPolyData()->SetPolys(this->getCellArray());
124  this->getPolyData()->GetPointData()->SetNormals(this->getNormals());
125 
126  //vtkSmartPointer<vtkPolyDataNormals> polyDataNormals = vtkSmartPointer<vtkPolyDataNormals>::New();
127  //polyDataNormals->AutoOrientNormalsOn();
128  //polyDataNormals->FlipNormalsOn();
129  //polyDataNormals->SetInput(this->getPolyData());
130 #if (VTK_MAJOR_VERSION <= 5)
131  this->getMapper()->SetInput(this->getPolyData());
132 #else
133  this->getMapper()->SetInputData(this->getPolyData());
134 #endif
135  this->getActor()->SetMapper(this->getMapper());
136 
137  this->getMapper()->ScalarVisibilityOff();
138 
139  // add sphere param
140  // this->initCurrentPoint();
141  //vtkSmartPointer<vtkProp3D> prop3d = this->getActor();
142  this->AddPart(this->getActor());
143 
144  // add the observer
145  if(!this->getObserver())
146  {
147  this->NewObserver();
148  this->setObserverData(d->splineSurface);
149  }
150 
151  QColor color = d->splineSurface->color();
152  this->getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
153 
154  QString shader = d->splineSurface->shader();
155  if(!shader.isEmpty())
156  this->setShader(shader);
157 
158 
160 
161  // char* fname1 =
162  // vtkTestUtilities::ExpandDataFileName(1, new char*(), "Data/ground.png");
163 
164  // vtkPNGReader * imageReaderRed = vtkPNGReader::New();
165  // imageReaderRed->SetFileName(fname1);
166 
167  // imageReaderRed->Update();
168 
169  // vtkFloatArray *TCoords = vtkFloatArray::New();
170  // TCoords->SetNumberOfComponents(2);
171  // TCoords->SetNumberOfTuples(this->getPoints()->GetNumberOfPoints());
172 
173  // for(int j = 0; j < n_v; j++)
174  // {
175  // for(int i = 0; i < n_u; i++)
176  // {
177  // if( i % 2 == 0 )
178  // if( j % 2 == 0 )
179  // {
180 
181  // TCoords->SetTuple2(j* n_u + i, 1.0, 0.0);
182  // }
183  // else
184  // {
185 
186  // TCoords->SetTuple2(j* n_u + i,1.0, 1.0);
187  // }
188  // else
189  // if( j % 2 == 0 )
190  // {
191 
192  // TCoords->SetTuple2(j* n_u + i,0.0, 0.0);
193  // }
194  // else
195  // {
196 
197  // TCoords->SetTuple2(j* n_u + i, 0.0, 1.0);
198  // }
199 
200  // }
201  // }
202 
203  // TCoords->SetName("MultTCoords");
204 
205  // this->getPolyData()->GetPointData()->SetTCoords(TCoords);
206 
207  // vtkTexture * textureRed = vtkTexture::New();
208  // textureRed->SetInputConnection(imageReaderRed->GetOutputPort());
209  // textureRed->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_REPLACE);
210  // textureRed->SetRepeat(true);
211 
212  // this->getMapper()->SetInput(this->getPolyData());
213  // this->getActor()->SetMapper(this->getMapper());
214  // this->getActor()->SetVisibility(true);
215 
216 
217  // // no multitexturing just show the green texture.
218  // this->getActor()->SetTexture(textureRed);
219 
220  //if(d->splineSurface->identifier() == "axlSurfaceBSpline"){
221  connect(d->splineSurface,SIGNAL(edgeSelected(int,int,int)),this,SLOT(onSelectBoundaryEdge(int,int,int)));
222 
223  //}
224 
225  // For updating the geometry (ie. the mesh representation of the spline)
226  connect(d->splineSurface,SIGNAL(modifiedGeometry()), this, SLOT(onUpdateGeometry()));
227  connect(d->splineSurface,SIGNAL(modifiedProperty()), this, SLOT(onUpdateProperty()));
228  // For redrawing the control point widget
229  connect(d->splineSurface,SIGNAL(modifiedStructure()), this, SLOT(onUpdateStructure()));
230 
231 }
232 
233 
235 {
236  vtkSmartPointer<vtkDoubleArray> scalarArray = vtkSmartPointer<vtkDoubleArray>::New();
237  scalarArray->SetName("mapperCollorArrayDefaultField");
238  scalarArray->SetNumberOfComponents(1);
239 
240  if(!d->splineSurface->hasCells()){
241 
242  double start_u = d->splineSurface->startParam_u();
243  double start_v = d->splineSurface->startParam_v();
244  double end_u = d->splineSurface->endParam_u();
245  double end_v = d->splineSurface->endParam_v();
246  double paramCourant_u = start_u;
247  double paramCourant_v = start_v;
248 
249  int n_u = d->splineSurface->numSamples_u();// need to be superior than 1
250  int n_v = d->splineSurface->numSamples_v();
251 
252  scalarArray->SetNumberOfTuples(n_u * n_v);
253 
254  double interval_u = (double)(end_u - start_u) / (n_u - 1);
255  double interval_v = (double)(end_v - start_v) / (n_v - 1);
256 
257  for(int i = 0; i < n_v - 1 ; i++)
258  {
259  for(int j = 0; j < n_u - 1 ; j++)
260  {
261  scalarArray->SetTuple1(i * n_u + j, d->splineSurface->scalarValue(paramCourant_u, paramCourant_v));
262  paramCourant_u += interval_u;
263  }
264 
265  scalarArray->SetTuple1(i * n_u + (n_u - 1), d->splineSurface->scalarValue(end_u, paramCourant_v));
266  paramCourant_u = start_u;
267  paramCourant_v += interval_v;
268  }
269  for(int i = 0; i < n_u - 1; i++)
270  {
271  scalarArray->SetTuple1(n_u * (n_v - 1) + i, d->splineSurface->scalarValue(paramCourant_u, end_v));
272  paramCourant_u += interval_u;
273  }
274  scalarArray->SetTuple1(n_u * n_v - 1, d->splineSurface->scalarValue(end_u, end_v));
275 
276 
277  vtkSmartPointer<vtkPolyData> data = this->getPolyData();
278  data->GetPointData()->AddArray(scalarArray);
279  data->GetPointData()->SetActiveScalars("mapperCollorArrayDefaultField");
280 
281  vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
282  lookupTable->SetRange(-1.0, 1.0);
283  lookupTable->SetNumberOfTableValues(d->splineSurface->stripes());
284  lookupTable->Build();
285  for(int i= 0; i < d->splineSurface->stripes(); i+=2)
286  {
287  lookupTable->SetTableValue(i , 1.0, 1.0, 1.0);
288  lookupTable->SetTableValue(i+1, 0.0, 0.0, 0.0);
289  }
290  // test to get light direction .... TO DELETE
291 
292  vtkSmartPointer<vtkDoubleArray> lightArray = vtkSmartPointer<vtkDoubleArray>::New();
293  lightArray->SetName("mapperLightDirection");
294  lightArray->SetNumberOfComponents(3);
295 
296  paramCourant_u = start_u;
297  paramCourant_v = start_v;
298 
299  lightArray->SetNumberOfTuples(n_u * n_v);
300  double *currentLight = new double[3];
301  currentLight[0] = 1.0;
302  currentLight[1] = 0.6;
303  currentLight[2] = 0.2;
304  for(int j = 0; j < n_v - 1; j++)
305  {
306  for(int i = 0; i < n_u - 1; i++)
307  {
308  lightArray->SetTuple(j * n_u + i, currentLight);
309  }
310 
311  lightArray->SetTuple(j * n_u + n_u - 1, currentLight);
312  paramCourant_u = start_u;
313  paramCourant_v += interval_v;
314  }
315 
316  for(int i = 0; i < n_u - 1; i++)
317  {
318  lightArray->SetTuple((n_v - 1) * n_u + i, currentLight);
319  paramCourant_u += interval_u;
320  }
321  lightArray->SetTuple(n_v * n_u - 1, currentLight);
322 
323  data = this->getPolyData();
324  data->GetPointData()->AddArray(lightArray);
325 
326 
327  //add vertex attrib array
328  vtkSmartPointer<vtkPolyDataMapper> mapper = this->getMapper();
329  vtkSmartPointer<vtkPolyData> polyData = this->getPolyData();
330  mapper->MapDataArrayToVertexAttribute("scalarsattrib", data->GetPointData()->GetArrayName(2), vtkDataObject::FIELD_ASSOCIATION_POINTS, -1);
331  mapper->SetLookupTable(lookupTable);
332  mapper->SetInterpolateScalarsBeforeMapping(true);
333  mapper->UseLookupTableScalarRangeOn();
334 
335 
336  }else {
337  int addIndex = 0;
338  for(int indice=0; indice < d->splineSurface->countCells();indice++){
339 
340  double start_u = d->splineSurface->startParam_u(indice);
341  double start_v = d->splineSurface->startParam_v(indice);
342  double end_u = d->splineSurface->endParam_u(indice);
343  double end_v = d->splineSurface->endParam_v(indice);
344  double paramCourant_u = start_u;
345  double paramCourant_v = start_v;
346 
347  int n_u = d->splineSurface->numSamples_u(indice);// need to be superior than 1
348  int n_v = d->splineSurface->numSamples_v(indice);
349 
350  scalarArray->SetNumberOfTuples(n_u * n_v);
351 
352  double interval_u = (double)(end_u - start_u) / (n_u - 1);
353  double interval_v = (double)(end_v - start_v) / (n_v - 1);
354 
355  for(int i = 0; i < n_v - 1 ; i++)
356  {
357  for(int j = 0; j < n_u - 1 ; j++)
358  {
359  scalarArray->SetTuple1(i * n_u + j+addIndex, d->splineSurface->scalarValue(paramCourant_u, paramCourant_v));
360  paramCourant_u += interval_u;
361  }
362 
363  scalarArray->SetTuple1(i * n_u + (n_u - 1)+addIndex, d->splineSurface->scalarValue(end_u, paramCourant_v));
364  paramCourant_u = start_u;
365  paramCourant_v += interval_v;
366  }
367  for(int i = 0; i < n_u - 1; i++)
368  {
369  scalarArray->SetTuple1(n_u * (n_v - 1) + i+addIndex, d->splineSurface->scalarValue(paramCourant_u, end_v));
370  paramCourant_u += interval_u;
371  }
372  scalarArray->SetTuple1(n_u * n_v - 1+addIndex, d->splineSurface->scalarValue(end_u, end_v));
373 
374 
375  vtkSmartPointer<vtkPolyData> data = this->getPolyData();
376  data->GetPointData()->AddArray(scalarArray);
377  data->GetPointData()->SetActiveScalars("mapperCollorArrayDefaultField");
378 
379  vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
380  lookupTable->SetRange(-1.0, 1.0);
381  lookupTable->SetNumberOfTableValues(d->splineSurface->stripes());
382  lookupTable->Build();
383  for(int i= 0; i < d->splineSurface->stripes(); i+=2)
384  {
385  lookupTable->SetTableValue(i , 1.0, 1.0, 1.0);
386  lookupTable->SetTableValue(i+1, 0.0, 0.0, 0.0);
387  }
388  // test to get light direction .... TO DELETE
389 
390  vtkSmartPointer<vtkDoubleArray> lightArray = vtkSmartPointer<vtkDoubleArray>::New();
391  lightArray->SetName("mapperLightDirection");
392  lightArray->SetNumberOfComponents(3);
393 
394  paramCourant_u = start_u;
395  paramCourant_v = start_v;
396 
397  lightArray->SetNumberOfTuples(n_u * n_v);
398  double *currentLight = new double[3];
399  currentLight[0] = 1.0;
400  currentLight[1] = 0.6;
401  currentLight[2] = 0.2;
402  for(int j = 0; j < n_v - 1; j++)
403  {
404  for(int i = 0; i < n_u - 1; i++)
405  {
406  lightArray->SetTuple(j * n_u + i+addIndex, currentLight);
407  }
408 
409  lightArray->SetTuple(j * n_u + n_u - 1+addIndex, currentLight);
410  paramCourant_u = start_u;
411  paramCourant_v += interval_v;
412  }
413 
414  for(int i = 0; i < n_u - 1; i++)
415  {
416  lightArray->SetTuple((n_v - 1) * n_u + i+addIndex, currentLight);
417  paramCourant_u += interval_u;
418  }
419  lightArray->SetTuple(n_v * n_u - 1+addIndex, currentLight);
420 
421  data = this->getPolyData();
422  data->GetPointData()->AddArray(lightArray);
423 
424 
425  //add vertex attrib array
426  vtkSmartPointer<vtkPolyDataMapper> mapper = this->getMapper();
427  vtkSmartPointer<vtkPolyData> polyData = this->getPolyData();
428  mapper->MapDataArrayToVertexAttribute("scalarsattrib", data->GetPointData()->GetArrayName(2), vtkDataObject::FIELD_ASSOCIATION_POINTS, -1);
429  mapper->SetLookupTable(lookupTable);
430  mapper->SetInterpolateScalarsBeforeMapping(true);
431  mapper->UseLookupTableScalarRangeOn();
432  addIndex = addIndex + n_u*n_v;
433 
434  }
435 
436  }
437 
438  this->Modified();
439 }
440 
441 
443 {
444 
445 
446  if(d->splineSurface)
447  {
448 
449  this->getMapper()->RemoveAllInputs();
450  this->getPolyData()->Initialize();
451 
452  // delete current vtkPoint and vtkCellArray
453  this->getPoints()->Reset();
454  this->getCellArray()->Reset();
455 
456  this->getPoints()->Squeeze();
457  this->getCellArray()->Squeeze();
458 
459  this->getNormals()->Initialize();
460  //this->getPolyData()->GetPointData()->RemoveArray("mapperCollorArrayIsophote");//back to solid color
461 
462  //this->pointsUpdate();
463  this->normalsUpdate();
464 
465  this->getPolyData()->GetPointData()->SetNormals(this->getNormals());
466 
467  this->polyDataUpdate();
468 
469 
470  this->getPolyData()->SetPoints(this->getPoints());
471  this->getPolyData()->SetPolys(this->getCellArray());
472 
473 #if (VTK_MAJOR_VERSION <= 5)
474  this->getMapper()->SetInput(this->getPolyData());
475 #else
476  this->getMapper()->SetInputData(this->getPolyData());
477 #endif
478 
479  }
480 
481  if(d->splineSurface->fields().count() != 0){
482  d->splineSurface->touchField();
483  d->splineSurface->touchGeometry();
484  }
485 
486 
487 
488 }
489 
491  // we consider here that all memory vtk pipeline from points to polydata are free but not deleted...
492  if(!d->splineSurface->hasCells()){
493  double start_u = d->splineSurface->startParam_u();
494  double start_v = d->splineSurface->startParam_v();
495  double end_u = d->splineSurface->endParam_u();
496  double end_v = d->splineSurface->endParam_v();
497  double paramCourant_u = start_u;
498  double paramCourant_v = start_v;
499 
500 
501  int n_u = d->splineSurface->numSamples_u();// need to be superior than 1
502  int n_v = d->splineSurface->numSamples_v();
503 
504  double interval_u = (double)(end_u - start_u) / (n_u - 1);
505  double interval_v = (double)(end_v - start_v) / (n_v - 1);
506 
507  vtkSmartPointer<vtkDoubleArray> normals = this->getNormals();
508 
509  normals->SetNumberOfComponents(3);
510  normals->SetNumberOfTuples(n_u * n_v);
511  normals->SetName("normalArray");
512  axlPoint *currentNormal = new axlPoint(0.,0.,1.);
513 
514  //double currentTime = vtkTimerLog::GetCPUTime();
515 
516  //qDebug()<<"axlActorSurfaceBSpline::setSurface 1";
517  int ind1 = 0;
518  int ind2 = 0;
519  for(int i = 0; i < n_v - 1; i++)
520  {
521  ind1 = i * n_u;
522  for(int j = 0; j < n_u - 1; j++)
523  {
524  ind2 = ind1 +j;
525 
526  d->splineSurface->normal(currentNormal ,paramCourant_u, paramCourant_v);
527  currentNormal->normalize();
528 
529  normals->SetTuple(ind2, currentNormal->coordinates());
530 
531  paramCourant_u += interval_u;
532  }
533  ind2 = ind1 + (n_u - 1);
534 
535 
536  d->splineSurface->normal(currentNormal, end_u, paramCourant_v);
537  currentNormal->normalize();
538 
539  normals->SetTuple(ind2, currentNormal->coordinates());
540 
541  paramCourant_u = start_u;
542  paramCourant_v += interval_v;
543  }
544  ind1 = n_u * (n_v - 1);
545  for(int i = 0; i < n_u - 1; i++)
546  {
547  ind2 = ind1 + i;
548 
549  d->splineSurface->normal(currentNormal, paramCourant_u, end_v);
550  currentNormal->normalize();
551 
552  normals->SetTuple(ind2, currentNormal->coordinates());
553 
554  paramCourant_u+=interval_u;
555  //qDebug()<< "ind 3"<<ind3;
556 
557  }
558  ind1 = n_u * n_v - 1;
559 
560  d->splineSurface->normal(currentNormal, end_u, end_v);
561  currentNormal->normalize();
562 
563  normals->SetTuple(ind1, currentNormal->coordinates());
564 
565 
566  delete currentNormal;
567  }else {
568 
569  int numCell = d->splineSurface->countCells();
570  int addIndex = 0;
571  int dataArraysSize =0;
572 
573 
574  for(int in = 0; in <numCell;in++){
575  int n_u = d->splineSurface->numSamples_u(in);// need to be superior than 1
576  int n_v = d->splineSurface->numSamples_v(in);
577  dataArraysSize = dataArraysSize + n_u*n_v;
578 
579  }
580 
581  vtkSmartPointer<vtkDoubleArray> normals = this->getNormals();
582  normals->SetNumberOfComponents(3);
583  normals->SetNumberOfTuples(dataArraysSize);
584  normals->SetName("normalArray");
585 
586  for(int indice =0;indice < numCell;indice ++){
587 
588  double start_u = d->splineSurface->startParam_u(indice);
589  double start_v = d->splineSurface->startParam_v(indice);
590  double end_u = d->splineSurface->endParam_u(indice);
591  double end_v = d->splineSurface->endParam_v(indice);
592  double paramCourant_u = start_u;
593  double paramCourant_v = start_v;
594 
595  int n_u = d->splineSurface->numSamples_u(indice);// need to be superior than 1
596  int n_v = d->splineSurface->numSamples_v(indice);
597 
598 
599  double interval_u = (double)(end_u - start_u) / (n_u - 1);
600  double interval_v = (double)(end_v - start_v) / (n_v - 1);
601 
602  axlPoint *currentNormal = new axlPoint(0.,0.,1.);
603 
604  //double currentTime = vtkTimerLog::GetCPUTime();
605 
606  // qDebug()<<"axlActorSurfaceBSpline::setSurface 1" <<currentTime;
607  int ind1 = 0;
608  int ind2 = 0;
609  for(int i = 0; i < n_v - 1; i++)
610  {
611  ind1 = i * n_u;
612  for(int j = 0; j < n_u - 1; j++)
613  {
614  ind2 = ind1 +j;
615 
616  d->splineSurface->normal(currentNormal ,paramCourant_u, paramCourant_v,indice);
617  currentNormal->normalize();
618 
619  normals->SetTuple(ind2+addIndex, currentNormal->coordinates());
620 
621  paramCourant_u += interval_u;
622  }
623  ind2 = ind1 + (n_u - 1);
624 
625  d->splineSurface->normal(currentNormal, end_u, paramCourant_v,indice);
626  currentNormal->normalize();
627 
628  normals->SetTuple(ind2+addIndex, currentNormal->coordinates());
629 
630  paramCourant_u = start_u;
631  paramCourant_v += interval_v;
632  }
633  ind1 = n_u * (n_v - 1);
634  for(int i = 0; i < n_u - 1; i++)
635  {
636  ind2 = ind1 + i;
637 
638  d->splineSurface->normal(currentNormal, paramCourant_u, end_v,indice);
639  currentNormal->normalize();
640 
641  normals->SetTuple(ind2 +addIndex, currentNormal->coordinates());
642 
643  paramCourant_u+=interval_u;
644  //qDebug()<< "ind 3"<<ind3;
645 
646  }
647  ind1 = n_u * n_v - 1;
648 
649  d->splineSurface->normal(currentNormal, end_u, end_v,indice);
650  currentNormal->normalize();
651 
652  normals->SetTuple(ind1+addIndex, currentNormal->coordinates());
653 
654 
655  delete currentNormal;
656 
657  addIndex = addIndex + n_u*n_v;
658 
659  }
660  }
661 }
662 
664 {
665  //qDebug()<<"pointsUpdate()";
666  //std::cin.get();
667 
668  if(d->splineSurface->rational())
669  {
670  d->splineSurface->updateRcoeff();
671  }
672 
673  // we consider here that all memory vtk pipeline from points to polydata are free but not deleted...
674  if(!d->splineSurface->hasCells()){
675 
676  //std::cout<<"axlActorSurfaceBSpline::pointsUpdate(void)::d->splineSurface->hasCells()=false"<<std::endl;
677  //qDebug()<<"rational_="<<d->splineSurface->rational();
678 
679  double start_u = d->splineSurface->startParam_u();
680  double start_v = d->splineSurface->startParam_v();
681  double end_u = d->splineSurface->endParam_u();
682  double end_v = d->splineSurface->endParam_v();
683  double paramCourant_u = start_u;
684  double paramCourant_v = start_v;
685 
686  vtkPoints *points = this->getPoints();
687 
688  int n_u = d->splineSurface->numSamples_u();// need to be superior than 1
689  int n_v = d->splineSurface->numSamples_v();
690  points->SetNumberOfPoints(n_u * n_v);
691 
692  axlPoint *pointCourant = new axlPoint;
693  double interval_u = (double)(end_u - start_u) / (n_u - 1);
694  double interval_v = (double)(end_v - start_v) / (n_v - 1);
695 
696  //qDebug()<<"axlActorSurfaceBSpline::setSurface 1"
697  int ind1 = 0;
698  int ind2 = 0;
699  for(int i = 0; i < n_v - 1; i++)
700  {
701  ind1 = i * n_u;
702  for(int j = 0; j < n_u - 1; j++)
703  {
704  ind2 = ind1 +j;
705  d->splineSurface->eval(pointCourant, paramCourant_u, paramCourant_v);
706 
707  points->SetPoint(ind2, pointCourant->coordinates());
708 
709  paramCourant_u += interval_u;
710  }
711  ind2 = ind1 + (n_u - 1);
712 
713  d->splineSurface->eval(pointCourant, end_u, paramCourant_v);
714  points->SetPoint(ind2 , pointCourant->coordinates());
715 
716 
717  paramCourant_u = start_u;
718  paramCourant_v += interval_v;
719  }
720  ind1 = n_u * (n_v - 1);
721  for(int i = 0; i < n_u - 1; i++)
722  {
723  ind2 = ind1 + i;
724  d->splineSurface->eval(pointCourant, paramCourant_u, end_v);
725  points->SetPoint(ind2, pointCourant->coordinates());
726 
727 
728  paramCourant_u+=interval_u;
729  //qDebug()<< "ind 3"<<ind3;
730 
731  }
732  ind1 = n_u * n_v - 1;
733  d->splineSurface->eval(pointCourant, end_u, end_v);
734  points->SetPoint(ind1, pointCourant->coordinates());
735 
736  delete pointCourant;
737  } else {
738 
739  std::cout<<"axlActorSurfaceBSpline::pointsUpdate(void)::d->splineSurface->hasCells()=ture"<<std::endl;
740 
741  int numCell = d->splineSurface->countCells();
742  int addIndex = 0;
743  int dataArraysSize =0;
744 
745 
746  for(int in = 0; in <numCell;in++){
747  int n_u = d->splineSurface->numSamples_u(in);// need to be superior than 1
748  int n_v = d->splineSurface->numSamples_v(in);
749  dataArraysSize = dataArraysSize + n_u*n_v;
750 
751  }
752 
753  vtkPoints *points = this->getPoints();
754  points->SetNumberOfPoints(dataArraysSize);
755 
756 
757 
758  for(int indice =0;indice < numCell;indice ++){
759 
760  double start_u = d->splineSurface->startParam_u(indice);
761  double start_v = d->splineSurface->startParam_v(indice);
762  double end_u = d->splineSurface->endParam_u(indice);
763  double end_v = d->splineSurface->endParam_v(indice);
764  double paramCourant_u = start_u;
765  double paramCourant_v = start_v;
766 
767  int n_u = d->splineSurface->numSamples_u(indice);// need to be superior than 1
768  int n_v = d->splineSurface->numSamples_v(indice);
769 
770  axlPoint *pointCourant = new axlPoint(0.,0.,0.);
771  double interval_u = (double)(end_u - start_u) / (n_u - 1);
772  double interval_v = (double)(end_v - start_v) / (n_v - 1);
773 
774 
775  //double currentTime = vtkTimerLog::GetCPUTime();
776 
777  // qDebug()<<"axlActorSurfaceBSpline::setSurface 1" <<currentTime;
778  int ind1 = 0;
779  int ind2 = 0;
780  for(int i = 0; i < n_v - 1; i++)
781  {
782  ind1 = i * n_u;
783  for(int j = 0; j < n_u - 1; j++)
784  {
785  ind2 = ind1 +j;
786  d->splineSurface->eval(pointCourant, paramCourant_u, paramCourant_v, indice);
787  points->SetPoint(ind2+addIndex, pointCourant->coordinates());
788 
789  paramCourant_u += interval_u;
790  }
791  ind2 = ind1 + (n_u - 1);
792 
793  d->splineSurface->eval(pointCourant, end_u, paramCourant_v,indice);
794  points->SetPoint(ind2+addIndex , pointCourant->coordinates());
795 
796 
797  paramCourant_u = start_u;
798  paramCourant_v += interval_v;
799  }
800  ind1 = n_u * (n_v - 1);
801  for(int i = 0; i < n_u - 1; i++)
802  {
803  ind2 = ind1 + i;
804  d->splineSurface->eval(pointCourant, paramCourant_u, end_v,indice);
805  points->SetPoint(ind2 +addIndex, pointCourant->coordinates());
806 
807 
808  paramCourant_u+=interval_u;
809  //qDebug()<< "ind 3"<<ind3;
810 
811  }
812  ind1 = n_u * n_v - 1;
813  d->splineSurface->eval(pointCourant, end_u, end_v,indice);
814  points->SetPoint(ind1+addIndex, pointCourant->coordinates());
815 
816  delete pointCourant;
817 
818  addIndex = addIndex + n_u*n_v;
819 
820  }
821  }
822 
823 
824 }
825 
826 //void axlActorSurfaceBSpline::polyDataUpdate(void)
827 //{
828 
829 // vtkSmartPointer<vtkCellArray> cellArray = this->getCellArray();
830 
831 // if(!d->splineSurface->hasCells()){
832 // int n_u = d->splineSurface->numSamples_u();
833 // int n_v = d->splineSurface->numSamples_v();
834 
835 
836 // int ind1 = 0;
837 // int ind2 = 0;
838 
839 // vtkSmartPointer<vtkQuad> currentQuad = vtkSmartPointer<vtkQuad>::New();
840 // currentQuad->GetPointIds()->SetNumberOfIds(4);
841 
842 // for(int j = 0; j < n_v - 1; j++)
843 // {
844 // for(int i= 0; i <n_u - 1; i++)
845 // {
846 // ind1 = j * n_u + i;
847 // ind2 = ind1 + n_u;
848 
849 // currentQuad->GetPointIds()->SetId(0, ind1);
850 // currentQuad->GetPointIds()->SetId(1, ind1 + 1);
851 // currentQuad->GetPointIds()->SetId(2, ind2 + 1);
852 // currentQuad->GetPointIds()->SetId(3, ind2);
853 
854 // cellArray->InsertNextCell(currentQuad);
855 // }
856 // }
857 
858 // }else{
859 
860 // int addIndex = 0;
861 // for(int indice = 0;indice < d->splineSurface->countCells();indice++){
862 // int n_u = d->splineSurface->numSamples_u(indice);
863 // int n_v = d->splineSurface->numSamples_v(indice);
864 
865 // int ind1 = 0;
866 // int ind2 = 0;
867 
868 // vtkSmartPointer<vtkQuad> currentQuad = vtkSmartPointer<vtkQuad>::New();
869 // currentQuad->GetPointIds()->SetNumberOfIds(4);
870 
871 // for(int j = 0; j < n_v - 1; j++)
872 // {
873 // for(int i= 0; i < n_u - 1; i++)
874 // {
875 // ind1 = j * n_u + i + addIndex;
876 // ind2 = ind1 + n_u ;
877 
878 // currentQuad->GetPointIds()->SetId(0, ind1);
879 // currentQuad->GetPointIds()->SetId(1, ind1 + 1);
880 // currentQuad->GetPointIds()->SetId(2, ind2 + 1);
881 // currentQuad->GetPointIds()->SetId(3, ind2);
882 
883 // cellArray->InsertNextCell(currentQuad);
884 // }
885 // }
886 // addIndex = addIndex + n_u*n_v;
887 // }
888 
889 // }
890 
891 //}
892 
894 
895 
896  vtkSmartPointer<vtkCellArray> cellArray =vtkSmartPointer<vtkCellArray>::New();
897  //this->getCellArray();
898  vtkSmartPointer<vtkCellArray> linesArray = d->lines;
899  //vtkSmartPointer<vtkPoints> pointLines = d->linePoints;
900 
901 
902  // //create mesh
903  // QString convertName = d->splineSurface->identifier();
904  // convertName.append("Converter");
905  // axlAbstractDataConverter *converter = dynamic_cast<axlAbstractDataConverter *>(dtkAbstractDataFactory::instance()->converter(convertName));
906  // if(converter){
907 
908  // qDebug() << Q_FUNC_INFO << "enter converter" << converter->identifier();
909  // converter->setData(d->splineSurface);
910  // axlMesh *mesh = converter->toMesh();
911 
912 
913  // vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
914  // //this->getPoints();
915  // points->SetNumberOfPoints(mesh->vertex_count());
916  // double *coord = new double[3];
917  // //add points, replace pointsUpdate();
918  // for(int i= 0 ; i < mesh->vertex_count(); i++){
919  // mesh->vertex(i,coord);
920  // points->SetPoint(i,coord);
921  // }
922 
923  // this->setPoints(points);
924 
925 
926  // // add vtkLines
927  // vtkSmartPointer<vtkLine> lines = vtkSmartPointer<vtkLine>::New();
928  // lines->GetPointIds()->SetNumberOfIds(2);
929  // for(int i = 0; i < mesh->edge_count();i++){
930 
931  // int f = mesh->edge(i).first();
932  // int s = mesh->edge(i).last();
933  // lines->GetPointIds()->SetId(0,f);
934  // lines->GetPointIds()->SetId(1,s);
935 
936  // //linesArray->InsertNextCell(lines);
937  // cellArray->InsertNextCell(lines);
938 
939  // }
940 
941  // // add vtkTriangles or vtkQuad
942  // for(int i = 0; i < mesh->face_count();i++){
943 
944 
945  // vtkSmartPointer<vtkTriangle> triangles = vtkSmartPointer<vtkTriangle>::New();
946  // triangles->GetPointIds()->SetNumberOfIds(3);
947  // vtkSmartPointer<vtkQuad> quad = vtkSmartPointer<vtkQuad>::New();
948  // quad->GetPointIds()->SetNumberOfIds(4);
949 
950  // if(mesh->face(i).size() == 3){
951  // //triangle
952 
953  // triangles->GetPointIds()->SetId(0, mesh->face(i).first());
954  // triangles->GetPointIds()->SetId(1, mesh->face(i).at(1));
955  // triangles->GetPointIds()->SetId(2, mesh->face(i).last());
956 
957  // cellArray->InsertNextCell(triangles);
958 
959  // }else if(mesh->face(i).size() == 4){
960  // //Quad
961 
962  // quad->GetPointIds()->SetId(0, mesh->face(i).first());
963  // quad->GetPointIds()->SetId(1, mesh->face(i).at(1));
964  // quad->GetPointIds()->SetId(2, mesh->face(i).at(2));
965  // quad->GetPointIds()->SetId(3, mesh->face(i).last());
966 
967  // cellArray->InsertNextCell(quad);
968  // }
969  // }
970 
971 
972 
973  // }else{
974 
975 
976  this->pointsUpdate();
977  if(!d->splineSurface->hasCells()){
978  int n_u = d->splineSurface->numSamples_u();
979  int n_v = d->splineSurface->numSamples_v();
980 
981 
982  int ind1 = 0;
983  int ind2 = 0;
984 
985  vtkSmartPointer<vtkQuad> currentQuad = vtkSmartPointer<vtkQuad>::New();
986  currentQuad->GetPointIds()->SetNumberOfIds(4);
987 
988  for(int j = 0; j < n_v - 1; j++)
989  {
990  for(int i= 0; i <n_u - 1; i++)
991  {
992  ind1 = j * n_u + i;
993  ind2 = ind1 + n_u;
994 
995  currentQuad->GetPointIds()->SetId(0, ind1);
996  currentQuad->GetPointIds()->SetId(1, ind1 + 1);
997  currentQuad->GetPointIds()->SetId(2, ind2 + 1);
998  currentQuad->GetPointIds()->SetId(3, ind2);
999 
1000  cellArray->InsertNextCell(currentQuad);
1001  }
1002  }
1003 
1004  } else {
1005 
1006  int addIndex = 0;
1007  for(int indice = 0;indice < d->splineSurface->countCells();indice++){
1008  int n_u = d->splineSurface->numSamples_u(indice);
1009  int n_v = d->splineSurface->numSamples_v(indice);
1010 
1011  int ind1 = 0;
1012  int ind2 = 0;
1013 
1014  vtkSmartPointer<vtkQuad> currentQuad = vtkSmartPointer<vtkQuad>::New();
1015  currentQuad->GetPointIds()->SetNumberOfIds(4);
1016 
1017  for(int j = 0; j < n_v - 1; j++)
1018  {
1019  for(int i= 0; i < n_u - 1; i++)
1020  {
1021  ind1 = j * n_u + i + addIndex;
1022  ind2 = ind1 + n_u ;
1023 
1024  currentQuad->GetPointIds()->SetId(0, ind1);
1025  currentQuad->GetPointIds()->SetId(1, ind1 + 1);
1026  currentQuad->GetPointIds()->SetId(2, ind2 + 1);
1027  currentQuad->GetPointIds()->SetId(3, ind2);
1028 
1029  cellArray->InsertNextCell(currentQuad);
1030  }
1031  }
1032  addIndex = addIndex + n_u*n_v;
1033  }
1034 
1035  }
1036  //}
1037 
1038  this->setCellArray(cellArray);
1039 }
1040 
1042 {
1043  // this->pointsUpdate();
1044  // this->normalsUpdate();
1045  // this->polyDataUpdate();
1046 
1047  // Note: ideally we should not need to call this ?
1048  this->onSamplingChanged();
1049 
1050  if (this->getControlPoints())
1051  this->getControlPoints()->SetControlPointRadius(d->splineSurface->size());
1052 
1053  emit updated();
1054 }
1055 
1056 
1057 void axlActorSurfaceBSpline::onSelectBoundaryEdge(int numEdge, int previous, int n)
1058 {
1059  if(numEdge == -1){
1060  if(d->edgeActor)
1061  d->edgeActor->SetVisibility(false);
1062  }else{
1063 
1064  vtkSmartPointer<vtkPolyData> selectedEdge = vtkSmartPointer<vtkPolyData>::New();
1065  selectedEdge->SetPoints(this->getPoints());
1066  selectedEdge->SetLines(d->lines);
1067  int ne = selectedEdge->GetNumberOfLines();
1068 
1069  selectedEdge->BuildLinks();
1070  for(int i = 0; i < previous;i++){
1071  selectedEdge->DeleteCell(i);
1072  }
1073  for(int i = previous-1+n; i < ne;i++){
1074  selectedEdge->DeleteCell(i);
1075  }
1076  selectedEdge->RemoveDeletedCells();
1077 
1078  // Visualize
1079  vtkSmartPointer<vtkPolyDataMapper> edgeMapper =
1080  vtkSmartPointer<vtkPolyDataMapper>::New();
1081 #if (VTK_MAJOR_VERSION <= 5)
1082  edgeMapper->SetInput(selectedEdge);
1083 #else
1084  edgeMapper->SetInputData(selectedEdge);
1085 #endif
1086 
1087  d->edgeActor->SetMapper(edgeMapper);
1088  d->edgeActor->GetProperty()->EdgeVisibilityOn();
1089  d->edgeActor->GetProperty()->SetEdgeColor(1,0,0);
1090 
1091  d->edgeActor->GetProperty()->SetLineWidth(6);
1092  d->edgeActor->SetVisibility(true);
1093  }
1094 
1095  emit updated();
1096 
1097 
1098 }
1099 
1100 
1101 axlActorSurfaceBSpline::axlActorSurfaceBSpline(void) : axlActorBSpline(), d(new axlActorSurfaceBSplinePrivate)
1102 {
1103  d->splineSurface = NULL;
1104  d->edgeActor = vtkSmartPointer<vtkActor>::New();
1105  d->edgeActor->SetVisibility(false);
1106  this->AddPart(d->edgeActor);
1107 
1108  d->lines = vtkSmartPointer<vtkCellArray>::New();
1109 
1110 }
1111 
1113 {
1114 
1115  if(d->splineSurface->identifier() == "axlSurfaceBSpline")
1116  disconnect(d->splineSurface,SIGNAL(edgeSelected(int)), this, SLOT(onSelectBoundaryEdge(int)));
1117 
1118  delete d;
1119  d = NULL;
1120 }
1121 
1123 
1124  return axlActorSurfaceBSpline::New();
1125 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
vtkSmartPointer< vtkCellArray > getCellArray(void)
Definition: axlActor.cpp:307
vtkSmartPointer< vtkDoubleArray > getNormals(void)
Definition: axlActor.cpp:285
virtual axlControlPointsWidget * getControlPoints(void)
double * coordinates(void) const
Returns coordinates of this point.
Definition: axlPoint.cpp:445
void setNormals(vtkSmartPointer< vtkDoubleArray > normals)
Definition: axlActor.cpp:290
virtual void setData(dtkAbstractData *spline_Surface1)
vtkCxxRevisionMacro(axlActorSurfaceBSpline,"$Revision: 0.0.1 $")
vtkSmartPointer< vtkPolyData > getPolyData(void)
Definition: axlActor.cpp:295
void setCellArray(vtkSmartPointer< vtkCellArray > cellArray)
Definition: axlActor.cpp:312
axlAbstractActor * createAxlActorSurfaceBSpline(void)
void updated(void)
vtkSmartPointer< vtkPoints > getPoints(void)
Definition: axlActor.cpp:275
static axlActorSurfaceBSpline * New(void)
void normalize(void)
Definition: axlPoint.cpp:410
virtual void setShader(QString vsfile)
Definition: axlActor.cpp:517
vtkStandardNewMacro(axlActorSurfaceBSpline)
void setPolyData(vtkSmartPointer< vtkPolyData > polyData)
Definition: axlActor.cpp:300
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
Definition: axlActor.cpp:332
void onSelectBoundaryEdge(int numEdge, int previous, int n)
void setActor(vtkSmartPointer< vtkActor > actor)
Definition: axlActor.cpp:322
vtkSmartPointer< vtkActor > getActor(void)
Definition: axlActor.cpp:317
virtual void onUpdateProperty(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
Definition: axlActor.cpp:327
void setObserverData(dtkAbstractData *data)
Definition: axlActor.cpp:424
virtual void onSamplingChanged(void)
axlActorControlPolygonObserver * getObserver(void)
Definition: axlActor.cpp:366
dtkAbstractData * data(void)
void SetControlPointRadius(double cpSize)
virtual void onUpdateStructure(void)
void NewObserver(void)
Definition: axlActor.cpp:386
void setPoints(vtkSmartPointer< vtkPoints > points)
Definition: axlActor.cpp:280