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 class ON_CLASS ON_BumpFunction
21 {
22 public:
24  ~ON_BumpFunction() = default;
25  ON_BumpFunction(const ON_BumpFunction&) = default;
26  ON_BumpFunction& operator=(const ON_BumpFunction&) = default;
27 
28 public:
29  double ValueAt(
30  double s,
31  double t
32  ) const;
33 
34  void Evaluate(
35  double s,
36  double t,
37  int der_count,
38  double* value
39  ) const;
40 
41 public:
42  ON_2dPoint m_point = ON_2dPoint::NanPoint; // center of bump
43  int m_type[2];// // = {0,0} // 1 = linear, 5 = quintic, else linear;
44 
45 public:
46  // numbers used in evaluation
47  double m_x0 = 0.0;
48  double m_y0 = 0.0;
49  double m_sx[2]; // = {0.0, 0.0} // 1/(support radius)
50  double m_sy[2]; // = {0.0, 0.0} // 1/(support radius)
51  double m_a = 0.0; // evaluation coefficient
52 
53 private:
54  void Internal_EvaluateLinearBump(double t, double dt, int der_count, double* value) const;
55  void Internal_EvaluateQuinticBump(double t, double dt, int der_count, double* value) const;
56 };
57 
58 
59 class ON_CLASS ON_OffsetSurfaceValue
60 {
61 public:
62  ON_OffsetSurfaceValue() = default;
63  ~ON_OffsetSurfaceValue() = default;
65  ON_OffsetSurfaceValue& operator=(const ON_OffsetSurfaceValue&) = default;
66 public:
67  double m_s = ON_DBL_QNAN;
68  double m_t = ON_DBL_QNAN;
69  double m_distance = ON_DBL_QNAN;
70  double m_radius = ON_DBL_QNAN;
71  int m_index = ON_UNSET_INT_INDEX;
72 };
73 
74 
75 #if defined(ON_DLL_TEMPLATE)
76 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_BumpFunction>;
77 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_OffsetSurfaceValue>;
78 #endif
79 
80 
82 {
83 public:
86 
87  /*
88  Description:
89  Sets base surface for the offset function.
90  Parameters:
91  srf - [in] pointer to the base surface.
92  This surface must remain valid while
93  the ON_OffsetSurfaceFunction class is used.
94  Returns:
95  True if successful.
96  */
97  bool SetBaseSurface(
98  const ON_Surface* srf
99  );
100 
101  /*
102  Returns:
103  Base surface specified SetBaseSurface().
104  */
105  const ON_Surface* BaseSurface() const;
106 
107  /*
108  Description:
109  Use set SetSideTangency if you want the offset
110  surface and base surface to have the same unit
111  normals along a side of the surfaces's parameter
112  spaces.
113  Parameters:
114  side - [in]
115  0 = south side
116  1 = east side
117  2 = north side
118  3 = west side
119  bEnable - [in] true to enable tangency,
120  false to disable tangency
121  Returns:
122  True if successful.
123  */
124  bool SetSideTangency(
125  int side,
126  bool bEnable
127  );
128 
129  /*
130  Parameters:
131  side - [in]
132  0 = south side
133  1 = east side
134  2 = north side
135  3 = west side
136  Returns:
137  True if side tangency is enabled.
138  */
139  bool SideTangency(int side) const;
140 
141  /*
142  Description:
143  Sets the offset distance at a point. Call this function
144  once for each point wher the user specifies an offset.
145  Parameters:
146  s - [in]
147  t - [in] (s,t) is a base surface evaluation parameter
148  distance - [in] distance is the offset distance.
149  radius - [in] if radius>0, then this value will be the
150  the approximate radius of the offset "bump".
151  */
152  bool SetOffsetPoint(
153  double s,
154  double t,
155  double distance,
156  double radius = 0.0
157  );
158 
159  /*
160  Description:
161  Sets the surface parameters of an existing offset point.
162  Parameters:
163  index - [in] index of the point to set
164  s - [in]
165  t - [in] (s,t) is a base surface evaluation parameter
166  */
167  bool SetPoint(
168  int index,
169  double s,
170  double t
171  );
172 
173 
174  /*
175  Description:
176  Set the offset distance for an existing point
177  Parameters:
178  index - [in] index of the point to set
179  distance - [in] new distance
180  */
181  bool SetDistance(
182  int index,
183  double distance);
184 
185 
186  /*
187  Returns:
188  Number of points specified using SetOffsetPoint().
189  */
190  int OffsetPointCount() const;
191 
192  /*
193  Parameters:
194  i - [in] an index >= 0 and < OffsetPointCount()
195  Returns:
196  Surface parameter specified using SetOffsetPoint().
197  */
198  ON_2dPoint OffsetSurfaceParameter(int i) const;
199 
200  /*
201  Parameters:
202  i - [in] an index >= 0 and < OffsetPointCount()
203  Returns:
204  Offset distance specified using SetOffsetPoint().
205  */
206  double OffsetDistance(int i) const;
207 
208  /*
209  Description:
210  Value of the offset distance at any surface parameter.
211  Parameters:
212  s - [in]
213  t - [in] (s,t) is a base surface evaluation parameter
214  Returns:
215  offset distance at the surface parameter
216  */
217  double DistanceAt(
218  double s,
219  double t
220  ) const;
221 
222  /*
223  Description:
224  Value of the offset distance at any surface parameter.
225  Parameters:
226  s - [in]
227  t - [in] (s,t) is a base surface evaluation parameter
228  num_der - [in] number of derivatives
229  value - [out] value and derivatives of distance function
230  value[0] = distance, value[1] = 1rst derivative,
231  value[2] = 2nd derivative, ...
232  Returns:
233  True if successful
234  */
235  bool EvaluateDistance(
236  double s,
237  double t,
238  int num_der,
239  double* value
240  ) const;
241 
242  /*
243  Description:
244  Value of the offset function at any surface parameter.
245  Parameters:
246  s - [in]
247  t - [in] (s,t) is a base surface evaluation parameter
248  Returns:
249  Point on the offset surface.
250  */
251  ON_3dPoint PointAt(
252  double s,
253  double t
254  ) const;
255 
256  /*
257  Description:
258  Resets this class if you want to reuse it.
259  */
260  void Destroy();
261 
262 private:
263  friend class ON_OffsetSurface;
264  bool Initialize();
265 
266  const ON_Surface* m_srf;
267 
268  ON_Interval m_domain[2];
269 
270  bool m_bZeroSideDerivative[4]; // S,E,N,W side
271 
273 
274 
276 
277  bool m_bValid;
278 };
279 
280 class ON_CLASS ON_OffsetSurface : public ON_SurfaceProxy
281 {
282  // This is still a work in progress. In particular,
283  // this surface class can not be saved in files, used
284  // as a brep surface, added to Rhino, etc.
285  //
286  // As of January 2004, it is useful for calculating
287  // offset meshes and any other fitting and approximation
288  // tools that requires a surface evaluator but do not need
289  // NURBS forms, isocurves, and so on.
290  ON_OBJECT_DECLARE(ON_OffsetSurface);
291 public:
293  ~ON_OffsetSurface();
294  ON_OffsetSurface( const ON_OffsetSurface& src);
295  ON_OffsetSurface& operator=(const ON_OffsetSurface& src);
296 
297  // virtual ON_Geometry GetBBox override
298  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
299 
300  bool Evaluate( // returns false if unable to evaluate
301  double, double, // evaluation parameters
302  int, // number of derivatives (>=0)
303  int, // array stride (>=Dimension())
304  double*, // array of length stride*(ndir+1)*(ndir+2)/2
305  int = 0, // optional - determines which quadrant to evaluate from
306  // 0 = default
307  // 1 from NE quadrant
308  // 2 from NW quadrant
309  // 3 from SW quadrant
310  // 4 from SE quadrant
311  int* = 0 // optional - evaluation hint (int[2]) used to speed
312  // repeated evaluations
313  ) const override;
314 
315  /*
316  Description:
317  Sets base surface to a surface that is not managed
318  by the ON_OffsetSurface class.
319  Parameters:
320  base_surface - [in] points to a base surface the
321  caller insures will exist for the lifetimes
322  of the ON_OffsetSurface class.
323  Returns:
324  True if successful.
325  */
326  bool SetBaseSurface(
327  const ON_Surface* base_surface
328  );
329 
330  /*
331  Description:
332  Sets base surface to a surface that is optionally managed
333  by the ON_OffsetSurface class.
334  Parameters:
335  base_surface - [in] points to a base surface the
336  caller insures will exist for the lifetimes
337  of the ON_OffsetSurface class.
338  bManage - [in] if true, the base_surface must point
339  to a surface that is on the heap and the surface
340  will be deleted by ~ON_OffsetSurface.
341  Returns:
342  True if successful.
343  */
344  bool SetBaseSurface(
345  ON_Surface* base_surface,
346  bool bManage
347  );
348 
349  /*
350  Returns:
351  Base surface;
352  */
353  const ON_Surface* BaseSurface() const;
354 
355  ON_OffsetSurfaceFunction& OffsetFunction();
356  const ON_OffsetSurfaceFunction& OffsetFunction() const;
357 
358 private:
359  // If not nullptr, this points to the base surface
360  ON_Surface* m__pSrf;
361  ON_OffsetSurfaceFunction m_offset_function;
362 };
363 
364 
365 #endif
static const ON_2dPoint NanPoint
Definition: opennurbs_point.h:292
Definition: opennurbs_offsetsurface.h:81
Definition: opennurbs_array.h:36
Definition: opennurbs_offsetsurface.h:59
Definition: opennurbs_surfaceproxy.h:26
Definition: opennurbs_point.h:277
Definition: opennurbs_offsetsurface.h:260
Definition: opennurbs_offsetsurface.h:20
Definition: opennurbs_point.h:460
Definition: opennurbs_surface.h:57
Definition: opennurbs_point.h:46