Developer documentation | Axl-2.5.1

axlShape.cpp
Go to the documentation of this file.
1 /* axlShape.h ---
2  *
3  * Author: Valentin Michelet
4  * Copyright (C) 2008-2013 - Valentin Michelet, Inria.
5  * Created: Wed Mar 20 03:47:23 2013 (+0100)
6  * Version: $Id$
7  */
8 
9 /* Commentary:
10  *
11  */
12 
13 /* Change log:
14  *
15  */
16 
17 #include "axlShape.h"
18 
19 #include "axlPoint.h"
22 
23 #include <dtkCoreSupport/dtkGlobal.h>
24 
25 
26 // /////////////////////////////////////////////////////////////////
27 // axlShapePrivate
28 // /////////////////////////////////////////////////////////////////
29 
30 class axlShapePrivate {
31 public:
32  int vertexCount;
33  int edgeCount;
34  int faceCount;
35 
36  QVector<axlPoint*> vertices;
37  QVector<axlShape::Edge*> edges;
38  QVector<axlShape::Face*> faces;
39 };
40 
41 // /////////////////////////////////////////////////////////////////
42 // axlShape implementation
43 // /////////////////////////////////////////////////////////////////
44 
45 axlShape::axlShape(int vertexCount, int edgeCount, int faceCount, axlShape *parent) :
46  axlAbstractData(parent),
47  d(new axlShapePrivate) {
48 
49  d->vertexCount = vertexCount;
50  d->edgeCount = edgeCount;
51  d->faceCount = faceCount;
52 
53  d->vertices = QVector<axlPoint*>(vertexCount, NULL);
54  d->edges = QVector<Edge*>(edgeCount, NULL);
55  d->faces = QVector<Face*>(faceCount, NULL);
56 
57  this->setObjectName(this->identifier());
58 }
59 
61  delete d;
62  d = NULL;
63 }
64 
65 QVector<axlPoint*> axlShape::getVertices(void) const {
66  return d->vertices;
67 }
68 
69 QVector<axlShape::Edge*> axlShape::getEdges(void) const {
70  return d->edges;
71 }
72 
73 QVector<axlShape::Face*> axlShape::getFaces(void) const {
74  return d->faces;
75 }
76 
77 int axlShape::getVertexCount(void) const {
78  return d->vertexCount;
79 }
80 
81 int axlShape::getEdgeCount(void) const {
82  return d->edgeCount;
83 }
84 
85 int axlShape::getFaceCount(void) const {
86  return d->faceCount;
87 }
88 
89 QString axlShape::description(void) const {
90  QString desc = "axlShape:\n";
91  desc += " #Vertices: " + QString::number(d->vertexCount) + "\n";
92  desc += " #Edges: " + QString::number(d->edgeCount) + "\n";
93  desc += " #Faces: " + QString::number(d->faceCount) + "\n\n";
94 
95  for (int k = 0; k < d->faceCount; k++) {
96 
97  int nbLoops = d->faces.at(k)->loops.size();
98  desc += "\nFace\t#" + QString::number(k) + ":\t" + QString::number(nbLoops) + " loop(s)\n";
99  for (int i = 0; i < nbLoops; i++) {
100  int nbEdges = d->faces.at(k)->loops.at(i)->edges.size();
101  desc += " Loop\t#" + QString::number(i) + ":\t" + QString::number(nbEdges) + " edge(s)\n";
102  for (int j = 0; j < nbEdges; j++) {
103  int currIndexEdge = d->faces.at(k)->loops.at(i)->edges.at(j);
104  if (currIndexEdge > -1 && currIndexEdge < d->edges.size()) {
105  axlShape::Edge* edge = d->edges.at(currIndexEdge);
106  if (edge) {
107  axlAbstractCurveParametric* currCurve = edge->curve;
108  if (currCurve) {
109  desc += " Edge\t#" + QString::number(j) + ":\t(" + currCurve->identifier() + ")\n";
110  } else
111  desc += " Edge\t#" + QString::number(j) + ":\tcurve NULL\n";
112  } else {
113  desc += " Edge\t#" + QString::number(j) + ":\tNULL\n";
114  }
115  } else {
116  desc += " Index of Edge out of range:" + QString::number(currIndexEdge) + "\n";
117  }
118  }
119  }
120  axlAbstractSurfaceParametric* currSurf = d->faces.at(k)->surface;
121  if (currSurf)
122  desc += " Surface\t:" + currSurf->identifier() + "\n";
123  else
124  desc += " Surface is NULL\n";
125  }
126 
127  return desc;
128 }
129 
130 QString axlShape::identifier(void) const {
131  return "axlShape";
132 }
133 
134 void axlShape::insert_vertex(axlPoint* vertex, int index) {
135  d->vertices.replace(index, vertex);
136 }
137 
138 void axlShape::insert_edge(Edge* edge, int index) {
139  d->edges.replace(index, edge);
140 }
141 
142 void axlShape::insert_edge(axlAbstractCurveParametric* crv, int si, int ei, int index) {
143  axlShape::Edge *edge = new axlShape::Edge(crv, si, ei);
144  d->edges.replace(index, edge);
145 }
146 
148  // Vector to store edges and orientation after sort
149  QVector<int> edgesSorted;
150  QVector<bool> orientationsSorted;
151 
152  // Get edges and orientation to sort
153  QVector<int> edges = loop->edges;
154  QVector<bool> orientations = loop->orientations;
155 
156  // First edge index and orientation variables
157  int fstEdgeIndex;
158  bool fstOrientation;
159 
160  // Browse every edges
161  for (int k = 0; k < edges.size()-1; k++) {
162  // Choose the first edge to start
163  if (k == 0) {
164  // Get first edge index and first orientation
165  fstEdgeIndex = edges.at(k);
166  fstOrientation = orientations.at(k);
167  // Record first edge index and orientation inside sorted vectors
168  edgesSorted << fstEdgeIndex;
169  orientationsSorted << fstOrientation;
170  }
171 
172  // Get real current first edge from index
173  Edge* fstEdge = d->edges.at(fstEdgeIndex);
174 
175  // Record current first index into p1, depending on orientation boolean value
176  int p1;
177  if (fstOrientation)
178  p1 = fstEdge->indexStartVertex;
179  else
180  p1 = fstEdge->indexEndVertex;
181 
182  // Second edge index and orientation variables
183  int sndEdgeIndex;
184  bool sndOrientation;
185 
186  // Browse every other edges, looking for second edge, according to orientation and current first edge
187  for (int i = 1; i <= edges.size(); i++) {
188  // Current index, modulo number of edge indices
189  int currIndex = (k+i)%edges.size();
190  // Current edge index among other ones
191  sndEdgeIndex = edges.at(currIndex);
192 
193  // Get real current second edge from index
194  Edge* sndEdge = d->edges.at(sndEdgeIndex);
195  // Get corresponding second orientation
196  sndOrientation = orientations.at(currIndex);
197 
198 
199  // Record current second index into p2, depending on orientation boolean value
200  int p2;
201  if (sndOrientation)
202  p2 = sndEdge->indexEndVertex;
203  else
204  p2 = sndEdge->indexStartVertex;
205 
206  // If p1 equals to p2, then the current second edge is the current first edge following one
207  if (p1 == p2) {
208 
209  // Record second edge index and orientation inside sorted vectors
210  edgesSorted << sndEdgeIndex;
211  orientationsSorted << sndOrientation;
212  // current first edge index and first orientation become the second ones for the next loop turn
213  fstEdgeIndex = sndEdgeIndex;
214  fstOrientation = sndOrientation;
215 
216  // No need to look for other edges
217  break;
218 
219  // If p1 does not equal to p2, and we already tested every other ones, then we got a situation
220  } else if (i == edges.size()) {
221  dtkError() << "Error within void axlShape::sortEdges";
222  return;
223  }
224  }
225  }
226 
227  // Replace old vectors by sorted vectors
228  loop->edges = edgesSorted;
229  loop->orientations = orientationsSorted;
230 }
231 
233  for (int k = 0; k < face->loops.size(); k++) {
234  sortEdges(face->loops.at(k));
235  }
236 }
237 
238 void axlShape::insert_face(axlAbstractSurfaceParametric*surf, int *l, int *orient,int *loopsSize, int sizel,int nbLoops, int index) {
239  axlShape::Face *face = new axlShape::Face;
240  QVector<axlShape::Loop *> loops;
241  face->surface = surf;
242  for(int k = 0;k < nbLoops;k++){
243  loops << new axlShape::Loop;
244  for(int i=0;i < loopsSize[k];i++){
245  if(k==0){
246  loops.at(k)->edges << l[i];
247  loops.at(k)->orientations << orient[i];
248  }else{
249  loops.at(k)->edges << l[i+loopsSize[k-1]];
250  loops.at(k)->orientations << orient[i+loopsSize[k-1]];
251  }
252  }
253  }
254  face->loops << loops;
255  sortLoops(face);
256  d->faces.replace(index, face);
257 }
258 
259 void axlShape::insert_face_with_no_sort(axlAbstractSurfaceParametric*surf, int *l, int *orient,int *loopsSize, int sizel,int nbLoops, int index) {
260  axlShape::Face *face = new axlShape::Face;
261  QVector<axlShape::Loop *> loops;
262  face->surface = surf;
263  for(int k = 0;k < nbLoops;k++){
264  loops << new axlShape::Loop;
265  for(int i=0;i < loopsSize[k];i++){
266  if(k==0){
267  loops.at(k)->edges << l[i];
268  loops.at(k)->orientations << orient[i];
269  }else{
270  loops.at(k)->edges << l[i+loopsSize[k-1]];
271  loops.at(k)->orientations << orient[i+loopsSize[k-1]];
272  }
273  }
274  }
275  face->loops << loops;
276  d->faces.replace(index, face);
277 }
278 
279 void axlShape::insert_face(axlAbstractSurfaceParametric*surf, int *l, int *orient, int sizel,int sizeOrient, int index){
280  axlShape::Face *face = new axlShape::Face;
281  face->surface = surf;
282  axlShape::Loop *loop = new axlShape::Loop;
283  for(int i=0;i < sizel;i++){
284  loop->edges << l[i];
285  }
286  for(int j=0;j < sizeOrient;j++){
287  loop->orientations << orient[j];
288  }
289  face->loops << loop;
290  sortLoops(face);
291  d->faces.replace(index, face);
292 }
293 
294 void axlShape::insert_face_with_no_sort(axlAbstractSurfaceParametric*surf, int *l, int *orient, int sizel,int sizeOrient, int index){
295  axlShape::Face *face = new axlShape::Face;
296  face->surface = surf;
297  axlShape::Loop *loop = new axlShape::Loop;
298  for(int i=0;i < sizel;i++){
299  loop->edges << l[i];
300  }
301  for(int j=0;j < sizeOrient;j++){
302  loop->orientations << orient[j];
303  }
304  face->loops << loop;
305  d->faces.replace(index, face);
306 }
307 
308 void axlShape::insert_face(Face* face, int index) {
309  sortLoops(face);
310  d->faces.replace(index, face);
311 }
312 
313 
314 QVariantList axlShape::convertDataToQVariant(void) const{
315  QVariantList list;
316  QVariant id = QVariant::fromValue(identifier());
317  QVariant vertexCount = QVariant::fromValue(d->vertexCount);
318  QVariant faceCount = QVariant::fromValue(d->faceCount);
319  QVariant edgeCount = QVariant::fromValue(d->edgeCount);
320 
321 
322 
323  list.append(id);
324  list.append(vertexCount);
325  list.append(faceCount);
326  list.append(edgeCount);
327 
328  //add vertices
329  for(int i = 0; i< d->vertexCount;i++){
330  list.append(d->vertices.at(i)->convertDataToQVariant());
331  }
332 
333  //add edges
334  for(int i = 0; i< d->edgeCount;i++){
335  //list.append(d->edges.at(i));
336  }
337 
338  //add faces
339  for(int i = 0; i< d->faceCount;i++){
340  //list.append(d->faces.at(i));
341  }
342 
343  QVariant name = QVariant::fromValue(objectName());
344  list.append(name);
345  return list;
346 
347 }
348 
349 int axlShape::convertQVariantToData(const QVariantList &data){
350 
351  // d->vertex_count = data.at(1).toInt();
352  // d->face_count = data.at(2).toInt();
353  // d->edge_count = data.at(3).toInt();
354 
355  int newBegin = 4;
356  //fill vertices
357  for(int i = 0; i< data.at(1).toInt();i++){
358  //first index is for the identifier
359  double x = data.at(4*i+1+newBegin).toDouble() ;
360  double y = data.at(4*i+2+newBegin).toDouble();
361  double z = data.at(4*i+3+newBegin).toDouble();
362  axlPoint *point = new axlPoint(x,y,z);
363  insert_vertex(point,i);
364  delete point;
365  }
366  //A point is defined with four variables, its three coordinates table and its identifier
367  newBegin = (4*d->vertexCount)+newBegin;
368 
369 
370  // //fill edges
371  // for(int i = 0; i< data.at(2).toInt();i++){
372  // int indiceEdge = newBegin+i;
373  // newBegin = newBegin+3;
374  // }
375 
376  // newBegin = newBegin+ d->edgeCount;
377 
378  // //fill faces
379  // for(int i = 0; i< data.at(3).toInt();i++){
380  // int indiceEdge = newBegin+i;
381  // int nb = data.at(indiceEdge).toInt();
382  // Face f;
383  // for(int j=1;j <= nb;j++){
384  // qDebug() << Q_FUNC_INFO << indiceEdge <<data.at(indiceEdge+j).toInt() ;
385  // f.append(data.at(indiceEdge+j).toInt());
386  // }
387  // push_back_face(f);
388  // newBegin = newBegin+nb;
389 
390  // }
391 
392  setObjectName(data.last().toString());
393 
394  return 1;
395 
396 
397 }
398 
400 //dtkAbstractData *createaxlShape(void)
401 //{
402 // return new axlShape;
403 //}
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
axlAbstractCurveParametric * curve
Pointer to the parametric curve supporting the edge, of type axlAbstractCurveParametric.
Definition: axlShape.h:49
The edge structure.
Definition: axlShape.h:41
virtual QString identifier(void) const
Definition: axlShape.cpp:130
int indexStartVertex
Index of the starting point of the edge in the array of vertices of the axlShape. ...
Definition: axlShape.h:43
axlShape(int vertexCount, int edgeCount, int faceCount, axlShape *parent=0)
Definition: axlShape.cpp:45
virtual ~axlShape(void)
Definition: axlShape.cpp:60
QVector< int > edges
Vector of indices of the edges of the loop in the array of edges of the axlShape. ...
Definition: axlShape.h:64
QVector< Face * > getFaces(void) const
Definition: axlShape.cpp:73
The Face structure.
Definition: axlShape.h:76
virtual QString description(void) const
Definition: axlShape.cpp:89
void sortLoops(Face *face)
Sort loops.
Definition: axlShape.cpp:232
QVector< Edge * > getEdges(void) const
Definition: axlShape.cpp:69
int getFaceCount(void) const
Definition: axlShape.cpp:85
int getEdgeCount(void) const
Definition: axlShape.cpp:81
The Loop structure.
Definition: axlShape.h:62
void insert_face(Face *face, int index)
Definition: axlShape.cpp:308
int getVertexCount(void) const
Definition: axlShape.cpp:77
void insert_edge(Edge *edge, int index)
Definition: axlShape.cpp:138
Generic interface for parametric curve.
void sortEdges(Loop *loop)
Sort edges.
Definition: axlShape.cpp:147
QVariantList convertDataToQVariant(void) const
Definition: axlShape.cpp:314
int indexEndVertex
Index of the ending point of the edge in the array of vertices of the axlShape.
Definition: axlShape.h:46
void insert_face_with_no_sort(axlAbstractSurfaceParametric *surf, int *l, int *orient, int sizel, int sizeOrient, int index)
Definition: axlShape.cpp:294
QVector< bool > orientations
Vector of booleans of the same size as edges: true means the direct orientation, false is the reverse...
Definition: axlShape.h:67
axlAbstractSurfaceParametric * surface
Pointer to the supporting surface of type axlAbstractSurfaceParametric.
Definition: axlShape.h:81
int convertQVariantToData(const QVariantList &data)
Definition: axlShape.cpp:349
QVector< Loop * > loops
Vector of all the loops defining the face.
Definition: axlShape.h:78
void insert_vertex(axlPoint *vertex, int index)
Definition: axlShape.cpp:134
QVector< axlPoint * > getVertices(void) const
Definition: axlShape.cpp:65
Class axlAbstractData defines an API for all type of axel data.