Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Overlay_primitives.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Overlay_primitives.h,v 1.16 2008/12/06 08:43:27 mtcampbe Exp $
24 
25 //==========================================================
26 // This file defines the class Overlay_primitives, which provides two
27 // basic primitives: intersection of two edges, and projection of
28 // a point onto a face. In addition, it also provides subroutines
29 // for computing weighted squared distance from a point to an object.
30 //
31 // Author: Xiangmin Jiao
32 // Last modified: 01/21/2001
33 //
34 // See also: Overlay_primitives.C.
35 //==========================================================
36 
37 #ifndef RFC_OVERLAY_PRIMITIVES_H
38 #define RFC_OVERLAY_PRIMITIVES_H
39 
40 #include <utility>
41 #include "HDS_overlay.h"
42 #include "HDS_accessor.h"
43 
45 
46 // Collection of vertices of the incident facet of a given halfedge.
47 class Vertex_set {
48 public:
49  typedef Vertex_set Self;
52  typedef int Value;
53  typedef unsigned int Size;
54 
55  Vertex_set() : _pane(NULL), _ne(0) {}
56  explicit Vertex_set( const Halfedge* h);
57  Vertex_set( const Halfedge* h, Size);
58 
59  // Use the default copy constructor and copy assignment operator.
60  // Vertex_set( const Vertex_set &vs) : _nodes( vs._nodes), _ne( vs._ne) {}
61  // Vertex_set &operator=( const Vertex_set &vs)
62  // { if (this!=&vs) { vs _nodes = vs._nodes; _ne = vs._ne;} return *this; }
63 
64  const RFC_Pane_overlay *pane() const { return _pane; }
65  int operator[]( Size i) const { return _nodes[i]; }
66 
67  Size size_of_edges() const { return _ne; }
68  Size size_of_nodes() const { return _nodes.size(); }
69 
70 protected:
71  Size count_edges( const Halfedge *e) const {
72  Size i=0;
73  const Halfedge *h=e;
74  do { ++i; } while ( (h=h->next())!= e);
75  return i;
76  }
77 
79  std::vector<int> _nodes;
80  Size _ne; // Number of edges and number of nodes.
81 };
82 
83 // Wrapper for point set of the incident facet of a given halfedge.
84 class Point_set {
85 public:
86  typedef Point_set Self;
89  typedef Point_3 Value;
90  typedef unsigned int Size;
91 
92  explicit Point_set( const Halfedge *h) : vs(h) {}
93  Point_set( const Halfedge *h, Size) : vs(h,0) {}
94 
95  // Use the default copy constructor and copy assignment operator.
96  // Point_set( const Self &ps) : vs( ps.vs) {}
97  // Self &operator=( const Self &ps)
98  // { if (this != ps) { vs = ps.vs; } return *this; }
99 
100  const Point_3& operator[]( Size i) const { return vs.pane()->get_point(vs[i]); }
101  Size size_of_edges() const { return vs.size_of_edges(); }
102  Size size_of_nodes() const { return vs.size_of_nodes(); }
103 
104 protected:
106 };
107 
108 // Wrapper for vertex normals of the incident facet of a given halfedge.
109 class Normal_set {
110 public:
111  typedef Normal_set Self;
115  typedef Vector_3 Value;
116  typedef unsigned int Size;
117 
118  explicit Normal_set( const Halfedge *h) : vs(h), hs(vs.size_of_nodes()) {
119  for ( unsigned int i=0, s=hs.size(); i<s; ++i)
120  { hs[i] = h; h = h->next(); }
121  }
122  Normal_set( const Halfedge *h, Size) : vs(h,0), hs(vs.size_of_nodes()) {
123  for ( unsigned int i=0, s=hs.size(); i<s; ++i)
124  { hs[i] = h; h = h->next(); }
125  }
126 
127  // Use the default copy constructor and copy assignment operator.
128  // Normal_set( const Self &ns) : vs( ns.vs);
129  // Self &operator=( const Self &ns);
130 
131  const Value& operator[]( Size i) const
132  { return vs.pane()->get_normal(hs[i], vs[i]); }
133  Size size_of_edges() const { return vs.size_of_edges(); }
134  Size size_of_nodes() const { return vs.size_of_nodes(); }
135 
136 protected:
138  std::vector< const Halfedge*> hs;
139 };
140 
142 public:
147 
148  typedef unsigned int Size;
149 
150  // Indicates whether the two surfaces have opposite normal directions.
151  // By default, they are opposite of each other.
152 
153  Overlay_primitives( Real ec=1.e-9, Real ep=1.e-6, Real ee=1.e-3)
154  : _eps_c(ec), _eps_p(ep), _eps_e(ee)
156 
157  // This function computes the intersection of the edge [b->org,b->dst]
158  // with [g->org,g->dst]. It assumes that the two edges are NOT
159  // colinear. The output c1 and c2 are parameterization of
160  // the locations of the intersection.
161  // Returns true iff both |*c1| and |*c2| are in [0,1].
162  bool
163  intersect( const Halfedge *b,
164  const Halfedge *g,
165  Real start,
166  Real *c1,
167  Real *c2,
168  Real *dir,
169  Real *dir_match,
170  bool is_opposite,
171  Real eps_e) const;
172 
173  void
174  intersect( const Point_set &pbs,
175  const Point_set &pgs,
176  const Normal_set &ngs,
177  Real *c1,
178  Real *c2, bool revsersed) const;
179 
180  // Project a point p onto an element along a given direction.
181  // The projection direction is given by the input parameter dir.
182  // If the input is NULL_VECTOR, evaluate the direction by sum N_i*n_i.
183  // g and pt are both input and output.
184  bool
185  project_onto_element( const Point_3 &p,
186  Halfedge **g,
187  Parent_type *pt,
188  Vector_3 dir,
189  Point_2 *nc_out,
190  const Real eps_p, // Tolerance for perturbation
191  Real eps_np=-1.) const;
192 
193  Real
194  project_green_feature( const Vector_3 &n, // Normal direction
195  const Vector_3 &t, // Tangential direction
196  const Point_3 &p1, // Source blue vertex
197  const Point_3 &p2, // Target blue vertex
198  const Point_3 &q, // Green vertex
199  const Real eps_p) const;
200 
201  Real
202  project_blue_feature( const Vector_3 &n1, const Vector_3 &n2,
203  const Vector_3 &t1, const Vector_3 &t2,
204  const Point_3 &q1, const Point_3 &q2,
205  const Point_3 &p,
206  const Real eps_p) const;
207 
208  Real normalmatch( const Halfedge *b, const Halfedge *g) const;
209 
210  // Helpers for evaluating physical coordinates, tangents and projdirs
211  Point_3 get_point( const Halfedge *b, const Point_2S &nc) const {
212  if ( b->is_border())
213  { RFC_assertion( nc[1]==0); return get_point( b, nc[0]); }
214 
215  Point_set ps(b); Point_2 p(nc[0],nc[1]);
216  return Generic_element(ps.size_of_edges()).interpolate(ps, p);
217  }
218 
219  Point_3 get_point( const Halfedge *b, const Point_2 &nc) const{
220  if ( b->is_border())
221  { RFC_assertion( nc[1]==0); return get_point( b, nc[0]); }
222 
223  Point_set ps(b);
224  return Generic_element(ps.size_of_edges()).interpolate(ps, nc);
225  }
226 
227  Point_3 get_point( const Halfedge *b, Real a) const {
228  // Here, we assume edge is straight line.
229  if ( a==0) return b->origin()->point();
230  return b->origin()->point() + a*(b->destination()->point()-
231  b->origin()->point());
232  }
233 
234  Vector_3 get_projdir( const Halfedge *b, Real a) const {
235  Normal_set ns(b,1);
236  return Generic_element(ns.size_of_edges()).interpolate( ns, a);
237  }
238 
239  Vector_3 get_tangent( const Halfedge *b, Real a) const {
240  Point_set ps(b,1);
241  Vector_3 v;
242  Generic_element(ps.size_of_edges()).Jacobian( ps, a, v);
243  return v;
244  }
245 
247 
248  // Note that the normal vector returned is not normalized.
249  // Use area-weighted by default.
250  Vector_3 get_face_normal( const Halfedge *b, const Point_2 &nc,
251  int scheme=0) const {
252  // Evaluate the normal as the cross product of the colume vectors
253  // of its Jacobian matrix.
254  Point_set ps(b);
255  Size ne = ps.size_of_edges(), nv=ne;
256  Vector_3 J[2];
257 
258  Generic_element( ne, nv).Jacobian( ps, nc, J);
259 
260  Vector_3 nrm = Vector_3::cross_product( J[0], J[1]);
261  if ( scheme == AREA_WEIGHTED) return nrm;
262  nrm.normalize();
263  if ( scheme == UNIT_WEIGHT) return nrm;
264 
265  double cosa = J[0]*J[1] / std::sqrt((J[0]*J[0])*(J[1]*J[1]));
266  if ( cosa>1) cosa = 1; else if ( cosa<-1) cosa = -1;
267 
268  return std::acos(cosa) * nrm;
269  }
270 
271  // Snap a ridge edge.
272  void snap_blue_ridge_edge( const Halfedge *b,
273  const Halfedge *g,
274  Real *cb,
275  Real *cg,
276  Parent_type *t,
277  Real tol=0.1) const;
278 
279  // Snap a ridge vertex
280  void snap_blue_ridge_vertex( const Vertex *v,
281  Halfedge **g,
282  Parent_type *t,
283  Point_2 *nc,
284  Real tol=0.1) const;
285 
286 protected:
287  Real abs( const Real x) const { return fabs(x); }
288 
289  int sign( const Real x) const
290  { return ( x == Real(0.)) ? 0 : ( x > Real(0.) ? 1 : -1); }
291 
292  Real squared_norm( const Vector_3 &v) const { return v*v; }
293 
297 
298 private:
299  // This class is neither copy constuctible nor assignable.
300  // Explicitly disallow implicit definition of these functions.
301  Self &operator=( const Self&);
302 };
303 
305 
306 #endif // RFC_OVERLAY_PRIMITIVES_H
307 // EOF
308 
309 
310 
311 
312 
313 
Vector_3 get_tangent(const Halfedge *b, Real a) const
unsigned int Size
Halfedge_overlay Halfedge
bool intersect(const Halfedge *b, const Halfedge *g, Real start, Real *c1, Real *c2, Real *dir, Real *dir_match, bool is_opposite, Real eps_e) const
Vertex_set vs
int sign(const Real x) const
Vertex_overlay Vertex
Real project_green_feature(const Vector_3 &n, const Vector_3 &t, const Point_3 &p1, const Point_3 &p2, const Point_3 &q, const Real eps_p) const
Vertex_overlay * destination()
Definition: HDS_overlay.h:137
double s
Definition: blastest.C:80
Vertex_overlay Vertex
NT q1
Self & operator=(const Self &)
NT p1
SURF::Point_2< float > Point_2S
Definition: rfc_basic.h:45
const Point_3 & operator[](Size i) const
Overlay_primitives Self
Vector_3 get_projdir(const Halfedge *b, Real a) const
Point_set(const Halfedge *h, Size)
This class encapsulate a halfedge over a window manifold.
Definition: Manifold_2.h:446
Facet_overlay Facet
Size count_edges(const Halfedge *e) const
double Real
Definition: mapbasic.h:322
unsigned int Size
double sqrt(double d)
Definition: double.h:73
Vector_3 & normalize()
Definition: mapbasic.h:114
SURF::Generic_element_2 Generic_element
Definition: rfc_basic.h:46
bool is_border() const
Definition: HDS_overlay.h:131
Real normalmatch(const Halfedge *b, const Halfedge *g) const
const RFC_Pane_overlay * pane() const
Vector_3 get_face_normal(const Halfedge *b, const Point_2 &nc, int scheme=0) const
Size size_of_edges() const
unsigned int Size
Vertex_overlay * origin()
Definition: HDS_overlay.h:135
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
Real abs(const Real x) const
Vertex_set Self
static const int scheme
Point_set(const Halfedge *h)
const Point_3 & get_point(int id) const
void snap_blue_ridge_edge(const Halfedge *b, const Halfedge *g, Real *cb, Real *cg, Parent_type *t, Real tol=0.1) const
#define RFC_END_NAME_SPACE
Definition: rfc_basic.h:29
Halfedge_overlay Halfedge
Parent_type
Definition: rfc_basic.h:49
Halfedge_overlay Halfedge
const Point & point() const
Vertex_overlay Vertex
Real project_blue_feature(const Vector_3 &n1, const Vector_3 &n2, const Vector_3 &t1, const Vector_3 &t2, const Point_3 &q1, const Point_3 &q2, const Point_3 &p, const Real eps_p) const
blockLoc i
Definition: read.cpp:79
#define RFC_BEGIN_NAME_SPACE
Definition: rfc_basic.h:28
void int int REAL * x
Definition: read.cpp:74
const NT & n
static Vector_3 cross_product(const Vector_3 &v, const Vector_3 &w)
Definition: mapbasic.h:104
void snap_blue_ridge_vertex(const Vertex *v, Halfedge **g, Parent_type *t, Point_2 *nc, Real tol=0.1) const
bool project_onto_element(const Point_3 &p, Halfedge **g, Parent_type *pt, Vector_3 dir, Point_2 *nc_out, const Real eps_p, Real eps_np=-1.) const
Point_3 get_point(const Halfedge *b, const Point_2 &nc) const
Size size_of_nodes() const
std::vector< const Halfedge * > hs
Overlay_primitives(Real ec=1.e-9, Real ep=1.e-6, Real ee=1.e-3)
Halfedge_overlay * next()
Definition: HDS_overlay.h:120
const Value & operator[](Size i) const
Real squared_norm(const Vector_3 &v) const
Size size_of_nodes() const
int operator[](Size i) const
Size size_of_edges() const
const RFC_Pane_overlay * _pane
NT q
Normal_set(const Halfedge *h)
Halfedge_overlay Halfedge
Point_3 get_point(const Halfedge *b, const Point_2S &nc) const
Point_3 get_point(const Halfedge *b, Real a) const
Normal_set Self
CImg< _cimg_Tfloat > acos(const CImg< T > &instance)
Definition: CImg.h:6051
Some basic geometric data types.
Definition: mapbasic.h:54
std::vector< int > _nodes
Size size_of_edges() const
Normal_set(const Halfedge *h, Size)
Vector_3 & get_normal(int v)
#define RFC_assertion
Definition: rfc_basic.h:65
Size size_of_nodes() const
Point_set Self