22 #include <dtkCoreSupport/dtkGlobal.h>
28 class axlSpherePrivate
31 double coordinates[3];
49 d->coordinates[0] = 0.0;
50 d->coordinates[1] = 0.0;
51 d->coordinates[2] = 0.0;
64 d->coordinates[0] =
x;
65 d->coordinates[1] =
y;
66 d->coordinates[2] =
z;
78 this->setParent(other.parent());
79 d->coordinates[0] = other.d->coordinates[0];
80 d->coordinates[1] = other.d->coordinates[1];
81 d->coordinates[2] = other.d->coordinates[2];
82 d->radius = other.d->radius;
103 d->coordinates[0] = other.d->coordinates[0];
104 d->coordinates[1] = other.d->coordinates[1];
105 d->coordinates[2] = other.d->coordinates[2];
106 d->radius = other.d->radius;
117 d->coordinates[0] += other.d->coordinates[0];
118 d->coordinates[1] += other.d->coordinates[1];
119 d->coordinates[2] += other.d->coordinates[2];
120 d->radius += other.d->radius;
131 d->coordinates[0] -= other.d->coordinates[0];
132 d->coordinates[1] -= other.d->coordinates[1];
133 d->coordinates[2] -= other.d->coordinates[2];
134 d->radius -= other.d->radius;
145 d->coordinates[0] *= scalar;
146 d->coordinates[1] *= scalar;
147 d->coordinates[2] *= scalar;
159 if(!(scalar != 0.)) {
160 qWarning() << DTK_PRETTY_FUNCTION <<
"Preventing division by 0. Operand not affected.";
164 d->coordinates[0] /= scalar;
165 d->coordinates[1] /= scalar;
166 d->coordinates[2] /= scalar;
178 axlSphere result(d->coordinates[0] + other.d->coordinates[0],
179 d->coordinates[1] + other.d->coordinates[1],
180 d->coordinates[2] + other.d->coordinates[2],
181 d->radius + other.d->radius);
191 axlSphere result(d->coordinates[0] - other.d->coordinates[0],
192 d->coordinates[1] - other.d->coordinates[1],
193 d->coordinates[2] - other.d->coordinates[2],
194 d->radius - other.d->radius);
204 axlSphere result(d->coordinates[0] * scalar,
205 d->coordinates[1] * scalar,
206 d->coordinates[2] * scalar,
217 if(!(scalar != 0.)) {
218 qWarning() << DTK_PRETTY_FUNCTION <<
"Preventing division by 0. Returning default sphere";
222 axlSphere result(d->coordinates[0] / scalar,
223 d->coordinates[1] / scalar,
224 d->coordinates[2] / scalar,
236 return d->coordinates[0];
245 return d->coordinates[1];
254 return d->coordinates[2];
276 d->coordinates[0] = center.
x();
277 d->coordinates[1] = center.
y();
278 d->coordinates[2] = center.
z();
295 d->coordinates[0] =
x;
296 d->coordinates[1] =
y;
297 d->coordinates[2] =
z;
304 d->coordinates[0] =
x;
305 d->coordinates[1] =
y;
306 d->coordinates[2] =
z;
312 double norm = sqrt(d->coordinates[0] * d->coordinates[0] + d->coordinates[1] * d->coordinates[1] + d->coordinates[2] * d->coordinates[2]);
313 d->coordinates[0] /= norm;
314 d->coordinates[1] /= norm;
315 d->coordinates[2] /= norm;
327 return d->coordinates ;
336 double dx = rhs.d->coordinates[0] - lhs.d->coordinates[0];
337 double dy = rhs.d->coordinates[1] - lhs.d->coordinates[1];
338 double dz = rhs.d->coordinates[2] - lhs.d->coordinates[2];
340 return qSqrt(dx*dx + dy*dy + dz*dz);
349 double dx = rhs->d->coordinates[0] - lhs->d->coordinates[0];
350 double dy = rhs->d->coordinates[1] - lhs->d->coordinates[1];
351 double dz = rhs->d->coordinates[2] - lhs->d->coordinates[2];
353 return qSqrt(dx*dx + dy*dy + dz*dz);
363 dbg.nospace() << QString(
"axlSphere: center: (%1, %2, %3) radius : (%4)").arg(sphere.
x()).arg(sphere.
y()).arg(sphere.
z()).arg(sphere.
radius());
370 dbg.nospace() << QString(
"axlSphere: center: (%1, %2, %3) radius : (%4)").arg(sphere.
x()).arg(sphere.
y()).arg(sphere.
z()).arg(sphere.
radius());
377 dbg.nospace() << QString(
"axlSphere: center: (%1, %2, %3) radius : (%4)").arg(sphere->
x()).arg(sphere->
y()).arg(sphere->
z()).arg(sphere->
radius());
384 QString result =
"axlSphere";
385 result.append(
"\nX : "+QString::number(d->coordinates[0]) +
"\nY : "+QString::number(d->coordinates[1]) +
"\nZ : "+QString::number(d->coordinates[2]) +
"\nRadius : "+QString::number(d->radius));
402 d->coordinates[0] =
x;
407 d->coordinates[1] =
y;
412 d->coordinates[2] =
z;
423 QVariant
id = QVariant::fromValue(
identifier());
424 QVariant xcenter = QVariant::fromValue(d->coordinates[0]);
425 QVariant ycenter = QVariant::fromValue(d->coordinates[1]);
426 QVariant zcenter = QVariant::fromValue(d->coordinates[2]);
427 QVariant
radius = QVariant::fromValue(d->radius);
429 list.append(xcenter);
430 list.append(ycenter);
431 list.append(zcenter);
433 QVariant name = QVariant::fromValue(objectName());
440 setCenter(data.at(1).toDouble(), data.at(2).toDouble(), data.at(3).toDouble());
442 setObjectName(data.last().toString());
Class axlPoint defines 3D points.
virtual QString identifier(void) const
~axlSphere(void)
Destroys the axel sphere.
axlSphere & operator/=(double scalar)
Divides the coordinates and radius of this sphere by a scalar value and returns a reference to this s...
axlPoint centerPoint(void)
void onYChanged(double y)
void setValues(double x, double y, double z, double radius)
Change coordinates of this sphere.
QVariantList convertDataToQVariant(void) const
Convert an axlAbstractData into a QVariantList that specifies all properties of the axlAbstractData...
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
double x(void) const
Returns x-coordinate of this sphere.
double z(void) const
Returns z-coordinate of this sphere.
void setCenter(double x, double y, double z)
void touchCenter(axlPoint center)
axlSphere operator*(double scalar) const
Returns a sphere that results from the multiplication of the scalar with this sphere.
double radius(void) const
void onXChanged(double x)
virtual QString description(void) const
double * coordinates(void) const
Returns coordinates of this sphere.
void touchRadius(double radius)
axlSphere & operator*=(double scalar)
Multiplies the coordinates and radius of this sphere by a scalar value and returns a reference to thi...
axlSphere & operator+=(const axlSphere &other)
Adds the coordinates and radius of the other sphere to this sphere and returns a reference to this sp...
void onRadiusChanged(double radius)
void setRadius(double radius)
Class axlSphere defines 3D spheres.
QDebug operator<<(QDebug dbg, axlSphere sphere)
void onZChanged(double z)
axlSphere(QObject *parent=0)
Constructs a axel sphere of zero coordinates and 1.0 radius with parent parent of QObject type...
axlSphere & operator-=(const axlSphere &other)
Substracts the coordinates and radius of the other sphere to this sphere and returns a reference to t...
static double distance(const axlSphere &lhs, const axlSphere &rhs)
Returns the distance between lhs sphere and rhs sphere.
dtkAbstractData * createaxlSphere(void)
axlSphere operator/(double scalar) const
Returns a sphere that results from the division of the scalar with this sphere.
double y(void) const
Returns y-coordinate of this sphere.
axlSphere operator-(const axlSphere &other) const
Returns a sphere that results from the substraction of this sphere and the other sphere.
axlSphere operator+(const axlSphere &other) const
Returns a sphere that results from the addition of this sphere and the other sphere.
Class axlAbstractData defines an API for all type of axel data.
axlSphere & operator=(const axlSphere &other)
Assigns other to this sphere and returns a reference to this sphere.