Branch data Line data Source code
1 : : //-------------------------------------------------------------------------
2 : : // Filename : PartitionTool.cpp
3 : : //
4 : : // Purpose : Functions for splitting geometry using VG
5 : : //
6 : : // Special Notes :
7 : : //
8 : : // Creator : Jason Kraftcheck
9 : : //
10 : : // Creation Date : 12/13/98
11 : : //-------------------------------------------------------------------------
12 : :
13 : : //When determining if a RefEdge lies within a Loop, this
14 : : //is the number of points on that RefEdge that are checked.
15 : :
16 : : #include "PartitionTool.hpp"
17 : : //#include "VirtualQueryEngine.hpp"
18 : : #include "DLIList.hpp"
19 : : #include "GfxDebug.hpp"
20 : : #include "GMem.hpp"
21 : : #include "CastTo.hpp"
22 : :
23 : : #include "Body.hpp"
24 : : #include "RefFace.hpp"
25 : : #include "RefEdge.hpp"
26 : : #include "RefVertex.hpp"
27 : : #include "Loop.hpp"
28 : : #include "Chain.hpp"
29 : : #include "Shell.hpp"
30 : :
31 : : #include "CoEdge.hpp"
32 : : #include "CoVertex.hpp"
33 : : #include "CoFace.hpp"
34 : : #include "CoVolume.hpp"
35 : :
36 : : #include "Point.hpp"
37 : : #include "Curve.hpp"
38 : : #include "IntersectionTool.hpp"
39 : :
40 : : #include "ModelQueryEngine.hpp"
41 : :
42 : : #include "PartitionLump.hpp"
43 : : #include "PartitionSurface.hpp"
44 : : #include "PartitionCurve.hpp"
45 : : #include "PartPTCurve.hpp"
46 : : #include "PartitionPoint.hpp"
47 : : //#include "PartitionLump.hpp"
48 : : #include "PartitionLoop.hpp"
49 : : #include "PartitionCoEdge.hpp"
50 : : #include "SegmentedCurve.hpp"
51 : :
52 : : #include "CompositeTool.hpp"
53 : : #include "CompositeEngine.hpp"
54 : : #include "CompositePoint.hpp"
55 : : #include "GeometryUtil.hpp"
56 : : #include "RefEntityName.hpp"
57 : :
58 : : #include "PartitionEngine.hpp"
59 : :
60 : : #include "BodySM.hpp"
61 : : #include "SubCurve.hpp"
62 : :
63 : : #include "RefEntityFactory.hpp"
64 : : #include "GeometryQueryTool.hpp"
65 : : #include "MergeTool.hpp"
66 : : #include "CubitUndo.hpp"
67 : :
68 : : #include "TDUPtr.hpp"
69 : : #include <vector>
70 : :
71 : : #include "AppUtil.hpp"
72 : : #include "GeometryEvent.hpp"
73 : :
74 : : PartitionTool* PartitionTool::instance_ = NULL;
75 : :
76 : : //Debugging output
77 : : void pt_print_bte_list( int debug_flag, DLIList<BasicTopologyEntity*>& edges,
78 : : const char* trailing_string = "\n" );
79 : : void pt_print_edge_list( int debug_flag, DLIList<RefEdge*>& edges,
80 : : const char* trailing_string = "\n" );
81 : : void pt_print_face_list( int debug_flag, DLIList<RefFace*>& faces,
82 : : const char* trailing_string = "\n" );
83 : : void pt_print_loop( int debug_flag, Loop* loop_ptr,
84 : : const char* trailing_string = "\n" );
85 : : void pt_print_shell( int debug_flag, Shell* shell_ptr,
86 : : const char* trailing_string = "\n" );
87 : :
88 : : //Helper class for surface partitioning.
89 : : struct LoopIntersection {
90 : : Loop* loop_ptr;
91 : : RefVertex* vtx_ptr;
92 : : //So we can put it in a DLIList:
93 : : LoopIntersection( int i = 0 );
94 : :
95 : :
96 : : bool operator<( const LoopIntersection& ) const { assert(0); return false; }
97 : : bool operator>( const LoopIntersection& ) const { assert(0); return false; }
98 : : bool operator<=( const LoopIntersection& ) const { assert(0); return false; }
99 : : bool operator>=( const LoopIntersection& ) const { assert(0); return false; }
100 : : bool operator==( const LoopIntersection& ) const { assert(0); return true; }
101 : : bool operator!=( const LoopIntersection& ) const { assert(0); return true; }
102 : : };
103 : : //So we can put it in a DLIList:
104 : 0 : LoopIntersection::LoopIntersection( int ) : loop_ptr(0), vtx_ptr(0) {}
105 : :
106 : : //-------------------------------------------------------------------------
107 : : // Purpose : constructor/destructor
108 : : //
109 : : // Special Notes :
110 : : //
111 : : // Creator : Jason Kraftcheck
112 : : //
113 : : // Creation Date : 12/13/98
114 : : //-------------------------------------------------------------------------
115 : 0 : PartitionTool::PartitionTool()
116 : : {
117 : 0 : facetingTolerance = 10;
118 : 0 : }
119 : 0 : PartitionTool::~PartitionTool()
120 : : {
121 : 0 : instance_ = NULL;
122 [ # # ]: 0 : }
123 : :
124 : : //-------------------------------------------------------------------------
125 : : // Purpose : Split a curve
126 : : //
127 : : // Special Notes :
128 : : //
129 : : // Creator : Jason Kraftcheck
130 : : //
131 : : // Creation Date : 06/15/99
132 : : //-------------------------------------------------------------------------
133 : 0 : RefVertex* PartitionTool::partition( RefEdge* edge_ptr,
134 : : const CubitVector& split_point,
135 : : RefEdge*& first_new_edge,
136 : : RefEdge*& second_new_edge,
137 : : CubitBoolean )
138 : : {
139 : : int i, j;
140 : 0 : first_new_edge = second_new_edge = NULL;
141 : :
142 : : CubitBoolean is_free_curve =
143 [ # # ][ # # ]: 0 : edge_ptr->num_parent_ref_entities() == 0 ? CUBIT_TRUE : CUBIT_FALSE;
144 : :
145 [ # # ]: 0 : DLIList<RefFace*> faces;
146 [ # # ]: 0 : edge_ptr->ref_faces( faces );
147 [ # # ]: 0 : RefVertex* input_start_vtx = edge_ptr->start_vertex();
148 [ # # ]: 0 : RefVertex* input_end_vtx = edge_ptr->end_vertex();
149 : :
150 : : // partition each merged curve in the refedge
151 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_list, curve_bridges, coedge_bridges, point_bridges;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
152 [ # # ][ # # ]: 0 : edge_ptr->bridge_manager()->get_bridge_list( bridge_list );
153 : 0 : RefVertex* new_vertex = 0;
154 [ # # ][ # # ]: 0 : for( i = bridge_list.size(); i--; )
155 : : {
156 [ # # ][ # # ]: 0 : Curve* curve_ptr = dynamic_cast<Curve*>(bridge_list.get_and_step());
157 [ # # ]: 0 : double u = curve_ptr->u_from_position( split_point );
158 [ # # ][ # # ]: 0 : TBPoint* pt = PartitionEngine::instance().insert_point( curve_ptr, u );
159 [ # # ]: 0 : if( !pt )
160 : : {
161 : : // try to back out any partitions we've already made.
162 [ # # ]: 0 : bridge_list.clean_out();
163 [ # # ]: 0 : if( new_vertex )
164 : : {
165 [ # # ][ # # ]: 0 : new_vertex->bridge_manager()->get_bridge_list(bridge_list);
166 [ # # ]: 0 : new_vertex->deactivated(CUBIT_TRUE);
167 : : }
168 : :
169 [ # # ][ # # ]: 0 : while( bridge_list.size() )
170 [ # # ]: 0 : PartitionEngine::instance().remove_point(
171 [ # # ][ # # ]: 0 : dynamic_cast<PartitionPoint*>(bridge_list.pop()) );
[ # # ]
172 : :
173 : 0 : break;
174 : : }
175 : :
176 [ # # ]: 0 : if( new_vertex )
177 [ # # ][ # # ]: 0 : new_vertex->bridge_manager()->add_bridge( pt );
178 : : else
179 [ # # ][ # # ]: 0 : new_vertex = GeometryQueryTool::instance()->make_RefVertex(pt);
180 : : }
181 : :
182 [ # # ]: 0 : if (!new_vertex) // failed -- no curves split
183 : 0 : return 0;
184 : :
185 : :
186 : : // Get two "new" RefEdges to work with
187 : : RefEdge* new_edges[2]; // two refedges split from input refedge
188 : : RefVertex* vertices[2]; // the to-be other RefVertex on each edge (not new_vtx)
189 : : bool start_vtx[2]; // for the first curve, is new_vtx the start of that curve
190 : : CubitSense senses[2]; // bridge sense for first curve in each refedge
191 : : // For each of two curves adjacent to the first split point
192 [ # # ]: 0 : TBPoint* point = new_vertex->get_point_ptr();
193 [ # # ]: 0 : point->get_parents(curve_bridges);
194 [ # # ][ # # ]: 0 : assert(curve_bridges.size() == 2);
195 [ # # ]: 0 : curve_bridges.reset();
196 [ # # ]: 0 : for (i = 0; i < 2; i++)
197 : : {
198 [ # # ][ # # ]: 0 : Curve* curve = dynamic_cast<Curve*>(curve_bridges.get_and_step());
199 [ # # ][ # # ]: 0 : new_edges[i] = dynamic_cast<RefEdge*>(curve->topology_entity());
200 : :
201 : : // need to create new RefEdge
202 [ # # ]: 0 : if (!new_edges[i])
203 : : {
204 [ # # ][ # # ]: 0 : if (curve->bridge_sense() == CUBIT_REVERSED)
205 [ # # ]: 0 : curve->reverse_bridge_sense(); // clear bridge sense
206 [ # # ]: 0 : if(is_free_curve)
207 [ # # ][ # # ]: 0 : new_edges[i] = GeometryQueryTool::instance()->make_free_RefEdge(curve);
208 : : else
209 [ # # ][ # # ]: 0 : new_edges[i] = GeometryQueryTool::instance()->make_RefEdge(curve);
210 : : }
211 : :
212 : : // get other vertex on refedge, save to use in determining
213 : : // which curve pairs should merge.
214 [ # # ]: 0 : bridge_list.clean_out();
215 [ # # ]: 0 : curve->get_children(bridge_list);
216 [ # # ]: 0 : bridge_list.move_to(point);
217 [ # # ]: 0 : bridge_list.reset();
218 [ # # ][ # # ]: 0 : if (bridge_list.get() == point)
219 : 0 : start_vtx[i] = true;
220 [ # # ][ # # ]: 0 : else if(bridge_list.step_and_get() == point)
221 : 0 : start_vtx[i] = false;
222 : : else
223 : 0 : assert(0);
224 : :
225 : : // populate arrays with necessary info to determine relative
226 : : // sense of other curves to be merged with this one.
227 [ # # ][ # # ]: 0 : vertices[i] = dynamic_cast<RefVertex*>(bridge_list.next()->topology_entity());
[ # # ]
228 [ # # ]: 0 : senses[i] = curve->bridge_sense();
229 : : }
230 : :
231 : : // Merge remaining curve pairs into the two refedges
232 [ # # ]: 0 : point_bridges.clean_out();
233 [ # # ][ # # ]: 0 : new_vertex->bridge_manager()->get_bridge_list(point_bridges);
234 [ # # ]: 0 : point_bridges.move_to(point);
235 [ # # ][ # # ]: 0 : assert(point_bridges.get() == point);
236 [ # # ][ # # ]: 0 : for (i = point_bridges.size() - 1; i--; ) // for each pair of curves
237 : : {
238 [ # # ]: 0 : TopologyBridge* point_bridge = point_bridges.step_and_get();
239 [ # # ]: 0 : curve_bridges.clean_out();
240 [ # # ]: 0 : point_bridge->get_parents(curve_bridges);
241 [ # # ][ # # ]: 0 : assert(curve_bridges.size() == 2);
242 : :
243 [ # # ][ # # ]: 0 : while (curve_bridges.size()) // for each curve in the pair
244 : : {
245 [ # # ][ # # ]: 0 : Curve* curve = dynamic_cast<Curve*>(curve_bridges.pop());
246 [ # # ]: 0 : bridge_list.clean_out();
247 [ # # ]: 0 : curve->get_children(bridge_list);
248 [ # # ]: 0 : bridge_list.reset();
249 : 0 : bool is_start = false;
250 [ # # ][ # # ]: 0 : if (bridge_list.get() == point_bridge)
251 : 0 : is_start = true;
252 [ # # ][ # # ]: 0 : else if(bridge_list.step_and_get() == point_bridge)
253 : 0 : is_start = false;
254 : : else
255 : 0 : assert(0); // bad bridge connectivity
256 : :
257 [ # # ][ # # ]: 0 : RefVertex* vtx = dynamic_cast<RefVertex*>(bridge_list.next()->topology_entity());
[ # # ]
258 : :
259 [ # # ][ # # ]: 0 : for (j = 0; j < 2 && vertices[j] != vtx; j++);
260 [ # # ]: 0 : if (j == 2)
261 : 0 : continue; // can't merge -- something went wrong
262 : :
263 [ # # ]: 0 : if (vertices[0] == vertices[1]) // closed curve, need to do geometric check
264 : : {
265 [ # # ]: 0 : CubitVector center = curve->center_point();
266 [ # # ][ # # ]: 0 : double d1 = (center - new_edges[0]->center_point()).length_squared();
[ # # ]
267 [ # # ][ # # ]: 0 : double d2 = (center - new_edges[1]->center_point()).length_squared();
[ # # ]
268 : 0 : j = d1 < d2 ? 0 : 1;
269 : : }
270 : :
271 : 0 : RefEdge* edge = new_edges[j];
272 [ # # ][ # # ]: 0 : if (curve->topology_entity() != edge) // if not already merged ...
273 : : {
274 [ # # ][ # # ]: 0 : if (curve->bridge_manager()) // if in a different edge, unmerge
275 [ # # ][ # # ]: 0 : curve->bridge_manager()->remove_bridge(curve);
276 : :
277 [ # # ]: 0 : curve->get_parents(coedge_bridges); // need to unmerge coedges too
278 [ # # ][ # # ]: 0 : while (coedge_bridges.size())
279 : : {
280 [ # # ]: 0 : TopologyBridge* coe_bridge = coedge_bridges.pop();
281 [ # # ][ # # ]: 0 : if (coe_bridge->owner())
282 [ # # ][ # # ]: 0 : coe_bridge->bridge_manager()->remove_bridge(coe_bridge);
283 : : }
284 : :
285 [ # # ][ # # ]: 0 : edge->bridge_manager()->add_bridge(curve); // merge
286 : : }
287 : :
288 : : // set relative sense
289 : 0 : bool edge_reversed = (is_start != start_vtx[j]);
290 [ # # ]: 0 : bool curv_reversed = curve->bridge_sense() != senses[j];
291 [ # # ]: 0 : if (edge_reversed != curv_reversed)
292 [ # # ]: 0 : curve->reverse_bridge_sense();
293 : : }
294 : : }
295 : :
296 : : // Rebuild TopologyEntity topology
297 [ # # ][ # # ]: 0 : for( i = faces.size(); i--; )
298 : : {
299 [ # # ]: 0 : RefFace* face = faces.get_and_step();
300 [ # # ]: 0 : bridge_list.clean_out();
301 [ # # ][ # # ]: 0 : face->bridge_manager()->get_bridge_list(bridge_list);
302 [ # # ][ # # ]: 0 : assert(bridge_list.size());
303 [ # # ][ # # ]: 0 : for (int j = bridge_list.size(); j--; )
304 : : {
305 [ # # ]: 0 : TopologyBridge* bridge = bridge_list.get_and_step();
306 [ # # ]: 0 : Surface* surf = dynamic_cast<Surface*>(bridge);
307 [ # # ]: 0 : assert(!!surf);
308 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->make_RefFace(surf);
309 : : }
310 : : }
311 : : // tweak some stuff so the resulting RefEdges have the same
312 : : // sense as the input RefEdge.
313 : :
314 : : // Get the edges in the order we want.
315 : : // If curve was not closed, put whichever contains the original start vertex first.
316 [ # # ]: 0 : if (input_start_vtx != input_end_vtx)
317 [ # # ]: 0 : i = new_edges[0]->other_vertex(input_start_vtx) ? 0 : 1;
318 : : //If closed, sense of original edge didn't change so use that to determine the order
319 [ # # ]: 0 : else if (new_edges[0] == edge_ptr)
320 [ # # ]: 0 : i = new_edges[0]->start_vertex() == input_start_vtx ? 0 : 1;
321 : : else
322 [ # # ][ # # ]: 0 : i = new_edges[1]->start_vertex() == input_start_vtx ? 1 : 0;
323 : 0 : first_new_edge = new_edges[i];
324 : 0 : second_new_edge = new_edges[1-i];
325 : :
326 [ # # ][ # # ]: 0 : DLIList<RefEntity*> vtx_list;
327 [ # # ][ # # ]: 0 : vtx_list.append(new_vertex);
328 [ # # ]: 0 : notify_partition( vtx_list, first_new_edge, second_new_edge, edge_ptr );
329 : :
330 : : // Adjust sense of new RefEdge
331 : : // The sense of the input edge should not have changed, so don't mess with
332 : : // it. Flip the new edge if it doesn't end with the correct vertex.
333 [ # # ][ # # ]: 0 : if (first_new_edge != edge_ptr && first_new_edge->start_vertex() != input_start_vtx)
[ # # ][ # # ]
334 : : {
335 [ # # ]: 0 : first_new_edge->reverse_tangent();
336 : : }
337 [ # # ][ # # ]: 0 : if (second_new_edge != edge_ptr && second_new_edge->end_vertex() != input_end_vtx)
[ # # ][ # # ]
338 : : {
339 [ # # ]: 0 : second_new_edge->reverse_tangent();
340 : : }
341 : :
342 [ # # ][ # # ]: 0 : PRINT_DEBUG_76("First new curve is %d, second new curve is %d.\n",
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
343 : : first_new_edge ? first_new_edge->id() : 0,
344 [ # # ]: 0 : second_new_edge ? second_new_edge->id() : 0 );
345 [ # # ]: 0 : return new_vertex;
346 : : }
347 : :
348 : 0 : RefVertex* PartitionTool::partition( RefEdge* edge_ptr,
349 : : const CubitVector& position,
350 : : DLIList<RefEdge*>& result_list,
351 : : CubitBoolean b )
352 : : {
353 : 0 : RefEdge *part1 = 0, *part2 = 0;
354 [ # # ]: 0 : RefVertex* result = partition( edge_ptr, position, part1, part2, b );
355 [ # # ][ # # ]: 0 : if( result && part1 )
356 [ # # ]: 0 : result_list.append(part1);
357 [ # # ][ # # ]: 0 : if( result && part2 )
358 [ # # ]: 0 : result_list.append(part2);
359 : 0 : return result;
360 : : }
361 : :
362 : : //-------------------------------------------------------------------------
363 : : // Purpose : Split a surface
364 : : //
365 : : // Special Notes :
366 : : //
367 : : // Creator : Jason Kraftcheck
368 : : //
369 : : // Creation Date : 09/20/99
370 : : //-------------------------------------------------------------------------
371 : 0 : CubitStatus PartitionTool::partition( RefFace* face_ptr,
372 : : RefEdge* edge_ptr,
373 : : RefFace*& new_face1,
374 : : RefFace*& new_face2,
375 : : CubitBoolean )
376 : : {
377 [ # # ][ # # ]: 0 : PRINT_DEBUG_86( "PT: PartitionTool::partition( RefFace %d, RefEdge %d )\n",
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
378 [ # # ]: 0 : face_ptr->id(), edge_ptr->id() );
379 : 0 : new_face1 = new_face2 = 0;
380 : :
381 [ # # ]: 0 : DLIList<CubitVector*> segments;
382 [ # # ][ # # ]: 0 : DLIList<RefEdge*> new_edges;
383 [ # # ][ # # ]: 0 : GMem edge_facets;
384 : :
385 [ # # ]: 0 : Curve* curve = edge_ptr->get_curve_ptr();
386 [ # # ][ # # ]: 0 : if( ! curve->get_geometry_query_engine()->get_graphics( curve, &edge_facets, facetingTolerance ) )
[ # # ]
387 : : {
388 : 0 : return CUBIT_FAILURE;
389 : : }
390 : :
391 : : int j;
392 : : //Use the exact end points to avoid precision problems with faceting.
393 [ # # ][ # # ]: 0 : CubitVector start_coord = edge_ptr->start_vertex()->coordinates();
394 [ # # ][ # # ]: 0 : CubitVector end_coord = edge_ptr->end_vertex()->coordinates();
395 [ # # ][ # # ]: 0 : segments.append( new CubitVector ( start_coord ) );
[ # # ]
396 [ # # ]: 0 : for( j = 1; j < (edge_facets.pointListCount-1); j++ )
397 : : {
398 [ # # ]: 0 : segments.append( new CubitVector( edge_facets.point_list()[j].x,
399 [ # # ]: 0 : edge_facets.point_list()[j].y,
400 [ # # ][ # # ]: 0 : edge_facets.point_list()[j].z ) );
[ # # ][ # # ]
401 : : }
402 [ # # ][ # # ]: 0 : segments.append( new CubitVector ( end_coord ) );
[ # # ]
403 : :
404 [ # # ]: 0 : new_face2 = insert_edge( face_ptr, segments, CUBIT_TRUE, new_edges );
405 : 0 : new_face1 = face_ptr;
406 : :
407 [ # # ][ # # ]: 0 : while( segments.size() )
408 [ # # ]: 0 : delete segments.pop();
409 : :
410 [ # # ][ # # ]: 0 : return new_face2 ? CUBIT_SUCCESS : CUBIT_FAILURE;
411 : : }
412 : :
413 : 0 : RefFace* PartitionTool::insert_edge( RefFace* face_ptr,
414 : : DLIList<CubitVector*>& segments,
415 : : CubitBoolean is_meshed,
416 : : DLIList<RefEdge*>& new_edges,
417 : : int level_of_recursion,
418 : : const double *tolerance_length)
419 : : {
420 : : int i,j,k;
421 : 0 : const double TOL_SQR = GEOMETRY_RESABS*GEOMETRY_RESABS;
422 [ # # ]: 0 : DLIList<Body*> bodies;
423 [ # # ]: 0 : face_ptr->bodies(bodies);
424 : 0 : CubitStatus status = CUBIT_SUCCESS;
425 : :
426 : : //Partition edges first
427 [ # # ]: 0 : if (CUBIT_FALSE == is_meshed)
428 : : {
429 [ # # ]: 0 : DLIList<RefEdge*> edge_list;
430 [ # # ]: 0 : face_ptr->ref_edges(edge_list);
431 [ # # ][ # # ]: 0 : CubitVector pos = *segments.get();
432 [ # # ]: 0 : CubitVector closest;
433 : 0 : RefEdge * the_edge = NULL;
434 [ # # ][ # # ]: 0 : DLIList <CubitVector *> vect_list;
435 [ # # ][ # # ]: 0 : DLIList<RefEdge*> temp_list;
436 : 0 : int count = 0;
437 [ # # ][ # # ]: 0 : for (i = 0 ; count < 2 && i < segments.size(); i++)
[ # # ][ # # ]
438 : : {
439 [ # # ][ # # ]: 0 : for (j = 0; j < edge_list.size(); j++)
440 : : {
441 [ # # ]: 0 : the_edge = edge_list.get_and_step();
442 [ # # ]: 0 : the_edge->closest_point_trimmed(pos, closest);
443 : :
444 [ # # ][ # # ]: 0 : if ( (pos - closest).length_squared() > TOL_SQR )
[ # # ]
445 : 0 : continue;
446 : :
447 : : //closest point need to be on the edge
448 : : /*
449 : : the_edge->get_graphics(polyline, 0.0);
450 : : int size = polyline.point_list_size();
451 : : GPoint* pts = polyline.point_list();
452 : : CubitVector pt1(pts[0]);
453 : : CubitVector pt2(pts[1]);
454 : : CubitBox edge_box (pt1, pt2);
455 : : if (size > 1)
456 : : {
457 : : for (k = 2; k < size; k ++)
458 : : {
459 : : CubitVector pt3(pts[k]);
460 : : CubitVector pt4(pts[k-1]);
461 : : CubitBox box2(pt4, pt3);
462 : : edge_box |= box2;
463 : : }
464 : : }
465 : :
466 : : CubitBox position_box(closest);
467 : : if (size == 1 || (size > 1 && !position_box.overlap(0, edge_box)))
468 : : continue;
469 : : */
470 [ # # ]: 0 : CubitBox position_box(closest);
471 [ # # ]: 0 : CubitBox edge_box = the_edge->bounding_box();
472 [ # # ][ # # ]: 0 : if (!position_box.overlap(GEOMETRY_RESABS, edge_box))
473 : : // if (!position_box.overlap(0, edge_box))
474 : 0 : continue;
475 : :
476 [ # # ][ # # ]: 0 : delete segments.change_to(new CubitVector (closest));
[ # # ]
477 [ # # ][ # # ]: 0 : if((the_edge->start_coordinates() - closest).length_squared() < TOL_SQR
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
478 [ # # ][ # # ]: 0 : ||(the_edge->end_coordinates() - closest).length_squared() < TOL_SQR)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
479 : 0 : break;
480 : :
481 [ # # ]: 0 : vect_list.clean_out();
482 [ # # ]: 0 : vect_list.append(&closest);
483 [ # # ]: 0 : temp_list.clean_out();
484 [ # # ]: 0 : status = partition(the_edge, vect_list, temp_list);
485 : :
486 : : // explicitly test for status here
487 [ # # ]: 0 : if (CUBIT_SUCCESS != status)
488 : : {
489 [ # # ][ # # ]: 0 : PRINT_ERROR("PartitionTool::insert_edge failed at partition...\n");
[ # # ][ # # ]
490 : : }
491 : :
492 : : // I've seen cases where the resulting partition position is not
493 : : // what we passed in so look at the resulting curves and get
494 : : // the end point that is closest to the point we used for
495 : : // partitioning the curve.
496 : 0 : double smallest_dist_sq = CUBIT_DBL_MAX;
497 : 0 : RefVertex *closest_vert = NULL;
498 [ # # ][ # # ]: 0 : for(k=temp_list.size(); k--;)
499 : : {
500 [ # # ]: 0 : RefEdge *current_edge = temp_list.get_and_step();
501 [ # # ]: 0 : RefVertex *start_vert = current_edge->start_vertex();
502 [ # # ]: 0 : RefVertex *end_vert = current_edge->end_vertex();
503 [ # # ][ # # ]: 0 : double len_sq = (start_vert->coordinates()-closest).length_squared();
[ # # ]
504 [ # # ]: 0 : if(len_sq < smallest_dist_sq)
505 : : {
506 : 0 : smallest_dist_sq = len_sq;
507 : 0 : closest_vert = start_vert;
508 : : }
509 [ # # ][ # # ]: 0 : len_sq = (end_vert->coordinates()-closest).length_squared();
[ # # ]
510 [ # # ]: 0 : if(len_sq < smallest_dist_sq)
511 : : {
512 : 0 : smallest_dist_sq = len_sq;
513 : 0 : closest_vert = end_vert;
514 : : }
515 : : }
516 : :
517 [ # # ]: 0 : if(closest_vert)
518 [ # # ][ # # ]: 0 : delete segments.change_to(new CubitVector(closest_vert->coordinates()));
[ # # ]
519 : :
520 [ # # ]: 0 : temp_list.remove(the_edge);
521 [ # # ][ # # ]: 0 : DLIList<RefEntity*> ref_list;
[ # # ][ # # ]
[ # # ][ # # ]
522 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT(temp_list, ref_list);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
523 [ # # ][ # # ]: 0 : notify_partition( ref_list, the_edge, temp_list.get(), the_edge );
524 : :
525 : : //need to debug later if this happens.
526 [ # # ]: 0 : if (CUBIT_SUCCESS != status)
527 : : {
528 [ # # ][ # # ]: 0 : PRINT_ERROR("PartitionTool::insert_edge failed at assert...\n");
[ # # ][ # # ]
529 : : }
530 [ # # ]: 0 : assert (CUBIT_SUCCESS == status);
531 [ # # ]: 0 : edge_list.remove(the_edge);
532 : 0 : count ++;
533 : 0 : break;
534 : 0 : }
535 [ # # ][ # # ]: 0 : pos = *segments.step_and_get();
536 [ # # ]: 0 : }
537 : : }
538 : :
539 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() )
540 : : {
541 [ # # ]: 0 : DLIList<RefFace*> tmp_face_list(1);
542 [ # # ]: 0 : tmp_face_list.append( face_ptr );
543 [ # # ][ # # ]: 0 : CubitUndo::save_state_with_cubit_file( tmp_face_list );
544 : : }
545 : :
546 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_list;
547 [ # # ][ # # ]: 0 : face_ptr->bridge_manager()->get_bridge_list( bridge_list );
548 [ # # ]: 0 : bridge_list.reset();
549 [ # # ]: 0 : bridge_list.step();
550 [ # # ][ # # ]: 0 : for( i = bridge_list.size(); i > 1; i-- )
551 [ # # ][ # # ]: 0 : face_ptr->bridge_manager()->remove_bridge( bridge_list.get_and_step() );
[ # # ]
552 : :
553 [ # # ]: 0 : bridge_list.reset();
554 [ # # ][ # # ]: 0 : DLIList<Surface*> result_surfaces;
555 [ # # ][ # # ]: 0 : DLIList<Curve*> curves(2), new_curves;;
[ # # ][ # # ]
556 [ # # ][ # # ]: 0 : DLIList<Surface*> curve_surfs(2);
557 : 0 : int removed_composite_curve = 0;
558 [ # # ][ # # ]: 0 : for( i = bridge_list.size(); i>0; i--)
559 : : {
560 [ # # ][ # # ]: 0 : Surface* old_surf = dynamic_cast<Surface*>(bridge_list.get_and_step());
561 : :
562 [ # # ]: 0 : Surface* new_surf = PartitionEngine::instance().
563 [ # # ]: 0 : insert_curve( old_surf, segments, curves, tolerance_length );
564 : :
565 : : // do it twice in case the segments changed during the first insert_curve
566 : : // because the segments intersect with the old_surf boundary. This is to
567 : : // ensure that new vertices are generated at those intersecting points.
568 [ # # ][ # # ]: 0 : if (!new_surf && level_of_recursion == 0)
569 : : {
570 : 0 : level_of_recursion++;
571 [ # # ]: 0 : RefFace *return_face = insert_edge( face_ptr, segments, CUBIT_FALSE, new_edges, level_of_recursion);
572 : :
573 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() && return_face == NULL )
[ # # ][ # # ]
574 [ # # ]: 0 : CubitUndo::remove_last_undo();
575 : :
576 : 0 : return return_face;
577 : : }
578 : :
579 [ # # ]: 0 : if(!new_surf)
580 : : {
581 [ # # ]: 0 : CompositeSurface* cs = dynamic_cast<CompositeSurface*>(old_surf);
582 [ # # ]: 0 : if(cs)
583 : : {
584 [ # # ]: 0 : Surface *tmp_srf = cs->get_surface(0);
585 [ # # ]: 0 : GeometryQueryEngine *gqe = tmp_srf->get_geometry_query_engine();
586 [ # # ]: 0 : double tmp_tol = gqe->get_sme_resabs_tolerance();
587 [ # # ]: 0 : DLIList<Curve*> hidden_curves;
588 [ # # ]: 0 : cs->get_hidden_curves(hidden_curves);
589 : : int k;
590 [ # # ][ # # ]: 0 : for(k=hidden_curves.size(); k--;)
591 : : {
592 [ # # ]: 0 : Curve *cur_curve = hidden_curves.get_and_step();
593 [ # # ][ # # ]: 0 : CubitVector start_vec, end_vec;
594 : : double min, max;
595 [ # # ]: 0 : IntersectionTool int_tool;
596 : 0 : int curve_on_polyline = 1;
597 [ # # ]: 0 : cur_curve->get_param_range(min, max);
598 [ # # ]: 0 : cur_curve->position_from_u(min, start_vec);
599 [ # # ][ # # ]: 0 : if(!int_tool.point_on_polyline(start_vec, segments, &tmp_tol))
600 : 0 : curve_on_polyline = 0;
601 [ # # ]: 0 : if(curve_on_polyline)
602 : : {
603 [ # # ]: 0 : cur_curve->position_from_u(max, end_vec);
604 [ # # ][ # # ]: 0 : if(!int_tool.point_on_polyline(end_vec, segments, &tmp_tol))
605 : 0 : curve_on_polyline = 0;
606 : : }
607 [ # # ]: 0 : if(curve_on_polyline)
608 : : {
609 : 0 : int num_mid_pts = 2;
610 : 0 : double dt = ((double)(max-min))/((double)(num_mid_pts+1));
611 : 0 : double cur_t = min + dt;
612 : : int n;
613 [ # # ]: 0 : CubitVector cur_vec;
614 [ # # ][ # # ]: 0 : for(n=0; n<num_mid_pts && curve_on_polyline; ++n)
615 : : {
616 [ # # ]: 0 : cur_curve->position_from_u(cur_t, cur_vec);
617 [ # # ][ # # ]: 0 : if(!int_tool.point_on_polyline(cur_vec, segments, &tmp_tol))
618 : 0 : curve_on_polyline = 0;
619 : 0 : cur_t += dt;
620 : : }
621 : : }
622 [ # # ]: 0 : if(curve_on_polyline)
623 : : {
624 [ # # ]: 0 : DLIList<Curve*> cur_curve_crvs;
625 [ # # ]: 0 : CompositeCurve *ccurve = dynamic_cast<CompositeCurve*>(cur_curve);
626 [ # # ]: 0 : if(ccurve)
627 : : {
628 [ # # ]: 0 : int f, num_crvs = ccurve->num_curves();
629 [ # # ]: 0 : for(f=0; f<num_crvs; ++f)
630 [ # # ][ # # ]: 0 : cur_curve_crvs.append(ccurve->get_curve(f));
631 : : }
632 : : else
633 : : {
634 [ # # ]: 0 : cur_curve_crvs.append(cur_curve);
635 : : }
636 [ # # ][ # # ]: 0 : CompositeEngine::instance().restore_curve(cur_curve);
637 [ # # ][ # # ]: 0 : ccurve = dynamic_cast<CompositeCurve*>(cur_curve_crvs.get()->owner());
[ # # ]
638 [ # # ]: 0 : if(ccurve)
639 : : {
640 [ # # ]: 0 : cur_curve_crvs.clean_out();
641 [ # # ]: 0 : cur_curve_crvs.append(ccurve);
642 : : }
643 : 0 : removed_composite_curve = 1;
644 : : int y, z;
645 [ # # ][ # # ]: 0 : for(z=cur_curve_crvs.size(); z--;)
646 : : {
647 [ # # ]: 0 : cur_curve = cur_curve_crvs.get_and_step();
648 [ # # ]: 0 : DLIList<TopologyBridge*> pts;
649 [ # # ]: 0 : cur_curve->get_children_virt(pts);
650 [ # # ][ # # ]: 0 : for(y=pts.size(); y--;)
651 : : {
652 [ # # ]: 0 : DLIList<TopologyBridge*> crvs;
653 [ # # ][ # # ]: 0 : pts.get()->get_parents_virt(crvs);
654 [ # # ][ # # ]: 0 : if(crvs.size() == 2)
655 : : {
656 : : TopologyBridge *other_curve;
657 [ # # ][ # # ]: 0 : if(crvs.get() == cur_curve)
658 [ # # ]: 0 : other_curve = crvs.step_and_get();
659 : : else
660 [ # # ]: 0 : other_curve = crvs.get();
661 : : int p;
662 [ # # ][ # # ]: 0 : for(p=curves.size(); p--;)
663 : : {
664 [ # # ][ # # ]: 0 : if(curves.get() == other_curve)
665 : : {
666 [ # # ][ # # ]: 0 : CompositeEngine::instance().remove_point(dynamic_cast<TBPoint*>(pts.get()));
[ # # ][ # # ]
667 [ # # ][ # # ]: 0 : curves.remove(curves.get());
668 : 0 : p = 0;
669 : : }
670 : : else
671 [ # # ]: 0 : curves.step();
672 : : }
673 : : }
674 [ # # ]: 0 : pts.step();
675 [ # # ]: 0 : }
676 [ # # ][ # # ]: 0 : }
677 : : }
678 [ # # ][ # # ]: 0 : }
679 : : }
680 : : }
681 [ # # ][ # # ]: 0 : if ( !curves.size() && !removed_composite_curve )
[ # # ][ # # ]
682 : : {
683 : 0 : status = CUBIT_FAILURE;
684 : 0 : break;
685 : : }
686 [ # # ][ # # ]: 0 : for ( int j = curves.size(); j--; )
687 : : {
688 [ # # ]: 0 : curve_surfs.clean_out();
689 [ # # ][ # # ]: 0 : curves.step_and_get()->surfaces(curve_surfs);
690 [ # # ]: 0 : result_surfaces.merge_unique(curve_surfs);
691 : : }
692 [ # # ]: 0 : new_curves += curves;
693 [ # # ]: 0 : curves.clean_out();
694 : :
695 : : }
696 : :
697 [ # # ][ # # ]: 0 : for( i = bodies.size(); i--; )
698 : : {
699 [ # # ]: 0 : Body* body = bodies.get_and_step();
700 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->make_Body(body->get_body_sm_ptr());
[ # # ]
701 : : }
702 : :
703 [ # # ][ # # ]: 0 : DLIList<RefFace*> result_faces;
704 [ # # ][ # # ]: 0 : for( i = result_surfaces.size(); i--; )
705 : : result_faces.append(
706 : : GeometryQueryTool::instance()->make_RefFace(
707 [ # # ][ # # ]: 0 : result_surfaces.get_and_step() ) );
[ # # ][ # # ]
708 : :
709 [ # # ][ # # ]: 0 : MergeTool::instance()->merge_reffaces( result_faces );
710 [ # # ]: 0 : result_faces.clean_out();
711 [ # # ][ # # ]: 0 : for( i = result_surfaces.size(); i--; )
712 [ # # ][ # # ]: 0 : result_faces.append_unique( dynamic_cast<RefFace*>(result_surfaces.get_and_step()->topology_entity()) );
[ # # ][ # # ]
713 : :
714 [ # # ]: 0 : result_faces.move_to( face_ptr );
715 [ # # ][ # # ]: 0 : RefFace* result = result_faces.size() ? result_faces.next() : 0;
[ # # ]
716 [ # # ][ # # ]: 0 : if(!result && removed_composite_curve)
717 : 0 : result = face_ptr;
718 [ # # ][ # # ]: 0 : for( i = new_curves.size(); i--; )
719 : : {
720 [ # # ]: 0 : Curve* curve = new_curves.get_and_step();
721 [ # # ][ # # ]: 0 : RefEdge* new_edge = dynamic_cast<RefEdge*>(curve->topology_entity());
722 [ # # ]: 0 : new_edges.append_unique(new_edge);
723 : : }
724 : :
725 [ # # ][ # # ]: 0 : if ( !removed_composite_curve && !new_edges.size() )
[ # # ][ # # ]
726 : : {
727 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() )
728 [ # # ]: 0 : CubitUndo::remove_last_undo();
729 : :
730 : 0 : return 0;
731 : : }
732 : :
733 [ # # ][ # # ]: 0 : DLIList<RefEntity*> ref_list;
734 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT(new_edges, ref_list);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
735 [ # # ]: 0 : notify_partition( ref_list, face_ptr, result, face_ptr );
736 : :
737 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() && status == CUBIT_FAILURE )
[ # # ][ # # ]
738 [ # # ]: 0 : CubitUndo::remove_last_undo();
739 : :
740 [ # # ][ # # ]: 0 : return status ? result : 0;
741 : : }
742 : :
743 : 0 : DLIList<Surface*>* PartitionTool::group_merged_surfaces(
744 : : DLIList<RefFace*>& face_list,
745 : : int& num_result_sets )
746 : : {
747 : : // make sure all surfaces are merged the same number of times
748 : : int i;
749 : 0 : num_result_sets = 0;
750 [ # # ][ # # ]: 0 : int bridge_count = face_list.get()->bridge_manager()->number_of_bridges();
[ # # ]
751 [ # # ][ # # ]: 0 : for ( i = face_list.size(); i--; )
752 [ # # ][ # # ]: 0 : if( face_list.step_and_get()->bridge_manager()->number_of_bridges() != bridge_count )
[ # # ][ # # ]
753 : 0 : return 0;
754 : :
755 : : // get the bridge list (merged Surface*) for the first RefFace
756 [ # # ][ # # ]: 0 : DLIList<Surface*>* results = new DLIList<Surface*>[bridge_count];
[ # # ]
[ # # # # ]
757 [ # # ]: 0 : DLIList<Lump*> surf_owners(bridge_count);
758 [ # # ]: 0 : face_list.reset();
759 [ # # ]: 0 : RefFace* face = face_list.get_and_step();
760 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_list(bridge_count);
761 [ # # ][ # # ]: 0 : face->bridge_manager()->get_bridge_list(bridge_list);
762 : :
763 : : // get the list of lumps involved in the merge from the first RefFace
764 [ # # ]: 0 : bridge_list.reset();
765 [ # # ][ # # ]: 0 : DLIList<Lump*> lump_list;
766 [ # # ][ # # ]: 0 : for ( i = 0; i < bridge_list.size(); i++ )
767 : : {
768 [ # # ][ # # ]: 0 : Surface* surface = dynamic_cast<Surface*>(bridge_list.get_and_step());
769 [ # # ]: 0 : assert(!!surface);
770 [ # # ]: 0 : lump_list.clean_out();
771 [ # # ]: 0 : surface->lumps(lump_list);
772 : 0 : Lump* lump = 0;
773 [ # # ][ # # ]: 0 : if ( lump_list.size() > 1 )
774 : : {
775 [ # # ][ # # ]: 0 : delete [] results;
[ # # ]
776 : 0 : return 0;
777 : : }
778 [ # # ][ # # ]: 0 : else if (lump_list.size())
779 [ # # ]: 0 : lump = lump_list.get();
780 : :
781 [ # # ][ # # ]: 0 : if( surf_owners.is_in_list( lump ) )
782 : : {
783 [ # # ][ # # ]: 0 : delete [] results;
[ # # ]
784 : 0 : return 0;
785 : : }
786 : :
787 [ # # ]: 0 : surf_owners.append(lump);
788 [ # # ]: 0 : results[i].append(surface);
789 : : }
790 : :
791 : : // add the rest of the Surfaces into separate lists according to
792 : : // the Lump they belong to
793 [ # # ][ # # ]: 0 : for ( i = 1; i < face_list.size(); i++ )
794 : : {
795 [ # # ]: 0 : face = face_list.get_and_step();
796 : :
797 [ # # ]: 0 : bridge_list.clean_out();
798 [ # # ][ # # ]: 0 : face->bridge_manager()->get_bridge_list(bridge_list);
799 [ # # ]: 0 : bridge_list.reset();
800 : :
801 [ # # ][ # # ]: 0 : for ( int j = bridge_list.size(); j--; )
802 : : {
803 [ # # ][ # # ]: 0 : Surface* surface = dynamic_cast<Surface*>(bridge_list.get_and_step());
804 [ # # ]: 0 : assert(!!surface);
805 [ # # ]: 0 : lump_list.clean_out();
806 [ # # ]: 0 : surface->lumps(lump_list);
807 : 0 : Lump* lump = 0;
808 [ # # ][ # # ]: 0 : if ( lump_list.size() > 1 )
809 : : {
810 [ # # ][ # # ]: 0 : delete [] results;
[ # # ]
811 : 0 : return 0;
812 : : }
813 [ # # ][ # # ]: 0 : else if (lump_list.size())
814 [ # # ]: 0 : lump = lump_list.get();
815 : :
816 [ # # ][ # # ]: 0 : if ( !surf_owners.move_to(lump) ||
[ # # ][ # # ]
817 [ # # ][ # # ]: 0 : results[surf_owners.get_index()].size() != i )
818 : : {
819 [ # # ][ # # ]: 0 : delete [] results;
[ # # ]
820 : 0 : return 0;
821 : : }
822 : :
823 [ # # ][ # # ]: 0 : results[surf_owners.get_index()].append(surface);
824 : : }
825 : : }
826 : :
827 : : // return the number of sets - one set for each Lump that was
828 : : // involved in the merge
829 : 0 : num_result_sets = bridge_count;
830 [ # # ][ # # ]: 0 : return results;
831 : : }
832 : :
833 : :
834 : 0 : CubitStatus PartitionTool::insert_edge(
835 : : DLIList<RefFace*>& input_faces,
836 : : DLIList<CubitVector*>& segments,
837 : : DLIList<RefFace*>& output_faces,
838 : : DLIList<RefEdge*>& new_edges,
839 : : CubitBoolean do_split_curves)
840 : : {
841 : : int i, j, w, set_count;
842 : 0 : const double TOL_SQR = GEOMETRY_RESABS*GEOMETRY_RESABS;
843 : :
844 : : // group surfaces by Lump
845 [ # # ]: 0 : DLIList<Surface*> *surface_sets = group_merged_surfaces( input_faces, set_count );
846 [ # # ]: 0 : if( !surface_sets )
847 : : {
848 [ # # ][ # # ]: 0 : PRINT_ERROR("Failed to group merged Surfaces in PartitionTool::insert_edge()\n");
[ # # ][ # # ]
849 : 0 : return CUBIT_FAILURE;
850 : : }
851 : :
852 [ # # ]: 0 : input_faces.reset();
853 [ # # ]: 0 : if(do_split_curves)
854 : : {
855 [ # # ][ # # ]: 0 : for ( w = input_faces.size(); w--; )
856 : : {
857 [ # # ]: 0 : RefFace* face_ptr = input_faces.get_and_step();
858 [ # # ]: 0 : DLIList<RefEdge*> edge_list;
859 [ # # ]: 0 : face_ptr->ref_edges(edge_list);
860 [ # # ][ # # ]: 0 : CubitVector pos = *segments.get();
861 [ # # ]: 0 : CubitVector closest;
862 : 0 : RefEdge * the_edge = NULL;
863 [ # # ][ # # ]: 0 : DLIList <CubitVector *> vect_list;
[ # # ]
864 [ # # ][ # # ]: 0 : DLIList<RefEdge*> temp_list;
[ # # ]
865 : 0 : int count = 0;
866 [ # # ][ # # ]: 0 : for (i = 0 ; count < 2 && i < segments.size(); i++)
[ # # ][ # # ]
[ # # ][ # # ]
867 : : {
868 [ # # ][ # # ]: 0 : for (j = 0; j < edge_list.size(); j++)
869 : : {
870 [ # # ]: 0 : the_edge = edge_list.get_and_step();
871 [ # # ]: 0 : the_edge->closest_point_trimmed(pos, closest );
872 : :
873 [ # # ][ # # ]: 0 : if ( (pos - closest).length_squared() > TOL_SQR )
[ # # ]
874 : 0 : continue;
875 : :
876 : : //closest point need to be on the edge
877 : : /*
878 : : the_edge->get_graphics(polyline, 0.0);
879 : : int size = polyline.point_list_size();
880 : : GPoint* pts = polyline.point_list();
881 : : CubitVector pt1(pts[0]);
882 : : CubitVector pt2(pts[1]);
883 : : CubitBox edge_box (pt1, pt2);
884 : : if (size > 1)
885 : : {
886 : : for (k = 2; k < size; k ++)
887 : : {
888 : : CubitVector pt3(pts[k]);
889 : : CubitVector pt4(pts[k-1]);
890 : : CubitBox box2(pt4, pt3);
891 : : edge_box |= box2;
892 : : }
893 : : }
894 : :
895 : : CubitBox position_box(closest);
896 : : if (size == 1 || (size > 1 && !position_box.overlap(0, edge_box)))
897 : : continue;
898 : : */
899 [ # # ]: 0 : CubitBox position_box(closest);
900 [ # # ]: 0 : CubitBox edge_box = the_edge->bounding_box();
901 [ # # ][ # # ]: 0 : if (!position_box.overlap(0, edge_box))
902 : 0 : continue;
903 : :
904 [ # # ][ # # ]: 0 : delete segments.change_to(new CubitVector (closest));
[ # # ]
905 [ # # ][ # # ]: 0 : if((the_edge->start_coordinates() - closest).length_squared() < TOL_SQR
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
906 [ # # ][ # # ]: 0 : ||(the_edge->end_coordinates() - closest).length_squared() < TOL_SQR)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
907 : 0 : break;
908 : :
909 [ # # ]: 0 : vect_list.clean_out();
910 [ # # ]: 0 : vect_list.append(&closest);
911 [ # # ]: 0 : CubitStatus status = partition(the_edge, vect_list, temp_list);
912 : : //need to debug later if this happens.
913 : : //assert (CUBIT_SUCCESS == status);
914 [ # # ]: 0 : if( CUBIT_FAILURE == status )
915 : 0 : return status;
916 [ # # ]: 0 : edge_list.remove(the_edge);
917 : 0 : count ++;
918 [ # # ]: 0 : break;
[ # # # ]
[ # # ]
[ # # # ]
919 : 0 : }
920 [ # # ][ # # ]: 0 : pos = *segments.step_and_get();
921 : : }
922 : 0 : }
923 : : }
924 : :
925 [ # # ]: 0 : input_faces.reset();
926 : :
927 : : // unmerge all the surfaces by removing all but the first Lump's
928 : : // surfaces from the bridge manager
929 [ # # ]: 0 : DLIList<TopologyBridge*> bridge_list;
930 [ # # ][ # # ]: 0 : DLIList<Surface*> surf_list;
931 [ # # ][ # # ]: 0 : for ( i = input_faces.size(); i--; )
932 : : {
933 [ # # ]: 0 : RefFace* face_ptr = input_faces.get_and_step();
934 [ # # ]: 0 : bridge_list.clean_out();
935 [ # # ][ # # ]: 0 : face_ptr->bridge_manager()->get_bridge_list( bridge_list );
936 [ # # ][ # # ]: 0 : CAST_LIST( bridge_list, surf_list, Surface );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
937 [ # # ]: 0 : surf_list -= surface_sets[0];
938 [ # # ][ # # ]: 0 : for ( int j = surf_list.size(); j--; )
939 [ # # ][ # # ]: 0 : face_ptr->bridge_manager()->remove_bridge( surf_list.get_and_step() );
[ # # ]
940 : : }
941 : :
942 : : // perform the partition operation - insert curve - on each Lump's set of surfaces
943 [ # # ][ # # ]: 0 : DLIList<Surface*> new_surfs, all_new_surfs;
[ # # ][ # # ]
944 [ # # ][ # # ]: 0 : DLIList<Curve*> new_curves, all_new_curves;
[ # # ][ # # ]
945 : 0 : CubitStatus result = CUBIT_SUCCESS;
946 [ # # ]: 0 : for ( i = 0; i < set_count; i++ )
947 : : {
948 [ # # ]: 0 : new_surfs.clean_out();
949 [ # # ]: 0 : new_curves.clean_out();
950 [ # # ][ # # ]: 0 : if ( !PartitionEngine::instance().
951 [ # # ]: 0 : insert_curve( surface_sets[i], segments, new_surfs, new_curves ) )
952 : 0 : result = CUBIT_FAILURE;
953 [ # # ]: 0 : all_new_surfs += new_surfs;
954 [ # # ]: 0 : all_new_curves += new_curves;
955 : : }
956 [ # # ][ # # ]: 0 : delete [] surface_sets;
[ # # ]
957 : :
958 : : // Do not create a new body in the failure case
959 [ # # ]: 0 : if (CUBIT_FAILURE == result)
960 : 0 : return result;
961 : :
962 : : // get the list of all bodies involved in the partition operation
963 [ # # ][ # # ]: 0 : DLIList<Body*> bodies, all_bodies;
[ # # ][ # # ]
964 [ # # ][ # # ]: 0 : for ( i = input_faces.size(); i--; )
965 : : {
966 [ # # ]: 0 : bodies.clean_out();
967 [ # # ][ # # ]: 0 : input_faces.step_and_get()->bodies( bodies );
968 [ # # ]: 0 : all_bodies.merge_unique(bodies);
969 : : }
970 : :
971 [ # # ][ # # ]: 0 : for( i = all_bodies.size(); i--; )
972 : : {
973 [ # # ]: 0 : Body* body = all_bodies.get_and_step();
974 [ # # ][ # # ]: 0 : BodySM* bodysm = dynamic_cast<BodySM*>(body->bridge_manager()->topology_bridge());
[ # # ]
975 [ # # ]: 0 : if( bodysm )
976 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->make_Body( bodysm );
977 : : }
978 : :
979 : : // re-merge if surfaces were merged before the partition operation
980 [ # # ]: 0 : if( set_count > 1 )
981 : : {
982 [ # # ]: 0 : DLIList<RefFace*> result_faces;
983 [ # # ][ # # ]: 0 : for( i = all_new_surfs.size(); i--; )
984 : : result_faces.append(
985 : : GeometryQueryTool::instance()->make_RefFace(
986 [ # # ][ # # ]: 0 : all_new_surfs.get_and_step() ) );
[ # # ][ # # ]
987 [ # # ][ # # ]: 0 : MergeTool::instance()->merge_reffaces( result_faces );
[ # # ]
988 : : }
989 : :
990 [ # # ]: 0 : output_faces.clean_out();
991 : :
992 : : //make sure you are dealing with top-level TopologyBridges here,
993 : : //ones that have a BridgeManager as the TBOwner.
994 [ # # ][ # # ]: 0 : for( i = all_new_surfs.size(); i--; )
995 : : {
996 [ # # ]: 0 : Surface *new_surface = all_new_surfs.get_and_step();
997 [ # # ][ # # ]: 0 : RefFace *new_face = dynamic_cast<RefFace*>(new_surface->topology_entity());
998 [ # # ]: 0 : if( new_face )
999 [ # # ]: 0 : output_faces.append_unique( new_face );
1000 : : else
1001 : : {
1002 [ # # ]: 0 : DLIList<TopologyBridge*> bridges;
1003 [ # # ][ # # ]: 0 : PartitionEngine::instance().get_tbs_with_bridge_manager_as_owner(new_surface, bridges );
1004 : :
1005 [ # # ][ # # ]: 0 : if( bridges.size() == 0 )
1006 [ # # ][ # # ]: 0 : CompositeEngine::instance().get_tbs_with_bridge_manager_as_owner( new_surface, bridges );
1007 : :
1008 : 0 : Surface *tmp_surf = NULL;
1009 [ # # ][ # # ]: 0 : if( bridges.get() )
1010 [ # # ]: 0 : tmp_surf = static_cast<Surface*>(bridges.get());
1011 : :
1012 [ # # ]: 0 : if( tmp_surf )
1013 : : {
1014 [ # # ][ # # ]: 0 : new_face = dynamic_cast<RefFace*>(tmp_surf->topology_entity());
1015 [ # # ]: 0 : output_faces.append_unique( new_face );
1016 [ # # ]: 0 : }
1017 : : }
1018 : : }
1019 : :
1020 [ # # ]: 0 : output_faces.merge_unique(input_faces);
1021 : :
1022 [ # # ][ # # ]: 0 : for( i = all_new_curves.size(); i--; )
1023 : : {
1024 [ # # ]: 0 : Curve* curve = all_new_curves.get_and_step();
1025 [ # # ][ # # ]: 0 : new_edges.append( dynamic_cast<RefEdge*>(curve->topology_entity()) );
[ # # ]
1026 : : }
1027 [ # # ]: 0 : return result;
1028 : : }
1029 : :
1030 : : //-------------------------------------------------------------------------
1031 : : // Purpose : Create point curves on RefFace
1032 : : //
1033 : : // Special Notes :
1034 : : //
1035 : : // Creator :
1036 : : //
1037 : : // Creation Date :
1038 : : //-------------------------------------------------------------------------
1039 : 0 : CubitStatus PartitionTool::make_point_curves( RefFace* face_ptr,
1040 : : DLIList<CubitVector> &positions,
1041 : : DLIList<RefVertex*> &new_vertices)
1042 : : {
1043 : : int i, j;
1044 [ # # ]: 0 : DLIList<TopologyBridge*> bridge_list;
1045 [ # # ][ # # ]: 0 : DLIList<Surface*> surface_list;
1046 [ # # ][ # # ]: 0 : DLIList<TBPoint*> new_points;
1047 : 0 : CubitStatus rval = CUBIT_SUCCESS;
1048 : :
1049 : : // Get list of surfaces from RefFace
1050 [ # # ][ # # ]: 0 : face_ptr->bridge_manager()->get_bridge_list( bridge_list );
1051 [ # # ][ # # ]: 0 : CAST_LIST(bridge_list, surface_list, Surface);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1052 [ # # ][ # # ]: 0 : assert(bridge_list.size() == surface_list.size());
[ # # ]
1053 [ # # ]: 0 : surface_list.reset();
1054 : :
1055 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() )
1056 : : {
1057 [ # # ]: 0 : DLIList<RefFace*> tmp_faces(1);
1058 [ # # ]: 0 : tmp_faces.append( face_ptr );
1059 [ # # ][ # # ]: 0 : CubitUndo::save_state_with_cubit_file( tmp_faces );
1060 : : }
1061 : :
1062 : : // For each position in the list
1063 [ # # ]: 0 : positions.reset();
1064 [ # # ][ # # ]: 0 : for (i = positions.size(); i--; )
1065 : : {
1066 [ # # ][ # # ]: 0 : CubitVector pos = positions.get_and_step();
1067 : 0 : RefVertex* result_vtx = 0;
1068 : 0 : RefEdge* point_curve = 0;
1069 : 0 : CubitSense bridge_sense = CUBIT_UNKNOWN;
1070 : :
1071 : : // Create point-curve on each surface
1072 [ # # ]: 0 : surface_list.last();
1073 [ # # ][ # # ]: 0 : for (j = surface_list.size(); j--; )
1074 : : {
1075 [ # # ]: 0 : Surface *new_surf, *old_surf = surface_list.step_and_get();
1076 [ # # ]: 0 : TBPoint* new_pt = PartitionEngine::instance().
1077 [ # # ]: 0 : insert_point_curve( old_surf, pos, new_surf );
1078 : :
1079 [ # # ]: 0 : if (!new_pt)
1080 : : {
1081 [ # # ][ # # ]: 0 : PRINT_ERROR("Error imprint surface at position (%f,%f,%f)\n",
[ # # ][ # # ]
[ # # ][ # # ]
1082 [ # # ]: 0 : pos.x(), pos.y(), pos.z());
1083 : 0 : rval = CUBIT_FAILURE;
1084 : 0 : continue;
1085 : : }
1086 : :
1087 : : // If surface was replaced with a virtual surface, update
1088 : : // the list
1089 [ # # ]: 0 : new_points.append(new_pt);
1090 [ # # ]: 0 : surface_list.change_to(new_surf);
1091 : :
1092 : : // Merge each result point into a single RefVertex
1093 [ # # ]: 0 : if (!result_vtx)
1094 [ # # ][ # # ]: 0 : result_vtx = GeometryQueryTool::instance()->make_RefVertex(new_pt);
1095 [ # # ][ # # ]: 0 : else if (!new_pt->owner())
1096 [ # # ][ # # ]: 0 : result_vtx->bridge_manager()->add_bridge(new_pt);
1097 : :
1098 : : // Merge each result point-curve into a single RefEdge.
1099 : : // If the result was not a point-curve (input position was
1100 : : // on some existing point or curve), just let the merge
1101 : : // code clean up, merging/unmerging depending on tolerance.
1102 [ # # ]: 0 : bridge_list.clean_out();
1103 [ # # ]: 0 : new_pt->get_parents(bridge_list);
1104 [ # # ][ # # ]: 0 : if (bridge_list.size() != 1)
1105 : 0 : continue;
1106 [ # # ][ # # ]: 0 : Curve* curve = dynamic_cast<Curve*>(bridge_list.get());
1107 [ # # ][ # # ]: 0 : if (curve->geometry_type() != POINT_CURVE_TYPE)
1108 : 0 : continue;
1109 [ # # ]: 0 : if (!point_curve)
1110 : : {
1111 [ # # ]: 0 : bridge_sense = new_surf->bridge_sense();
1112 [ # # ][ # # ]: 0 : if (curve->bridge_sense() != bridge_sense)
1113 [ # # ]: 0 : curve->reverse_bridge_sense();
1114 [ # # ]: 0 : RefEdge::suppress_edge_length_warning(true);
1115 [ # # ][ # # ]: 0 : point_curve = GeometryQueryTool::instance()->make_RefEdge(curve);
1116 [ # # ]: 0 : RefEdge::suppress_edge_length_warning(false);
1117 : : }
1118 [ # # ][ # # ]: 0 : else if(!curve->owner())
1119 : : {
1120 [ # # ][ # # ]: 0 : point_curve->bridge_manager()->add_bridge(curve);
1121 [ # # ]: 0 : CubitSense merge_sense = new_surf->bridge_sense() == bridge_sense ?
1122 : 0 : CUBIT_FORWARD : CUBIT_REVERSED ;
1123 [ # # ][ # # ]: 0 : if (curve->bridge_sense() != merge_sense)
1124 [ # # ]: 0 : curve->reverse_bridge_sense();
1125 : : }
1126 : : }
1127 : : }
1128 : :
1129 : : // Update DAG topoloy for TB changes
1130 [ # # ][ # # ]: 0 : DLIList<RefFace*> result_faces;
1131 [ # # ]: 0 : surface_list.reset();
1132 [ # # ][ # # ]: 0 : for (i = surface_list.size(); i--; )
1133 : : {
1134 : : RefFace* face = GeometryQueryTool::instance()
1135 [ # # ][ # # ]: 0 : ->make_RefFace(surface_list.get_and_step());
[ # # ]
1136 [ # # ]: 0 : result_faces.append_unique(face);
1137 : : }
1138 : :
1139 : : // Attempt to re-merge anything that was unmerged
1140 : : // during DAG update
1141 [ # # ][ # # ]: 0 : if( result_faces.size() > 1 )
1142 : : {
1143 [ # # ][ # # ]: 0 : MergeTool::instance()->merge_reffaces( result_faces );
1144 : : }
1145 : :
1146 : : // Get list of RefVertices that were actually created after
1147 : : // all the merging, unmerging, re-merging, etc.
1148 [ # # ]: 0 : new_points.reset();
1149 [ # # ][ # # ]: 0 : for (i = new_points.size(); i--; )
1150 : : new_vertices.append(
1151 [ # # ][ # # ]: 0 : dynamic_cast<RefVertex*>(new_points.get_and_step()->topology_entity()));
[ # # ][ # # ]
1152 : :
1153 [ # # ][ # # ]: 0 : if (new_vertices.size() > 1)
1154 [ # # ]: 0 : new_vertices.uniquify_ordered();
1155 : :
1156 : :
1157 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() && new_points.size() == 0 )
[ # # ][ # # ]
[ # # ]
1158 [ # # ]: 0 : CubitUndo::remove_last_undo();
1159 : :
1160 [ # # ]: 0 : return rval;
1161 : : }
1162 : :
1163 : :
1164 : : //-------------------------------------------------------------------------
1165 : : // Purpose : Imprint a point on a surface
1166 : : //
1167 : : // Special Notes :
1168 : : //
1169 : : // Creator : Jason Kraftcheck
1170 : : //
1171 : : // Creation Date : 02/28/03
1172 : : //-------------------------------------------------------------------------
1173 : 0 : RefVertex* PartitionTool::make_point_curve( RefFace* face_ptr,
1174 : : const CubitVector& position )
1175 : : {
1176 [ # # ]: 0 : DLIList<CubitVector> positions(1);
1177 [ # # ][ # # ]: 0 : DLIList<RefVertex*> results(1);
1178 [ # # ]: 0 : positions.append(position);
1179 : :
1180 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() )
1181 [ # # ]: 0 : CubitUndo::save_state_with_cubit_file( face_ptr );
1182 : :
1183 [ # # ][ # # ]: 0 : if (make_point_curves(face_ptr, positions, results) && results.size())
[ # # ][ # # ]
[ # # ]
1184 [ # # ]: 0 : return results.get();
1185 : : else
1186 : : {
1187 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() )
1188 [ # # ]: 0 : CubitUndo::remove_last_undo();
1189 : 0 : return 0;
1190 [ # # ]: 0 : }
1191 : : }
1192 : :
1193 : :
1194 : : //-------------------------------------------------------------------------
1195 : : // Purpose : Partition an Edge
1196 : : //
1197 : : // Special Notes :
1198 : : //
1199 : : // Creator : Jason Kraftcheck
1200 : : //
1201 : : // Creation Date : 09/24/99
1202 : : //-------------------------------------------------------------------------
1203 : : /*
1204 : : CubitStatus PartitionTool::partition( RefEdge* edge_ptr,
1205 : : DLIList<RefVertex*>& split_points,
1206 : : DLIList<RefEdge*>& new_edges,
1207 : : CubitBoolean ignore_mesh )
1208 : : {
1209 : : DLIList<CubitVector*> vect_list;
1210 : : split_points.reset();
1211 : : for( int i = split_points.size(); i--; )
1212 : : vect_list.append( new CubitVector( split_points.get_and_step()->coordinates() ) );
1213 : : CubitStatus result = partition( edge_ptr, vect_list, new_edges, ignore_mesh );
1214 : : while( vect_list.size() )
1215 : : delete vect_list.pop();
1216 : : return result;
1217 : : }
1218 : : */
1219 : 0 : CubitStatus PartitionTool::partition( RefEdge* edge_ptr,
1220 : : DLIList<CubitVector*>& split_points,
1221 : : DLIList<RefEdge*>& new_edges,
1222 : : CubitBoolean ignore_mesh )
1223 : : {
1224 [ # # ]: 0 : DLIList<RefVertex*> new_vertices;
1225 [ # # ][ # # ]: 0 : return partition( edge_ptr, split_points, new_vertices, new_edges, ignore_mesh );
1226 : : }
1227 : :
1228 : 0 : CubitStatus PartitionTool::partition( RefEdge* edge_ptr,
1229 : : DLIList<CubitVector*>& split_points,
1230 : : DLIList<RefVertex*>& new_vertices,
1231 : : DLIList<RefEdge*>& new_edges,
1232 : : CubitBoolean ignore_mesh )
1233 : : {
1234 [ # # ][ # # ]: 0 : if( split_points.size() < 1 ) return CUBIT_FAILURE;
1235 : 0 : CubitStatus result = CUBIT_SUCCESS;
1236 : 0 : RefVertex* new_vtx = 0;
1237 : :
1238 [ # # ][ # # ]: 0 : if( split_points.size() == 1 ) {
1239 : 0 : RefEdge *edge1_ptr = 0, *edge2_ptr = 0;
1240 [ # # ][ # # ]: 0 : new_vtx = partition( edge_ptr, *(split_points.get()), edge1_ptr, edge2_ptr, ignore_mesh );
1241 [ # # ]: 0 : if( !new_vtx )
1242 : 0 : return CUBIT_FAILURE;
1243 : :
1244 [ # # ]: 0 : new_vertices.append(new_vtx);
1245 [ # # ][ # # ]: 0 : if( edge1_ptr ) new_edges.append( edge1_ptr );
1246 [ # # ][ # # ]: 0 : if( edge2_ptr ) new_edges.append( edge2_ptr );
1247 : 0 : return CUBIT_SUCCESS;
1248 : : }
1249 : :
1250 [ # # ]: 0 : int i, j, count = split_points.size();
1251 : :
1252 [ # # ][ # # ]: 0 : CubitVector** vtx_array = new CubitVector*[count];
1253 [ # # ][ # # ]: 0 : double* param_array = new double[count];
1254 [ # # ]: 0 : for( i = 0; i < count; i++ )
1255 : : {
1256 [ # # ]: 0 : vtx_array[i] = split_points.get_and_step();
1257 [ # # ]: 0 : param_array[i] = edge_ptr->u_from_position( *(vtx_array[i]) );
1258 : : }
1259 : :
1260 [ # # ]: 0 : for( i = 0; i < count - 1; i++ )
1261 : : {
1262 : 0 : int index = i;
1263 [ # # ]: 0 : for( j = i + 1; j < count; j++ )
1264 [ # # ]: 0 : if( param_array[j] < param_array[index] ) index = j;
1265 : 0 : double temp_dbl = param_array[i];
1266 : 0 : CubitVector* temp_vtx = vtx_array[i];
1267 : 0 : param_array[i] = param_array[index];
1268 : 0 : vtx_array[i] = vtx_array[index];
1269 : 0 : param_array[index] = temp_dbl;
1270 : 0 : vtx_array[index] = temp_vtx;
1271 : : }
1272 [ # # ]: 0 : delete [] param_array;
1273 : :
1274 [ # # ]: 0 : RefVertex* end_vtx = edge_ptr->end_vertex();
1275 [ # # ]: 0 : for( i = 0; i < count; i++ )
1276 : : {
1277 : : RefEdge *first_new_edge, *secnd_new_edge;
1278 : 0 : new_vtx = partition( edge_ptr, *(vtx_array[i]), first_new_edge,
1279 [ # # ]: 0 : secnd_new_edge, ignore_mesh );
1280 [ # # ]: 0 : if( ! new_vtx )
1281 : : {
1282 : 0 : result = CUBIT_FAILURE;
1283 : 0 : continue;
1284 : : }
1285 : :
1286 [ # # ]: 0 : new_vertices.append(new_vtx);
1287 : :
1288 [ # # ]: 0 : if( ! secnd_new_edge ) secnd_new_edge = edge_ptr;
1289 [ # # ][ # # ]: 0 : if( NULL == secnd_new_edge->other_vertex(end_vtx) )
1290 : : {
1291 : 0 : edge_ptr = first_new_edge;
1292 [ # # ]: 0 : new_edges.append( secnd_new_edge );
1293 : : }
1294 : : else
1295 : : {
1296 : 0 : edge_ptr = secnd_new_edge;
1297 [ # # ]: 0 : new_edges.append( first_new_edge );
1298 : : }
1299 : : }
1300 [ # # ]: 0 : new_edges.append( edge_ptr );
1301 [ # # ]: 0 : delete [] vtx_array;
1302 : :
1303 : 0 : return result;
1304 : : }
1305 : :
1306 : :
1307 : :
1308 : :
1309 : : //-------------------------------------------------------------------------
1310 : : // Purpose : Combine all possible PartitionEdges
1311 : : //
1312 : : // Special Notes :
1313 : : //
1314 : : // Creator : Jason Kraftcheck
1315 : : //
1316 : : // Creation Date : 08/23/99
1317 : : //-------------------------------------------------------------------------
1318 : 0 : CubitStatus PartitionTool::unpartitionAll( DLIList<RefEdge*>& partition_edges,
1319 : : DLIList<RefEdge*>& restored_edges)
1320 : : {
1321 : : int i;
1322 [ # # ][ # # ]: 0 : DLIList<RefVertex*> vertex_list, tmp_list;
[ # # ]
1323 [ # # ][ # # ]: 0 : for ( i = partition_edges.size(); i--; )
1324 : : {
1325 [ # # ]: 0 : tmp_list.clean_out();
1326 [ # # ][ # # ]: 0 : partition_edges.step_and_get()->ref_vertices( tmp_list );
1327 [ # # ]: 0 : vertex_list += tmp_list;
1328 : : }
1329 : :
1330 [ # # ][ # # ]: 0 : for ( i = vertex_list.size(); i--; )
1331 [ # # ][ # # ]: 0 : vertex_list.step_and_get()->marked(0);
1332 [ # # ][ # # ]: 0 : for ( i = vertex_list.size(); i--; )
1333 : : {
1334 [ # # ]: 0 : RefVertex* vtx = vertex_list.step_and_get();
1335 [ # # ][ # # ]: 0 : vtx->marked( vtx->marked() + 1 );
1336 : : }
1337 [ # # ][ # # ]: 0 : for ( i = vertex_list.size(); i--; )
1338 : : {
1339 [ # # ]: 0 : RefVertex* vtx = vertex_list.step_and_get();
1340 : :
1341 [ # # ]: 0 : TBPoint* pt = vtx->get_point_ptr();
1342 [ # # ]: 0 : CompositePoint* comp = dynamic_cast<CompositePoint*>(pt);
1343 [ # # ]: 0 : if ( comp )
1344 [ # # ]: 0 : pt = comp->get_point();
1345 [ # # ]: 0 : PartitionPoint* part = dynamic_cast<PartitionPoint*>(pt);
1346 : :
1347 [ # # ][ # # ]: 0 : if( vtx->marked() != 2 || !can_remove(vtx) ||
[ # # ][ # # ]
[ # # ]
1348 [ # # ][ # # ]: 0 : !part || part->real_point() )
[ # # ]
1349 [ # # ]: 0 : vertex_list.change_to(0);
1350 [ # # ]: 0 : vtx->marked(0);
1351 : : }
1352 [ # # ]: 0 : vertex_list.remove_all_with_value(0);
1353 : :
1354 [ # # ][ # # ]: 0 : if (vertex_list.size() == 0)
1355 : 0 : return CUBIT_SUCCESS;
1356 : :
1357 : : RefEdge* edge;
1358 [ # # ][ # # ]: 0 : std::vector< TDUPtr<RefEdge> > result_list;
1359 [ # # ][ # # ]: 0 : for ( i = vertex_list.size(); i--; )
1360 : : {
1361 : : edge = CompositeTool::instance()
1362 [ # # ][ # # ]: 0 : ->remove_vertex( vertex_list.get_and_step(), true );
[ # # ]
1363 [ # # ]: 0 : if ( edge )
1364 : : {
1365 [ # # ][ # # ]: 0 : result_list.push_back( edge );
[ # # ]
1366 : : }
1367 : : }
1368 : :
1369 : : unsigned int j;
1370 [ # # ][ # # ]: 0 : for ( j = 0; j < result_list.size(); j++ )
1371 [ # # ][ # # ]: 0 : if( result_list[j] )
[ # # ]
1372 [ # # ][ # # ]: 0 : restored_edges.append_unique( result_list[j].ptr() );
[ # # ]
1373 : :
1374 [ # # ][ # # ]: 0 : return restored_edges.size() ? CUBIT_SUCCESS : CUBIT_FAILURE;
[ # # ]
1375 : : }
1376 : :
1377 : :
1378 : : //-------------------------------------------------------------------------
1379 : : // Purpose : Unpartition faces and cleanup.
1380 : : //
1381 : : // Special Notes :
1382 : : //
1383 : : // Creator : Jason Kraftcheck
1384 : : //
1385 : : // Creation Date : 07/26/99
1386 : : //-------------------------------------------------------------------------
1387 : 0 : CubitStatus PartitionTool::unpartitionAll(
1388 : : DLIList<RefFace*>& partition_faces,
1389 : : DLIList<RefFace*>& restored_faces )
1390 : : {
1391 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> query_input, query_output;
[ # # ]
1392 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( partition_faces, query_input );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1393 : : ModelQueryEngine::instance()->query_model(
1394 [ # # ][ # # ]: 0 : query_input, DagType::co_edge_type(), query_output );
[ # # ]
1395 : :
1396 [ # # ][ # # ]: 0 : DLIList<CoEdge*> coedge_list;
1397 [ # # ][ # # ]: 0 : DLIList<RefEdge*> refedge_list;
1398 [ # # ][ # # ]: 0 : CAST_LIST( query_output, coedge_list, CoEdge );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1399 [ # # ][ # # ]: 0 : assert( query_output.size() == coedge_list.size() );
[ # # ]
1400 : : int i;
1401 [ # # ][ # # ]: 0 : for ( i = coedge_list.size(); i--; )
1402 [ # # ][ # # ]: 0 : refedge_list.append( coedge_list.step_and_get()->get_ref_edge_ptr() );
[ # # ]
1403 : :
1404 [ # # ][ # # ]: 0 : for ( i = refedge_list.size(); i--; )
1405 [ # # ][ # # ]: 0 : refedge_list.step_and_get()->marked(0);
1406 [ # # ][ # # ]: 0 : for ( i = refedge_list.size(); i--; )
1407 : : {
1408 [ # # ]: 0 : RefEdge* edge = refedge_list.step_and_get();
1409 [ # # ][ # # ]: 0 : edge->marked( edge->marked() + 1 );
1410 : : }
1411 [ # # ][ # # ]: 0 : for ( i = refedge_list.size(); i--; )
1412 : : {
1413 [ # # ]: 0 : RefEdge* edge = refedge_list.step_and_get();
1414 [ # # ][ # # ]: 0 : PartPTCurve* point_curve = dynamic_cast<PartPTCurve*>(edge->get_curve_ptr());
1415 [ # # ][ # # ]: 0 : SegmentedCurve* seg_curve = dynamic_cast<SegmentedCurve*>(edge->get_curve_ptr());
1416 [ # # ][ # # ]: 0 : if((point_curve || (seg_curve && edge->marked() == 2)) &&
[ # # ][ # # ]
[ # # ][ # # ]
1417 [ # # ]: 0 : can_remove(edge))
1418 : : {
1419 : : // Try to remove this partition.
1420 : : }
1421 : : else
1422 : : {
1423 : : // Don't try to remove this partition.
1424 [ # # ]: 0 : refedge_list.change_to(0);
1425 : : }
1426 [ # # ]: 0 : edge->marked(0);
1427 : : }
1428 [ # # ]: 0 : refedge_list.remove_all_with_value(0);
1429 : :
1430 [ # # ][ # # ]: 0 : if (refedge_list.size() == 0)
1431 : 0 : return CUBIT_SUCCESS;
1432 : :
1433 : : RefFace* face;
1434 [ # # ][ # # ]: 0 : std::vector< TDUPtr<RefFace> > result_list;
1435 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_list;
1436 [ # # ][ # # ]: 0 : for ( i = refedge_list.size(); i--; )
1437 : : {
1438 : 0 : bool is_partition = false;
1439 [ # # ]: 0 : RefEdge* edge = refedge_list.get_and_step();
1440 [ # # ][ # # ]: 0 : edge->bridge_manager()->get_bridge_list( bridge_list );
1441 [ # # ][ # # ]: 0 : while ( bridge_list.size() )
1442 : : {
1443 [ # # ]: 0 : TopologyBridge* bridge = bridge_list.pop();
1444 [ # # ][ # # ]: 0 : if ( dynamic_cast<PartitionEntity*>(bridge) ) {
[ # # ]
1445 : 0 : is_partition = true;
1446 : 0 : break;
1447 : : }
1448 [ # # ]: 0 : CompositeCurve* comp = dynamic_cast<CompositeCurve*>(bridge);
1449 [ # # ]: 0 : if ( comp ) {
1450 [ # # ][ # # ]: 0 : for ( int j = 0; j < comp->num_curves(); j++ )
1451 [ # # ][ # # ]: 0 : bridge_list.append(comp->get_curve(j));
1452 : : }
1453 : : }
1454 [ # # ]: 0 : if ( !is_partition )
1455 : 0 : continue;
1456 : :
1457 [ # # ][ # # ]: 0 : face = CompositeTool::instance()->remove_edge( edge, true );
1458 [ # # ]: 0 : if ( face )
1459 : : {
1460 [ # # ][ # # ]: 0 : result_list.push_back( face );
[ # # ]
1461 : : }
1462 : : }
1463 : :
1464 : : unsigned int j;
1465 [ # # ][ # # ]: 0 : for ( j = 0; j < result_list.size(); j++ )
1466 [ # # ][ # # ]: 0 : if( result_list[j] )
[ # # ]
1467 [ # # ][ # # ]: 0 : restored_faces.append_unique( result_list[j].ptr() );
[ # # ]
1468 : :
1469 [ # # ][ # # ]: 0 : return restored_faces.size() ? CUBIT_SUCCESS : CUBIT_FAILURE;
[ # # ]
1470 : : }
1471 : :
1472 : :
1473 : :
1474 : :
1475 : 0 : CubitStatus PartitionTool::partition_face_by_curves( RefFace* face_to_split,
1476 : : const DLIList<Curve*>& split_curves,
1477 : : DLIList<RefFace*>& result_set,
1478 : : CubitBoolean do_split_curves,
1479 : : DLIList<RefEdge*>* new_edges,
1480 : : CubitBoolean )
1481 : : {
1482 : : int i, j, numpts;
1483 : 0 : CubitStatus status = CUBIT_SUCCESS;
1484 : 0 : bool some_success = false;
1485 [ # # ]: 0 : DLIList<RefEdge*> new_edge_list;
1486 [ # # ][ # # ]: 0 : DLIList<RefFace*> faces[2];
[ # # ][ # # ]
[ # # # # ]
1487 [ # # ][ # # ]: 0 : DLIList<CubitVector*> segments;
1488 [ # # ][ # # ]: 0 : GMem gmem;
1489 : :
1490 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() )
1491 : : {
1492 [ # # ]: 0 : DLIList<RefFace*> tmp_ref_face_list(1);
1493 [ # # ]: 0 : tmp_ref_face_list.append( face_to_split );
1494 [ # # ][ # # ]: 0 : CubitUndo::save_state_with_cubit_file( tmp_ref_face_list );
1495 : : }
1496 : :
1497 [ # # ]: 0 : faces[0].append( face_to_split );
1498 [ # # ][ # # ]: 0 : for (i = 0; i < split_curves.size(); i++ )
1499 : : {
1500 [ # # ]: 0 : Curve* curve = split_curves.next(i);
1501 [ # # ]: 0 : GeometryQueryEngine* engine = curve->get_geometry_query_engine();
1502 : :
1503 [ # # ][ # # ]: 0 : if (!engine->get_graphics( curve, &gmem, facetingTolerance ))
1504 : : {
1505 : 0 : status = CUBIT_FAILURE;
1506 : 0 : continue;
1507 : : }
1508 : :
1509 : 0 : numpts = gmem.pointListCount;
1510 : : /*
1511 : : This code causes a failure in virtual imprint because it compares
1512 : : against the number of graphics curve facets. I think this is wrong but
1513 : : for now I will comment out this code. In the end, I think that
1514 : : partitioning should not be done on the faceted model.
1515 : : If this hasn't been addressed in 6 months just kill this code. KGM 1/5/06
1516 : :
1517 : : // arbitrary # of subdivisions = 20 --KGM
1518 : : const double NUM_SEGS = 20.0;
1519 : :
1520 : : // if the graphics facets give too many points
1521 : : // (which happens if the model is large right now)
1522 : : // trim it to some more reasonable number
1523 : : if ( numpts > static_cast<int>(NUM_SEGS) )
1524 : : {
1525 : :
1526 : : // this independent of the curve sense
1527 : : double t0 = curve->start_param();
1528 : : double t1 = curve->end_param();
1529 : :
1530 : : double inc = (t1 - t0)/NUM_SEGS;
1531 : : double t;
1532 : : CubitVector* p1;
1533 : : for (t = t0; t < t1; t+= inc)
1534 : : {
1535 : : p1 = new CubitVector;
1536 : : CubitStatus status = curve->position_from_u( t, *p1 );
1537 : : if (status == CUBIT_SUCCESS)
1538 : : segments.append( p1 );
1539 : : }
1540 : :
1541 : : // make sure the end point is EXACTLY represented
1542 : : p1 = new CubitVector;
1543 : : CubitStatus status = curve->position_from_u( t1, *p1 );
1544 : : if (status == CUBIT_SUCCESS)
1545 : : {
1546 : : segments.append( p1 );
1547 : : }
1548 : : else
1549 : : {
1550 : : PRINT_ERROR("Bad end point evaluation on curve\n");
1551 : : }
1552 : :
1553 : : bool tmp_debug = false;
1554 : : if ( tmp_debug ) // KGM
1555 : : {
1556 : : for ( int i = 0; i < segments.size(); i++ )
1557 : : {
1558 : : CubitVector* point = segments.get_and_step();
1559 : : GfxDebug::draw_point( *point, CUBIT_RED_INDEX );
1560 : : }
1561 : : GfxDebug::flush();
1562 : : }
1563 : : }
1564 : : else
1565 : : */
1566 : : {
1567 [ # # ][ # # ]: 0 : if (curve->bridge_sense() == CUBIT_REVERSED)
1568 : : {
1569 [ # # ][ # # ]: 0 : CubitVector* p1 = new CubitVector;
1570 [ # # ][ # # ]: 0 : curve->position_from_u( curve->end_param(), *p1 );
1571 [ # # ]: 0 : segments.append( p1 );
1572 : : }
1573 : : else
1574 : : {
1575 [ # # ][ # # ]: 0 : CubitVector* p1 = new CubitVector;
1576 [ # # ][ # # ]: 0 : curve->position_from_u( curve->start_param(), *p1 );
1577 [ # # ]: 0 : segments.append( p1 );
1578 : : }
1579 : :
1580 : 0 : --numpts;
1581 [ # # ]: 0 : for (j = 1; j < numpts; j++)
1582 : : {
1583 [ # # ]: 0 : const GPoint& p = gmem.point_list()[j];
1584 [ # # ][ # # ]: 0 : segments.append( new CubitVector( p.x, p.y, p.z ) );
[ # # ]
1585 : : }
1586 : :
1587 [ # # ][ # # ]: 0 : if (curve->bridge_sense() == CUBIT_REVERSED)
1588 : : {
1589 [ # # ][ # # ]: 0 : CubitVector* p1 = new CubitVector;
1590 [ # # ][ # # ]: 0 : curve->position_from_u( curve->start_param(), *p1 );
1591 [ # # ]: 0 : segments.append( p1 );
1592 : : }
1593 : : else
1594 : : {
1595 [ # # ][ # # ]: 0 : CubitVector* p1 = new CubitVector;
1596 [ # # ][ # # ]: 0 : curve->position_from_u( curve->end_param(), *p1 );
1597 [ # # ]: 0 : segments.append( p1 );
1598 : : }
1599 : : }
1600 : :
1601 : 0 : int index = i % 2;
1602 [ # # ]: 0 : status = insert_edge( faces[index], segments, faces[1-index], new_edge_list, do_split_curves );
1603 [ # # ]: 0 : if (status)
1604 : : {
1605 : 0 : some_success = true;
1606 [ # # ]: 0 : if (new_edges)
1607 [ # # ]: 0 : *new_edges += new_edge_list;
1608 : : }
1609 : : else
1610 : : {
1611 [ # # ]: 0 : faces[1-index] = faces[index];
1612 : : }
1613 : :
1614 [ # # ][ # # ]: 0 : while (segments.size())
1615 [ # # ]: 0 : delete segments.pop();
1616 : : }
1617 : :
1618 [ # # ][ # # ]: 0 : result_set = faces[split_curves.size()%2];
1619 : :
1620 : : //surface might not have gotton split
1621 [ # # ][ # # ]: 0 : if( CubitUndo::get_undo_enabled() && result_set.size() == 1)
[ # # ][ # # ]
[ # # ]
1622 [ # # ]: 0 : CubitUndo::remove_last_undo();
1623 : :
1624 [ # # ]: 0 : if( some_success )
1625 : 0 : return CUBIT_SUCCESS;
1626 : : else
1627 [ # # ][ # # ]: 0 : return CUBIT_FAILURE;
1628 : : }
1629 : :
1630 : : //-------------------------------------------------------------------------
1631 : : // Purpose : Do multiple partitioning of a RefFace
1632 : : //
1633 : : // Special Notes :
1634 : : //
1635 : : // Creator : Jason Kraftcheck
1636 : : //
1637 : : // Creation Date : 11/23/99
1638 : : //-------------------------------------------------------------------------
1639 : 0 : CubitStatus PartitionTool::partition( RefFace* face_to_split,
1640 : : const DLIList<RefEdge*>& split_edges,
1641 : : DLIList<RefFace*>& result_set,
1642 : : CubitBoolean do_split_curves,
1643 : : DLIList<RefEdge*>* new_edges,
1644 : : CubitBoolean )
1645 : : {
1646 : : int i;
1647 : 0 : CubitStatus status = CUBIT_SUCCESS;
1648 : :
1649 : : // get the curves out of the edge list
1650 [ # # ]: 0 : DLIList<Curve*> split_curves;
1651 [ # # ][ # # ]: 0 : for (i = 0; i < split_edges.size(); i++ )
1652 : : {
1653 [ # # ]: 0 : RefEdge* edge = split_edges.next(i);
1654 [ # # ][ # # ]: 0 : split_curves.append( edge->get_curve_ptr() );
1655 : : }
1656 : :
1657 : : // partition based on the Curves
1658 : : status = partition_face_by_curves( face_to_split, split_curves,
1659 [ # # ]: 0 : result_set, do_split_curves, new_edges );
1660 : :
1661 [ # # ]: 0 : return status;
1662 : : }
1663 : :
1664 : 0 : CubitStatus PartitionTool::partition( RefFace* face,
1665 : : DLIList<RefEdge*>& edges,
1666 : : RefFace*& new1,
1667 : : RefFace*& new2,
1668 : : CubitBoolean im )
1669 : : {
1670 [ # # ]: 0 : DLIList<RefFace*> result_faces;
1671 [ # # ]: 0 : CubitStatus result = partition( face, edges, result_faces, im );
1672 [ # # ]: 0 : result_faces.reset();
1673 [ # # ]: 0 : new1 = result_faces.get_and_step();
1674 [ # # ]: 0 : new2 = result_faces.get_and_step();
1675 [ # # ]: 0 : return result;
1676 : : }
1677 : :
1678 : :
1679 : :
1680 : : //-------------------------------------------------------------------------
1681 : : // Purpose : Partition a volume.
1682 : : //
1683 : : // Special Notes :
1684 : : //
1685 : : // Creator : Jason Kraftcheck
1686 : : //
1687 : : // Creation Date : 11/24/99
1688 : : //-------------------------------------------------------------------------
1689 : 0 : CubitStatus PartitionTool::partition( RefVolume* volume_ptr,
1690 : : DLIList<RefFace*>& split_faces,
1691 : : RefVolume*& first_new_volume,
1692 : : RefVolume*& second_new_volume,
1693 : : CubitBoolean )
1694 : : {
1695 : : int i;
1696 : :
1697 [ # # ]: 0 : Lump* lump = volume_ptr->get_lump_ptr();
1698 [ # # ]: 0 : DLIList<Surface*> surface_list;
1699 [ # # ][ # # ]: 0 : for( i = split_faces.size(); i--; )
1700 [ # # ][ # # ]: 0 : surface_list.append(split_faces.step_and_get()->get_surface_ptr());
[ # # ]
1701 : :
1702 [ # # ][ # # ]: 0 : DLIList<Lump*> result_list;
1703 [ # # ][ # # ]: 0 : for( i = surface_list.size(); result_list.size() < 2 && i--; )
[ # # ][ # # ]
[ # # ]
1704 : : {
1705 [ # # ]: 0 : Lump* result = PartitionEngine::instance().
1706 [ # # ][ # # ]: 0 : insert_surface( surface_list.step_and_get(), lump );
1707 : :
1708 [ # # ]: 0 : if(!result)
1709 : : {
1710 [ # # ][ # # ]: 0 : RefFace* face = dynamic_cast<RefFace*>(surface_list.get()->topology_entity());
[ # # ]
1711 [ # # ][ # # ]: 0 : PRINT_ERROR("Insertion of surface %d into volume %d failed.\n",
[ # # ][ # # ]
[ # # ][ # # ]
1712 [ # # ]: 0 : face ? face->id() : 0, volume_ptr->id() );
1713 : 0 : continue;
1714 : : }
1715 : :
1716 : 0 : lump = result;
1717 [ # # ]: 0 : result_list.append_unique(lump);
1718 : : }
1719 : :
1720 [ # # ][ # # ]: 0 : DLIList<Body*> body_list;
1721 [ # # ]: 0 : volume_ptr->bodies(body_list);
1722 [ # # ][ # # ]: 0 : assert(body_list.size() == 1);
1723 [ # # ]: 0 : Body* body_ptr = body_list.get();
1724 [ # # ]: 0 : BodySM* bodysm = body_ptr->get_body_sm_ptr();
1725 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->make_Body(bodysm);
1726 : :
1727 [ # # ]: 0 : result_list.reset();
1728 [ # # ][ # # ]: 0 : if( ! result_list.size() )
1729 : 0 : return CUBIT_FAILURE;
1730 : :
1731 : 0 : first_new_volume = volume_ptr;
1732 [ # # ][ # # ]: 0 : second_new_volume = dynamic_cast<RefVolume*>(result_list.get()->topology_entity());
[ # # ]
1733 : :
1734 [ # # ]: 0 : return CUBIT_SUCCESS;
1735 : : }
1736 : 0 : CubitStatus PartitionTool::partition( RefVolume* volume_ptr,
1737 : : DLIList<CubitFacet*>& split_faces,
1738 : : RefVolume*& first_new_volume,
1739 : : RefVolume*& second_new_volume,
1740 : : DLIList<RefFace*>& new_surfaces,
1741 : : CubitBoolean )
1742 : : {
1743 [ # # ]: 0 : Lump* lump = volume_ptr->get_lump_ptr();
1744 : :
1745 [ # # ]: 0 : Surface* result = PartitionEngine::instance().
1746 [ # # ]: 0 : insert_surface( split_faces, lump );
1747 : :
1748 [ # # ]: 0 : DLIList<Body*> body_list;
1749 [ # # ]: 0 : volume_ptr->bodies(body_list);
1750 [ # # ][ # # ]: 0 : assert(body_list.size() == 1);
1751 [ # # ]: 0 : Body* body_ptr = body_list.get();
1752 [ # # ]: 0 : BodySM* bodysm = body_ptr->get_body_sm_ptr();
1753 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->make_Body(bodysm);
1754 : :
1755 [ # # ]: 0 : if( ! result )
1756 : : {
1757 [ # # ][ # # ]: 0 : PRINT_ERROR("Failed to insert faceted surface into volume %d\n",
[ # # ][ # # ]
1758 [ # # ]: 0 : volume_ptr->id());
1759 : 0 : return CUBIT_FAILURE;
1760 : : }
1761 : :
1762 [ # # ][ # # ]: 0 : RefFace* result_face = dynamic_cast<RefFace*>(result->topology_entity());
1763 [ # # ]: 0 : assert(!!result_face);
1764 [ # # ]: 0 : new_surfaces.append(result_face);
1765 : :
1766 [ # # ][ # # ]: 0 : DLIList<RefVolume*> face_vols;
1767 [ # # ]: 0 : result_face->ref_volumes(face_vols);
1768 [ # # ]: 0 : face_vols.reset();
1769 [ # # ]: 0 : first_new_volume = face_vols.get();
1770 [ # # ]: 0 : second_new_volume = face_vols.next();
1771 : :
1772 [ # # ][ # # ]: 0 : if ( DEBUG_FLAG(88) ) {
[ # # ]
1773 [ # # ]: 0 : GfxDebug::display_all();
1774 [ # # ][ # # ]: 0 : if( PartitionSurface* ps = dynamic_cast<PartitionSurface*>(result) )
1775 [ # # ]: 0 : ps->draw_facets(CUBIT_GREEN_INDEX);
1776 [ # # ]: 0 : DLIList<RefEdge*> edges;
1777 [ # # ][ # # ]: 0 : DLIList<RefFace*> faces;
1778 [ # # ]: 0 : result_face->ref_edges(edges);
1779 [ # # ][ # # ]: 0 : for ( int i = edges.size(); i--; )
1780 : : {
1781 [ # # ]: 0 : faces.clean_out();
1782 [ # # ]: 0 : RefEdge* edge = edges.get_and_step();
1783 [ # # ]: 0 : edge->ref_faces(faces);
1784 [ # # ][ # # ]: 0 : if ( faces.size() > 1 )
1785 [ # # ]: 0 : GfxDebug::highlight_ref_edge( edge );
1786 : : }
1787 [ # # ][ # # ]: 0 : GfxDebug::flush();
1788 : : }
1789 : :
1790 [ # # ]: 0 : return CUBIT_SUCCESS;
1791 : : }
1792 : :
1793 : :
1794 : : //-------------------------------------------------------------------------
1795 : : // Purpose : Delete a volume
1796 : : //
1797 : : // Special Notes :
1798 : : //
1799 : : // Creator : Jason Kraftcheck
1800 : : //
1801 : : // Creation Date : 02/11/03
1802 : : //-------------------------------------------------------------------------
1803 : 0 : CubitStatus PartitionTool::destroy_volume_partition( RefVolume* volume )
1804 : : {
1805 : 0 : Body* body = volume->get_body_ptr();
1806 [ # # ]: 0 : PartitionLump* lump = dynamic_cast<PartitionLump*>(volume->get_lump_ptr());
1807 [ # # ]: 0 : if( !lump ) return CUBIT_FAILURE;
1808 : 0 : CubitStatus result = PartitionEngine::instance().destroy_lump(lump);
1809 : 0 : TopologyBridge* tb = body->bridge_manager()->topology_bridge();
1810 [ # # ]: 0 : GeometryQueryTool::instance()->make_Body(dynamic_cast<BodySM*>(tb));
1811 : 0 : return result;
1812 : : }
1813 : :
1814 : :
1815 : 0 : CubitStatus PartitionTool::unpartitionAll( DLIList<RefVolume*>& passed_list,
1816 : : DLIList<RefVolume*>& restored_list )
1817 : : {
1818 : : int i;
1819 : :
1820 [ # # ][ # # ]: 0 : if (!passed_list.size())
1821 : 0 : return CUBIT_FAILURE;
1822 : :
1823 : : // Get owning body
1824 [ # # ]: 0 : DLIList<Body*> body_list;
1825 : 0 : Body* body_ptr = 0;
1826 [ # # ][ # # ]: 0 : for( i = passed_list.size(); i--; )
1827 : : {
1828 [ # # ]: 0 : RefVolume* vol_ptr = passed_list.step_and_get();
1829 [ # # ]: 0 : body_list.clean_out();
1830 [ # # ]: 0 : vol_ptr->bodies(body_list);
1831 [ # # ][ # # ]: 0 : assert(body_list.size() == 1);
1832 [ # # ]: 0 : if( !body_ptr )
1833 [ # # ]: 0 : body_ptr = body_list.get();
1834 [ # # ][ # # ]: 0 : else if( body_ptr != body_list.get() )
1835 : : {
1836 [ # # ][ # # ]: 0 : PRINT_ERROR("Invalid volume list passed to PartitionTool::unpartition.\n"
[ # # ]
1837 [ # # ]: 0 : "All volumes must belong to the same body.\n");
1838 : 0 : return CUBIT_FAILURE;
1839 : : }
1840 : : }
1841 : :
1842 : : // Get lump list and real, partitioned lump
1843 [ # # ][ # # ]: 0 : DLIList<PartitionLump*> lump_list;
1844 : 0 : TopologyBridge* real_lump = 0;
1845 [ # # ][ # # ]: 0 : for( i = passed_list.size(); i--; )
1846 : : {
1847 [ # # ][ # # ]: 0 : Lump* lump = passed_list.step_and_get()->get_lump_ptr();
1848 [ # # ]: 0 : PartitionLump* partlump = dynamic_cast<PartitionLump*>(lump);
1849 [ # # ]: 0 : if( !partlump )
1850 : : {
1851 [ # # ][ # # ]: 0 : PRINT_ERROR("Invalid volume list passed to PartitionTool::unpartition.\n"
[ # # ][ # # ]
[ # # ]
1852 : : "Volume %d is not a partition.\n",
1853 [ # # ]: 0 : passed_list.get()->id());
1854 : 0 : return CUBIT_FAILURE;
1855 : : }
1856 [ # # ]: 0 : if( !real_lump )
1857 [ # # ]: 0 : real_lump = partlump->partitioned_entity();
1858 [ # # ][ # # ]: 0 : else if( real_lump != partlump->partitioned_entity() )
1859 : : {
1860 [ # # ][ # # ]: 0 : PRINT_ERROR("Invalid volume list passed to PartitionTool::unpartition.\n"
[ # # ]
1861 [ # # ]: 0 : "All volumes must be partitions of the same real volume.\n");
1862 : 0 : return CUBIT_FAILURE;
1863 : : }
1864 : :
1865 [ # # ]: 0 : lump_list.append(partlump);
1866 : : }
1867 : :
1868 : : // Find all faces volumes have in common
1869 [ # # ][ # # ]: 0 : DLIList<RefFace*> all_faces, vol_faces;
[ # # ][ # # ]
1870 [ # # ]: 0 : passed_list.last();
1871 [ # # ][ # # ]: 0 : for( i = passed_list.size(); i--; )
1872 : : {
1873 [ # # ]: 0 : vol_faces.clean_out();
1874 [ # # ][ # # ]: 0 : passed_list.step_and_get()->ref_faces( vol_faces );
1875 [ # # ]: 0 : all_faces += vol_faces;
1876 : : }
1877 [ # # ][ # # ]: 0 : for( i = all_faces.size(); i--; )
1878 [ # # ][ # # ]: 0 : all_faces.step_and_get()->marked(-1);
1879 [ # # ][ # # ]: 0 : for( i = all_faces.size(); i--; )
1880 : : {
1881 [ # # ]: 0 : RefFace* face = all_faces.step_and_get();
1882 [ # # ][ # # ]: 0 : face->marked( face->marked() + 1 );
1883 : : }
1884 [ # # ][ # # ]: 0 : for( i = all_faces.size(); i--; )
1885 [ # # ][ # # ]: 0 : if( all_faces.step_and_get()->marked() )
[ # # ]
1886 [ # # ][ # # ]: 0 : all_faces.get()->marked(0);
1887 : : else
1888 [ # # ]: 0 : all_faces.change_to(0);
1889 [ # # ]: 0 : all_faces.remove_all_with_value(0);
1890 : :
1891 [ # # ][ # # ]: 0 : for( i = all_faces.size(); i--; )
1892 [ # # ][ # # ]: 0 : if ( !can_remove( all_faces.step_and_get() ) )
[ # # ]
1893 [ # # ]: 0 : all_faces.change_to(0);
1894 [ # # ]: 0 : all_faces.remove_all_with_value(0);
1895 : :
1896 : :
1897 : : // Find all partition surfaces
1898 [ # # ][ # # ]: 0 : DLIList<PartitionSurface*> psurf_list;
1899 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_list;
1900 [ # # ][ # # ]: 0 : for( i = all_faces.size(); i--; )
1901 : : {
1902 [ # # ]: 0 : bridge_list.clean_out();
1903 [ # # ][ # # ]: 0 : all_faces.step_and_get()->bridge_manager()->get_bridge_list(bridge_list);
[ # # ]
1904 [ # # ][ # # ]: 0 : for( int j = bridge_list.size(); j--; )
1905 : : {
1906 [ # # ][ # # ]: 0 : PartitionSurface* psurf = dynamic_cast<PartitionSurface*>(bridge_list.step_and_get());
1907 [ # # ][ # # ]: 0 : if(psurf && psurf->partitioned_entity() == real_lump)
[ # # ][ # # ]
1908 : : {
1909 [ # # ]: 0 : psurf_list.append(psurf);
1910 : : }
1911 : : }
1912 : : }
1913 : :
1914 : : // Remove partitioning surfaces
1915 [ # # ][ # # ]: 0 : for( i = psurf_list.size(); i--; )
1916 : : {
1917 [ # # ]: 0 : PartitionSurface* surf = psurf_list.step_and_get();
1918 : :
1919 [ # # ]: 0 : DLIList<Lump*> lumps;
1920 [ # # ]: 0 : surf->lumps(lumps);
1921 [ # # ][ # # ]: 0 : assert(lumps.size() > 0 && lumps.size() <= 2); // should be one or two surfs
[ # # ][ # # ]
1922 : :
1923 : 0 : RefVolume* volume1 = NULL;
1924 : 0 : RefVolume* volume2 = NULL;
1925 : :
1926 [ # # ]: 0 : lumps.reset();
1927 [ # # ][ # # ]: 0 : if(lumps.size() == 2)
1928 : : {
1929 [ # # ][ # # ]: 0 : TopologyEntity *topo = lumps.get_and_step()->topology_entity();
1930 [ # # ]: 0 : volume1 = CAST_TO(topo, RefVolume);
1931 [ # # ]: 0 : assert(volume1 != NULL);
1932 : :
1933 [ # # ][ # # ]: 0 : topo = lumps.get_and_step()->topology_entity();
1934 [ # # ]: 0 : volume2 = CAST_TO(topo, RefVolume);
1935 [ # # ]: 0 : assert(volume2 != NULL);
1936 : : }
1937 : :
1938 : : //RefFace* face = dynamic_cast<RefFace*>(surf->owner());
1939 [ # # ][ # # ]: 0 : Lump* lump = PartitionEngine::instance().remove_surface(surf);
1940 [ # # ]: 0 : if( !lump )
1941 : : {
1942 [ # # ][ # # ]: 0 : RefFace* face = dynamic_cast<RefFace*>(surf->topology_entity());
1943 [ # # ][ # # ]: 0 : PRINT_ERROR("Failed to remove surface %d\n", face ? face->id() : 0);
[ # # ][ # # ]
[ # # ][ # # ]
1944 : : }
1945 : : else
1946 : : {
1947 [ # # ][ # # ]: 0 : RefVolume *survivor = dynamic_cast<RefVolume*>(lump->topology_entity());
1948 [ # # ][ # # ]: 0 : RefVolume *dead = lumps.size() < 2 ? 0 : survivor == volume1 ? volume2 : volume1;
[ # # ]
1949 [ # # ][ # # ]: 0 : CompositeTool::instance()->update_combined_vols( survivor, dead );
1950 : : }
1951 [ # # ]: 0 : }
1952 : :
1953 : : // Find a surviving volume to return
1954 [ # # ][ # # ]: 0 : for ( i = passed_list.size(); i--; )
1955 : : {
1956 [ # # ][ # # ]: 0 : if( passed_list.step_and_get()->get_lump_ptr() )
[ # # ]
1957 : : {
1958 [ # # ][ # # ]: 0 : restored_list.append( passed_list.get() );
1959 : : }
1960 : : }
1961 : :
1962 : : // update DAG and return
1963 [ # # ]: 0 : BodySM* bodysm = body_ptr->get_body_sm_ptr();
1964 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->make_Body(bodysm);
1965 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
1966 : :
1967 [ # # ]: 0 : return CUBIT_SUCCESS;;
1968 : : }
1969 : :
1970 : :
1971 : :
1972 : : /************** Methods for debugging output ******************/
1973 : :
1974 : 0 : void pt_print_bte_list( int debug_flag, DLIList<BasicTopologyEntity*>& edges,
1975 : : const char* trailing_string )
1976 : : {
1977 [ # # ]: 0 : if( DEBUG_FLAG( debug_flag ) )
1978 : : {
1979 [ # # ][ # # ]: 0 : PRINT_DEBUG(debug_flag, "{ ");
[ # # ]
1980 : 0 : edges.reset();
1981 [ # # ]: 0 : for( int i = edges.size(); i > 1; i-- )
1982 [ # # ][ # # ]: 0 : PRINT_DEBUG(debug_flag, "%d, ",edges.get_and_step()->id() );
[ # # ]
1983 [ # # ]: 0 : if( edges.size() ) {
1984 [ # # ][ # # ]: 0 : PRINT_DEBUG(debug_flag, "%d",edges.get_and_step()->id() );
[ # # ]
1985 : : }
1986 [ # # ][ # # ]: 0 : PRINT_DEBUG(debug_flag, " }%s",trailing_string ? trailing_string : "");
[ # # ][ # # ]
1987 : : }
1988 : 0 : }
1989 : 0 : void pt_print_edge_list( int debug_flag, DLIList<RefEdge*>& edges,
1990 : : const char* trailing_string )
1991 : : {
1992 [ # # ]: 0 : if( DEBUG_FLAG( debug_flag ) )
1993 : : {
1994 [ # # ]: 0 : DLIList<BasicTopologyEntity*> bte_list;
1995 [ # # ]: 0 : bte_list.reset();
1996 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( edges, bte_list);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1997 [ # # ][ # # ]: 0 : pt_print_bte_list( debug_flag, bte_list, trailing_string );
1998 : : }
1999 : 0 : }
2000 : 0 : void pt_print_face_list( int debug_flag, DLIList<RefFace*>& faces,
2001 : : const char* trailing_string )
2002 : : {
2003 [ # # ]: 0 : if( DEBUG_FLAG( debug_flag ) )
2004 : : {
2005 [ # # ]: 0 : DLIList<BasicTopologyEntity*> bte_list;
2006 [ # # ]: 0 : bte_list.reset();
2007 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( faces, bte_list);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2008 [ # # ][ # # ]: 0 : pt_print_bte_list( debug_flag, bte_list, trailing_string );
2009 : : }
2010 : 0 : }
2011 : 0 : void pt_print_loop( int debug_flag, Loop* loop_ptr,
2012 : : const char* trailing_string )
2013 : : {
2014 [ # # ]: 0 : if( DEBUG_FLAG( debug_flag ) )
2015 : : {
2016 [ # # ]: 0 : DLIList<RefEdge*> edges;
2017 [ # # ]: 0 : loop_ptr->ordered_ref_edges( edges );
2018 [ # # ][ # # ]: 0 : pt_print_edge_list( debug_flag, edges, trailing_string );
2019 : : }
2020 : 0 : }
2021 : 0 : void pt_print_shell( int debug_flag, Shell* shell_ptr,
2022 : : const char* trailing_string )
2023 : : {
2024 [ # # ]: 0 : if( DEBUG_FLAG( debug_flag ) )
2025 : : {
2026 [ # # ]: 0 : DLIList<RefFace*> faces;
2027 [ # # ]: 0 : shell_ptr->ref_faces( faces );
2028 [ # # ][ # # ]: 0 : pt_print_face_list( debug_flag, faces, trailing_string );
2029 : : }
2030 : 0 : }
2031 : :
2032 : 0 : void PartitionTool::notify_partition(
2033 : : DLIList<RefEntity*> & /*partitioning_entities*/,
2034 : : BasicTopologyEntity *first_partitioned_entity,
2035 : : BasicTopologyEntity *second_partitioned_entity,
2036 : : BasicTopologyEntity *old_entity )
2037 : : {
2038 : : int i;
2039 : :
2040 : : // are the first and second entities unique?
2041 : : int first_unique =
2042 [ # # ][ # # ]: 0 : first_partitioned_entity != old_entity &&
2043 : 0 : first_partitioned_entity != NULL;
2044 : :
2045 : : int second_unique =
2046 [ # # ]: 0 : second_partitioned_entity != first_partitioned_entity &&
2047 [ # # ][ # # ]: 0 : second_partitioned_entity != old_entity &&
2048 : 0 : second_partitioned_entity != NULL;
2049 : :
2050 : : // add unique entities to graphics
2051 : : // attach names to entities.
2052 [ # # ]: 0 : if ( first_unique )
2053 : : {
2054 : : RefEntityName::instance()
2055 [ # # ][ # # ]: 0 : ->copy_refentity_names( old_entity, first_partitioned_entity );
[ # # ][ # # ]
2056 : : }
2057 [ # # ]: 0 : if ( second_unique )
2058 : : {
2059 : : RefEntityName::instance()
2060 [ # # ][ # # ]: 0 : ->copy_refentity_names( old_entity, second_partitioned_entity );
[ # # ][ # # ]
2061 : : }
2062 : :
2063 : : // notify observers of this
2064 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::GEOMETRY_TOPOLOGY_MODIFIED, old_entity));
[ # # ][ # # ]
[ # # ]
2065 : :
2066 : : // notify containing entities
2067 : 0 : BasicTopologyEntity* entity_ptr = old_entity;
2068 [ # # ]: 0 : if( first_unique )
2069 : 0 : entity_ptr = first_partitioned_entity;
2070 [ # # ]: 0 : else if( second_unique )
2071 : 0 : entity_ptr = second_partitioned_entity;
2072 : :
2073 [ # # ]: 0 : DLIList<RefFace*> face_list;
2074 : : RefFace *ref_face;
2075 [ # # ][ # # ]: 0 : DLIList<RefVolume*> vol_list;
2076 : : RefVolume *ref_volume;
2077 [ # # ][ # # ]: 0 : DLIList<Body*> body_list;
2078 : : Body *body;
2079 [ # # ][ # # ]: 0 : DLIList<RefEdge*> ref_edges;
2080 [ # # ][ # # ]: 0 : DLIList<RefVertex*> ref_verts;
2081 : :
2082 : 0 : int has_parents = CUBIT_TRUE;
2083 [ # # ]: 0 : int dim = entity_ptr->dimension();
2084 [ # # # # ]: 0 : switch ( dim )
2085 : : {
2086 : : case 0:
2087 : : // ?
2088 : : // no break
2089 : : case 1:
2090 : : // does old_entity still have pointers to the ref_faces?
2091 [ # # ]: 0 : entity_ptr->ref_faces( face_list );
2092 [ # # ][ # # ]: 0 : if ( face_list.size() == 0 && dim == 1 )
[ # # ][ # # ]
2093 : 0 : has_parents = CUBIT_FALSE;
2094 [ # # ][ # # ]: 0 : for( i = face_list.size(); i > 0; i-- )
2095 : : {
2096 [ # # ]: 0 : ref_face = face_list.get_and_step();
2097 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_MODIFIED, ref_face));
[ # # ][ # # ]
[ # # ]
2098 : : }
2099 [ # # ]: 0 : if( first_partitioned_entity )
2100 [ # # ]: 0 : first_partitioned_entity->ref_vertices( ref_verts );
2101 [ # # ]: 0 : if( second_partitioned_entity )
2102 [ # # ]: 0 : second_partitioned_entity->ref_vertices( ref_verts );
2103 [ # # ][ # # ]: 0 : for( i=0; i<ref_verts.size(); i++ )
2104 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::VIRTUAL_STATUS_CHANGED, ref_verts[i]));
[ # # ][ # # ]
[ # # ][ # # ]
2105 : :
2106 : :
2107 : : // no break
2108 : : case 2:
2109 [ # # ]: 0 : entity_ptr->ref_volumes( vol_list );
2110 [ # # ][ # # ]: 0 : if ( vol_list.size() == 0 && dim == 2 )
[ # # ][ # # ]
2111 : 0 : has_parents = CUBIT_FALSE;
2112 [ # # ][ # # ]: 0 : for( i = vol_list.size(); i > 0; i-- )
2113 : : {
2114 [ # # ]: 0 : ref_volume = vol_list.get_and_step();
2115 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_MODIFIED, ref_volume));
[ # # ][ # # ]
[ # # ]
2116 : : }
2117 [ # # ]: 0 : if( first_partitioned_entity )
2118 : : {
2119 [ # # ]: 0 : first_partitioned_entity->ref_vertices( ref_verts );
2120 [ # # ]: 0 : first_partitioned_entity->ref_edges( ref_edges );
2121 : : }
2122 [ # # ]: 0 : if( second_partitioned_entity )
2123 : : {
2124 [ # # ]: 0 : second_partitioned_entity->ref_vertices( ref_verts );
2125 [ # # ]: 0 : second_partitioned_entity->ref_edges( ref_edges );
2126 : : }
2127 [ # # ][ # # ]: 0 : for( i=0; i<ref_verts.size(); i++ )
2128 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::VIRTUAL_STATUS_CHANGED, ref_verts[i]));
[ # # ][ # # ]
[ # # ][ # # ]
2129 [ # # ][ # # ]: 0 : for( i=0; i<ref_edges.size(); i++ )
2130 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::VIRTUAL_STATUS_CHANGED, ref_edges[i]));
[ # # ][ # # ]
[ # # ][ # # ]
2131 : :
2132 : : // no break
2133 : : case 3:
2134 [ # # ]: 0 : entity_ptr->bodies( body_list );
2135 [ # # ][ # # ]: 0 : if ( body_list.size() == 0 && dim == 3 )
[ # # ][ # # ]
2136 : 0 : has_parents = CUBIT_FALSE;
2137 [ # # ][ # # ]: 0 : for( i = body_list.size(); i > 0; i-- )
2138 : : {
2139 [ # # ]: 0 : body = body_list.get_and_step();
2140 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_MODIFIED, body));
[ # # ][ # # ]
[ # # ]
2141 : : }
2142 : 0 : break;
2143 : : default:
2144 : 0 : break;
2145 : : }
2146 : :
2147 [ # # ]: 0 : if( !has_parents )
2148 : : {
2149 : : // TODO -- should call GMT::make_free_RefEdge where appropriate or
2150 : : // GQE could be changed to recoginize it is making a free RefEdge.
2151 : : // When that is done, we no longer need these calls to the static observers.
2152 [ # # ]: 0 : if( second_unique )
2153 : : {
2154 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event( GeometryEvent(GeometryEvent::FREE_REF_ENTITY_GENERATED, second_partitioned_entity));
[ # # ][ # # ]
[ # # ]
2155 : : }
2156 [ # # ]: 0 : if( first_unique )
2157 : : {
2158 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event( GeometryEvent(GeometryEvent::FREE_REF_ENTITY_GENERATED, first_partitioned_entity));
[ # # ][ # # ]
[ # # ]
2159 : : }
2160 [ # # ]: 0 : }
2161 : :
2162 : 0 : }
2163 : :
2164 : : //-------------------------------------------------------------------------
2165 : : // Purpose : These are overloaded by PartitionToolMesh
2166 : : // to prevent un-partitioning where the mesh cannot
2167 : : // be updated.
2168 : : //
2169 : : // Special Notes :
2170 : : //
2171 : : // Creator : Jason Kraftcheck
2172 : : //
2173 : : // Creation Date : 03/12/03
2174 : : //-------------------------------------------------------------------------
2175 : 0 : CubitStatus PartitionTool::can_remove( RefVertex* ) { return CUBIT_SUCCESS; }
2176 : 0 : CubitStatus PartitionTool::can_remove( RefEdge* ) { return CUBIT_SUCCESS; }
2177 [ + - ][ + - ]: 6364 : CubitStatus PartitionTool::can_remove( RefFace* ) { return CUBIT_SUCCESS; }
|