25 #include <dtkMathSupport/dtkVector3D.h>
28 #include <vtkActorCollection.h>
29 #include <vtkCellArray.h>
30 #include <vtkCellData.h>
31 #include <vtkCommand.h>
32 #include <vtkDoubleArray.h>
33 #include <vtkLookupTable.h>
34 #include <vtkObjectFactory.h>
36 #include <vtkPoints.h>
37 #include <vtkPointData.h>
38 #include <vtkPolyData.h>
39 #include <vtkPolyVertex.h>
40 #include <vtkPolygon.h>
41 #include <vtkPolyDataMapper.h>
42 #include <vtkPolyDataNormals.h>
43 #include <vtkProperty.h>
46 #include <vtkTexture.h>
47 #include <vtkTriangle.h>
48 #include <vtkTimerLog.h>
49 #include <vtkSmartPointer.h>
55 class axlActorSurfaceTrimmedPrivate
61 #if (VTK_MAJOR_VERSION <= 5)
69 return d->splineSurface;
75 d->splineSurface = spline_Surface;
77 this->
setPoints(vtkSmartPointer<vtkPoints>::New());
78 this->
setActor(vtkSmartPointer<vtkActor>::New());
79 this->
setCellArray(vtkSmartPointer<vtkCellArray>::New());
80 this->
setPolyData(vtkSmartPointer<vtkPolyData>::New());
81 this->
setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
91 vtkProp3D *prop3d = this->
getActor();
92 this->AddPart(prop3d);
101 QString shader = d->splineSurface->shader();
102 if(!shader.isEmpty())
108 void axlActorSurfaceTrimmed::mehsProcess(
void)
111 double start_u = d->splineSurface->startParam_u();
112 double start_v = d->splineSurface->startParam_v();
113 double end_u = d->splineSurface->endParam_u();
114 double end_v = d->splineSurface->endParam_v();
115 double paramCourant_u = start_u;
116 double paramCourant_v = start_v;
120 int n_u = d->splineSurface->numSamples_u();
121 int n_v = d->splineSurface->numSamples_v();
124 double interval_u = (double)(end_u - start_u) / (n_u - 1);
125 double interval_v = (double)(end_v - start_v) / (n_v - 1);
127 vtkSmartPointer<vtkDoubleArray> normals = vtkSmartPointer<vtkDoubleArray>::New();
128 normals->SetNumberOfComponents(3);
129 normals->SetNumberOfTuples(n_u * n_v);
130 normals->SetName(
"normalArray");
131 double *currentNormal =
new double[3];
133 dtkDeprecated::dtkVector<bool> inDomain;
134 inDomain.allocate(n_u * n_v);
136 dtkDeprecated::dtkVector<double> normal;
137 for(
int j = 0; j < n_v - 1; j++)
139 for(
int i = 0; i < n_u - 1; i++)
141 if(d->splineSurface->inDomain(paramCourant_u, paramCourant_v))
142 inDomain[j * n_u + i] =
true;
144 inDomain[j * n_u + i] =
false;
146 pointCourant = d->splineSurface->eval(paramCourant_u, paramCourant_v);
147 normal = d->splineSurface->normal(paramCourant_u, paramCourant_v).unit();
148 currentNormal[0] = normal[0];
149 currentNormal[1] = normal[1];
150 currentNormal[2] = normal[2];
151 normals->SetTuple(j * n_u + i, currentNormal);
153 this->
getPoints()->InsertNextPoint(pointCourant.
x(), pointCourant.
y(), pointCourant.
z());
154 paramCourant_u += interval_u;
157 if(d->splineSurface->inDomain(end_u, paramCourant_v))
158 inDomain[j * n_u + n_u - 1] =
true;
160 inDomain[j * n_u + n_u - 1] =
false;
162 normal = d->splineSurface->normal(end_u, paramCourant_v).unit();
163 currentNormal[0] = normal[0];
164 currentNormal[1] = normal[1];
165 currentNormal[2] = normal[2];
166 normals->SetTuple(j * n_u + n_u - 1, currentNormal);
168 pointCourant = d->splineSurface->eval(end_u, paramCourant_v);
169 this->
getPoints()->InsertNextPoint(pointCourant.
x(), pointCourant.
y(), pointCourant.
z());
170 paramCourant_u = start_u;
171 paramCourant_v += interval_v;
174 for(
int i = 0; i < n_u - 1; i++)
176 if(d->splineSurface->inDomain(paramCourant_u, end_v))
177 inDomain[(n_v - 1) * n_u + i] =
true;
179 inDomain[(n_v - 1) * n_u + i] =
false;
182 normal = d->splineSurface->normal(paramCourant_u, end_v).unit();
183 currentNormal[0] = normal[0];
184 currentNormal[1] = normal[1];
185 currentNormal[2] = normal[2];
186 normals->SetTuple((n_v - 1) * n_u + i, currentNormal);
188 pointCourant=d->splineSurface->eval(paramCourant_u, end_v);
189 this->
getPoints()->InsertNextPoint(pointCourant.
x(), pointCourant.
y(), pointCourant.
z());
190 paramCourant_u += interval_u;
193 if(d->splineSurface->inDomain(end_u, end_v))
194 inDomain[n_v * n_u - 1] =
true;
196 inDomain[n_v * n_u - 1] =
false;
199 normal = d->splineSurface->normal(end_u, end_v).unit();
200 currentNormal[0] = normal[0];
201 currentNormal[1] = normal[1];
202 currentNormal[2] = normal[2];
203 normals->SetTuple(n_v * n_u - 1, currentNormal);
205 pointCourant = d->splineSurface->eval(end_u, end_v);
207 this->
getPoints()->InsertNextPoint(pointCourant.
x() , pointCourant.
y(), pointCourant.
z());
212 vtkSmartPointer<vtkTriangle> currentTriangle = vtkSmartPointer<vtkTriangle>::New();
213 currentTriangle->GetPointIds()->SetNumberOfIds(3);
215 for(
int j = 0; j < n_v - 1; j++)
217 for(
int i= 0; i <n_u - 1; i++)
222 currentTriangle->GetPointIds()->SetId(0, ind1);
223 currentTriangle->GetPointIds()->SetId(1, ind1 + 1);
224 currentTriangle->GetPointIds()->SetId(2, ind2);
226 if(inDomain[ind1] + inDomain[ind1 + 1] + inDomain[ind2] > 1)
229 currentTriangle->GetPointIds()->SetId(1, ind1 + 1);
230 currentTriangle->GetPointIds()->SetId(0, ind2);
231 currentTriangle->GetPointIds()->SetId(2, ind2 + 1);
233 if(inDomain[ind1] + inDomain[ind1 + 1] + inDomain[ind2] > 1)
242 vtkSmartPointer<vtkPolyDataNormals> polyDataNormals = vtkSmartPointer<vtkPolyDataNormals>::New();
243 polyDataNormals->AutoOrientNormalsOn();
244 polyDataNormals->FlipNormalsOn();
245 #if (VTK_MAJOR_VERSION <= 5)
247 this->
getMapper()->SetInput(polyDataNormals->GetOutput());
249 polyDataNormals->SetInputData(this->
getPolyData());
250 this->
getMapper()->SetInputData(polyDataNormals->GetOutput());
254 if(d->splineSurface->fields().count() != 0)
255 d->splineSurface->touchField();
263 vtkSmartPointer<vtkDoubleArray> scalarArray = vtkSmartPointer<vtkDoubleArray>::New();
264 scalarArray->SetName(
"mapperCollorArrayDefaultField");
265 scalarArray->SetNumberOfComponents(1);
267 double start_u = d->splineSurface->startParam_u();
268 double start_v = d->splineSurface->startParam_v();
269 double end_u = d->splineSurface->endParam_u();
270 double end_v = d->splineSurface->endParam_v();
271 double paramCourant_u = start_u;
272 double paramCourant_v = start_v;
274 int n_u = d->splineSurface->numSamples_u();
275 int n_v = d->splineSurface->numSamples_v();
277 scalarArray->SetNumberOfTuples(n_u * n_v);
279 double interval_u = (double)(end_u - start_u) / (n_u - 1);
280 double interval_v = (double)(end_v - start_v) / (n_v - 1);
282 for(
int i = 0; i < n_v - 1 ; i++)
284 for(
int j = 0; j < n_u - 1 ; j++)
286 scalarArray->SetTuple1(i * n_u + j, d->splineSurface->inDomain(paramCourant_u, paramCourant_v) ? 1:0);
287 paramCourant_u += interval_u;
290 scalarArray->SetTuple1(i * n_u + (n_u - 1), d->splineSurface->inDomain(end_u, paramCourant_v) ? 1:0);
291 paramCourant_u = start_u;
292 paramCourant_v += interval_v;
294 for(
int i = 0; i < n_u - 1; i++)
296 scalarArray->SetTuple1(n_u * (n_v - 1) + i, d->splineSurface->inDomain(paramCourant_u, end_v) ? 1:0);
297 paramCourant_u += interval_u;
299 scalarArray->SetTuple1(n_u * n_v - 1, d->splineSurface->inDomain(end_u, end_v) ? 1:0);
303 data->GetPointData()->AddArray(scalarArray);
304 data->GetPointData()->SetActiveScalars(
"mapperCollorArrayDefaultField");
306 vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
307 lookupTable->SetRange(0.0, 1.0);
308 lookupTable->SetNumberOfTableValues(2);
309 lookupTable->Build();
311 lookupTable->SetTableValue(0 , 0.0, 0.0, 0.0, 0.0);
312 lookupTable->SetTableValue(1 , 1.0, 1.0, 1.0, 1.0);
316 vtkSmartPointer<vtkPolyDataMapper> mapper = this->
getMapper();
317 vtkSmartPointer<vtkPolyData> polyData = this->
getPolyData();
318 mapper->SetLookupTable(lookupTable);
319 mapper->SetInterpolateScalarsBeforeMapping(
true);
320 mapper->UseLookupTableScalarRangeOn();
362 #if (VTK_MAJOR_VERSION <= 5)
Class axlPoint defines 3D points.
vtkSmartPointer< vtkCellArray > getCellArray(void)
virtual axlControlPointsWidget * getControlPoints(void)
dtkAbstractData * data(void)
vtkStandardNewMacro(axlActorSurfaceTrimmed)
vtkSmartPointer< vtkPolyData > getPolyData(void)
void setCellArray(vtkSmartPointer< vtkCellArray > cellArray)
axlActorSurfaceTrimmed(void)
vtkCxxRevisionMacro(axlActorSurfaceTrimmed,"$Revision: 0.0.1 $")
vtkSmartPointer< vtkPoints > getPoints(void)
~axlActorSurfaceTrimmed(void)
virtual void setShader(QString vsfile)
void setPolyData(vtkSmartPointer< vtkPolyData > polyData)
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
virtual void addToObserver(int idEvent, vtkCommand *observer)
void setObserverData(dtkAbstractData *data)
void setMapperCollorArray(void)
void setSurface(axlAbstractSurfaceTrimmed *Surface)
axlActorControlPolygonObserver * getObserver(void)
void setControlPolygon(bool control)
virtual vtkRenderWindowInteractor * getInteractor(void)
virtual void onSamplingChanged(void)
virtual void setControlPoints(axlControlPointsWidget *controlPoints)
void setPoints(vtkSmartPointer< vtkPoints > points)