Developer documentation | Axl-2.5.1

axlTorus.cpp
Go to the documentation of this file.
1 /* axlTorus.cpp ---
2  *
3  * Author: Valentin Michelet
4  * Copyright (C) 2008-2012 - Valentin Michelet, Inria.
5  * Created: Tue Nov 9 16:58:59 2012 (+0100)
6  * Version: $Id$
7  */
8 
9 /* Commentary:
10  *
11  */
12 
13 /* Change log:
14  *
15  */
16 
17 #include "axlTorus.h"
18 
19 #include "axlPoint.h"
20 
21 #include <dtkCoreSupport/dtkGlobal.h>
22 
23 // /////////////////////////////////////////////////////////////////
24 // axlTorusPrivate
25 // /////////////////////////////////////////////////////////////////
26 
27 class axlTorusPrivate {
28 public:
29  axlPoint* center;
30  axlPoint* direction;
31  double ringRadius;
32  double crossSectionRadius;
33 };
34 
35 // /////////////////////////////////////////////////////////////////
36 // axlTorus implementation
37 // /////////////////////////////////////////////////////////////////
38 
39 axlTorus::axlTorus(QObject *parent) :
41  d(new axlTorusPrivate) {
42 
43  this->setObjectName(this->identifier());
44 
45  d->center = new axlPoint;
46  d->direction = new axlPoint(1.0, 0.0, 0.0);
47  d->ringRadius = 1.0;
48  d->crossSectionRadius = 0.2;
49 }
50 
51 axlTorus::axlTorus(axlPoint* center, axlPoint* direction, double ringRadius, double crossSectionRadius) :
53  d(new axlTorusPrivate) {
54 
55  this->setObjectName(this->identifier());
56 
57  d->center = new axlPoint(center);
58  d->direction = new axlPoint(direction);
59  d->ringRadius = ringRadius;
60  d->crossSectionRadius = crossSectionRadius;
61 }
62 
63 axlTorus::axlTorus(const axlPoint& center, const axlPoint& direction, double ringRadius, double crossSectionRadius) :
65  d(new axlTorusPrivate) {
66 
67  this->setObjectName(this->identifier());
68 
69  d->center = new axlPoint(center);
70  d->direction = new axlPoint(direction);
71  d->ringRadius = ringRadius;
72  d->crossSectionRadius = crossSectionRadius;
73 }
74 
77  d(new axlTorusPrivate) {
78 
79  this->setObjectName(this->identifier());
80  this->setParent(other.parent());
81  d->center = new axlPoint(other.d->center);
82  d->direction = new axlPoint(other.d->direction);
83  d->ringRadius = other.d->ringRadius;
84  d->crossSectionRadius = other.d->crossSectionRadius;
85 }
86 
88  if(d->center) {
89  delete d->center;
90  d->center = NULL;
91  }
92  if(d->direction) {
93  delete d->direction;
94  d->direction = NULL;
95  }
96  delete d;
97  d = NULL;
98 }
99 
100 QString axlTorus::description(void) const {
101  QString res = "axlTorus";
102  res.append("\nCenter: " + d->center->description());
103  res.append("\nDirection: " + d->direction->description());
104  res.append("\nRing radius: " + QString::number(d->ringRadius));
105  res.append("\nCross section radius: " + QString::number(d->crossSectionRadius));
106  return res;
107 }
108 
109 QString axlTorus::identifier(void) const {
110  return "axlTorus";
111 }
112 
114  return d->center;
115 }
116 
118  return d->direction;
119 }
120 
121 double axlTorus::ringRadius(void) const {
122  return d->ringRadius;
123 }
124 
125 double axlTorus::crossSectionRadius(void) const {
126  return d->crossSectionRadius;
127 }
128 
129 void axlTorus::setValues(axlPoint *center, axlPoint *direction, double ringRadius, double crossSectionRadius) {
130  *(d->center) = *center;
131  *(d->direction) = *direction;
132  d->ringRadius = ringRadius;
133  d->crossSectionRadius = crossSectionRadius;
134 }
135 
137  *(d->center) = *center;
138 }
139 
141  *(d->direction) = *direction;
142 }
143 
144 void axlTorus::setRingRadius(double ringRadius) {
145  d->ringRadius = ringRadius;
146 }
147 
148 void axlTorus::setCrossSectionRadius(double crossSectionRadius) {
149  d->crossSectionRadius = crossSectionRadius;
150 }
151 
152 void axlTorus::setCenter(double* center) {
153  d->center->coordinates()[0] = center[0];
154  d->center->coordinates()[1] = center[1];
155  d->center->coordinates()[2] = center[2];
156  //this->touchGeometry();
157 }
158 
159 void axlTorus::setDirection(double* direction) {
160  d->direction->coordinates()[0] = direction[0];
161  d->direction->coordinates()[1] = direction[1];
162  d->direction->coordinates()[2] = direction[2];
163  this->touchGeometry();
164 }
165 
167  {
168  d->center->setCoordinates(center.x(),center.y(),center.z());
169  this->touchGeometry();
170  }
171 
173  {
174  d->direction->setCoordinates(direction.x(),direction.y(),direction.z());
175  this->touchGeometry();
176  }
177 
178  void axlTorus::touchRingRadius(double ringRadius)
179  {
180  d->ringRadius = ringRadius;
181  this->touchGeometry();
182  }
183 
184  void axlTorus::touchCrossSectionRadius(double crossSectionRadius)
185  {
186  d->crossSectionRadius = crossSectionRadius;
187  this->touchGeometry();
188  }
189 
191  *(d->center) = *(other.d->center);
192  *(d->direction) = *(other.d->direction);
193  d->ringRadius = other.d->ringRadius;
194  d->crossSectionRadius = other.d->crossSectionRadius;
195 
196  return (*this);
197 }
198 
199 QDebug operator<<(QDebug dbg, axlTorus torus) {
200  dbg.nospace() << torus.description();
201  return dbg.space();
202 }
203 
204 QDebug operator<<(QDebug dbg, axlTorus& torus) {
205  dbg.nospace() << torus.description();
206  return dbg.space();
207 }
208 
209 QDebug operator<<(QDebug dbg, axlTorus* torus) {
210  dbg.nospace() << torus->description();
211  return dbg.space();
212 }
213 
215  *(d->center) = *center;
216  this->touchGeometry();
217 }
218 
220  *(d->direction) = *direction;
221  this->touchGeometry();
222 }
223 
224 void axlTorus::onRingRadiusChanged(double ringRadius) {
225  d->ringRadius = ringRadius;
226  this->touchGeometry();
227 }
228 
229 void axlTorus::onCrossSectionRadiusChanged(double crossSectionRadius) {
230  d->crossSectionRadius = crossSectionRadius;
231  this->touchGeometry();
232 }
233 
234 QVariantList axlTorus::convertDataToQVariant(void) const{
235  QVariantList list;
236  QVariant id = QVariant::fromValue(identifier());
237  QVariant crossSectionRadius = QVariant::fromValue(d->crossSectionRadius);
238  QVariant ringRadius = QVariant::fromValue(d->ringRadius);
239  QVariantList center = d->center->convertDataToQVariant();
240  QVariantList direction = d->direction->convertDataToQVariant();
241  list.append(id);
242  list.append(center);
243  list.append(direction);
244  list.append(crossSectionRadius);
245  list.append(ringRadius);
246  QVariant name = QVariant::fromValue(objectName());
247  list.append(name);
248  return list;
249 
250 }
251 
252 int axlTorus::convertQVariantToData(const QVariantList &data){
253  QVariantList center;
254  center.append(data.at(1));
255  center.append(data.at(2));
256  center.append(data.at(3));
257  center.append(data.at(4));
258  center.append(data.at(5));
259  d->center->convertQVariantToData(center);
260  QVariantList direction;
261  direction.append(data.at(6));
262  direction.append(data.at(7));
263  direction.append(data.at(8));
264  direction.append(data.at(9));
265  direction.append(data.at(10));
266  d->direction->convertQVariantToData(direction);
267  setCrossSectionRadius(data.at(11).toDouble());
268  setRingRadius(data.at(12).toDouble());
269  setObjectName(data.last().toString());
270  return 1;
271 }
272 //to be registered to the data factory.
273 dtkAbstractData *createaxlTorus(void)
274 {
275  return new axlTorus;
276 }
void touchGeometry(void)
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void onDirectionChanged(axlPoint *direction)
Definition: axlTorus.cpp:219
void setCenter(axlPoint *center)
Definition: axlTorus.cpp:136
axlTorus(QObject *parent=0)
Definition: axlTorus.cpp:39
void setCrossSectionRadius(double crossSectionRadius)
Definition: axlTorus.cpp:148
void onCrossSectionRadiusChanged(double crossSectionRadius)
Definition: axlTorus.cpp:229
void onCenterChanged(axlPoint *center)
Definition: axlTorus.cpp:214
virtual ~axlTorus(void)
Definition: axlTorus.cpp:87
dtkAbstractData * createaxlTorus(void)
Definition: axlTorus.cpp:273
void touchCenterPoint(axlPoint center)
Definition: axlTorus.cpp:166
void touchCrossSectionRadius(double crossSectionRadius)
Definition: axlTorus.cpp:184
void setValues(axlPoint *center, axlPoint *direction, double ringRadius, double crossSectionRadius)
Definition: axlTorus.cpp:129
void onRingRadiusChanged(double ringRadius)
Definition: axlTorus.cpp:224
axlTorus & operator=(const axlTorus &other)
Definition: axlTorus.cpp:190
QVariantList convertDataToQVariant(void) const
Convert an axlAbstractData into a QVariantList that specifies all properties of the axlAbstractData...
Definition: axlTorus.cpp:234
void touchDirection(axlPoint direction)
Definition: axlTorus.cpp:172
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
Definition: axlTorus.cpp:252
axlPoint * centerPoint(void) const
Definition: axlTorus.cpp:113
void setRingRadius(double ringRadius)
Definition: axlTorus.cpp:144
void setDirection(axlPoint *direction)
Definition: axlTorus.cpp:140
virtual QString identifier(void) const
Definition: axlTorus.cpp:109
QDebug operator<<(QDebug dbg, axlTorus torus)
Definition: axlTorus.cpp:199
double y
Definition: axlPoint.h:37
double ringRadius(void) const
Definition: axlTorus.cpp:121
double z
Definition: axlPoint.h:38
axlPoint * direction(void) const
Definition: axlTorus.cpp:117
double x
Definition: axlPoint.h:37
double crossSectionRadius(void) const
Definition: axlTorus.cpp:125
Class axlAbstractData defines an API for all type of axel data.
void touchRingRadius(double ringRadius)
Definition: axlTorus.cpp:178
virtual QString description(void) const
Definition: axlTorus.cpp:100