27 #include <dtkCoreSupport/dtkAbstractDataConverter.h>
34 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
37 #include <vtkCommand.h>
38 #include <vtkCellArray.h>
39 #include <vtkCleanPolyData.h>
40 #include <vtkDoubleArray.h>
42 #include <vtkObjectFactory.h>
43 #include <vtkDataSetMapper.h>
44 #include <vtkPointData.h>
45 #include <vtkPolyDataMapper.h>
46 #include <vtkPolyDataNormals.h>
47 #include <vtkPolygon.h>
48 #include <vtkProperty.h>
49 #include <vtkSmartPointer.h>
50 #include <vtkSphereSource.h>
51 #include <vtkTubeFilter.h>
52 #include <vtkUnstructuredGrid.h>
53 #include <vtkVertex.h>
55 #include <vtkIntArray.h>
56 #include <vtkLookupTable.h>
57 #include <vtkAreaPicker.h>
58 #include <vtkCellPicker.h>
60 #include <vtkRenderWindow.h>
61 #include <vtkRenderer.h>
62 #include <vtkRenderWindowInteractor.h>
63 #include <vtkIdFilter.h>
64 #include <vtkDataSetSurfaceFilter.h>
65 #include <vtkTriangleFilter.h>
67 #include <vtkFeatureEdges.h>
68 #include <vtkExtractEdges.h>
70 #include <vtkRendererCollection.h>
71 #include <vtkPoints.h>
79 class axlActorMeshPrivate
82 vtkSmartPointer<vtkDataSetMapper> dataSetMapper;
83 vtkSmartPointer<vtkActor> actorSphereParam;
85 vtkSmartPointer<vtkPolyDataNormals> polyDataNormals;
95 #if (VTK_MAJOR_VERSION <= 5)
103 return "axlActorMesh";
116 this->
setActor(vtkSmartPointer<vtkActor>::New());
117 this->
setCellArray(vtkSmartPointer<vtkCellArray>::New());
118 this->
setPolyData(vtkSmartPointer<vtkPolyData>::New());
119 this->
setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
120 this->
setPoints(vtkSmartPointer<vtkPoints>::New());
121 this->
getMapper()->ScalarVisibilityOff();
126 if (!d->mesh->normal_count()){
128 this->
getActor()->GetProperty()->SetInterpolationToFlat();
130 d->mesh->setInterpolation(2);
131 this->
getActor()->GetProperty()->SetInterpolationToPhong();
138 QColor color = d->data->color();
139 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
141 this->
setSize(d->data->size());
142 QString shader = d->data->shader();
143 if(!shader.isEmpty())
147 connect(d->data, SIGNAL(modifiedGeometry()),
this, SLOT(
onUpdateGeometry()));
148 connect(d->data, SIGNAL(modifiedProperty()),
this, SLOT(
onUpdateProperty()));
153 #if VTK_MAJOR_VERSION <= 5
154 d->polyDataNormals->SetInput(polydata);
156 d->polyDataNormals->SetInputData(this->
getPolyData());
158 d->polyDataNormals->ComputePointNormalsOn();
159 d->polyDataNormals->ComputeCellNormalsOff();
160 d->polyDataNormals->SetSplitting(0);
162 d->polyDataNormals->Update();
174 this->
setPolyData(d->polyDataNormals->GetOutput());
176 d->mesh->clearNormals();
179 vtkDataArray* normalsGeneric = this->
getPolyData()->GetPointData()->GetNormals();
183 double normalDouble[3];
184 if (normalsGeneric->GetNumberOfTuples() != d->mesh->vertex_count()){
185 dtkWarn() <<
"Couldn't compute normals.";
190 for (
int i = 0; i < normalsGeneric->GetNumberOfTuples(); i++) {
191 normalsGeneric->GetTuple(i, normalDouble);
193 d->mesh->push_back_normal(normalDouble);
212 this->
getActor()->GetProperty()->SetPointSize(10 * size);
213 this->
getActor()->GetProperty()->SetLineWidth(10 * size);
226 QColor color = d->data->color();
227 this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
235 vtkProperty *prop = this->
getActor()->GetProperty();
239 QColor color = d->data->color();
240 qreal *h =
new qreal(0.0);
241 qreal *s =
new qreal(0.0);
242 qreal *l =
new qreal(0.0);
243 color.getHslF(h, s, l);
244 color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
245 prop->SetColor(color.redF(), color.greenF(), color.blueF());
255 vtkProperty *prop = this->
getActor()->GetProperty();
258 QColor color = d->data->color();
259 qreal *h =
new qreal(0.0);
260 qreal *s =
new qreal(0.0);
261 qreal *l =
new qreal(0.0);
262 color.getHslF(h, s, l);
263 color.setHslF(*h, *s, *l + (1.0 - *l)/2.0);
264 prop->SetColor(color.redF(), color.greenF(), color.blueF());
277 if(d->mesh &&d->data)
279 bool isNormal = (d->mesh->normal_used() && d->mesh->vertex_count() == d->mesh->normal_count());
284 if(d->data->size() >= 0.001 && d->mesh->edge_show() && (!d->mesh->face_show()))
288 #if (VTK_MAJOR_VERSION <= 5)
298 #if (VTK_MAJOR_VERSION <= 5)
308 if(d->data->size() >= 0.001 && d->mesh->edge_show() && (!d->mesh->face_show()))
311 #if (VTK_MAJOR_VERSION <= 5)
312 this->
getMapper()->SetInput(d->polyDataNormals->GetOutput());
314 this->
getMapper()->SetInputData(d->polyDataNormals->GetOutput());
321 #if (VTK_MAJOR_VERSION <= 5)
322 this->
getMapper()->SetInput(d->polyDataNormals->GetOutput());
324 this->
getMapper()->SetInputData(d->polyDataNormals->GetOutput());
354 if(!(mesh = dynamic_cast<axlMesh *>(d->data)) ){
362 dtkWarn() << Q_FUNC_INFO << t ;
363 converter->setData(d->data);
364 mesh = converter->
toMesh();
368 this->
getActor()->GetProperty()->SetInterpolationToGouraud();
375 d->data->setMesh(mesh);
380 dtkWarn()<<
"axlActorMesh vertices"<<d->mesh->vertex_count();
381 dtkWarn()<<
"axlActorMesh edges"<<d->mesh->edge_count();
382 dtkWarn()<<
"axlActorMesh faces"<<d->mesh->face_count();
385 this->
getPoints()->SetNumberOfPoints(d->mesh->vertex_count());
390 for (
int i = 0; i < d->mesh->vertex_count(); i++){
391 this->
getPoints()->SetPoint(i, d->mesh->vertex2(i, &pointCourant)->coordinates());
395 vtkSmartPointer<vtkCellArray> cellArray = this->
getCellArray();
396 vtkSmartPointer<vtkPolygon> currentPolygon = vtkSmartPointer<vtkPolygon>::New();
397 vtkSmartPointer<vtkLine> currentLine = vtkSmartPointer<vtkLine>::New();
398 vtkSmartPointer<vtkVertex> currentVertex = vtkSmartPointer<vtkVertex>::New();
399 vtkSmartPointer<vtkCellArray> cellArrayVertex = vtkSmartPointer<vtkCellArray>::New();
400 vtkSmartPointer<vtkDoubleArray> normals = vtkSmartPointer<vtkDoubleArray>::New();
403 bool isNormal = (d->mesh->normal_used() && d->mesh->vertex_count() == d->mesh->normal_count());
406 dtkWarn()<<
"axlActorMesh::normal 1 ";
407 normals->SetNumberOfComponents(3);
408 normals->SetNumberOfTuples(d->mesh->normal_count());
409 normals->SetName(
"normalArray");
413 for (
int i = 0; i < d->mesh->vertex_count(); i++)
415 currentVertex->GetPointIds()->SetId(0, i);
416 cellArrayVertex->InsertNextCell(currentVertex);
420 d->mesh->normal(i, currentNormal);
427 if(d->mesh->color_count() > 0)
429 vtkSmartPointer<vtkIntArray> scalarArray = vtkSmartPointer<vtkIntArray>::New();
430 scalarArray->SetName(
"mapperCollorArrayDefaultField");
431 scalarArray->SetNumberOfComponents(1);
432 scalarArray->SetNumberOfTuples(d->mesh->vertex_count());
434 vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
435 lookupTable->SetRange(0.0, d->mesh->vertex_count());
436 lookupTable->SetNumberOfTableValues(d->mesh->vertex_count());
438 for(
int i = 0; i < d->mesh->vertex_count(); i++)
440 scalarArray->SetTuple1(i, i);
441 lookupTable->SetTableValue(i , d->mesh->colorRF(i), d->mesh->colorGF(i), d->mesh->colorBF(i), 1.0);
443 this->
getPolyData()->GetPointData()->RemoveArray(scalarArray->GetName());
444 this->
getPolyData()->GetPointData()->AddArray(scalarArray);
445 this->
getPolyData()->GetPointData()->SetActiveScalars(
"mapperCollorArrayDefaultField");
447 this->
getMapper()->SelectColorArray(
"mapperCollorArrayDefaultField");
448 this->
getMapper()->SetLookupTable(lookupTable);
450 this->
getMapper()->UseLookupTableScalarRangeOn();
451 this->
getMapper()->SetScalarModeToUsePointData();
460 vtkSmartPointer<vtkCellArray> cellArrayLine = vtkSmartPointer<vtkCellArray>::New();
462 if(d->mesh->edge_show())
464 for(
int i = 0; i <d->mesh->edge_count(); i++)
468 for(
int j=0; j< currentEdge.size()-1;j++) {
469 currentLine->GetPointIds()->SetId(0 , currentEdge.at(j));
470 currentLine->GetPointIds()->SetId(1 , currentEdge.at(j+1));
471 cellArrayLine->InsertNextCell(currentLine);
478 if(d->mesh->face_show())
480 for(
int i = 0; i <d->mesh->face_count(); i++)
484 int sizeface = currentPoly.size();
485 currentPolygon->GetPointIds()->SetNumberOfIds(sizeface);
488 for(
int j = 0; j < sizeface; j++)
490 currentPolygon->GetPointIds()->SetId(j , currentPoly.at(j));
494 cellArray->InsertNextCell(currentPolygon);
505 if(d->mesh->vertex_show())
507 if(d->mesh->edge_show())
509 if(d->mesh->face_show())
515 this->
getPolyData()->GetPointData()->SetNormals(normals);
516 #if (VTK_MAJOR_VERSION <= 5)
522 if(d->data->size() >= 0.001 && d->mesh->edge_show() && (!d->mesh->face_show()))
526 #if (VTK_MAJOR_VERSION <= 5)
543 vtkSmartPointer<vtkCleanPolyData> cleanPolyData = vtkSmartPointer<vtkCleanPolyData>::New();
544 #if (VTK_MAJOR_VERSION <= 5)
546 d->polyDataNormals->SetInput(cleanPolyData->GetOutput());
547 this->
getMapper()->SetInput(d->polyDataNormals->GetOutput());
550 d->polyDataNormals->SetInputData(cleanPolyData->GetOutput());
551 this->
getMapper()->SetInputData(d->polyDataNormals->GetOutput());
554 #if (VTK_MAJOR_VERSION <= 5)
562 if(d->data->size() >= 0.001 && d->mesh->edge_show() && (!d->mesh->face_show()))
566 #if (VTK_MAJOR_VERSION <= 5)
577 if(!(d->mesh->fields().isEmpty())){
578 d->mesh->touchField();
716 d->polyDataNormals = vtkSmartPointer<vtkPolyDataNormals>::New();
717 d->polyDataNormals->AutoOrientNormalsOn();
727 disconnect(d->style, SIGNAL(IdsSelectedChanged()),
this,SLOT(onSelectionChanged()));
Class axlPoint defines 3D points.
vtkSmartPointer< vtkCellArray > getCellArray(void)
virtual void onUpdateGeometry()
double * coordinates(void) const
Returns coordinates of this point.
vtkCxxRevisionMacro(axlActorMesh,"$Revision: 0.0.1 $")
void computeNormals(void)
void stateChanged(dtkAbstractData *data, int mode)
virtual void setMode(int state)
vtkSmartPointer< vtkPolyData > getPolyData(void)
virtual void onTubeFilterRadiusChanged(double radius)
virtual void setState(int state)
QVector< int > Edge
An edge is represented by a sequence of vertices.
void setCellArray(vtkSmartPointer< vtkCellArray > cellArray)
vtkStandardNewMacro(axlActorMesh)
dtkAbstractData * data(void)
vtkSmartPointer< vtkPoints > getPoints(void)
QVector< int > Face
A face is a polygon represented by a loop of vertices.
void setData(dtkAbstractData *data)
virtual void setShader(QString vsfile)
void setPolyData(vtkSmartPointer< vtkPolyData > polyData)
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
virtual void onModeChanged(int state)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
axlAbstractActor * createAxlActorMesh(void)
virtual void onUpdateProperty(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
virtual void setSize(double size)
static axlActorMesh * New(void)
virtual axlMesh * toMesh(void)
Mesh conversion.
Class axlAbstractData defines an API for all type of axel data.
void setPoints(vtkSmartPointer< vtkPoints > points)
static dtkAbstractDataFactory * dataFactSingleton
Class axlMesh defines a piecewise-linear 3D object.