Developer documentation | Axl-2.5.1

axlVolumeDiscreteConverter.cpp
Go to the documentation of this file.
1 /* axlVolumeDiscreteConverter.cpp ---
2  *
3  * Author: Anais Ducoffe
4  * Copyright (C) 2013 - Anais Ducoffe, Inria.
5  */
6 
7 /* Commentary:
8  *
9  */
10 
11 /* Change log:
12  *
13  */
14 
16 #include "axlVolumeDiscrete.h"
17 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
18 #include <axlCore/axlMesh.h>
19 #include <axlCore/axlPoint.h>
20 
21 #include <vtkImageData.h>
22 #include <vtkIdList.h>
23 #include <vtkCell.h>
24 #include <vtkPoints.h>
25 
26 #include <algorithm>
27 #include <QVector>
28 
29 #include "axlVtkViewPlugin.h"
30 
31 //#namespace std
32 
33 // ///////////////////////////////////////////////////////////////////
34 // axlVolumeDiscreteConverterPrivate
35 // ///////////////////////////////////////////////////////////////////
36 
37 class axlVolumeDiscreteConverterPrivate
38 {
39 public:
40  axlVolumeDiscrete *data;
41 };
42 // ///////////////////////////////////////////////////////////////////
43 // axlVolumeDiscreteConverter implementation
44 // ///////////////////////////////////////////////////////////////////
45 
46 axlVolumeDiscreteConverter::axlVolumeDiscreteConverter(void) : axlAbstractDataConverter(), d(new axlVolumeDiscreteConverterPrivate)
47 {
48  d->data = NULL;
49 }
50 
52 {
53 
54  delete d;
55  d = NULL;
56 }
57 
59 {
60  return "axlVolumeDiscreteConverter";
61 }
62 
64 {
65  return "Converter from axlVolume to axlMesh";
66 }
67 
69 {
70  return QStringList() << "axlVolumeDiscreteConverter" << "axlVolume" ;
71 }
72 
74 {
75  return "axlMesh";
76 }
77 
79 {
80  return axlVtkViewPlugin::dataFactSingleton->registerDataConverterType("axlVolumeDiscreteConverter", QStringList(), "axlMesh", createaxlVolumeDiscreteConverter);
81 }
82 
84 {
85  if(!d->data)
86  return NULL;
87 
88  axlMesh *mesh = new axlMesh;
89  vtkImageData *grid = static_cast<vtkImageData *>(d->data->data());
90 
91  //grid points list
92  QVector<axlPoint *> listPoints;
93  int nbPoints = grid->GetNumberOfPoints();
94 
95  for(int i = 0; i <nbPoints;i++){
96  axlPoint *point = new axlPoint(grid->GetPoint(i));
97  listPoints << point;
98  }
99 
100  mesh->setVertices(listPoints);
101 
102 
103  QVector<int> listFaces;
104  QVector<int> listEdges;
105 
106  vtkCell *currentCell;
107  vtkCell *currentFace;
108  vtkCell *currentEdge;
109  vtkPoints *list;
110  int id= 0;
111  int points = 0;
112  int faces = 0;
113  int edges = 0;
114 
115  int first = 0;
116  int second = 0;
117  int third = 0;
118  int last = 0;
119 
120  int nbCells = grid->GetNumberOfCells();
121  for(int ic = 0 ; ic < nbCells ; ic++){
122  currentCell = grid->GetCell(ic);
123  faces = currentCell->GetNumberOfFaces();
124  edges = currentCell->GetNumberOfEdges();
125 
126  //fill faces for this cell
127  for(int jf= 0 ;jf < faces;jf++){
128  currentFace = currentCell->GetFace(jf);
129  list = currentFace->GetPoints();
130  points = list->GetNumberOfPoints();
131  if(!listFaces.empty()){
132  listFaces.clear();
133  }
134  for (int jp = 0; jp < points; jp ++){
135  id = currentFace->GetPointId(jp);
136  listFaces.append(id);
137  }
138  //order ids
139  std::vector<int> vectorFace = listFaces.toStdVector();
140  std::sort (vectorFace.begin(), vectorFace.end());
141  listFaces = QVector<int>::fromStdVector(vectorFace);
142  first = listFaces.first();
143  second = listFaces.at(1);
144  third = listFaces.at(2);
145  last = listFaces.last();
146 
147  mesh->push_back_face(first,second,third);
148  mesh->push_back_face(second,third,last);
149  }
150 
151  //fill edges for this cell
152  for(int je= 0 ;je < edges;je++){
153  currentEdge = currentCell->GetEdge(je);
154  list = currentEdge->GetPoints();
155  points = list->GetNumberOfPoints();
156  if(!listEdges.empty()){
157  listEdges.clear();
158  }
159  for (int jp = 0; jp < points; jp ++){
160  id = currentEdge->GetPointId(jp);
161  listEdges.append(id);
162  }
163  mesh->push_back_edge(listEdges.first(), listEdges.last());
164  }
165  }
166 
167  mesh->noDuplicateVertices();
168 
169  return mesh;
170 }
171 
172 void axlVolumeDiscreteConverter::setData(dtkAbstractData *data)
173 {
174  if(axlVolumeDiscrete *volData = dynamic_cast<axlVolumeDiscrete *>(data)){
175  d->data = volData;
176  }
177 }
178 
179 
180 
181 dtkAbstractDataConverter *createaxlVolumeDiscreteConverter(void){
182  return new axlVolumeDiscreteConverter;
183 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void noDuplicateVertices(void)
Remove duplicated vertices.
Definition: axlMesh.cpp:863
void setData(dtkAbstractData *data)
void push_back_edge(int, int)
Definition: axlMesh.cpp:669
void setVertices(const QVector< axlPoint * > &pointSet)
Definition: axlMesh.cpp:564
void push_back_face(const Face &face)
Definition: axlMesh.cpp:735
dtkAbstractDataConverter * createaxlVolumeDiscreteConverter(void)
static dtkAbstractDataFactory * dataFactSingleton
Class axlMesh defines a piecewise-linear 3D object.
Definition: axlMesh.h:41