Branch data Line data Source code
1 : : //- Class: SurfaceOverlapTool
2 : : //- Description: Utilities to debug imprinting/merging problems
3 : : //- Owner: Steve Storm
4 : : //- Created: 22 October 1999
5 : :
6 : : #ifndef SurfaceOverlapTool_HPP
7 : : #define SurfaceOverlapTool_HPP
8 : :
9 : : #include <map>
10 : : #include "GMem.hpp"
11 : : #include "AnalyticGeometryTool.hpp"
12 : : #include "CGMGeomConfigure.h"
13 : : #include "CurveOverlapFacet.hpp"
14 : : #include "SurfaceOverlapFacet.hpp"
15 : : #include "AbstractTree.hpp"
16 : :
17 : : template <class X> class DLIList;
18 : : class RefFace;
19 : :
20 : : //! Tool to find surfaces and curves that overlap.
21 : : class CUBIT_GEOM_EXPORT SurfaceOverlapTool
22 : : {
23 : :
24 : : public :
25 : :
26 : : //! From the specified surfaces, find surfaces that overlap.
27 : : CubitStatus find_overlapping_surfaces( DLIList<RefFace*> &ref_face_list,
28 : : DLIList<RefEntity*> &faces_to_draw,
29 : : bool filter_slivers = false );
30 : :
31 : : //! From the specified bodies, find surfaces that overlap.
32 : : CubitStatus find_overlapping_surfaces( DLIList<Body*> &body_list,
33 : : DLIList<RefEntity*> &faces_to_draw,
34 : : bool filter_slivers = false );
35 : :
36 : : //! From the specified surfaces, find surfaces that overlap.
37 : : CubitStatus find_overlapping_surfaces( DLIList<RefFace*> &ref_face_list,
38 : : DLIList<RefFace*> &ref_face_list1,
39 : : DLIList<RefFace*> &ref_face_list2,
40 : : DLIList<RefEntity*> &faces_to_draw,
41 : : CubitBoolean show_messages = CUBIT_FALSE,
42 : : bool filter_slivers = false);
43 : :
44 : : //! From the specified bodies, find surfaces that overlap.
45 : : CubitStatus find_overlapping_surfaces( DLIList<Body*> &body_list,
46 : : DLIList<RefFace*> &ref_face_list1,
47 : : DLIList<RefFace*> &ref_face_list2,
48 : : DLIList<RefEntity*> &faces_to_draw,
49 : : CubitBoolean show_messages = CUBIT_FALSE,
50 : : bool filter_slivers = false);
51 : :
52 : : //! From the specified bodies, find surfaces that overlap.
53 : : CubitStatus find_candidate_surfaces_for_imprinting( DLIList<BodySM*> &body_list,
54 : : DLIList<Surface*> &surface_list1,
55 : : DLIList<Surface*> &surface_list2,
56 : : double overlap_tol = -1.0,
57 : : bool filter_slivers = false );
58 : :
59 : : // Searches for surfaces that overlap each other and are good
60 : : // candidates for imprinting. It can even find those with gaps
61 : : // between them (according to settings).
62 : : // First method is for interactive use. They print messages and
63 : : // draw the surfaces as it finds them, as dictated by settings.
64 : : // The second method is for non-interactive use. It simply returns the
65 : : // surface pairs in lists. Note that the same surface can occur
66 : : // multiple times in the lists. The first list will contain sequential
67 : : // surfaces - ie., if surface 1 overlaps with 2 other surfaces, list1
68 : : // will contain surface 1, then surface 1, then the next surface,
69 : : // etc.. If show_messages is CUBIT_TRUE, you will see "Finding surface
70 : : // overlap...", and groupResults, listPairs and displayPairs will be
71 : : // used, otherwise they will be false (default).
72 : :
73 : : //! From the specified surfaces, find overlapping curves.
74 : : CubitStatus find_overlapping_curves( DLIList<Surface*> &surf_list,
75 : : DLIList< DLIList<Curve*> *> &overlapping_curve_lists,
76 : : std::map<Curve*, DLIList<Curve*>* > &curve_to_list_map,
77 : : std::multimap<BodySM*, CubitVector> &body_point_imprint_map);
78 : :
79 : : //! From the specified curves, find those that overlap.
80 : : CubitStatus find_overlapping_curves( DLIList<Curve*> &curve_list,
81 : : DLIList< DLIList<Curve*> *> &overlapping_curve_lists,
82 : : std::map<Curve*, DLIList<Curve*>* > &curve_to_list_map,
83 : : std::multimap<BodySM*, CubitVector> &body_point_imprint_map, double overlap_tol=-1.0);
84 : :
85 : : //! From the specified bodies, find curves that overlap.
86 : : CubitStatus find_overlapping_curves( DLIList<Body*> &bodies,
87 : : std::multimap<RefEdge*, RefEdge*> &overlapping_edge_map,
88 : : double maxgap = -1);
89 : :
90 : : //! From the specified bodies, find curves that overlap.
91 : : CubitStatus find_overlapping_curves( DLIList<BodySM*> &bodies,
92 : : DLIList< DLIList<Curve*> *> &overlapping_curve_lists,
93 : : std::map<Curve*, DLIList<Curve*>* > &curve_to_list_map,
94 : : std::multimap<BodySM*, CubitVector> &body_vertex_imprint_map,
95 : : double overlap_tol);
96 : :
97 : : //! From the specified surfaces, find curves that overlap.
98 : : CubitStatus find_overlapping_curves( DLIList<RefFace*> &faces,
99 : : std::multimap<RefEdge*,
100 : : RefEdge*> &overlapping_edge_map,
101 : : double maxgap = -1);
102 : :
103 : :
104 : : //! From the specified curves, find curves that overlap.
105 : : CubitStatus find_overlapping_curves( DLIList<RefEdge*> &edgelist,
106 : : std::multimap<RefEdge*, RefEdge*> &overlapping_edge_map,
107 : : double maxgap = -1);
108 : :
109 : : //! From the specified curves, find curves that overlap.
110 : : CubitStatus find_overlapping_curves( DLIList<RefEdge*> &edges1, DLIList<RefEdge*> &edges2,
111 : : std::multimap<RefEdge*, RefEdge*> &overlapping_edge_map,
112 : : double maxgap = -1);
113 : :
114 : : //! Checks to if two facets overlap
115 : : CubitBoolean check_overlap( SurfaceOverlapFacet *facet1, SurfaceOverlapFacet *facet2, const double facet_compare_tol );
116 : :
117 : : //! Checks to see if two curves overlap. Reuses graphic facets.
118 : : CubitBoolean check_overlap( RefEdge *edge1, RefEdge *edge2,
119 : : std::map<RefEdge*, DLIList<CurveOverlapFacet*>* > *facet_map,
120 : : double *overlap_tol = NULL );
121 : :
122 : : //! Checks to see if two surfaces overlap.
123 : : CubitBoolean check_overlap( RefFace *ref_face_ptr1,
124 : : RefFace *ref_face_ptr2,
125 : : CubitBoolean abort,
126 : : CubitBoolean draw_overlap = CUBIT_FALSE,
127 : : double *overlap_area = NULL );
128 : :
129 : : //! Checks to see if two curves overlap. Reuses graphic facets.
130 : : CubitBoolean check_overlap( Curve *curve1, Curve *curve2,
131 : : std::map<Curve*, DLIList<CurveOverlapFacet*>* > *facet_map,
132 : : std::multimap<BodySM*, CubitVector > *body_point_imprint_map = NULL,
133 : : double overlap_tol = -1.0);
134 : :
135 : : //! Checks for boundary contact between surfaces
136 : : CubitBoolean check_boundary_contact(
137 : : DLIList<SurfaceOverlapFacet*> *facet_list1,
138 : : DLIList<SurfaceOverlapFacet*> *facet_list2,
139 : : AbstractTree<SurfaceOverlapFacet*> *a_tree,
140 : : const double facet_compare_tol,
141 : : const double tmp_overlap_tol );
142 : :
143 : :
144 : : // swap surfaces and facets to keep the smaller surface first
145 : : CubitBoolean check_size_and_swap_surfs(
146 : : Surface *&tmp_surf1,
147 : : Surface *&tmp_surf2,
148 : : const double tolerance,
149 : : const double facet_tol,
150 : : DLIList<SurfaceOverlapFacet*> *&facet_list1,
151 : : DLIList<SurfaceOverlapFacet*> *&facet_list2,
152 : : std::map<Surface*, AbstractTree<SurfaceOverlapFacet*>* > *&a_tree_map,
153 : : AbstractTree<SurfaceOverlapFacet*> *&a_tree2 );
154 : :
155 : : // extract facets if not already available
156 : : CubitBoolean extract_surf_facets(
157 : : Surface *surface1,
158 : : Surface *surface2,
159 : : std::map<Surface*, DLIList<SurfaceOverlapFacet*>* > *facet_map,
160 : : const double tolerance,
161 : : const double facet_tol,
162 : : DLIList<SurfaceOverlapFacet*> *&facet_list1,
163 : : DLIList<SurfaceOverlapFacet*> *&facet_list2 );
164 : :
165 : : //! Determine tolerance for checking intersection between surfaces
166 : : CubitBoolean calculate_tolerances_for_surf_intersection(
167 : : Surface *tmp_surf1,
168 : : Surface *tmp_surf2,
169 : : DLIList<SurfaceOverlapFacet*> *facet_list1,
170 : : DLIList<SurfaceOverlapFacet*> *facet_list2,
171 : : std::map<Surface*, double > *area_map,
172 : : double &facet_compare_tol,
173 : : double &overlap_tolerance );
174 : :
175 : : //! Checks for overlap betwen facet_lists of two surfaces
176 : : CubitBoolean check_overlap( DLIList<SurfaceOverlapFacet*> *facet_list1,
177 : : DLIList<SurfaceOverlapFacet*> *facet_list2,
178 : : AbstractTree<SurfaceOverlapFacet*> *a_tree,
179 : : const double facet_tol,
180 : : const double tolerance );
181 : :
182 : : //! Checks to see the two groups of facets overlap.
183 : : CubitBoolean check_overlap( DLIList<SurfaceOverlapFacet*> *facet_list1,
184 : : DLIList<SurfaceOverlapFacet*> *facet_list2,
185 : : AbstractTree<SurfaceOverlapFacet*> *a_tree,
186 : : CubitBoolean abort,
187 : : CubitBoolean draw_overlap,
188 : : double *overlap_area );
189 : :
190 : : //! Draws the overlapping surface pair.
191 : : CubitBoolean draw_overlapping_surface_pair( RefFace *ref_face_1,
192 : : RefFace *ref_face_2);
193 : :
194 : :
195 : : //! List the settings used for surface overlap detection
196 : : void list_settings();
197 : :
198 : : unsigned short get_facet_ang_tol();
199 : : void set_facet_ang_tol( unsigned short angle_tol );
200 : :
201 : :
202 : : //Initialize all settings in this class
203 : : static void initialize_settings();
204 : :
205 : : static int get_facet_ang_tol_setting();
206 : : static void set_facet_ang_tol_setting( int angle_tol );
207 : :
208 : : static double get_facet_abs_tol();
209 : : static void set_facet_abs_tol( double absolute_tol );
210 : :
211 : : static double get_gap_min();
212 : : static void set_gap_min( double val );
213 : :
214 : : static double get_gap_max();
215 : : static void set_gap_max( double val );
216 : :
217 : : static double get_angle_min();
218 : : static void set_angle_min( double val );
219 : :
220 : : static double get_angle_max();
221 : : static void set_angle_max( double val );
222 : :
223 : : static double get_overlap_tolerance();
224 : : static void set_overlap_tolerance( double val );
225 : :
226 : : static int get_normal_type(); //
227 : : static void set_normal_type( int type ); //
228 : :
229 : : static CubitString get_normal_type_setting();
230 : : static void set_normal_type_setting( CubitString type );
231 : :
232 : : static CubitBoolean get_group_results(); //
233 : : static void set_group_results( CubitBoolean setting ); //
234 : :
235 : : static CubitBoolean get_list_pairs(); //
236 : : static void set_list_pairs( CubitBoolean setting ); //
237 : :
238 : : static CubitBoolean get_display_pairs(); //
239 : : static void set_display_pairs( CubitBoolean setting ); //
240 : :
241 : : static int get_group_results_setting();
242 : : static void set_group_results_setting( int setting );
243 : :
244 : : static int get_list_pairs_setting();
245 : : static void set_list_pairs_setting( int setting );
246 : :
247 : : static int get_display_pairs_setting();
248 : : static void set_display_pairs_setting( int setting );
249 : :
250 : : static CubitBoolean get_imprint();
251 : : static void set_imprint( CubitBoolean setting );
252 : :
253 : : static CubitBoolean get_check_within_bodies();
254 : : static void set_check_within_bodies( CubitBoolean setting );
255 : :
256 : : static CubitBoolean get_check_across_bodies();
257 : : static void set_check_across_bodies( CubitBoolean setting );
258 : : CubitBoolean get_skip_facing_surfaces();
259 : : void set_skip_facing_surfaces( CubitBoolean setting );
260 : : static SurfaceOverlapTool* instance();
261 : : // Returns a static pointer to unique instance of this class.
262 : : static void delete_instance()
263 : : {
264 : : if(instance_)
265 : : delete instance_;
266 : : instance_ = NULL;
267 : : };
268 : :
269 : : ~SurfaceOverlapTool();
270 : : //- Destructor.
271 : :
272 : : protected :
273 : :
274 : : private :
275 : :
276 : :
277 : :
278 : : CubitStatus find_overlapping_surfaces( DLIList<RefFace*> &ref_face_list,
279 : : DLIList<RefFace*> &ref_face_list1,
280 : : DLIList<RefFace*> &ref_face_list2,
281 : : DLIList<RefEntity*> &pair_list,
282 : : CubitBoolean list_pairs,
283 : : int prog_step,
284 : : bool filter_slivers = false);
285 : : // Private workhorse function for finding the overlapping surfaces. Here
286 : : // pair_list is a list of all the surfaces that were found that overlap.
287 : : // If prog_step == -1 it does not step the progress bar.
288 : :
289 : : double find_area_overlap( SurfaceOverlapFacet *facet1, SurfaceOverlapFacet *facet2, const double facet_compare_tol );
290 : :
291 : :
292 : : CubitBoolean check_surfs_for_imprinting( Surface *surface1,
293 : : Surface *surface2,
294 : : std::map<Surface*, DLIList<SurfaceOverlapFacet*>* > *facet_map,
295 : : std::map<Surface*, double > *area_map,
296 : : std::map<Surface*, AbstractTree<SurfaceOverlapFacet*>* > *a_tree_map,
297 : : double overlap_tol=-1.0);
298 : :
299 : :
300 : : //CubitStatus draw_facets( GMem* gMem, int color = 2 );
301 : : //void draw_triangle( Triangle3 &T, int color = 2 );
302 : :
303 : : CubitStatus imprint(DLIList<RefFace*> &ref_face_list1,
304 : : DLIList<RefFace*> &ref_face_list2);
305 : : //- Imprints the bodies containing the lists of surfaces. Also
306 : : //- uses the edges imprinting rather than the normal imprint.
307 : :
308 : : int num_descendants(Body *body);
309 : : //- Counts the total number of descendants of the body.
310 : : //- Only counts Ref* entities.
311 : :
312 : : CubitStatus copy_edges_in_list(DLIList<RefEdge*> &old_list,
313 : : DLIList<RefEdge*> &new_list );
314 : : //- copy's each of the edges in the old list, and puts the
315 : : //- stand alone edges in the new list.
316 : : //- NOTE: THESE ARE NEWLY CREATED EDGES AND SHOULD BE DELETED
317 : : //- BY THE CALLING FUNCTION.
318 : :
319 : : CubitStatus delete_edges_in_list(DLIList<RefEdge*> &edge_list);
320 : : //- Deletes the RefEdges in the list via GeometryQueryTool.
321 : :
322 : : static SurfaceOverlapTool* instance_;
323 : : // Static pointer to unique instance of this class
324 : :
325 : : SurfaceOverlapTool();
326 : : //- Constructor for the SurfaceOverlapTool object
327 : :
328 : : /*! The angular tolerance indicates the maximum angle between
329 : : normals of adjacent surface facets. The default angular
330 : : tolerance is 15° - consider using a value of 5° . This will
331 : : generate a more accurate facetted representation of the
332 : : geometry for overlap detection. */
333 : : static unsigned short facetAngTol;
334 : :
335 : : /*! The distance tolerance means the maximum actual distance
336 : : between the generated facets and the surface. This value is
337 : : by default ignored by the facetter - consider specifying a
338 : : reasonable value here for more accurate results */
339 : : static double facetAbsTol;
340 : :
341 : : /*! The overlap algorithm will search for surfaces that are
342 : : within a distance from the gapMin to gapMax. */
343 : : static double gapMin;
344 : : static double gapMax;
345 : :
346 : : //@{
347 : : /*! Angle comparison for determining if facets are coplanar. If
348 : : they are within angleMin and angleMax they are considered to be
349 : : coplanar. */
350 : : static double angleMin;
351 : : static double angleMax;
352 : : //@}
353 : :
354 : : //! Searches for overlapping surface that have surface normals
355 : : //! in any, opposite, or the same direction.
356 : : static int normalType; // 1=any, 2=opposite, 3=same
357 : :
358 : : //! Controls if surfaces are put in a group or not.
359 : : static CubitBoolean groupResults;
360 : :
361 : : //! Prints out the lists of overlapping surface pairs.
362 : : static CubitBoolean listPairs;
363 : :
364 : : //! Draws the lists of overlapping surface pairs.
365 : : static CubitBoolean displayPairs;
366 : :
367 : : //! Imprint overlapping surfaces parts onto one another.
368 : : static CubitBoolean imprintResults;
369 : :
370 : : //! The area threshold that 2 surfaces have to actually overlap.
371 : : //! Prevents detection of sliver overlaps.
372 : : static double overlapTolerance;
373 : :
374 : : //! if the normalType is 2 skip surfaces that face each other
375 : : static CubitBoolean skipFacingSurfaces;
376 : :
377 : : //! By default this tool will not search for overlapping
378 : : //! pairs within bodies - only between different bodies.
379 : : //! Turn this setting on to search for pairs within bodies.
380 : : //! Note however that this will slow the algorithm down.
381 : : static CubitBoolean checkWithinBodies;
382 : :
383 : : //! If true, by default, will try to find surfaces of body A
384 : : //! that overlap surfaces of body B. Setting this flag to
385 : : //! false will make the tool only check for surfaces that
386 : : //! overlap in the same body.
387 : : static CubitBoolean checkAcrossBodies;
388 : : };
389 : :
390 : : inline
391 : : void SurfaceOverlapTool::set_facet_ang_tol( unsigned short val )
392 : : {facetAngTol=val;}
393 : :
394 : : inline
395 : 0 : double SurfaceOverlapTool::get_facet_abs_tol()
396 : 0 : {return facetAbsTol;}
397 : : inline
398 : 0 : void SurfaceOverlapTool::set_facet_abs_tol( double val )
399 : 0 : {facetAbsTol=val;}
400 : :
401 : : inline
402 : 0 : double SurfaceOverlapTool::get_gap_min()
403 : 0 : {return gapMin;}
404 : : inline
405 : 0 : void SurfaceOverlapTool::set_gap_min( double val )
406 : 0 : {gapMin=val;}
407 : :
408 : : inline
409 : 0 : double SurfaceOverlapTool::get_gap_max()
410 : 0 : {return gapMax;}
411 : : inline
412 : 0 : void SurfaceOverlapTool::set_gap_max( double val )
413 : 0 : {gapMax=val;}
414 : :
415 : : inline
416 : 0 : double SurfaceOverlapTool::get_angle_min()
417 : 0 : {return angleMin;}
418 : : inline
419 : 0 : void SurfaceOverlapTool::set_angle_min( double val )
420 : 0 : {angleMin=val;}
421 : :
422 : : inline
423 : 0 : double SurfaceOverlapTool::get_angle_max()
424 : 0 : {return angleMax;}
425 : : inline
426 : 0 : void SurfaceOverlapTool::set_angle_max( double val )
427 : 0 : {angleMax=val;}
428 : :
429 : : inline
430 : 0 : double SurfaceOverlapTool::get_overlap_tolerance()
431 : 0 : {return overlapTolerance;}
432 : : inline
433 : 0 : void SurfaceOverlapTool::set_overlap_tolerance( double val )
434 : 0 : {overlapTolerance=val;}
435 : :
436 : : inline
437 : 0 : int SurfaceOverlapTool::get_normal_type()
438 : 0 : {return normalType;}
439 : : inline
440 : 0 : void SurfaceOverlapTool::set_normal_type( int type )
441 : 0 : {normalType=type;}
442 : :
443 : : inline
444 : : CubitBoolean SurfaceOverlapTool::get_group_results()
445 : : {return groupResults;}
446 : : inline
447 : : void SurfaceOverlapTool::set_group_results( CubitBoolean setting )
448 : : {groupResults=setting;}
449 : :
450 : : inline
451 : : CubitBoolean SurfaceOverlapTool::get_list_pairs()
452 : : {return listPairs;}
453 : : inline
454 : : void SurfaceOverlapTool::set_list_pairs( CubitBoolean setting )
455 : : {listPairs=setting;}
456 : :
457 : : inline
458 : : CubitBoolean SurfaceOverlapTool::get_display_pairs()
459 : : {return displayPairs;}
460 : : inline
461 : : void SurfaceOverlapTool::set_display_pairs( CubitBoolean setting )
462 : : {displayPairs=setting;}
463 : : inline
464 : : CubitBoolean SurfaceOverlapTool::get_imprint()
465 : : {return imprintResults;}
466 : : inline
467 : : void SurfaceOverlapTool::set_imprint( CubitBoolean setting )
468 : : {imprintResults=setting;}
469 : : inline
470 : 0 : CubitBoolean SurfaceOverlapTool::get_check_within_bodies()
471 : 0 : {return checkWithinBodies;}
472 : : inline
473 : 0 : void SurfaceOverlapTool::set_check_within_bodies( CubitBoolean setting )
474 : 0 : {checkWithinBodies=setting;}
475 : : inline
476 : 0 : CubitBoolean SurfaceOverlapTool::get_check_across_bodies()
477 : 0 : {return checkAcrossBodies;}
478 : : inline
479 : 0 : void SurfaceOverlapTool::set_check_across_bodies( CubitBoolean setting )
480 : 0 : {checkAcrossBodies=setting;}
481 : : inline
482 : 0 : CubitBoolean SurfaceOverlapTool::get_skip_facing_surfaces()
483 : 0 : {return skipFacingSurfaces;}
484 : : inline
485 : 0 : void SurfaceOverlapTool::set_skip_facing_surfaces( CubitBoolean setting )
486 : 0 : {skipFacingSurfaces=setting;}
487 : : #endif
488 : :
489 : :
490 : :
|