Branch data Line data Source code
1 : : //-------------------------------------------------------------------------
2 : : // Filename : OffsetSplitTool.cpp
3 : : //
4 : : // Purpose :
5 : : //
6 : : // Split Surface <id_list> Offset Curve <id_list>
7 : : // Distance <val> [Segment <val>] [Partition] [Blunt] [Preview [Create]]
8 : : //
9 : : // Special Notes :
10 : : //
11 : : // Creator : Sam Showman
12 : : //
13 : : // Creation Date : 05/10/2005
14 : : //-------------------------------------------------------------------------
15 : : #include "OffsetSplitTool.hpp"
16 : : #include "AnalyticGeometryTool.hpp"
17 : : #include "RefFace.hpp"
18 : : #include "Point.hpp"
19 : : #include "Curve.hpp"
20 : : #include "CubitMessage.hpp"
21 : : #include "GeometryModifyTool.hpp"
22 : : #include "GeometryModifyEngine.hpp"
23 : : #include "GeometryQueryTool.hpp"
24 : : #include "CubitUtil.hpp"
25 : : #include "DLIList.hpp"
26 : : #include "GfxPreview.hpp"
27 : : #include "GMem.hpp"
28 : : #include "Curve.hpp"
29 : : #include "BodySM.hpp"
30 : : #include "TopologyBridge.hpp"
31 : : #include "Surface.hpp"
32 : : #include "CubitBox.hpp"
33 : :
34 : : // #define OFFSET_SPLIT_DEBUG
35 : :
36 : : double OffsetSplitTool::tolerance = .001;
37 : :
38 : 0 : OffsetSplitTool::OffsetSplitTool()
39 : : {
40 : 0 : }
41 : :
42 : 0 : CubitStatus OffsetSplitTool::split_surfaces_offset(DLIList<RefFace*> &ref_face_list,
43 : : DLIList<RefEdge*> &edge_list,
44 : : int num_segs,
45 : : double distance_in,
46 : : CubitBoolean divide_flg,
47 : : CubitBoolean blunt_flg,
48 : : CubitBoolean preview_flg,
49 : : CubitBoolean create_ref_edges_flg)
50 : : {
51 [ # # ]: 0 : ref_face_list.uniquify_unordered();
52 [ # # ]: 0 : edge_list.uniquify_unordered();
53 : :
54 : : // Check for valid number of segments
55 [ # # ]: 0 : if( num_segs < 1 )
56 : : {
57 [ # # ][ # # ]: 0 : PRINT_ERROR( "Number of specified segments must be >= 1\n" );
[ # # ][ # # ]
58 : 0 : return CUBIT_FAILURE;
59 : : }
60 : :
61 [ # # ][ # # ]: 0 : if(ref_face_list.size() < 1)
62 : : {
63 [ # # ][ # # ]: 0 : PRINT_ERROR( "No surfaces specified for splitting\n" );
[ # # ][ # # ]
64 : 0 : return CUBIT_FAILURE;
65 : : }
66 : :
67 [ # # ][ # # ]: 0 : if(edge_list.size() < 1)
68 : : {
69 [ # # ][ # # ]: 0 : PRINT_ERROR( "No curves specified for splitting\n" );
[ # # ][ # # ]
70 : 0 : return CUBIT_FAILURE;
71 : : }
72 : :
73 : : // clear the preview graphics
74 [ # # ]: 0 : GfxPreview::clear();
75 : :
76 [ # # ]: 0 : DLIList<Curve*> offset_curves;
77 [ # # ][ # # ]: 0 : DLIList<DLIList<Curve*>*> imprint_list;
78 [ # # ]: 0 : for(int seg = 1;seg<num_segs+1;seg++)
79 : : {
80 : : // set the current distance
81 : 0 : double distance = (distance_in/(double)num_segs)*(seg);
82 : :
83 : : // generate a swept body at each curve
84 [ # # ]: 0 : DLIList<BodySM*> body_list;
85 [ # # ][ # # ]: 0 : DLIList<TBPoint*> points;
[ # # ]
86 : 0 : GeometryModifyEngine* gme = 0;
87 : 0 : GeometryQueryEngine* gqe = 0;
88 [ # # ]: 0 : edge_list.reset();
89 : 0 : int i = 0;
90 [ # # ][ # # ]: 0 : for(i =edge_list.size();i--;)
91 : : {
92 [ # # ]: 0 : RefEdge* ref_edge = edge_list.get_and_step();
93 [ # # ]: 0 : Curve* cur_curve = ref_edge->get_curve_ptr();
94 : :
95 : : // add the curve to the class list of source curves
96 : : // will use this latter for dividing surfaces
97 [ # # ]: 0 : sourceCurves.append(cur_curve);
98 : :
99 [ # # ]: 0 : gqe = cur_curve->get_geometry_query_engine();
100 [ # # ][ # # ]: 0 : gme = GeometryModifyTool::instance()->get_engine(cur_curve);
101 [ # # ]: 0 : tolerance = gqe->get_sme_resabs_tolerance();
102 : :
103 [ # # ]: 0 : if(!gme)
104 : : {
105 [ # # ][ # # ]: 0 : PRINT_ERROR( "No ModifyEngine found!\n" );
[ # # ][ # # ]
106 : 0 : return CUBIT_FAILURE;
107 : : }
108 : :
109 [ # # ]: 0 : cur_curve->points(points);
110 [ # # ]: 0 : Curve* swept_curve = create_sweep_curve(cur_curve,distance,tolerance,CUBIT_TRUE);
111 [ # # ]: 0 : if(!swept_curve)
112 : : {
113 [ # # ][ # # ]: 0 : PRINT_WARNING("Failed to create offset geometry for curve %d.\n",ref_edge->id());
[ # # ][ # # ]
[ # # ]
114 : 0 : continue;
115 : : }
116 : :
117 [ # # ][ # # ]: 0 : CubitVector swpt_loc, source_loc;
118 [ # # ]: 0 : cur_curve->position_from_fraction(0.0,source_loc);
119 [ # # ]: 0 : swept_curve->position_from_fraction(0.0,swpt_loc);
120 : :
121 [ # # ]: 0 : CubitVector up_vector = swpt_loc-source_loc;
122 : :
123 [ # # ][ # # ]: 0 : Surface* section = create_sweep_section(cur_curve,distance,up_vector);
124 [ # # ]: 0 : if(!section)
125 : : {
126 [ # # ][ # # ]: 0 : PRINT_WARNING("Failed to create offset geometry for curve %d.\n",ref_edge->id());
[ # # ][ # # ]
[ # # ]
127 : : // delete the Curve path
128 [ # # ]: 0 : gqe->delete_solid_model_entities(swept_curve);
129 : 0 : continue;
130 : : }
131 : :
132 [ # # ]: 0 : BodySM* swept_body = create_sweep_body(section,swept_curve);
133 : :
134 : : // delete the Curve path and Surface section
135 [ # # ]: 0 : gqe->delete_solid_model_entities(swept_curve);
136 [ # # ]: 0 : if(!swept_body)
137 : : {
138 [ # # ][ # # ]: 0 : PRINT_WARNING("Failed to create offset geometry for curve %d.\n",ref_edge->id());
[ # # ][ # # ]
[ # # ]
139 : 0 : continue;
140 : : }
141 : :
142 [ # # ]: 0 : body_list.append(swept_body);
143 : : }
144 : :
145 [ # # ][ # # ]: 0 : if(body_list.size() == 0)
146 : : {
147 [ # # ][ # # ]: 0 : PRINT_ERROR("Failed to offset any curve.\n");
[ # # ][ # # ]
148 : 0 : return CUBIT_FAILURE;
149 : : }
150 : :
151 [ # # ][ # # ]: 0 : DLIList<TBPoint*> blunt_points;
[ # # ]
152 [ # # ]: 0 : if(blunt_flg == CUBIT_TRUE)
153 : : {
154 [ # # ][ # # ]: 0 : for(i = 0; i < points.size(); i++)
155 : : {
156 : 0 : bool remove_point = true;
157 [ # # ][ # # ]: 0 : CubitVector pnt_loc_0 = points[i]->coordinates();
158 : 0 : int j = 0;
159 [ # # ][ # # ]: 0 : for(j = 0;j < points.size(); j++)
160 : : {
161 [ # # ]: 0 : if(i==j)
162 : 0 : continue;
163 : :
164 [ # # ][ # # ]: 0 : if(points[j] == points[i])
[ # # ]
165 : : {
166 : 0 : remove_point = false;
167 : 0 : break;
168 : : }
169 : :
170 [ # # ][ # # ]: 0 : CubitVector pnt_loc_1 = points[j]->coordinates();
171 : :
172 [ # # ][ # # ]: 0 : if(pnt_loc_1.within_tolerance(pnt_loc_0,tolerance))
173 : : {
174 : 0 : remove_point = false;
175 : 0 : break;
176 : : }
177 : : }
178 [ # # ]: 0 : if(remove_point)
179 [ # # ][ # # ]: 0 : blunt_points.append(points[i]);
180 : : }
181 : : }
182 [ # # ]: 0 : points.uniquify_ordered();
183 [ # # ]: 0 : points -= blunt_points;
184 : :
185 [ # # ][ # # ]: 0 : for(i = points.size(); i--;)
186 : : {
187 [ # # ]: 0 : BodySM* shpere_body = gme->sphere(distance);
188 [ # # ][ # # ]: 0 : CubitVector trans_dist = points.get_and_step()->coordinates();
189 [ # # ]: 0 : gqe->translate(shpere_body,trans_dist);
190 [ # # ]: 0 : body_list.append(shpere_body);
191 : : }
192 : :
193 : : // create the offset geometry for debuging
194 : : #ifdef OFFSET_SPLIT_DEBUG
195 : : for(i=body_list.size();i--;)
196 : : {
197 : : GeometryQueryTool::instance()->make_Body(
198 : : gme->copy_body(body_list.get_and_step()));
199 : : }
200 : : #endif
201 : :
202 [ # # ][ # # ]: 0 : DLIList<BodySM*> united_body_list;
[ # # ]
203 [ # # ][ # # ]: 0 : if(body_list.size() == 1)
204 [ # # ]: 0 : united_body_list = body_list;
205 : : else
206 : : {
207 [ # # ][ # # ]: 0 : if(!gme->unite(body_list,united_body_list))//united_body_list))
208 : : {
209 [ # # ][ # # ]: 0 : if(body_list.size() == 1)
210 [ # # ][ # # ]: 0 : PRINT_ERROR( "Offset split failed at the unite step.\n" );
[ # # ][ # # ]
211 : : else
212 [ # # ][ # # ]: 0 : PRINT_ERROR( "Offset split failed at the unite step. Try reducing the curve count\n" );
[ # # ][ # # ]
213 : :
214 : : // delete the solid bodies
215 [ # # ][ # # ]: 0 : for(i = body_list.size(); i--;)
216 [ # # ][ # # ]: 0 : gqe->delete_solid_model_entities(body_list.get_and_step());
217 : :
218 : 0 : return CUBIT_FAILURE;
219 : : }
220 : : }
221 : :
222 : : // get the surfaces contained in the body
223 [ # # ][ # # ]: 0 : DLIList<Surface*> surface_united_list;
[ # # ][ # # ]
224 [ # # ][ # # ]: 0 : for(i = united_body_list.size(); i--;)
225 : : {
226 [ # # ]: 0 : BodySM* cur_body = united_body_list.get_and_step();
227 [ # # ]: 0 : cur_body->surfaces(surface_united_list);
228 : : }
229 : :
230 [ # # ]: 0 : ref_face_list.reset();
231 [ # # ]: 0 : imprint_list.reset();
232 [ # # ][ # # ]: 0 : for(i = ref_face_list.size(); i--;)
233 : : {
234 [ # # ][ # # ]: 0 : Surface* surf_1 = ref_face_list.get_and_step()->get_surface_ptr();
235 [ # # ]: 0 : DLIList<Curve*> cur_curves;
236 [ # # ][ # # ]: 0 : for(int j = surface_united_list.size(); j--;)
237 : : {
238 [ # # ]: 0 : DLIList<Curve*> intersection_curves;
239 [ # # ]: 0 : Surface* surf_2 = surface_united_list.get_and_step();
240 [ # # ]: 0 : gme->surface_intersection(surf_1,surf_2,intersection_curves,0.0);
241 : :
242 : : // remove any very small curves from the intersection graph
243 : : // for some reason seems to return zero length curves
244 [ # # ][ # # ]: 0 : for(int k = intersection_curves.size();k--;)
245 : : {
246 [ # # ]: 0 : Curve* cur_curve = intersection_curves[k];
247 : : double len = cur_curve->
248 [ # # ][ # # ]: 0 : length_from_u(cur_curve->start_param(),cur_curve->end_param());
[ # # ]
249 : :
250 [ # # ]: 0 : if(fabs(len) < tolerance)
251 : : {
252 [ # # ]: 0 : intersection_curves.remove(cur_curve);
253 [ # # ]: 0 : gqe->delete_solid_model_entities(cur_curve);
254 : : }
255 : : }
256 : :
257 : : // do the division if the user asks for it
258 [ # # ][ # # ]: 0 : if(divide_flg &&
259 [ # # ]: 0 : num_segs == seg &&
260 : : // skip the curves created by sphere surfaces
261 [ # # ][ # # ]: 0 : surf_2->geometry_type() != SPHERE_SURFACE_TYPE &&
[ # # ]
262 [ # # ]: 0 : surf_2->geometry_type() != PLANE_SURFACE_TYPE)
263 : : {
264 [ # # ][ # # ]: 0 : intersection_curves +=
265 [ # # ]: 0 : this->create_divide_curves(intersection_curves,surf_1,distance);
266 : : }
267 : :
268 [ # # ]: 0 : cur_curves += intersection_curves;
269 [ # # ]: 0 : }
270 : 0 : DLIList<Curve*>* surf_inter_list = 0;
271 : :
272 [ # # ][ # # ]: 0 : if(ref_face_list.size() > imprint_list.size())
[ # # ]
273 : : {
274 [ # # ][ # # ]: 0 : surf_inter_list = new DLIList<Curve*>;
275 [ # # ]: 0 : imprint_list.append(surf_inter_list);
276 : : }
277 : : else
278 [ # # ]: 0 : surf_inter_list = imprint_list.get_and_step();
279 : :
280 [ # # ]: 0 : (*surf_inter_list) += cur_curves;
281 [ # # ]: 0 : offset_curves += cur_curves;
282 : :
283 : : // draw the preview as the offset curves are being calculated
284 [ # # ][ # # ]: 0 : if(preview_flg && !create_ref_edges_flg)
285 [ # # ]: 0 : draw_preview(cur_curves);
286 [ # # ]: 0 : }
287 : :
288 : : // delete the solid bodies
289 [ # # ][ # # ]: 0 : for(i = united_body_list.size(); i--;)
290 [ # # ][ # # ]: 0 : gqe->delete_solid_model_entities(united_body_list.get_and_step());
291 : 0 : }
292 : :
293 : : // ok, now do the imprint or preview
294 [ # # ]: 0 : if(preview_flg)
295 : : {
296 [ # # ]: 0 : if(!create_ref_edges_flg)
297 : : {
298 : : //Delete the Curve entities
299 [ # # ][ # # ]: 0 : for(int i=0;i<offset_curves.size();i++)
300 : : {
301 [ # # ]: 0 : Curve* cur_curve = offset_curves.get_and_step();
302 [ # # ]: 0 : cur_curve->get_geometry_query_engine()->
303 [ # # ]: 0 : delete_solid_model_entities(cur_curve);
304 : : }
305 : : }
306 : : else
307 : : {
308 [ # # ]: 0 : create_ref_edges(offset_curves);
309 : : }
310 : :
311 : : // delete the list that contained the curves that would have been imprinted
312 [ # # ][ # # ]: 0 : for(int i= imprint_list.size();i--;)
313 [ # # ][ # # ]: 0 : delete imprint_list.get_and_step();
[ # # ]
314 : : }
315 : : // Imprint
316 : : else
317 : : {
318 : 0 : int i = 0;
319 [ # # ]: 0 : ref_face_list.reset();
320 [ # # ]: 0 : DLIList<Surface*> surface_list;
321 [ # # ][ # # ]: 0 : for( i = ref_face_list.size(); i--;)
322 [ # # ][ # # ]: 0 : surface_list.append(ref_face_list.get_and_step()->get_surface_ptr());
[ # # ]
323 : :
324 : : Body *new_body_ptr;
325 [ # # ]: 0 : if( GeometryModifyTool::instance()->imprint( surface_list,
326 [ # # ][ # # ]: 0 : imprint_list, new_body_ptr, false, false ) == CUBIT_FAILURE )
327 : : {
328 : : //Delete the Curve entities
329 [ # # ][ # # ]: 0 : for(i= offset_curves.size();i--;)
330 : : {
331 [ # # ]: 0 : Curve* cur_curve = offset_curves.get_and_step();
332 [ # # ]: 0 : cur_curve->get_geometry_query_engine()->
333 [ # # ]: 0 : delete_solid_model_entities(cur_curve);
334 : : }
335 : :
336 : : // delete the curves that would have been imprinted
337 [ # # ][ # # ]: 0 : for( i= imprint_list.size();i--;)
338 [ # # ][ # # ]: 0 : delete imprint_list.get_and_step();
[ # # ]
339 : :
340 : 0 : return CUBIT_FAILURE;
341 : : }
342 : :
343 : : //Delete the Curve entities
344 [ # # ][ # # ]: 0 : for( i= offset_curves.size();i--;)
345 : : {
346 [ # # ]: 0 : Curve* cur_curve = offset_curves.get_and_step();
347 [ # # ]: 0 : cur_curve->get_geometry_query_engine()->
348 [ # # ]: 0 : delete_solid_model_entities(cur_curve);
349 : : }
350 : :
351 : : // delete the curves that were used for imprinted
352 [ # # ][ # # ]: 0 : for( i= imprint_list.size();i--;)
[ # # ][ # # ]
353 [ # # ][ # # ]: 0 : delete imprint_list.get_and_step();
[ # # ]
354 : : }
355 : :
356 [ # # ]: 0 : return CUBIT_SUCCESS;
357 : : }
358 : :
359 : : //- Begin Private Functions
360 : 0 : CubitStatus OffsetSplitTool::draw_preview(
361 : : DLIList<Curve*> &curve_list,
362 : : int color )
363 : : {
364 : : int i;
365 : : Curve *curve_ptr;
366 : 0 : curve_list.reset();
367 [ # # ]: 0 : for( i=curve_list.size(); i--; )
368 : : {
369 : 0 : curve_ptr = curve_list.get_and_step();
370 : 0 : draw_preview( curve_ptr, CUBIT_FALSE, color );
371 : : }
372 : :
373 : 0 : GfxPreview::flush();
374 : :
375 : 0 : return CUBIT_SUCCESS;
376 : : }
377 : :
378 : 0 : CubitStatus OffsetSplitTool::draw_preview(
379 : : Curve *curve_ptr,
380 : : CubitBoolean flush,
381 : : int color )
382 : : {
383 : : CubitStatus result;
384 [ # # ]: 0 : GMem g_mem;
385 : :
386 : : // get the graphics
387 [ # # ]: 0 : result = curve_ptr->get_geometry_query_engine()->
388 [ # # ]: 0 : get_graphics( curve_ptr, &g_mem );
389 : :
390 [ # # ][ # # ]: 0 : if (result==CUBIT_FAILURE || g_mem.pointListCount == 0)
391 : : {
392 [ # # ][ # # ]: 0 : PRINT_WARNING("Unable to preview a curve\n" );;
[ # # ][ # # ]
393 : : double len = curve_ptr->
394 [ # # ][ # # ]: 0 : length_from_u(curve_ptr->start_param(),curve_ptr->end_param());
[ # # ]
395 : :
396 [ # # ][ # # ]: 0 : PRINT_WARNING("Curve len: %f\n",len);
[ # # ][ # # ]
397 : : }
398 : :
399 : : // Draw the polyline
400 [ # # ][ # # ]: 0 : GfxPreview::draw_polyline( g_mem.point_list(), g_mem.pointListCount, color );
401 [ # # ]: 0 : if( flush )
402 [ # # ]: 0 : GfxPreview::flush();
403 : :
404 [ # # ]: 0 : return CUBIT_SUCCESS;
405 : : }
406 : :
407 : :
408 : 0 : Curve *OffsetSplitTool::create_sweep_curve(
409 : : Curve *curve_in,
410 : : double distance,
411 : : double chord_tol,
412 : : CubitBoolean iterate)
413 : : {
414 : : GeometryModifyEngine* gme =
415 [ # # ][ # # ]: 0 : GeometryModifyTool::instance()->get_engine( curve_in );
416 [ # # ]: 0 : GeometryQueryEngine* gqe = curve_in->get_geometry_query_engine();
417 : :
418 [ # # ]: 0 : CubitVector start_pos;
419 [ # # ]: 0 : CubitVector end_pos;
420 [ # # ]: 0 : CubitVector dummy_pos;
421 [ # # ]: 0 : CubitVector x_axis;
422 [ # # ]: 0 : CubitVector y_axis;
423 [ # # ]: 0 : CubitVector z_axis;
424 [ # # ]: 0 : CubitVector curvature;
425 : :
426 [ # # ][ # # ]: 0 : if(!curve_in->position_from_fraction(0.0,start_pos))
427 : 0 : return 0;
428 : :
429 [ # # ][ # # ]: 0 : if(!curve_in->position_from_fraction(1.0,end_pos))
430 : 0 : return 0;
431 : :
432 [ # # ]: 0 : curve_in->closest_point(start_pos,dummy_pos,&z_axis,&curvature);
433 : :
434 : : // check to see if the curve is planar
435 : 0 : CubitBoolean is_planar = CUBIT_FALSE;
436 [ # # ]: 0 : DLIList<Surface*> attached_surfs;
437 [ # # ]: 0 : curve_in->surfaces(attached_surfs);
438 : 0 : int i = 0;
439 [ # # ][ # # ]: 0 : for(i = 0;i < attached_surfs.size();i++)
440 : : {
441 [ # # ]: 0 : Surface* cur_surf = attached_surfs.get_and_step();
442 [ # # ][ # # ]: 0 : if(cur_surf &&
[ # # ]
443 [ # # ]: 0 : cur_surf->geometry_type() == PLANE_SURFACE_TYPE)
444 : : {
445 [ # # ]: 0 : CubitVector center_vec;
446 [ # # ]: 0 : cur_surf->get_point_normal(center_vec,x_axis);
447 : 0 : is_planar = CUBIT_TRUE;
448 : 0 : break;
449 : : }
450 : : }
451 : :
452 [ # # ]: 0 : if(is_planar)
453 : : {
454 [ # # ][ # # ]: 0 : y_axis = z_axis*x_axis;
455 : : }
456 : : // If curvature is significant, use it to create the sweep coordinate system
457 [ # # ][ # # ]: 0 : else if(curvature.length() < CUBIT_DBL_MIN)
458 : : {
459 [ # # ]: 0 : z_axis.orthogonal_vectors(x_axis,y_axis);
460 : : }
461 : : else
462 : : {
463 [ # # ]: 0 : y_axis = curvature;
464 [ # # ][ # # ]: 0 : x_axis = z_axis*y_axis;
465 : : }
466 : :
467 [ # # ]: 0 : x_axis.normalize();
468 [ # # ]: 0 : y_axis.normalize();
469 [ # # ]: 0 : z_axis.normalize();
470 [ # # ]: 0 : x_axis *=distance;
471 : :
472 [ # # ]: 0 : GeometryType geom_type = curve_in->geometry_type();
473 [ # # ]: 0 : if(geom_type == STRAIGHT_CURVE_TYPE) // if the curve is a line just offset it
474 : : {
475 : : // has problems calculating the intersection curves of surface edges and surfaces
476 : : // so rotate the coordinate system to some angle that is less likely to be used
477 [ # # ]: 0 : x_axis.normalize();
478 [ # # ]: 0 : y_axis.normalize();
479 [ # # ]: 0 : CubitVector move_vec = y_axis - x_axis;
480 [ # # ][ # # ]: 0 : y_axis = y_axis+(move_vec*.744561789854);
[ # # ]
481 [ # # ][ # # ]: 0 : x_axis = z_axis*y_axis;
482 : :
483 [ # # ]: 0 : x_axis.normalize();
484 [ # # ]: 0 : y_axis.normalize();
485 [ # # ]: 0 : z_axis.normalize();
486 [ # # ]: 0 : x_axis *=distance;
487 : :
488 : : // just offset the curve
489 [ # # ]: 0 : Curve* offset_curve = gme->make_Curve(curve_in);
490 [ # # ]: 0 : gqe->translate(offset_curve,x_axis);
491 : 0 : return offset_curve;
492 : : }
493 [ # # ][ # # ]: 0 : else if(geom_type == ARC_CURVE_TYPE ||
494 [ # # ]: 0 : geom_type == ELLIPSE_CURVE_TYPE ||
495 : : is_planar) // if the curve is a arc just offset it
496 : : {
497 : : // just offset the curve
498 [ # # ]: 0 : Curve* offset_curve = gme->make_Curve(curve_in);
499 [ # # ]: 0 : gqe->translate(offset_curve,x_axis);
500 : 0 : return offset_curve;
501 : : }
502 : :
503 [ # # ][ # # ]: 0 : DLIList<CubitVector*> pnt_list;
504 [ # # ][ # # ]: 0 : CubitVector* loc_0 = new CubitVector(start_pos);
505 [ # # ][ # # ]: 0 : CubitVector* loc_1 = new CubitVector(end_pos);
506 [ # # ]: 0 : pnt_list.append(loc_0);
507 [ # # ]: 0 : pnt_list.append(loc_1);
508 [ # # ][ # # ]: 0 : DLIList<double> frac_list;
509 [ # # ]: 0 : frac_list.append(0.0);
510 [ # # ]: 0 : frac_list.append(1.0);
511 [ # # ]: 0 : frac_list.reset();
512 : :
513 : : // create the curve points with a maximum deviation of 'chord_tol'
514 : : while(1)
515 : : {
516 [ # # ]: 0 : double frac_0 = frac_list.get_and_step();
517 [ # # ]: 0 : double frac_1 = frac_list.get();
518 [ # # ]: 0 : pnt_list.step();
519 : :
520 [ # # ]: 0 : if(frac_0>frac_1)
521 : 0 : break;
522 : :
523 [ # # ]: 0 : CubitVector tmp_pos_0;
524 [ # # ]: 0 : curve_in->position_from_fraction(frac_0,tmp_pos_0);
525 [ # # ]: 0 : CubitVector tmp_pos_1;
526 [ # # ]: 0 : curve_in->position_from_fraction(frac_1,tmp_pos_1);
527 [ # # ][ # # ]: 0 : CubitVector tmp_pos_2 = (tmp_pos_0+tmp_pos_1)/2.0;
528 [ # # ]: 0 : CubitVector tmp_pos_3;
529 : 0 : double mid_frac = (frac_0+frac_1)/2.0;
530 [ # # ]: 0 : curve_in->position_from_fraction(mid_frac,tmp_pos_3);
531 : :
532 [ # # ][ # # ]: 0 : if(tmp_pos_3.distance_between(tmp_pos_2) > chord_tol)
533 : : {
534 [ # # ][ # # ]: 0 : CubitVector* loc = new CubitVector(tmp_pos_3);
535 [ # # ]: 0 : pnt_list.back();
536 [ # # ]: 0 : frac_list.back();
537 [ # # ]: 0 : pnt_list.insert(loc);
538 [ # # ]: 0 : frac_list.insert(mid_frac);
539 [ # # ]: 0 : pnt_list.back();
540 [ # # ]: 0 : frac_list.back();
541 : : }
542 : : }
543 : :
544 : : // generate the offset curve points
545 [ # # ]: 0 : CubitVector last_vec = x_axis;
546 [ # # ]: 0 : pnt_list.reset();
547 [ # # ][ # # ]: 0 : for(i = 0;i < pnt_list.size();i++)
548 : : {
549 [ # # ][ # # ]: 0 : CubitVector curv,tangent,dummy;
[ # # ]
550 [ # # ]: 0 : CubitVector *cur_pnt = pnt_list.get_and_step();
551 [ # # ]: 0 : curve_in->closest_point(*cur_pnt,dummy,&tangent,&curv);
552 : :
553 : : // if the radius of curvature is smaller than the distance of the
554 : : // sweep offset then return a NULL curve
555 [ # # ][ # # ]: 0 : if(curvature.length()> CUBIT_DBL_MIN &&
[ # # ][ # # ]
556 [ # # ]: 0 : 1.0/(curv.length()) <= distance)
557 : : {
558 : : // clean out the points
559 [ # # ][ # # ]: 0 : for(int i =pnt_list.size();i--;)
560 [ # # ]: 0 : delete pnt_list.get_and_step();
561 : :
562 [ # # ][ # # ]: 0 : PRINT_WARNING("Radius of curvature is smaller than or equal to %f.\n"
[ # # ]
563 [ # # ]: 0 : "Cannot offset curve.\n",distance);
564 : 0 : return 0;
565 : : }
566 : :
567 [ # # ]: 0 : CubitVector up_vec = tangent*last_vec;
568 [ # # ]: 0 : CubitVector offset_vec = up_vec*tangent;
569 [ # # ]: 0 : offset_vec.normalize();
570 [ # # ]: 0 : offset_vec *= distance;
571 [ # # ][ # # ]: 0 : cur_pnt->set(*cur_pnt + offset_vec);
572 [ # # ]: 0 : last_vec = offset_vec;
573 : : }
574 : :
575 : : // create a spline sweep path
576 [ # # ]: 0 : pnt_list.reset();
577 [ # # ][ # # ]: 0 : TBPoint* start_point = gme->make_Point(*(pnt_list.get_and_back()));
578 [ # # ][ # # ]: 0 : TBPoint* end_point = gme->make_Point(*(pnt_list.get_and_step()));
579 : :
580 : : // Create the curve
581 : :
582 : : Curve* curve_out =
583 : : gme->make_Curve(
584 : : SPLINE_CURVE_TYPE,
585 [ # # ]: 0 : start_point,end_point,pnt_list);
586 : :
587 [ # # ]: 0 : pnt_list.reset();
588 [ # # ][ # # ]: 0 : for(i =pnt_list.size();i--;)
589 [ # # ]: 0 : delete pnt_list.get_and_step();
590 : :
591 [ # # ]: 0 : pnt_list.clean_out();
592 [ # # ]: 0 : return curve_out;
593 : : }
594 : :
595 : :
596 : 0 : Surface* OffsetSplitTool::create_sweep_section(
597 : : Curve* path,
598 : : double distance,
599 : : CubitVector up_vector,
600 : : double fraction)
601 : : {
602 [ # # ]: 0 : up_vector.normalize();
603 : : GeometryModifyEngine* gme =
604 [ # # ][ # # ]: 0 : GeometryModifyTool::instance()->get_engine( path );
605 : :
606 [ # # ]: 0 : CubitVector start_pos;
607 [ # # ]: 0 : CubitVector dummy_pos;
608 [ # # ]: 0 : CubitVector x_axis;
609 [ # # ]: 0 : CubitVector y_axis;
610 [ # # ]: 0 : CubitVector z_axis;
611 [ # # ][ # # ]: 0 : if(!path->position_from_fraction(fraction,start_pos))
612 : 0 : return 0;
613 : :
614 [ # # ]: 0 : path->closest_point(start_pos,dummy_pos,&z_axis);
615 [ # # ][ # # ]: 0 : y_axis = z_axis*up_vector;
616 [ # # ]: 0 : x_axis = up_vector;
617 : :
618 [ # # ]: 0 : x_axis.normalize();
619 [ # # ]: 0 : y_axis.normalize();
620 [ # # ]: 0 : z_axis.normalize();
621 : :
622 [ # # ][ # # ]: 0 : TBPoint* start_point = gme->make_Point(start_pos+x_axis);
623 [ # # ][ # # ]: 0 : TBPoint* end_point = gme->make_Point(start_pos-x_axis);
624 [ # # ]: 0 : TBPoint* center_point = gme->make_Point(start_pos);
625 : :
626 : : Curve* arc_curve_0 =
627 [ # # ]: 0 : gme->create_arc_center_edge(center_point,start_point,end_point,z_axis,distance);
628 : :
629 [ # # ][ # # ]: 0 : start_point = gme->make_Point(start_pos+x_axis);
630 [ # # ][ # # ]: 0 : end_point = gme->make_Point(start_pos-x_axis);
631 [ # # ]: 0 : center_point = gme->make_Point(start_pos);
632 : :
633 : : Curve* arc_curve_1 =
634 [ # # ][ # # ]: 0 : gme->create_arc_center_edge(center_point,start_point,end_point,-z_axis,distance);
635 : :
636 [ # # ]: 0 : DLIList<Curve*> curve_list;
637 [ # # ]: 0 : curve_list.append(arc_curve_0);
638 [ # # ]: 0 : curve_list.append(arc_curve_1);
639 : :
640 : : Surface* surf_out =
641 [ # # ]: 0 : gme->make_Surface(PLANE_SURFACE_TYPE,curve_list,0,false);
642 : :
643 [ # # ]: 0 : return surf_out;
644 : : }
645 : :
646 : 0 : BodySM* OffsetSplitTool::create_sweep_body(
647 : : Surface* section,
648 : : Curve* path)
649 : : {
650 : : GeometryModifyEngine* gme =
651 [ # # ][ # # ]: 0 : GeometryModifyTool::instance()->get_engine( section );
652 : :
653 [ # # ]: 0 : DLIList<GeometryEntity*> ent_list;
654 [ # # ]: 0 : ent_list.append(section);
655 [ # # ][ # # ]: 0 : DLIList<BodySM*> body_list;
656 [ # # ][ # # ]: 0 : DLIList<Curve*> path_list;
657 [ # # ]: 0 : path_list.append(path);
658 : :
659 : : gme->sweep_along_curve(ent_list,body_list,path_list, 0.0, 0,
660 [ # # ]: 0 : CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE);
661 : :
662 [ # # ][ # # ]: 0 : if(body_list.size())
663 [ # # ]: 0 : return body_list.get();
664 : :
665 [ # # ]: 0 : return 0;
666 : : }
667 : :
668 : 0 : CubitStatus OffsetSplitTool::create_ref_edges(
669 : : DLIList<Curve*> &curve_list )
670 : : {
671 : : int i;
672 : : Curve *curve_ptr;
673 : 0 : curve_list.reset();
674 [ # # ]: 0 : for( i=curve_list.size(); i--; )
675 : : {
676 : 0 : curve_ptr = curve_list.get_and_step();
677 : 0 : GeometryQueryTool::instance()->make_free_RefEdge(curve_ptr);
678 : : }
679 : 0 : return CUBIT_SUCCESS;
680 : : }
681 : :
682 : 0 : DLIList<Curve*> OffsetSplitTool::create_divide_curves(
683 : : DLIList<Curve*> &curve_list,
684 : : Surface* target_surface,
685 : : double distance)
686 : : {
687 : 0 : DLIList<Curve*> return_list;
688 [ # # ]: 0 : curve_list.reset();
689 [ # # ]: 0 : int curve_list_size = curve_list.size();
690 [ # # ]: 0 : for(int i = curve_list_size; i--;)
691 : : {
692 [ # # ]: 0 : Curve* cur_curve = curve_list.get_and_step();
693 : : GeometryModifyEngine* gme =
694 [ # # ][ # # ]: 0 : GeometryModifyTool::instance()->get_engine( cur_curve );
695 : : GeometryQueryEngine* gqe =
696 [ # # ]: 0 : cur_curve->get_geometry_query_engine();
697 : :
698 : : // Find the matching source curve.
699 : : // there are better ways to do this such as using the surface
700 : : // arc intersection but that only seems to work for one engine or another
701 : : // not both
702 [ # # ][ # # ]: 0 : for(int j = sourceCurves.size(); j--;)
703 : : {
704 [ # # ]: 0 : Curve* source_curve = sourceCurves.get_and_step();
705 [ # # ]: 0 : CubitVector coord1;
706 [ # # ]: 0 : CubitVector coord2;
707 : 0 : double distance_out = 0.0;
708 [ # # ]: 0 : if(!gqe->entity_entity_distance( source_curve, cur_curve,
709 [ # # ]: 0 : coord1, coord2, distance_out ))
710 : 0 : continue;
711 : :
712 [ # # ]: 0 : if(fabs(distance_out-distance) < tolerance)
713 : : {
714 : : // check three points
715 [ # # ]: 0 : CubitVector pnt_0;
716 [ # # ]: 0 : CubitVector pnt_1;
717 [ # # ]: 0 : CubitVector pnt_2;
718 [ # # ]: 0 : CubitVector pnt_3;
719 [ # # ]: 0 : CubitVector pnt_4;
720 [ # # ]: 0 : CubitVector pnt_5;
721 [ # # ]: 0 : cur_curve->position_from_fraction(0.0,pnt_0);
722 [ # # ]: 0 : source_curve->closest_point(pnt_0,pnt_1);
723 [ # # ]: 0 : cur_curve->position_from_fraction(0.5,pnt_2);
724 [ # # ]: 0 : source_curve->closest_point(pnt_2,pnt_3);
725 [ # # ]: 0 : cur_curve->position_from_fraction(1.0,pnt_4);
726 [ # # ]: 0 : source_curve->closest_point(pnt_4,pnt_5);
727 : :
728 [ # # ][ # # ]: 0 : if(fabs(pnt_0.distance_between(pnt_1) - distance) < tolerance &&
[ # # ]
729 [ # # ][ # # ]: 0 : fabs(pnt_2.distance_between(pnt_3) - distance) < tolerance &&
[ # # ]
730 [ # # ]: 0 : fabs(pnt_4.distance_between(pnt_5) - distance) < tolerance)
731 : : {
732 : : // ok now just create curves between each end of the surface intersection curves
733 : : // and the projection to the source curves
734 : :
735 : : // first curve
736 [ # # ]: 0 : TBPoint* start_point_0 = gme->make_Point(pnt_0);
737 [ # # ]: 0 : TBPoint* end_point_0 = gme->make_Point(pnt_1);
738 [ # # ]: 0 : CubitVector vert3_coord_0 = start_point_0->coordinates();
739 : :
740 : : Curve* new_curve_0 =
741 : : gme->make_Curve(STRAIGHT_CURVE_TYPE,
742 [ # # ]: 0 : start_point_0,end_point_0,&vert3_coord_0 );
743 : :
744 : : // second curve
745 [ # # ]: 0 : TBPoint* start_point_1 = gme->make_Point(pnt_4);
746 [ # # ]: 0 : TBPoint* end_point_1 = gme->make_Point(pnt_5);
747 [ # # ]: 0 : CubitVector vert3_coord_1 = start_point_1->coordinates();
748 : :
749 : : Curve* new_curve_1 =
750 : : gme->make_Curve(STRAIGHT_CURVE_TYPE,
751 [ # # ]: 0 : start_point_1,end_point_1,&vert3_coord_1 );
752 : :
753 : : // if the target surface is not a plane then do a projection
754 [ # # ][ # # ]: 0 : if(target_surface->geometry_type() != PLANE_SURFACE_TYPE)
755 : : {
756 [ # # ]: 0 : DLIList<Curve*> curves_in;
757 : :
758 [ # # ]: 0 : if(new_curve_0)
759 [ # # ]: 0 : curves_in.append(new_curve_0);
760 : :
761 [ # # ]: 0 : if(new_curve_1)
762 [ # # ]: 0 : curves_in.append(new_curve_1);
763 : :
764 [ # # ][ # # ]: 0 : DLIList<Curve*> curves_out;
765 [ # # ][ # # ]: 0 : DLIList<Surface*> surface_in;
766 [ # # ]: 0 : surface_in.append(target_surface);
767 [ # # ][ # # ]: 0 : if(gme->project_edges(surface_in,curves_in,curves_out))
768 [ # # ][ # # ]: 0 : return_list += curves_out; // add the curves to the return list
769 : : }
770 : : else // add the curves to the return list
771 : : {
772 [ # # ]: 0 : if(new_curve_0)
773 [ # # ]: 0 : return_list.append(new_curve_0);
774 : :
775 [ # # ]: 0 : if(new_curve_1)
776 [ # # ]: 0 : return_list.append(new_curve_1);
777 : : }
778 : : }
779 : : }
780 : : }
781 : : }
782 : 0 : return return_list;
783 [ + - ][ + - ]: 6540 : }
|