Point Cloud Library (PCL)  1.9.1-dev
opennurbs_offsetsurface.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(ON_OFFSETSURFACE_INC_)
18 #define ON_OFFSETSURFACE_INC_
19 
20 // This file is to be used in V3 plug-ins.
21 // In V4, this will be included as part of opennurbs.
22 // Ask Dale Lear if you have any questions.
23 
25 {
26 public:
28 
29  bool operator==(const ON_BumpFunction& other) const;
30  bool operator<(const ON_BumpFunction& other) const;
31  bool operator>(const ON_BumpFunction& other) const;
32 
33  double ValueAt(
34  double s,
35  double t
36  ) const;
37 
38  void Evaluate(
39  double s,
40  double t,
41  int der_count,
42  double* value
43  ) const;
44 
45  ON_2dPoint m_point; // center of bump
46  int m_type[2]; // 1 = linear, 5 = quintic;
47 
48  // numbers used in evaluation
49  double m_x0;
50  double m_y0;
51  double m_sx[2]; // 1/(suppor radius)
52  double m_sy[2]; // 1/(suppor radius)
53  double m_a; // evaluation coefficient
54 
55  void EvaluateHelperLinearBump(double t, double dt, int der_count, double* value) const;
56  void EvaluateHelperQuinticBump(double t, double dt, int der_count, double* value) const;
57 };
58 
59 
61 {
62 public:
63  double m_s;
64  double m_t;
65  double m_distance;
66  double m_radius;
67  int m_index;
68 };
69 
70 
71 #if defined(ON_DLL_TEMPLATE)
72 // This stuff is here because of a limitation in the way Microsoft
73 // handles templates and DLLs. See Microsoft's knowledge base
74 // article ID Q168958 for details.
75 #pragma warning( push )
76 #pragma warning( disable : 4231 )
77 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_BumpFunction>;
78 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_OffsetSurfaceValue>;
79 #pragma warning( pop )
80 #endif
81 
82 
84 {
85 public:
88 
89  /*
90  Description:
91  Sets base surface for the offset function.
92  Parameters:
93  srf - [in] pointer to the base surface.
94  This surface must remain valid while
95  the ON_OffsetSurfaceFunction class is used.
96  Returns:
97  True if successful.
98  */
99  bool SetBaseSurface(
100  const ON_Surface* srf
101  );
102 
103  /*
104  Returns:
105  Base surface specified SetBaseSurface().
106  */
107  const ON_Surface* BaseSurface() const;
108 
109  /*
110  Description:
111  Use set SetSideTangency if you want the offset
112  surface and base surface to have the same unit
113  normals along a side of the surfaces's parameter
114  spaces.
115  Parameters:
116  side - [in]
117  0 = south side
118  1 = east side
119  2 = north side
120  3 = west side
121  bEnable - [in] true to enable tangency,
122  false to disable tangency
123  Returns:
124  True if successful.
125  */
126  bool SetSideTangency(
127  int side,
128  bool bEnable
129  );
130 
131  /*
132  Parameters:
133  side - [in]
134  0 = south side
135  1 = east side
136  2 = north side
137  3 = west side
138  Returns:
139  True if side tangency is enabled.
140  */
141  bool SideTangency(int side) const;
142 
143  /*
144  Description:
145  Sets the offset distance at a point. Call this function
146  once for each point wher the user specifies an offset.
147  Parameters:
148  s - [in]
149  t - [in] (s,t) is a base surface evaluation parameter
150  distance - [in] distance is the offset distance.
151  radius - [in] if radius>0, then this value will be the
152  the approximate radius of the offset "bump".
153  */
154  bool SetOffsetPoint(
155  double s,
156  double t,
157  double distance,
158  double radius = 0.0
159  );
160 
161  /*
162  Description:
163  Sets the surface parameters of an existing offset point.
164  Parameters:
165  index - [in] index of the point to set
166  s - [in]
167  t - [in] (s,t) is a base surface evaluation parameter
168  */
169  bool SetPoint(
170  int index,
171  double s,
172  double t
173  );
174 
175 
176  /*
177  Description:
178  Set the offset distance for an existing point
179  Parameters:
180  index - [in] index of the point to set
181  distance - [in] new distance
182  */
183  bool SetDistance(
184  int index,
185  double distance);
186 
187 
188  /*
189  Returns:
190  Number of points specified using SetOffsetPoint().
191  */
192  int OffsetPointCount() const;
193 
194  /*
195  Parameters:
196  i - [in] an index >= 0 and < OffsetPointCount()
197  Returns:
198  Surface parameter specified using SetOffsetPoint().
199  */
200  ON_2dPoint OffsetSurfaceParameter(int i) const;
201 
202  /*
203  Parameters:
204  i - [in] an index >= 0 and < OffsetPointCount()
205  Returns:
206  Offset distance specified using SetOffsetPoint().
207  */
208  double OffsetDistance(int i) const;
209 
210  /*
211  Description:
212  Value of the offset distance at any surface parameter.
213  Parameters:
214  s - [in]
215  t - [in] (s,t) is a base surface evaluation parameter
216  Returns:
217  offset distance at the surface parameter
218  */
219  double DistanceAt(
220  double s,
221  double t
222  ) const;
223 
224  /*
225  Description:
226  Value of the offset distance at any surface parameter.
227  Parameters:
228  s - [in]
229  t - [in] (s,t) is a base surface evaluation parameter
230  num_der - [in] number of derivatives
231  value - [out] value and derivatives of distance function
232  value[0] = distance, value[1] = 1rst derivative,
233  value[2] = 2nd derivative, ...
234  Returns:
235  True if successful
236  */
237  bool EvaluateDistance(
238  double s,
239  double t,
240  int num_der,
241  double* value
242  ) const;
243 
244  /*
245  Description:
246  Value of the offset function at any surface parameter.
247  Parameters:
248  s - [in]
249  t - [in] (s,t) is a base surface evaluation parameter
250  Returns:
251  Point on the offset surface.
252  */
253  ON_3dPoint PointAt(
254  double s,
255  double t
256  ) const;
257 
258  /*
259  Description:
260  Resets this class if you want to reuse it.
261  */
262  void Destroy();
263 
264 private:
265  friend class ON_OffsetSurface;
266  bool Initialize();
267 
268  const ON_Surface* m_srf;
269 
270  ON_Interval m_domain[2];
271 
272  bool m_bZeroSideDerivative[4]; // S,E,N,W side
273 
275 
276 
278 
279  bool m_bValid;
280 };
281 
282 class ON_CLASS ON_OffsetSurface : public ON_SurfaceProxy
283 {
284  // This is still a work in progress. In particular,
285  // this surface class can not be saved in files, used
286  // as a brep surface, added to Rhino, etc.
287  //
288  // As of January 2004, it is useful for calculating
289  // offset meshes and any other fitting and approximation
290  // tools that requires a surface evaluator but do not need
291  // NURBS forms, isocurves, and so on.
292  ON_OBJECT_DECLARE(ON_OffsetSurface);
293 public:
295  ~ON_OffsetSurface();
296  ON_OffsetSurface( const ON_OffsetSurface& src);
297  ON_OffsetSurface& operator=(const ON_OffsetSurface& src);
298 
299  ON_BOOL32 GetBBox(
300  double* bbox_min,
301  double* bbox_max,
302  int bGrowBox = false
303  ) const;
304 
305  ON_BOOL32 Evaluate( // returns false if unable to evaluate
306  double, double, // evaluation parameters
307  int, // number of derivatives (>=0)
308  int, // array stride (>=Dimension())
309  double*, // array of length stride*(ndir+1)*(ndir+2)/2
310  int = 0, // optional - determines which quadrant to evaluate from
311  // 0 = default
312  // 1 from NE quadrant
313  // 2 from NW quadrant
314  // 3 from SW quadrant
315  // 4 from SE quadrant
316  int* = 0 // optional - evaluation hint (int[2]) used to speed
317  // repeated evaluations
318  ) const;
319 
320  /*
321  Description:
322  Sets base surface to a surface that is not managed
323  by the ON_OffsetSurface class.
324  Parameters:
325  base_surface - [in] points to a base surface the
326  caller insures will exist for the lifetimes
327  of the ON_OffsetSurface class.
328  Returns:
329  True if successful.
330  */
331  bool SetBaseSurface(
332  const ON_Surface* base_surface
333  );
334 
335  /*
336  Description:
337  Sets base surface to a surface that is optionally managed
338  by the ON_OffsetSurface class.
339  Parameters:
340  base_surface - [in] points to a base surface the
341  caller insures will exist for the lifetimes
342  of the ON_OffsetSurface class.
343  bManage - [in] if true, the base_surface must point
344  to a surface that is on the heap and the surface
345  will be deleted by ~ON_OffsetSurface.
346  Returns:
347  True if successful.
348  */
349  bool SetBaseSurface(
350  ON_Surface* base_surface,
351  bool bManage
352  );
353 
354  /*
355  Returns:
356  Base surface;
357  */
358  const ON_Surface* BaseSurface() const;
359 
360  ON_OffsetSurfaceFunction& OffsetFunction();
361  const ON_OffsetSurfaceFunction& OffsetFunction() const;
362 
363 private:
364  // If not NULL, this points to the base surface
365  ON_Surface* m__pSrf;
366  ON_OffsetSurfaceFunction m_offset_function;
367 };
368 
369 
370 #endif
bool operator==(const ON_BumpFunction &other) const
double ValueAt(double s, double t) const
void EvaluateHelperQuinticBump(double t, double dt, int der_count, double *value) const
void EvaluateHelperLinearBump(double t, double dt, int der_count, double *value) const
float distance(const PointT &p1, const PointT &p2)
Definition: geometry.h:60
void Evaluate(double s, double t, int der_count, double *value) const
bool operator>(const ON_BumpFunction &other) const
bool operator<(const ON_BumpFunction &other) const