Developer documentation | Axl-2.5.1

axlShapeBSplineWriter.cpp
Go to the documentation of this file.
1 /* axlShapeBSplineWriter.cpp ---
2  *
3  * Author: Anais Ducoffe
4  * Copyright (C) 2014 - Anais Ducoffe, Inria.
5  */
6 
7 /* Commentary:
8  *
9  */
10 
11 /* Change log:
12  *
13  */
14 
15 #include "axlShapeBSplineWriter.h"
16 
19 
20 #include <dtkCoreSupport/dtkAbstractData.h>
21 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
23 
24 // /////////////////////////////////////////////////////////////////
25 // axlShapeBSplineWriter
26 // /////////////////////////////////////////////////////////////////
27 
29 {
30  this->setObjectName(this->description());
31 }
32 
34 {
35 
36 }
37 
39 {
40  return "axlShapeBSplineWriter";
41 }
42 
44 {
45  return "axlShapeBSplineWriter";
46 }
47 
48 QStringList axlShapeBSplineWriter::handled(void) const
49 {
50  return QStringList() << "axlShapeBSpline";
51 }
52 
54 {
55  return dtkAbstractDataFactory::instance()->registerDataWriterType("axlShapeBSplineWriter", QStringList(), createaxlShapeBSplineWriter);
56 }
57 
58 bool axlShapeBSplineWriter::accept(dtkAbstractData *data)
59 {
60  axlShapeBSpline *surf = dynamic_cast<axlShapeBSpline *>(data);
61  if(surf){
62  if(surf->identifier() == "axlShapeBSpline"){
63  return true;
64  }else {
65  return false;
66  }
67  }
68  return false;
69 }
70 
71 bool axlShapeBSplineWriter::reject(dtkAbstractData *data)
72 {
73  return !this->accept(data);
74 }
75 
76 QDomElement axlShapeBSplineWriter::write(QDomDocument *doc, dtkAbstractData *data)
77 {
78  axlShapeBSpline* surf = dynamic_cast<axlShapeBSpline*>(data);
79 
81  QDomElement surfElement = doc->createElement("surface");
82  surfElement.setAttribute("name", surf->name());
83 
85  surfElement.setAttribute("type", "patch");
86 
88  surfElement.setAttribute("size", QString::number(surf->size()));
89 
91  QColor qcolor = surf->color();
92  QString color ;
93  QTextStream(&color) << QString::number(qcolor.red()) << " "
94  << QString::number(qcolor.green()) << " "
95  << QString::number(qcolor.blue()) << " "
96  << QString::number(surf->opacity());
97  surfElement.setAttribute("color", color);
98 
100  QString shader = surf->shader();
101  QFileInfo shaderFileInfo(shader);
102  surfElement.setAttribute("shader", shaderFileInfo.fileName());
103 
104  // Write surf
105  surfElement.setAttribute("nb_points", surf->countControlPoints());
106  surfElement.setAttribute("nb_edges", surf->countBoundaryEdges());
107  surfElement.setAttribute("nb_faces", surf->countFaces());
108  surfElement.setAttribute("orderu", surf->order_u());
109  surfElement.setAttribute("orderv", surf->order_v());
110 
111  // Vertices
112  QDomElement verticesElement = doc->createElement("points");
113  for (int k = 1; k <= surf->countControlPoints(); k++) {
114  QString coordsString = QString::number(surf->getCoef(k).x()) + " "
115  + QString::number(surf->getCoef(k).y()) + " "
116  + QString::number(surf->getCoef(k).z()) + "\n\t";
117  QDomText coordsDomText = doc->createTextNode(coordsString);
118  verticesElement.appendChild(coordsDomText);
119  }
120  surfElement.appendChild(verticesElement);
121 
122  // Edges
123  QDomElement edgesElement = doc->createElement("edges");
124  for (int k = 0; k < surf->countBoundaryEdges(); k++) {
125  QDomElement edgeElement = doc->createElement("edge");
126  edgeElement.setAttribute("id", k);
127 
128  axlShapeBSpline::Edge* currEdge = surf->getEdge(k);
129 
130  QDomElement controlP = doc->createElement("controlPoints");
131  for (int j = 0; j < currEdge->controlPointsIndices.size(); j++) {
132  QString coordsString = QString::number(currEdge->controlPointsIndices.at(j)) + " ";
133  QDomText coordsDomText = doc->createTextNode(coordsString);
134  controlP.appendChild(coordsDomText);
135  }
136 
137  edgeElement.appendChild(controlP);
138  edgeElement.setAttribute("tag", currEdge->tag);
139  edgesElement.appendChild(edgeElement);
140  }
141 
142  surfElement.appendChild(edgesElement);
143 
144  // Faces
145  QDomElement facesElement = doc->createElement("faces");
146  for (int k = 0; k < surf->countFaces(); k++) {
147  QDomElement faceElement = doc->createElement("face");
148  faceElement.setAttribute("id", k);
149 
150  axlShapeBSpline::Face* currFace =surf->getFace(k);
151 
152  QDomElement controlP = doc->createElement("controlPoints");
153  for (int j = 0; j < currFace->controlPointsIndices.size(); j++) {
154  QString coordsString = QString::number(currFace->controlPointsIndices.at(j)) + " ";
155  QDomText coordsDomText = doc->createTextNode(coordsString);
156  controlP.appendChild(coordsDomText);
157  }
158 
159  QDomElement edgeInd = doc->createElement("nbpts");
160 
161  QString coordsString = QString::number(currFace->nbpts_u) + " " + QString::number(currFace->nbpts_v);
162  QDomText coordsDomText = doc->createTextNode(coordsString);
163  edgeInd.appendChild(coordsDomText);
164 
165 
166  faceElement.appendChild(controlP);
167  faceElement.appendChild(edgeInd);
168  facesElement.appendChild(faceElement);
169  }
170  surfElement.appendChild(facesElement);
171 
172  return surfElement;
173 }
174 
175 
176 QDomElement axlShapeBSplineWriter::elementByWriter(axlAbstractDataWriter *axl_writer, QDomDocument *doc, dtkAbstractData *data)
177 {
178  QDomElement element;
179 
180  if(!axl_writer)
181  return element;
182 
183  if(!axl_writer->accept(data))
184  return element;
185 
186  element = axl_writer->write(doc, data);
187 
188  return element;
189 }
190 
191 dtkAbstractDataWriter *createaxlShapeBSplineWriter(void)
192 {
193  return new axlShapeBSplineWriter;
194 }
195 
axlPoint getCoef(int index) const
Get a coefficient of the surface.
int order_u() const
Return the order of the surface for the u parameter.
Edge * getEdge(int i)
Return edge.
bool accept(dtkAbstractData *data)
int countFaces(void)
Return how many faces.
int order_v() const
Return the order of the surface for the v parameter.
QVector< int > controlPointsIndices
bool reject(dtkAbstractData *data)
virtual bool accept(dtkAbstractData *data)=0
Face * getFace(int i)
Return face.
QStringList handled(void) const
QString description(void) const
QString identifier(void) const
dtkAbstractDataWriter * createaxlShapeBSplineWriter(void)
int countBoundaryEdges() const
Return how many edges.
QDomElement write(QDomDocument *doc, dtkAbstractData *data)
double y
Definition: axlPoint.h:37
int countControlPoints() const
Modified a coefficient of the surface.
double z
Definition: axlPoint.h:38
Class axlShapeBSpline defines a set of boundary curves (Edges) and bspline surface patches (Face)...
virtual QDomElement write(QDomDocument *doc, dtkAbstractData *data)=0
double x
Definition: axlPoint.h:37
QVector< int > controlPointsIndices
QString identifier(void) const
Return the "axlShapeBSpline" identifier.Useful for data factory.