26 #include <dtkMathSupport/dtkVector3D.h>
29 #include <vtkVolume.h>
30 #include <vtkActorCollection.h>
31 #include <vtkCellArray.h>
32 #include <vtkCellData.h>
33 #include <vtkCommand.h>
34 #include <vtkDoubleArray.h>
35 #include <vtkLookupTable.h>
36 #include <vtkObjectFactory.h>
38 #include <vtkPoints.h>
39 #include <vtkPointData.h>
40 #include <vtkPolyData.h>
41 #include <vtkUnstructuredGrid.h>
42 #include <vtkPolyVertex.h>
43 #include <vtkPolygon.h>
44 #include <vtkPolyDataMapper.h>
45 #include <vtkDataSetMapper.h>
46 #include <vtkPolyDataNormals.h>
47 #include <vtkProperty.h>
49 #include <vtkHexahedron.h>
51 #include <vtkTexture.h>
53 #include <vtkTriangleStrip.h>
54 #include <vtkTimerLog.h>
55 #include <vtkSmartPointer.h>
56 #include <vtkStripper.h>
57 #include <vtkPointData.h>
58 #include <vtkTriangleFilter.h>
59 #include <vtkPNGReader.h>
60 #include <vtkFloatArray.h>
62 #include <vtkOpenGLRenderWindow.h>
64 #include <vtkProperty.h>
65 #include <vtkIdList.h>
71 class axlActorVolumeBSplinePrivate
77 #if (VTK_MAJOR_VERSION <= 5)
85 return d->splineVolume;
92 d->splineVolume = spline_Volume;
94 this->
setPoints(vtkSmartPointer<vtkPoints>::New());
96 this->
setActor(vtkSmartPointer<vtkActor>::New());
97 this->
setCellArray(vtkSmartPointer<vtkCellArray>::New());
110 #if (VTK_MAJOR_VERSION <= 5)
129 QColor color = d->splineVolume->color();
130 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
132 QString shader = d->splineVolume->shader();
133 if(!shader.isEmpty())
136 connect(d->splineVolume, SIGNAL(modifiedGeometry()),
this, SLOT(
onUpdateGeometry()));
137 connect(d->splineVolume, SIGNAL(modifiedProperty()),
this, SLOT(
onUpdateProperty()));
143 vtkSmartPointer<vtkDoubleArray> scalarArray = vtkSmartPointer<vtkDoubleArray>::New();
144 scalarArray->SetName(
"mapperCollorArrayDefaultField");
145 scalarArray->SetNumberOfComponents(1);
147 double start_u = d->splineVolume->startParam_u();
148 double start_v = d->splineVolume->startParam_v();
149 double start_w = d->splineVolume->startParam_w();
150 double end_u = d->splineVolume->endParam_u();
151 double end_v = d->splineVolume->endParam_v();
152 double end_w = d->splineVolume->endParam_w();
153 double paramCourant_u = start_u;
154 double paramCourant_v = start_v;
155 double paramCourant_w = start_w;
157 int n_u = d->splineVolume->numSamples_u();
158 int n_v = d->splineVolume->numSamples_v();
159 int n_w = d->splineVolume->numSamples_w();
161 scalarArray->SetNumberOfTuples(n_u * n_v * n_w);
163 double interval_u = (double)(end_u - start_u) / (n_u - 1);
164 double interval_v = (double)(end_v - start_v) / (n_v - 1);
165 double interval_w = (double)(end_w - start_w) / (n_w - 1);
168 for(
int k = 0; k < n_w - 1 ; k++)
170 for(
int i = 0; i < n_v - 1 ; i++)
172 for(
int j = 0; j < n_u - 1 ; j++)
174 scalarArray->SetTuple1(k * n_u*n_v + i * n_u + j, d->splineVolume->scalarValue(paramCourant_u, paramCourant_v, paramCourant_w));
175 paramCourant_u += interval_u;
178 scalarArray->SetTuple1(k * n_u*n_v + i * n_u + (n_u - 1), d->splineVolume->scalarValue(end_u, paramCourant_v, paramCourant_w));
179 paramCourant_u = start_u;
180 paramCourant_v += interval_v;
182 scalarArray->SetTuple1(k * n_u*n_v + (n_v-1) * n_u + (n_u - 1), d->splineVolume->scalarValue(end_u,end_v, paramCourant_w));
183 paramCourant_u = start_u;
184 paramCourant_v = start_v;
185 paramCourant_w += interval_w;
188 for(
int j = 0; j < n_v - 1; j++)
190 for(
int i = 0; i < n_u - 1; i++)
192 scalarArray->SetTuple1( n_u * n_v * (n_w -1)+ n_u * j + i, d->splineVolume->scalarValue(paramCourant_u, paramCourant_v, end_w));
193 paramCourant_u += interval_u;
195 scalarArray->SetTuple1( n_u * n_v * (n_w -1)+ n_u * j + (n_u-1), d->splineVolume->scalarValue(end_u,paramCourant_v, end_w));
196 paramCourant_u = start_u;
197 paramCourant_u += interval_u;
200 paramCourant_w = start_w;
201 for(
int k = 0; k < n_w ; k++)
203 for(
int i = 0; i < n_u - 1; i++)
205 scalarArray->SetTuple1( n_u * n_v * k + n_u * (n_v-1) + i, d->splineVolume->scalarValue(paramCourant_u, end_v, paramCourant_w));
206 paramCourant_u += interval_u;
209 paramCourant_u = start_u;
210 paramCourant_w += interval_w;
213 scalarArray->SetTuple1(n_u * n_v * n_w - 1, d->splineVolume->scalarValue(end_u, end_v, end_w));
217 data->GetPointData()->AddArray(scalarArray);
218 data->GetPointData()->SetActiveScalars(
"mapperCollorArrayDefaultField");
220 vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
221 lookupTable->SetRange(-1.0, 1.0);
222 lookupTable->SetNumberOfTableValues(d->splineVolume->stripes());
223 lookupTable->Build();
224 for(
int i= 0; i < d->splineVolume->stripes(); i+=2)
226 lookupTable->SetTableValue(i , 1.0, 1.0, 1.0);
227 lookupTable->SetTableValue(i+1, 0.0, 0.0, 0.0);
231 vtkSmartPointer<vtkDoubleArray> lightArray = vtkSmartPointer<vtkDoubleArray>::New();
232 lightArray->SetName(
"mapperLightDirection");
233 lightArray->SetNumberOfComponents(3);
235 paramCourant_u = start_u;
236 paramCourant_v = start_v;
238 lightArray->SetNumberOfTuples(n_u * n_v * n_w);
239 double *currentLight =
new double[3];
240 currentLight[0] = 1.0;
241 currentLight[1] = 0.6;
242 currentLight[2] = 0.2;
243 for(
int k = 0; k < n_w - 1; k++)
245 for(
int j = 0; j < n_v - 1; j++)
247 for(
int i = 0; i < n_u - 1; i++)
249 lightArray->SetTuple(k * n_u* n_v + j * n_u + i, currentLight);
252 lightArray->SetTuple(k * n_u* n_v + j * n_u + n_u - 1, currentLight);
253 paramCourant_u = start_u;
254 paramCourant_v += interval_v;
256 lightArray->SetTuple(k * n_u* n_v + (n_v -1) * n_u + n_u - 1, currentLight);
257 paramCourant_u = start_u;
258 paramCourant_v = start_v;
259 paramCourant_w += interval_w;
262 for(
int j = 0; j < n_v - 1; j++)
264 for(
int i = 0; i < n_u - 1; i++)
266 lightArray->SetTuple((n_w -1)* n_u* n_v + j * n_u + i, currentLight);
267 paramCourant_u += interval_u;
269 lightArray->SetTuple((n_w -1)* n_u* n_v + j * n_u + n_u -1, currentLight);
270 paramCourant_u += interval_u;
273 for(
int k = 0; k < n_w ; k++)
275 for(
int i = 0; i < n_u - 1; i++)
277 lightArray->SetTuple(k* n_u* n_v + (n_v-1) * n_u + i, currentLight);
278 paramCourant_u += interval_u;
281 paramCourant_u += start_u;
282 paramCourant_w += interval_w;
284 lightArray->SetTuple(n_w * n_u* n_v -1, currentLight);
287 data->GetPointData()->AddArray(lightArray);
294 mapper->SetLookupTable(lookupTable);
295 mapper->SetInterpolateScalarsBeforeMapping(
true);
296 mapper->UseLookupTableScalarRangeOn();
327 #if (VTK_MAJOR_VERSION <= 5)
336 if(d->splineVolume->fields().count() != 0){
337 d->splineVolume->touchField();
338 d->splineVolume->touchGeometry();
353 if(d->splineVolume->rational())
355 d->splineVolume->updateRcoeff();
358 double start_u = d->splineVolume->startParam_u();
359 double start_v = d->splineVolume->startParam_v();
360 double start_w = d->splineVolume->startParam_w();
361 double end_u = d->splineVolume->endParam_u();
362 double end_v = d->splineVolume->endParam_v();
363 double end_w = d->splineVolume->endParam_w();
364 double paramCourant_u = start_u;
365 double paramCourant_v = start_v;
366 double paramCourant_w = start_w;
370 int n_u = d->splineVolume->numSamples_u();
371 int n_v = d->splineVolume->numSamples_v();
372 int n_w = d->splineVolume->numSamples_w();
373 points->SetNumberOfPoints(n_u * n_v * n_w);
376 double interval_u = (double)(end_u - start_u) / (n_u - 1);
377 double interval_v = (double)(end_v - start_v) / (n_v - 1);
378 double interval_w = (double)(end_w - start_w) / (n_w - 1);
384 for(
int k = 0; k < n_w - 1; k++)
386 ind1 = k * n_u * n_v;
387 for(
int i = 0; i < n_v - 1; i++)
390 for(
int j = 0; j < n_u - 1; j++)
392 ind3 = ind1 + ind2 +j;
393 d->splineVolume->eval(pointCourant, paramCourant_u, paramCourant_v, paramCourant_w);
394 points->SetPoint(ind3, pointCourant->
coordinates());
395 paramCourant_u += interval_u;
397 ind3 = ind1 + ind2 + (n_u - 1);
399 d->splineVolume->eval(pointCourant, end_u, paramCourant_v, paramCourant_w);
400 points->SetPoint(ind3 , pointCourant->
coordinates());
402 paramCourant_u = start_u;
403 paramCourant_v += interval_v;
405 ind3 = ind1 + (n_v -1)* n_u + (n_u - 1);
407 d->splineVolume->eval(pointCourant, end_u, end_v, paramCourant_w);
408 points->SetPoint(ind3 , pointCourant->
coordinates());
410 paramCourant_u = start_u;
411 paramCourant_v = start_v;
412 paramCourant_w += interval_w;
416 ind1 = n_u * n_v * (n_w - 1);
417 for(
int j = 0; j < n_v - 1; j++)
420 for(
int i = 0; i < n_u - 1; i++)
422 ind3 = ind1 + ind2 + i;
423 d->splineVolume->eval(pointCourant, paramCourant_u,paramCourant_v, end_w);
424 points->SetPoint(ind3, pointCourant->
coordinates());
427 paramCourant_u+=interval_u;
430 ind3 = ind1 + ind2 + (n_u -1);
431 d->splineVolume->eval(pointCourant, end_u, paramCourant_v, end_w);
432 points->SetPoint(ind3, pointCourant->
coordinates());
435 paramCourant_u=start_u;
436 paramCourant_v+=interval_v;
439 paramCourant_w=start_w;
441 ind2 = (n_v-1) * n_u;
443 for(
int k = 0; k < n_w-1 ; k++)
445 ind1 = n_u * n_v * k;
446 for(
int i = 0; i < n_u - 1; i++)
448 ind3 = ind1 + ind2 + i;
449 d->splineVolume->eval(pointCourant, paramCourant_u,end_v, paramCourant_w);
450 points->SetPoint(ind3, pointCourant->
coordinates());
453 paramCourant_u+=interval_u;
456 ind3 = ind2 + ind1 + (n_u-1);
457 paramCourant_u=start_u;
458 paramCourant_w+=interval_w;
460 paramCourant_w = end_w;
461 ind1 = n_u * n_v * (n_w-1);
462 for(
int i = 0; i < n_u - 1; i++)
464 ind3 = ind1 + ind2 + i;
465 d->splineVolume->eval(pointCourant, paramCourant_u,end_v, paramCourant_w);
466 points->SetPoint(ind3, pointCourant->
coordinates());
469 paramCourant_u+=interval_u;
473 ind3 = n_u * n_v * n_w -1;
474 d->splineVolume->eval(pointCourant, end_u, end_v, end_w);
475 points->SetPoint(ind3, pointCourant->
coordinates());
483 vtkSmartPointer<vtkCellArray> cellArray = this->
getCellArray();
485 int n_u = d->splineVolume->numSamples_u();
486 int n_v = d->splineVolume->numSamples_v();
487 int n_w = d->splineVolume->numSamples_w();
493 vtkSmartPointer<vtkHexahedron> currentHexa = vtkSmartPointer<vtkHexahedron>::New();
494 currentHexa->GetPointIds()->SetNumberOfIds(8);
496 vtkSmartPointer<vtkQuad> currentQuad = vtkSmartPointer<vtkQuad>::New();
497 currentQuad->GetPointIds()->SetNumberOfIds(4);
499 vtkSmartPointer<vtkTetra> currentTetra = vtkSmartPointer<vtkTetra>::New();
500 currentTetra->GetPointIds()->SetNumberOfIds(4);
502 for(
int k = 0; k < n_w - 1; k++)
504 for(
int j = 0; j < n_v - 1; j++)
506 for(
int i= 0; i < n_u - 1; i++)
509 ind1 = k * n_u * n_v + j * n_u + i;
511 ind3 = ind1 + n_u * n_v;
512 ind4 = ind2 + n_u * n_v;
571 currentQuad->GetPointIds()->SetId(0, ind1 );
572 currentQuad->GetPointIds()->SetId(1, ind1+1);
573 currentQuad->GetPointIds()->SetId(2, ind2+1 );
574 currentQuad->GetPointIds()->SetId(3, ind2);
576 cellArray->InsertNextCell(currentQuad);
581 currentQuad->GetPointIds()->SetId(0, ind1 );
582 currentQuad->GetPointIds()->SetId(1, ind1+1);
583 currentQuad->GetPointIds()->SetId(2, ind3+1 );
584 currentQuad->GetPointIds()->SetId(3, ind3);
586 cellArray->InsertNextCell(currentQuad);
592 currentQuad->GetPointIds()->SetId(0, ind3 );
593 currentQuad->GetPointIds()->SetId(1, ind1);
594 currentQuad->GetPointIds()->SetId(2, ind2 );
595 currentQuad->GetPointIds()->SetId(3, ind4);
597 cellArray->InsertNextCell(currentQuad);
602 currentQuad->GetPointIds()->SetId(0, ind3 );
603 currentQuad->GetPointIds()->SetId(1, ind3+1);
604 currentQuad->GetPointIds()->SetId(2, ind4+1 );
605 currentQuad->GetPointIds()->SetId(3, ind4);
607 cellArray->InsertNextCell(currentQuad);
611 currentQuad->GetPointIds()->SetId(0, ind2 );
612 currentQuad->GetPointIds()->SetId(1, ind2+1);
613 currentQuad->GetPointIds()->SetId(2, ind4+1 );
614 currentQuad->GetPointIds()->SetId(3, ind4);
616 cellArray->InsertNextCell(currentQuad);
621 currentQuad->GetPointIds()->SetId(0, ind3+1 );
622 currentQuad->GetPointIds()->SetId(1, ind1+1);
623 currentQuad->GetPointIds()->SetId(2, ind2+1 );
624 currentQuad->GetPointIds()->SetId(3, ind4+1);
626 cellArray->InsertNextCell(currentQuad);
Class axlPoint defines 3D points.
vtkSmartPointer< vtkCellArray > getCellArray(void)
void setDataSetMapper(vtkSmartPointer< vtkDataSetMapper > mapper)
vtkCxxRevisionMacro(axlActorVolumeBSpline,"$Revision: 0.0.1 $")
void setUnstructuredGrid(vtkSmartPointer< vtkUnstructuredGrid > unstructuredGrid)
virtual axlControlPointsWidget * getControlPoints(void)
double * coordinates(void) const
Returns coordinates of this point.
axlActorVolumeBSpline(void)
void setMapperCollorArray(void)
static axlActorVolumeBSpline * New(void)
void setCellArray(vtkSmartPointer< vtkCellArray > cellArray)
virtual void setData(dtkAbstractData *spline_Volume1)
dtkAbstractData * data(void)
vtkSmartPointer< vtkPoints > getPoints(void)
virtual void onUpdateGeometry(void)
virtual void onSamplingChanged(void)
virtual void setShader(QString vsfile)
vtkSmartPointer< vtkUnstructuredGrid > getUnstructuredGrid(void)
vtkSmartPointer< vtkDataSetMapper > getDataSetMapper(void)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
virtual void onUpdateProperty(void)
axlAbstractActor * createAxlActorVolumeBSpline(void)
vtkStandardNewMacro(axlActorVolumeBSpline)
~axlActorVolumeBSpline(void)
void setObserverData(dtkAbstractData *data)
axlActorControlPolygonObserver * getObserver(void)
void setPoints(vtkSmartPointer< vtkPoints > points)
void UnstructuredGridUpdate(void)