26 #include <dtkMathSupport/dtkVector3D.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>
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>
47 #include <vtkTexture.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>
58 #include <vtkOpenGLRenderWindow.h>
60 #include <vtkProperty.h>
62 #include <vtkFeatureEdges.h>
63 #include <vtkExtractEdges.h>
64 #include <vtkRenderWindowInteractor.h>
65 #include <vtkRendererCollection.h>
70 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
74 #include <vtkTriangle.h>
80 class axlActorShapeBSplinePrivate
84 vtkSmartPointer<vtkActor> edgeActor;
86 vtkSmartPointer<vtkCellArray> lines;
89 #if (VTK_MAJOR_VERSION <= 5)
97 d->splineShape = NULL;
98 d->edgeActor = vtkSmartPointer<vtkActor>::New();
99 d->edgeActor->SetVisibility(
false);
100 this->AddPart(d->edgeActor);
102 d->lines = vtkSmartPointer<vtkCellArray>::New();
109 if(d->splineShape->identifier() ==
"axlShapeBSpline")
118 return d->splineShape;
125 d->splineShape = spline_Shape;
127 this->
setPoints(vtkSmartPointer<vtkPoints>::New());
129 this->
setNormals(vtkSmartPointer<vtkDoubleArray>::New());
133 this->
setActor(vtkSmartPointer<vtkActor>::New());
134 this->
setCellArray(vtkSmartPointer<vtkCellArray>::New());
135 this->
setPolyData(vtkSmartPointer<vtkPolyData>::New());
136 this->
setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
151 #if (VTK_MAJOR_VERSION <= 5)
158 this->
getMapper()->ScalarVisibilityOff();
172 QColor color = d->splineShape->color();
173 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
175 QString shader = d->splineShape->shader();
176 if(!shader.isEmpty())
179 connect(d->splineShape, SIGNAL(edgeSelected(
int,
int,
int)),
this, SLOT(
onSelectBoundaryEdge(
int,
int,
int)));
182 connect(d->splineShape, SIGNAL(modifiedGeometry()),
this, SLOT(
onUpdateGeometry()));
183 connect(d->splineShape, SIGNAL(modifiedProperty()),
this, SLOT(
onUpdateProperty()));
185 connect(d->splineShape, SIGNAL(modifiedStructure()),
this, SLOT(
onUpdateStructure()));
191 vtkSmartPointer<vtkDoubleArray> scalarArray = vtkSmartPointer<vtkDoubleArray>::New();
192 scalarArray->SetName(
"mapperCollorArrayDefaultField");
193 scalarArray->SetNumberOfComponents(1);
195 if(d->splineShape->hasFaces()) {
198 for(
int indice = 0; indice < d->splineShape->countFaces(); indice++){
200 double start_u = d->splineShape->startParam_u(indice);
201 double start_v = d->splineShape->startParam_v(indice);
202 double end_u = d->splineShape->endParam_u(indice);
203 double end_v = d->splineShape->endParam_v(indice);
204 double paramCourant_u = start_u;
205 double paramCourant_v = start_v;
207 int n_u = d->splineShape->numSamples_u(indice);
208 int n_v = d->splineShape->numSamples_v(indice);
210 scalarArray->SetNumberOfTuples(n_u * n_v);
212 double interval_u = (double)(end_u - start_u) / (n_u - 1);
213 double interval_v = (double)(end_v - start_v) / (n_v - 1);
215 for(
int i = 0; i < n_v - 1 ; i++)
217 for(
int j = 0; j < n_u - 1 ; j++)
219 scalarArray->SetTuple1(i * n_u + j+addIndex, d->splineShape->scalarValue(paramCourant_u, paramCourant_v));
220 paramCourant_u += interval_u;
223 scalarArray->SetTuple1(i * n_u + (n_u - 1)+addIndex, d->splineShape->scalarValue(end_u, paramCourant_v));
224 paramCourant_u = start_u;
225 paramCourant_v += interval_v;
227 for(
int i = 0; i < n_u - 1; i++)
229 scalarArray->SetTuple1(n_u * (n_v - 1) + i+addIndex, d->splineShape->scalarValue(paramCourant_u, end_v));
230 paramCourant_u += interval_u;
232 scalarArray->SetTuple1(n_u * n_v - 1+addIndex, d->splineShape->scalarValue(end_u, end_v));
236 data->GetPointData()->AddArray(scalarArray);
237 data->GetPointData()->SetActiveScalars(
"mapperCollorArrayDefaultField");
239 vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
240 lookupTable->SetRange(-1.0, 1.0);
241 lookupTable->SetNumberOfTableValues(d->splineShape->stripes());
242 lookupTable->Build();
243 for(
int i= 0; i < d->splineShape->stripes(); i+=2)
245 lookupTable->SetTableValue(i , 1.0, 1.0, 1.0);
246 lookupTable->SetTableValue(i+1, 0.0, 0.0, 0.0);
250 vtkSmartPointer<vtkDoubleArray> lightArray = vtkSmartPointer<vtkDoubleArray>::New();
251 lightArray->SetName(
"mapperLightDirection");
252 lightArray->SetNumberOfComponents(3);
254 paramCourant_u = start_u;
255 paramCourant_v = start_v;
257 lightArray->SetNumberOfTuples(n_u * n_v);
258 double *currentLight =
new double[3];
259 currentLight[0] = 1.0;
260 currentLight[1] = 0.6;
261 currentLight[2] = 0.2;
262 for(
int j = 0; j < n_v - 1; j++)
264 for(
int i = 0; i < n_u - 1; i++)
266 lightArray->SetTuple(j * n_u + i+addIndex, currentLight);
269 lightArray->SetTuple(j * n_u + n_u - 1+addIndex, currentLight);
270 paramCourant_u = start_u;
271 paramCourant_v += interval_v;
274 for(
int i = 0; i < n_u - 1; i++)
276 lightArray->SetTuple((n_v - 1) * n_u + i+addIndex, currentLight);
277 paramCourant_u += interval_u;
279 lightArray->SetTuple(n_v * n_u - 1+addIndex, currentLight);
282 data->GetPointData()->AddArray(lightArray);
286 vtkSmartPointer<vtkPolyDataMapper> mapper = this->
getMapper();
287 vtkSmartPointer<vtkPolyData> polyData = this->
getPolyData();
288 mapper->MapDataArrayToVertexAttribute(
"scalarsattrib", data->GetPointData()->GetArrayName(2), vtkDataObject::FIELD_ASSOCIATION_POINTS, -1);
289 mapper->SetLookupTable(lookupTable);
290 mapper->SetInterpolateScalarsBeforeMapping(
true);
291 mapper->UseLookupTableScalarRangeOn();
292 addIndex = addIndex + n_u*n_v;
331 #if (VTK_MAJOR_VERSION <= 5)
339 if(d->splineShape->fields().count() != 0){
340 d->splineShape->touchField();
341 d->splineShape->touchGeometry();
348 if(d->splineShape->hasFaces()) {
350 int numCell = d->splineShape->countFaces();
352 int dataArraysSize =0;
354 for(
int in = 0; in <numCell;in++){
355 int n_u = d->splineShape->numSamples_u(in);
356 int n_v = d->splineShape->numSamples_v(in);
357 dataArraysSize = dataArraysSize + n_u*n_v;
361 vtkSmartPointer<vtkDoubleArray> normals = this->
getNormals();
362 normals->SetNumberOfComponents(3);
363 normals->SetNumberOfTuples(dataArraysSize);
364 normals->SetName(
"normalArray");
366 for(
int indice =0;indice < numCell;indice ++){
368 double start_u = d->splineShape->startParam_u(indice);
369 double start_v = d->splineShape->startParam_v(indice);
370 double end_u = d->splineShape->endParam_u(indice);
371 double end_v = d->splineShape->endParam_v(indice);
372 double paramCourant_u = start_u;
373 double paramCourant_v = start_v;
375 int n_u = d->splineShape->numSamples_u(indice);
376 int n_v = d->splineShape->numSamples_v(indice);
379 double interval_u = (double)(end_u - start_u) / (n_u - 1);
380 double interval_v = (double)(end_v - start_v) / (n_v - 1);
389 for(
int i = 0; i < n_v - 1; i++)
392 for(
int j = 0; j < n_u - 1; j++)
396 d->splineShape->normal(currentNormal ,paramCourant_u, paramCourant_v,indice);
399 normals->SetTuple(ind2+addIndex, currentNormal->
coordinates());
401 paramCourant_u += interval_u;
403 ind2 = ind1 + (n_u - 1);
405 d->splineShape->normal(currentNormal, end_u, paramCourant_v,indice);
408 normals->SetTuple(ind2+addIndex, currentNormal->
coordinates());
410 paramCourant_u = start_u;
411 paramCourant_v += interval_v;
413 ind1 = n_u * (n_v - 1);
414 for(
int i = 0; i < n_u - 1; i++)
418 d->splineShape->normal(currentNormal, paramCourant_u, end_v,indice);
421 normals->SetTuple(ind2 +addIndex, currentNormal->
coordinates());
423 paramCourant_u+=interval_u;
427 ind1 = n_u * n_v - 1;
429 d->splineShape->normal(currentNormal, end_u, end_v,indice);
432 normals->SetTuple(ind1+addIndex, currentNormal->
coordinates());
434 delete currentNormal;
436 addIndex = addIndex + n_u*n_v;
445 if(d->splineShape->hasFaces()){
447 int numCell = d->splineShape->countFaces();
449 int dataArraysSize =0;
451 for(
int in = 0; in <numCell;in++){
452 int n_u = d->splineShape->numSamples_u(in);
453 int n_v = d->splineShape->numSamples_v(in);
454 dataArraysSize = dataArraysSize + n_u*n_v;
459 points->SetNumberOfPoints(dataArraysSize);
461 for(
int indice =0;indice < numCell;indice ++){
463 double start_u = d->splineShape->startParam_u(indice);
464 double start_v = d->splineShape->startParam_v(indice);
465 double end_u = d->splineShape->endParam_u(indice);
466 double end_v = d->splineShape->endParam_v(indice);
467 double paramCourant_u = start_u;
468 double paramCourant_v = start_v;
470 int n_u = d->splineShape->numSamples_u(indice);
471 int n_v = d->splineShape->numSamples_v(indice);
474 double interval_u = (double)(end_u - start_u) / (n_u - 1);
475 double interval_v = (double)(end_v - start_v) / (n_v - 1);
483 for(
int i = 0; i < n_v - 1; i++)
486 for(
int j = 0; j < n_u - 1; j++)
489 d->splineShape->eval(pointCourant, paramCourant_u, paramCourant_v, indice);
490 points->SetPoint(ind2+addIndex, pointCourant->
coordinates());
493 paramCourant_u += interval_u;
495 ind2 = ind1 + (n_u - 1);
497 d->splineShape->eval(pointCourant, end_u, paramCourant_v,indice);
498 points->SetPoint(ind2+addIndex , pointCourant->
coordinates());
501 paramCourant_u = start_u;
502 paramCourant_v += interval_v;
504 ind1 = n_u * (n_v - 1);
505 for(
int i = 0; i < n_u - 1; i++)
508 d->splineShape->eval(pointCourant, paramCourant_u, end_v,indice);
509 points->SetPoint(ind2 +addIndex, pointCourant->
coordinates());
512 paramCourant_u+=interval_u;
516 ind1 = n_u * n_v - 1;
517 d->splineShape->eval(pointCourant, end_u, end_v,indice);
518 points->SetPoint(ind1+addIndex, pointCourant->
coordinates());
522 addIndex = addIndex + n_u*n_v;
531 vtkSmartPointer<vtkCellArray> cellArray = vtkSmartPointer<vtkCellArray>::New();
533 vtkSmartPointer<vtkCellArray> linesArray = d->lines;
537 if(d->splineShape->hasFaces()) {
540 for(
int indice = 0;indice < d->splineShape->countFaces();indice++){
541 int n_u = d->splineShape->numSamples_u(indice);
542 int n_v = d->splineShape->numSamples_v(indice);
547 vtkSmartPointer<vtkQuad> currentQuad = vtkSmartPointer<vtkQuad>::New();
548 currentQuad->GetPointIds()->SetNumberOfIds(4);
550 for(
int j = 0; j < n_v - 1; j++)
552 for(
int i= 0; i < n_u - 1; i++)
554 ind1 = j * n_u + i + addIndex;
557 currentQuad->GetPointIds()->SetId(0, ind1);
558 currentQuad->GetPointIds()->SetId(1, ind1 + 1);
559 currentQuad->GetPointIds()->SetId(2, ind2 + 1);
560 currentQuad->GetPointIds()->SetId(3, ind2);
562 cellArray->InsertNextCell(currentQuad);
565 addIndex = addIndex + n_u*n_v;
587 d->edgeActor->SetVisibility(
false);
590 vtkSmartPointer<vtkPolyData> selectedEdge = vtkSmartPointer<vtkPolyData>::New();
591 selectedEdge->SetPoints(this->
getPoints());
592 selectedEdge->SetLines(d->lines);
593 int ne = selectedEdge->GetNumberOfLines();
595 selectedEdge->BuildLinks();
596 for(
int i = 0; i < previous;i++){
597 selectedEdge->DeleteCell(i);
599 for(
int i = previous-1+n; i < ne;i++){
600 selectedEdge->DeleteCell(i);
602 selectedEdge->RemoveDeletedCells();
605 vtkSmartPointer<vtkPolyDataMapper> edgeMapper =
606 vtkSmartPointer<vtkPolyDataMapper>::New();
607 #if (VTK_MAJOR_VERSION <= 5)
608 edgeMapper->SetInput(selectedEdge);
610 edgeMapper->SetInputData(selectedEdge);
613 d->edgeActor->SetMapper(edgeMapper);
614 d->edgeActor->GetProperty()->EdgeVisibilityOn();
615 d->edgeActor->GetProperty()->SetEdgeColor(1,0,0);
617 d->edgeActor->GetProperty()->SetLineWidth(6);
618 d->edgeActor->SetVisibility(
true);
Class axlPoint defines 3D points.
vtkSmartPointer< vtkCellArray > getCellArray(void)
vtkSmartPointer< vtkDoubleArray > getNormals(void)
vtkStandardNewMacro(axlActorShapeBSpline)
double * coordinates(void) const
Returns coordinates of this point.
void setNormals(vtkSmartPointer< vtkDoubleArray > normals)
virtual void onSamplingChanged(void)
void setMapperCollorArray(void)
~axlActorShapeBSpline(void)
vtkSmartPointer< vtkPolyData > getPolyData(void)
void polyDataUpdate(void)
void setCellArray(vtkSmartPointer< vtkCellArray > cellArray)
static axlActorShapeBSpline * New(void)
vtkCxxRevisionMacro(axlActorShapeBSpline,"$Revision: 0.0.1 $")
vtkSmartPointer< vtkPoints > getPoints(void)
dtkAbstractData * data(void)
axlActorShapeBSpline(void)
virtual void setShader(QString vsfile)
void setPolyData(vtkSmartPointer< vtkPolyData > polyData)
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
virtual void setData(dtkAbstractData *spline_shape1)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
virtual void onUpdateProperty(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
axlAbstractActor * createAxlActorShapeBSpline(void)
Class axlShapeBSpline defines a set of boundary curves (Edges) and bspline surface patches (Face)...
void setObserverData(dtkAbstractData *data)
axlActorControlPolygonObserver * getObserver(void)
virtual void onUpdateStructure(void)
virtual void onUpdateGeometry(void)
void setPoints(vtkSmartPointer< vtkPoints > points)
void onSelectBoundaryEdge(int numEdge, int previous, int n)