Developer documentation | Axl-2.5.1

axlCircleArc.cpp
Go to the documentation of this file.
1 /* axlCircleArc.cpp ---
2  *
3  * Author: Valentin Michelet
4  * Copyright (C) 2008 - Valentin Michelet, 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: Valentin Michelet
9  * Update #: 19
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlCircleArc.h"
21 
22 #include "axlPoint.h"
23 
24 #include <dtkCoreSupport/dtkGlobal.h>
25 
26 
27 // /////////////////////////////////////////////////////////////////
28 // axlCircleArcPrivate
29 // /////////////////////////////////////////////////////////////////
30 
31 class axlCircleArcPrivate {
32 public:
33  axlPoint point1;
34  axlPoint point2;
35  axlPoint normal;
36  axlPoint center;
37 
38  bool direct;
39 };
40 
41 // /////////////////////////////////////////////////////////////////
42 // axlCircleArc implementation
43 // /////////////////////////////////////////////////////////////////
44 
45 axlCircleArc::axlCircleArc(QObject *parent) :
47  d(new axlCircleArcPrivate) {
48 
49  this->setObjectName(this->identifier());
50 
51  d->point1 = axlPoint();
52  d->point2 = axlPoint();
53  d->center = axlPoint();
54  d->normal = axlPoint();
55 
56  d->direct = true;
57 }
58 
59 axlCircleArc::axlCircleArc(const axlPoint& point1, const axlPoint& point2, const axlPoint& center, const axlPoint& normal, bool direct) :
61  d(new axlCircleArcPrivate) {
62 
63  this->setObjectName(this->identifier());
64 
65  d->point1 = axlPoint(point1);
66  d->point2 = axlPoint(point2);
67  d->center = axlPoint(center);
68  d->normal = axlPoint(normal);
69 
70  d->direct = direct;
71 
73 }
74 
77  d(new axlCircleArcPrivate) {
78 
79  this->setObjectName(this->identifier());
80  this->setParent(other.parent());
81  d->point1 = other.d->point1;
82  d->point2 = other.d->point2;
83  d->center = other.d->center;
84  d->normal = other.d->normal;
85 
86  d->direct = other.d->direct;
87 }
88 
90  delete d;
91  d = NULL;
92 }
93 
94 QString axlCircleArc::description(void) const {
95  QString res = "axlCircleArc";
96  res.append("\nPoint1: " + d->point1.description());
97  res.append("\nPoint2: " + d->point2.description());
98  res.append("\nNormal: " + d->normal.description());
99  res.append("\nCenter: " + d->center.description());
100  res.append("\nDirect: " + QString::number(d->direct));
101  res.append("\nRadius: " + QString::number(calculateRadius()));
102  return res;
103 }
104 
105 QString axlCircleArc::identifier(void) const {
106  return "axlCircleArc";
107 }
108 
109 double axlCircleArc::calculateRadius(void) const {
110  return axlPoint::distance(d->point1, d->center);
111 }
112 
114  int direct = -1;
115  if (d->direct)
116  direct = 1;
117  return axlPoint::crossProduct(d->point1-d->center, d->point2-d->center) * direct;
118 }
119 
121  return d->point1;
122 }
123 
125  return d->point2;
126 }
127 
129  return d->normal;
130 }
131 
133  return d->center;
134 }
135 
136 bool axlCircleArc::isDirect(void) const {
137  return d->direct;
138 }
139 
140 void axlCircleArc::setValues(const axlPoint& point1, const axlPoint& point2, const axlPoint& center, const axlPoint& normal, bool direct) {
141  d->point1 = point1;
142  d->point2 = point2;
143  d->center = center;
144  d->normal = normal;
145 
146  d->direct = direct;
147  axlPoint newNormal = calculateNormal().normalized();
148  if (newNormal.norm() > 0.001)
149  setNormal(newNormal);
150 }
151 
152 void axlCircleArc::setPoint1(const axlPoint& point1) {
153  d->point1 = point1;
154 }
155 
156 void axlCircleArc::setPoint2(const axlPoint& point2) {
157  d->point2 = point2;
158 }
159 
160 void axlCircleArc::setCenter(const axlPoint& center) {
161  d->center = center;
162 }
163 
164 void axlCircleArc::setNormal(const axlPoint& normal) {
165  d->normal = normal;
166 }
167 
168 void axlCircleArc::setDirect(bool direct) {
169  d->direct = direct;
170 }
171 
172 void axlCircleArc::modifyPoint1(double* point1) {
173  d->point1.coordinates()[0] = point1[0];
174  d->point1.coordinates()[1] = point1[1];
175  d->point1.coordinates()[2] = point1[2];
176 }
177 
178 void axlCircleArc::modifyPoint2(double* point2) {
179  d->point2.coordinates()[0] = point2[0];
180  d->point2.coordinates()[1] = point2[1];
181  d->point2.coordinates()[2] = point2[2];
182 }
183 
184 void axlCircleArc::modifyCenter(double *center) {
185  d->center.coordinates()[0] = center[0];
186  d->center.coordinates()[1] = center[1];
187  d->center.coordinates()[2] = center[2];
188 }
189 
190 void axlCircleArc::modifyNormal(double* normal) {
191  d->normal.coordinates()[0] = normal[0];
192  d->normal.coordinates()[1] = normal[1];
193  d->normal.coordinates()[2] = normal[2];
194 }
195 
197  d->point1 = other.d->point1;
198  d->point2 = other.d->point2;
199  d->normal = other.d->normal;
200  d->center = other.d->center;
201 
202  d->direct = other.d->direct;
203 
204  return (*this);
205 }
206 
207 QDebug operator<<(QDebug dbg, axlCircleArc arc) {
208  dbg.nospace() << arc.description();
209  return dbg.space();
210 }
211 
212 QDebug operator<<(QDebug dbg, axlCircleArc& arc) {
213  dbg.nospace() << arc.description();
214  return dbg.space();
215 }
216 
217 QDebug operator<<(QDebug dbg, axlCircleArc* arc) {
218  dbg.nospace() << arc->description();
219  return dbg.space();
220 }
221 
222 void axlCircleArc::applyMatrix(double* matrix) {
223  d->point1.transformAsPoint(matrix);
224  d->point2.transformAsPoint(matrix);
225  d->center.transformAsPoint(matrix);
226  d->normal.transformAsVector(matrix);
227 }
228 
230  d->point1.x() = x;
231 }
232 
234  d->point1.y() = y;
235 }
236 
238  d->point1.z() = z;
239 }
240 
242  d->point2.x() = x;
243 }
244 
246  d->point2.y() = y;
247 }
248 
250  d->point2.z() = z;
251 }
252 
254  d->center.x() = x;
255 }
256 
258  d->center.y() = y;
259 }
260 
262  d->center.z() = z;
263 }
264 
266  d->normal.x() = x;
267 }
268 
270  d->normal.y() = y;
271 }
272 
274  d->normal.z() = z;
275 }
276 
277 void axlCircleArc::onDirectChanged(bool direct) {
278  d->direct = direct;
279  axlPoint newNormal = calculateNormal().normalized();
280  if (newNormal.norm() > 0.001)
281  setNormal(newNormal);
282 }
283 
284 QVariantList axlCircleArc::convertDataToQVariant(void) const{
285  QVariantList list;
286  QVariant id = QVariant::fromValue(identifier());
287  QVariant direct = QVariant::fromValue(d->direct);
288  QVariantList center = d->center.convertDataToQVariant();
289  QVariantList point1 = d->point1.convertDataToQVariant();
290  QVariantList point2 = d->point2.convertDataToQVariant();
291  QVariantList normal = d->normal.convertDataToQVariant();
292  list.append(id);
293  list.append(center);
294  list.append(point1);
295  list.append(point2);
296  list.append(normal);
297  list.append(direct);
298  QVariant name = QVariant::fromValue(objectName());
299  list.append(name);
300  return list;
301 
302 }
303 
304 int axlCircleArc::convertQVariantToData(const QVariantList& data){
305  QVariantList center;
306  center.append(data.at(1));
307  center.append(data.at(2));
308  center.append(data.at(3));
309  center.append(data.at(4));
310  center.append(data.at(5));
311  d->center.convertQVariantToData(center);
312  QVariantList point1;
313  point1.append(data.at(6));
314  point1.append(data.at(7));
315  point1.append(data.at(8));
316  point1.append(data.at(9));
317  point1.append(data.at(10));
318  d->point1.convertQVariantToData(point1);
319  QVariantList point2;
320  point2.append(data.at(11));
321  point2.append(data.at(12));
322  point2.append(data.at(13));
323  point2.append(data.at(14));
324  point2.append(data.at(15));
325  d->point2.convertQVariantToData(point2);
326  QVariantList normal;
327  normal.append(data.at(16));
328  normal.append(data.at(17));
329  normal.append(data.at(18));
330  normal.append(data.at(19));
331  normal.append(data.at(20));
332  d->normal.convertQVariantToData(normal);
333  setDirect(data.at(21).toBool());
334  setObjectName(data.last().toString());
335  return 1;
336 }
337 
338 //to be registered to the data factory.
339 dtkAbstractData *createaxlCircleArc(void)
340 {
341  return new axlCircleArc;
342 }
bool isDirect(void) const
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void onCenterZChanged(double z)
virtual ~axlCircleArc(void)
void onPoint1XChanged(double x)
axlPoint point1(void) const
virtual QString identifier(void) const
void modifyCenter(double *center)
void setValues(const axlPoint &point1, const axlPoint &point2, const axlPoint &center, const axlPoint &normal, bool direct=true)
void modifyPoint2(double *point2)
double calculateRadius(void) const
void setCenter(const axlPoint &center)
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
void onNormalYChanged(double y)
void setDirect(bool direct)
void onPoint2XChanged(double x)
void onNormalZChanged(double z)
axlCircleArc(QObject *parent=0)
axlPoint center(void) const
void onNormalXChanged(double x)
void applyMatrix(double *matrix)
void modifyNormal(double *normal)
void onCenterYChanged(double y)
axlCircleArc & operator=(const axlCircleArc &other)
void modifyPoint1(double *point1)
QDebug operator<<(QDebug dbg, axlCircleArc arc)
Generic interface for parametric curve.
dtkAbstractData * createaxlCircleArc(void)
virtual void onDirectChanged(bool direct)
double norm(void) const
Definition: axlPoint.cpp:450
axlPoint point2(void) const
void onPoint2YChanged(double y)
axlPoint & normalized(void)
Definition: axlPoint.cpp:421
void setPoint1(const axlPoint &point1)
axlPoint calculateNormal(void) const
virtual QString description(void) const
void onCenterXChanged(double x)
void setPoint2(const axlPoint &point2)
axlPoint normal(void) const
void onPoint1YChanged(double y)
void onPoint1ZChanged(double z)
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
Definition: axlPoint.cpp:485
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.
Definition: axlPoint.cpp:459
QVariantList convertDataToQVariant(void) const
Convert an axlAbstractData into a QVariantList that specifies all properties of the axlAbstractData...
void onPoint2ZChanged(double z)
void setNormal(const axlPoint &normal)