Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Overlay_init.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_init.C,v 1.12 2008/12/06 08:43:28 mtcampbe Exp $
24 
25 //==========================================================
26 // The implementation of the overlay algorithm.
27 //
28 // Author: Xiangmin Jiao
29 // Last modified: 04/06/2001
30 //
31 //==========================================================
32 
33 #include <cstdlib>
34 #include <iostream>
35 #include <fstream>
36 #include <queue>
37 #include <set>
38 #include <utility>
39 #include "Timing.h"
40 #include "Overlay.h"
41 
43 
44 // The initialization for the overlay algorithm. It locates the
45 // green parent of a blue vertex and create an inode for it.
46 // This initialization step takes linear time.
47 // Returns NULL if unsuccessful. Otherwise, creates a new INode.
49  INode *v=NULL;
50 
51  // get an unmarked halfedge from the blue mesh and take its origin as x.
53  if ( b==NULL) return NULL;
54 
55  Vertex *x = b->origin(); RFC_assertion( !acc.is_border(x));
56 
57  // locate the green parent of x.
58  Parent_type t;
59  Point_2 nc;
60  get_green_parent( x, b, &g, &t, &nc);
61  RFC_assertion ( t != PARENT_NONE && g != NULL);
62 
63  // create a new inode for x
64  v = new INode();
65  v->set_parent( b, Point_2(0,0), BLUE);
66  v->set_parent( g, nc, GREEN);
67 
68  if ( verbose2) {
69  std::cout << "\nFound a seed at blue vertex ("
70  << acc.get_pane(x)->get_point(x) << ") \nin green ";
71  const RFC_Pane_overlay *gpane=acc.get_pane(g);
72  switch ( t) {
73  case PARENT_VERTEX:
74  std::cout << "vertex (" << gpane->get_point( g->origin()) << ")\n";
75  break;
76  case PARENT_EDGE:
77  std::cout << "edge (" << gpane->get_point( g->origin()) << "), ("
78  << gpane->get_point( g->destination()) << ")\n";
79  break;
80  case PARENT_FACE: {
81  std::cout << "face ";
82  Halfedge *gt = g;
83  do {
84  std::cout << "\t(" << gpane->get_point( gt->origin()) << "), ";
85  } while ( (gt = gt->next()) != g);
86  std::cout << std::endl;
87  break;
88  }
89  default:
90  RFC_assertion( false);
91  }
92  std::cout << std::endl;
93  }
94 
95  return v;
96 }
97 
98 // Get the green parent of a vertex v. This subroutine takes
99 // linear time in terms of the number of vertices in G.
100 void Overlay::
102  const Halfedge *b,
103  Halfedge **h_out,
104  Parent_type *t_out,
105  Point_2 *nc)
106 {
107  const Point_3 &p = acc.get_pane(v)->get_point(v);
108  Real sq_dist = 1.e30;
109  Vertex *w = NULL;
110 
111  //=================================================================
112  // Locate the closest green vertex
113  //=================================================================
114  std::vector<RFC_Pane_overlay*> ps;
115  G->panes( ps);
116  // Loop through all the panes of G
117  for ( std::vector<RFC_Pane_overlay*>::iterator
118  pit=ps.begin(); pit != ps.end(); ++pit) {
119  RFC_Pane_overlay &pane = **pit;
120  // loop through all the green vertices that are complete
121  for ( HDS::Vertex_iterator vit=pane.hds().vertices_begin();
122  vit!=pane.hds().vertices_end(); ++vit)
123  if ( vit->halfedge() && vit->halfedge()->destination() == &*vit) {
124  // if the distance is closer than previous ones, save it
125  Real sq_d = ( p- acc.get_pane(&*vit)->get_point(&*vit)).squared_norm();
126  if ( sq_d < sq_dist) { sq_dist = sq_d; w = &*vit; }
127  }
128  }
129 
130  if ( w == NULL) return;
131 
132  RFC_assertion( acc.is_primary( w)); // Because we start from smaller ids.
133  // Let h be a nonborder incident halfedge of w
134  Halfedge *h = acc.get_halfedge( w);
135  h = !acc.is_border( h) ? acc.get_next( h) : acc.get_opposite( h);
136 
137  // We perform breadth-first search starting from h
138  std::queue< Halfedge*> q;
139  std::list< Halfedge*> hlist;
140 
141  q.push( h);
142  // Mark the halfedges in the same face as h
143  Halfedge *h0 = h;
144  do { RFC_assertion( !acc.marked(h)); acc.mark( h); hlist.push_back( h); }
145  while ( (h=acc.get_next(h)) != h0);
146 
147  Vector_3 vec(0.,0.,0.);
148  while ( !q.empty()) {
149  h = q.front(); q.pop();
150 
151  *t_out = PARENT_NONE; *h_out=h;
152  if ( op.project_onto_element( p, h_out, t_out, vec, nc, eps_e) &&
153  std::abs(acc.get_normal(b)* acc.get_normal(h)) >= 0.6)
154  break;
155 
156  // Insert the incident faces of h into the queue
157  h0 = h;
158  do {
159  Halfedge *hopp=acc.get_opposite(h);
160  if ( !acc.is_border(hopp) && ! acc.marked( hopp)) {
161  Halfedge *h1 = hopp;
162  q.push( h1);
163  do {
164  acc.mark(h1); hlist.push_back( h1);
165  } while ((h1=acc.get_next(h1))!=hopp);
166  }
167  } while ( (h=acc.get_next(h)) != h0);
168  }
169  // Unmark the halfedges
170  while ( !hlist.empty())
171  { acc.unmark( hlist.front()); hlist.pop_front(); }
172 
173  // If v is too far from p_out, return NULL.
174  vec = op.get_point( *h_out, *nc) - p;
175  if ( vec * vec > sq_length( **h_out) + sq_length( *acc.get_halfedge(v))) {
176  *h_out = NULL; *t_out = PARENT_NONE;
177  }
178  else {
179  // Determine whether the two surfaces are facing each other
180  is_opposite = ( acc.get_pane(b)->get_normal( b, v) *
181  op.get_face_normal( *h_out, *nc)) < 0;
182  }
183 }
184 
186 
187 
188 
189 
190 
191 
Halfedge * get_next(Halfedge *h) const
Definition: HDS_accessor.h:108
bool is_primary(const Vertex *v) const
Definition: HDS_accessor.h:187
Halfedge * get_opposite(Halfedge *h) const
Definition: HDS_accessor.h:99
Real eps_e
Definition: Overlay.h:291
RFC_Pane_overlay * get_pane(Vertex *v) const
Definition: HDS_accessor.h:128
bool is_opposite
Definition: Overlay.h:286
INode * overlay_init()
Definition: Overlay_init.C:48
const Vector_3 & get_normal(const Halfedge *h) const
Definition: HDS_accessor.h:289
bool marked(const Halfedge *h) const
Definition: HDS_accessor.h:299
double Real
Definition: mapbasic.h:322
const Color GREEN
Definition: Color.C:59
Vector_3 get_face_normal(const Halfedge *b, const Point_2 &nc, int scheme=0) const
void unmark(Halfedge *h) const
Definition: HDS_accessor.h:297
void panes(std::vector< Pane * > &ps)
Get a vector of local panes contained in the window.
Halfedge * get_halfedge(Vertex *v) const
Definition: HDS_accessor.h:75
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
const Point_3 & get_point(int id) const
#define RFC_END_NAME_SPACE
Definition: rfc_basic.h:29
Parent_type
Definition: rfc_basic.h:49
RFC_Window_overlay * G
Definition: Overlay.h:281
void get_green_parent(const Vertex *v, const Halfedge *b, Halfedge **o, Parent_type *t, Point_2 *nc)
Definition: Overlay_init.C:101
#define RFC_BEGIN_NAME_SPACE
Definition: rfc_basic.h:28
void int int REAL * x
Definition: read.cpp:74
const Color BLUE
Definition: Color.C:62
Real sq_length(const Halfedge &h) const
Definition: Overlay.C:178
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
HDS_accessor< Tag_true > acc
Definition: Overlay.h:284
Overlay_primitives op
Definition: Overlay.h:283
Halfedge_overlay * next()
Definition: HDS_overlay.h:120
NT q
void mark(Halfedge *h) const
Definition: HDS_accessor.h:295
const Halfedge * get_an_unmarked_halfedge() const
Point_3 get_point(const Halfedge *b, const Point_2S &nc) const
NT abs(const NT &x)
Definition: number_utils.h:130
Some basic geometric data types.
Definition: mapbasic.h:54
bool is_border(const Halfedge *h) const
Definition: HDS_accessor.h:153
RFC_Window_overlay * B
Definition: Overlay.h:280
void set_parent(Halfedge *h, const Point_2 &p, int color)
Definition: HDS_overlay.h:337
bool verbose2
Definition: Overlay.h:288
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