Developer documentation | Axl-2.5.1

axlShapeConverter.cpp
Go to the documentation of this file.
1 /* axlShapeConverter.cpp ---
2  *
3  * Author: Valentin Michelet
4  * Copyright (C) 2008-2011 - Valentin Michelet, Inria.
5  * Created: Tue Apr 30 11:03:18 2012 (+0100)
6  */
7 
8 /* Commentary:
9  *
10  */
11 
12 /* Change log:
13  *
14  */
15 
16 #include "axlMesh.h"
17 #include "axlShape.h"
18 #include "axlShapeConverter.h"
19 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
20 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
21 #include "axlPoint.h"
22 
23 #include <cmath>
24 
25 class axlShapeConverterPrivate {
26 public:
27  axlShape* data;
28 };
29 
30 axlShapeConverter::axlShapeConverter(void) : axlAbstractDataConverter(), d(new axlShapeConverterPrivate) {
31  d->data = NULL;
32 }
33 
35  delete d;
36  d = NULL;
37 }
38 
39 QString axlShapeConverter::description(void) const {
40  return "Converter from axlShape to axlMesh";
41 }
42 
44  return "axlShapeConverter";
45 }
46 
47 QStringList axlShapeConverter::fromTypes(void) const {
48  return QStringList() << "axlShapeConverter" << "axlShape";
49 }
50 
51 QString axlShapeConverter::toType (void) const {
52  return "axlMesh";
53 }
54 
56  return dtkAbstractDataFactory::instance()->registerDataConverterType("axlShapeConverter", QStringList(), "axlMesh", createaxlShapeConverter);
57 }
58 
60  //qDebug() << "#################################################";
61  if(!d->data)
62  return NULL;
63  //qDebug() << "#################################################";
64 
65  // Create mesh
66  axlMesh* mesh = new axlMesh;
67 
68  // Add every vertices to mesh
69  QVector<axlPoint*> vertices = d->data->getVertices();
70  for (int k = 0; k < d->data->getVertexCount(); k++) {
71  mesh->push_back_vertex(*vertices.at(k));
72  }
73 
74  dtkWarn() << "nb of edges" << d->data->getEdgeCount();
75 
76  // Add edges to mesh thanks to curve convector
77  QVector<axlShape::Edge*> allEdges = d->data->getEdges();
78  for (int k = 0; k < d->data->getEdgeCount(); k++) {
79  // Get current edge
80  axlShape::Edge currEdge = *allEdges.at(k);
81 
82  // Create current curve converter name
83  QString converterName = currEdge.curve->identifier()+"Converter";
84  dtkWarn() << currEdge.curve->identifier()+"Converter";
85  // Create current converter according to current curve
86  axlAbstractDataConverter* converter = dynamic_cast<axlAbstractDataConverter*>(dtkAbstractDataFactory::instance()->converter(converterName));
87 
88  // Complete current mesh from current converter
89  if (converter) {
90  converter->setData(currEdge.curve);
91  converter->setParams(0, currEdge.indexStartVertex);
92  converter->setParams(1, currEdge.indexEndVertex);
93  converter->setOutput(mesh);
94  if (!converter->toMesh()) {
95  dtkWarn() << "Mesh is NULL within converterName::toMesh";
96  }
97  } else
98  dtkWarn() << "No converter found for" << currEdge.curve->identifier();
99  }
100 
101  dtkWarn() << "nb of faces" << d->data->getFaceCount();
102 
103  // Add faces to mesh thanks to surface convector
104  QVector<axlShape::Face*> allFaces = d->data->getFaces();
105  for (int k = 0; k < d->data->getFaceCount(); k++) {
106  // Get current Face
107  axlShape::Face currFace = *allFaces.at(k);
108 
109  // Create current curve converter name
110  QString converterName = currFace.surface->identifier()+"Converter";
111  dtkWarn() << currFace.surface->identifier()+"Converter";
112  // Create current converter according to current curve
113  axlAbstractDataConverter* converter = dynamic_cast<axlAbstractDataConverter*>(dtkAbstractDataFactory::instance()->converter(converterName));
114 
115  // Complete current mesh from current converter for faces with no loop.
116  if (converter && currFace.loops.size()==1) {
117  converter->setData(currFace.surface);
118  converter->setOutput(mesh);
119  if (!converter->toMesh()) {
120  dtkWarn() << "Mesh is NULL within converterName::toMesh";
121  }
122  } else
123  dtkWarn() << "No converter found for face with " << currFace.surface->identifier();
124  }
125 
126 
127  mesh->vertex_show() = false;
128  mesh->normal_used() = false;
129  mesh->color_used() = false;
130  mesh->edge_show() = true;
131  mesh->face_show() = true;
132 
133  if(mesh){
134  dtkWarn() << Q_FUNC_INFO << "mesh is created with axlShapeConverter"
135  << "[" << mesh->vertex_count()<< mesh->edge_count()<< mesh->face_count() << "]";
136  }
137 
138  return mesh;
139 }
140 
141 void axlShapeConverter::setData(dtkAbstractData* data) {
142  if(axlShape* shape = dynamic_cast<axlShape*>(data))
143  d->data = shape;
144 }
145 
146 dtkAbstractDataConverter* createaxlShapeConverter(void) {
147  return new axlShapeConverter;
148 }
virtual ~axlShapeConverter(void)
int face_count(void) const
Definition: axlMesh.cpp:138
axlAbstractCurveParametric * curve
Pointer to the parametric curve supporting the edge, of type axlAbstractCurveParametric.
Definition: axlShape.h:49
QString description(void) const
virtual void setOutput(axlAbstractData *output)
The edge structure.
Definition: axlShape.h:41
bool vertex_show(void) const
Definition: axlMesh.cpp:159
int indexStartVertex
Index of the starting point of the edge in the array of vertices of the axlShape. ...
Definition: axlShape.h:43
axlMesh * toMesh(void)
virtual void setParams(int channel, int index)
The Face structure.
Definition: axlShape.h:76
bool normal_used(void) const
Definition: axlMesh.cpp:170
void setData(dtkAbstractData *data)
static bool registered(void)
QString toType(void) const
bool edge_show(void) const
Definition: axlMesh.cpp:190
int edge_count(void) const
Definition: axlMesh.cpp:143
int indexEndVertex
Index of the ending point of the edge in the array of vertices of the axlShape.
Definition: axlShape.h:46
axlAbstractSurfaceParametric * surface
Pointer to the supporting surface of type axlAbstractSurfaceParametric.
Definition: axlShape.h:81
QString identifier(void) const
bool face_show(void) const
Definition: axlMesh.cpp:200
QVector< Loop * > loops
Vector of all the loops defining the face.
Definition: axlShape.h:78
bool color_used(void) const
Definition: axlMesh.cpp:180
dtkAbstractDataConverter * createaxlShapeConverter(void)
QStringList fromTypes(void) const
virtual axlMesh * toMesh(void)
Mesh conversion.
int vertex_count(void) const
Definition: axlMesh.cpp:122
Class axlMesh defines a piecewise-linear 3D object.
Definition: axlMesh.h:41
void push_back_vertex(const double &x, const double &y, const double &z)
Add a new vertex to the mesh.
Definition: axlMesh.cpp:333