Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Overlay.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.h,v 1.17 2008/12/06 08:43:27 mtcampbe Exp $
24 
25 //==========================================================
26 // The header file for the class Overlay.
27 //
28 // Author: Xiangmin Jiao
29 // Revision: May 14, 2001
30 //
31 // See also: Overlay.C.
32 //==========================================================
33 
34 #ifndef MESH_OVERLAY_H
35 #define MESH_OVERLAY_H
36 
37 #include <iostream>
38 #include <list>
39 #include <vector>
40 #include <queue>
41 #include "HDS_overlay.h"
42 #include "HDS_accessor.h"
43 #include "RFC_Window_overlay.h"
44 #include "Overlay_primitives.h"
45 
47 
48 // This class encapsulates the (simplified) overlay algorithm.
49 // The algorithm proceeds in four steps.
50 // Step 1: Project blue vertices onto G.
51 // Step 2: Compute intersection of blue edges with green
52 // edges, and insert intersections into blue edges.
53 // Step 3: Sort intersections on green edges.
54 // Step 4: Project green vertices on B.
55 class Overlay { // Updated: Feb. 25, 2001
56 public:
57  typedef Overlay Self;
58  typedef HDS_overlay HDS;
62  typedef std::pair< const Halfedge*, const Halfedge*> Parent_pair;
63  typedef std::list< const INode *> INode_const_list;
64  typedef std::vector< const INode*> Subface;
65  typedef std::list< Subface > Subface_list;
70 
71 public:
72  // Constructor
73  Overlay( const COM::Window *w1, const COM::Window *w2, const char *pre);
74  // Destructor
75  ~Overlay();
76 
77  // This function is the main interface for the overlay algorithm.
78  int overlay();
79 
80  // Set tolerance for snapping vertices.
81  void set_tolerance( double tol);
82 
83  // Interfaces for the data transfer algorithms
84  RFC_Window_overlay *get_rfc_window( const COM::Window *w)
85  { return ( B->base() == w) ? B : G; }
86  const RFC_Window_overlay *get_rfc_window( const COM::Window *w) const
87  { return ( B->base() == w) ? B : G; }
90  const RFC_Window_overlay *get_blue_window() const { return B; }
91  const RFC_Window_overlay *get_green_window() const { return G; }
92 
93  void get_inodes_of_face( const Facet *f, INode_const_list &nodes);
94 
95  Halfedge* get_parent_face( const Subface &sf, int color);
96 
97  bool subdivide( const INode_const_list &face,
98  INode_const_list::const_iterator last_checked,
99  Subface_list &sub_faces, int color, int depth=0) const;
100 
101  // Obtain the natural coordinates of an inode in the incident face of h.
102  Point_2 get_nat_coor( const INode &i, const Generic_element &e,
103  const Halfedge *h, int color) const;
104 
105  //=========== Subroutines for outputting the intermediate results
108 
109  // Write out all the inodes in Tecplot format.
110  void
111  write_inodes_tec( std::ostream &os, const char *color);
112 
113  // Write out all the inodes in vect format for Geomview.
114  // rgbo [0..255] specifies drawing color.
115  void
116  write_inodes_vec( std::ostream &os);
117 
118  void
119  write_overlay_tec( std::ostream &, const COM::Window *);
120 
121  void
122  write_overlay_off( std::ostream &, const COM::Window *);
123 
124 protected:
125  // ----------------- Functions for step 1 --------------------
126  // The initialization for the overlay algorithm. It locates the
127  // green parent of a blue vertex and create an inode for it.
128  // This initialization step takes linear time.
129  // Returns NULL if unsuccessful. Otherwise, creates a new INode.
130  INode *overlay_init();
131  // Helper for overlay_init which computes the parent of a point x
132  void get_green_parent( const Vertex *v,
133  const Halfedge *b,
134  Halfedge **o,
135  Parent_type *t,
136  Point_2 *nc);
137 
138  // This function ensures the consistency of the green parent of x.
140 
141  // This subroutine is step 1 of the algorithm. It determines the
142  // associates of the vertices of the blue mesh in the green mesh.
143  // and computes the intersections of the blue edges with the green
144  // edges. These intersections are stored in the lists associated
145  // with the blue edges. At input, x is an inode corresponding to
146  // a blue vertex.
148 
149  // Sort the intersection points with respect to green edges and
150  // computes the projection of green vertices in B.
151  void sort_on_green_edges();
153 
154  // The helper for sort_on_green_edges. It inserts a node v into the green
155  // edge v->green_halfedge(). Tag is for marking the buckets. We assume
156  // that each green(blue) edge intersects a blue(green) face at most twice.
157  void insert_node_in_green_edge( INode * v, int tag);
158 
159  // Helper for associate_green_vertices, which determines the parent
160  // of g->destination() from the object containing (b0,t0).
161  void
163 
164  bool verify_inode( const INode *i);
165 
166  // Helpers for determine_edge_parents.
167  Host_face
168  get_edge_parent( const INode &i0, const INode &i1,
169  const int color) const;
170 
172  get_edge_pair_parents( const INode &i0, const INode &i1,
173  const int color) const;
174 
175  //================= Other general helpers for the algorithm.
176  // Computes the intersection of a halfedge b with
177  // the edges in Lk( g1,t1)-St( g0,t0).
178  // It takes O(n) time, where n is the number of incident
179  // edges of the green_parent of (g1,t1). It returns the intersection
180  // point on both b and g, and the parent of the intersection.
181  // This subroutine is used in associate_blue_vertices and
182  // intersect_blue_with_green.
183  bool
184  intersect_link( const INode *x,
185  const Halfedge *b,
186  const Halfedge *g0,
187  const Parent_type t0,
188  Halfedge *g1,
189  const Parent_type t1,
190  Real start,
191  Real *cb,
192  Real *cg,
193  Halfedge **g,
194  Parent_type *t, int tryindex=0);
195 
196  bool
198  Halfedge *g2,
199  Real start,
200  Real *cb,
201  Real *cg,
202  Halfedge **g,
203  Parent_type *t,
204  bool *found,
205  int snapcode,
206  const Vertex *anchor,
207  bool panic);
208 
209  bool
211  Real *cg,
212  Halfedge **g,
213  Parent_type *t);
214 
215  // Checking whether an object <e1,t1> contains another object <e2,t2>.
216  bool
217  contains( const Halfedge *e1, const Parent_type t1,
218  const Halfedge *e2, const Parent_type t2) const;
219 
220  // ===== Following subroutines are for matching 0-dimensional features
221  void match_features_0();
223 
224  int count_edges( const Halfedge *e) const {
225  int i=0;
226  const Halfedge *h=e;
227  do { ++i; } while ( (h=h->next())!= e);
228  return i;
229  }
230 
231 private: // Data and functions for numering the subnodes and subfaces.
232  void set_subnode_id( INode *i, int color, int pane_id, int l_id);
233  int get_subnode_id( const INode *i, int color, int pane_id) const;
234  int get_subnode_copies( const INode *i, int color) const;
235  void convert_nat_coordinates( const INode *i, Halfedge *h, int color,
236  int pane_id, int &lid,
238  Point_2 &nc) const;
239 
240  void number_a_subnode( INode *i, int color,
241  std::map<int, std::pair<int, int> > &cnts);
242  void count_subnodes( INode *i, int color,
243  std::map<int, std::pair<int, int> > &cnts);
244  void number_subnodes();
245  void number_subfaces();
246 
247  std::vector< Node_ID> _subnode_ids_b;
248  std::vector< Node_ID> _subnode_ids_g;
249  std::vector< char> _subnode_copies_b;
250  std::vector< char> _subnode_copies_g;
251 
252  std::map< int,std::map<int,int> > _subnode_imap_b;
253  std::map< int,std::map<int,int> > _subnode_imap_g;
254 
255 private:
256 
258  std::queue<Halfedge*> &q,
259  std::queue<Halfedge*> &q_rdg,
260  std::queue<Halfedge*> &q_crn);
261 
262  bool is_queue_empty( std::queue<Halfedge*> &q,
263  std::queue<Halfedge*> &q_rdg,
264  std::queue<Halfedge*> &q_crn);
265 
266  // Evaluating the squared length of a halfedge. Verified: Jan. 4, 2001
267  Real sq_length( const Halfedge &h) const;
268 
269  const INode *get_next_inode( const INode *v1, const INode *v2, int) const;
270 
271  std::pair<const INode *, const Halfedge*>
272  get_next_inode_ccw( const INode *v0, const INode *v1, int color) const;
273 
274  std::pair<const INode *, const Halfedge*>
275  get_next_inode_cw( const INode *v0, const INode *v1, int color) const;
276 
277  bool logical_xor ( bool a, bool b) const { return a&&!b || !a&&b; }
278 
279 protected:
280  RFC_Window_overlay *B; // input blue window.
281  RFC_Window_overlay *G; // input green window.
282  std::list< INode*> inodes; // Container for all the inode objects.
285 
287  bool verbose;
288  bool verbose2;
289  std::string out_pre; // Output prefix
290 
293 };
294 
296 
297 #endif // MESH_OVERLAY_H
298 
299 
300 
301 
302 
303 
304 
void number_subnodes()
Definition: Overlay_IO.C:236
RFC_Window_overlay * get_green_window()
Definition: Overlay.h:89
std::vector< Node_ID > _subnode_ids_b
Definition: Overlay.h:247
std::list< const INode * > INode_const_list
Definition: Overlay.h:63
Overlay Self
Definition: Overlay.h:57
const RFC_Window_overlay * get_green_window() const
Definition: Overlay.h:91
const INode * get_next_inode(const INode *v1, const INode *v2, int) const
Definition: Overlay.C:1728
std::pair< const Halfedge *, const Halfedge * > Parent_pair
Definition: Overlay.h:62
void set_subnode_id(INode *i, int color, int pane_id, int l_id)
Definition: Overlay_IO.C:45
RFC_Window_overlay * get_rfc_window(const COM::Window *w)
Definition: Overlay.h:84
void number_subfaces()
Definition: Overlay_IO.C:281
Definition: face.h:90
Real eps_e
Definition: Overlay.h:291
RFC_Window_overlay::Feature_0 Feature_0
Definition: Overlay.h:66
void write_overlay_off(std::ostream &, const COM::Window *)
Definition: Overlay.C:2006
void project_adjacent_green_vertices(const INode *, Halfedge *)
Helper for associate_green_vertices().
Definition: Overlay.C:940
bool is_opposite
Definition: Overlay.h:286
Overlay(const COM::Window *w1, const COM::Window *w2, const char *pre)
Definition: Overlay.C:46
INode * overlay_init()
Definition: Overlay_init.C:48
std::map< int, std::map< int, int > > _subnode_imap_g
Definition: Overlay.h:253
void write_inodes_tec(std::ostream &os, const char *color)
Definition: Overlay.C:1541
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
Halfedge * get_parent_face(const Subface &sf, int color)
Definition: Overlay.C:1841
double Real
Definition: mapbasic.h:322
SURF::Generic_element_2 Generic_element
Definition: rfc_basic.h:46
int overlay()
Definition: Overlay.C:73
Host_face get_edge_parent(const INode &i0, const INode &i1, const int color) const
Definition: Overlay.C:1393
RFC_Window_overlay::Halfedge Halfedge
Definition: Overlay.h:60
void insert_node_in_green_edge(INode *v, int tag)
Definition: Overlay.C:856
Real eps_p
Definition: Overlay.h:292
std::vector< char > _subnode_copies_g
Definition: Overlay.h:250
void number_a_subnode(INode *i, int color, std::map< int, std::pair< int, int > > &cnts)
Definition: Overlay_IO.C:165
A window is a collection of panes.
*********************************************************************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 RFC_Window_overlay * get_rfc_window(const COM::Window *w) const
Definition: Overlay.h:86
RFC_Window_overlay::Vertex Vertex
Definition: Overlay.h:59
void get_inodes_of_face(const Facet *f, INode_const_list &nodes)
Definition: Overlay.C:1922
bool intersect_link(const INode *x, const Halfedge *b, const Halfedge *g0, const Parent_type t0, Halfedge *g1, const Parent_type t1, Real start, Real *cb, Real *cg, Halfedge **g, Parent_type *t, int tryindex=0)
Definition: Overlay.C:1251
#define RFC_END_NAME_SPACE
Definition: rfc_basic.h:29
HDS_overlay HDS
Definition: Overlay.h:58
std::list< Feature_1 > Feature_list_1
void insert_edge_into_queue(Halfedge *h, INode *v, std::queue< Halfedge * > &q, std::queue< Halfedge * > &q_rdg, std::queue< Halfedge * > &q_crn)
Definition: Overlay.C:486
void convert_nat_coordinates(const INode *i, Halfedge *h, int color, int pane_id, int &lid, RFC_Pane_overlay::Edge_ID &eid, Point_2 &nc) const
Definition: Overlay_IO.C:123
Parent_type
Definition: rfc_basic.h:49
void match_features_0()
Definition: Overlay_0d.C:51
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
std::list< Feature_0 > Feature_list_0
void export_windows(RFC_Window_base *, RFC_Window_base *)
Export the subdivisions to the two given windows.
Definition: Overlay_IO.C:455
A window is a collection of panes.
A local ID of an edge.
void write_inodes_vec(std::ostream &os)
Definition: Overlay.C:1561
const COM::Window * base() const
Get a reference to the base COM::Window object.
void intersect_blue_with_green()
Definition: Overlay.C:572
std::vector< Node_ID > _subnode_ids_g
Definition: Overlay.h:248
RFC_Window_overlay::Feature_1 Feature_1
Definition: Overlay.h:67
blockLoc i
Definition: read.cpp:79
const RFC_Window_overlay * get_blue_window() const
Definition: Overlay.h:90
void sort_on_green_edges()
Definition: Overlay.C:771
#define RFC_BEGIN_NAME_SPACE
Definition: rfc_basic.h:28
void int int REAL * x
Definition: read.cpp:74
int get_subnode_id(const INode *i, int color, int pane_id) const
Definition: Overlay_IO.C:83
std::map< int, std::map< int, int > > _subnode_imap_b
Definition: Overlay.h:252
RFC_Window_overlay * get_blue_window()
Definition: Overlay.h:88
std::vector< const INode * > Subface
Definition: Overlay.h:64
int count_edges(const Halfedge *e) const
Definition: Overlay.h:224
bool verify_inode(const INode *i)
Definition: Overlay.C:1022
void write_overlay_tec(std::ostream &, const COM::Window *)
Definition: Overlay.C:1956
Real sq_length(const Halfedge &h) const
Definition: Overlay.C:178
RFC_Window_overlay::Facet Facet
Definition: Overlay.h:61
bool intersect_link_helper2(Real *cb, Real *cg, Halfedge **g, Parent_type *t)
Definition: Overlay.C:1223
bool logical_xor(bool a, bool b) const
Definition: Overlay.h:277
HDS_accessor< Tag_true > acc
Definition: Overlay.h:284
RFC_Window_overlay::Feature_list_0 Feature_list_0
Definition: Overlay.h:68
Overlay_primitives op
Definition: Overlay.h:283
Halfedge_overlay * next()
Definition: HDS_overlay.h:120
bool subdivide(const INode_const_list &face, INode_const_list::const_iterator last_checked, Subface_list &sub_faces, int color, int depth=0) const
Definition: Overlay.C:1759
std::list< Subface > Subface_list
Definition: Overlay.h:65
std::vector< char > _subnode_copies_b
Definition: Overlay.h:249
NT q
Point_2 get_nat_coor(const INode &i, const Generic_element &e, const Halfedge *h, int color) const
Definition: Overlay.C:1854
Parent_pair get_edge_pair_parents(const INode &i0, const INode &i1, const int color) const
Definition: Overlay.C:1464
bool intersect_link_helper(const Halfedge *b, Halfedge *g2, Real start, Real *cb, Real *cg, Halfedge **g, Parent_type *t, bool *found, int snapcode, const Vertex *anchor, bool panic)
Definition: Overlay.C:1058
~Overlay()
Definition: Overlay.C:61
void insert_node_in_blue_edge(INode &x, Halfedge *b)
Definition: Overlay.C:187
void set_tolerance(double tol)
Definition: Overlay.C:66
bool verbose
Definition: Overlay.h:287
std::pair< const INode *, const Halfedge * > get_next_inode_ccw(const INode *v0, const INode *v1, int color) const
Definition: Overlay.C:1585
RFC_Window_overlay * B
Definition: Overlay.h:280
int get_subnode_copies(const INode *i, int color) const
Definition: Overlay_IO.C:107
bool verbose2
Definition: Overlay.h:288
void associate_green_vertices()
Definition: Overlay.C:898
std::list< INode * > inodes
Definition: Overlay.h:282
void count_subnodes(INode *i, int color, std::map< int, std::pair< int, int > > &cnts)
Definition: Overlay_IO.C:212
std::string out_pre
Definition: Overlay.h:289
std::pair< const INode *, const Halfedge * > get_next_inode_cw(const INode *v0, const INode *v1, int color) const
Definition: Overlay.C:1655
bool is_queue_empty(std::queue< Halfedge * > &q, std::queue< Halfedge * > &q_rdg, std::queue< Halfedge * > &q_crn)
Definition: Overlay.C:546
bool contains(const Halfedge *e1, const Parent_type t1, const Halfedge *e2, const Parent_type t2) const
Definition: Overlay.C:1488