Developer documentation | Axl-2.5.1

axlLine.cpp
Go to the documentation of this file.
1 /* axlLine.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 "axlLine.h"
21 
22 #include "axlPoint.h"
23 
24 #include <dtkCoreSupport/dtkGlobal.h>
25 
26 // /////////////////////////////////////////////////////////////////
27 // axlLinePrivate
28 // /////////////////////////////////////////////////////////////////
29 
30 class axlLinePrivate
31 {
32 public:
33  axlPoint *p1;
34  axlPoint *p2;
35 };
36 
37 // /////////////////////////////////////////////////////////////////
38 // axlLine implementation
39 // /////////////////////////////////////////////////////////////////
40 
42 
47 axlLine::axlLine(QObject *parent) : axlAbstractCurveParametric(), d(new axlLinePrivate)
48 {
49  this->setObjectName(this->identifier());
50 
51  d->p1 = new axlPoint();
52  d->p2 = new axlPoint(1.0, 0.0, 0.0);
53 }
55 
60 axlLine::axlLine(axlPoint *p1, axlPoint *p2, QObject *parent) : axlAbstractCurveParametric(), d(new axlLinePrivate)
61 {
62  this->setObjectName(this->identifier());
63 
64  d->p1 = new axlPoint(p1);
65  d->p2 = new axlPoint(p2);
66 }
67 
69 
74 axlLine::axlLine(const axlPoint& p1, const axlPoint& p2, QObject* parent) : axlAbstractCurveParametric(), d(new axlLinePrivate)
75 {
76  this->setObjectName(this->identifier());
77 
78  d->p1 = new axlPoint(p1);
79  d->p2 = new axlPoint(p2);
80 }
81 
83 
86 axlLine::axlLine(const axlLine& other) : axlAbstractCurveParametric(), d(new axlLinePrivate)
87 {
88  this->setObjectName(this->identifier());
89  this->setParent(other.parent());
90  d->p1 = new axlPoint(other.d->p1);
91  d->p2 = new axlPoint(other.d->p2);
92 }
93 
95 
99 {
100  if (d->p1) {
101  delete(d->p1);
102  d->p1 = NULL;
103  }
104  if (d->p2) {
105  delete(d->p2);
106  d->p2 = NULL;
107  }
108  delete d;
109  d = NULL;
110 }
111 
113 
117 {
118  *(d->p1) = *(other.d->p1);
119  *(d->p2) = *(other.d->p2);
120 
121  return (*this);
122 }
123 
125 
129 {
130  return d->p1;
131 }
132 
134 
138 {
139  return d->p2;
140 }
141 
143 
147 {
148  double x = (firstPoint()->x() + coeff*(secondPoint()->x() - firstPoint()->x()));
149  double y = (firstPoint()->y() + coeff*(secondPoint()->y() - firstPoint()->y()));
150  double z = (firstPoint()->z() + coeff*(secondPoint()->z() - firstPoint()->z()));
151  return new axlPoint(x,y,z);
152 }
153 
155 
159 {
160  double x = (firstPoint()->x() + 0.5*(secondPoint()->x() - firstPoint()->x()));
161  double y = (firstPoint()->y() + 0.5*(secondPoint()->y() - firstPoint()->y()));
162  double z = (firstPoint()->z() + 0.5*(secondPoint()->z() - firstPoint()->z()));
163  return new axlPoint(x,y,z);
164 }
165 
167 
171 {
172  *(d->p1) = *p1;
173  *(d->p2) = *p2;
174  //this->touchGeometry();
175 
176 }
177 
179 
183 {
184  *(d->p1) = *p1;
185  //this->touchGeometry();
186 }
187 
189 
193 {
194  *(d->p2) = *p2;
195  //this->touchGeometry();
196 }
197 
199 
202 void axlLine::setFirstPoint(double *p1)
203 {
204  d->p1->coordinates()[0] = p1[0];
205  d->p1->coordinates()[1] = p1[1];
206  d->p1->coordinates()[2] = p1[2];
207  //this->touchGeometry();
208 }
209 
211 
214 void axlLine::setSecondPoint(double *p2)
215 {
216  d->p2->coordinates()[0] = p2[0];
217  d->p2->coordinates()[1] = p2[1];
218  d->p2->coordinates()[2] = p2[2];
219  //this->touchGeometry();
220 }
221 
223 
226 void axlLine::touchFirstPoint(const axlPoint &point) {
227  setFirstPoint(point.coordinates());
228 
229  this->touchGeometry();
230 }
231 
233 
237  setSecondPoint(point.coordinates());
238 
239  this->touchGeometry();
240 }
241 
242 void axlLine::applyMatrix(double* matrix) {
243  d->p1->transformAsPoint(matrix);
244  d->p2->transformAsPoint(matrix);
245  this->touchGeometry();
246 }
247 
249 
253 {
254  double a = 0.5*((secondPoint()->y() - firstPoint()->y())/(secondPoint()->x() - firstPoint()->x()));
255  return a;
256 }
257 
259 
263 {
264  double b = firstPoint()->y() - planeDirection()*firstPoint()->x();
265  return b;
266 }
267 
268 // /////////////////////////////////////////////////////////////////
269 // Debug operators
270 // /////////////////////////////////////////////////////////////////
271 
272 QDebug operator<<(QDebug dbg, axlLine line)
273 {
274  dbg.nospace() << line.description();
275 
276  return dbg.space();
277 }
278 
279 QDebug operator<<(QDebug dbg, axlLine& line)
280 {
281  dbg.nospace() << line.description();
282 
283  return dbg.space();
284 }
285 
286 QDebug operator<<(QDebug dbg, axlLine *line)
287 {
288  dbg.nospace() << line->description();
289 
290  return dbg.space();
291 }
292 
293 QString axlLine::description(void) const
294 {
295  QString result = "axlLine";
296  result.append("\nfirstPoint : "+d->p1->description() + "\nsecondPoint : "+d->p2->description());
297  return result;
298 }
299 
300 QString axlLine::identifier(void) const
301 {
302  return "axlLine";
303 }
304 
305 //SLOT
307 {
308  *(d->p1) = *p1;
309  //this->touchGeometry();
310 }
311 
313 {
314  *(d->p2) = *p2;
315  //this->touchGeometry();
316 }
317 
318 
319 QVariantList axlLine::convertDataToQVariant(void) const{
320  QVariantList list;
321  QVariant id = QVariant::fromValue(identifier());
322  QVariantList point1 = d->p1->convertDataToQVariant();
323  QVariantList point2 = d->p2->convertDataToQVariant();
324  list.append(id);
325  list.append(point1);
326  list.append(point2);
327  QVariant name = QVariant::fromValue(objectName());
328  list.append(name);
329  return list;
330 
331 }
332 
333 int axlLine::convertQVariantToData(const QVariantList &data){
334  QVariantList point1;
335  point1.append(data.at(1));
336  point1.append(data.at(2));
337  point1.append(data.at(3));
338  point1.append(data.at(4));
339  point1.append(data.at(5));
340  d->p1->convertQVariantToData(point1);
341  QVariantList point2;
342  point2.append(data.at(6));
343  point2.append(data.at(7));
344  point2.append(data.at(8));
345  point2.append(data.at(9));
346  point2.append(data.at(10));
347  d->p2->convertQVariantToData(point2);
348  setObjectName(data.last().toString());
349  return 1;
350 }
351 
352 //to be registered to the data factory.
353 dtkAbstractData *createaxlLine(void)
354 {
355  return new axlLine;
356 }
357 
358 
359 // /////////////////////////////////////////////////////////////////
360 // axlLine documentation
361 // /////////////////////////////////////////////////////////////////
362 
void touchGeometry(void)
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
Definition: axlLine.cpp:333
Class axlLine defines 3D lines.
Definition: axlLine.h:35
double * coordinates(void) const
Returns coordinates of this point.
Definition: axlPoint.cpp:445
QVariantList convertDataToQVariant(void) const
Convert an axlAbstractData into a QVariantList that specifies all properties of the axlAbstractData...
Definition: axlLine.cpp:319
~axlLine(void)
Destroys the axel line.
Definition: axlLine.cpp:98
axlPoint * secondPoint(void) const
Returns second point of the line.
Definition: axlLine.cpp:137
axlPoint * getMiddlePoint(void)
Returns the center point of the line.
Definition: axlLine.cpp:158
void touchFirstPoint(const axlPoint &point)
Change first point of this line and emit using touchGeometry.
Definition: axlLine.cpp:226
virtual QString description(void) const
Definition: axlLine.cpp:293
axlPoint point2
Definition: axlLine.h:39
axlPoint * getBarycenterPoint(double coeff)
Returns a barycenter point of the line.
Definition: axlLine.cpp:146
void onFirstPointChanged(axlPoint *p1)
Definition: axlLine.cpp:306
void applyMatrix(double *matrix)
Definition: axlLine.cpp:242
axlPoint point1
Definition: axlLine.h:39
Generic interface for parametric curve.
axlPoint * firstPoint(void) const
Returns first point of the line.
Definition: axlLine.cpp:128
double planeDirection(void)
compute the direction value of the line ie a in y = ax + b.
Definition: axlLine.cpp:252
axlLine & operator=(const axlLine &other)
Assigns other to this line and returns a reference to this line.
Definition: axlLine.cpp:116
void setSecondPoint(axlPoint *p2)
Change second point of this line.
Definition: axlLine.cpp:192
void touchSecondPoint(const axlPoint &point)
Change second point of this line and emit using touchGeometry.
Definition: axlLine.cpp:236
void setFirstPoint(axlPoint *p1)
Change first point of this line.
Definition: axlLine.cpp:182
virtual QString identifier(void) const
Definition: axlLine.cpp:300
void onSecondPointChanged(axlPoint *p2)
Definition: axlLine.cpp:312
axlLine(QObject *parent=0)
Constructs a axel line of with firstPoint and second point are NULL with parent parent of QObject typ...
Definition: axlLine.cpp:47
dtkAbstractData * createaxlLine(void)
Definition: axlLine.cpp:353
double y
Definition: axlPoint.h:37
double z
Definition: axlPoint.h:38
double planeOrigineOrdinate(void)
compute the b value of the line y = ax + b.
Definition: axlLine.cpp:262
void setValues(axlPoint *p1, axlPoint *p2)
Change first point and second point of this line.
Definition: axlLine.cpp:170
double x
Definition: axlPoint.h:37
QDebug operator<<(QDebug dbg, axlLine line)
Definition: axlLine.cpp:272