Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Overlay_1d.C
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_1d.C,v 1.17 2008/12/06 08:43:28 mtcampbe Exp $
24 
25 #include "Overlay.h"
26 #include <cstdio>
27 #include <iterator>
28 
30 
31 // Find the next vertex on b.
34  const RFC_Pane_overlay *gpane = acc.get_pane(g);
35  const Vertex *borg = b->origin(), *bdst = b->destination();
36  const Vertex *gorg = g->origin(), *gdst = g->destination();
37 
38  double eps_e;
39 
40  if ( B->snap_on_features()) eps_e = 5.e-3; // Increase the threshold for RSRM
41  else eps_e = Overlay::eps_e;
42 
43  Real s = op.project_green_feature( gpane->get_normal( g, gdst),
44  gpane->get_tangent( g, gdst),
45  borg->point(), bdst->point(),
46  gdst->point(), eps_e);
47  INode *x = new INode();
48  if ( s < 1) {
49  if ( s < 0) s = 0; // Adjust the origin of the blue edge.
50  acc.set_parent( x, b, Point_2( s,0), BLUE);
51  acc.set_parent( x, g, Point_2( 1,0), GREEN);
52  }
53  else if ( s>= 1) {
54  // The blue parent is bdst, so we locate a non-border
55  // blue halfedge originated from b.
56  acc.set_parent( x, b, Point_2( 1,0), BLUE);
57  // Project green vertex onto blue edge
58  Real t;
59  if ( s > 1) {
60  // Project the blue vertex onto the green halfedge
61  t=op.project_blue_feature( gpane->get_normal(g, gorg),
62  gpane->get_normal(g, gdst),
63  gpane->get_tangent(g, gorg),
64  gpane->get_tangent(g, gdst),
65  gorg->point(), gdst->point(),
66  bdst->point(), eps_e);
67  if ( t>1) t=1;
68  }
69  else
70  t = 1;
71  acc.set_parent( x, g, Point_2(t,0), GREEN);
72 
73  if ( B->snap_on_features()) {
74  // Update the coordinates for the blue point
75  Point_3 &pnt = const_cast<Point_3&>(bdst->point());
76  pnt = gorg->point()+t*(gdst->point()-gorg->point());
77  }
78  }
79 
80  // Insert the new edge into the blue edge.
81  insert_node_in_blue_edge( *x, b);
82 
83  return x;
84 }
85 
86 // Compare whether two bounding boxes are the same within certain tolerance
87 static bool equal( const Bbox_3 &b1, const Bbox_3 &b2, Real tol_r) {
88  Bbox_3 u = b1+b2;
89  Real tol_a = std::max(std::max(u.xmax()-u.xmin(), u.ymax()-u.ymin()),
90  u.zmax()-u.zmin()) * tol_r;
91  return ( std::max( std::fabs(b1.xmin()-b2.xmin()),
92  std::fabs(b1.xmax()-b2.xmax())) <= tol_a &&
93  std::max( std::fabs(b1.ymin()-b2.ymin()),
94  std::fabs(b1.ymax()-b2.ymax())) <= tol_a &&
95  std::max( std::fabs(b1.zmin()-b2.zmin()),
96  std::fabs(b1.zmax()-b2.zmax())) <= tol_a);
97 }
98 
99 int Overlay::
100 overlay_features_1() {
101  Feature_list_1 &lf_b = B->flist_1(), &lf_g = G->flist_1();
102 
103  bool determined_direction=false;
104  int is_opp=-1;
105  const Real bbox_tol = 1.e-1, d2e_ratio_sq=0.5, d2e_ratio_sq_l=1.e-4;
106 
107  int dropped=0;
108 
109  // Loop through blue features
110  for ( Feature_list_1::iterator it_f_b = lf_b.begin(), iend_f_b=lf_b.end();
111  it_f_b != iend_f_b; ++it_f_b) {
112  std::cout << "\nProcessing blue ridge with bounding box "
113  << it_f_b->bbox << std::endl;
114  Feature_1 *f_b = &*it_f_b;
115  Feature_1::iterator it_b_mid = it_f_b->begin();
116  // Find a vertex in middle of the blue feature
117  std::advance( it_b_mid, (f_b->size()-1)/2);
118 
119  Halfedge *b = *it_b_mid;
120  Vertex *bdst = acc.get_destination(b);
121  const Point_3 &bpdst = bdst->point();
122  INode *bnode=acc.get_inode( bdst);
123  INode *bn_frt=acc.get_inode( acc.get_origin(it_f_b->front()));
124  INode *bn_bck=acc.get_inode( acc.get_destination(it_f_b->back()));
125 
126  Feature_list_1::iterator f_g = lf_g.end();
127  Feature_1::iterator it_g_mid;
128  Real param=-HUGE_VAL, sqd=HUGE_VAL;
129 
130  // Loop through green 1-features
131  for ( Feature_list_1::iterator it_f_g = lf_g.begin(), iend_f_g=lf_g.end();
132  it_f_g != iend_f_g; ++it_f_g) {
133  // Pre-filter out severely mismatching ones
134  if ( bn_frt && bn_frt!=acc.get_inode( acc.get_origin(it_f_g->front())) &&
135  bn_frt != acc.get_inode( acc.get_destination(it_f_g->back())) ||
136  bn_bck && bn_bck!=acc.get_inode( acc.get_origin(it_f_g->front())) &&
137  bn_bck != acc.get_inode( acc.get_destination(it_f_g->back())) ||
138  !equal( it_f_b->bbox, it_f_g->bbox, bbox_tol))
139  continue;
140 
141  std::cout << "\tComparing with green ridge with bounding box "
142  << it_f_g->bbox << std::endl;
143  if ( bnode != NULL) {
144  f_g = it_f_g; RFC_assertion( bn_frt && bn_bck == bnode);
145  if ( bnode == acc.get_inode( acc.get_origin(it_f_g->front())))
146  { it_g_mid = it_f_g->begin(); param = 0.; }
147  else
148  { it_g_mid = --it_f_g->end(); param = 1.; }
149  break;
150  }
151  // Identify the green edge closest to the blue point
152  for ( Feature_1::iterator tmp_it_g=it_f_g->begin(), iend=it_f_g->end();
153  tmp_it_g != iend; ++tmp_it_g) {
154  Halfedge *g = *tmp_it_g;
155  const Vertex *gorg = g->origin(), *gdst = g->destination();
156  const Point_3 &gporg = gorg->point(), &gpdst = gdst->point();
157 
158  Real gsqlen = (gpdst-gporg).squared_norm(), sd=gsqlen*d2e_ratio_sq;
159  if ( (bpdst-gporg).squared_norm()<sd ||
160  (bpdst-gpdst).squared_norm()<sd) {
161  const RFC_Pane_overlay *gpane = acc.get_pane(g);
162  Real t = op.project_blue_feature( gpane->get_normal(g, gorg),
163  gpane->get_normal(g, gdst),
164  gpane->get_tangent(g, gorg),
165  gpane->get_tangent(g, gdst),
166  gporg, gpdst,
167  bpdst, eps_e);
168  if ( t>=0 && t <= 1) {
169  Point_3 gp = gporg+t*(gpdst-gporg);
170  Real sd = (gp-bpdst).squared_norm();
171  if (sd < d2e_ratio_sq*(bpdst-b->origin()->point()).squared_norm() && sd<sqd) {
172  f_g = it_f_g; it_g_mid = tmp_it_g; param=t; sqd = sd;
173  if ( sqd < d2e_ratio_sq_l*gsqlen) break;
174  }
175  }
176  }
177  }
178  }
179 
180  // If did not find a match, remove the blue feature.
181  if ( f_g == lf_g.end()) {
182  std::cout << "Warning: Could not find match for the blue ridge!" << std::endl;
183 
184  it_f_b = --lf_b.erase( it_f_b);
185  ++dropped;
186  continue;
187  }
188  else {
189  std::cout << "\tMatched with green ridge with bounding box "
190  << f_g->bbox << std::endl;
191  }
192 
193  // Determine the orientation of the blue and green features and
194  // reverse the green feature if they have different orientation
195  Vector_3 dir_b = acc.get_pane(b)->get_tangent( b,b->destination());
196  Halfedge *g=*it_g_mid;
197  Vector_3 dir_g = acc.get_pane(g)->get_tangent( g,g->destination());
198  bool dir_match = dir_b*dir_g > 0;
199 
200  // If no inode has yet been created at the blue vertex, create one now.
201  if ( bnode == NULL) {
202  // Create a new inode for the vertex
203  bnode = new INode();
204  acc.set_parent( bnode, b, Point_2(1,0), BLUE);
205  acc.set_parent( bnode, *it_g_mid, Point_2( param, 0), GREEN);
206 
207  insert_node_in_blue_edge( *bnode, b);
208 
209  if ( !determined_direction) {
210  const Halfedge *bopp = acc.get_opposite( b);
211  const Halfedge *g=*it_g_mid, *gopp = acc.get_opposite( g);
212  is_opp = ((acc.get_pane(b)->get_normal( b, b->destination())+
213  acc.get_pane(bopp)->get_normal( bopp, bopp->origin())) *
214  (acc.get_pane(g)->get_normal( g, g->destination()) +
215  acc.get_pane(gopp)->get_normal( gopp, gopp->origin())) < 0);
216  determined_direction = true;
217  }
218  }
219 
220  // Project the blue vertex to the green 1-feature.
221  // Starting from the blue vertex, move forward along the blue 1-feature
222  // and intersect with the normal planes of the green 1-features to
223  // locate all the inodes.
224  INode *x = bnode;
225  Feature_1::iterator it_g=it_g_mid;
226  if ( param == 0. && dir_match)
227  { if ( it_g == f_g->begin()) it_g = f_g->end(); --it_g; }
228  else if ( param == 1. && !dir_match)
229  { ++it_g; if ( it_g == f_g->end()) it_g = f_g->begin(); }
230 
231  for (Feature_1::iterator it_b=it_b_mid, iend=--f_b->begin();
232  it_b!=iend; --it_b) {
233  // Loop until the target of the green halfedge projects beyond the
234  // halfedge.
235  Halfedge *b=acc.get_opposite(*it_b);
238 
239  for (;;) {
240  Halfedge *g = dir_match?acc.get_opposite(*it_g):*it_g;
242 
243  if ( x->parent_type( BLUE)==PARENT_VERTEX &&
245  idst && get_edge_parent(*x,*idst,GREEN)!=Host_face(0,PARENT_NONE))
246  break;
247  x = project_next_vertex(b, g);
248 
249  if ( x->nat_coor( GREEN)[0] == 0. &&
250  acc.get_origin(x->halfedge( GREEN)) != acc.get_origin(g)) {
251  // Done with the green edge
252  if ( dir_match)
253  { if ( it_g == f_g->begin()) it_g = f_g->end(); --it_g; }
254  else
255  { ++it_g; if ( it_g == f_g->end()) it_g = f_g->begin(); }
256  }
257  else
258  break;
259  }
260  }
261  x = bnode;
262  it_g=it_g_mid;
263  if ( param == 0. && !dir_match)
264  { if ( it_g == f_g->begin()) it_g = f_g->end(); --it_g; }
265  else if ( param == 1. && dir_match)
266  { ++it_g; if ( it_g == f_g->end()) it_g = f_g->begin(); }
267 
268  for (Feature_1::iterator it_b=it_b_mid, iend=f_b->end(); ++it_b!=iend; ) {
269  // Loop until the target of the green halfedge projects beyond the
270  // halfedge.
271  Halfedge *b=*it_b; RFC_assertion( acc.get_pane(b)->is_feature_1(b));
273 
274  for (;;) {
275  Halfedge *g = dir_match?*it_g:acc.get_opposite(*it_g);
277 
278  if ( x->parent_type( BLUE)==PARENT_VERTEX &&
280  idst && get_edge_parent(*x,*idst,GREEN)!=Host_face(0,PARENT_NONE))
281  break;
282  x = project_next_vertex(b, g);
283 
284  if ( x->nat_coor( GREEN)[0] == 0. &&
285  acc.get_origin(x->halfedge( GREEN)) != acc.get_origin(g)) {
286  // Done with the green edge
287  if ( dir_match)
288  { ++it_g; if ( it_g == f_g->end()) it_g = f_g->begin(); }
289  else
290  { if ( it_g == f_g->begin()) it_g = f_g->end(); --it_g; }
291  }
292  else
293  break;
294  }
295  }
296  }
297 
298  if ( dropped)
299  std::cout << "Ignored " << dropped << " 1-features in \"" << B->name()
300  << "\" during matching" << std::endl;
301 
302  if ( (dropped=lf_g.size()-lf_b.size()))
303  std::cout << "Ignored " << dropped << " 1-features in \"" << G->name()
304  << "\" after matching" << std::endl;
305 
306  return is_opp;
307 }
308 
310 
311 
312 
313 
314 
315 
std::string name() const
The name of the window.
Vertex * get_origin(Halfedge *h) const
Definition: HDS_accessor.h:87
Parent_type parent_type(const int color) const
Definition: HDS_overlay.h:350
double xmax() const
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
Halfedge * get_opposite(Halfedge *h) const
Definition: HDS_accessor.h:99
Real eps_e
Definition: Overlay.h:291
Vertex_overlay * destination()
Definition: HDS_overlay.h:137
double s
Definition: blastest.C:80
RFC_Pane_overlay * get_pane(Vertex *v) const
Definition: HDS_accessor.h:128
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
INode * project_next_vertex(Halfedge *, Halfedge *)
Definition: Overlay_1d.C:33
RFC_Window_overlay::Feature_list_1 Feature_list_1
Definition: Overlay.h:69
This class encapsulate a halfedge over a window manifold.
Definition: Manifold_2.h:446
double Real
Definition: mapbasic.h:322
double xmin() const
double zmin() const
Bbox_3 bbox() const
Definition: Point_3.h:150
INode * get_inode(Vertex *v) const
Definition: HDS_accessor.h:370
const Color GREEN
Definition: Color.C:59
Host_face get_edge_parent(const INode &i0, const INode &i1, const int color) const
Definition: Overlay.C:1393
Vector_3 & get_tangent(Halfedge *h, Vertex *v)
Vertex_overlay * origin()
Definition: HDS_overlay.h:135
RFC_Window_overlay::Vertex Vertex
Definition: Overlay.h:59
Point object that represents a single point.
Definition: datatypedef.h:68
bool snap_on_features() const
#define RFC_END_NAME_SPACE
Definition: rfc_basic.h:29
double ymax() const
const Point & point() const
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com 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 **********************************************************************INTERFACE SUBROUTINE knode iend
const Point_2S & nat_coor(const int color) const
Definition: HDS_overlay.h:327
RFC_Window_overlay * G
Definition: Overlay.h:281
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
RFC_Window_overlay::Feature_1 Feature_1
Definition: Overlay.h:67
#define RFC_BEGIN_NAME_SPACE
Definition: rfc_basic.h:28
void int int REAL * x
Definition: read.cpp:74
Node destination() const
Obtain the (primary copy of the) destination of the edge.
Definition: Manifold_2.h:472
double zmax() const
static bool equal(const Bbox_3 &b1, const Bbox_3 &b2, Real tol_r)
Definition: Overlay_1d.C:87
const Color BLUE
Definition: Color.C:62
void set_parent(INode *i, Halfedge *h, const Point_2 &p, int color)
Definition: HDS_accessor.h:355
Halfedge * halfedge(const int color) const
Definition: HDS_overlay.h:357
Feature_list_1 & flist_1()
HDS_accessor< Tag_true > acc
Definition: Overlay.h:284
Overlay_primitives op
Definition: Overlay.h:283
double ymin() const
const Point_3< Real > & point() const
Obtain the coordinates of a node.
Definition: Manifold_2.h:394
void insert_node_in_blue_edge(INode &x, Halfedge *b)
Definition: Overlay.C:187
Vertex * get_destination(Halfedge *h) const
Definition: HDS_accessor.h:93
Some basic geometric data types.
Definition: mapbasic.h:54
RFC_Window_overlay * B
Definition: Overlay.h:280
bool is_feature_1(const Halfedge *h) const
Node origin() const
Obtain the (primary copy of the) origin of the edge.
Definition: Manifold_2.h:468
Vector_3 & get_normal(int v)
#define RFC_assertion
Definition: rfc_basic.h:65
SURF::Vector_2< Real > Point_2
Definition: rfc_basic.h:43