Developer documentation | Axl-2.5.1

axlConeParametric.cpp
Go to the documentation of this file.
1 /* axlConeParametric.cpp ---
2  *
3  * Author: Hung NGUYEN.
4  */
5 
6 /* Commentary:
7  *
8  */
9 
10 /* Change log:
11  *
12  */
13 
14 #include "axlConeParametric.h"
15 #include "axlCone.h"
16 #include "axlPoint.h"
17 
18 #include <dtkCoreSupport/dtkGlobal.h>
19 
20 // /////////////////////////////////////////////////////////////////
21 // axlConeParametricPrivate
22 // /////////////////////////////////////////////////////////////////
23 
24 class axlConeParametricPrivate {
25 public:
26  axlCone* cone;
27  axlPoint* v;
28  axlPoint* r;
29  axlPoint* w;
30 };
31 
32 // /////////////////////////////////////////////////////////////////
33 // axlConeParametric implementation
34 // /////////////////////////////////////////////////////////////////
35 
38  d(new axlConeParametricPrivate) {
39 
40  DTK_UNUSED(parent);
41 
42  this->setObjectName(this->identifier());
43 
44  d->cone = new axlCone;
45  d->v = new axlPoint(*(d->cone->apex()) - (d->cone->basePoint()));
46  d->v->normalize();
47  d->r = new axlPoint;
48  d->w = new axlPoint;
49 }
50 
53  d(new axlConeParametricPrivate) {
54 
55  this->setObjectName(this->identifier());
56 
57  d->cone = new axlCone(*cone);
58  d->v = new axlPoint(*(d->cone->apex()) - (d->cone->basePoint()));
59  d->v->normalize();
60  d->r = new axlPoint(r);
61  d->r->normalize();
62  d->w = new axlPoint(axlPoint::crossProduct(d->v, r));
63  d->w->normalize();
64 }
65 
68  d(new axlConeParametricPrivate) {
69 
70  this->setObjectName(this->identifier());
71 
72  d->cone = new axlCone(cone);
73  d->v = new axlPoint(*(d->cone->apex()) - *(d->cone->basePoint()));
74  d->v->normalize();
75  d->r = new axlPoint(r);
76  d->r->normalize();
77  d->w = new axlPoint(axlPoint::crossProduct(d->v, r));
78  d->w->normalize();
79 }
80 
83  d(new axlConeParametricPrivate) {
84 
85  this->setObjectName(this->identifier());
86  this->setParent(other.parent());
87 
88  d->cone = new axlCone(other.d->cone);
89  d->v = new axlPoint(other.d->v);
90  d->v->normalize();
91  d->r = new axlPoint(other.d->r);
92  d->r->normalize();
93  d->w = new axlPoint(other.d->w);
94  d->w->normalize();
95 }
96 
98  delete d->cone;
99  d->cone = NULL;
100  delete d->v;
101  d->v = NULL;
102  delete d->r;
103  d->r = NULL;
104  delete d->w;
105  d->w = NULL;
106 
107  delete d;
108  d = NULL;
109 }
110 
111 QString axlConeParametric::description(void) const {
112  QString result = "axlConeParametric";
113  result.append("\nCone :\n" + d->cone->description()
114  + "\nv :\n" + d->v->description()
115  + "\nr :\n" + d->r->description()
116  + "\nw :\n" + d->w->description());
117  return result;
118 }
119 
120 QString axlConeParametric::identifier(void) const {
121  return "axlConeParametric";
122 }
123 
125  return d->r;
126 }
127 
129  *(d->r) = *r;
130  d->r->normalize();
131  *(d->w) = axlPoint::crossProduct(*(d->v), *(d->r));
132  d->w->normalize();
133 }
134 
136  *(d->cone) = *(other.d->cone);
137  *(d->v) = *(other.d->v);
138  *(d->r) = *(other.d->r);
139  *(d->w) = *(other.d->w);
140 
141  return *this;
142 }
143 
144 void axlConeParametric::modifyR(double* r) {
145  d->r->coordinates()[0] = r[0];
146  d->r->coordinates()[1] = r[1];
147  d->r->coordinates()[2] = r[2];
148 }
149 
151  return d->cone;
152 }
153 
155  *(d->cone) = cone;
156  *(d->v) = (*(cone.apex()) - *(cone.basePoint()));
157  d->v->normalize();
158  *(d->w) = axlPoint::crossProduct(*(d->v), *(d->r));
159  d->w->normalize();
160 }
161 
162 axlPoint axlConeParametric::eval(double u, double v) {
163  double height = axlPoint::distance(d->cone->apex(),d->cone->basePoint());
164  return *(d->cone->basePoint()) + *(d->v)*(height - height*u/d->cone->radius())*std::cos(v) + *(d->r)*(height - height*u/d->cone->radius())*std::sin(v) + *(d->w)*u;
165 }
166 
167 void axlConeParametric::eval(axlPoint *point, double u,double v) {
168  double height = axlPoint::distance(d->cone->apex(),d->cone->basePoint());
169  axlPoint p(*(d->cone->basePoint()) + *(d->v)*(height - height*u/d->cone->radius())*std::cos(v) + *(d->r)*(height - height*u/d->cone->radius())*std::sin(v) + *(d->w)*u);
170  point->setCoordinates(p.x(), p.y(), p.z());
171 }
172 
173 void axlConeParametric::eval(double& x, double& y, double& z, double u,double v) {
174  double height = axlPoint::distance(d->cone->apex(),d->cone->basePoint());
175  axlPoint p(*(d->cone->basePoint()) + *(d->v)*(height - height*u/d->cone->radius())*std::cos(v) + *(d->r)*(height - height*u/d->cone->radius())*std::sin(v) + *(d->w)*u);
176  x = p.x();
177  y = p.y();
178  z = p.z();
179 }
180 
181 void axlConeParametric::parameterOf(const axlPoint& point, double& um, double& vm) {
182  axlPoint* o = d->cone->basePoint();
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->cone) = *cone;
195 }
196 
198  *(d->r) = *r;
199 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void onConeChanged(axlCone *cone)
void onRChanged(axlPoint *r)
axlPoint apex
Definition: axlCone.h:37
axlConeParametric & operator=(const axlConeParametric &other)
virtual QString identifier(void) const
axlPoint basePoint
Definition: axlCone.h:37
axlCone * getCone(void) const
virtual axlPoint eval(double u, double v)
axlConeParametric(axlAbstractSurfaceParametric *parent=0)
static double dotProduct(const axlPoint &lhs, const axlPoint &rhs)
Definition: axlPoint.cpp:508
void modifyR(double *r)
virtual void parameterOf(const axlPoint &point, double &um, double &vm)
axlPoint * getR(void) const
void setCone(axlCone *cone)
Class axlCone defines 3D cones.
Definition: axlCone.h:34
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
void setCoordinates(double x, double y, double z)
Change coordinates of this point.
Definition: axlPoint.cpp:370
virtual ~axlConeParametric(void)
void setR(axlPoint *r)
virtual QString description(void) const