1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#ifndef GEN_HPP
#define GEN_HPP

#include <iostream>
#include <iomanip> // for setprecision
#include <limits> // for min/max values
#include <assert.h>
#include <math.h>
#include <time.h>
#include <vector>
#include <algorithm>
#include "moab/Core.hpp"
#include "moab/Range.hpp"
#include "moab/AdaptiveKDTree.hpp" // for merging verts
#include "moab/CartVect.hpp"

// SENSE CONVENTIONS
#define SENSE_FORWARD 1
#define SENSE_REVERSE -1
#define SENSE_UNKNOWN 0


// returns a moab interface
moab::Interface *MBI(); 

namespace gen {
  bool error( const bool error_has_occured, const std::string message="" );<--- Function parameter 'message' should be passed by reference.
  
  /// prints a string of the error code returned from MOAB to standard output 
  void moab_printer(moab::ErrorCode error_code);

  void print_vertex_cubit( const moab::EntityHandle vertex );

  void print_vertex_coords( const moab::EntityHandle vertex );

  void print_triangles( const moab::Range tris );

  void print_triangle( const moab::EntityHandle triangle, bool print_edges );

  void print_edge( const moab::EntityHandle edge );

  void print_vertex_count( const moab::EntityHandle input_meshset);

  void print_range( const moab::Range range );

  void print_range_of_edges( const moab::Range range );

  void print_arc_of_edges( const std::vector<moab::EntityHandle> arc_of_edges );<--- Function parameter 'arc_of_edges' should be passed by reference.

  void print_arcs( const std::vector < std::vector<moab::EntityHandle> > arcs );<--- Function parameter 'arcs' should be passed by reference.

  void print_loop( const std::vector<moab::EntityHandle> loop_of_verts );<--- Function parameter 'loop_of_verts' should be passed by reference.

moab::ErrorCode find_closest_vert( const moab::EntityHandle reference_vert,
                               const std::vector<moab::EntityHandle> arc_of_verts,<--- Function parameter 'arc_of_verts' should be passed by reference.
                               unsigned &position,
                               const double dist_limit );

  moab::ErrorCode find_closest_vert( const double tol,
                                 const moab::EntityHandle reference_vert,
                                 const std::vector<moab::EntityHandle> loop_of_verts,<--- Function parameter 'loop_of_verts' should be passed by reference.
                                 std::vector<unsigned> &positions, 
                                 std::vector<double>   &dists);
  /*  moab::ErrorCode find_closest_vert( const moab::EntityHandle reference_vert,
                                  const std::vector<std::vector<moab::EntityHandle> > loops_of_verts,
                                  unsigned int &loop, unsigned int &position, 
                                  double &min_dist);
  */
  // Merge the range of vertices. We do not merge by edges (more
  // stringent) because we do not want to miss corner vertices.

/// finds any vertices within the moab::Range vertices that are with in tol of 
/// each other and merges them
  moab::ErrorCode merge_vertices( moab::Range vertices /* in */, 
			      const  double tol       /* in */);
			      //bool &merge_vertices_again /* out */);

/// returns the square of the distance between v0 and v1
  moab::ErrorCode squared_dist_between_verts( const moab::EntityHandle v0, 
                                          const moab::EntityHandle v1, 
                                          double &d);
/// returns the distance between v0 and v1

  double dist_between_verts( const moab::CartVect v0, const moab::CartVect v1 );
  moab::ErrorCode dist_between_verts( const moab::EntityHandle v0, const moab::EntityHandle v1,
                                  double &d );
  double dist_between_verts( double coords0[], double coords1[] );
  double dist_between_verts( moab::EntityHandle vert0, moab::EntityHandle vert1 );                             

  // Return the length of the curve defined by MBEDGEs or ordered MBVERTEXs.
  double length( std::vector<moab::EntityHandle> curve );

  // Given a vertex and vector of edges, return the number of edges adjacent to the vertex.
  unsigned int n_adj_edges( moab::EntityHandle vert, moab::Range edges );

// Return true if the edges share a vertex. Does not check for coincident edges.
  bool edges_adjacent( moab::EntityHandle edge0, moab::EntityHandle edge1 );

// get the direction unit vector from one vertex to another vertex
  //moab::ErrorCode get_direction( moab::EntityHandle from_vert, moab::EntityHandle to_vert, double dir[] );
  moab::ErrorCode get_direction( const moab::EntityHandle from_vert, const moab::EntityHandle to_vert,
                           moab::CartVect &dir ); 

// from http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=geometry1
  double edge_point_dist( const moab::CartVect a, const moab::CartVect b, const moab::CartVect c );
  double edge_point_dist( const moab::EntityHandle endpt0, const moab::EntityHandle endpt1, 
                          const moab::EntityHandle pt );
  double edge_point_dist( const moab::EntityHandle edge, const moab::EntityHandle pt );

  moab::ErrorCode point_curve_min_dist( const std::vector<moab::EntityHandle> curve, <--- Function parameter 'curve' should be passed by reference.
                                    const moab::EntityHandle pt, double &min_dist,
                                    const double max_dist_along_curve );
  moab::ErrorCode point_curve_min_dist( const std::vector<moab::EntityHandle> curve, <--- Function parameter 'curve' should be passed by reference.
                                    const moab::EntityHandle pt, double &min_dist );

  double triangle_area( const moab::CartVect a, const moab::CartVect b, const moab::CartVect c);
  moab::ErrorCode triangle_area( const moab::EntityHandle conn[], double &area );
  moab::ErrorCode triangle_area( const moab::EntityHandle triangle, double &area );
  double triangle_area( moab::Range triangles );
  
  bool triangle_degenerate( const moab::EntityHandle triangle );
  bool triangle_degenerate( const moab::EntityHandle v0, const moab::EntityHandle v1, const moab::EntityHandle v2);

/// gets the normal vectors of all triangles in moab::Range triangles and returns them as MBCartVect's in normals
  moab::ErrorCode triangle_normals( const moab::Range triangles, std::vector<moab::CartVect> &normals );
  moab::ErrorCode triangle_normal( const moab::EntityHandle triangle, moab::CartVect &normal );
  moab::ErrorCode triangle_normal( const moab::EntityHandle v0, const moab::EntityHandle v1,
                               const moab::EntityHandle v2, moab::CartVect &normal );
  moab::ErrorCode triangle_normal( const moab::CartVect v0, const moab::CartVect v1, 
                               const moab::CartVect v2, moab::CartVect &normal ); 

  // Distance between a point and line. The line is defined by two verts.
  // We are using a line and not a line segment!
  // http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
  moab::ErrorCode line_point_dist( const moab::EntityHandle line_pt1, const moab::EntityHandle line_pt2,
                               const moab::EntityHandle pt0, double &dist );

  // Project the point onto the line. Not the line segment! 
  // Change the coordinates of the pt0 to the projection.
  moab::ErrorCode point_line_projection( const moab::EntityHandle line_pt1,     
                                     const moab::EntityHandle line_pt2,             
                                     const moab::EntityHandle pt0 );

  // Do not change the coords of pt0. Instead return the projected coords.              
  moab::ErrorCode point_line_projection( const moab::EntityHandle line_pt1,     
                                     const moab::EntityHandle line_pt2,             
                                     const moab::EntityHandle pt0,              
                                     moab::CartVect &projected_coords,
                                     double &parameter );  
  // Get the distance of pt0 from line_pt1 if pt0 is projected. No coords are
  // changed in MOAB.
  moab::ErrorCode point_line_projection( const moab::EntityHandle line_pt1,
				     const moab::EntityHandle line_pt2,
				     const moab::EntityHandle pt0,
				     double &dist_along_edge  );
  
  moab::ErrorCode ear_clip_polygon( std::vector<moab::EntityHandle> polygon_of_verts,
                                    const moab::CartVect plane_normal_vector, moab::Range &new_tris );

  int geom_id_by_handle( const moab::EntityHandle set);

/// gets the normal vector of each triangle in tris and tags each triangle with its normal vector
  moab::ErrorCode save_normals( moab::Range tris, moab::Tag normal_tag );

  moab::ErrorCode flip(const moab::EntityHandle tri, const moab::EntityHandle vert0, 
                   const moab::EntityHandle vert2, const moab::EntityHandle surf_set);


/// creates a set of ordered verts from the a set of ordered edges. uses commone vertex between edges to check continuity. 
  moab::ErrorCode ordered_verts_from_ordered_edges( const std::vector<moab::EntityHandle> ordered_edges,<--- Function parameter 'ordered_edges' should be passed by reference.
                                                std::vector<moab::EntityHandle> &ordered_verts );
/// returns the average distance between the vertices in arc0 and arc1. assumes the vertices
/// are ordered appropriately
  moab::ErrorCode dist_between_arcs( bool debug,
                         const std::vector<moab::EntityHandle> arc0,<--- Function parameter 'arc0' should be passed by reference.
                         const std::vector<moab::EntityHandle> arc1,<--- Function parameter 'arc1' should be passed by reference.
                         double &dist );

  // skin edges are a vector of two vertex handles
    // Hold edges in an array of handles.
  struct edge {
    moab::EntityHandle edge, v0, v1;
  };
  int compare_edge(const void *a, const void *b);
  moab::ErrorCode find_skin( moab::Range tris, const int dim,                     
			 // std::vector<std::vector<moab::EntityHandle> > &skin_edges,    
			 moab::Range &skin_edges,                         
                         const bool );
  //moab::ErrorCode find_skin( const moab::Range tris, const int dim, moab::Range &skin_edges, const bool );
  moab::ErrorCode measure( const moab::EntityHandle set, const moab::Tag geom_tag, double &size, bool debug, bool verbose );

  // Given a curve and surface set, get the relative sense.
  // From CGMA/builds/dbg/include/CubitDefines, CUBIT_UNKNOWN=-1, CUBIT_FORWARD=0, CUBIT_REVERSED=1
  moab::ErrorCode get_curve_surf_sense( const moab::EntityHandle surf_set, const moab::EntityHandle curve_set,
                                    int &sense, bool debug = false );

  moab::ErrorCode surface_sense( moab::EntityHandle volume, int num_surfaces,const moab::EntityHandle* surfaces,int* senses_out );
  moab::ErrorCode surface_sense( moab::EntityHandle volume, moab::EntityHandle surface, int& sense_out );

  moab::Tag get_tag( const char* name, int size, moab::TagType store,moab::DataType type, const void* def_value, bool create_if_missing);

  moab::ErrorCode delete_surface( moab::EntityHandle surf, moab::Tag geom_tag, moab::Range tris, int id, bool debug, bool verbose);

  moab::ErrorCode remove_surf_sense_data(moab::EntityHandle del_surf, bool debug);

  moab::ErrorCode combine_merged_curve_senses( std::vector<moab::EntityHandle> &curves, moab::Tag merge_tag, bool debug = false) ;

 /// used to get all mesh tags necessary for sealing a mesh
  moab::ErrorCode get_sealing_mesh_tags( double &facet_tol,
                             double &sme_resabs_tol,
                             moab::Tag &geom_tag, 
                             moab::Tag &id_tag, 
                             moab::Tag &normal_tag, 
                             moab::Tag &merge_tag, 
                             moab::Tag &faceting_tol_tag, 
                             moab::Tag &geometry_resabs_tag, 
                             moab::Tag &size_tag, 
                             moab::Tag &orig_curve_tag);

 /// sets the tracking and ordering options of meshsets retrieved from the mesh
  moab::ErrorCode get_geometry_meshsets( moab::Range geometry_sets[], moab::Tag geom_tag, bool verbose = false);

 /// returns moab::MB_SUCCESS if there exists geometry sets of each dimension in the model
 /// returns MB_FAILURE if there are no geometry sets of any dimension in the model
  moab::ErrorCode check_for_geometry_sets(moab::Tag geom_tag, bool verbose);

}

#endif