Developer documentation | Axl-2.5.1

axlPointSetReader.cpp
Go to the documentation of this file.
1 /* axlPointSetReader.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008-2011 - Meriadeg Perrinel, Inria.
5  * Created: Wed Sep 21 11:36:52 2011 (+0200)
6  * Version: $Id$
7  * Last-Updated: Wed Sep 21 12:11:29 2011 (+0200)
8  * By: Meriadeg Perrinel
9  * Update #: 88
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlPointSetReader.h"
21 
22 #include <axlCore/axlPointSet.h>
23 
24 #include <dtkCoreSupport/dtkAbstractData.h>
25 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
26 
27 // /////////////////////////////////////////////////////////////////
28 // axlPointSetReader
29 // /////////////////////////////////////////////////////////////////
30 
32 {
33  this->setObjectName(this->description());
34 }
35 
37 {
38 
39 }
40 
41 QString axlPointSetReader::identifier(void) const
42 {
43  return "axlPointSetReader";
44 }
45 
46 QString axlPointSetReader::description(void) const
47 {
48  return "axlPointSetReader";
49 }
50 
51 QStringList axlPointSetReader::handled(void) const
52 {
53  return QStringList() << "axlPointSet";
54 }
55 
57 {
58  return dtkAbstractDataFactory::instance()->registerDataReaderType("axlPointSetReader", QStringList(), createaxlPointSetReader);
59 }
60 
61 bool axlPointSetReader::accept(const QDomNode& node)
62 {
63  QDomElement element = node.toElement();
64 
65  if(element.tagName() != "pointset")
66  return false;
67 
68  if(!hasChildNode(element, "numberofpoints"))
69  return false;
70 
71  if(!hasChildNode(element, "points"))
72  return false;
73 
74  return true;
75 }
76 
77 bool axlPointSetReader::reject(const QDomNode& node)
78 {
79  return !this->accept(node);
80 }
81 
82 dtkAbstractData *axlPointSetReader::read(const QDomNode& node)
83 {
84  QDomElement element = node.toElement();
85 
86  bool colors = false ;
87  axlPointSet *currentPointSet = new axlPointSet;
88 
89  QString name = element.attribute("name");
90  if(!name.isEmpty())
91  {
92  currentPointSet->setObjectName(name);
93  }
94 
95  QString color = element.attribute("color");
96 
97  if(!color.isEmpty())
98  {
99  if(color == "rgb") //mean each point of the point Set have a specific color
100  {
101  currentPointSet->setUniqueColor(false);
102  colors = true;
103  }
104  else //mean the axlPointSet has one unique color
105  {
106  QStringList colorList = color.split(" ");
107  if(colorList.size() > 2) // rgb components
108  currentPointSet->setColor(QColor(colorList.at(0).toInt(), colorList.at(1).toInt(), colorList.at(2).toInt()));
109  if(colorList.size() == 4)
110  currentPointSet->setOpacity(colorList.at(3).toFloat());
111  }
112  }
113 
114  QString shader = element.attribute("shader");
115  QString dirShader;
116  if(!shader.isEmpty())
117  {
118  // try to read from axelShader.qrc
119  dirShader = ":axlShader/shader/"+shader;
120  if(!QFile::exists(dirShader))
121  {
122  QSettings settings("inria", "dtk");
123  QString defaultPath;
124  settings.beginGroup("shader");
125  dirShader = settings.value("path", defaultPath).toString();
126 // dirShader = this->file().left(this->file().lastIndexOf("axel-data") + 9); // to Remove later
127  dirShader.append("/"+shader);
128  }
129  currentPointSet->setShader(dirShader);
130  }
131 
132  QString size = element.attribute("size");
133  if(!size.isEmpty())
134  currentPointSet->setSize(size.toFloat());
135 
136  //Coordinates
137  QDomNodeList nodelistcoordinates = element.elementsByTagName("points") ;
138  QDomElement elementCoordinates = nodelistcoordinates.item(0).toElement() ;
139 
140  QStringList coordinates = elementCoordinates.text().simplified().split(QRegExp("\\s+"));
141  if(colors) {
142 
143  for(int i=0 ; i<coordinates.size() ; i+=6) {
144  float x = coordinates[i+0].toFloat();
145  float y = coordinates[i+1].toFloat();
146  float z = coordinates[i+2].toFloat();
147  int r = coordinates[i+3].toInt();
148  int g = coordinates[i+4].toInt();
149  int b = coordinates[i+5].toInt();
150  axlPoint *currentPoint = new axlPoint(x, y, z);
151  currentPoint->setColor(QColor(r, g, b));
152  currentPointSet->push_back(currentPoint);
153  }
154 
155  } else {
156 
157  for(int i=0 ; i<coordinates.size() ; i+=3) {
158  float x = coordinates[i+0].toFloat() ;
159  float y = coordinates[i+1].toFloat() ;
160  float z = coordinates[i+2].toFloat() ;
161  currentPointSet->push_back(new axlPoint(x, y, z));
162  }
163  }
164 
165  return currentPointSet;
166 }
167 
168 dtkAbstractDataReader *createaxlPointSetReader(void)
169 {
170  return new axlPointSetReader;
171 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void setShader(const QString &shader)
void setUniqueColor(const bool uniqueColor)
Definition: axlPointSet.cpp:80
dtkAbstractDataReader * createaxlPointSetReader(void)
void push_back(axlPoint *p)
Definition: axlPointSet.cpp:98
QStringList handled(void) const
QString identifier(void) const
bool accept(const QDomNode &node)
bool hasChildNode(QDomElement element, const QString &tag)
Definition: axlFormat.h:20
QString description(void) const
void setOpacity(const double &opacity)
dtkAbstractData * read(const QDomNode &node)
void setSize(const double &size)
void setColor(double r, double g, double b)
static bool registered(void)
bool reject(const QDomNode &node)