Developer documentation | Axl-2.5.1

axlCylinderParametric.cpp
Go to the documentation of this file.
1 /* axlCylinderParametric.cpp ---
2  *
3  * Author: Valentin Michelet
4  * Copyright (C) 2008-2013 - Valentin Michelet, Inria.
5  * Created: Wed Jul 26 16:58:59 2013 (+0100)
6  * Version: $Id$
7  */
8 
9 /* Commentary:
10  *
11  */
12 
13 /* Change log:
14  *
15  */
16 
17 #include "axlCylinderParametric.h"
18 #include "axlCylinder.h"
19 #include "axlPoint.h"
20 
21 #include <dtkCoreSupport/dtkGlobal.h>
22 
23 // /////////////////////////////////////////////////////////////////
24 // axlCylinderParametricPrivate
25 // /////////////////////////////////////////////////////////////////
26 
27 class axlCylinderParametricPrivate {
28 public:
29  axlCylinder* cylinder;
30  axlPoint* v;
31  axlPoint* r;
32  axlPoint* w;
33 };
34 
35 // /////////////////////////////////////////////////////////////////
36 // axlCylinderParametric implementation
37 // /////////////////////////////////////////////////////////////////
38 
41  d(new axlCylinderParametricPrivate) {
42 
43  DTK_UNUSED(parent);
44 
45  this->setObjectName(this->identifier());
46 
47  d->cylinder = new axlCylinder;
48  d->v = new axlPoint(*(d->cylinder->secondPoint()) - (d->cylinder->firstPoint()));
49  d->v->normalize();
50  d->r = new axlPoint;
51  d->w = new axlPoint;
52 }
53 
56  d(new axlCylinderParametricPrivate) {
57 
58  this->setObjectName(this->identifier());
59 
60  d->cylinder = new axlCylinder(*cylinder);
61  d->v = new axlPoint(*(d->cylinder->secondPoint()) - (d->cylinder->firstPoint()));
62  d->v->normalize();
63  d->r = new axlPoint(r);
64  d->r->normalize();
65  d->w = new axlPoint(axlPoint::crossProduct(d->v, r));
66  d->w->normalize();
67 }
68 
71  d(new axlCylinderParametricPrivate) {
72 
73  this->setObjectName(this->identifier());
74 
75  d->cylinder = new axlCylinder(cylinder);
76  d->v = new axlPoint(*(d->cylinder->secondPoint()) - (d->cylinder->firstPoint()));
77  d->v->normalize();
78  d->r = new axlPoint(r);
79  d->r->normalize();
80  d->w = new axlPoint(axlPoint::crossProduct(d->v, r));
81  d->w->normalize();
82 }
83 
86  d(new axlCylinderParametricPrivate) {
87 
88  this->setObjectName(this->identifier());
89  this->setParent(other.parent());
90 
91  d->cylinder = new axlCylinder(other.d->cylinder);
92  d->v = new axlPoint(other.d->v);
93  d->v->normalize();
94  d->r = new axlPoint(other.d->r);
95  d->r->normalize();
96  d->w = new axlPoint(other.d->w);
97  d->w->normalize();
98 }
99 
101  delete d->cylinder;
102  d->cylinder = NULL;
103  delete d->v;
104  d->v = NULL;
105  delete d->r;
106  d->r = NULL;
107  delete d->w;
108  d->w = NULL;
109 
110  delete d;
111  d = NULL;
112 }
113 
115  QString result = "axlCylinderParametric";
116  result.append("\nCylinder :\n" + d->cylinder->description()
117  + "\nv :\n" + d->v->description()
118  + "\nr :\n" + d->r->description()
119  + "\nw :\n" + d->w->description());
120  return result;
121 }
122 
124  return "axlCylinderParametric";
125 }
126 
128  return d->r;
129 }
130 
132  *(d->r) = *r;
133  d->r->normalize();
134  *(d->w) = axlPoint::crossProduct(*(d->v), *(d->r));
135  d->w->normalize();
136 }
137 
139  *(d->cylinder) = *(other.d->cylinder);
140  *(d->v) = *(other.d->v);
141  *(d->r) = *(other.d->r);
142  *(d->w) = *(other.d->w);
143 
144  return *this;
145 }
146 
148  d->r->coordinates()[0] = r[0];
149  d->r->coordinates()[1] = r[1];
150  d->r->coordinates()[2] = r[2];
151 }
152 
154  return d->cylinder;
155 }
156 
158  *(d->cylinder) = cylinder;
159  *(d->v) = (*(cylinder.secondPoint()) - *(cylinder.firstPoint()));
160  d->v->normalize();
161  *(d->w) = axlPoint::crossProduct(*(d->v), *(d->r));
162  d->w->normalize();
163 }
164 
166  return *(d->cylinder->firstPoint()) + *(d->v)*u + *(d->r)*d->cylinder->radius()*std::cos(v) + *(d->w)*d->cylinder->radius()*std::sin(v);
167 }
168 
169 void axlCylinderParametric::eval(axlPoint *point, double u,double v) {
170  axlPoint p(*(d->cylinder->firstPoint()) + *(d->v)*u + *(d->r)*d->cylinder->radius()*std::cos(v) + *(d->w)*d->cylinder->radius()*std::sin(v));
171  point->setCoordinates(p.x(), p.y(), p.z());
172 }
173 
174 void axlCylinderParametric::eval(double& x, double& y, double& z, double u,double v) {
175  axlPoint p(*(d->cylinder->firstPoint()) + *(d->v)*u + *(d->r)*d->cylinder->radius()*std::cos(v) + *(d->w)*d->cylinder->radius()*std::sin(v));
176  x = p.x();
177  y = p.y();
178  z = p.z();
179 }
180 
181 void axlCylinderParametric::parameterOf(const axlPoint& point, double& um, double& vm) {
182  axlPoint* o = d->cylinder->firstPoint();
183 
184  axlPoint op = point - *o;
185  um = axlPoint::dotProduct(op, d->v);
186  vm = std::atan2(axlPoint::dotProduct(op, d->w), axlPoint::dotProduct(op, d->r));
187 }
188 
189 
190 // /////////////////////
191 // Slots
192 // /////////////////////
194  *(d->cylinder) = *cylinder;
195 }
196 
198  *(d->r) = *r;
199 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
axlCylinderParametric & operator=(const axlCylinderParametric &other)
axlPoint * secondPoint(void) const
Returns second point of the cylinder.
Class axlCylinder defines 3D cylinders.
Definition: axlCylinder.h:33
axlPoint * firstPoint(void) const
Returns first point of the cylinder.
virtual void parameterOf(const axlPoint &point, double &um, double &vm)
void onCylinderChanged(axlCylinder *cylinder)
axlCylinderParametric(axlAbstractSurfaceParametric *parent=0)
virtual QString identifier(void) const
static double dotProduct(const axlPoint &lhs, const axlPoint &rhs)
Definition: axlPoint.cpp:508
virtual axlPoint eval(double u, double v)
void setCylinder(axlCylinder *cylinder)
virtual QString description(void) const
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
Definition: axlPoint.cpp:485
axlCylinder * getCylinder(void) const
double x
Definition: axlPoint.h:37
void setCoordinates(double x, double y, double z)
Change coordinates of this point.
Definition: axlPoint.cpp:370
axlPoint * getR(void) const