27 #include <dtkCoreSupport/dtkAbstractData.h>
28 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
48 return "axlMeshReader";
53 return "axlMeshReader";
58 return QStringList() <<
"axlMesh";
63 return dtkAbstractDataFactory::instance()->registerDataReaderType(
"axlMeshReader", QStringList(),
createaxlMeshReader);
68 QDomElement element = node.toElement();
70 if(element.tagName() !=
"mesh")
88 return !this->
accept(node);
93 QDomElement element = node.toElement();
98 QString name = element.attribute(
"name");
101 mesh->setObjectName(name);
104 QString color = element.attribute(
"color");
107 QStringList colorList = color.split(
" ");
108 if(colorList.size() > 2)
109 mesh->
setColor(QColor(colorList.at(0).toInt(), colorList.at(1).toInt(), colorList.at(2).toInt()));
110 if(colorList.size() > 3)
115 QString shader = element.attribute(
"shader");
117 if(!shader.isEmpty())
120 dirShader =
":axlShader/shader/"+shader;
121 if(!QFile::exists(dirShader))
123 QSettings settings(
"inria",
"dtk");
125 settings.beginGroup(
"shader");
126 dirShader = settings.value(
"path", defaultPath).toString();
128 dirShader.append(
"/"+shader);
134 QString size = element.attribute(
"size");
140 QDomNodeList nodelist_count = element.elementsByTagName(
"count") ;
141 QDomElement count = nodelist_count.item(0).toElement();
142 QString *text_count =
new QString(count.text());
143 QTextStream in(text_count);
172 QDomNodeList nodelist_points = element.elementsByTagName(
"points") ;
173 QDomElement points = nodelist_points.item(0).toElement();
175 QString *text_points =
new QString(points.text());
176 QTextStream in_points(text_points);
178 QString color = points.attribute(
"color");
182 for(
int i = 0 ; i < vertexCount ; i++)
184 in_points.skipWhiteSpace();
186 in_points.skipWhiteSpace();
188 in_points.skipWhiteSpace();
193 in_points.skipWhiteSpace();
195 in_points.skipWhiteSpace();
197 in_points.skipWhiteSpace();
208 QDomNodeList nodelist_colors = element.elementsByTagName(
"colors") ;
209 QString *text_colors;
210 if(nodelist_colors.size()>0 && !mesh->
color_used()) {
211 text_colors =
new QString(nodelist_colors.item(0).toElement().text());
213 QTextStream in_colors(text_colors);
215 for(
int i = 0 ; i < vertexCount ; i++)
217 in_colors.skipWhiteSpace();
219 in_colors.skipWhiteSpace();
221 in_colors.skipWhiteSpace();
230 QDomNodeList nodelist_normals = element.elementsByTagName(
"normals") ;
231 if(nodelist_normals.size()>0) {
232 QString *text_normals =
new QString(nodelist_normals.item(0).toElement().text());
233 QTextStream in_normals(text_normals);
237 for(
int i = 0 ; i < vertexCount ; i++)
239 in_normals.skipWhiteSpace();
241 in_normals.skipWhiteSpace();
243 in_normals.skipWhiteSpace();
370 QDomNodeList nodeListField = element.elementsByTagName(
"field");
371 if(!nodeListField.isEmpty()){
372 for(
int i =0; i < nodeListField.size(); i++){
373 QDomElement fieldElement = nodeListField.at(i).toElement();
374 QString fieldType = fieldElement.attribute(
"type");
375 if(!fieldType.isEmpty()){
382 fieldToAdd->setObjectName(newName);
386 qDebug() << Q_FUNC_INFO <<
"no reader available";
395 QDomNodeList nodelist_edges = element.elementsByTagName(
"edges") ;
396 if (nodelist_edges.size()==0) {
397 dtkWarn() <<
"Error in mesh format: no edge but edgeCount>0";
401 QString *text_edges =
new QString(nodelist_edges.item(0).toElement().text());
402 QTextStream in_edges(text_edges);
405 for(
int i = 0 ; i < edgeCount ; i++)
407 in_edges.skipWhiteSpace();
411 for(
int j=0; j< l0; j++) {
412 in_edges.skipWhiteSpace();
425 QDomNodeList nodelist_faces = element.elementsByTagName(
"faces") ;
426 if (nodelist_faces.size()==0) {
427 dtkWarn() <<
"Error in mesh format: no face but faceCount>0";
431 QString *text_faces =
new QString(nodelist_faces.item(0).toElement().text());
432 QTextStream in_faces(text_faces);
434 QVector<int> currentFace;
435 int currentFaceSize = 0;
436 int currentFaceIndex = 0;
437 for(
int i = 0 ; i < faceCount ; i++)
440 in_faces.skipWhiteSpace();
441 in_faces >> currentFaceSize;
444 for(
int j = 0 ; j < currentFaceSize ; j++)
446 in_faces.skipWhiteSpace();
447 in_faces >> currentFaceIndex;
448 currentFace << currentFaceIndex;
450 in_faces.readLine(75);
int face_count(void) const
axlAbstractData * read(const QDomNode &node)
bool vertex_show(void) const
void push_back_edge(int, int)
QStringList handled(void) const
void setShader(const QString &shader)
bool normal_used(void) const
QVector< int > Edge
An edge is represented by a sequence of vertices.
QString changeFieldName(QString fieldName)
bool reject(const QDomNode &node)
bool accept(const QDomNode &node)
dtkAbstractDataReader * create(const QString &interface_name)
bool edge_show(void) const
QString description(void) const
void push_back_color(const int &r, const int &g, const int &b)
Add color to the mesh.
int edge_count(void) const
virtual axlAbstractData * read(const QDomNode &node)=0
Class axlAbstractField defines an API for arrays of numeric data.
bool face_show(void) const
bool hasChildNode(QDomElement element, const QString &tag)
void push_back_face(const Face &face)
void setOpacity(const double &opacity)
bool color_used(void) const
static bool registered(void)
static axlFieldReadersFactory * instance(void)
void addField(axlAbstractField *field)
Add a field to the field list of the object.
void setSize(const double &size)
void setColor(double r, double g, double b)
void push_back_normal(axlPoint *normal)
int vertex_count(void) const
Class axlAbstractData defines an API for all type of axel data.
QString identifier(void) const
Class axlMesh defines a piecewise-linear 3D object.
dtkAbstractDataReader * createaxlMeshReader(void)
void push_back_vertex(const double &x, const double &y, const double &z)
Add a new vertex to the mesh.