cgma
OffsetSplitTool.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : OffsetSplitTool.cpp
00003 //
00004 // Purpose       :
00005 //
00006 //   Split Surface <id_list> Offset Curve <id_list>
00007 //       Distance <val> [Segment <val>] [Partition] [Blunt] [Preview [Create]]
00008 //
00009 // Special Notes :
00010 //
00011 // Creator       : Sam Showman
00012 //
00013 // Creation Date : 05/10/2005
00014 //-------------------------------------------------------------------------
00015 #include "OffsetSplitTool.hpp"
00016 #include "AnalyticGeometryTool.hpp"
00017 #include "RefFace.hpp"
00018 #include "Point.hpp"
00019 #include "Curve.hpp"
00020 #include "CubitMessage.hpp"
00021 #include "GeometryModifyTool.hpp"
00022 #include "GeometryModifyEngine.hpp"
00023 #include "GeometryQueryTool.hpp"
00024 #include "CubitUtil.hpp"
00025 #include "DLIList.hpp"
00026 #include "GfxPreview.hpp"
00027 #include "GMem.hpp"
00028 #include "Curve.hpp"
00029 #include "BodySM.hpp"
00030 #include "TopologyBridge.hpp"
00031 #include "Surface.hpp"
00032 #include "CubitBox.hpp"
00033 
00034 // #define OFFSET_SPLIT_DEBUG
00035 
00036 double OffsetSplitTool::tolerance = .001;
00037 
00038 OffsetSplitTool::OffsetSplitTool()
00039 {
00040 }
00041 
00042 CubitStatus OffsetSplitTool::split_surfaces_offset(DLIList<RefFace*> &ref_face_list,
00043                                                    DLIList<RefEdge*> &edge_list,
00044                                                    int num_segs,
00045                                                    double distance_in,
00046                                                    CubitBoolean divide_flg,
00047                                                    CubitBoolean blunt_flg,
00048                                                    CubitBoolean preview_flg,
00049                                                    CubitBoolean create_ref_edges_flg)
00050 {
00051     ref_face_list.uniquify_unordered();
00052     edge_list.uniquify_unordered();
00053 
00054     // Check for valid number of segments
00055     if( num_segs < 1 )
00056     {
00057         PRINT_ERROR( "Number of specified segments must be >= 1\n" );
00058         return CUBIT_FAILURE;
00059     }
00060 
00061     if(ref_face_list.size() < 1)
00062     {
00063         PRINT_ERROR( "No surfaces specified for splitting\n" );
00064         return CUBIT_FAILURE;
00065     }
00066 
00067     if(edge_list.size() < 1)
00068     {
00069         PRINT_ERROR( "No curves specified for splitting\n" );
00070         return CUBIT_FAILURE;
00071     }
00072 
00073     // clear the preview graphics
00074     GfxPreview::clear();
00075 
00076     DLIList<Curve*> offset_curves;
00077     DLIList<DLIList<Curve*>*> imprint_list;
00078     for(int seg = 1;seg<num_segs+1;seg++)
00079     {
00080         // set the current distance
00081         double distance = (distance_in/(double)num_segs)*(seg);
00082 
00083         // generate a swept body at each curve
00084         DLIList<BodySM*> body_list;
00085         DLIList<TBPoint*> points;
00086         GeometryModifyEngine* gme = 0;
00087         GeometryQueryEngine* gqe = 0;
00088         edge_list.reset();
00089         int i = 0;
00090         for(i =edge_list.size();i--;)
00091         {
00092             RefEdge* ref_edge = edge_list.get_and_step();
00093             Curve* cur_curve = ref_edge->get_curve_ptr();
00094 
00095             // add the curve to the class list of source curves
00096             // will use this latter for dividing surfaces
00097             sourceCurves.append(cur_curve);
00098 
00099             gqe = cur_curve->get_geometry_query_engine();
00100             gme = GeometryModifyTool::instance()->get_engine(cur_curve);
00101             tolerance = gqe->get_sme_resabs_tolerance();
00102 
00103             if(!gme)
00104             {
00105                 PRINT_ERROR( "No ModifyEngine found!\n" );
00106                 return CUBIT_FAILURE;
00107             }
00108 
00109             cur_curve->points(points);
00110             Curve* swept_curve = create_sweep_curve(cur_curve,distance,tolerance,CUBIT_TRUE);
00111             if(!swept_curve)
00112             {
00113                 PRINT_WARNING("Failed to create offset geometry for curve %d.\n",ref_edge->id());
00114                 continue;
00115             }
00116 
00117             CubitVector swpt_loc, source_loc;
00118             cur_curve->position_from_fraction(0.0,source_loc);
00119             swept_curve->position_from_fraction(0.0,swpt_loc);
00120 
00121             CubitVector up_vector = swpt_loc-source_loc;
00122 
00123             Surface* section = create_sweep_section(cur_curve,distance,up_vector);
00124             if(!section)
00125             {
00126                 PRINT_WARNING("Failed to create offset geometry for curve %d.\n",ref_edge->id());
00127                 // delete the Curve path
00128                 gqe->delete_solid_model_entities(swept_curve);
00129                 continue;
00130             }
00131 
00132             BodySM* swept_body = create_sweep_body(section,swept_curve);
00133 
00134             // delete the Curve path and Surface section
00135             gqe->delete_solid_model_entities(swept_curve);
00136             if(!swept_body)
00137             {
00138                 PRINT_WARNING("Failed to create offset geometry for curve %d.\n",ref_edge->id());
00139                 continue;
00140             }
00141 
00142             body_list.append(swept_body);
00143         }
00144 
00145         if(body_list.size() == 0)
00146         {
00147             PRINT_ERROR("Failed to offset any curve.\n");
00148             return CUBIT_FAILURE;
00149         }
00150 
00151         DLIList<TBPoint*> blunt_points;
00152         if(blunt_flg == CUBIT_TRUE)
00153         {
00154             for(i = 0; i < points.size(); i++)
00155             {
00156                 bool remove_point = true;
00157                 CubitVector pnt_loc_0 = points[i]->coordinates();
00158                 int j = 0;
00159                 for(j = 0;j < points.size(); j++)
00160                 {
00161                     if(i==j)
00162                         continue;
00163 
00164                     if(points[j] == points[i])
00165                     {
00166                         remove_point = false;
00167                         break;
00168                     }
00169 
00170                     CubitVector pnt_loc_1 = points[j]->coordinates();
00171 
00172                     if(pnt_loc_1.within_tolerance(pnt_loc_0,tolerance))
00173                     {
00174                         remove_point = false;
00175                         break;
00176                     }
00177                 }
00178                 if(remove_point)
00179                     blunt_points.append(points[i]);
00180             }
00181         }
00182         points.uniquify_ordered();
00183         points -= blunt_points;
00184 
00185         for(i = points.size(); i--;)
00186         {
00187             BodySM* shpere_body = gme->sphere(distance);
00188             CubitVector trans_dist = points.get_and_step()->coordinates();
00189             gqe->translate(shpere_body,trans_dist);
00190             body_list.append(shpere_body);
00191         }
00192 
00193         // create the offset geometry for debuging
00194 #ifdef OFFSET_SPLIT_DEBUG
00195         for(i=body_list.size();i--;)
00196         {
00197             GeometryQueryTool::instance()->make_Body(
00198                 gme->copy_body(body_list.get_and_step()));
00199         }
00200 #endif
00201 
00202         DLIList<BodySM*> united_body_list;
00203         if(body_list.size() == 1)
00204             united_body_list = body_list;
00205         else
00206         {
00207             if(!gme->unite(body_list,united_body_list))//united_body_list))
00208             {
00209                 if(body_list.size() == 1)
00210                     PRINT_ERROR( "Offset split failed at the unite step.\n" );
00211                 else
00212                     PRINT_ERROR( "Offset split failed at the unite step. Try reducing the curve count\n" );
00213 
00214                 // delete the solid bodies
00215                 for(i = body_list.size(); i--;)
00216                     gqe->delete_solid_model_entities(body_list.get_and_step());
00217 
00218                 return CUBIT_FAILURE;
00219             }
00220         }
00221 
00222         // get the surfaces contained in the body
00223         DLIList<Surface*> surface_united_list;
00224         for(i = united_body_list.size(); i--;)
00225         {
00226             BodySM* cur_body = united_body_list.get_and_step();
00227             cur_body->surfaces(surface_united_list);
00228         }
00229 
00230         ref_face_list.reset();
00231         imprint_list.reset();
00232         for(i = ref_face_list.size(); i--;)
00233         {
00234             Surface* surf_1 = ref_face_list.get_and_step()->get_surface_ptr();
00235             DLIList<Curve*> cur_curves;
00236             for(int j = surface_united_list.size(); j--;)
00237             {
00238                 DLIList<Curve*> intersection_curves;
00239                 Surface* surf_2 = surface_united_list.get_and_step();
00240                 gme->surface_intersection(surf_1,surf_2,intersection_curves,0.0);
00241 
00242                 // remove any very small curves from the intersection graph
00243                 // for some reason  seems to return zero length curves
00244                 for(int k = intersection_curves.size();k--;)
00245                 {
00246                     Curve* cur_curve = intersection_curves[k];
00247                     double len = cur_curve->
00248                         length_from_u(cur_curve->start_param(),cur_curve->end_param());
00249 
00250                     if(fabs(len) < tolerance)
00251                     {
00252                         intersection_curves.remove(cur_curve);
00253                         gqe->delete_solid_model_entities(cur_curve);
00254                     }
00255                 }
00256 
00257                 // do the division if the user asks for it
00258                 if(divide_flg &&
00259                     num_segs == seg &&
00260                     // skip the curves created by sphere surfaces
00261                     surf_2->geometry_type() != SPHERE_SURFACE_TYPE &&
00262                     surf_2->geometry_type() != PLANE_SURFACE_TYPE)
00263                 {
00264                     intersection_curves +=
00265                         this->create_divide_curves(intersection_curves,surf_1,distance);
00266                 }
00267 
00268                 cur_curves += intersection_curves;
00269             }
00270             DLIList<Curve*>* surf_inter_list = 0;
00271 
00272             if(ref_face_list.size() > imprint_list.size())
00273             {
00274                 surf_inter_list = new DLIList<Curve*>;
00275                 imprint_list.append(surf_inter_list);
00276             }
00277             else
00278                 surf_inter_list = imprint_list.get_and_step();
00279 
00280             (*surf_inter_list) += cur_curves;
00281             offset_curves += cur_curves;
00282 
00283             // draw the preview as the offset curves are being calculated
00284             if(preview_flg && !create_ref_edges_flg)
00285                 draw_preview(cur_curves);
00286         }
00287 
00288         // delete the solid bodies
00289         for(i = united_body_list.size(); i--;)
00290             gqe->delete_solid_model_entities(united_body_list.get_and_step());
00291     }
00292 
00293     // ok, now do the imprint or preview
00294     if(preview_flg)
00295     {
00296         if(!create_ref_edges_flg)
00297         {
00298             //Delete the Curve entities
00299             for(int i=0;i<offset_curves.size();i++)
00300             {
00301                 Curve* cur_curve = offset_curves.get_and_step();
00302                 cur_curve->get_geometry_query_engine()->
00303                     delete_solid_model_entities(cur_curve);
00304             }
00305         }
00306         else
00307         {
00308             create_ref_edges(offset_curves);
00309         }
00310 
00311         // delete the list that contained the curves that would have been imprinted
00312         for(int i= imprint_list.size();i--;)
00313             delete imprint_list.get_and_step();
00314     }
00315     // Imprint
00316     else
00317     {
00318         int i = 0;
00319         ref_face_list.reset();
00320         DLIList<Surface*> surface_list;
00321         for( i = ref_face_list.size(); i--;)
00322             surface_list.append(ref_face_list.get_and_step()->get_surface_ptr());
00323 
00324         Body *new_body_ptr;
00325         if( GeometryModifyTool::instance()->imprint( surface_list,
00326             imprint_list, new_body_ptr, false, false ) == CUBIT_FAILURE )
00327         {
00328             //Delete the Curve entities
00329             for(i= offset_curves.size();i--;)
00330             {
00331                 Curve* cur_curve = offset_curves.get_and_step();
00332                 cur_curve->get_geometry_query_engine()->
00333                     delete_solid_model_entities(cur_curve);
00334             }
00335 
00336             // delete the curves that would have been imprinted
00337             for( i= imprint_list.size();i--;)
00338                 delete imprint_list.get_and_step();
00339 
00340             return CUBIT_FAILURE;
00341         }
00342 
00343         //Delete the Curve entities
00344         for( i= offset_curves.size();i--;)
00345         {
00346             Curve* cur_curve = offset_curves.get_and_step();
00347             cur_curve->get_geometry_query_engine()->
00348                 delete_solid_model_entities(cur_curve);
00349         }
00350 
00351         // delete the curves that were used for imprinted
00352         for( i= imprint_list.size();i--;)
00353             delete imprint_list.get_and_step();
00354     }
00355 
00356     return CUBIT_SUCCESS;
00357 }
00358 
00359 //- Begin Private Functions
00360 CubitStatus OffsetSplitTool::draw_preview(
00361     DLIList<Curve*> &curve_list,
00362     int color )
00363 {
00364     int i;
00365     Curve *curve_ptr;
00366     curve_list.reset();
00367     for( i=curve_list.size(); i--; )
00368     {
00369         curve_ptr = curve_list.get_and_step();
00370         draw_preview( curve_ptr, CUBIT_FALSE, color );
00371     }
00372 
00373     GfxPreview::flush();
00374 
00375     return CUBIT_SUCCESS;
00376 }
00377 
00378 CubitStatus OffsetSplitTool::draw_preview(
00379     Curve *curve_ptr,
00380     CubitBoolean flush,
00381     int color )
00382 {
00383     CubitStatus result;
00384     GMem g_mem;
00385 
00386     // get the graphics
00387     result = curve_ptr->get_geometry_query_engine()->
00388         get_graphics( curve_ptr, &g_mem );
00389 
00390     if (result==CUBIT_FAILURE || g_mem.pointListCount == 0)
00391     {
00392         PRINT_WARNING("Unable to preview a curve\n" );;
00393         double len = curve_ptr->
00394             length_from_u(curve_ptr->start_param(),curve_ptr->end_param());
00395 
00396         PRINT_WARNING("Curve len: %f\n",len);
00397     }
00398 
00399     // Draw the polyline
00400     GfxPreview::draw_polyline( g_mem.point_list(), g_mem.pointListCount, color );
00401     if( flush )
00402         GfxPreview::flush();
00403 
00404     return CUBIT_SUCCESS;
00405 }
00406 
00407 
00408 Curve *OffsetSplitTool::create_sweep_curve(
00409     Curve *curve_in,
00410     double distance,
00411     double chord_tol,
00412     CubitBoolean iterate)
00413 {
00414     GeometryModifyEngine* gme =
00415         GeometryModifyTool::instance()->get_engine( curve_in );
00416     GeometryQueryEngine* gqe = curve_in->get_geometry_query_engine();
00417 
00418     CubitVector start_pos;
00419     CubitVector end_pos;
00420     CubitVector dummy_pos;
00421     CubitVector x_axis;
00422     CubitVector y_axis;
00423     CubitVector z_axis;
00424     CubitVector curvature;
00425 
00426     if(!curve_in->position_from_fraction(0.0,start_pos))
00427         return 0;
00428 
00429     if(!curve_in->position_from_fraction(1.0,end_pos))
00430         return 0;
00431 
00432     curve_in->closest_point(start_pos,dummy_pos,&z_axis,&curvature);
00433 
00434     // check to see if the curve is planar
00435     CubitBoolean is_planar = CUBIT_FALSE;
00436     DLIList<Surface*> attached_surfs;
00437     curve_in->surfaces(attached_surfs);
00438     int i = 0;
00439     for(i = 0;i < attached_surfs.size();i++)
00440     {
00441         Surface* cur_surf = attached_surfs.get_and_step();
00442         if(cur_surf && 
00443             cur_surf->geometry_type() == PLANE_SURFACE_TYPE)
00444         {
00445             CubitVector center_vec;
00446             cur_surf->get_point_normal(center_vec,x_axis);
00447             is_planar = CUBIT_TRUE;
00448             break;
00449         }
00450     }
00451 
00452     if(is_planar)
00453     {
00454         y_axis = z_axis*x_axis;
00455     }
00456     // If curvature is significant, use it to create the sweep coordinate system
00457     else if(curvature.length() < CUBIT_DBL_MIN)
00458     {
00459         z_axis.orthogonal_vectors(x_axis,y_axis);
00460     }
00461     else
00462     {
00463         y_axis = curvature;
00464         x_axis = z_axis*y_axis;
00465     }
00466 
00467     x_axis.normalize();
00468     y_axis.normalize();
00469     z_axis.normalize();
00470     x_axis *=distance;
00471 
00472     GeometryType geom_type = curve_in->geometry_type();
00473     if(geom_type == STRAIGHT_CURVE_TYPE) // if the curve is a line just offset it
00474     {
00475         //  has problems calculating the intersection curves of surface edges and surfaces
00476         // so rotate the coordinate system to some angle that is less likely to be used
00477         x_axis.normalize();
00478         y_axis.normalize();
00479         CubitVector move_vec = y_axis - x_axis;
00480         y_axis = y_axis+(move_vec*.744561789854);
00481         x_axis = z_axis*y_axis;
00482 
00483         x_axis.normalize();
00484         y_axis.normalize();
00485         z_axis.normalize();
00486         x_axis *=distance;
00487 
00488         // just offset the curve
00489         Curve* offset_curve = gme->make_Curve(curve_in);
00490         gqe->translate(offset_curve,x_axis);
00491         return offset_curve;
00492     }
00493     else if(geom_type == ARC_CURVE_TYPE ||
00494         geom_type == ELLIPSE_CURVE_TYPE ||
00495         is_planar) // if the curve is a arc just offset it
00496     {
00497         // just offset the curve
00498         Curve* offset_curve = gme->make_Curve(curve_in);
00499         gqe->translate(offset_curve,x_axis);
00500         return offset_curve;
00501     }
00502 
00503     DLIList<CubitVector*> pnt_list;
00504     CubitVector* loc_0 = new CubitVector(start_pos);
00505     CubitVector* loc_1 = new CubitVector(end_pos);
00506     pnt_list.append(loc_0);
00507     pnt_list.append(loc_1);
00508     DLIList<double> frac_list;
00509     frac_list.append(0.0);
00510     frac_list.append(1.0);
00511     frac_list.reset();
00512 
00513     // create the curve points with a maximum deviation of 'chord_tol'
00514     while(1)
00515     {
00516         double frac_0 = frac_list.get_and_step();
00517         double frac_1 = frac_list.get();
00518         pnt_list.step();
00519 
00520         if(frac_0>frac_1)
00521             break;
00522 
00523         CubitVector tmp_pos_0;
00524         curve_in->position_from_fraction(frac_0,tmp_pos_0);
00525         CubitVector tmp_pos_1;
00526         curve_in->position_from_fraction(frac_1,tmp_pos_1);
00527         CubitVector tmp_pos_2 = (tmp_pos_0+tmp_pos_1)/2.0;
00528         CubitVector tmp_pos_3;
00529         double mid_frac = (frac_0+frac_1)/2.0;
00530         curve_in->position_from_fraction(mid_frac,tmp_pos_3);
00531 
00532         if(tmp_pos_3.distance_between(tmp_pos_2) > chord_tol)
00533         {
00534             CubitVector* loc = new CubitVector(tmp_pos_3);
00535             pnt_list.back();
00536             frac_list.back();
00537             pnt_list.insert(loc);
00538             frac_list.insert(mid_frac);
00539             pnt_list.back();
00540             frac_list.back();
00541         }
00542     }
00543 
00544     // generate the offset curve points
00545     CubitVector last_vec = x_axis;
00546     pnt_list.reset();
00547     for(i = 0;i < pnt_list.size();i++)
00548     {
00549         CubitVector curv,tangent,dummy;
00550         CubitVector *cur_pnt = pnt_list.get_and_step();
00551         curve_in->closest_point(*cur_pnt,dummy,&tangent,&curv);
00552 
00553         // if the radius of curvature is smaller than the distance of the
00554         // sweep offset then return a NULL curve
00555         if(curvature.length()> CUBIT_DBL_MIN &&
00556             1.0/(curv.length()) <= distance)
00557         {
00558             // clean out the points
00559             for(int i =pnt_list.size();i--;)
00560                 delete pnt_list.get_and_step();
00561 
00562             PRINT_WARNING("Radius of curvature is smaller than or equal to %f.\n"
00563                 "Cannot offset curve.\n",distance);
00564             return 0;
00565         }
00566 
00567         CubitVector up_vec = tangent*last_vec;
00568         CubitVector offset_vec = up_vec*tangent;
00569         offset_vec.normalize();
00570         offset_vec *= distance;
00571         cur_pnt->set(*cur_pnt + offset_vec);
00572         last_vec = offset_vec;
00573     }
00574 
00575     // create a spline sweep path
00576     pnt_list.reset();
00577     TBPoint* start_point = gme->make_Point(*(pnt_list.get_and_back()));
00578     TBPoint* end_point = gme->make_Point(*(pnt_list.get_and_step()));
00579 
00580     // Create the curve
00581 
00582     Curve* curve_out =
00583         gme->make_Curve(
00584         SPLINE_CURVE_TYPE,
00585         start_point,end_point,pnt_list);
00586 
00587     pnt_list.reset();
00588     for(i =pnt_list.size();i--;)
00589         delete pnt_list.get_and_step();
00590 
00591     pnt_list.clean_out();
00592     return curve_out;
00593 }
00594 
00595 
00596 Surface* OffsetSplitTool::create_sweep_section(
00597     Curve* path,
00598     double distance,
00599     CubitVector up_vector,
00600     double fraction)
00601 {
00602     up_vector.normalize();
00603     GeometryModifyEngine* gme =
00604         GeometryModifyTool::instance()->get_engine( path );
00605 
00606     CubitVector start_pos;
00607     CubitVector dummy_pos;
00608     CubitVector x_axis;
00609     CubitVector y_axis;
00610     CubitVector z_axis;
00611     if(!path->position_from_fraction(fraction,start_pos))
00612         return 0;
00613 
00614     path->closest_point(start_pos,dummy_pos,&z_axis);
00615     y_axis = z_axis*up_vector;
00616     x_axis = up_vector;
00617 
00618     x_axis.normalize();
00619     y_axis.normalize();
00620     z_axis.normalize();
00621 
00622     TBPoint* start_point = gme->make_Point(start_pos+x_axis);
00623     TBPoint* end_point = gme->make_Point(start_pos-x_axis);
00624     TBPoint* center_point = gme->make_Point(start_pos);
00625 
00626     Curve* arc_curve_0 =
00627         gme->create_arc_center_edge(center_point,start_point,end_point,z_axis,distance);
00628 
00629     start_point = gme->make_Point(start_pos+x_axis);
00630     end_point = gme->make_Point(start_pos-x_axis);
00631     center_point = gme->make_Point(start_pos);
00632 
00633     Curve* arc_curve_1 =
00634         gme->create_arc_center_edge(center_point,start_point,end_point,-z_axis,distance);
00635 
00636     DLIList<Curve*> curve_list;
00637     curve_list.append(arc_curve_0);
00638     curve_list.append(arc_curve_1);
00639 
00640     Surface* surf_out =
00641         gme->make_Surface(PLANE_SURFACE_TYPE,curve_list,0,false);
00642 
00643     return surf_out;
00644 }
00645 
00646 BodySM* OffsetSplitTool::create_sweep_body(
00647     Surface* section,
00648     Curve* path)
00649 {
00650     GeometryModifyEngine* gme =
00651         GeometryModifyTool::instance()->get_engine( section );
00652 
00653     DLIList<GeometryEntity*> ent_list;
00654     ent_list.append(section);
00655     DLIList<BodySM*> body_list;
00656     DLIList<Curve*> path_list;
00657     path_list.append(path);
00658 
00659     gme->sweep_along_curve(ent_list,body_list,path_list, 0.0, 0, 
00660                                CUBIT_FALSE, CUBIT_FALSE, CUBIT_FALSE);
00661 
00662     if(body_list.size())
00663         return body_list.get();
00664 
00665     return 0;
00666 }
00667 
00668 CubitStatus OffsetSplitTool::create_ref_edges(
00669     DLIList<Curve*> &curve_list )
00670 {
00671     int i;
00672     Curve *curve_ptr;
00673     curve_list.reset();
00674     for( i=curve_list.size(); i--; )
00675     {
00676         curve_ptr = curve_list.get_and_step();
00677         GeometryQueryTool::instance()->make_free_RefEdge(curve_ptr);
00678     }
00679     return CUBIT_SUCCESS;
00680 }
00681 
00682 DLIList<Curve*> OffsetSplitTool::create_divide_curves(
00683     DLIList<Curve*> &curve_list,
00684     Surface* target_surface,
00685     double distance)
00686 {
00687     DLIList<Curve*> return_list;
00688     curve_list.reset();
00689     int curve_list_size = curve_list.size();
00690     for(int i = curve_list_size; i--;)
00691     {
00692         Curve* cur_curve = curve_list.get_and_step();
00693         GeometryModifyEngine* gme =
00694             GeometryModifyTool::instance()->get_engine( cur_curve );
00695         GeometryQueryEngine* gqe =
00696             cur_curve->get_geometry_query_engine();
00697 
00698         // Find the matching source curve.
00699         // there are better ways to do this such as using the surface
00700         // arc intersection but that only seems to work for one engine or another
00701         // not both
00702         for(int j = sourceCurves.size(); j--;)
00703         {
00704             Curve* source_curve = sourceCurves.get_and_step();
00705             CubitVector coord1;
00706             CubitVector coord2;
00707             double distance_out = 0.0;
00708             if(!gqe->entity_entity_distance( source_curve, cur_curve,
00709                 coord1, coord2, distance_out ))
00710                 continue;
00711 
00712             if(fabs(distance_out-distance) < tolerance)
00713             {
00714                 // check three points
00715                 CubitVector pnt_0;
00716                 CubitVector pnt_1;
00717                 CubitVector pnt_2;
00718                 CubitVector pnt_3;
00719                 CubitVector pnt_4;
00720                 CubitVector pnt_5;
00721                 cur_curve->position_from_fraction(0.0,pnt_0);
00722                 source_curve->closest_point(pnt_0,pnt_1);
00723                 cur_curve->position_from_fraction(0.5,pnt_2);
00724                 source_curve->closest_point(pnt_2,pnt_3);
00725                 cur_curve->position_from_fraction(1.0,pnt_4);
00726                 source_curve->closest_point(pnt_4,pnt_5);
00727 
00728                 if(fabs(pnt_0.distance_between(pnt_1) - distance) < tolerance &&
00729                     fabs(pnt_2.distance_between(pnt_3) - distance) < tolerance &&
00730                     fabs(pnt_4.distance_between(pnt_5) - distance) < tolerance)
00731                 {
00732                     // ok now just create curves between each end of the surface intersection curves
00733                     // and the projection to the source curves
00734 
00735                     // first curve
00736                     TBPoint* start_point_0 = gme->make_Point(pnt_0);
00737                     TBPoint* end_point_0 = gme->make_Point(pnt_1);
00738                     CubitVector vert3_coord_0 = start_point_0->coordinates();
00739 
00740                     Curve* new_curve_0 =
00741                         gme->make_Curve(STRAIGHT_CURVE_TYPE,
00742                         start_point_0,end_point_0,&vert3_coord_0 );
00743 
00744                     // second curve
00745                     TBPoint* start_point_1 = gme->make_Point(pnt_4);
00746                     TBPoint* end_point_1 = gme->make_Point(pnt_5);
00747                     CubitVector vert3_coord_1 = start_point_1->coordinates();
00748 
00749                     Curve* new_curve_1 =
00750                         gme->make_Curve(STRAIGHT_CURVE_TYPE,
00751                         start_point_1,end_point_1,&vert3_coord_1 );
00752 
00753                     // if the target surface is not a plane then do a projection
00754                     if(target_surface->geometry_type() != PLANE_SURFACE_TYPE)
00755                     {
00756                         DLIList<Curve*> curves_in;
00757 
00758                         if(new_curve_0)
00759                             curves_in.append(new_curve_0);
00760 
00761                         if(new_curve_1)
00762                             curves_in.append(new_curve_1);
00763 
00764                         DLIList<Curve*> curves_out;
00765                         DLIList<Surface*> surface_in;
00766                         surface_in.append(target_surface);
00767                         if(gme->project_edges(surface_in,curves_in,curves_out))
00768                             return_list += curves_out; // add the curves to the return list
00769                     }
00770                     else // add the curves to the return list
00771                     {
00772                         if(new_curve_0)
00773                             return_list.append(new_curve_0);
00774 
00775                         if(new_curve_1)
00776                             return_list.append(new_curve_1);
00777                     }
00778                 }
00779             }
00780         }
00781     }
00782     return return_list;
00783 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines