cgma
SplitSurfaceVirtual.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : SplitSurfaceVirtual.cpp
00003 //
00004 // Purpose       : Split a surface and create virtual surfaces
00005 //
00006 // Special Notes : 
00007 //
00008 // Creator       : KGM
00009 //
00010 // Creation Date : 30-Jun-2005
00011 //-------------------------------------------------------------------------
00012 
00013 #include "SplitSurfaceVirtual.hpp"
00014 #include "SplitSurfaceTool.hpp"
00015 #include "RefVertex.hpp"
00016 #include "RefEdge.hpp"
00017 #include "RefFace.hpp"
00018 #include "Curve.hpp"
00019 #include "Surface.hpp"
00020 #include "GeometryQueryTool.hpp"
00021 #include "PartitionTool.hpp"
00022 #include "CubitMessage.hpp"
00023 #include "CubitUtil.hpp"
00024 #include "DLIList.hpp"
00025 #include "GfxDebug.hpp"
00026 #include "GMem.hpp"
00027 
00028 CubitStatus                                
00029 SplitSurfaceVirtual::split_surface_virtual( RefFace *ref_face_ptr,
00030                                  DLIList<CubitVector*> &locations,
00031                                  DLIList<DLIList<CubitVector*>*> &vec_lists )
00032 {
00033   // find the splitting curves. 
00034   SplitSurfaceTool sst;
00035   DLIList<Curve*> curve_list;
00036   CubitStatus err  = sst.calculate_split_curves( ref_face_ptr, locations, 
00037                                              vec_lists, curve_list );
00038 
00039   GMem gmem;
00040   int  num_points;
00041   DLIList<CubitVector*> segments;
00042 
00043   // loop over all the curves 
00044   int i;
00045   for (i = 0; i < curve_list.size(); i++)
00046   {
00047     Curve* curve_ptr = curve_list.get_and_step();
00048 
00049     // get the curve facets
00050     err = curve_ptr->get_geometry_query_engine()->
00051                           get_graphics( curve_ptr, num_points, &gmem );
00052 
00053     // load the graphics points into a CubitVector for insert_curve
00054     --num_points;  
00055     int j;
00056     for (j = 0; j < num_points; j++)
00057     {
00058       const GPoint& p = gmem.point_list()[j];
00059       segments.append( new CubitVector( p.x, p.y, p.z ) );
00060     }
00061   }
00062 
00063   // add last point to the end of the list
00064   const GPoint& p = gmem.point_list()[num_points];
00065   segments.append( new CubitVector(p.x, p.y, p.z ) );
00066 
00067   // now partition the surface
00068   DLIList<RefEdge*> new_edges;
00069   RefFace* new_surf = PartitionTool::instance()->insert_edge( ref_face_ptr, segments, 
00070                                                                 false, new_edges );
00071   //DLIList<Curve*> new_curves;
00072   //Surface* new_surf = PartitionEngine::instance().insert_curve( old_surf, segments, new_curves );
00073 
00074   // called routines allocate memory.  Clean up for them.
00075   while( curve_list.size() ) 
00076     delete curve_list.pop();
00077 
00078   //while( new_curves.size() ) 
00079   //  delete new_curves.pop();
00080 
00081   return CUBIT_SUCCESS;
00082 }
00083 
00084 
00085 //===============================================================================
00086 // Function   : split_surfaces
00087 // Member Type: PUBLIC
00088 // Description: Split a chain of surfaces into one or more pieces
00089 // Author     : Steve Storm (CAT)
00090 // Date       : 01/04
00091 //===============================================================================
00092 CubitStatus 
00093 SplitSurfaceVirtual::split_surfaces_virtual( DLIList<RefFace*> &ref_face_list, 
00094                                              int num_segs, 
00095                                              double fraction,
00096                                              double distance,
00097                                              RefEdge *from_curve_ptr,
00098                                              DLIList<RefVertex*> &corner_vertex_list,
00099                                              DLIList<RefVertex*> &through_vertex_list,
00100                                              RefEdge *curve_dir_ptr,
00101                                              CubitBoolean preview_flg,
00102                                              CubitBoolean create_ref_edges_flg )
00103 {
00104   // Get parent bodies - all surfs must be from same body
00105   int i;
00106   DLIList<Body*> old_body_list;
00107   RefFace *ref_face_ptr;
00108   ref_face_list.reset();
00109   for( i=ref_face_list.size(); i--; )
00110   {
00111     ref_face_ptr = ref_face_list.get_and_step();
00112 
00113     DLIList<Body*> body_list;
00114     ref_face_ptr->bodies( body_list );
00115     old_body_list.merge_unique( body_list );
00116   }
00117 
00118   if( old_body_list.size() > 1 )
00119   {
00120     PRINT_ERROR( "This operation requires all surfaces to be from the same volume\n" );
00121     // Note: this restriction could be pretty easily lifted by sorting the 
00122     //       input lists and calling the SplitSurfaceTool separately for each set of
00123     //       surfaces on each body.
00124     return CUBIT_FAILURE;
00125   }
00126 
00127   //bad geom with no body -- dont try to imprint this...  
00128   //quick and dirty fix by (aga@cat|1/7/04)
00129   if( old_body_list.size() < 1 )
00130   {
00131     PRINT_ERROR( "A surface is not contained within a parent body.\n"
00132       "       It cannot be split.\n");
00133     return CUBIT_FAILURE;
00134   }
00135  /* KGM -- need this? 
00136   // Check for virtual geometry
00137   if ( contains_intermediate_geometry(ref_face_list) )
00138   {
00139     PRINT_ERROR("SPLITTING surfaces containing virtual geometry is not\n"
00140       "       allowed. Delete virtual geometry on these surfaces\n"
00141       "       before operation.\n" );
00142     return CUBIT_FAILURE;
00143   }
00144   */
00145 
00146   // Make sure all surfaces are from same geometry engine
00147   DLIList<RefEntity*> ref_ent_list;
00148   CAST_LIST_TO_PARENT(ref_face_list, ref_ent_list);
00149   /* KGM -- need this?
00150   if ( !same_modify_engine(ref_ent_list, CUBIT_TRUE) )   
00151   {
00152     PRINT_ERROR("Performing SPLIT with surfaces containing geometry from\n"
00153       "different modeling engines is not allowed.\n"
00154       "Delete uncommon geometry on these surfaces before operation.\n\n");
00155     return CUBIT_FAILURE;
00156   }
00157   */
00158 
00159   // get the splitting curves
00160   DLIList<DLIList<Curve*>*> curve_lists_list;
00161   SplitSurfaceTool sst;
00162   CubitStatus err = sst.calculate_split_curves( ref_face_list, num_segs, fraction, distance,
00163                                                 from_curve_ptr,corner_vertex_list,
00164                                                 through_vertex_list, curve_dir_ptr,
00165                                                 preview_flg, create_ref_edges_flg,
00166                                                 false, curve_lists_list );
00167 
00168 
00169   // loop over all the curves 
00170   GMem gmem;
00171   int  num_points;
00172   DLIList<CubitVector*> segments;
00173   int k;
00174   for (k=0; k < curve_lists_list.size(); k++)
00175   {
00176     DLIList<Curve*> *curve_list = curve_lists_list[k];
00177 
00178     int i;
00179     for (i = 0; i < curve_list->size(); i++)
00180     {
00181       Curve* curve_ptr = curve_list->get_and_step();
00182 
00183       // get the curve facets
00184       err = curve_ptr->get_geometry_query_engine()->
00185                             get_graphics( curve_ptr, num_points, &gmem );
00186 
00187       // load the graphics points into a CubitVector for insert_curve
00188       --num_points;  
00189       int j;
00190       for (j = 0; j < num_points; j++)
00191       {
00192         const GPoint& p = gmem.point_list()[j];
00193         segments.append( new CubitVector( p.x, p.y, p.z ) );
00194       }
00195     }
00196   }
00197 
00198   // add last point to the end of the list
00199   const GPoint& p = gmem.point_list()[num_points];
00200   segments.append( new CubitVector(p.x, p.y, p.z ) );
00201 
00202   // Get the underlying surface (what if it is virtual does this still work?)
00203   //Surface *old_surf = ref_face_list[k]->get_surface_ptr(); KGM
00204 
00205   // now partition the surface
00206   DLIList<RefEdge*> new_edges;
00207   DLIList<RefFace*> new_faces;
00208   err = PartitionTool::instance()->insert_edge( ref_face_list, 
00209                           segments, new_faces, new_edges); 
00210   //DLIList<Curve*> new_curves;
00211   //Surface* new_surf = PartitionEngine::instance().insert_curve( old_surf, segments, new_curves );
00212 
00213   // insert_curve allocates memory.  Clean up.
00214   //while( new_curves.size() ) 
00215   //  delete new_curves.pop();
00216 
00217   // called routines allocate memory.  Clean up for them.
00218   for (k=0; k < curve_lists_list.size(); k++)
00219   {
00220     DLIList<Curve*> *curve_list = curve_lists_list[k];
00221     while( curve_list->size() ) 
00222       delete curve_list->pop();
00223   }
00224 
00225   return CUBIT_SUCCESS;
00226 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines