Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Overlay_0d.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_0d.C,v 1.15 2008/12/06 08:43:28 mtcampbe Exp $
24 
25 #include "Overlay.h"
26 #include <cmath>
27 #include "../Rocmap/include/kdtree_d.h"
28 
30 
31 class Point_3_ref : protected Point_3 {
32 public:
33  Point_3_ref() : _v(NULL) {}
34  Point_3_ref( const Point_3 &r, Overlay::Vertex *v=NULL)
35  : Point_3(r), _v(v) {}
36 
37  using Point_3::operator[];
38 
39  Overlay::Vertex *vertex() const { RFC_assertion( _v); return _v; }
40 
41 private:
43 };
44 
45 typedef CGAL::Kdtree_interface<Point_3_ref> KD_interface;
46 typedef CGAL::Kdtree_d<KD_interface> KD_tree;
47 typedef KD_tree::Box box;
48 
49 // Match 0-dimensional features.
50 void Overlay::
52 
53  const Real w2e_ratio = 1;
54  const Real d2e_ratio_sq = 1;
55 
56  std::list<Feature_0> &bf0 = B->flist_0();
57  std::list<Feature_0> &gf0 = G->flist_0();
58 
59  std::vector< Point_3_ref> gf0_1;
60  gf0_1.reserve( gf0.size());
61  for ( std::list<Feature_0>::iterator it=gf0.begin(); it!=gf0.end(); ++it)
62  gf0_1.push_back( Point_3_ref( it->point(), it->vertex()));
63 
64  // Create a 3-dimensional KD-tree for the 0-features of green mesh
65  KD_tree kdtree(3); kdtree.build( gf0_1);
66 
67  int dropped=0;
68  // Query every 0-feature of the blue mesh in the KD-tree to find
69  // whether there is a unique corresponding one in the other mesh.
70  for ( std::list<Feature_0>::iterator
71  it=bf0.begin(), iend=bf0.end(); it != iend; ++it) {
72  Vertex *v = it->vertex();
73  // Find the corresponding green feature of *it in the KD-tree
74  const Point_3 &p = v->point();
75 
76  // Compute the tolerance.
77  Real tol=HUGE_VAL;
78  Halfedge *b=acc.get_halfedge(v), *b0=b;
79  do {
80  Real t = sq_length( *b);
81  if ( t<tol) tol=t;
82  } while ( (b=acc.get_next_around_destination( b))!=b0);
83  tol = std::sqrt( tol);
84 
85  const Vector_3 vtol(tol*w2e_ratio, tol*w2e_ratio, tol*w2e_ratio);
86  KD_tree::Box box( p-vtol, p+vtol, 3);
87 
88  std::vector< Point_3_ref> outList; outList.reserve(2);
89  kdtree.search( std::back_inserter( outList), box);
90 
91  // Find the closest corner in the list
92  Real dist_min = HUGE_VAL;
93  int k=-1;
94 
95  for ( int i=0, n = outList.size(); i<n; ++i) {
96  Real d=(p-reinterpret_cast<const Point_3&>(outList[i])).squared_norm();
97  if ( d <= dist_min) {
98  dist_min = d; k=i;
99  }
100  }
101 
102  if ( dist_min<HUGE_VAL) {
103  Halfedge *g = acc.get_halfedge( outList[k].vertex());
104  if ( acc.is_border(g)) g = acc.get_opposite(g);
105  else g = acc.get_next(g);
106 
107  Real s=tol*tol;
108  Halfedge *h=g, *h0=h;
109  do {
110  Real t = sq_length( *h);
111  if ( t<s) s=t;
112  } while ( (h=acc.get_next_around_origin( h))!=h0);
113 
114  if ( dist_min < s*d2e_ratio_sq) {
115  if ( verbose2) {
116  std::cout << "Matched\t blue vertex "
117  << acc.get_pane(b)->get_index(b->origin())+1
118  << " in pane " << acc.get_pane(b)->id() << " at " << p
119  << "\n with\t green vertex "
120  << acc.get_pane(g)->get_index(g->origin())+1
121  << " in pane " << acc.get_pane(g)->id() << " at "
122  << g->origin()->point() << std::endl;
123  }
124 
125  Halfedge *b = acc.get_halfedge( v);
126  if ( acc.is_border(b)) b = acc.get_opposite(b);
127  else b = acc.get_next(b);
128 
129  // Create an inode for the o-feature
130  INode *x = new INode();
131  x->set_parent( b, Point_2(0,0), BLUE);
132  x->set_parent( g, Point_2(0,0), GREEN);
133 
134  if ( B->snap_on_features()) {
135  // Update the coordinates for the blue point
136  Point_3 &pnt = const_cast<Point_3&>( acc.get_origin(b)->point());
137  pnt = acc.get_origin( g)->point();
138  }
139 
140  insert_node_in_blue_edge( *x, b);
141  continue;
142  }
143  }
144 
145  if ( verbose) {
146  std::cout << "\nRocface Warning: Dropping blue corner vertex "
147  << acc.get_pane(b)->get_index(b->origin())+1
148  << " in pane " << acc.get_pane(b)->id()
149  << " at " << p << std::endl;
150  }
151 
152  // Remove the false blue 0-feature
153  it = --B->remove_feature_0( it);
154  ++dropped;
155  }
156 
157  if ( verbose && dropped) {
158  std::cout << "Dropped " << dropped << " corners in \"" << B->name()
159  << "\" after feature matching" << std::endl;
160  }
161 
162  dropped=0;
163  // Remove the false green 0-features
164  for ( std::list<Feature_0>::iterator
165  it=gf0.begin(), iend=gf0.end(); it != iend; ++it) {
166  Vertex *v = it->vertex();
167  if ( acc.get_inode( v) == NULL) {
168 
169  if ( verbose) {
170  std::cout << "\nRocface Warning: Dropping green corner vertex "
171  << acc.get_pane(v)->get_index(v)+1
172  << " in pane " << acc.get_pane(v)->id()
173  << " at " << v->point() << std::endl;
174  }
175 
176  // Unmark the 0-features in the green window
177  it = --G->remove_feature_0( it);
178  ++dropped;
179  }
180  }
181 
182  if ( verbose && dropped) {
183  std::cout << "Dropped " << dropped << " corners in \"" << G->name()
184  << "\" after feature matching" << std::endl;
185  }
186 }
187 
189 
190 
191 
192 
193 
194 
std::string name() const
The name of the window.
Vertex * get_origin(Halfedge *h) const
Definition: HDS_accessor.h:87
Halfedge * get_next(Halfedge *h) const
Definition: HDS_accessor.h:108
Overlay::Vertex * _v
Definition: Overlay_0d.C:42
Point_3_ref(const Point_3 &r, Overlay::Vertex *v=NULL)
Definition: Overlay_0d.C:34
Feature_list_0::iterator remove_feature_0(Feature_list_0::iterator i)
Remove the given 0-feature from the list.
const NT & d
Halfedge * get_opposite(Halfedge *h) const
Definition: HDS_accessor.h:99
j indices k indices k
Definition: Indexing.h:6
double s
Definition: blastest.C:80
RFC_Pane_overlay * get_pane(Vertex *v) const
Definition: HDS_accessor.h:128
Overlay::Vertex * vertex() const
Definition: Overlay_0d.C:39
KD_tree::Box box
Definition: Overlay_0d.C:47
double Real
Definition: mapbasic.h:322
double sqrt(double d)
Definition: double.h:73
INode * get_inode(Vertex *v) const
Definition: HDS_accessor.h:370
const Color GREEN
Definition: Color.C:59
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
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
CGAL::Kdtree_interface< Point_3_ref > KD_interface
Definition: Overlay_0d.C:45
const Point & point() const
void match_features_0()
Definition: Overlay_0d.C:51
**********************************************************************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
RFC_Window_overlay * G
Definition: Overlay.h:281
Feature_list_0 & flist_0()
blockLoc i
Definition: read.cpp:79
#define RFC_BEGIN_NAME_SPACE
Definition: rfc_basic.h:28
CGAL::Kdtree_d< KD_interface > KD_tree
Definition: Overlay_0d.C:46
void int int REAL * x
Definition: read.cpp:74
const NT & n
const Color BLUE
Definition: Color.C:62
Real sq_length(const Halfedge &h) const
Definition: Overlay.C:178
HDS_accessor< Tag_true > acc
Definition: Overlay.h:284
int get_index(const Vertex *v) const
Halfedge * get_next_around_origin(Halfedge *h) const
Definition: HDS_accessor.h:136
void insert_node_in_blue_edge(INode &x, Halfedge *b)
Definition: Overlay.C:187
Halfedge * get_next_around_destination(Halfedge *h) const
Definition: HDS_accessor.h:146
Some basic geometric data types.
Definition: mapbasic.h:54
bool verbose
Definition: Overlay.h:287
bool is_border(const Halfedge *h) const
Definition: HDS_accessor.h:153
RFC_Window_overlay * B
Definition: Overlay.h:280
int id() const
void set_parent(Halfedge *h, const Point_2 &p, int color)
Definition: HDS_overlay.h:337
bool verbose2
Definition: Overlay.h:288
#define RFC_assertion
Definition: rfc_basic.h:65
SURF::Vector_2< Real > Point_2
Definition: rfc_basic.h:43