Developer documentation | Axl-2.5.1

axlCone.cpp
Go to the documentation of this file.
1 /* axlCone.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Tue Nov 9 16:58:59 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Nov 9 17:09:38 2010 (+0100)
8  * By: Meriadeg Perrinel
9  * Update #: 19
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlCone.h"
21 
22 #include "axlPoint.h"
23 
24 #include <dtkCoreSupport/dtkGlobal.h>
25 
26 // /////////////////////////////////////////////////////////////////
27 // axlConePrivate
28 // /////////////////////////////////////////////////////////////////
29 
30 class axlConePrivate
31 {
32 public:
33  axlPoint *apex;
34  axlPoint *basePoint;
35  double radius;
36 };
37 
38 // /////////////////////////////////////////////////////////////////
39 // axlCone implementation
40 // /////////////////////////////////////////////////////////////////
41 
43 
48 axlCone::axlCone(QObject *parent) : axlAbstractData(), d(new axlConePrivate)
49 {
50  this->setObjectName(this->identifier());
51 
52  d->apex = new axlPoint();
53  d->basePoint = new axlPoint(1.0, 0.0, 0.0);
54  d->radius = 1.0;
55 }
56 
58 
63 axlCone::axlCone(axlPoint *apex, axlPoint *basePoint, double radius, QObject *parent) : axlAbstractData(), d(new axlConePrivate)
64 {
65  this->setObjectName(this->identifier());
66 
67  d->apex = new axlPoint(apex);
68  d->basePoint = new axlPoint(basePoint);
69  d->radius = radius;
70 }
71 
73 
78 axlCone::axlCone(const axlPoint &apex, const axlPoint &basePoint, double radius, QObject *parent) : axlAbstractData(), d(new axlConePrivate) {
79  this->setObjectName(this->identifier());
80 
81  d->apex = new axlPoint(apex);
82  d->basePoint = new axlPoint(basePoint);
83  d->radius = radius;
84 }
85 
87 
90 axlCone::axlCone(const axlCone& other) : axlAbstractData(), d(new axlConePrivate)
91 {
92  this->setObjectName(this->identifier());
93  this->setParent(other.parent());
94  d->apex = new axlPoint(other.d->apex);
95  d->basePoint = new axlPoint(other.d->basePoint);
96  d->radius = other.radius();
97 }
98 
100 
104 {
105  if (d->apex)
106  {
107  delete d->apex;
108  d->apex = NULL;
109  }
110  if (d->basePoint)
111  {
112  delete d->basePoint;
113  d->basePoint = NULL;
114  }
115  delete d;
116  d = NULL;
117 }
118 
120 
124 {
125  *(d->apex) = *(other.d->apex);
126  *(d->basePoint) = *(other.d->basePoint);
127  d->radius = other.radius();
128 
129  return (*this);
130 }
131 
133 
137 {
138  return d->apex;
139 }
140 
142 
146 {
147  return d->basePoint;
148 }
149 
151 
154 double axlCone::radius(void) const
155 {
156  return d->radius;
157 }
158 
160 
163 double axlCone::length(void) const
164 {
165  return axlPoint::distance(d->apex, d->basePoint);
166 }
167 
169 
172 void axlCone::setValues(axlPoint *apex, axlPoint *basePoint, double radius)
173 {
174  *(d->apex) = *apex;
175  *(d->basePoint) = *basePoint;
176  d->radius = radius;
177 
178  //this->touchGeometry();
179 }
180 
182 
186 {
187  *(d->apex) = *apex;
188 
189  //this->touchGeometry();
190 }
191 
192 void axlCone::setApex(double *apex)
193 {
194  d->apex->coordinates()[0] = apex[0];
195  d->apex->coordinates()[1] = apex[1];
196  d->apex->coordinates()[2] = apex[2];
197 }
198 
200 
204 {
205  *(d->basePoint) = *basePoint;
206 
207  //this->touchGeometry();
208 }
209 
210 void axlCone::setBasePoint(double *basePoint)
211 {
212  d->basePoint->coordinates()[0] = basePoint[0];
213  d->basePoint->coordinates()[1] = basePoint[1];
214  d->basePoint->coordinates()[2] = basePoint[2];
215 }
216 
218 
221 void axlCone::setRadius(double radius)
222 {
223  d->radius = radius;
224 
225  //this->touchGeometry();
226 }
227 
229 
232 void axlCone::setLength(double length)
233 {
234  double oldLength = this->length();
235  if(oldLength != 0)
236  {
237  (*d->basePoint) = *(d->apex) + (*(d->basePoint) - *(d->apex)) * (length/oldLength) ;
238  }
239  else
240  qDebug()<< "cone is not correctly defined length = 0.0";
241 
242  this->touchGeometry();
243 }
244 
245 void axlCone::touchRadius(double radius)
246 {
247  d->radius = radius;
248  this->touchGeometry();
249 }
250 
252 {
253  d->basePoint->setCoordinates(basePoint.x(),basePoint.y(),basePoint.z());
254  this->touchGeometry();
255 }
256 
258 {
259  d->apex->setCoordinates(apex.x(),apex.y(),apex.z());
260  this->touchGeometry();
261 }
262 
263 // /////////////////////////////////////////////////////////////////
264 // Debug operators
265 // /////////////////////////////////////////////////////////////////
266 
267 QDebug operator<<(QDebug dbg, axlCone cone)
268 {
269  dbg.nospace() << cone.description();
270 
271  return dbg.space();
272 }
273 
274 QDebug operator<<(QDebug dbg, axlCone& cone)
275 {
276  dbg.nospace() << cone.description();
277 
278  return dbg.space();
279 }
280 
281 QDebug operator<<(QDebug dbg, axlCone *cone)
282 {
283  dbg.nospace() << cone->description();
284 
285  return dbg.space();
286 }
287 
288 QString axlCone::description(void) const
289 {
290  QString result = "axlCone";
291  if(!d->apex)
292  return "Please set an apex";
293 
294  if(!d->basePoint)
295  return "Please set a base point";
296 
297  result.append("\napex : "+d->apex->description() + "\nbase point : "+d->basePoint->description() + "\nradius : "+ QString::number(d->radius));
298  return result;
299 }
300 
301 QString axlCone::identifier(void) const
302 {
303  return "axlCone";
304 }
305 
306 //SLOT
308 {
309  *(d->apex) = *apex;
310  this->touchGeometry();
311 }
312 
314 {
315  *(d->basePoint) = *basePoint;
316  this->touchGeometry();
317 }
318 
319 void axlCone::onRadiusChanged(double radius)
320 {
321  d->radius = radius;
322  this->touchGeometry();
323 }
324 
325 
326 QVariantList axlCone::convertDataToQVariant(void) const
327 {
328  QVariantList list;
329  QVariant id = QVariant::fromValue(identifier());
330  QVariant radius = QVariant::fromValue(d->radius);
331  QVariantList base = d->basePoint->convertDataToQVariant();
332  QVariantList apex = d->apex->convertDataToQVariant();
333  list.append(id);
334  list.append(radius);
335  list.append(base);
336  list.append(apex);
337  QVariant name = QVariant::fromValue(objectName());
338  list.append(name);
339  return list;
340 }
341 
342 int axlCone::convertQVariantToData(const QVariantList &data)
343 {
344  setRadius(data.at(1).toDouble());
345  QVariantList baseList;
346  baseList.append(data.at(2));
347  baseList.append(data.at(3));
348  baseList.append(data.at(4));
349  baseList.append(data.at(5));
350  baseList.append(data.at(6));
351  d->basePoint->convertQVariantToData(baseList);
352  QVariantList apexList;
353  apexList.append(data.at(7));
354  apexList.append(data.at(8));
355  apexList.append(data.at(9));
356  apexList.append(data.at(10));
357  d->apex->convertQVariantToData(apexList);
358  setObjectName(data.last().toString());
359  return 1;
360 }
361 
362 //to be registered to the data factory.
363 dtkAbstractData *createaxlCone(void)
364 {
365  return new axlCone;
366 }
367 
368 // /////////////////////////////////////////////////////////////////
369 // axlCone documentation
370 // /////////////////////////////////////////////////////////////////
371 
void touchGeometry(void)
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
QVariantList convertDataToQVariant(void) const
Convert an axlAbstractData into a QVariantList that specifies all properties of the axlAbstractData...
Definition: axlCone.cpp:326
axlCone & operator=(const axlCone &other)
Assigns other to this cone and returns a reference to this cone.
Definition: axlCone.cpp:123
virtual QString identifier(void) const
Definition: axlCone.cpp:301
virtual QString description(void) const
Definition: axlCone.cpp:288
QDebug operator<<(QDebug dbg, axlCone cone)
Definition: axlCone.cpp:267
void touchApex(axlPoint apex)
Definition: axlCone.cpp:257
~axlCone(void)
Destroys the axel cone.
Definition: axlCone.cpp:103
void setApex(axlPoint *apex)
Change apex of this cone.
Definition: axlCone.cpp:185
void onApexChanged(axlPoint *apex)
Definition: axlCone.cpp:307
void setRadius(double radius)
Change radius of this cone.
Definition: axlCone.cpp:221
axlPoint * apex(void) const
Returns apex of the cone.
Definition: axlCone.cpp:136
axlCone(QObject *parent=0)
Constructs a axel cone of with apex and basePoint point are NULL and 1.0 radius with parent parent of...
Definition: axlCone.cpp:48
double length(void) const
Returns length of the cone.
Definition: axlCone.cpp:163
void touchBasePoint(axlPoint basePoint)
Definition: axlCone.cpp:251
void onRadiusChanged(double radius)
Definition: axlCone.cpp:319
void setLength(double length)
Change length of this cone we considered then apex is the origin of the cone and we change base point...
Definition: axlCone.cpp:232
double y
Definition: axlPoint.h:37
void onBasePointChanged(axlPoint *basePoint)
Definition: axlCone.cpp:313
double radius
Definition: axlCone.h:38
void setValues(axlPoint *apex, axlPoint *basePoint, double radius)
Change apex and basePoint of this cone.
Definition: axlCone.cpp:172
double z
Definition: axlPoint.h:38
Class axlCone defines 3D cones.
Definition: axlCone.h:34
axlPoint * basePoint(void) const
Returns basePoint point of the cone.
Definition: axlCone.cpp:145
void setBasePoint(axlPoint *basePoint)
Change base point of this cone.
Definition: axlCone.cpp:203
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.
Definition: axlPoint.cpp:459
double x
Definition: axlPoint.h:37
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
Definition: axlCone.cpp:342
Class axlAbstractData defines an API for all type of axel data.
double radius(void) const
Returns radius of the cone.
Definition: axlCone.cpp:154
dtkAbstractData * createaxlCone(void)
Definition: axlCone.cpp:363
void touchRadius(double radius)
Definition: axlCone.cpp:245