Developer documentation | Axl-2.5.1

axlTorusParametric.cpp
Go to the documentation of this file.
1 /* axlTorusParametric.cpp ---
2  *
3  * Author: Valentin Michelet
4  * Copyright (C) 2008-2013 - Valentin Michelet, Inria.
5  * Created: Tue Jul 30 16:58:59 2013 (+0100)
6  * Version: $Id$
7  */
8 
9 /* Commentary:
10  *
11  */
12 
13 /* Change log:
14  *
15  */
16 
17 #include "axlTorusParametric.h"
18 #include "axlTorus.h"
19 #include "axlPoint.h"
20 
21 #include <dtkCoreSupport/dtkGlobal.h>
22 
23 #ifndef M_PI
24 # define M_PI 3.14159265358979323846
25 #endif
26 
27 #ifndef M_PI_2
28 # define M_PI_2 1.57079632679489661923
29 #endif
30 
31 // /////////////////////////////////////////////////////////////////
32 // axlTorusParametricPrivate
33 // /////////////////////////////////////////////////////////////////
34 
35 class axlTorusParametricPrivate {
36 public:
37  axlTorus* torus;
38  axlPoint* v;
39  axlPoint* r;
40  axlPoint* w;
41 };
42 
43 // /////////////////////////////////////////////////////////////////
44 // axlTorusParametric implementation
45 // /////////////////////////////////////////////////////////////////
46 
49  d(new axlTorusParametricPrivate) {
50 
51  DTK_UNUSED(parent);
52 
53  this->setObjectName(this->identifier());
54 
55  d->torus = new axlTorus;
56  d->v = new axlPoint(*d->torus->direction());
57  d->v->normalize();
58  d->r = new axlPoint;
59  d->w = new axlPoint;
60 }
61 
64  d(new axlTorusParametricPrivate) {
65 
66  this->setObjectName(this->identifier());
67 
68  d->torus = new axlTorus(*torus);
69  d->v = new axlPoint(*d->torus->direction());
70  d->v->normalize();
71  d->r = new axlPoint(r);
72  d->r->normalize();
73  d->w = new axlPoint(axlPoint::crossProduct(d->v, r));
74  d->w->normalize();
75 }
76 
79  d(new axlTorusParametricPrivate) {
80 
81  this->setObjectName(this->identifier());
82 
83  d->torus = new axlTorus(torus);
84  d->v = new axlPoint(*torus.direction());
85  d->v->normalize();
86  d->r = new axlPoint(r);
87  d->r->normalize();
88  d->w = new axlPoint(axlPoint::crossProduct(d->v, r));
89  d->w->normalize();
90 }
91 
94  d(new axlTorusParametricPrivate) {
95 
96  this->setObjectName(this->identifier());
97  this->setParent(other.parent());
98 
99  d->torus = new axlTorus(other.d->torus);
100  d->v = new axlPoint(other.d->v);
101  d->v->normalize();
102  d->r = new axlPoint(other.d->r);
103  d->r->normalize();
104  d->w = new axlPoint(other.d->w);
105  d->w->normalize();
106 }
107 
109  delete d->torus;
110  d->torus = NULL;
111  delete d->v;
112  d->v = NULL;
113  delete d->r;
114  d->r = NULL;
115  delete d->w;
116  d->w = NULL;
117 
118  delete d;
119  d = NULL;
120 }
121 
122 QString axlTorusParametric::description(void) const {
123  QString result = "axlTorusParametric";
124  result.append("\nTorus : " + d->torus->description()
125  + "\nv : " + d->v->description()
126  + "\nr : " + d->r->description()
127  + "\nw : " + d->w->description());
128  return result;
129 }
130 
131 QString axlTorusParametric::identifier(void) const {
132  return "axlTorusParametric";
133 }
134 
136  return d->v;
137 }
138 
140  return d->r;
141 }
142 
144  return d->w;
145 }
146 
148  *(d->torus) = torus;
149  *(d->v) = (*(torus.direction()));
150  d->v->normalize();
151  *(d->w) = axlPoint::crossProduct(*(d->v), *(d->r));
152  d->w->normalize();
153 }
154 
156  *(d->r) = *r;
157  r->normalize();
158  *(d->w) = axlPoint::crossProduct(*(d->v), *(d->r));
159  d->w->normalize();
160 }
161 
163  *(d->torus) = *(other.d->torus);
164  *(d->v) = *(other.d->v);
165  *(d->r) = *(other.d->r);
166  *(d->w) = *(other.d->w);
167 
168  return *this;
169 }
170 
172  d->r->coordinates()[0] = r[0];
173  d->r->coordinates()[1] = r[1];
174  d->r->coordinates()[2] = r[2];
175 }
176 
178  return d->torus;
179 }
180 
181 axlPoint axlTorusParametric::eval(double u, double v) {
182  double r = d->torus->crossSectionRadius();
183  double a = d->torus->ringRadius();
184 
185  return *(d->torus->centerPoint()) + *(d->r)*(a + r*std::cos(u))*std::cos(v)
186  + *(d->w)*(a + r*std::cos(u))*std::sin(v)
187  + *(d->v)*r*sin(u);
188 }
189 
190 void axlTorusParametric::eval(axlPoint *point, double u,double v) {
191  double r = d->torus->crossSectionRadius();
192  double a = d->torus->ringRadius();
193 
194  axlPoint p(*(d->torus->centerPoint()) + *(d->r)*(a + r*std::cos(u))*std::cos(v)
195  + *(d->w)*(a + r*std::cos(u))*std::sin(v)
196  + *(d->v)*r*sin(u));
197 
198  point->setCoordinates(p.x(), p.y(), p.z());
199 }
200 
201 void axlTorusParametric::eval(double& x, double& y, double& z, double u,double v) {
202  double r = d->torus->crossSectionRadius();
203  double a = d->torus->ringRadius();
204 
205  axlPoint p(*(d->torus->centerPoint()) + *(d->r)*(a + r*std::cos(u))*std::cos(v)
206  + *(d->w)*(a + r*std::cos(u))*std::sin(v)
207  + *(d->v)*r*sin(u));
208 
209  x = p.x();
210  y = p.y();
211  z = p.z();
212 }
213 
214 void axlTorusParametric::parameterOf(const axlPoint& point, double& um, double& vm) {
215  double a = d->torus->ringRadius();
216  double r = d->torus->crossSectionRadius();
217 
218  axlPoint* o = d->torus->centerPoint();
219 
220  axlPoint op = point - *o;
221 
222  double OPi = axlPoint::dotProduct(op, d->r);
223  double OPj = axlPoint::dotProduct(op, d->w);
224  double OPk = axlPoint::dotProduct(op, d->v);
225 
226  double u = std::asin(OPk/r);
227  if (std::sqrt(std::pow(OPi ,2) + std::pow(OPj ,2)) < a)
228  um = M_PI - u;
229  else
230  um = u;
231 
232  if (std::abs(OPi) < 0.001)
233  (OPj < 0) ? (vm = -M_PI_2) : (vm = M_PI_2);
234  else
235  vm = std::atan2(OPj, OPi);
236 }
237 
238 
239 // /////////////////////
240 // Slots
241 // /////////////////////
243  *(d->torus) = *torus;
244 }
245 
247  *(d->r) = *r;
248 }
axlTorus * getTorus(void) const
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
axlPoint * getW(void) const
virtual void parameterOf(const axlPoint &point, double &um, double &vm)
#define M_PI
axlTorusParametric(axlAbstractSurfaceParametric *parent=0)
virtual QString description(void) const
axlPoint * getV(void) const
void setR(axlPoint *r)
virtual QString identifier(void) const
virtual axlPoint eval(double u, double v)
virtual ~axlTorusParametric(void)
void setTorus(const axlTorus &torus)
void normalize(void)
Definition: axlPoint.cpp:410
static double dotProduct(const axlPoint &lhs, const axlPoint &rhs)
Definition: axlPoint.cpp:508
axlPoint direction
Definition: axlTorus.h:30
axlPoint * getR(void) const
void onRChanged(axlPoint *r)
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
Definition: axlPoint.cpp:485
#define M_PI_2
double x
Definition: axlPoint.h:37
void setCoordinates(double x, double y, double z)
Change coordinates of this point.
Definition: axlPoint.cpp:370
axlTorusParametric & operator=(const axlTorusParametric &other)
void onTorusChanged(axlTorus *torus)