Developer documentation | Axl-2.5.1

axlEllipsoid.cpp
Go to the documentation of this file.
1 /* axlEllipsoid.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 "axlEllipsoid.h"
21 
22 #include "axlPoint.h"
23 
24 #include <dtkCoreSupport/dtkGlobal.h>
25 
26 #include <dtkMathSupport/dtkQuaternion.h>
27 
28 // /////////////////////////////////////////////////////////////////
29 // axlEllipsoidPrivate
30 // /////////////////////////////////////////////////////////////////
31 
32 class axlEllipsoidPrivate
33 {
34 public:
35  axlPoint *center;
36  axlPoint *semiX;
37  axlPoint *semiY;
38  axlPoint *semiZ;
39 };
40 
41 // /////////////////////////////////////////////////////////////////
42 // axlEllipsoid implementation
43 // /////////////////////////////////////////////////////////////////
44 
46 
51 axlEllipsoid::axlEllipsoid(QObject *parent) : axlAbstractData(), d(new axlEllipsoidPrivate)
52 {
53  this->setObjectName(this->identifier());
54 
55  d->center = new axlPoint();
56  d->semiX = new axlPoint(1.0, 0.0, 0.0);
57  d->semiY = new axlPoint(0.0, 1.0, 0.0);
58  d->semiZ = new axlPoint(0.0, 0.0, 1.0);
59 }
60 
62 
67 axlEllipsoid::axlEllipsoid(axlPoint *center, axlPoint *semiX, axlPoint *semiY, axlPoint *semiZ, QObject *parent) : axlAbstractData(), d(new axlEllipsoidPrivate)
68 {
69  this->setObjectName(this->identifier());
70 
71  d->center = new axlPoint(center);
72  d->semiX = new axlPoint(semiX);
73  d->semiY = new axlPoint(semiY);
74  d->semiZ = new axlPoint(semiZ);
75 }
76 
78 
83 axlEllipsoid::axlEllipsoid(const axlPoint& center, const axlPoint& semiX, const axlPoint& semiY, const axlPoint& semiZ, QObject *parent) : axlAbstractData(), d(new axlEllipsoidPrivate)
84 {
85  this->setObjectName(this->identifier());
86 
87  d->center =new axlPoint(center);
88  d->semiX = new axlPoint(semiX);
89  d->semiY = new axlPoint(semiY);
90  d->semiZ = new axlPoint(semiZ);
91 }
92 
94 
97 axlEllipsoid::axlEllipsoid(const axlEllipsoid& other) : axlAbstractData(), d(new axlEllipsoidPrivate)
98 {
99  this->setObjectName(this->identifier());
100  this->setParent(other.parent());
101 
102  d->center = new axlPoint(other.d->center);
103  d->semiX = new axlPoint(other.d->semiX);
104  d->semiY = new axlPoint(other.d->semiY);
105  d->semiZ = new axlPoint(other.d->semiZ);
106 }
107 
109 
113 {
114  if (d->center) {
115  delete d->center;
116  d->center = NULL;
117  }
118 
119  if (d->semiX) {
120  delete d->semiX;
121  d->semiX = NULL;
122  }
123 
124  if (d->semiY) {
125  delete d->semiY;
126  d->semiY = NULL;
127  }
128 
129  if (d->semiZ) {
130  delete d->semiZ;
131  d->semiZ = NULL;
132  }
133 
134  delete d;
135 
136  d = NULL;
137 }
138 
140 
144 {
145  *(d->center) = *(other.d->center);
146  *(d->semiX) = *(other.d->semiX);
147  *(d->semiY) = *(other.d->semiY);
148  *(d->semiZ) = *(other.d->semiZ);
149 
150  return (*this);
151 }
152 
154 
158 {
159  return d->center;
160 }
161 
163 
167 {
168  return d->semiX;
169 }
170 
172 
176 {
177  return d->semiY;
178 }
179 
181 
185 {
186  return d->semiZ;
187 }
188 
190 
193 void axlEllipsoid::setValues(axlPoint *center, axlPoint *semiX, axlPoint *semiY, axlPoint *semiZ)
194 {
195  *(d->center) = *center;
196  *(d->semiX) = *semiX;
197  *(d->semiY) = *semiY;
198  *(d->semiZ) = *semiZ;
199 
200  //this->touchGeometry();
201 }
202 
204 
208 {
209  *(d->center) = *center;
210 
211  //this->touchGeometry();
212 }
213 
215 
219 {
220  *(d->semiX) = *semiX;
221 
222  //this->touchGeometry();
223 }
224 
226 
230 {
231  *(d->semiY) = *semiY;
232 
233  //this->touchGeometry();
234 }
235 
237 
241 {
242  *(d->semiZ) = *semiZ;
243 
244  //this->touchGeometry();
245 }
246 
248 {
249  d->center->setCoordinates(center.x(),center.y(),center.z());
250  this->touchGeometry();
251 }
252 
254 {
255  d->semiX->setCoordinates(semiX.x(),semiX.y(),semiX.z());
256  this->touchGeometry();
257 }
258 
260 {
261  d->semiY->setCoordinates(semiY.x(),semiY.y(),semiY.z());
262  this->touchGeometry();
263 }
264 
266 {
267  d->semiZ->setCoordinates(semiZ.x(),semiZ.y(),semiZ.z());
268  this->touchGeometry();
269 }
270 
271 // /////////////////////////////////////////////////////////////////
272 // Debug operators
273 // /////////////////////////////////////////////////////////////////
274 
275 QDebug operator<<(QDebug dbg, axlEllipsoid ellipsoid)
276 {
277  dbg.nospace() << ellipsoid.description();
278 
279  return dbg.space();
280 }
281 
282 QDebug operator<<(QDebug dbg, axlEllipsoid& ellipsoid)
283 {
284  dbg.nospace() << ellipsoid.description();
285 
286  return dbg.space();
287 }
288 
289 QDebug operator<<(QDebug dbg, axlEllipsoid *ellipsoid)
290 {
291  dbg.nospace() << ellipsoid->description();
292 
293  return dbg.space();
294 }
295 
296 QString axlEllipsoid::description(void) const
297 {
298  QString result = "axlEllipsoid";
299 
300  result.append("\ncenter : "+d->center->description()
301  + "\nsemi axes X value : "+d->semiX->description()
302  + "\nsemi axes Y value : "+d->semiY->description()
303  + "\nsemi axes Z value : "+d->semiZ->description());
304 
305  return result;
306 }
307 
308 QString axlEllipsoid::identifier(void) const
309 {
310  return "axlEllipsoid";
311 }
312 
313 //SLOT
315 {
316  *(d->center) = *center;
317  this->touchGeometry();
318 }
319 
321 {
322  *(d->semiX) = *semiX;
323  this->touchGeometry();
324 }
325 
327 {
328  *(d->semiY) = *semiY;
329  this->touchGeometry();
330 }
331 
333 {
334  *(d->semiZ) = *semiZ;
335  this->touchGeometry();
336 }
337 
339 
342 void axlEllipsoid::modifyCenter(double *center)
343 {
344  d->center->setCoordinates(center[0], center[1], center[2]);
345  this->touchGeometry();
346 }
347 
349 
353 {
354  d->center->coordinates()[0] = x;
355  this->touchGeometry();
356 }
357 
359 
363 {
364  d->center->coordinates()[1] = y;
365  this->touchGeometry();
366 }
367 
369 
373 {
374  d->center->coordinates()[2] = z;
375  this->touchGeometry();
376 }
377 
379 
382 void axlEllipsoid::modifySemiX(double *semiX)
383 {
384  d->semiX->setCoordinates(semiX[0], semiX[1], semiX[2]);
385  this->touchGeometry();
386 }
387 
389 
393 {
394  d->semiX->coordinates()[0] = x;
395  this->touchGeometry();
396 }
397 
399 
403 {
404  d->semiX->coordinates()[1] = y;
405  this->touchGeometry();
406 }
407 
409 
413 {
414  d->semiX->coordinates()[2] = z;
415  this->touchGeometry();
416 }
417 
419 
422 void axlEllipsoid::modifySemiY(double *semiY)
423 {
424  d->semiY->setCoordinates(semiY[0], semiY[1], semiY[2]);
425  this->touchGeometry();
426 }
427 
429 
433 {
434  d->semiY->coordinates()[0] = x;
435 
436  this->touchGeometry();
437 }
438 
440 
444 {
445  d->semiY->coordinates()[1] = y;
446  this->touchGeometry();
447 }
448 
450 
454 {
455  d->semiY->coordinates()[2] = z;
456  this->touchGeometry();
457 }
458 
460 
463 void axlEllipsoid::modifySemiZ(double *semiZ)
464 {
465  d->semiZ->setCoordinates(semiZ[0], semiZ[1], semiZ[2]);
466  this->touchGeometry();
467 }
468 
470 
474 {
475  d->semiZ->coordinates()[0] = x;
476 
477  this->touchGeometry();
478 }
479 
481 
485 {
486  d->semiZ->coordinates()[1] = y;
487 
488  this->touchGeometry();
489 }
490 
492 
496 {
497  d->semiZ->coordinates()[2] = z;
498 
499  this->touchGeometry();
500 }
501 
503 {
504  axlPoint semix(d->semiX->coordinates());
505  axlPoint startSemix(semix);
506 
507  semix.normalize();
508 
509  axlPoint semiy(d->semiY->coordinates());
510  double semiyRadius = semiy.norm();
511 
512  semiy.normalize();
513 
514  axlPoint semiz(d->semiZ->coordinates());
515  double semizRadius = semiz.norm();
516 
517  semiz.normalize();
518 
519  if (semix.norm() < 0.001) {
520  axlPoint pv = axlPoint::crossProduct(semiy, semiz);
521  if (pv.norm() < 0.001) {
522  return;
523  } else {
524  semix = pv;
525  semix.normalize();
526  semiy = axlPoint::crossProduct(semiz, semix);
527  semiy.normalize();
528  }
529  } else {
530  axlPoint pv = axlPoint::crossProduct(semix, semiy);
531  if (pv.norm() < 0.001) {
532  pv = axlPoint::crossProduct(semiz, semix);
533  if (pv.norm() < 0.001) {
534  return;
535  } else {
536  semiy = pv;
537  semiy.normalize();
538  semiz = axlPoint::crossProduct(semix, semiy);
539  semiz.normalize();
540  }
541  } else {
542  semiz = pv;
543  semiz.normalize();
544  semiy = axlPoint::crossProduct(semiz, semix);
545  semiy.normalize();
546  }
547  }
548 
549  modifySemiX(startSemix.coordinates());
550  semiy *= semiyRadius;
551  modifySemiY(semiy.coordinates());
552  semiz *= semizRadius;
553  modifySemiZ(semiz.coordinates());
554 }
555 
557 {
558  axlPoint semix(d->semiX->coordinates());
559  double semixRadius = semix.norm();
560 
561  semix.normalize();
562 
563  axlPoint semiy(d->semiY->coordinates());
564  axlPoint startSemiy(semiy);
565 
566  semiy.normalize();
567 
568  axlPoint semiz(d->semiZ->coordinates());
569  double semizRadius = semiz.norm();
570 
571  semiz.normalize();
572 
573  if (semiy.norm() < 0.001) {
574  axlPoint pv = axlPoint::crossProduct(semiz, semix);
575  if (pv.norm() < 0.001) {
576  return;
577  } else {
578  semiy = pv;
579  semiy.normalize();
580  semiz = axlPoint::crossProduct(semix, semiy);
581  semiz.normalize();
582  }
583  } else {
584  axlPoint pv = axlPoint::crossProduct(semiy, semiz);
585  if (pv.norm() < 0.001) {
586  pv = axlPoint::crossProduct(semix, semiy);
587  if (pv.norm() < 0.001) {
588  return;
589  } else {
590  semiz = pv;
591  semiz.normalize();
592  semix = axlPoint::crossProduct(semiy, semiz);
593  semix.normalize();
594  }
595  } else {
596  semix = pv;
597  semix.normalize();
598  semiz = axlPoint::crossProduct(semix, semiy);
599  semiz.normalize();
600  }
601  }
602 
603  semix *= semixRadius;
604  modifySemiX(semix.coordinates());
605  modifySemiY(startSemiy.coordinates());
606  semiz *= semizRadius;
607  modifySemiZ(semiz.coordinates());
608 }
609 
611 {
612  axlPoint semix(d->semiX->coordinates());
613  double semixRadius = semix.norm();
614 
615  semix.normalize();
616 
617  axlPoint semiy(d->semiY->coordinates());
618  double semiyRadius = semiy.norm();
619 
620  semiy.normalize();
621 
622  axlPoint semiz(d->semiZ->coordinates());
623  axlPoint startSemiz(semiz);
624 
625  semiz.normalize();
626 
627  if (semiz.norm() < 0.001) {
628  axlPoint pv = axlPoint::crossProduct(semix, semiy);
629  if (pv.norm() < 0.001) {
630  return;
631  } else {
632  semiz = pv;
633  semiz.normalize();
634  semix = axlPoint::crossProduct(semiy, semiz);
635  semix.normalize();
636  }
637  } else {
638  axlPoint pv = axlPoint::crossProduct(semiz, semix);
639  if (pv.norm() < 0.001) {
640  pv = axlPoint::crossProduct(semiy, semiz);
641  if (pv.norm() < 0.001) {
642  return;
643  } else {
644  semix = pv;
645  semix.normalize();
646  semiy = axlPoint::crossProduct(semiz, semix);
647  semiy.normalize();
648  }
649  } else {
650  semiy = pv;
651  semiy.normalize();
652  semix = axlPoint::crossProduct(semiy, semiz);
653  semix.normalize();
654  }
655  }
656 
657  semix *= semixRadius;
658  modifySemiX(semix.coordinates());
659  semiy *= semiyRadius;
660  modifySemiY(semiy.coordinates());
661  modifySemiZ(startSemiz.coordinates());
662 }
663 
664 QVariantList axlEllipsoid::convertDataToQVariant(void) const
665 {
666  QVariantList list;
667  QVariant id = QVariant::fromValue(identifier());
668  QVariantList center = d->center->convertDataToQVariant();
669  QVariantList semiX = d->semiX->convertDataToQVariant();
670  QVariantList semiY = d->semiY->convertDataToQVariant();
671  QVariantList semiZ = d->semiZ->convertDataToQVariant();
672  list.append(id);
673  list.append(center);
674  list.append(semiX);
675  list.append(semiY);
676  list.append(semiZ);
677  QVariant name = QVariant::fromValue(objectName());
678  list.append(name);
679  return list;
680 }
681 
682 int axlEllipsoid::convertQVariantToData(const QVariantList &data)
683 {
684  QVariantList center;
685  center.append(data.at(1));
686  center.append(data.at(2));
687  center.append(data.at(3));
688  center.append(data.at(4));
689  center.append(data.at(5));
690  d->center->convertQVariantToData(center);
691  QVariantList semiX;
692  semiX.append(data.at(6));
693  semiX.append(data.at(7));
694  semiX.append(data.at(8));
695  semiX.append(data.at(9));
696  semiX.append(data.at(10));
697  d->semiX->convertQVariantToData(semiX);
698  QVariantList semiY;
699  semiY.append(data.at(11));
700  semiY.append(data.at(12));
701  semiY.append(data.at(13));
702  semiY.append(data.at(14));
703  semiY.append(data.at(15));
704  d->semiY->convertQVariantToData(semiY);
705  QVariantList semiZ;
706  semiZ.append(data.at(16));
707  semiZ.append(data.at(17));
708  semiZ.append(data.at(18));
709  semiZ.append(data.at(19));
710  semiZ.append(data.at(20));
711  d->semiZ->convertQVariantToData(semiZ);
712  setObjectName(data.last().toString());
713  return 1;
714 }
715 
716 dtkAbstractData *createaxlEllipsoid(void)
717 {
718  return new axlEllipsoid;
719 }
720 
721 // /////////////////////////////////////////////////////////////////
722 // axlEllipsoid documentation
723 // /////////////////////////////////////////////////////////////////
724 
void touchGeometry(void)
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void onSemiYChanged(axlPoint *semiY)
void setSemiZ(axlPoint *semiZ)
Change semi axes z value of this ellipsoid.
void modifyCenter(double *center)
modify Center of this Ellipsoid.
axlEllipsoid(QObject *parent=0)
Constructs a axel ellipsoid of with firstPoint and second point are NULL and 1.0 radius with parent p...
void modifySemiXZ(double z)
modify Z SemiX value of this Ellipsoid.
void modifySemiYY(double y)
modify Y SemiY value of this Ellipsoid.
void onCenterChanged(axlPoint *center)
void modifySemiYX(double x)
modify X SemiY value of this Ellipsoid.
void touchCenter(axlPoint center)
virtual QString identifier(void) const
void setValues(axlPoint *center, axlPoint *semiX, axlPoint *semiY, axlPoint *semiZ)
Change center, semi axes x, y, z values and quarternion of this ellipsoid.
void modifySemiXX(double x)
modify X SemiX value of this Ellipsoid.
axlPoint * semiX(void) const
Returns semi x axe value of the ellipsoid.
void setCenter(axlPoint *center)
Change center of this ellipsoid.
void touchSemiZ(axlPoint semiZ)
axlPoint * semiY(void) const
Returns semi y axe value of the ellipsoid.
void modifySemiX(double *semiX)
modify SemiX of this Ellipsoid.
axlEllipsoid & operator=(const axlEllipsoid &other)
Assigns other to this ellipsoid and returns a reference to this ellipsoid.
axlPoint * semiZ(void) const
Returns semi z axe value of the ellipsoid.
void modifyCenterZ(double z)
modify Z Center value of this Ellipsoid.
void calculateXZ(void)
void calculateYZ(void)
void modifySemiY(double *semiY)
modify SemiY of this Ellipsoid.
void onSemiXChanged(axlPoint *semiX)
void modifySemiZX(double x)
modify X SemiZ value of this Ellipsoid.
void normalize(void)
Definition: axlPoint.cpp:410
double norm(void) const
Definition: axlPoint.cpp:450
void modifySemiZZ(double z)
modify Z SemiZ value of this Ellipsoid.
void modifyCenterY(double y)
modify Y Center value of this Ellipsoid.
void modifySemiYZ(double z)
modify Z SemiY value of this Ellipsoid.
void modifySemiXY(double y)
modify Y SemiX value of this Ellipsoid.
void setSemiX(axlPoint *semiX)
Change semi axes x value of this ellipsoid.
dtkAbstractData * createaxlEllipsoid(void)
void modifyCenterX(double x)
modify X Center value of this Ellipsoid.
void modifySemiZY(double y)
modify Y SemiZ value of this Ellipsoid.
double y
Definition: axlPoint.h:37
axlPoint * center(void) const
Returns center of the ellipsoid.
QVariantList convertDataToQVariant(void) const
Convert an axlAbstractData into a QVariantList that specifies all properties of the axlAbstractData...
void touchSemiY(axlPoint semiY)
~axlEllipsoid(void)
Destroys the axel ellipsoid.
double z
Definition: axlPoint.h:38
void touchSemiX(axlPoint semiX)
void modifySemiZ(double *semiZ)
modify SemiZ of this Ellipsoid.
QDebug operator<<(QDebug dbg, axlEllipsoid ellipsoid)
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
Definition: axlPoint.cpp:485
virtual QString description(void) const
double x
Definition: axlPoint.h:37
Class axlEllipsoid defines 3D ellipsoids.
Definition: axlEllipsoid.h:35
void onSemiZChanged(axlPoint *semiZ)
void calculateXY(void)
Class axlAbstractData defines an API for all type of axel data.
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
void setSemiY(axlPoint *semiY)
Change semi axes y value of this ellipsoid.