Developer documentation | Axl-2.5.1

axlMesh.cpp
Go to the documentation of this file.
1 /* axlMesh.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Tue Nov 9 16:58:59 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Nov 9 17:09:38 2010 (+0100)
8  * By: Meriadeg Perrinel
9  * Update #: 19
10  */
11 
12 /* Comments:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlMesh.h"
21 #include "axlPoint.h"
22 
23 #include <dtkCoreSupport/dtkGlobal.h>
24 
25 // /////////////////////////////////////////////////////////////////
26 // axlMeshPrivate
27 // /////////////////////////////////////////////////////////////////
28 
29 class axlMeshPrivate
30 {
31 public:
32  int vertex_count;
33  int color_count;
34  int normal_count;
35  int face_count;
36  int edge_count;
37 
38  double epsilon;
39 
40  bool color_used;
41  bool color_rgb;
42  bool normal_used;
43 
44  bool vertex_show;
45  bool face_show;
46  bool edge_show;
47 
48  bool planar;
49 
50  QVector<double> vertices;
51  QVector<double> normals;
52  QVector<int> colors;
53  QVector<axlMesh::Edge> edges;
54  QVector<axlMesh::Face> faces;
55 
56  QVector<int> selectedVertices;
57 
58  axlMesh::Intepolation interpolation;
59 };
60 
61 // /////////////////////////////////////////////////////////////////
62 // axlMesh implementation
63 // /////////////////////////////////////////////////////////////////
64 
66 
70 axlMesh::axlMesh(void) : axlAbstractData(), d(new axlMeshPrivate)
71 {
72  this->setObjectName(this->identifier());
73 
74  d->vertex_count = 0;
75  d->color_count = 0;
76  d->normal_count = 0;
77  d->face_count = 0;
78  d->edge_count = 0;
79 
80  d->epsilon = 1.e-9;
81 
82  d->normal_used = false;
83  d->color_used = false;
84 
85  d->vertex_show = false;
86  d->face_show = true;
87  d->edge_show = false;
88 
89  d->planar = false;
90 
91  d->interpolation = FLAT;
92 }
93 
95 
99 {
100  delete d;
101  d = NULL;
102 }
103 
104 
105 //QVector<int> axlMesh::selectedVertices(void){
106 // return d->selectedVertices;
107 //}
108 
109 //void axlMesh::setSelectedVertices(QVector<int> selected){
110 
111 // qDebug() << Q_FUNC_INFO;
112 
113 // if(!d->selectedVertices.isEmpty())
114 // d->selectedVertices.clear();
115 
116 // d->selectedVertices = selected;
117 
118 // if(!d->selectedVertices.isEmpty())
119 // emit verticesSelected();
120 //}
121 
122 int axlMesh::vertex_count(void) const
123 {
124  return d->vertex_count;
125 }
126 
128 {
129  return d->color_count;
130 }
131 
132 int axlMesh::normal_count(void) const
133 {
134  return d->normal_count;
135 }
136 
137 
138 int axlMesh::face_count(void) const
139 {
140  return d->face_count;
141 }
142 
143 int axlMesh::edge_count(void) const
144 {
145  return d->edge_count;
146 }
147 
148 int axlMesh::all_edge_count(void) const {
149  int res = 0;
150 
151  for (int k = 0; k < d->edge_count; k++) {
152  res += d->edges.at(k).size() - 1;
153  }
154 
155  return res;
156 }
157 
158 
159 bool axlMesh::vertex_show(void) const
160 {
161  return d->vertex_show;
162 }
163 
165 {
166  return d->vertex_show;
167 }
168 
169 
170 bool axlMesh::normal_used(void) const
171 {
172  return d->normal_used;
173 }
174 
176 {
177  return d->normal_used;
178 }
179 
180 bool axlMesh::color_used(void) const
181 {
182  return d->color_used;
183 }
184 
186 {
187  return d->color_used;
188 }
189 
190 bool axlMesh::edge_show(void) const
191 {
192  return d->edge_show;
193 }
194 
196 {
197  return d->edge_show;
198 }
199 
200 bool axlMesh::face_show(void) const
201 {
202  return d->face_show;
203 }
204 
206 {
207  return d->face_show;
208 }
209 
210 bool axlMesh::isPlanar(void) const
211 {
212  return d->planar;
213 }
214 
215 bool& axlMesh::isPlanar(void)
216 {
217  return d->planar;
218 }
219 
220 int axlMesh::interpolation(void) const
221 {
222  return d->interpolation;
223 }
224 
225 void axlMesh::setInterpolation(int interpolation)
226 {
227  d->interpolation = (axlMesh::Intepolation)interpolation;
228 }
229 
231 
235  return axlPoint(d->vertices[3 * i], d->vertices[3 * i + 1], d->vertices[3 * i + 2]);
236 }
237 
239 
242 void axlMesh::vertex(int ind, axlPoint &point) const
243 {
244  point.setCoordinates(d->vertices[3 * ind], d->vertices[3 * ind + 1], d->vertices[3 * ind + 2]);
245 }
246 
248 
251 void axlMesh::vertex(int ind, axlPoint *point) const
252 {
253  point->setCoordinates(d->vertices[3 * ind], d->vertices[3 * ind + 1], d->vertices[3 * ind + 2]);
254 }
255 
257 
260 axlPoint *axlMesh::vertex2(int ind, axlPoint *point) const
261 {
262  point->setCoordinates(d->vertices[3 * ind], d->vertices[3 * ind + 1], d->vertices[3 * ind + 2]);
263  return point;
264 }
265 
266 QVector<double> axlMesh::vertexSet(void) const
267 {
268  return d->vertices;
269 }
270 
277 void axlMesh::setEpsilon(double epsilon)
278 {
279  d->epsilon = epsilon;
280 }
281 
286 double axlMesh::espilon(void)
287 {
288  return d->epsilon;
289 }
290 
292 
295 double axlMesh::vertexX(const int &ind) const
296 {
297  return d->vertices[3 * ind];
298 }
299 
301 
304 double axlMesh::vertexY(const int &ind) const
305 {
306  return d->vertices[3 * ind + 1];
307 }
308 
310 
313 double axlMesh::vertexZ(const int &ind) const
314 {
315  return d->vertices[3 * ind + 2];
316 }
317 
319 
322 void axlMesh::vertex(const int &ind, double vertex[3])
323 {
324  vertex[0] = d->vertices[3 * ind];
325  vertex[1] = d->vertices[3 * ind + 1];
326  vertex[2] = d->vertices[3 * ind + 2];
327 }
328 
330 
333 void axlMesh::push_back_vertex(const double &x, const double &y, const double &z)
334 {
335  d->vertex_count++;
336  d->vertices.push_back(x);
337  d->vertices.push_back(y);
338  d->vertices.push_back(z);
339 }
340 
342 
346 void axlMesh::push_back_vertex(const double vertex[])
347 {
348  d->vertex_count++;
349  d->vertices.push_back(vertex[0]);
350  d->vertices.push_back(vertex[1]);
351  d->vertices.push_back(vertex[2]);
352 }
353 
355 
360 {
361  d->vertex_count++;
362  d->vertices.push_back(vertex.x());
363  d->vertices.push_back(vertex.y());
364  d->vertices.push_back(vertex.z());
365 }
366 
368 
373 {
374  d->vertex_count++;
375  //dtkWarn()<<"mesh"<<vertex->x()<< vertex->y()<<vertex->y();
376  d->vertices.push_back(vertex->x());
377  d->vertices.push_back(vertex->y());
378  d->vertices.push_back(vertex->z());
379 }
380 
387 void axlMesh::set_vertex(axlPoint* point, const int &ind)
388 {
389  if(ind < 0 )
390  {
391  dtkError()<< "axlMesh : specified index must be positive integer !";
392  }
393  else
394  if(ind > d->vertex_count-1 )
395  {
396  dtkError()<< "axlMesh : specified index out of mesh !";
397  }
398  else
399  {
400  d->vertices.replace(3*ind,point->x());
401  d->vertices.replace(3*ind+1,point->y());
402  d->vertices.replace(3*ind+2,point->z());
403  }
404 }
405 
406 
408 
411 double axlMesh::normalX(const int &ind) const
412 {
413  return d->normals[3 * ind];
414 }
415 
417 
420 double axlMesh::normalY(const int &ind) const
421 {
422  return d->normals[3 * ind + 1];
423 }
424 
426 
429 double axlMesh::normalZ(const int &ind) const
430 {
431  return d->normals[3 * ind + 2];
432 }
433 
435 
438 void axlMesh::normal(const int &ind, double normal[3])
439 {
440  normal[0] = d->normals[3 * ind];
441  normal[1] = d->normals[3 * ind + 1];
442  normal[2] = d->normals[3 * ind + 2];
443 }
444 
445 
447 
450 void axlMesh::push_back_normal(const double &x, const double &y, const double &z)
451 {
452  d->normal_count++;
453  d->normals.push_back(x);
454  d->normals.push_back(y);
455  d->normals.push_back(z);
456 }
457 
459 
462 void axlMesh::push_back_normal(const double normal[3])
463 {
464  d->normal_count++;
465  d->normals.push_back(normal[0]);
466  d->normals.push_back(normal[1]);
467  d->normals.push_back(normal[2]);
468 }
469 
471 
474 int axlMesh::colorR(const int &ind)
475 {
476  return d->colors[3 * ind];
477 }
478 
480 
483 double axlMesh::colorRF(const int &ind)
484 {
485  return d->colors[3 * ind] / 255.0 ;
486 }
487 
489 
492 int axlMesh::colorG(const int &ind)
493 {
494  return d->colors[3 * ind + 1];
495 }
496 
498 
501 double axlMesh::colorGF(const int &ind)
502 {
503  return d->colors[3 * ind + 1] / 255.0 ;
504 }
505 
506 
508 
511 int axlMesh::colorB(const int &ind)
512 {
513  return d->colors[3 * ind + 2];
514 }
515 
517 
520 double axlMesh::colorBF(const int &ind)
521 {
522  return d->colors[3 * ind + 2] / 255.0 ;
523 }
524 
525 
527 
530 void axlMesh::getColor(const int &ind, int color[3])
531 {
532  color[0] = d->colors[3 * ind];
533  color[1] = d->colors[3 * ind + 1];
534  color[2] = d->colors[3 * ind + 2];
535 }
536 
538 
542 void axlMesh::push_back_color(const int &r, const int &g, const int &b)
543 {
544  d->color_count++;
545  d->colors.push_back(r);
546  d->colors.push_back(g);
547  d->colors.push_back(b);
548 }
549 
551 
555 void axlMesh::push_back_color(const int color[3])
556 {
557  d->color_count++;
558  d->colors.push_back(color[0]);
559  d->colors.push_back(color[1]);
560  d->colors.push_back(color[2]);
561 }
562 
563 
564 void axlMesh::setVertices(const QVector<axlPoint *> &pointSet)
565 {
566  // if(d->vertex_count > 0)
567  // qDebug()<< " this axlMesh instance already have one vertex at less. This method cannot be use now. See push_back_vertex";
568  // else
569  // {
570  for (int i = 0 ; i < pointSet.size() ; i++)
571  {
572  this->push_back_vertex(pointSet.value(i));
573 
574  }
575  // }
576 
577 }
578 
580 
583 void axlMesh::normal(int ind, axlPoint& normal)
584 {
585  normal.setCoordinates(d->normals[3 * ind], d->normals[3 * ind + 1], d->normals[3 * ind + 2]);
586 }
587 
589 
592 void axlMesh::normal(int ind, axlPoint *normal)
593 {
594  normal->setCoordinates(d->normals[3 * ind], d->normals[3 * ind + 1], d->normals[3 * ind + 2]);
595 }
596 
598 
602 {
603  normal->setCoordinates(d->normals[3 * ind], d->normals[3 * ind + 1], d->normals[3 * ind + 2]);
604  return normal;
605 }
606 
607 QVector<double> axlMesh::normalSet(void)
608 {
609  return d->normals;
610 }
611 
612 
614 {
615  d->normal_count++;
616  d->normals.push_back(normal->x());
617  d->normals.push_back(normal->y());
618  d->normals.push_back(normal->z());
619 }
620 
621 void axlMesh::setNormals(const QList<axlPoint*>& pointSet)
622 {
623  if(d->normal_count > 0)
624  qDebug()<< " this axlMesh instance already have one vertex at less, This method cannot be use now. See push_back_vertex";
625  else
626  {
627  for (int i = 0 ; i < pointSet.size() ; i++)
628  {
629  this->push_back_normal(pointSet.value(i));
630  }
631  }
632 
633 }
634 
636  d->normals.clear();
637  d->normal_count = 0;
638 }
639 
641 {
642  return d->edges.at(ind);
643 }
644 
645 QVector< axlMesh::Edge > axlMesh::edgeSet(void) const
646 {
647  return d->edges;
648 }
649 
650 
652 
655 int axlMesh::edgePointIndex(int i, int j) const{
656  return d->edges.at(i).at(j);
657 }
658 
659 
661 
664 int axlMesh::edgePointCount(int i) const{
665  return d->edges.at(i).size();
666 }
667 
668 
669 void axlMesh::push_back_edge(int i1, int i2)
670 {
671  d->edge_count++;
672  Edge e; e<<i1 <<i2;
673  d->edges.push_back(e);
674 }
675 
677 
681 {
682  d->edge_count++;
683  d->edges.push_back(e);
684 }
685 
687 
691 {
692  d->edge_count++;
693  Edge e;
694  d->edges.push_back(e);
695 
696  return d->edge_count-1;
697 }
698 
699 
701 
704 void axlMesh::edgePushBack(int i, int j)
705 {
706  d->edges[i]<<j;
707 }
708 
710 {
711  return d->faces.at(ind);
712 }
713 
714 QVector< axlMesh::Face > axlMesh::faceSet(void) const
715 {
716  return d->faces;
717 }
718 
720 
723 int axlMesh::facePointIndex(int i, int j) const{
724  return d->faces.at(i).at(j);
725 }
726 
728 
731 int axlMesh::facePointCount(int i) const{
732  return d->faces.at(i).size();
733 }
734 
735 void axlMesh::push_back_face(const Face &face)
736 {
737  d->face_count++;
738  d->faces.push_back(face);
739 }
740 
741 void axlMesh::push_back_face(int i1, int i2, int i3)
742 {
743  Face face; face<<i1<<i2<<i3;
744  d->face_count++;
745  d->faces.push_back(face);
746 }
747 
749 
758 const QVector<double> axlMesh::boundingBoxVertex() const
759 {
760  QVector<double> bbox;
761  bbox.reserve(6);
762  bbox[0] = d->vertices[0];
763  bbox[1] = d->vertices[0];
764  bbox[2] = d->vertices[1];
765  bbox[3] = d->vertices[1];
766  bbox[4] = d->vertices[2];
767  bbox[5] = d->vertices[2];
768 
769  for(int i = 1 ; i < vertex_count(); i++)
770  {
771  if(bbox[0] > d->vertices[3 * i])
772  bbox[0] = d->vertices[3 * i];
773 
774  if(bbox[1] < d->vertices[3 * i])
775  bbox[1] = d->vertices[3 * i];
776 
777  if(bbox[2] > d->vertices[3 * i + 1])
778  bbox[2] = d->vertices[3 * i + 1];
779 
780  if(bbox[3] < d->vertices[3 * i + 1])
781  bbox[3] = d->vertices[3 * i + 1];
782 
783  if(bbox[4] > d->vertices[3 * i + 2])
784  bbox[4] = d->vertices[3 * i + 2];
785 
786  if(bbox[5] < d->vertices[3 * i + 2])
787  bbox[5] = d->vertices[3 * i + 2];
788  }
789 
790  return bbox;
791 }
792 
793 
795 
799 {
800  QVector<double> bbox = this->boundingBoxVertex();
801  double scale = bbox[1]- bbox[0];
802  if(scale < bbox[3] - bbox[2])
803  scale = bbox[3] - bbox[2];
804 
805  if(scale < bbox[5] - bbox[4])
806  scale = bbox[5] - bbox[4];
807 
808  return scale;
809 }
810 
811 
812 
813 
815 {
816  for (int i = 0 ; i < mesh->face_count() ; i++)
817  {
818  Face currentList = mesh->face(i);
819  for (int j = 0 ; j < currentList.size() ; j ++)
820  currentList.replace(j, currentList.at(j) + this->vertex_count());
821 
822  this->push_back_face(currentList);
823  }
824 
825  for (int i = 0 ; i < mesh->edge_count() ; i++)
826  {
827  Edge currentEdge = mesh->edge(i);
828  Edge newEdge;
829  for (int j = 0; j< currentEdge.size(); j++)
830  newEdge << (currentEdge.at(j) + this->vertex_count());
831  this->push_back_edge(newEdge);
832  }
833 
834 
835  for (int i = 0 ; i < mesh->vertex_count() ; i++)
836  {
837  axlPoint currentPoint;
838  mesh->vertex(i, &currentPoint);
839  this->push_back_vertex(&currentPoint);
840  }
841 
842  for (int i = 0 ; i < mesh->normal_count() ; i++)
843  {
844  axlPoint currentNormal;
845  mesh->normal(i, &currentNormal);
846  this->push_back_normal(&currentNormal);
847  }
848 
849  //d->edge_count += mesh->edge_count();
850 }
851 
864 {
865  QVector<int> verticesFirstIndexes;
866 
867  axlPoint p1;
868  axlPoint p2;
869  QVector<int> idx(d->vertex_count,0);
870 
871  int vertexUnique_count=0;
872 
873  for(int i = 0 ; i < d->vertex_count ; i++)
874  {
875  int j = 0;
876  bool not_found = true;
877  this->vertex(i, &p1);
878 
879  while(j < i && not_found)
880  {
881  this->vertex(j, &p2);
882  if(axlPoint::distance(p1, p2) < d->epsilon) {
883  not_found = false;
884  idx[i]=j;
885  }
886  j++;
887  }
888 
889  if(not_found)
890  {
891  idx[i]=i;
892  vertexUnique_count ++;
893  verticesFirstIndexes << i;
894  }
895 
896  }//assossiation are done
897 
898  //update edge indexes
899  if(vertexUnique_count< d->vertex_count) {
900 
901  QVector<double> new_vertices;
902 
903  for(int k=0; k< verticesFirstIndexes.size();k++)
904  new_vertices << this->vertexX(verticesFirstIndexes.at(k))
905  << this->vertexY(verticesFirstIndexes.at(k))
906  << this->vertexZ(verticesFirstIndexes.at(k));
907 
908  d->vertices = new_vertices;
909 
910 
911  if(d->vertex_count==d->normal_count) {
912  QVector<double> new_normals;
913  for(int k=0; k < verticesFirstIndexes.size();k++)
914  new_normals << this->normalX(verticesFirstIndexes.at(k))
915  << this->normalY(verticesFirstIndexes.at(k))
916  << this->normalZ(verticesFirstIndexes.at(k));
917 
918  d->normals = new_normals;
919  d->normal_count = new_normals.size()/3;
920  }
921 
922  if(d->vertex_count==d->color_count) {
923  QVector<int> new_colors;
924  for(int k=0; k< verticesFirstIndexes.size();k++)
925  new_colors << this->colorR(verticesFirstIndexes.at(k))
926  << this->colorG(verticesFirstIndexes.at(k))
927  << this->colorB(verticesFirstIndexes.at(k));
928 
929  d->colors = new_colors;
930  d->color_count = new_colors.size()/3;
931  }
932 
933  d->vertex_count = new_vertices.size()/3;
934 
935  QVector<Edge> new_edges;
936  int j1;
937  for(int i = 0 ; i < d->edge_count ; i++)
938  {
939  Edge newEdge;
940  for(int j=0;j<d->edges.at(i).size(); j++) {
941  j1 = idx[d->edges.at(i).at(j)];
942  if(j == 0 || (j1 != idx[d->edges.at(i).at(j-1)]))
943  newEdge<< j1;
944  }
945 
946  if(newEdge.size()>1)
947  new_edges << newEdge;
948  }
949 
950  d->edges = new_edges;
951  d->edge_count = new_edges.size();
952 
953  QVector<Face> new_faces;
954  for(int i = 0 ; i < d->face_count ; i++)
955  {
956  QVector<int> face;
957  for(int j = 0 ; j < d->faces.at(i).size() ; j ++) {
958  j1 = idx[d->faces.at(i)[j]];
959  if(!face.contains(j1))
960  face<< j1;
961  }
962  if(face.size()>2)
963  new_faces << face;
964  }
965  d->faces = new_faces;
966  d->face_count = new_faces.size();
967  }
968  //qDebug()<<"vertex"<<d->vertex_count;
969 }
970 
972 
975 double axlMesh::distance(int ind1, int ind2)
976 {
977  if(ind1 >= d->vertex_count || ind2 >= d->vertex_count)
978  return -1.0;
979 
980  return sqrt((d->vertices[3 * ind1]- d->vertices[3 * ind2]) * (d->vertices[3 * ind1]- d->vertices[3 * ind2]) + (d->vertices[3 * ind1 + 1]- d->vertices[3 * ind2 + 1]) * (d->vertices[3 * ind1 + 1]- d->vertices[3 * ind2 + 1]) + (d->vertices[3 * ind1 + 2]- d->vertices[3 * ind2 + 2]) * (d->vertices[3 * ind1 + 2]- d->vertices[3 * ind2 + 2]));
981 }
982 
983 
984 
985 QString axlMesh::description(void) const
986 {
987  QString result = "axlMesh";
988  result.append("\nVertex count : "+QString::number(d->vertex_count));
989  result.append("\nNormal count : "+QString::number(d->normal_count));
990  result.append("\nEdge count : "+QString::number(d->edge_count));
991  result.append("\nFace count : "+QString::number(d->face_count));
992  result.append("\nVertex show : "+QString::number(d->vertex_show));
993  result.append("\nNormal use : "+QString::number(d->normal_used));
994  result.append("\nEdge show : "+QString::number(d->edge_show));
995  result.append("\nFace show : "+QString::number(d->face_show));
996  return result;
997 
998 }
999 
1000 QString axlMesh::identifier(void) const
1001 {
1002  return "axlMesh";
1003 }
1004 
1006 
1009 QVector<QSet<int> > axlMesh::neighborsFace(const axlMesh &mesh)
1010 {
1011  QVector<QSet<int> > result(mesh.vertex_count());
1012 
1013  for(int i = 0 ; i < mesh.face_count(); i++)
1014  {
1015  // each face contains at least three vertices
1016  // two particular case
1017  int vfirst = mesh.face(i).first();
1018  int vatone = mesh.face(i).at(1);
1019  int vatlastminusone = mesh.face(i).at(mesh.face(i).count() -2);
1020  int vlast = mesh.face(i).last();
1021 
1022  if(vfirst != vatone)
1023  result[vfirst] << vatone;
1024 
1025  if(vfirst != vlast)
1026  result[vfirst] << vlast;
1027 
1028  if(vlast != vfirst)
1029  result[vlast] << vfirst;
1030 
1031  if(vlast != vatlastminusone)
1032  result[vlast] << vatlastminusone;
1033 
1034  // result[vlast]<< vfirst << vatlastminusone;
1035 
1036  //generic case
1037  for (int j = 1 ; j < mesh.face(i).count() -1; j++)
1038  {
1039  vfirst = mesh.face(i).at(j-1);
1040  vatone = mesh.face(i).at(j);
1041  vlast = mesh.face(i).at(j+1);
1042 
1043  if(vatone != vfirst)
1044  result[vatone] << vfirst;
1045 
1046  if(vatone != vlast)
1047  result[vatone] << vlast;
1048  // result[mesh.face(i).at(j)]<< mesh.face(i).at(j-1) << mesh.face(i).at(j+1);
1049 
1050  }
1051 
1052 
1053  }
1054 
1055  return result;
1056 }
1057 
1058 
1060 
1063 QVector<QSet<int> > axlMesh::VertexTofaceIndexes(const axlMesh &mesh)
1064 {
1065  QVector<QSet<int> > result(mesh.vertex_count());
1066 
1067  for(int i = 0 ; i < mesh.face_count(); i++)
1068  {
1069  // each face contains at least three vertices
1070  // two particular case
1071 
1072  result[mesh.face(i).first()] << i;
1073  result[mesh.face(i).last()] << i;
1074 
1075 
1076  // result[vlast]<< vfirst << vatlastminusone;
1077 
1078  //generic case
1079  for (int j = 1 ; j < mesh.face(i).count() -1; j++)
1080  result[mesh.face(i).at(j)] << i;
1081 
1082  }
1083 
1084  return result;
1085 
1086 }
1087 
1088 
1089 QVariantList axlMesh::convertDataToQVariant(void) const{
1090  QVariantList list;
1091  QVariant id = QVariant::fromValue(identifier());
1092  QVariant vertexCount = QVariant::fromValue(d->vertex_count);
1093  QVariant colorCount = QVariant::fromValue(d->color_count);
1094  QVariant normalCount = QVariant::fromValue(d->normal_count);
1095  QVariant faceCount = QVariant::fromValue(d->face_count);
1096  QVariant edgeCount = QVariant::fromValue(d->edge_count);
1097  QVariant epsilon = QVariant::fromValue(d->epsilon);
1098  QVariant colorUsed = QVariant::fromValue(d->color_used);
1099  QVariant colorRgb = QVariant::fromValue(d->color_rgb);
1100  QVariant normalUsed = QVariant::fromValue(d->normal_used);
1101  QVariant vertexShow = QVariant::fromValue(d->vertex_show);
1102  QVariant faceShow = QVariant::fromValue(d->face_show);
1103  QVariant edgeShow = QVariant::fromValue(d->edge_show);
1104  QVariant planar = QVariant::fromValue(d->planar);
1105 
1106 
1107 
1108  list.append(id);
1109  list.append(vertexCount);
1110  list.append(colorCount);
1111  list.append(normalCount);
1112  list.append(faceCount);
1113  list.append(edgeCount);
1114  list.append(epsilon);
1115  list.append(colorUsed);
1116  list.append(colorRgb);
1117  list.append(normalUsed);
1118  list.append(vertexShow);
1119  list.append(faceShow);
1120  list.append(edgeShow);
1121  list.append(planar);
1122 
1123  //add vertices
1124  for(int i = 0; i< d->vertex_count;i++){
1125  list.append(vertexX(i));
1126  list.append(vertexY(i));
1127  list.append(vertexZ(i));
1128  }
1129 
1130  //add normals
1131  for(int i = 0; i< d->normal_count;i++){
1132  list.append(normalX(i));
1133  list.append(normalY(i));
1134  list.append(normalZ(i));
1135  }
1136 
1137  //add color
1138  // for(int i = 0; i< d->color_count;i++){
1139  // list.append(col);
1140  // }
1141 
1142  //add edges
1143  for(int i = 0; i< d->edge_count;i++){
1144  list.append(edgePointCount(i));
1145  for(int j =0;j < edgePointCount(i); j++){
1146  list.append(edge(i).at(j));
1147  }
1148  }
1149 
1150  //add faces
1151  for(int i = 0; i< d->face_count;i++){
1152  list.append(facePointCount(i));
1153  for(int j = 0;j < facePointCount(i);j++){
1154  list.append(face(i).at(j));
1155  }
1156  }
1157 
1158  QVariant name = QVariant::fromValue(objectName());
1159  list.append(name);
1160 
1161  return list;
1162 
1163 }
1164 
1165 int axlMesh::convertQVariantToData(const QVariantList &data){
1166 
1167  // d->vertex_count = data.at(1).toInt();
1168  // d->color_count = data.at(2).toInt();
1169  // d->normal_count = data.at(3).toInt();
1170  // d->face_count = data.at(4).toInt();
1171  // d->edge_count = data.at(5).toInt();
1172  d->epsilon = data.at(6).toDouble();
1173  d->color_used = data.at(7).toBool();
1174  d->color_rgb = data.at(8).toBool();
1175  d->normal_used = data.at(9).toBool();
1176  d->vertex_show = data.at(10).toBool();
1177  d->face_show = data.at(11).toBool();
1178  d->edge_show = data.at(12).toBool();
1179  d->planar = data.at(13).toBool();
1180 
1181 
1182  int newBegin = 14;
1183  //fill vertices
1184  for(int i = 0; i< data.at(1).toInt();i++){
1185  double x = data.at(3*i+newBegin).toDouble() ;
1186  double y = data.at(3*i+1+newBegin).toDouble();
1187  double z = data.at(3*i+2+newBegin).toDouble();
1188  push_back_vertex(x,y,z);
1189  }
1190  newBegin = (3*d->vertex_count)+newBegin;
1191 
1192  if(!d->normals.isEmpty()){
1193  //fill normals
1194  for(int i = 0; i< d->normal_count;i++){
1195  double x = data.at(3*i+newBegin).toDouble() ;
1196  double y = data.at(3*i+1+newBegin).toDouble();
1197  double z = data.at(3*i+2+newBegin).toDouble();
1198  push_back_normal(x,y,z);
1199  }
1200 
1201  newBegin = (3*d->normal_count) + newBegin;
1202  }
1203 
1204  //fill color
1205  // for(int i = 0; i< d->color_count;i++){
1206  // list.append(col);
1207  // }
1208 
1209  //fill edges
1210  for(int i = 0; i< data.at(5).toInt();i++){
1211  int indiceEdge = newBegin+i;
1212  int nb = data.at(indiceEdge).toInt();
1213  push_back_edge(data.at(indiceEdge+1).toInt(), data.at(indiceEdge+2).toInt());
1214  newBegin = newBegin+nb;
1215  }
1216 
1217  newBegin = newBegin+ d->edge_count;
1218 
1219  //fill faces
1220  for(int i = 0; i< data.at(4).toInt();i++){
1221  int indiceEdge = newBegin+i;
1222  int nb = data.at(indiceEdge).toInt();
1223  Face f;
1224  for(int j=1;j <= nb;j++){
1225  f.append(data.at(indiceEdge+j).toInt());
1226  }
1227  push_back_face(f);
1228  newBegin = newBegin+nb;
1229 
1230  }
1231  setObjectName(data.last().toString());
1232  return 1;
1233 
1234 
1235 }
1236 
1237 //to be registered to the data factory.
1238 dtkAbstractData *createaxlMesh(void)
1239 {
1240  return new axlMesh;
1241 }
1242 
1243 
1244 // /////////////////////////////////////////////////////////////////
1245 // axlMesh documentation
1246 // /////////////////////////////////////////////////////////////////
1247 
axlMesh(void)
Construct an axlMesh.
Definition: axlMesh.cpp:70
const QVector< double > boundingBoxVertex(void) const
Return the bounding box vector of the mesh.
Definition: axlMesh.cpp:758
int facePointIndex(int i, int j) const
Returns the index of the j-th point of the i-th face of the mesh.
Definition: axlMesh.cpp:723
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
virtual QString description(void) const
Definition: axlMesh.cpp:985
double vertexZ(const int &ind) const
return Z coordinates of vertex with index ind.
Definition: axlMesh.cpp:313
int face_count(void) const
Definition: axlMesh.cpp:138
void clearNormals(void)
Definition: axlMesh.cpp:635
void noDuplicateVertices(void)
Remove duplicated vertices.
Definition: axlMesh.cpp:863
QVector< Edge > edgeSet(void) const
Definition: axlMesh.cpp:645
void edgePushBack(int, int)
Add to the edge i the index j.
Definition: axlMesh.cpp:704
bool vertex_show(void) const
Definition: axlMesh.cpp:159
void push_back_edge(int, int)
Definition: axlMesh.cpp:669
int facePointCount(int i) const
Returns the number of vertex of a mesh face.
Definition: axlMesh.cpp:731
void getColor(const int &ind, int color[3])
Set color values of colors with index ind.
Definition: axlMesh.cpp:530
void setNormals(const QList< axlPoint * > &pointSet)
Definition: axlMesh.cpp:621
int colorG(const int &ind)
return int Green component of color with index ind.
Definition: axlMesh.cpp:492
axlPoint * normal2(int ind, axlPoint *normal)
Set normal values of vertices with index ind and return it.
Definition: axlMesh.cpp:601
dtkAbstractData * createaxlMesh(void)
Definition: axlMesh.cpp:1238
double normalY(const int &ind) const
return Y coordinates of normal with index ind.
Definition: axlMesh.cpp:420
bool normal_used(void) const
Definition: axlMesh.cpp:170
double colorGF(const int &ind)
Return double Green component of color with index ind.
Definition: axlMesh.cpp:501
QVector< int > Edge
An edge is represented by a sequence of vertices.
Definition: axlMesh.h:55
axlPoint operator[](int i)
Return the i th vertex of the mesh.
Definition: axlMesh.cpp:234
int edgePointIndex(int i, int j) const
Returns the index of the j-th point of the i-th edge of the mesh.
Definition: axlMesh.cpp:655
double colorBF(const int &ind)
Return double Blue component of color with index ind.
Definition: axlMesh.cpp:520
void append(axlMesh *mesh)
Definition: axlMesh.cpp:814
void normal(const int &ind, double normal[3])
set normal values of normals with index ind.
Definition: axlMesh.cpp:438
void setEpsilon(double epsilon)
Set the precision parameter for point comparison.
Definition: axlMesh.cpp:277
bool edge_show(void) const
Definition: axlMesh.cpp:190
double distance(int ind1, int ind2)
Compute the distance in the 3d space between two points of indices ind1 and ind2. ...
Definition: axlMesh.cpp:975
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
Definition: axlMesh.cpp:1165
bool isPlanar(void) const
Definition: axlMesh.cpp:210
virtual QString identifier(void) const
Definition: axlMesh.cpp:1000
static QVector< QSet< int > > VertexTofaceIndexes(const axlMesh &mesh)
Construct Faces Indexes Table. of all points of the mesh.
Definition: axlMesh.cpp:1063
double normalX(const int &ind) const
return X coordinates of normal with index ind.
Definition: axlMesh.cpp:411
void push_back_color(const int &r, const int &g, const int &b)
Add color to the mesh.
Definition: axlMesh.cpp:542
QVector< int > Face
A face is a polygon represented by a loop of vertices.
Definition: axlMesh.h:58
int edge_count(void) const
Definition: axlMesh.cpp:143
void vertex(const int &ind, double vertex[3])
set vertex values of vertices with index ind.
Definition: axlMesh.cpp:322
double normalZ(const int &ind) const
return Z coordinates of normal with index ind.
Definition: axlMesh.cpp:429
QVariantList convertDataToQVariant(void) const
Convert an axlAbstractData into a QVariantList that specifies all properties of the axlAbstractData...
Definition: axlMesh.cpp:1089
double vertexY(const int &ind) const
return Y coordinates of vertex with index ind.
Definition: axlMesh.cpp:304
void set_vertex(axlPoint *point, const int &ind)
Function to set a vertex.
Definition: axlMesh.cpp:387
int edgePointCount(int i) const
Return the number of point contained in the i-th edge of the mesh.
Definition: axlMesh.cpp:664
int interpolation(void) const
Definition: axlMesh.cpp:220
int colorR(const int &ind)
return int Red component of color with index ind.
Definition: axlMesh.cpp:474
int all_edge_count(void) const
Definition: axlMesh.cpp:148
QVector< double > vertexSet(void) const
Definition: axlMesh.cpp:266
Intepolation
Definition: axlMesh.h:45
bool face_show(void) const
Definition: axlMesh.cpp:200
int normal_count(void) const
Definition: axlMesh.cpp:132
double y
Definition: axlPoint.h:37
void setVertices(const QVector< axlPoint * > &pointSet)
Definition: axlMesh.cpp:564
int push_back_new_edge(void)
Add an empty edge to the mesh.
Definition: axlMesh.cpp:690
axlPoint * vertex2(int ind, axlPoint *point) const
Set vertex values of vertices with index ind and return it.
Definition: axlMesh.cpp:260
void push_back_face(const Face &face)
Definition: axlMesh.cpp:735
bool color_used(void) const
Definition: axlMesh.cpp:180
double espilon(void)
Return the parameter used to identify points.
Definition: axlMesh.cpp:286
double z
Definition: axlPoint.h:38
int colorB(const int &ind)
Return int Blue component of color with index ind.
Definition: axlMesh.cpp:511
double meshVertexScaleFactor() const
Return a scale factor based on the distance max founded with the bounding box.
Definition: axlMesh.cpp:798
int color_count(void) const
Definition: axlMesh.cpp:127
double colorRF(const int &ind)
return double Red component of color with index ind.
Definition: axlMesh.cpp:483
QVector< double > normalSet(void)
Definition: axlMesh.cpp:607
double vertexX(const int &ind) const
Return X coordinates of vertex with index ind.
Definition: axlMesh.cpp:295
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.
Definition: axlPoint.cpp:459
void push_back_normal(axlPoint *normal)
Definition: axlMesh.cpp:613
void setInterpolation(int interpolation)
Definition: axlMesh.cpp:225
double x
Definition: axlPoint.h:37
void setCoordinates(double x, double y, double z)
Change coordinates of this point.
Definition: axlPoint.cpp:370
static QVector< QSet< int > > neighborsFace(const axlMesh &mesh)
Construct neighbors of all points of the mesh.
Definition: axlMesh.cpp:1009
int vertex_count(void) const
Definition: axlMesh.cpp:122
Face face(int ind) const
Definition: axlMesh.cpp:709
~axlMesh(void)
Destroy the axlMesh.
Definition: axlMesh.cpp:98
QVector< Face > faceSet(void) const
Definition: axlMesh.cpp:714
Class axlAbstractData defines an API for all type of axel data.
Edge edge(int ind) const
Definition: axlMesh.cpp:640
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