Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
Spline.h
1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 #ifndef DIME_SPLINE_H
34 #define DIME_SPLINE_H
35 
36 #include <dime/entities/ExtrusionEntity.h>
37 #include <assert.h>
38 
39 class DIME_DLL_API dimeSpline : public dimeEntity
40 {
41 public:
42  dimeSpline();
43  virtual ~dimeSpline();
44 
45  enum Flags {
46  CLOSED = 0x01,
47  PERIODIC = 0x02,
48  RATIONAL = 0x04,
49  PLANAR = 0x08,
50  LINEAR = 0x10
51  };
52 
53  bool hasWeights() const;
54 
55  int16 getFlags() const;
56  void setFlags(const int16 flags);
57 
58  int16 getDegree() const;
59  void setDegree(const int16 degree);
60 
61  dxfdouble getControlPointTolerance() const;
62  void setControlPointTolerance(const dxfdouble tol);
63  dxfdouble getFitPointTolerance() const;
64  void setFitPointTolerance(const dxfdouble tol);
65  dxfdouble getKnotTolerance() const;
66  void setKnotTolerance(const dxfdouble tol);
67 
68  int getNumKnots() const;
69  dxfdouble getKnotValue(const int idx) const;
70  void setKnotValue(const int idx, const dxfdouble value);
71  void setKnotValues(const dxfdouble * const values, const int numvalues,
72  dimeMemHandler * const memhandler = NULL);
73 
74  int getNumControlPoints() const;
75  const dimeVec3f &getControlPoint(const int idx) const;
76  void setControlPoint(const int idx, const dimeVec3f &v);
77  void setControlPoints(const dimeVec3f * const pts, const int numpts,
78  dimeMemHandler * const memhandler = NULL);
79 
80  int getNumWeights() const;
81  dxfdouble getWeight(const int idx) const;
82  void setWeight(const int idx, const dxfdouble w,
83  dimeMemHandler * const memhandler = NULL);
84 
85  int getNumFitPoints() const;
86  const dimeVec3f &getFitPoint(const int idx) const;
87  void setFitPoint(const int idx, const dimeVec3f &pt);
88  void setFitPoints(const dimeVec3f * const pts, const int numpts,
89  dimeMemHandler * const memhandler = NULL);
90 
91  virtual dimeEntity *copy(dimeModel * const model) const;
92  virtual bool getRecord(const int groupcode,
93  dimeParam &param,
94  const int index) const;
95  virtual const char *getEntityName() const;
96 
97  virtual void print() const;
98  virtual bool write(dimeOutput * const out);
99  virtual int typeId() const;
100  virtual int countRecords() const;
101 
102 protected:
103  virtual bool handleRecord(const int groupcode,
104  const dimeParam &param,
105  dimeMemHandler * const memhandler);
106 
107 private:
108  int16 flags;
109 #ifdef DIME_FIXBIG
110  int32 degree;
111  int32 numKnots;
112  int32 numControlPoints;
113  int32 numFitPoints;
114 #else
115  int16 degree;
116  int16 numKnots;
117  int16 numControlPoints;
118  int16 numFitPoints;
119 #endif
120  dxfdouble knotTolerance;
121  dxfdouble fitTolerance;
122  dxfdouble cpTolerance;
123  dxfdouble *knots;
124  dxfdouble *weights;
125  dimeVec3f *controlPoints;
126  dimeVec3f *fitPoints;
127 
128  // read/handle counters
129  int16 knotCnt;
130  int16 fitCnt;
131  int16 cpCnt;
132  int16 weightCnt;
133 
134 }; // class dimeSpline
135 
136 inline int16
137 dimeSpline::getFlags() const
138 {
139  return this->flags;
140 }
141 
142 inline void
143 dimeSpline::setFlags(const int16 flags)
144 {
145  this->flags = flags;
146 }
147 
148 inline int16
149 dimeSpline::getDegree() const
150 {
151  return this->degree;
152 }
153 
154 inline void
155 dimeSpline::setDegree(const int16 degree)
156 {
157  this->degree = degree;
158 }
159 
160 inline dxfdouble
161 dimeSpline::getControlPointTolerance() const
162 {
163  return this->cpTolerance;
164 }
165 
166 inline void
167 dimeSpline::setControlPointTolerance(const dxfdouble tol)
168 {
169  this->cpTolerance = tol;
170 }
171 
172 inline dxfdouble
173 dimeSpline::getFitPointTolerance() const
174 {
175  return this->fitTolerance;
176 }
177 
178 inline void
179 dimeSpline::setFitPointTolerance(const dxfdouble tol)
180 {
181  this->fitTolerance = tol;
182 }
183 
184 inline dxfdouble
185 dimeSpline::getKnotTolerance() const
186 {
187  return this->knotTolerance;
188 }
189 
190 inline void
191 dimeSpline::setKnotTolerance(const dxfdouble tol)
192 {
193  this->knotTolerance = tol;
194 }
195 
196 inline int
197 dimeSpline::getNumKnots() const
198 {
199  return this->numKnots;
200 }
201 
202 inline dxfdouble
203 dimeSpline::getKnotValue(const int idx) const
204 {
205  assert(idx >= 0 && idx < this->numKnots);
206  return this->knots[idx];
207 }
208 
209 inline void
210 dimeSpline::setKnotValue(const int idx, const dxfdouble value)
211 {
212  assert(idx >= 0 && idx < this->numKnots);
213  this->knots[idx] = value;
214 }
215 
216 inline int
217 dimeSpline::getNumControlPoints() const
218 {
219  return this->numControlPoints;
220 }
221 
222 inline const dimeVec3f &
223 dimeSpline::getControlPoint(const int idx) const
224 {
225  assert(idx >= 0 && idx < this->numControlPoints);
226  return this->controlPoints[idx];
227 }
228 
229 inline void
230 dimeSpline::setControlPoint(const int idx, const dimeVec3f &v)
231 {
232  assert(idx >= 0 && idx < this->numControlPoints);
233  this->controlPoints[idx] = v;
234 }
235 
236 inline int
237 dimeSpline::getNumWeights() const
238 {
239  return this->getNumControlPoints();
240 }
241 
242 inline dxfdouble
243 dimeSpline::getWeight(const int idx) const
244 {
245  if (this->hasWeights()) {
246  assert(idx >= 0 && idx < this->numControlPoints);
247  return this->weights[idx];
248  }
249  return 1.0;
250 }
251 
252 inline int
253 dimeSpline::getNumFitPoints() const
254 {
255  return this->numFitPoints;
256 }
257 
258 inline const dimeVec3f &
259 dimeSpline::getFitPoint(const int idx) const
260 {
261  assert(idx >= 0 && idx < this->numFitPoints);
262  return this->fitPoints[idx];
263 }
264 
265 inline void
266 dimeSpline::setFitPoint(const int idx, const dimeVec3f &pt)
267 {
268  assert(idx >= 0 && idx < this->numFitPoints);
269  this->fitPoints[idx] = pt;
270 }
271 
272 #endif // ! DIME_SPLINE_H
273 
The dimeMemHandler class is a special-purpose memory manager.
Definition: MemHandler.h:38
virtual int typeId() const =0
The dimeSpline class handles a SPLINE entity.
Definition: Spline.h:39
virtual int countRecords() const
Definition: Entity.cpp:526
virtual dimeEntity * copy(dimeModel *const model) const =0
The dimeEntity class is the superclass of all entity classes.
Definition: Entity.h:60
The dimeModel class organizes a model.
Definition: Model.h:54
virtual const char * getEntityName() const =0
The dimeVec3f class is for containing and operating on a 3D vector / coordinate.
Definition: Linear.h:61
The dimeParam class is a union of the different parameter types.
Definition: Basic.h:102
virtual bool getRecord(const int groupcode, dimeParam &param, const int index=0) const
Definition: Entity.cpp:715
virtual bool write(dimeOutput *const out)
Definition: Entity.cpp:271
virtual bool handleRecord(const int groupcode, const dimeParam &param, dimeMemHandler *const memhandler)
Definition: Entity.cpp:659
The dimeOutput class handles writing of DXF and DXB files.
Definition: Output.h:41
bool hasWeights() const
Definition: Spline.cpp:88