Developer documentation | Axl-2.5.1

axlAbstractCurveBSpline.cpp
Go to the documentation of this file.
1 /* axlAbstractCurveBSpline.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Tue Nov 9 17:03:56 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Mon Dec 6 15:42:00 2010 (+0100)
8  * By: Meriadeg Perrinel
9  * Update #: 24
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
21 
22 #include <dtkCoreSupport/dtkGlobal.h>
23 #include <qhash.h>
24 #include <cmath>
25 #include <stdio.h>
26 
27 typedef QMap<double, axlPoint> Sample;
28 
29 class axlPoint;
30 
31 class axlAbstractCurveBSplinePrivate
32 {
33 public:
34  QHash<int, QList<int> > connect;
35 };
36 
37 axlAbstractCurveBSpline::axlAbstractCurveBSpline(void) : axlAbstractCurveParametric(), d(new axlAbstractCurveBSplinePrivate)
38 {
39 
40 }
41 
43 {
44  delete d;
45 
46  d = NULL;
47 }
48 
50 {
51  DTK_DEFAULT_IMPLEMENTATION;
52 
53  return 0;
54 }
55 
57 {
58  DTK_DEFAULT_IMPLEMENTATION;
59 
60  return 0;
61 }
62 
64 {
65  DTK_DEFAULT_IMPLEMENTATION;
66 
67  return 0;
68 }
69 
71 {
72  DTK_DEFAULT_IMPLEMENTATION;
73 
74  return 0;
75 }
76 
77 
79 {
80  DTK_DEFAULT_IMPLEMENTATION;
81 
82  return 0;
83 }
85 {
86  DTK_DEFAULT_IMPLEMENTATION;
87 
88  return 0;
89 }
90 
92 {
93  DTK_DEFAULT_IMPLEMENTATION;
94 
95  return 1;
96 }
97 
98 void axlAbstractCurveBSpline::setCurve(int pointsCount, int order, int dimension, double *knots, double *points, bool rational)
99 {
100  DTK_DEFAULT_IMPLEMENTATION;
101 }
102 
104 {
105  DTK_DEFAULT_IMPLEMENTATION;
106 
107  return axlPoint();
108 }
109 
111 {
112  DTK_DEFAULT_IMPLEMENTATION;
113 
114  return 0;
115 }
116 
117 
119 {
120  DTK_DEFAULT_IMPLEMENTATION;
121 
122  return Sample();
123 }
124 
126 {
127  DTK_DEFAULT_IMPLEMENTATION;
128 
129  return axlPoint();
130 }
131 
132 bool axlAbstractCurveBSpline::setCoef(int n, double *controlPoint)
133 {
134  DTK_DEFAULT_IMPLEMENTATION;
135 
136  return 0;
137 }
138 
139 //Added
141 {
142  DTK_DEFAULT_IMPLEMENTATION;
143 
144  return 1.0;
145 }
146 
147 //Added
149 {
150  DTK_DEFAULT_IMPLEMENTATION;
151 }
152 
154 {
155  DTK_DEFAULT_IMPLEMENTATION;
156 
157  return 0;
158 }
159 
161 {
162  Q_UNUSED(k);
163 }
164 
166 {
167  Q_UNUSED(k);
168 }
169 
170 QString axlAbstractCurveBSpline::printCoeffs(bool print) const
171 {
172  DTK_DEFAULT_IMPLEMENTATION;
173 
174  return "";
175 }
176 
178 {
179  DTK_DEFAULT_IMPLEMENTATION;
180 
181  return "";
182 }
183 
185 {
186  DTK_DEFAULT_IMPLEMENTATION;
187 
188  return "";
189 }
190 
192 
196  return !d->connect.isEmpty();
197 }
198 
200 
204 {
205  d->connect.clear();
206 }
207 
209 
213  return d->connect.value(i);
214 }
215 
216 
218 
222  if(i==j){
223  qDebug() << "The two indices must be different.";
224  }else{
225  int mini = std::min(i,j);
226  int maxi = std::max(i,j);
227 
228  if(d->connect.keys().contains(mini)){
229  QList<int> list = d->connect.value(mini);
230 
231  if(!list.contains(maxi) ){
232  list << maxi;
233  d->connect.insert(mini, list);
234  }
235  }else{
236  QList<int> list;
237  list << maxi;
238  d->connect.insert(mini,list);
239  }
240  }
241 }
242 
244  QVariantList list;
245  list.append(identifier());
246  QVariant n = QVariant::fromValue(countControlPoints());
247  list.append(n);
248  QVariant ord = QVariant::fromValue(order());
249  list.append(ord);
250  QVariant dimension = QVariant::fromValue(3);
251  list.append(dimension);
252  //append knots
253  for(int i = 0; i < n.toInt()+ order();i++){
254  list.append(getKnot(i+1));
255  }
256  //append control points table
257  for(int i = 0; i < n.toInt();i++){
258  list.append(getCoef(i+1).convertDataToQVariant());
259  }
260  QVariant name = QVariant::fromValue(objectName());
261  list.append(name);
262  return list;
263 }
264 
266  int n = data.at(1).toInt();
267  int order = data.at(2).toInt();
268  int dimension = data.at(3).toInt();
269  //append knots
270  double *knots = new double[n+order];
271  for(int i = 0; i < n+order;i++){
272  knots[i] = data.at(i+4).toDouble();
273  //insertKnot_u(data.at(i+7).toDouble());
274  }
275  //append control points table
276  int indice = 4 +n+order;
277  double *CP = new double[3*n];
278  for(int i = 0; i < n;i++){
279  QVariantList list;
280  list.append(data.at(indice));
281  list.append(data.at(indice+1));
282  list.append(data.at(indice+2));
283  list.append(data.at(indice+3));
284  list.append(data.at(indice+4));
285  axlPoint* point = new axlPoint();
286  point->convertQVariantToData(list);
287  //double *controlPoint = point->coordinates();
288  CP[3*i] = point->x();
289  CP[3*i+1] = point->y();
290  CP[3*i+2] = point->z();
291  //setCoef(i,controlPoint);
292  indice = indice+5;
293  }
294  setCurve(n ,order,dimension,knots,CP, false);// rational=false, this curve is a bspline curve (non-rational)
295  QString name = data.last().toString();
296  setObjectName(name);
297  return 1;
298 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
virtual bool rational(void) const
virtual axlPoint getCoef(int n) const
QVariantList convertDataToQVariant(void) const
Convert an axlAbstractData into a QVariantList that specifies all properties of the axlAbstractData...
virtual void defineControlPointConnection(int i, int j)
Define connection between the ith and the jth coefficient.
virtual QString printCoeffs(bool print) const
virtual bool setCoef(int n, double *controlPoint)
virtual double closestParameter(const axlPoint &pt)
virtual axlPoint closestPoint(const axlPoint &pt)
QMap< double, axlPoint > Sample
virtual void insertKnot(double k)
virtual bool connectionsAreDefined(void)
Return true if control points connections were defined by developers. False if there are default conn...
virtual int knotVectorSize(void) const
Generic interface for parametric curve.
virtual QList< int > getControlPointConnection(int i)
The list returned contains all indices of coefficients that are still to be connected to the ith coef...
virtual double getWeight(int n) const
virtual QString printKnotsVector(bool print) const
virtual void setCurve(int pointsCount, int order, int dimension, double *knots, double *points, bool rational)
QMap< double, axlPoint > Sample
virtual void resetControlPointConnections(void)
Removes all control point connections.
double y
Definition: axlPoint.h:37
virtual void removeKnot(double k)
virtual double getKnot(int n) const
double z
Definition: axlPoint.h:38
virtual int order(void) const
virtual int countControlPoints(void) const
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
Definition: axlPoint.cpp:588
double x
Definition: axlPoint.h:37
virtual QString description(void) const
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
virtual int dimension(void) const