cgma
FacetModifyEngine.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 //-------------------------------------------------------------------------
00003 
00004 // Filename      : FacetModifyEngine.cpp
00005 //
00006 // Purpose       : ModifyEngine for faceted geometry
00007 //
00008 // Special Notes : Modeled after GeometryModifyEngine and OCCModifyEngine.
00009 //
00010 // Creator       : John Fowler
00011 //
00012 // Creation Date : 6/02
00013 //
00014 // Owner         : John Fowler
00015 //-------------------------------------------------------------------------
00016 
00017 #include "FacetModifyEngine.hpp"
00018 #include "FacetQueryEngine.hpp"
00019 #include "SettingHandler.hpp"
00020 
00021 #include "CubitMessage.hpp"
00022 #include "CubitDefines.h"
00023 
00024 #include "CubitUtil.hpp"
00025 #include "CubitPoint.hpp"
00026 #include "CubitPointData.hpp"
00027 #include "CubitFacet.hpp"
00028 #include "CubitQuadFacet.hpp"
00029 #include "CubitFacetData.hpp"
00030 #include "CubitFacetEdge.hpp"
00031 #include "CubitFacetEdgeData.hpp"
00032 #include "GeometryQueryTool.hpp"
00033 #include "GeometryModifyTool.hpp"
00034 #include "ChollaSurface.hpp"
00035 #include "ChollaCurve.hpp"
00036 #include "ChollaPoint.hpp"
00037 #include "FacetPoint.hpp"
00038 #include "FacetCurve.hpp"
00039 #include "CurveFacetEvalTool.hpp"
00040 #include "FacetEvalTool.hpp"
00041 #include "FacetCoEdge.hpp"
00042 #include "FacetLoop.hpp"
00043 #include "FacetSurface.hpp"
00044 #include "FacetShell.hpp"
00045 #include "FacetLump.hpp"
00046 #include "FacetBody.hpp"
00047 #include "ChollaEngine.hpp"
00048 #include "TDGeomFacet.hpp"
00049 #include "CubitFileIOWrapper.hpp"
00050 #include "TDFacetBoundaryPoint.hpp"
00051 #include "Cholla.h"
00052 #include "Body.hpp"
00053 #include "GfxDebug.hpp"
00054 #include "RefFace.hpp"
00055 #include "FacetDataUtil.hpp"
00056 #include "FBDataUtil.hpp"
00057 #include "FBIntersect.hpp"
00058 #include "IntegerHash.hpp"
00059 #include "FacetboolInterface.hpp"
00060 #include "CpuTimer.hpp"
00061 #include "ProgressTool.hpp"
00062 #include "AppUtil.hpp"
00063 #include "SphereEvaluator.hpp"
00064 #include "CylinderEvaluator.hpp"
00065 #include "CubitLoops.hpp"
00066 #include "FacetProjectTool.hpp"
00067 
00068 #include <algorithm>
00069 
00070 FacetModifyEngine* FacetModifyEngine::instance_ = 0;
00071 CubitBoolean FacetModifyEngine::modifyEnabled = CUBIT_FALSE;
00072 
00073 //The do... while(0) trick is to get the trailing semicolon to
00074 // do nothing in some very rare cases.  From Steven Engelhardt's Weblog.
00075 
00076 #define MODIFY_CHECK_RETURN_NULL \
00077 do {if(!modifyEnabled){                                                               \
00078     PRINT_INFO("Facet-based geometry modification is a beta capability.\n");\
00079     PRINT_ERROR("This capability is currently disabled.\n");\
00080     PRINT_INFO("To enable this capability, issue the command 'set developer commands on'. \n");\
00081     return NULL;} }while(0)
00082 
00083 #define MODIFY_CHECK_RETURN_VOID \
00084 do {if(!modifyEnabled){ \
00085     PRINT_INFO("Facet-based geometry modification is a beta capability.\n");\
00086     PRINT_ERROR("This capability is currently disabled.\n");\
00087     PRINT_INFO("To enable this capability, issue the command 'set developer commands on'. \n");\
00088     return;} }while(0)
00089 
00090 #define MODIFY_CHECK_RETURN_FAILURE \
00091 do {if(!modifyEnabled){ \
00092     PRINT_INFO("Facet-based geometry modification is a beta capability.\n");\
00093     PRINT_ERROR("This capability is currently disabled.\n");\
00094     PRINT_INFO("To enable this capability, issue the command 'set developer commands on'. \n");\
00095     return CUBIT_FAILURE;} }while(0)
00096 //===============================================================================
00097 // Function   : FacetModifyEngine
00098 // Member Type: PUBLIC
00099 // Description: constructor
00100 // Author     : John Fowler
00101 // Date       : 10/02
00102 //===============================================================================
00103 FacetModifyEngine::FacetModifyEngine()
00104 {
00105 //  assert( !instance_ );
00106 
00107     // add this modify engine to geometrymodifytool
00108   GeometryModifyTool::instance()->add_gme(this);
00109 }
00110 //Initialize all settings in this class
00111 void FacetModifyEngine::initialize_settings()
00112 {
00113 
00114   SettingHandler::instance()->add_setting(
00115     "Facet_modify",FacetModifyEngine::set_modify_enabled,
00116     FacetModifyEngine::is_modify_enabled);
00117   
00118 }
00119 
00120 //===============================================================================
00121 // Function   : ~FacetModifyEngine
00122 // Member Type: PUBLIC
00123 // Description: destructor
00124 // Author     : John Fowler
00125 // Date       : 10/02
00126 //===============================================================================
00127 FacetModifyEngine::~FacetModifyEngine() 
00128 {
00129         instance_ = 0;
00130 }
00131 
00132 //===============================================================================
00133 // Function   : make_Point
00134 // Member Type: PUBLIC
00135 // Description: make a geometric entity point
00136 // Author     : John Fowler
00137 // Date       : 10/02
00138 //===============================================================================
00139 TBPoint* FacetModifyEngine::make_Point( CubitVector const& point) const
00140 {
00141   FacetModifyEngine *self = const_cast<FacetModifyEngine *> (this);
00142   TBPoint* new_point = NULL;
00143   self->make_facet_point(point, new_point);
00144   return new_point;
00145 }
00146 
00147 //===============================================================================
00148 // Function   : make_Curve
00149 // Member Type: PUBLIC
00150 // Description: make a curve
00151 // Author     : John Fowler
00152 // Date       : 10/02
00153 //===============================================================================
00154 Curve* FacetModifyEngine::make_Curve(Curve * /*curve_ptr*/,
00155   std::map<TopologyBridge*, TopologyBridge*> *old_tb_to_new_tb ) const
00156 {
00157   PRINT_ERROR("Option not supported for mesh based geometry.\n");
00158   return (Curve*) NULL;
00159 }
00160 
00161 //===============================================================================
00162 // Function   : make_Curve
00163 // Member Type: PUBLIC
00164 // Description: make a curve
00165 // Author     : John Fowler
00166 // Date       : 10/02
00167 //===============================================================================
00168 Curve* FacetModifyEngine::make_Curve( TBPoint const* point1_ptr,
00169                              TBPoint const* point2_ptr,
00170                              Surface* ref_face_ptr,
00171                              const CubitVector * third_point) const
00172 {
00173 
00174   CubitPoint* p1 = static_cast<const FacetPoint*>(point1_ptr)->get_cubit_point();
00175   CubitPoint* p2 = static_cast<const FacetPoint*>(point2_ptr)->get_cubit_point();
00176 
00177   // gather data
00178   CubitVector v1 = p1->coordinates();
00179   CubitVector v2 = p2->coordinates();
00180   CubitVector v3 = third_point ? *third_point : CubitVector();
00181 
00182   DLIList<CubitVector*> pts;
00183   pts.append(&v1);
00184   if(third_point)
00185     pts.append(&v3);
00186   pts.append(&v2);
00187 
00188   FacetSurface* facet_surf = CAST_TO( ref_face_ptr, FacetSurface );
00189   DLIList<CubitPoint*> surf_pts;
00190   DLIList<CubitFacet*> surf_facets;
00191   facet_surf->get_my_facets(surf_facets, surf_pts);
00192   
00193   
00194   std::vector<double> facet_pts;
00195   std::vector<int> facet_conn;
00196 
00197   for(DLIList<CubitPoint*>::iterator iter = surf_pts.begin(), end = surf_pts.end();
00198       iter != end; ++iter)
00199   {
00200     (*iter)->marked(-1);
00201   }
00202   for(DLIList<CubitFacet*>::iterator iter = surf_facets.begin(), end = surf_facets.end();
00203       iter != end; ++iter)
00204   {
00205     CubitPoint* p[3];
00206     (*iter)->points(p[0], p[1], p[2]);
00207     for(int i=0; i<3; i++)
00208     {
00209       if(p[i]->marked() == -1)
00210       {
00211         p[i]->marked(facet_pts.size()/3);
00212         CubitVector v = p[i]->coordinates();
00213         facet_pts.push_back(v.x());
00214         facet_pts.push_back(v.y());
00215         facet_pts.push_back(v.z());
00216       }
00217       facet_conn.push_back(p[i]->marked());
00218     }
00219   }
00220 
00221   // project straight line betwee points to surface
00222   std::vector<int> dudded_facets, new_facets, new_facetindex;
00223   std::vector<double> new_pts;
00224   std::vector<int> edges, segmentPts;
00225 
00226   FacetProjectTool proj_tool;
00227   CubitStatus stat = proj_tool.project(pts, facet_pts, facet_conn,
00228                                        dudded_facets, new_facets, new_facetindex,
00229                                        new_pts, edges, segmentPts);
00230 
00231   if(stat != CUBIT_SUCCESS)
00232   {
00233     PRINT_ERROR("Failed to project facet curve to surface.\n");
00234     return NULL;
00235   }
00236 
00237   assert(edges[0] + 2 >= 0);
00238   if((size_t)(edges[0] + 2) != edges.size())
00239   {
00240     PRINT_ERROR("Facet curve projection produced multiple curves when one was expected.\n");
00241     return NULL;
00242   }
00243 
00244   // lump new points with old points (we don't care about conforming to the surface mesh)
00245   facet_pts.insert(facet_pts.end(), new_pts.begin(), new_pts.end());
00246 
00247 
00248   // build the new curve
00249   edges.erase(edges.begin());
00250   edges.erase(edges.end()-1);
00251   
00252   DLIList<CubitPoint*> curve_pts;
00253   DLIList<CubitFacetEdge*> curve_edges;
00254   CubitPoint* prev_point = p1;
00255   for(size_t i=1; i<edges.size()-1; i++)
00256   {
00257     CubitPoint* next_point = new CubitPointData(CubitVector(&facet_pts[3*edges[i]]));
00258     curve_pts.append(next_point);
00259     CubitFacetEdgeData* cfe = new CubitFacetEdgeData(prev_point, next_point);
00260     curve_edges.append(cfe);
00261     prev_point = next_point;
00262   }
00263 
00264   CubitFacetEdgeData* cfe = new CubitFacetEdgeData(prev_point, p2);
00265   curve_edges.append(cfe);
00266   curve_pts.append(p2);
00267 
00268   Curve* new_curve = NULL;
00269   FacetModifyEngine* self = const_cast<FacetModifyEngine*>(this);
00270   self->make_facet_curve(const_cast<TBPoint*>(point1_ptr), 
00271                          const_cast<TBPoint*>(point2_ptr),
00272                          curve_edges, curve_pts, new_curve, NULL);
00273 
00274   return new_curve;
00275 }
00276 
00277 //===============================================================================
00278 // Function   : make_Curve
00279 // Member Type: PUBLIC
00280 // Description: make a curve using point_tangents to describe curvature
00281 // Author     : John Fowler
00282 // Date       : 10/02
00283 //===============================================================================
00284 Curve* FacetModifyEngine::make_Curve( DLIList<CubitVector*>& point_list,
00285                    DLIList<CubitVector*>& point_tangents) const
00286 {
00287     PRINT_ERROR("Option not supported for mesh based geometry.\n");
00288     return (Curve*)NULL;
00289 }
00290 
00291 //===============================================================================
00292 // Function   : make_Curve
00293 // Member Type: PUBLIC
00294 // Description: make a curve
00295 // Author     : John Fowler
00296 // Date       : 10/02
00297 //===============================================================================
00298 Curve* FacetModifyEngine::make_Curve(GeometryType /*curve_type*/,
00299                              TBPoint const* point1_ptr,
00300                              TBPoint const* point2_ptr,
00301                              DLIList<CubitVector *> &vector_list,
00302                              Surface* /*ref_face_ptr*/) const
00303 {
00304   Curve* new_curve = NULL;
00305 
00306   DLIList<CubitPoint*> points;
00307   DLIList<CubitFacetEdge*> edges;
00308 
00309   CubitPoint* prev_point = static_cast<const FacetPoint*>(point1_ptr)->get_cubit_point();
00310   points.append(prev_point);
00311 
00312   for(int i=0; i<vector_list.size(); i++)
00313   {
00314     CubitPoint* next_point = new CubitPointData(*vector_list[i]);
00315     CubitFacetEdgeData* cfe = new CubitFacetEdgeData(prev_point, next_point);
00316     edges.append(cfe);
00317     prev_point = next_point;
00318     points.append(prev_point);
00319   }
00320 
00321   CubitPoint* end_point = static_cast<const FacetPoint*>(point2_ptr)->get_cubit_point();
00322 
00323   CubitFacetEdgeData* cfe = new CubitFacetEdgeData(prev_point, end_point);
00324   edges.append(cfe);
00325   points.append(end_point);
00326 
00327   FacetModifyEngine* self = const_cast<FacetModifyEngine*>(this);
00328   self->make_facet_curve(const_cast<TBPoint*>(point1_ptr), 
00329                          const_cast<TBPoint*>(point2_ptr),
00330                          edges, points, new_curve, NULL);
00331 
00332   return new_curve;
00333 }
00334 
00335 //===============================================================================
00336 // Function   : make_Curve
00337 // Member Type: PUBLIC
00338 // Description: make a curve
00339 // Author     : John Fowler
00340 // Date       : 10/02
00341 //===============================================================================
00342 Curve* FacetModifyEngine::make_Curve( GeometryType /*curve_type*/,
00343                              TBPoint const* /*point1_ptr*/,
00344                              TBPoint const* /*point2_ptr*/,
00345                              CubitVector const* /*intermediate_point_ptr*/ ) const
00346 {
00347   PRINT_ERROR("Option not supported for mesh based geometry.\n");
00348   return (Curve*) NULL;
00349 }
00350 
00351 //===============================================================================
00352 // Function   : make_Surface
00353 // Member Type: PUBLIC
00354 // Description: make a surface
00355 // Author     : John Fowler
00356 // Date       : 10/02
00357 //===============================================================================
00358 Surface* FacetModifyEngine::make_Surface( Surface * /*old_surface_ptr*/,
00359                                  std::map< TopologyBridge*, TopologyBridge* > * /*old_tb_to_new_tb*/) const
00360 {
00361   PRINT_ERROR("Option not supported for mesh based geometry.\n");
00362   return (Surface*) NULL;
00363 }
00364 
00365 //===============================================================================
00366 // Function   : make_extended_sheet
00367 // Member Type: PUBLIC
00368 // Description: make an extended sheet from a set of surfaces
00369 // Author     : 
00370 // Date       : 
00371 //===============================================================================
00372 BodySM* FacetModifyEngine::make_extended_sheet( DLIList<Surface*> & /*surface_list*/,
00373                                  CubitBox * /*clip_box_ptr*/,
00374                                  bool /*preview*/ ) const
00375 {
00376   PRINT_ERROR("Option not supported for mesh based geometry.\n");
00377   return (BodySM*) NULL;
00378 }
00379 
00380 //===============================================================================
00381 // Function   : make_Surface
00382 // Member Type: PUBLIC
00383 // Description: make a surface
00384 // Author     : John Fowler
00385 // Date       : 10/02
00386 //===============================================================================
00387 Surface* FacetModifyEngine::make_Surface( GeometryType /*surface_type*/,
00388                                  DLIList<Curve*>& /*curve_list*/,
00389                                  Surface * /*old_surface_ptr*/,
00390                                  bool /*check_edges*/) const
00391 {
00392   PRINT_ERROR("Option not supported for mesh based geometry.\n");
00393   return (Surface*) NULL;
00394 }
00395 
00396 //===============================================================================
00397 // Function   : make_Lump
00398 // Member Type: PUBLIC
00399 // Description: make a lump
00400 // Author     : John Fowler
00401 // Date       : 10/02
00402 //===============================================================================
00403 Lump* FacetModifyEngine::make_Lump( DLIList<Surface*>& /*surface_list*/ ) const
00404 {
00405   PRINT_ERROR("Option not supported for mesh based geometry.\n");
00406   return (Lump*) NULL;
00407 }
00408 
00409 //===============================================================================
00410 // Function   : make_BodySM
00411 // Member Type: PUBLIC
00412 // Description: make a BodySM
00413 // Author     : John Fowler
00414 // Date       : 10/02
00415 //===============================================================================
00416 BodySM* FacetModifyEngine::make_BodySM( Surface * ) const
00417     {return NULL ;}
00418 
00419 //===============================================================================
00420 // Function   : make_BodySM
00421 // Member Type: PUBLIC
00422 // Description: make a BodySM
00423 // Author     : John Fowler
00424 // Date       : 10/02
00425 //===============================================================================
00426 BodySM* FacetModifyEngine::make_BodySM( DLIList<Lump*>& /*lump_list*/ ) const
00427     {return NULL ;}
00428 
00429 //===============================================================================
00430 // Function   : fillinedge
00431 // Member Type: PRIVATE
00432 // Description: put points on this edge of triangle to be refined
00433 // Author     : John Fowler
00434 // Date       : 11/02
00435 //===============================================================================
00436 void FacetModifyEngine::fillinedge( 
00437   int *edge, 
00438   int numpointsonanedge, 
00439   double radius, 
00440   std::vector<CubitPoint *>& points) const
00441 {
00442     MODIFY_CHECK_RETURN_VOID;
00443   
00444   int numintervals, i;
00445   double xbegin, ybegin, zbegin, xend, yend, zend, xincr, yincr, zincr;
00446   double dist;
00447   CubitPoint *new_point;
00448   
00449   numintervals = numpointsonanedge - 1;
00450   if ( numintervals < 1 ) return;
00451   xbegin = points[edge[0]]->x();
00452   ybegin = points[edge[0]]->y();  
00453   zbegin = points[edge[0]]->z();
00454   xend = points[edge[numintervals]]->x();
00455   yend = points[edge[numintervals]]->y();  
00456   zend = points[edge[numintervals]]->z();  
00457   xincr = (xend-xbegin)/(double)(numintervals);  
00458   yincr = (yend-ybegin)/(double)(numintervals);  
00459   zincr = (zend-zbegin)/(double)(numintervals);  
00460   for ( i = 0; i < numintervals - 1; i++ ) {
00461     xbegin += xincr; 
00462     ybegin += yincr;
00463     zbegin += zincr;
00464 
00465     dist = sqrt(xbegin*xbegin + ybegin*ybegin + zbegin*zbegin);
00466     new_point = (CubitPoint *) new CubitPointData( xbegin*radius/dist, ybegin*radius/dist, 
00467                                 zbegin*radius/dist ); 
00468     edge[i+1] = points.size(); // get the point number
00469     points.push_back(new_point);   
00470   }
00471 
00472 }
00473 
00474 //===============================================================================
00475 // Function   : refinetriangle
00476 // Member Type: PRIVATE
00477 // Description: add internal points and make connections for this triangle
00478 // Author     : John Fowler
00479 // Date       : 11/02
00480 //===============================================================================
00481 void FacetModifyEngine::refinetriangle(
00482   int level, 
00483   int numpointsonanedge, 
00484   int *iedge1, 
00485   int *iedge2, 
00486   int *iedge3,
00487   int isign1, 
00488   int isign2, 
00489   int isign3, 
00490   double radius,
00491   std::vector<CubitPoint *>& points,
00492   DLIList<CubitFacet *>& facet_list) const
00493 {
00494   
00495   MODIFY_CHECK_RETURN_VOID;
00496   
00497 int i, numintervals, icount, j, jcount;
00498 int ntris;
00499 int iedge1cnt, iedge2cnt, iedge3cnt;
00500 
00501 int increment, trissofar, i1s, i2s, i1e;  
00502 int nverts1, nverts;
00503 double dlev;
00504 int *vertnumarray, index, iskip;
00505 CubitFacet *facet_ptr;
00506 CubitPoint *new_point;
00507         double x1inc, y1inc, z1inc, x2inc, y2inc, z2inc;
00508         double xstart, ystart, zstart, xend, yend, zend, dist;
00509             double xinternalinc, yinternalinc, zinternalinc;
00510   
00511   numintervals = numpointsonanedge - 1;
00512   iedge1cnt = ( isign1 == 1 ) ? 0 : numintervals;
00513   iedge2cnt = ( isign2 == 1 ) ? 0 : numintervals;
00514   iedge3cnt = ( isign3 == 1 ) ? 0 : numintervals;
00515 
00516     index = points.size();
00517     dlev = 1. + (double)level;
00518     nverts1 = (int)(0.5*(dlev+1.)*dlev);
00519 
00520     ntris = (level+1)*(level+1);
00521     dlev += 1.; 
00522     nverts = (int)(0.5*(dlev+1.)*dlev);
00523     vertnumarray = new int[nverts];
00524 
00525 //  Put the point numbers for the interior points into vertnumarray.
00526     if ( numintervals > 2 ) {  // numintervals must be at least 3 to make interior points
00527         jcount = 1;
00528         icount = 2;
00529         for ( i = 2; i < numintervals; i++ ) {
00530             icount += 2;
00531             for ( j = 0; j < jcount; j++ ) {
00532                 vertnumarray[icount] = index++;
00533                 icount += 1;
00534             }
00535             jcount += 1;        
00536         }   
00537     }   
00538     i = 3;
00539 
00540     iskip = 2;
00541     vertnumarray[0] = iedge1[iedge1cnt]; iedge1cnt += isign1;
00542     vertnumarray[1] = iedge1[iedge1cnt]; iedge1cnt += isign1;
00543     iedge2cnt += isign2;
00544     vertnumarray[2] = iedge2[iedge2cnt]; iedge2cnt += isign2;
00545 
00546     while ( i < nverts1 ) {
00547         vertnumarray[i] = iedge1[iedge1cnt]; iedge1cnt += isign1;
00548         vertnumarray[i+iskip] = iedge2[iedge2cnt]; iedge2cnt += isign2;
00549         i += iskip+1;
00550         iskip += 1; 
00551     }
00552     for ( i = nverts1; i < nverts; i++ ) {
00553         vertnumarray[i] = iedge3[iedge3cnt]; iedge3cnt += isign3;
00554     }   
00555     
00556 
00558 
00559     if ( numintervals > 2 ) {
00560         int i1first, i1last, i2first, i2last;
00561         if ( isign1 == 1 ) {
00562             i1first = 0; i1last = numintervals;
00563         } else {
00564             i1last = 0; i1first = numintervals;
00565         }
00566         if ( isign2 == 1 ) {
00567             i2first = 0; i2last = numintervals;
00568         } else {
00569             i2last = 0; i2first = numintervals;
00570         }
00571         x1inc = (points[iedge1[i1last]]->x() - points[iedge1[i1first]]->x())/numintervals;  
00572         y1inc = (points[iedge1[i1last]]->y() - points[iedge1[i1first]]->y())/numintervals;  
00573         z1inc = (points[iedge1[i1last]]->z() - points[iedge1[i1first]]->z())/numintervals;  
00574         x2inc = (points[iedge2[i2last]]->x() - points[iedge2[i2first]]->x())/numintervals;  
00575         y2inc = (points[iedge2[i2last]]->y() - points[iedge2[i2first]]->y())/numintervals;  
00576         z2inc = (points[iedge2[i2last]]->z() - points[iedge2[i2first]]->z())/numintervals;  
00577 
00578         icount = 2;
00579         jcount = 1;
00580         for ( i = 2; i < numintervals; i++ ) {
00581         xstart = points[iedge1[i1first]]->x() + (double)i*x1inc;
00582         ystart = points[iedge1[i1first]]->y() + (double)i*y1inc;
00583         zstart = points[iedge1[i1first]]->z() + (double)i*z1inc;
00584         xend = points[iedge2[i2first]]->x() + (double)i*x2inc;
00585         yend = points[iedge2[i2first]]->y() + (double)i*y2inc;
00586         zend = points[iedge2[i2first]]->z() + (double)i*z2inc;
00587             xinternalinc = (xend-xstart)/(icount);    
00588             yinternalinc = (yend-ystart)/(icount);    
00589             zinternalinc = (zend-zstart)/(icount);    
00590                 for ( j = 0; j < jcount; j++ ) {
00591                     xstart += xinternalinc;
00592                     ystart += yinternalinc;
00593                     zstart += zinternalinc;
00594 
00595                         dist = sqrt(xstart*xstart + ystart*ystart + zstart*zstart);
00596                     new_point = (CubitPoint *) new CubitPointData( xstart*radius/dist, 
00597                                             ystart*radius/dist,
00598                                             zstart*radius/dist );
00599                     points.push_back(new_point);                    
00600                 }
00601             icount += 1;
00602             jcount += 1;
00603         }   
00604     
00605     }
00606 
00608     increment = trissofar = 0;
00609     i1s = 0;
00610     i2s = 1;
00611     while ( trissofar < ntris ) {
00612         i1e = i1s + increment;
00613         while ( i1s < i1e) {
00614             facet_ptr = new CubitFacetData( points[vertnumarray[i1s]],
00615                             points[vertnumarray[i2s]], 
00616                             points[vertnumarray[i2s+1]] );
00617             facet_list.append( facet_ptr );
00618             facet_ptr = new CubitFacetData( points[vertnumarray[i1s]],
00619                             points[vertnumarray[i2s+1]], 
00620                             points[vertnumarray[i1s+1]] );
00621             facet_list.append( facet_ptr );
00622             i1s++;
00623             i2s++;
00624             trissofar += 2;
00625         }
00626             facet_ptr = new CubitFacetData( points[vertnumarray[i1s]],
00627                             points[vertnumarray[i2s]], 
00628                             points[vertnumarray[i2s+1]] );
00629             facet_list.append( facet_ptr );
00630         increment++;
00631         trissofar++;
00632         i1s++;
00633         i2s += 2;
00634     }
00635     delete [] vertnumarray;
00636 }
00637 
00638 //===============================================================================
00639 // Function   : sphere
00640 // Member Type: PUBLIC
00641 // Description: build a sphere with facets
00642 // Author     : John Fowler
00643 // Date       : 10/02
00644 //===============================================================================
00645 BodySM* FacetModifyEngine::sphere(double radius) const
00646 {
00647   MODIFY_CHECK_RETURN_NULL;
00648   
00649   CubitStatus rv = CUBIT_SUCCESS;
00650   DLIList <CubitFacet *>facet_list;
00651   DLIList <CubitPoint *>point_list;
00652   CubitPoint *new_point;
00653   double feature_angle;
00654   int i, interp_order;
00655   CubitBoolean smooth_non_manifold, split_surfaces;
00656   BodySM *body_ptr = NULL;
00657   std::vector<CubitPoint *> points;
00663   const double xp = 0.525731112119133606*radius, zp = 0.850650808352039932*radius;
00666   int level, numpointsonanedge;
00667   int *edge[30];
00670 /*
00671   const int basefacets[20][3] = { {0,1,2},{0,2,3},{3,2,4},{2,5,4},
00672                   {2,1,5},{5,1,6},{5,6,7},{4,5,7},
00673                   {4,7,8},{8,7,9},{9,7,6},{9,6,10},
00674                   {9,10,11},{11,10,0},{0,10,1},{10,6,1},
00675                   {3,11,0},{3,8,11},{3,4,8},{9,11,8} };
00676 */
00677   const int edgeendverts[30][2] = { {0,1},{0,2},{0,3},{0,11},{0,10},{1,2},
00678                         {1,5},{1,6},{1,10},{2,3},{2,4},{2,5},
00679                         {3,4},{3,8},{3,11},{4,5},{4,7},{4,8},
00680                         {5,6},{5,7},{6,7},{6,9},{6,10},{7,8},
00681                         {7,9},{8,9},{8,11},{9,10},{9,11},{10,11} };
00686   const int triedges[20][3] = { {1,2,6},{2,3,10},{-10,13,11},{12,11,-16,},
00687                 {-6,12,7,},{-7,19,8,},{19,20,21},{16,17,20},
00688                 {17,18,24,},{-24,26,25},{-25,-22,-21},{-22,28,23},
00689                 {28,29,30},{-30,-4,-5},{5,1,-9},{-23,-9,-8},
00690                 {15,-3,-4},{14,15,27},{13,14,18},{29,-26,-27} };
00692   const double svert[12][3] = { {-xp,0.,zp}, {xp,0.,zp}, {0.,zp,xp}, {-zp, xp, 0.},
00693                 {0.,zp,-xp}, {zp,xp,0.}, {zp,-xp,0.}, {xp,0.,-zp},
00694                 {-xp,0.,-zp}, {0.,-zp,-xp}, {0.,-zp,xp}, {-zp,-xp,0.} };
00695     
00696   level = 7;  // gives a sphere with 642 vertices and 1280 triangles.
00697           // Eventually this should be user-selectable.
00698   numpointsonanedge = 2 + level;  
00699 
00700   for ( i = 0; i < 30; i++ ) { // make the edges
00701     edge[i] = new int[numpointsonanedge];
00702     edge[i][0] = edgeendverts[i][0];
00703     edge[i][numpointsonanedge-1] = edgeendverts[i][1];
00704   }
00705   
00706   for ( i = 0; i < 12; i++ ) { // make the icosahedron vertices
00707     new_point = (CubitPoint *) new CubitPointData( svert[i][0],svert[i][1],svert[i][2] );
00708     points.push_back(new_point);
00709   }
00710    
00711   for ( i = 0; i < 30; i++ ) { // put points on the edges
00712     fillinedge(edge[i], numpointsonanedge, radius, points); 
00713   }
00714 
00715  int sign1, sign2, sign3, edg1, edg2, edg3; 
00716   for ( i = 0; i < 20; i++ ) { // refine the 20 triangles
00717     edg1 = ( triedges[i][0] > 0 ) ? triedges[i][0] - 1 : -triedges[i][0] - 1;
00718     edg2 = ( triedges[i][1] > 0 ) ? triedges[i][1] - 1 : -triedges[i][1] - 1;
00719     edg3 = ( triedges[i][2] > 0 ) ? triedges[i][2] - 1 : -triedges[i][2] - 1;
00721     sign1 = ( triedges[i][0] > 0 ) ? 1 : -1;
00722     sign2 = ( triedges[i][1] > 0 ) ? 1 : -1;
00723     sign3 = ( triedges[i][2] > 0 ) ? 1 : -1;
00724     
00725     refinetriangle(level,numpointsonanedge,edge[edg1],edge[edg2],edge[edg3],
00726             sign1,sign2,sign3,radius,points,facet_list);
00727   }
00728 
00730   for ( unsigned int z = 0; z < points.size(); z++ ) {
00731     point_list.append(points[z]);
00732   }
00733 
00734   points.clear();
00735 
00736   for ( i = 0; i < 30; i++ ) delete[] edge[i];  
00737   feature_angle = -1.0;
00738   interp_order = 0;
00739   smooth_non_manifold = CUBIT_TRUE;
00740   split_surfaces = CUBIT_FALSE;
00741 
00742   ChollaEngine *cholla_ptr = NULL;
00743   FacetModifyEngine *fme = const_cast<FacetModifyEngine *> (this);
00744   rv = fme->build_cholla_surfaces( facet_list,
00745                                    point_list,
00746                                    feature_angle,
00747                                    interp_order,
00748                                    smooth_non_manifold,
00749                                    split_surfaces,
00750                                    cholla_ptr );
00751   if ( rv == CUBIT_SUCCESS )
00752   {
00753       CubitEvaluatorData **sphere_data;
00754 
00755       set_sphere_eval_data( cholla_ptr, radius, sphere_data );
00756 
00757       finish_facet_Body( cholla_ptr,
00758                          (const CubitEvaluatorData **)sphere_data,
00759                          feature_angle,
00760                          interp_order,
00761                          body_ptr);
00762 
00763       if ( cholla_ptr )
00764       {
00765          cholla_ptr->delete_me();
00766          delete cholla_ptr;
00767       }
00768       if ( sphere_data[0] ) delete sphere_data[0];
00769       delete sphere_data;
00770   }
00771   return body_ptr;
00772 }
00773 
00774 CubitStatus FacetModifyEngine::remove_topology(DLIList<Curve*> &curves_to_remove,
00775                                        DLIList<Surface*> &surfs_to_remove,
00776                                        double backoff_distance,
00777                                        double small_edge_size,
00778                                        DLIList<BodySM*> &new_bodysm_list,
00779                                        CubitBoolean preview) const
00780 {
00781    PRINT_INFO("This functionality is not implemented for faceted geometry.\n");
00782    return CUBIT_FAILURE;
00783 }
00784 
00785 void FacetModifyEngine::set_sphere_eval_data
00786 (
00787     ChollaEngine *cholla_ptr,
00788     double radius,
00789     CubitEvaluatorData **&eval_data ) const
00790 {
00791   
00792   //MODIFY_CHECK_RETURN_VOID;
00793   
00794   eval_data = new CubitEvaluatorData*;
00795 
00796     SphereEvaluatorData *data = new SphereEvaluatorData;
00797     data->radius = radius;
00798     data->center.set( 0.0, 0.0, 0.0 );
00799     eval_data[0] = data;
00800 }
00801 
00802 //===============================================================================
00803 // Function   : brick
00804 // Member Type: PUBLIC
00805 // Description: build a brick with facets
00806 // Author     : John Fowler
00807 // Date       : 10/02
00808 //===============================================================================
00809 BodySM* FacetModifyEngine::brick( double wid, double dep, double hi ) const
00810 {
00811   
00812 
00813   MODIFY_CHECK_RETURN_NULL;
00814   CubitStatus rv = CUBIT_SUCCESS;
00815   double xmin, xmax, ymin, ymax, zmin, zmax;
00816   DLIList <CubitFacet *>facet_list;
00817   DLIList <CubitPoint *>point_list;
00818   CubitPoint *new_point;
00819   CubitFacet *facet_ptr;
00820   int i, numpoints;
00821   double feature_angle;
00822   int interp_order;
00823   CubitBoolean smooth_non_manifold, split_surfaces;
00824   BodySM *body_ptr = NULL;
00825   std::vector<CubitPoint *> points;
00826   
00827   numpoints = 14;
00828   
00829   xmin = -0.5*wid;
00830   xmax = 0.5*wid;
00831   ymin = -0.5*dep;
00832   ymax = 0.5*dep;
00833   zmin = -0.5*hi;
00834   zmax = 0.5*hi;
00835   
00836   new_point = (CubitPoint *) new CubitPointData( xmin,ymin,zmin ); 
00837   points.push_back(new_point);
00838   new_point = (CubitPoint *) new CubitPointData( xmax,ymin,zmin ); 
00839   points.push_back(new_point);
00840   new_point = (CubitPoint *) new CubitPointData( xmax,ymin,zmax ); 
00841   points.push_back(new_point);  
00842   new_point = (CubitPoint *) new CubitPointData( xmin,ymin,zmax ); 
00843   points.push_back(new_point); 
00844   new_point = (CubitPoint *) new CubitPointData( xmin,ymax,zmin ); 
00845   points.push_back(new_point);
00846   new_point = (CubitPoint *) new CubitPointData( xmax,ymax,zmin ); 
00847   points.push_back(new_point);
00848   new_point = (CubitPoint *) new CubitPointData( xmax,ymax,zmax ); 
00849   points.push_back(new_point);  
00850   new_point = (CubitPoint *) new CubitPointData( xmin,ymax,zmax ); 
00851   points.push_back(new_point);   
00852   new_point = (CubitPoint *) new CubitPointData( 0.5*(xmin+xmax),0.5*(ymin+ymax),zmin ); 
00853   points.push_back(new_point);  
00854   new_point = (CubitPoint *) new CubitPointData( xmax,0.5*(ymin+ymax),0.5*(zmin+zmax) ); 
00855   points.push_back(new_point);    
00856   new_point = (CubitPoint *) new CubitPointData( 0.5*(xmin+xmax),0.5*(ymin+ymax),zmax ); 
00857   points.push_back(new_point);  
00858   new_point = (CubitPoint *) new CubitPointData( xmin,0.5*(ymin+ymax),0.5*(zmin+zmax) ); 
00859   points.push_back(new_point);   
00860   new_point = (CubitPoint *) new CubitPointData( 0.5*(xmin+xmax),ymin,0.5*(zmin+zmax) ); 
00861   points.push_back(new_point);   
00862   new_point = (CubitPoint *) new CubitPointData( 0.5*(xmin+xmax),ymax,0.5*(zmin+zmax) ); 
00863   points.push_back(new_point);   
00864   
00865   for ( i = 0; i < numpoints; i++ ) {
00866     point_list.append(points[i]);
00867   }    
00868   
00869   // bottom face      
00870   facet_ptr = new CubitFacetData( points[0],points[1], points[12] );
00871   facet_list.append( facet_ptr );
00872   facet_ptr = new CubitFacetData( points[1],points[2], points[12] );
00873   facet_list.append( facet_ptr );
00874   facet_ptr = new CubitFacetData( points[2],points[3], points[12] );
00875   facet_list.append( facet_ptr );
00876   facet_ptr = new CubitFacetData( points[3],points[0], points[12] );
00877   // back face
00878   facet_list.append( facet_ptr );
00879   facet_ptr = new CubitFacetData( points[1],points[0], points[8] );
00880   facet_list.append( facet_ptr );
00881   facet_ptr = new CubitFacetData( points[5],points[1], points[8] );
00882   facet_list.append( facet_ptr );  
00883   facet_ptr = new CubitFacetData( points[4],points[5], points[8] );
00884   facet_list.append( facet_ptr );
00885   facet_ptr = new CubitFacetData( points[0],points[4], points[8] );
00886   facet_list.append( facet_ptr );
00887   // left face
00888   facet_ptr = new CubitFacetData( points[0],points[3], points[11] );
00889   facet_list.append( facet_ptr );
00890   facet_ptr = new CubitFacetData( points[3],points[7], points[11] );
00891   facet_list.append( facet_ptr );
00892   facet_ptr = new CubitFacetData( points[7],points[4], points[11] );
00893   facet_list.append( facet_ptr );
00894   facet_ptr = new CubitFacetData( points[4],points[0], points[11] );
00895   facet_list.append( facet_ptr ); 
00896   // top face
00897   facet_ptr = new CubitFacetData( points[7],points[6], points[13] );
00898   facet_list.append( facet_ptr );
00899   facet_ptr = new CubitFacetData( points[6],points[5], points[13] );
00900   facet_list.append( facet_ptr );
00901   facet_ptr = new CubitFacetData( points[5],points[4], points[13] );
00902   facet_list.append( facet_ptr );
00903   facet_ptr = new CubitFacetData( points[4],points[7], points[13] );
00904   facet_list.append( facet_ptr ); 
00905   // right face
00906   facet_ptr = new CubitFacetData( points[1],points[5], points[9] );
00907   facet_list.append( facet_ptr );
00908   facet_ptr = new CubitFacetData( points[5],points[6], points[9] );
00909   facet_list.append( facet_ptr );
00910   facet_ptr = new CubitFacetData( points[6],points[2], points[9] );
00911   facet_list.append( facet_ptr );
00912   facet_ptr = new CubitFacetData( points[2],points[1], points[9] );
00913   facet_list.append( facet_ptr ); 
00914   // front face  
00915   facet_ptr = new CubitFacetData( points[3],points[2], points[10] );
00916   facet_list.append( facet_ptr );
00917   facet_ptr = new CubitFacetData( points[2],points[6], points[10] );
00918   facet_list.append( facet_ptr );
00919   facet_ptr = new CubitFacetData( points[6],points[7], points[10] );
00920   facet_list.append( facet_ptr );
00921   facet_ptr = new CubitFacetData( points[7],points[3], points[10] );
00922   facet_list.append( facet_ptr );   
00923   
00924   points.clear(); //  clear out the points vector since we are through with it.
00925   
00926   feature_angle = 100.0;
00927   interp_order = 0;
00928   smooth_non_manifold = CUBIT_TRUE;
00929   split_surfaces = CUBIT_FALSE;
00930   
00931   ChollaEngine *cholla_ptr = NULL;
00932   FacetModifyEngine *fme = const_cast<FacetModifyEngine *> (this);
00933   rv = fme->build_cholla_surfaces( facet_list,
00934                                    point_list,
00935                                    feature_angle,
00936                                    interp_order,
00937                                    smooth_non_manifold,
00938                                    split_surfaces,
00939                                    cholla_ptr );
00940   if ( rv == CUBIT_SUCCESS )
00941   {
00942       finish_facet_Body( cholla_ptr,
00943                          NULL,
00944                          feature_angle,
00945                          interp_order,
00946                          body_ptr);
00947       if ( cholla_ptr )
00948       {
00949          cholla_ptr->delete_me();
00950          delete cholla_ptr;
00951       }
00952 
00953   }
00954   return body_ptr;
00955 }
00956 
00957 //===============================================================================
00958 // Function   : finish_facet_Body
00959 // Member Type: PRIVATE
00960 // Description: general function for creating a facet-based Body given a closed
00961 //              set of facets
00962 // Author     : John Fowler
00963 // Date       : 10/02
00964 //===============================================================================
00965 CubitStatus FacetModifyEngine::finish_facet_Body( ChollaEngine *cholla_ptr,
00966                                                   const CubitEvaluatorData **eval_data,
00967                                                   double feature_angle,
00968                                                   int interp_order,
00969                                                   BodySM *&bodysm_ptr) const
00970 {
00971 
00972   MODIFY_CHECK_RETURN_FAILURE;
00973   
00974   DLIList<Surface *> surface_list;
00975   ShellSM *shell_ptr;
00976   DLIList<ShellSM*> shell_list;
00977   Lump *lump_ptr;
00978   DLIList<Lump*> lump_list;
00979   CubitStatus rv;
00980   DLIList<ChollaSurface *> cholla_surface_list;
00981   DLIList<ChollaCurve *> cholla_curve_list;
00982   DLIList<ChollaPoint *> cholla_point_list;
00983 
00984   cholla_ptr->get_curves( cholla_curve_list );
00985   cholla_ptr->get_surfaces( cholla_surface_list );
00986   cholla_ptr->get_points( cholla_point_list );
00987 
00988   CubitBoolean use_feature_angle;
00989   if (feature_angle < 0.0)
00990     use_feature_angle = CUBIT_FALSE;
00991   else
00992     use_feature_angle = CUBIT_TRUE;
00993   
00994   GeometryQueryTool *gti = GeometryQueryTool::instance();  
00995   
00996   FacetModifyEngine *fme = const_cast<FacetModifyEngine *> (this);
00997 
00998   rv = fme->build_cholla_geometry( eval_data,
00999                                    cholla_surface_list,
01000                                    cholla_curve_list,
01001                                    cholla_point_list,
01002                                    use_feature_angle, 
01003                                    feature_angle,
01004                                    interp_order, surface_list );
01005   
01006   if ( surface_list.size() == 0 || rv != CUBIT_SUCCESS )
01007   {
01008     PRINT_ERROR("Problems building facet based surfaces.\n");
01009     rv = CUBIT_FAILURE;
01010     goto end_brick;
01011   }
01012 
01013   // make a body out of it
01014   rv = fme->make_facet_shell(surface_list,shell_ptr);
01015   if ( shell_ptr == NULL || rv != CUBIT_SUCCESS )
01016   {
01017     PRINT_ERROR("Problems building facet based shell entity.\n");
01018     rv = CUBIT_FAILURE;
01019     goto end_brick;
01020   } 
01021       //Set the sense for the surfaces (will be cofaces) on this shell.
01022       //Assumption: The sense is always forward when creating geom from facets.
01023       // (This may not be correct -especially with multiple shells in a body)
01024   int ii;
01025   FacetShell* facet_shell;
01026   facet_shell = CAST_TO( shell_ptr, FacetShell );
01027   for( ii = surface_list.size(); ii > 0; ii-- )
01028   {
01029     Surface* surf = surface_list.get_and_step();
01030     FacetSurface* facet_surf = CAST_TO( surf, FacetSurface );
01031     facet_surf->set_shell_sense( facet_shell, CUBIT_FORWARD );
01032   }
01033                  
01034   shell_list.append(shell_ptr);
01035   rv = fme->make_facet_lump(shell_list,lump_ptr);
01036   if ( lump_ptr == NULL || rv != CUBIT_SUCCESS )
01037   {
01038     PRINT_ERROR("Problems building facet based lump entity.\n");
01039     rv = CUBIT_FAILURE;
01040     goto end_brick;
01041   }
01042   lump_list.append(lump_ptr);
01043   rv = fme->make_facet_body(lump_list,bodysm_ptr);
01044   
01045   if ( rv != CUBIT_SUCCESS )
01046   {
01047     PRINT_ERROR("Problems building facet based body entity.\n");
01048     rv = CUBIT_FAILURE;
01049     goto end_brick;
01050   }
01051   
01052   PRINT_INFO("Body successfully created.\n");
01053   PRINT_INFO("  Number of vertices = %d\n", gti->num_ref_vertices());
01054   PRINT_INFO("  Number of edges = %d\n", gti->num_ref_edges());
01055   PRINT_INFO("  Number of faces = %d\n", gti->num_ref_faces());
01056   PRINT_INFO("  Number of volumes = %d\n", gti->num_ref_volumes());
01057   PRINT_INFO("  Number of bodies = %d\n", gti->num_bodies());
01058    
01059   return rv;
01060   
01061 end_brick:
01062   bodysm_ptr = (BodySM *)NULL;
01063   return rv;
01064   
01065 }
01066 
01067 CubitStatus FacetModifyEngine::finish_facet_Body( DLIList<Surface*>& surface_list, DLIList<CubitSense>& surface_sense,
01068                                                   BodySM *&bodysm_ptr) const
01069 {
01070   ShellSM *shell_ptr;
01071   DLIList<ShellSM*> shell_list;
01072   Lump *lump_ptr;
01073   DLIList<Lump*> lump_list;
01074   CubitStatus rv;
01075   
01076   FacetModifyEngine *fme = const_cast<FacetModifyEngine *> (this);
01077 
01078   if ( surface_list.size() == 0 )
01079   {
01080     PRINT_ERROR("Problems building facet based surfaces.\n");
01081     rv = CUBIT_FAILURE;
01082     goto end_brick;
01083   }
01084 
01085   // make a body out of it
01086   rv = fme->make_facet_shell(surface_list,shell_ptr);
01087   if ( shell_ptr == NULL || rv != CUBIT_SUCCESS )
01088   {
01089     PRINT_ERROR("Problems building facet based shell entity.\n");
01090     rv = CUBIT_FAILURE;
01091     goto end_brick;
01092   } 
01093 
01094   int ii;
01095   FacetShell* facet_shell;
01096   facet_shell = CAST_TO( shell_ptr, FacetShell );
01097   for( ii = 0; ii< surface_list.size(); ii++)
01098   {
01099     Surface* surf = surface_list[ii];
01100     FacetSurface* facet_surf = CAST_TO( surf, FacetSurface );
01101     facet_surf->set_shell_sense( facet_shell, surface_sense[ii] );
01102   }
01103 
01104   shell_list.append(shell_ptr);
01105   rv = fme->make_facet_lump(shell_list,lump_ptr);
01106   if ( lump_ptr == NULL || rv != CUBIT_SUCCESS )
01107   {
01108     PRINT_ERROR("Problems building facet based lump entity.\n");
01109     rv = CUBIT_FAILURE;
01110     goto end_brick;
01111   }
01112   lump_list.append(lump_ptr);
01113   rv = fme->make_facet_body(lump_list,bodysm_ptr);
01114   
01115   if ( rv != CUBIT_SUCCESS )
01116   {
01117     PRINT_ERROR("Problems building facet based body entity.\n");
01118     rv = CUBIT_FAILURE;
01119     goto end_brick;
01120   }
01121   
01122   return rv;
01123   
01124 end_brick:
01125   bodysm_ptr = (BodySM *)NULL;
01126   return rv;
01127   
01128 }
01129 
01130 //===============================================================================
01131 // Function   : brick
01132 // Member Type: PUBLIC
01133 // Description: create a brick with facets given center axes and extension
01134 // Author     : Steve Owen
01135 // Date       : 1/09
01136 //===============================================================================
01137 BodySM* FacetModifyEngine::brick( const CubitVector &center, 
01138                                   const CubitVector axes[3],
01139                                   const CubitVector &extension) const
01140 {
01141   
01142     
01143   MODIFY_CHECK_RETURN_NULL;
01144   CubitStatus rv = CUBIT_SUCCESS;
01145   CubitVector uvec, vvec, wvec, corner, mid;
01146   DLIList <CubitFacet *>facet_list;
01147   DLIList <CubitPoint *>point_list;
01148   CubitPoint *new_point;
01149   CubitFacet *facet_ptr;
01150   int i, numpoints;
01151   double feature_angle;
01152   int interp_order;
01153   CubitBoolean smooth_non_manifold, split_surfaces;
01154   BodySM *body_ptr = NULL;
01155   std::vector<CubitPoint *> points;
01156   
01157   numpoints = 14;
01158   
01159     uvec = extension.x() * axes[0];
01160     vvec = extension.y() * axes[1];
01161     wvec = extension.z() * axes[2];
01162   
01163     corner = center - uvec - vvec - wvec; 
01164   new_point = (CubitPoint *) new CubitPointData( corner.x(),corner.y(),corner.z() ); 
01165   points.push_back(new_point);
01166     
01167     corner = center + uvec - vvec - wvec;
01168   new_point = (CubitPoint *) new CubitPointData( corner.x(),corner.y(),corner.z() ); 
01169   points.push_back(new_point);
01170     
01171     corner = center + uvec - vvec + wvec;
01172   new_point = (CubitPoint *) new CubitPointData( corner.x(),corner.y(),corner.z() ); 
01173   points.push_back(new_point);
01174   
01175     corner = center - uvec - vvec + wvec;
01176   new_point = (CubitPoint *) new CubitPointData( corner.x(),corner.y(),corner.z() ); 
01177   points.push_back(new_point); 
01178     
01179     corner = center - uvec + vvec - wvec;
01180   new_point = (CubitPoint *) new CubitPointData( corner.x(),corner.y(),corner.z() ); 
01181   points.push_back(new_point);
01182     
01183     corner = center + uvec + vvec - wvec;
01184   new_point = (CubitPoint *) new CubitPointData( corner.x(),corner.y(),corner.z() ); 
01185   points.push_back(new_point);
01186     
01187     corner = center + uvec + vvec + wvec;
01188   new_point = (CubitPoint *) new CubitPointData( corner.x(),corner.y(),corner.z() ); 
01189   points.push_back(new_point);  
01190     
01191     corner = center - uvec + vvec + wvec;
01192   new_point = (CubitPoint *) new CubitPointData( corner.x(),corner.y(),corner.z() ); 
01193   points.push_back(new_point);   
01194     
01195     mid = center - wvec;
01196   new_point = (CubitPoint *) new CubitPointData( mid.x(), mid.y(), mid.z() ); 
01197   points.push_back(new_point);
01198     
01199     mid = center + uvec;
01200   new_point = (CubitPoint *) new CubitPointData( mid.x(), mid.y(), mid.z() ); 
01201   points.push_back(new_point);  
01202   
01203     mid = center + wvec;
01204   new_point = (CubitPoint *) new CubitPointData( mid.x(), mid.y(), mid.z() ); 
01205   points.push_back(new_point);  
01206     
01207     mid = center - uvec;
01208   new_point = (CubitPoint *) new CubitPointData( mid.x(), mid.y(), mid.z() ); 
01209   points.push_back(new_point); 
01210   
01211     mid = center - vvec;
01212   new_point = (CubitPoint *) new CubitPointData( mid.x(), mid.y(), mid.z() ); 
01213   points.push_back(new_point); 
01214   
01215     mid = center + vvec;
01216   new_point = (CubitPoint *) new CubitPointData( mid.x(), mid.y(), mid.z() ); 
01217   points.push_back(new_point);   
01218   
01219   for ( i = 0; i < numpoints; i++ ) {
01220     point_list.append(points[i]);
01221   }    
01222   
01223   // bottom face      
01224   facet_ptr = new CubitFacetData( points[0],points[1], points[12] );
01225   facet_list.append( facet_ptr );
01226   facet_ptr = new CubitFacetData( points[1],points[2], points[12] );
01227   facet_list.append( facet_ptr );
01228   facet_ptr = new CubitFacetData( points[2],points[3], points[12] );
01229   facet_list.append( facet_ptr );
01230   facet_ptr = new CubitFacetData( points[3],points[0], points[12] );
01231   // back face
01232   facet_list.append( facet_ptr );
01233   facet_ptr = new CubitFacetData( points[1],points[0], points[8] );
01234   facet_list.append( facet_ptr );
01235   facet_ptr = new CubitFacetData( points[5],points[1], points[8] );
01236   facet_list.append( facet_ptr );  
01237   facet_ptr = new CubitFacetData( points[4],points[5], points[8] );
01238   facet_list.append( facet_ptr );
01239   facet_ptr = new CubitFacetData( points[0],points[4], points[8] );
01240   facet_list.append( facet_ptr );
01241   // left face
01242   facet_ptr = new CubitFacetData( points[0],points[3], points[11] );
01243   facet_list.append( facet_ptr );
01244   facet_ptr = new CubitFacetData( points[3],points[7], points[11] );
01245   facet_list.append( facet_ptr );
01246   facet_ptr = new CubitFacetData( points[7],points[4], points[11] );
01247   facet_list.append( facet_ptr );
01248   facet_ptr = new CubitFacetData( points[4],points[0], points[11] );
01249   facet_list.append( facet_ptr ); 
01250   // top face
01251   facet_ptr = new CubitFacetData( points[7],points[6], points[13] );
01252   facet_list.append( facet_ptr );
01253   facet_ptr = new CubitFacetData( points[6],points[5], points[13] );
01254   facet_list.append( facet_ptr );
01255   facet_ptr = new CubitFacetData( points[5],points[4], points[13] );
01256   facet_list.append( facet_ptr );
01257   facet_ptr = new CubitFacetData( points[4],points[7], points[13] );
01258   facet_list.append( facet_ptr ); 
01259   // right face
01260   facet_ptr = new CubitFacetData( points[1],points[5], points[9] );
01261   facet_list.append( facet_ptr );
01262   facet_ptr = new CubitFacetData( points[5],points[6], points[9] );
01263   facet_list.append( facet_ptr );
01264   facet_ptr = new CubitFacetData( points[6],points[2], points[9] );
01265   facet_list.append( facet_ptr );
01266   facet_ptr = new CubitFacetData( points[2],points[1], points[9] );
01267   facet_list.append( facet_ptr ); 
01268   // front face  
01269   facet_ptr = new CubitFacetData( points[3],points[2], points[10] );
01270   facet_list.append( facet_ptr );
01271   facet_ptr = new CubitFacetData( points[2],points[6], points[10] );
01272   facet_list.append( facet_ptr );
01273   facet_ptr = new CubitFacetData( points[6],points[7], points[10] );
01274   facet_list.append( facet_ptr );
01275   facet_ptr = new CubitFacetData( points[7],points[3], points[10] );
01276   facet_list.append( facet_ptr );   
01277   
01278   points.clear(); //  clear out the points vector since we are through with it.
01279   
01280   feature_angle = 100.0;
01281   interp_order = 0;
01282   smooth_non_manifold = CUBIT_TRUE;
01283   split_surfaces = CUBIT_FALSE;
01284   
01285   ChollaEngine *cholla_ptr = NULL;
01286   FacetModifyEngine *fme = const_cast<FacetModifyEngine *> (this);
01287   rv = fme->build_cholla_surfaces( facet_list,
01288                                                                     point_list,
01289                                                                     feature_angle,
01290                                                                     interp_order,
01291                                                                     smooth_non_manifold,
01292                                                                     split_surfaces,
01293                                                                     cholla_ptr );
01294   if ( rv == CUBIT_SUCCESS )
01295   {
01296         finish_facet_Body( cholla_ptr,
01297                                             NULL,
01298                                             feature_angle,
01299                                             interp_order,
01300                                             body_ptr);
01301         if ( cholla_ptr )
01302         {
01303             cholla_ptr->delete_me();
01304             delete cholla_ptr;
01305         }
01306         
01307   }
01308   return body_ptr;
01309 }
01310 
01311 //===============================================================================
01312 // Function   : prism
01313 // Member Type: PUBLIC
01314 // Description: create a prism with facets
01315 // Author     : John Fowler
01316 // Date       : 10/02
01317 //===============================================================================
01318 BodySM* FacetModifyEngine::prism( double /*height*/, int /*sides*/, double /*major*/,
01319                                double /*minor*/) const
01320 {
01321   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01322   return (BodySM*) NULL;
01323 }
01324 
01325 //===============================================================================
01326 // Function   : pyramid
01327 // Member Type: PUBLIC
01328 // Description: create a pyramid with facets
01329 // Author     : John Fowler
01330 // Date       : 10/02
01331 //===============================================================================
01332 BodySM* FacetModifyEngine::pyramid( double /*height*/, int /*sides*/, double /*major*/,
01333                                  double /*minor*/, double /*top*/) const
01334 {
01335   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01336   return (BodySM*) NULL;
01337 }
01338 
01339 //===============================================================================
01340 // Function   : cylinder
01341 // Member Type: PUBLIC
01342 // Description: create a cylinder with facets
01343 // Author     : John Fowler
01344 // Date       : 10/02
01345 //===============================================================================
01346 BodySM* FacetModifyEngine::cylinder( double hi, double r1, double r2, double r3 ) const
01347 {
01348   MODIFY_CHECK_RETURN_NULL;
01349 
01350   CubitStatus rv = CUBIT_SUCCESS;
01351   DLIList <CubitFacet *>facet_list;
01352   DLIList <CubitPoint *>point_list;
01353   CubitPoint *new_point;
01354   CubitFacet *facet_ptr;
01355   int i, j, numpoints;
01356   double feature_angle;
01357   int interp_order;
01358   CubitBoolean smooth_non_manifold, split_surfaces;
01359   BodySM *body_ptr = NULL;
01360   std::vector<CubitPoint *> points;
01361   int reslevel;  // relative level of resolution
01362   int nl;  // number of axial divisions
01363   int nr;  // number of radil divisions
01364   double cfac, rinc, linc;
01365   double x, y, z;
01366   int istart, iend, V3, pend;
01367   double zoffset, lpos, rpos, xrad, yrad;
01368   double rad_ratio = 1.0;
01369 
01370   reslevel = 4;
01371   nl = reslevel;
01372   nr = 8*reslevel;
01373     
01374   rinc = 360.0/(double)nr;
01375   linc = hi/(double)nl;
01376   cfac = CUBIT_PI/180.;
01377   
01378   if ( r3 > 0.0 ) {
01379     //  Cylinder:
01380     numpoints = (nl + 1)*nr + 2;
01381     istart = 0; iend = nl+1;
01382     V3 = (nl+1)*nr;
01383     pend = nl;
01384     rad_ratio = r2/r1;
01385   } else {
01386     //  Cone:
01387     numpoints = nl*nr + 2;
01388     istart = 0; iend = nl;
01389     V3 = nl*nr;
01390     pend = nl-1;
01391   }
01392   
01393   //  Make the points.
01394   
01395   zoffset = 0.0;
01396   lpos = -0.5*hi; 
01397   xrad = r1;
01398   yrad = r2;
01399   for ( i = istart; i < iend; i++ ) {
01400     rpos = 10.0;
01401     xrad = zoffset*r3/hi + (hi - zoffset)*r1/hi;
01402     yrad = zoffset*r3*rad_ratio/hi + (hi - zoffset)*r2/hi;
01403     for ( j = 0; j < nr; j++ ) {
01404       x = xrad*cos(cfac*rpos);
01405       y = yrad*sin(cfac*rpos);
01406       z = lpos;
01407       new_point = (CubitPoint *) new CubitPointData( x,y,z );
01408       points.push_back(new_point);
01409       rpos += rinc;   
01410     }
01411     lpos += linc;
01412     zoffset += linc;
01413   } 
01414   //  Add the two apoint on the axis at the ends.
01415   new_point = (CubitPoint *) new CubitPointData( 0.,0.,-0.5*hi );
01416   points.push_back(new_point);
01417   new_point = (CubitPoint *) new CubitPointData( 0.,0.,0.5*hi );
01418   points.push_back(new_point);
01419   
01420   for ( i = 0; i < numpoints; i++ ) {
01421     point_list.append(points[i]);
01422   }  
01423   
01424   //  Make the triangles.
01425   int vertnum;
01426   vertnum = 0;
01427   for ( i = 0; i < pend; i++ ) {
01428     for ( j = 0; j < nr-1; j++ ) {
01429       facet_ptr = new CubitFacetData( points[vertnum+j],points[vertnum+j+1], points[vertnum+j+nr] );
01430       facet_list.append( facet_ptr );     
01431       facet_ptr = new CubitFacetData( points[vertnum+j+1],points[vertnum+j+1+nr], points[vertnum+j+nr] );
01432       facet_list.append( facet_ptr ); 
01433     }
01434     facet_ptr = new CubitFacetData( points[vertnum],points[vertnum+nr], points[vertnum+2*nr-1] );
01435     facet_list.append( facet_ptr );     
01436     facet_ptr = new CubitFacetData( points[vertnum+nr-1],points[vertnum], points[vertnum+2*nr-1] );
01437     facet_list.append( facet_ptr );     
01438     vertnum += nr;
01439   }
01440   
01441   //  Endcap(s)
01442   for ( i = 0; i < nr-1; i++ ) { // top cap
01443     facet_ptr = new CubitFacetData( points[vertnum+i],points[vertnum+i+1], points[V3+1] );
01444     facet_list.append( facet_ptr );  
01445   }   
01446   facet_ptr = new CubitFacetData( points[nr-1+vertnum],points[vertnum], points[V3+1] );
01447   facet_list.append( facet_ptr );    
01448   
01449   for ( i = 0; i < nr-1; i++ ) { // bottom cap
01450     facet_ptr = new CubitFacetData( points[i+1],points[i], points[V3] );
01451     facet_list.append( facet_ptr );  
01452   }   
01453   facet_ptr = new CubitFacetData( points[0],points[nr-1], points[V3] );
01454   facet_list.append( facet_ptr );    
01455   
01456   points.clear(); //  clear out the points vector since we are through with it.
01457   
01458   feature_angle = 135.0;
01459   interp_order = 0;
01460   smooth_non_manifold = CUBIT_TRUE;
01461   split_surfaces = CUBIT_FALSE;
01462   
01463   ChollaEngine *cholla_ptr = NULL;
01464   FacetModifyEngine *fme = const_cast<FacetModifyEngine *> (this);
01465   rv = fme->build_cholla_surfaces( facet_list,
01466                                    point_list,
01467                                    feature_angle,
01468                                    interp_order,
01469                                    smooth_non_manifold,
01470                                    split_surfaces,
01471                                    cholla_ptr );
01472 
01473   if ( rv == CUBIT_SUCCESS )
01474   {
01475       CubitEvaluatorData **cyl_data = NULL;
01476 
01477       set_cylinder_eval_data( cholla_ptr, hi, r1, r2, r3, cyl_data );
01478       finish_facet_Body( cholla_ptr,
01479                          (const CubitEvaluatorData**)cyl_data,
01480                          feature_angle,
01481                          interp_order,
01482                          body_ptr);
01483       if ( cholla_ptr )
01484       {
01485          cholla_ptr->delete_me();
01486          delete cholla_ptr;
01487       }
01488       if ( cyl_data )
01489       {
01490           if ( cyl_data[0] ) delete cyl_data[0];
01491           if ( cyl_data[1] ) delete cyl_data[1];
01492           if ( cyl_data[2] ) delete cyl_data[2];
01493           delete []cyl_data;
01494       }
01495   }
01496   return body_ptr;
01497 }
01498 
01499 void FacetModifyEngine::set_cylinder_eval_data
01500 (
01501     ChollaEngine *cholla_ptr,
01502     double height,
01503     double base_radius_xdir,
01504     double base_radius_ydir,
01505     double top_radius,
01506     CubitEvaluatorData **&eval_data ) const
01507 {
01508   
01509  // MODIFY_CHECK_RETURN_VOID;
01510     DLIList<ChollaSurface *> cholla_surface_list;
01511     cholla_ptr->get_surfaces( cholla_surface_list );
01512     cholla_surface_list.reset();
01513 
01514     eval_data = NULL;
01515 
01516     if ( cholla_surface_list.size() != 3 )
01517     {
01518         // This cylinder/cone is shaped quite unusually such that the cholla engine
01519         // found more than 3 faces on it.  This is likely because it is quite smashed
01520         // in the minor radius direction.  As such, there is not a cylindrical
01521         // surface so exit.
01522 
01523         return;
01524     }
01525 
01526     eval_data = new CubitEvaluatorData* [3];
01527     eval_data[0] =
01528     eval_data[1] =
01529     eval_data[2] = NULL;
01530 
01531     int isurf;
01532     for ( isurf = 0; isurf < cholla_surface_list.size(); isurf++ )
01533     {
01534         eval_data[isurf] = NULL;
01535         DLIList<ChollaCurve*> cholla_curve_list;
01536         ChollaSurface *csurf = cholla_surface_list.get_and_step();
01537         csurf->get_curves( cholla_curve_list );
01538         if ( cholla_curve_list.size() == 2 )
01539         {
01540             // this is the cylindrical face around the cylinder.
01541             CylinderEvaluatorData *data = new CylinderEvaluatorData;
01542             data->height = height;
01543             data->height = height;
01544             data->base_radius_x = base_radius_xdir;
01545             data->base_radius_y = base_radius_ydir;
01546             data->top_radius = top_radius;
01547 
01548             eval_data[isurf] = data;
01549         }
01550     }
01551 }
01552 
01553 //===============================================================================
01554 // Function   : torus
01555 // Member Type: PUBLIC
01556 // Description: create a torus with facets
01557 // Author     : John Fowler
01558 // Date       : 10/02
01559 //===============================================================================
01560 BodySM* FacetModifyEngine::torus( double r1, double r2 ) const
01561 {
01562   
01563   MODIFY_CHECK_RETURN_NULL;
01564   CubitStatus rv = CUBIT_SUCCESS;
01565   DLIList <CubitFacet *>facet_list;
01566   DLIList <CubitPoint *>point_list;
01567   CubitPoint *new_point;
01568   CubitFacet *facet_ptr;
01569   int numpoints;
01570   double feature_angle;
01571 int interp_order;
01572 CubitBoolean smooth_non_manifold, split_surfaces;
01573   BodySM *body_ptr = NULL;
01574   std::vector<CubitPoint *> points;
01575   int reslevel;  // relative level of resolution
01576   double theta, thetainc, phi, phiinc, x, z, xp, yp, zp, rmajor, rminor;
01577   int numtheta, numphi, i, j;
01578  
01579   reslevel = 4;
01580   numtheta = 8*reslevel;
01581   numphi = 8*reslevel;  
01582   numpoints = numtheta*numphi;
01583   rmajor = r1;
01584   rminor = r2;  
01585   thetainc = 2.*CUBIT_PI/(double)numtheta;
01586   phiinc = 2.*CUBIT_PI/(double)numphi;
01587   phi = 0.;
01588 
01589 //  Make the points in the y=0 plane
01590   for ( j = 0; j < numphi; j++ ) {
01591     theta = 0.;
01592     for ( i = 0; i < numtheta; i++ ) {
01593       x = rmajor + rminor*cos(theta);
01594       z = rminor*sin(theta);
01595 //  Rotate around the z axis
01596       xp = x*cos(phi);
01597       zp = z;
01598       yp = x*sin(phi);
01599       new_point = (CubitPoint *) new CubitPointData( xp,yp,zp );
01600       points.push_back(new_point);
01601       theta += thetainc;
01602     }
01603     phi += phiinc;  
01604   }
01605 
01606   for ( i = 0; i < numpoints; i++ ) {
01607     point_list.append(points[i]);
01608   } 
01609 //  Make the triangles  
01610   int m, k, m2, numtris;
01611   m = numtheta;
01612   numtris = 0;
01613   for ( j = 0; j < numphi; j++ ) {
01614     if ( j == numphi-1 ) m2 = 0;
01615     else m2 = m;
01616     for ( i = 0; i < numtheta; i++ ) {
01617       k = (i+1)%numtheta;
01618       facet_ptr = new CubitFacetData( points[i+m-numtheta], points[m2+i], points[m2+k] );
01619       facet_list.append( facet_ptr );     
01620       facet_ptr = new CubitFacetData( points[i+m-numtheta], points[m2+k], points[m-numtheta+k] );
01621       facet_list.append( facet_ptr );
01622       numtris += 2;     
01623     }
01624     m += numtheta;
01625   }
01626 
01627   points.clear(); //  clear out the points vector since we are through with it.
01628 
01629   feature_angle = 135.0;
01630   interp_order = 0;
01631   smooth_non_manifold = CUBIT_TRUE;
01632   split_surfaces = CUBIT_FALSE;
01633   
01634   ChollaEngine *cholla_ptr = NULL;
01635   FacetModifyEngine *fme = const_cast<FacetModifyEngine *> (this);
01636   rv = fme->build_cholla_surfaces( facet_list,
01637                                    point_list,
01638                                    feature_angle,
01639                                    interp_order,
01640                                    smooth_non_manifold,
01641                                    split_surfaces,
01642                                    cholla_ptr );
01643 
01644 
01645   if ( rv == CUBIT_SUCCESS )
01646   {
01647       finish_facet_Body( cholla_ptr,
01648                          NULL,
01649                          feature_angle,
01650                          interp_order,
01651                          body_ptr);
01652       if ( cholla_ptr )
01653       {
01654          cholla_ptr->delete_me();
01655          delete cholla_ptr;
01656       }
01657   }
01658   return body_ptr;
01659 }
01660 
01661 //===============================================================================
01662 // Function   : planar_sheet
01663 // Member Type: PUBLIC
01664 // Description: create a planar_sheet with facets
01665 // Author     : John Fowler
01666 // Date       : 10/02
01667 //===============================================================================
01668 BodySM* FacetModifyEngine::planar_sheet ( const CubitVector& /*p1*/,
01669                                        const CubitVector& /*p2*/,
01670                                        const CubitVector& /*p3*/,
01671                                        const CubitVector& /*p4*/ ) const
01672 {
01673   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01674   return (BodySM*) NULL;
01675 }
01676 
01677 //===============================================================================
01678 // Function   : copy_body
01679 // Member Type: PUBLIC
01680 // Description: copy a facet-based body
01681 // Author     : John Fowler
01682 // Date       : 10/02
01683 //===============================================================================
01684 BodySM* FacetModifyEngine::copy_body( BodySM* /*body_sm*/,
01685         std::map<TopologyBridge*, TopologyBridge*> * /*old_tb_to_new_tb */) const
01686 {
01687   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01688   return (BodySM*) NULL;
01689 }
01690 
01691 /*
01692 CubitStatus FacetModifyEngine::stitch_surfs(
01693                       DLIList<BodySM*>& surf_bodies,
01694                       BodySM*& stitched_body) const
01695 {
01696   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01697   return CUBIT_SUCCESS;
01698 }
01699 */
01700 //===============================================================================
01701 // Function   : subtract
01702 // Member Type: PUBLIC
01703 // Description: subtract boolean operation on facet-based bodies
01704 // Author     : John Fowler
01705 // Date       : 10/02
01706 //===============================================================================
01707 CubitStatus     FacetModifyEngine::subtract(DLIList<BodySM*> &tool_body_list,
01708                                             DLIList<BodySM*> &from_bodies,
01709                                             DLIList<BodySM*> &new_bodies,
01710                                             bool /*imprint*/,
01711                                             bool keep_old) const
01712 {
01713 
01714   MODIFY_CHECK_RETURN_FAILURE;
01715   CubitStatus status = CUBIT_FAILURE;
01716   int i;
01717   BodySM *tool_body, *from_body;
01718   FacetboolInterface *fbint;
01719   CubitFacetboolOp op;
01720 
01721   bool *to_be_deleted = new bool[from_bodies.size()];
01722 
01723   op = CUBIT_FB_SUBTRACTION;
01724 
01725   from_bodies.reset();
01726   tool_body_list.reset();
01727 
01728   for ( i = 0; i < from_bodies.size(); i++ ) to_be_deleted[i] = false;
01729 
01730   for ( i = tool_body_list.size(); i > 0; i-- ) { 
01731     tool_body = tool_body_list.get_and_step(); 
01732     fbint = new FacetboolInterface;
01733     status = fbint->dofacetboolean_subtract(tool_body,from_bodies,new_bodies,
01734                                             keep_old,to_be_deleted,op);
01735     delete fbint;
01736     if( keep_old == false )
01737       FacetQueryEngine::instance()->delete_solid_model_entities(tool_body);    
01738   }
01739 
01740   for ( i = 0; i < from_bodies.size(); i++ ) {
01741     from_body = from_bodies.get_and_step();
01742     if ( to_be_deleted[i] == true ) 
01743       FacetQueryEngine::instance()->delete_solid_model_entities(from_body);  
01744   }
01745 
01746   delete [] to_be_deleted;
01747     
01748   return status; 
01749      
01750 }
01751 
01752 //===============================================================================
01753 // Function   : imprint
01754 // Member Type: PUBLIC
01755 // Description: imprint boolean operation on facet-based bodies
01756 // Author     : John Fowler
01757 // Date       : 10/02
01758 //===============================================================================
01759 CubitStatus     FacetModifyEngine::imprint(BodySM* /*BodyPtr1*/, BodySM* /*BodyPtr2*/,
01760                                            BodySM*& /*newBody1*/, BodySM*& /*newBody2*/,
01761                                            bool  /*keep_old*/) const
01762 {
01763   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01764   return CUBIT_FAILURE;
01765 }
01766 
01767 //===============================================================================
01768 // Function   : imprint
01769 // Member Type: PUBLIC
01770 // Description: imprint boolean operation on facet-based bodies
01771 // Author     : John Fowler
01772 // Date       : 10/02
01773 //===============================================================================
01774 CubitStatus     FacetModifyEngine::imprint(DLIList<BodySM*> &from_body_list ,
01775                                            DLIList<BodySM*> &new_from_body_list,
01776                                            bool keep_old,
01777                                            DLIList<TopologyBridge*> *new_tbs,
01778                                            DLIList<TopologyBridge*> *att_tbs) const
01779 {
01780   MODIFY_CHECK_RETURN_FAILURE;
01781   
01782   CubitStatus success = CUBIT_SUCCESS;
01783 
01784     // total number of imprints to be done
01785   const int num_bodies = from_body_list.size();
01786 //  int total_imprints = (num_bodies *(num_bodies-1))/2;
01787   int i, j;
01788   CubitBox bbox1, bbox2; 
01789   std::vector<BodySM*> bodies_vector;
01790   for ( i = 0; i < from_body_list.size(); i++ ) 
01791     bodies_vector.push_back(from_body_list.get_and_step());
01792     
01793     // pass in keep_old to the delete_owner_attrib flag; if we're not keeping
01794     // old bodies, we want to keep the owner attrib, so we can pick up entities
01795     // that didn't change
01796 //  bool delete_attribs =
01797       (GeometryModifyTool::instance()->get_new_ids() || keep_old);
01798 
01799   from_body_list.reset();
01800   for (i = 0; success && i < num_bodies - 1; i++) {
01801     for (j = i + 1; j < num_bodies; j++) {
01802       BodySM *Body_Ptr1 = bodies_vector[i];
01803       success = FacetQueryEngine::instance()->create_facet_bounding_box(
01804                                              Body_Ptr1,
01805                                              bbox1);
01806       
01807       if (AppUtil::instance()->interrupt())
01808       {
01809         success = CUBIT_FAILURE;
01810         break;
01811       }    
01812       BodySM *Body_Ptr2 = bodies_vector[j];
01813       success = FacetQueryEngine::instance()->create_facet_bounding_box(
01814                                                Body_Ptr2,
01815                                                bbox2);
01816       if (bbox1.overlap(GEOMETRY_RESABS, bbox2)) {
01817         FacetboolInterface *FBInt = new FacetboolInterface;
01818         BodySM *out_Body_Ptr1, *out_Body_Ptr2;
01819         FBInt->dofacetboolean_2bodies_imprint(Body_Ptr1,Body_Ptr2,
01820                                               out_Body_Ptr1,out_Body_Ptr2,
01821                                               keep_old);
01822         delete FBInt;
01823         instance()->get_gqe()->delete_solid_model_entities(bodies_vector[i]);
01824         instance()->get_gqe()->delete_solid_model_entities(bodies_vector[j]);
01825         bodies_vector[i] = out_Body_Ptr1;
01826         bodies_vector[j] = out_Body_Ptr2;                                         
01827       }
01828 
01829     }
01830   }
01831 
01832   from_body_list.reset();
01833   for ( i = 0; i < from_body_list.size(); i++ ) {  
01834       new_from_body_list.append(bodies_vector[i]);
01835   }
01836    
01837   return success;
01838 }
01839 
01840 //===============================================================================
01841 // Function   : imprint
01842 // Member Type: PUBLIC
01843 // Description: imprint boolean operation on facet-based bodies
01844 // Author     : John Fowler
01845 // Date       : 10/02
01846 //===============================================================================
01847 CubitStatus     FacetModifyEngine::imprint( DLIList<BodySM*> &body_list,
01848                                            DLIList<Curve*> &ref_edge_list,
01849                                            DLIList<BodySM*>& new_body_list,
01850                                            DLIList<TopologyBridge*> &temporary_bridges,
01851                                            bool keep_old,
01852                                            bool show_messages) const
01853 {
01854   MODIFY_CHECK_RETURN_FAILURE;
01855   
01856   CubitStatus success = CUBIT_SUCCESS;
01857 //  bool delete_attribs =
01858       (GeometryModifyTool::instance()->get_new_ids() || keep_old);
01859   int i;
01860   CubitBox edge_list_bbox, bbox2; 
01861   const int num_bodies = body_list.size();
01862 
01863   FacetboolInterface *FBInt = new FacetboolInterface;
01864       
01865   FBInt->make_FB_edge_list(ref_edge_list);
01866   FBInt->get_edge_list_bbox(edge_list_bbox);
01867 
01868   for (i = 0; success && i < num_bodies; i++) {
01869     BodySM *Body_Ptr = body_list.next(i);
01870     success = FacetQueryEngine::instance()->create_facet_bounding_box(
01871                                              Body_Ptr,
01872                                              bbox2);
01873     if (edge_list_bbox.overlap(GEOMETRY_RESABS, bbox2)) {
01874     BodySM *new_body;
01875       FBInt->FB_imprint_with_curves(Body_Ptr,new_body,keep_old);
01876       new_body_list.append(new_body);      
01877     }
01878   }
01879 
01880   delete FBInt;
01881 
01882   body_list.reset();
01883   for ( i = 0; i < body_list.size(); i++ ) {  
01884       instance()->get_gqe()->delete_solid_model_entities(body_list.get_and_step());
01885   }
01886 
01887   return success;
01888 }
01889 
01890 //===============================================================================
01891 // Function   : imprint
01892 // Member Type: PUBLIC
01893 // Description: imprint boolean operation on facet-based bodies
01894 // Author     : John Fowler
01895 // Date       : 10/02
01896 //===============================================================================
01897 CubitStatus     FacetModifyEngine::imprint( DLIList<Surface*> &/*ref_face_list*/,
01898                                            DLIList<Curve*> &/*ref_edge_list*/,
01899                                            DLIList<TopologyBridge*> &temporary_bridges,
01900                                            DLIList<BodySM*>& /*new_body_list*/,
01901                                            bool /*keep_old_body*/ ) const
01902 {
01903   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01904   return CUBIT_FAILURE;
01905 }
01906 
01907 //===============================================================================
01908 // Function   : imprint
01909 // Member Type: PUBLIC
01910 // Description: imprint boolean operation on facet-based bodies
01911 // Author     : John Fowler
01912 // Date       : 10/02
01913 //===============================================================================
01914 CubitStatus     FacetModifyEngine::imprint( DLIList<Surface*> &/*surface_list*/,
01915                                            DLIList<DLIList<Curve*>*> &/*curve_lists_list*/,
01916                                            BodySM*& /*new_body*/,
01917                                            bool /*keep_old_body*/,
01918                                            bool /*expand*/,
01919                                            DLIList<TopologyBridge*> *new_tbs,
01920                                            DLIList<TopologyBridge*> *att_tbs ) const
01921 {
01922   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01923   return CUBIT_FAILURE;
01924 }
01925 
01926 //===============================================================================
01927 // Function   : imprint
01928 // Member Type: PUBLIC
01929 // Description: imprint boolean operation on facet-based bodies
01930 // Author     : John Fowler
01931 // Date       : 10/02
01932 //===============================================================================
01933 CubitStatus     FacetModifyEngine::imprint(DLIList<BodySM*> &/*body_list*/,
01934                                            DLIList<CubitVector> &/*vector_list*/,
01935                                            DLIList<BodySM*>& /*new_body_list*/,
01936                                            bool keep_old, /* keep old body */
01937                                           DLIList<TopologyBridge*> *new_tbs,
01938                                           DLIList<TopologyBridge*> *att_tbs,
01939                                           double *tol_in,
01940                                           bool clean_up_slivers) const
01941 {
01942   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01943   return CUBIT_FAILURE;
01944 }
01945 
01946 //===============================================================================
01947 // Function   : imprint_projected_edges
01948 // Member Type: PUBLIC
01949 // Description: 
01950 // Author     : John Fowler
01951 // Date       : 10/02
01952 //===============================================================================
01953 CubitStatus     FacetModifyEngine::imprint_projected_edges( DLIList<Surface*> &/*ref_face_list*/,
01954                                                            DLIList<Curve*> &/*ref_edge_list*/,
01955                                                            DLIList<BodySM*>& /*new_body_list*/,
01956                                                            DLIList<Curve*> & /*kept_curve_list*/,
01957                                                            bool /*keep_old_body*/,
01958                                                            bool /*keep_free_edges*/) const
01959 {
01960   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01961   return CUBIT_FAILURE;
01962 }
01963 
01964 //===============================================================================
01965 // Function   : imprint_projected_edges
01966 // Member Type: PUBLIC
01967 // Description: 
01968 // Author     : John Fowler
01969 // Date       : 10/02
01970 //===============================================================================
01971 CubitStatus     FacetModifyEngine::imprint_projected_edges(DLIList<Surface*> &/*ref_face_list*/,
01972                                                            DLIList<BodySM*> &/*body_list*/,
01973                                                            DLIList<Curve*> &/*ref_edge_list*/,
01974                                                            DLIList<BodySM*>& /*new_body_list*/,
01975                                                            bool /*keep_old_body*/,
01976                                                            bool /*keep_free_edges*/) const
01977 {
01978   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01979   return CUBIT_FAILURE;
01980 }
01981 
01982 //===============================================================================
01983 // Function   : project_edges
01984 // Member Type: PUBLIC
01985 // Description: 
01986 // Author     : John Fowler
01987 // Date       : 10/02
01988 //===============================================================================
01989 CubitStatus     FacetModifyEngine::project_edges( DLIList<Surface*> &/*ref_face_list*/,
01990                                                  DLIList<Curve*> &/*ref_edge_list_in*/,
01991                                                  DLIList<Curve*> &/*ref_edge_list_new*/,
01992                                                  bool /*print_error*/ ) const
01993 {
01994   PRINT_ERROR("Option not supported for mesh based geometry.\n");
01995   return CUBIT_FAILURE;
01996 }
01997 
01998 //===============================================================================
01999 // Function   : intersect
02000 // Member Type: PUBLIC
02001 // Description: intersect boolean operation between facet-based bodies
02002 // Author     : John Fowler
02003 // Date       : 10/02
02004 //===============================================================================
02005 CubitStatus     FacetModifyEngine::intersect(BodySM*  tool_body_ptr,
02006                                              DLIList<BodySM*>  &from_bodies,
02007                                              DLIList<BodySM*>  &new_bodies,
02008                                              bool  keep_old,
02009                                              bool preview ) const
02010 {
02011   if (preview)
02012   {
02013     PRINT_ERROR("Intersect preview not implemented for Facet geometry\n");
02014     return CUBIT_FAILURE;
02015   }
02016 
02017 
02018   MODIFY_CHECK_RETURN_FAILURE;
02019   
02020   CubitStatus status = CUBIT_FAILURE;
02021   int i;
02022   BodySM *from_body, *newBody;
02023 //  FacetboolInterface *fbint;
02024   CubitFacetboolOp op;
02025   DLIList<BodySM*> bodies;
02026 
02027   op = CUBIT_FB_INTERSECTION;
02028 
02029   from_bodies.reset();
02030   for ( i = from_bodies.size(); i > 0; i-- ) {
02031     bodies.clean_out();
02032     bodies.append(tool_body_ptr);    
02033     from_body = from_bodies.get_and_step();
02034     bodies.append(from_body);
02035     FacetboolInterface fbint;
02036     status = fbint.dofacetboolean(bodies,newBody,keep_old,op);
02037     if ( status == CUBIT_SUCCESS && newBody) new_bodies.append(newBody);
02038   }
02039     
02040   return status;
02041   
02042 /*
02043   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02044   return CUBIT_FAILURE;
02045 */  
02046 }
02047 
02048 //===============================================================================
02049 // Function   : chop
02050 // Member Type: PUBLIC
02051 // Description: chop boolean operation between facet-based bodies
02052 // Author     : John Fowler
02053 // Date       : 10/02
02054 //===============================================================================
02055 CubitStatus      FacetModifyEngine::chop(DLIList<BodySM*>& bodies, 
02056                                          DLIList<BodySM*> &intersectBodies, 
02057                                          DLIList<BodySM*> &outsideBodies,
02058                                          BodySM*& leftoversBody,
02059                                          bool keep_old ,
02060                                          bool nonreg) const
02061 {
02062   MODIFY_CHECK_RETURN_FAILURE;
02063   
02064 //Note:  there is never any leftover body.
02065 FacetboolInterface *fbint;
02066 CubitFacetboolOp op;
02067 bool keep_old_this = keep_old;
02068 CubitStatus status;
02069 BodySM *body_1, *body_2;
02070 bool intersection_found;
02071 BodySM* intersectBody = NULL;
02072 BodySM* outsideBody = NULL;
02073 
02074   if ( bodies.size() > 2 ) {
02075     PRINT_ERROR("Chop not yet supported for more than two bodies.\n");
02076     return CUBIT_FAILURE;
02077   }
02078   body_1 = bodies.get_and_step();
02079   body_2 = bodies.get();
02080   op = CUBIT_FB_INTERSECTION;
02081   fbint = new FacetboolInterface;  
02082   status = fbint->dofacetboolean_2bodies(body_2,body_1,intersectBody,
02083                                          keep_old_this,intersection_found,op);
02084   if(!status){
02085     delete fbint;
02086     return status;
02087   }
02088   
02089   
02090   delete fbint; 
02091   if(intersection_found){
02092     intersectBodies.append( intersectBody );
02093   }                
02094   else{
02095     return CUBIT_FAILURE;
02096   }
02097   op = CUBIT_FB_SUBTRACTION;
02098   fbint = new FacetboolInterface;  
02099   status = fbint->dofacetboolean_2bodies(body_1,body_2,outsideBody,
02100                                        keep_old_this,intersection_found,op);
02101    if(!status){
02102     delete fbint;
02103     return status;
02104   }
02105   delete fbint;        
02106   if(intersection_found){
02107     outsideBodies.append( outsideBody );
02108   }              
02109   else{
02110     return CUBIT_FAILURE;
02111   }                               
02112 
02113   if ( keep_old == false ) {
02114       FacetQueryEngine::instance()->delete_solid_model_entities(body_1);
02115       FacetQueryEngine::instance()->delete_solid_model_entities(body_2);        
02116   }
02117 
02118   return status;
02119   
02120 }
02121 
02122 void FacetModifyEngine::get_possible_invalid_tbs(DLIList<TopologyBridge*> &bridges_in,
02123                              DLIList<TopologyBridge*> &bridges_out)
02124 {
02125 }
02126 
02127 //===============================================================================
02128 // Function   : unite
02129 // Member Type: PUBLIC
02130 // Description: unite boolean operation between facet-based bodies
02131 // Author     : John Fowler
02132 // Date       : 10/02
02133 //===============================================================================
02134 CubitStatus     FacetModifyEngine::unite(DLIList<BodySM*> &bodies, 
02135                                          DLIList<BodySM*> &newBodies,
02136                                          bool keep_old) const
02137 {
02138   MODIFY_CHECK_RETURN_FAILURE;
02139   
02140 
02141 CubitStatus status;
02142 FacetboolInterface *fbint;
02143 CubitFacetboolOp op;
02144 
02145   op = CUBIT_FB_UNION;
02146   fbint = new FacetboolInterface;
02147 
02148   BodySM *newBody = NULL;
02149   status = fbint->dofacetboolean(bodies,newBody,keep_old,op);
02150 
02151   newBodies.append( newBody );
02152   delete fbint;
02153   return status;
02154 /*
02155   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02156   return CUBIT_FAILURE;
02157 */
02158   
02159 }
02160 
02161 
02162 CubitStatus FacetModifyEngine::hollow( DLIList<BodySM*>& /*bodies*/,
02163                                        DLIList<Surface*> & /*surfs*/,
02164                                        DLIList<BodySM*>& /*new_bodies*/,
02165                                        double /*depth*/) const
02166 {
02167   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02168   return CUBIT_FAILURE;
02169 }
02170 
02171 //===============================================================================
02172 // Function   : thicken
02173 // Member Type: PUBLIC
02174 // Description: 
02175 // Author     : John Fowler
02176 // Date       : 10/02
02177 //===============================================================================
02178 CubitStatus FacetModifyEngine::thicken(DLIList<BodySM*>& /*bodies*/, 
02179                                        DLIList<BodySM*>& /*new_bodies*/,
02180                                        double /*depth*/,
02181                                        bool /*both*/) const
02182 {
02183   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02184   return CUBIT_FAILURE;
02185 }
02186 
02187 
02188 //===============================================================================
02189 // Function   : flip_normals
02190 // Member Type: PUBLIC
02191 // Description: 
02192 // Author     : John Fowler
02193 // Date       : 10/02
02194 //===============================================================================
02195 CubitStatus FacetModifyEngine :: flip_normals( DLIList<Surface*>& face_list ) const
02196 {
02197   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02198   return CUBIT_FAILURE;
02199 }
02200 
02201 
02202 //===============================================================================
02203 // Function   : sweep_translational
02204 // Member Type: PUBLIC
02205 // Description: 
02206 // Author     : John Fowler
02207 // Date       : 10/02
02208 //===============================================================================
02209 CubitStatus FacetModifyEngine:: sweep_translational(
02210   DLIList<GeometryEntity*>& /*ref_ent_list*/,
02211   DLIList<BodySM*>& /*result_body_list*/,
02212   const CubitVector& /*sweep_vector*/,
02213   double /*draft_angle*/,
02214   int /*draft_type*/,
02215   bool /*switchside*/,
02216   bool /*rigid*/,
02217   bool /*anchor_entity*/,
02218   bool /*keep_old*/ ) const
02219 {
02220   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02221   return CUBIT_FAILURE;
02222 }
02223 
02224 //===============================================================================
02225 // Function   : sweep_perpendicular
02226 // Member Type: PUBLIC
02227 // Description: 
02228 // Author     : John Fowler
02229 // Date       : 10/02
02230 //===============================================================================
02231 CubitStatus FacetModifyEngine:: sweep_perpendicular(
02232   DLIList<GeometryEntity*>& /*ref_ent_list*/,
02233   DLIList<BodySM*>& /*result_body_list*/,
02234   double /*distance*/,
02235   double /*draft_angle*/,
02236   int /*draft_type*/,
02237   bool /*switchside*/,
02238   bool /*rigid*/,
02239   bool /*anchor_entity*/,
02240   bool /*keep_old*/ ) const
02241 {
02242   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02243   return CUBIT_FAILURE;
02244 }
02245 
02246 //===============================================================================
02247 // Function   : sweep_rotational
02248 // Member Type: PUBLIC
02249 // Description: 
02250 // Author     : John Fowler
02251 // Date       : 10/02
02252 //===============================================================================
02253 CubitStatus FacetModifyEngine:: sweep_rotational(
02254   DLIList<GeometryEntity*>& /*ref_ent_list*/,
02255   DLIList<BodySM*>& /*result_body_list*/,
02256   const CubitVector& /*point*/,
02257   const CubitVector& /*direction*/,
02258   double /*angle*/,
02259   int /*steps*/,
02260   double /*draft_angle*/,
02261   int /*draft_type*/,
02262   bool /*switchside*/,
02263   bool /*make_solid*/,
02264   bool /*rigid*/,
02265   bool /*anchor_entity*/,
02266   bool /*keep_old*/ ) const
02267 {
02268   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02269   return CUBIT_FAILURE;
02270 }
02271 
02272 //===============================================================================
02273 // Function   : sweep_along_curve
02274 // Member Type: PUBLIC
02275 // Description: 
02276 // Author     : John Fowler
02277 // Date       : 10/02
02278 //===============================================================================
02279 CubitStatus FacetModifyEngine::sweep_along_curve(
02280   DLIList<GeometryEntity*>& /*ref_ent_list*/,
02281   DLIList<BodySM*>& /*result_body_list*/,
02282   DLIList<Curve*>& /*ref_edge_list*/,
02283   double /*draft_angle*/,
02284   int /*draft_type*/,
02285   bool /*rigid*/,
02286   bool /*anchor_entity*/,
02287   bool /*keep_old*/ ) const
02288 {
02289   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02290   return CUBIT_FAILURE;
02291 }
02292 
02293 CubitStatus FacetModifyEngine::sweep_to_body( DLIList<Curve*> curve_list,
02294                                                BodySM *target_body,
02295                                                CubitVector distance,
02296                                                DLIList<BodySM*> &new_bodies,
02297                                                bool unite ) const
02298 {
02299   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02300   return CUBIT_FAILURE;
02301 }
02302 
02303 CubitStatus FacetModifyEngine::sweep_to_body( Surface *source_surface,
02304                                                BodySM *target_body,
02305                                                CubitVector distance,
02306                                                DLIList<BodySM*> &new_bodies ) const
02307 {
02308   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02309   return CUBIT_FAILURE;
02310 }
02311 
02312 //HEADER- Webcut-related functions
02313 
02314 //===============================================================================
02315 // Function   : webcut
02316 // Member Type: PUBLIC
02317 // Description: 
02318 // Author     : John Fowler
02319 // Date       : 10/02
02320 //===============================================================================
02321 CubitStatus FacetModifyEngine::webcut(DLIList<BodySM*>& webcut_body_list,
02322                               const CubitVector &v1,
02323                               const CubitVector &v2,
02324                               const CubitVector &v3,
02325                               DLIList<BodySM*>& neighbor_imprint_list,
02326                               DLIList<BodySM*>& results_list,
02327                               ImprintType imprint_type,
02328                               bool /*preview*/) const
02329 {
02330 
02331   MODIFY_CHECK_RETURN_FAILURE;
02332   
02333 CubitBox super_bbox;
02334 CubitStatus status;
02335 int i;
02336 
02337   CubitBoolean delete_bodies = (GeometryModifyTool::instance()->get_new_ids() ?
02338                                 CUBIT_FALSE : CUBIT_TRUE);
02339 
02340 //  Find the bounding box of all of the bodies.  This will be used to make
02341 //  the cutting plane.
02342 
02343 
02344   status = FacetQueryEngine::instance()->create_super_facet_bounding_box(webcut_body_list,
02345                                              super_bbox);
02346   
02347 //  Find the size of the cutting plane (x,y) in terms of super_bbox.
02348   DLIList<CubitVector> intersection_points;
02349   FBDataUtil::intersect_plane_with_boundingbox(super_bbox,
02350                                   v1,v2,v3,intersection_points); 
02351   int numpts = intersection_points.size();;
02352   if ( numpts < 3 ) {
02353       PRINT_INFO("INFO: Cutting Tool overlaps the original volume,\n"
02354                  "      Or cutting plane does not pass through volume.\n"
02355                  "         The original volume is unaffected.\n" );
02356 
02357     return CUBIT_FAILURE;
02358   }                                            
02359 double xsize, ysize, xcen, ycen, zcen;
02360 double xmin, ymin, zmin, xmax, ymax, zmax, xx, yy, zz;
02361   xmin = ymin = zmin = CUBIT_DBL_MAX;
02362   xmax = ymax = zmax = -xmin + 1;
02363   xcen = ycen = zcen = 0.0;
02364   for ( i = 0; i < numpts; i++ ) {
02365     xx = intersection_points[i].x();
02366     yy = intersection_points[i].y();
02367     zz = intersection_points[i].z();
02368     
02369     xcen += xx;
02370     ycen += yy;
02371     zcen += zz;
02372 
02373     xmin = (xmin < xx ) ? xmin : xx; 
02374     ymin = (ymin < yy ) ? ymin : yy; 
02375     zmin = (zmin < zz ) ? zmin : zz; 
02376     xmax = (xmax > xx ) ? xmax : xx; 
02377     ymax = (ymax > yy ) ? ymax : yy; 
02378     zmax = (zmax > zz ) ? zmax : zz;        
02379   }
02380   xcen /= numpts; ycen /= numpts; zcen /= numpts;  
02381   
02382   //  Could do this better by rotating the intersection points into the
02383   //  x-y plane and then getting xsize and ysize.  Factor of 1.3 is just
02384   //  to make sure that the plane extends beyond the bodies.
02385   xsize = ysize = 1.3*sqrt( (xmax-xmin)*(xmax-xmin) + 
02386                             (ymax-ymin)*(ymax-ymin) +
02387                             (zmax-zmin)*(zmax-zmin) );
02388   std::vector<double> cutter_verts;
02389   std::vector<int> cutter_connections;
02390   int numx, numy;
02391   numx = 20;
02392   numy = 20;
02393   //  Make the cutter surface.
02394   status = FBDataUtil::FBmake_xy_plane(cutter_verts, cutter_connections, 
02395                   xsize, ysize, numx, numy);
02396   CubitVector va, vb;
02397   va = v1 - v2;
02398   vb = v3 - v2;               
02399   CubitVector rotate_to;
02400  
02401   rotate_to = vb*va;
02402   rotate_to.normalize();
02403   CubitVector center_pt(xcen,ycen,zcen);
02404   status = FBDataUtil::rotate_FB_object(cutter_verts,rotate_to,center_pt);
02405   FacetboolInterface *fbint;
02406   bool cutter_is_plane = true;
02407   //  Now make the facetbool objects for the bodies. 
02408   webcut_body_list.reset();                
02409 BodySM *body_sm;
02410 
02411   for ( i = webcut_body_list.size(); i > 0; i-- ) {
02412     CubitBoolean intersects;
02413     body_sm = webcut_body_list.get_and_step();
02414     fbint = new FacetboolInterface;
02415     status = fbint->webcut_FB(body_sm,cutter_verts,cutter_connections,
02416                               cutter_is_plane,delete_bodies,
02417                               intersects,results_list); 
02418     delete fbint;    
02419     if ( status == CUBIT_FAILURE )
02420     {
02421         PRINT_ERROR(" Unable to perform webcut.\n" );
02422         return CUBIT_FAILURE;
02423     }
02424 
02425     if ( status == CUBIT_SUCCESS && intersects )  
02426     {
02427       instance()->get_gqe()->delete_solid_model_entities(body_sm);
02428     }
02429     else
02430     {
02431       PRINT_INFO("INFO: Cutting Tool overlaps the original volume,\n"
02432                  "      Or cutting plane does not pass through volume.\n"
02433                  "         The original volume is unaffected.\n" );
02434     }
02435   }
02436                                  
02437   return status;
02438     
02439 }
02440 
02441 //===============================================================================
02442 // Function   : webcut
02443 // Member Type: PUBLIC
02444 // Description: 
02445 // Author     : John Fowler
02446 // Date       : 10/02
02447 //===============================================================================
02448 CubitStatus    FacetModifyEngine::webcut(DLIList<BodySM*>& /*webcut_body_list*/,
02449                                  BodySM const* /*tool_body*/,
02450                                  DLIList<BodySM*>& /*neighbor_imprint_list*/,
02451                                  DLIList<BodySM*>& /*results_list*/,
02452                                  ImprintType imprint_type,
02453                                  bool /*preview*/) const
02454 {
02455   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02456   return CUBIT_FAILURE;
02457 }
02458 
02459 //===============================================================================
02460 // Function   : webcut_across_translate
02461 // Member Type: PUBLIC
02462 // Description: 
02463 // Author     : John Fowler
02464 // Date       : 10/02
02465 //===============================================================================
02466 CubitStatus    FacetModifyEngine::webcut_across_translate( DLIList<BodySM*>& /*body_list*/,
02467                                                           Surface* /*plane_surf1*/,
02468                                                           Surface* /*plane_surf2*/,
02469                                                           DLIList<BodySM*>& /*neighbor_imprint_list*/,
02470                                                           DLIList<BodySM*>& /*results_list*/,
02471                                                           ImprintType imprint_type,
02472                                                           bool /*preview*/) const
02473 {
02474   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02475   return CUBIT_FAILURE;
02476 }
02477 
02478 //===============================================================================
02479 // Function   : webcut_with_sheet
02480 // Member Type: PUBLIC
02481 // Description: 
02482 // Author     : John Fowler
02483 // Date       : 10/02
02484 //===============================================================================
02485 CubitStatus FacetModifyEngine::webcut_with_sheet(DLIList<BodySM*> & /*webcut_body_list*/,
02486                                                  BodySM * /*sheet_body*/,
02487                                                  DLIList<BodySM*>& /*neighbor_imprint_list*/,
02488                                                  DLIList<BodySM*> & /*new_bodies*/,
02489                                                  ImprintType imprint_type,
02490                                                  bool /*preview*/)
02491 {
02492   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02493   return CUBIT_FAILURE;
02494 }
02495 
02496 //===============================================================================
02497 // Function   : webcut_with_extended_surf
02498 // Member Type: PUBLIC
02499 // Description: 
02500 // Author     : John Fowler
02501 // Date       : 10/02
02502 //===============================================================================
02503 CubitStatus FacetModifyEngine::webcut_with_extended_sheet(DLIList<BodySM*> & /*webcut_body_list*/,
02504                                                          DLIList<Surface*> & /*surface_list*/,
02505                                                          DLIList<BodySM*>& /*neighbor_imprint_list*/,
02506                                                          DLIList<BodySM*> & /*new_bodies*/,
02507                                                          int & /*num_cut*/,
02508                                                          ImprintType imprint_type,
02509                                                          bool /*preview*/)
02510 {
02511   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02512   return CUBIT_FAILURE;
02513 }
02514 
02515 //===============================================================================
02516 // Function   : webcut_with_cylinder
02517 // Member Type: PUBLIC
02518 // Description: 
02519 // Author     : John Fowler
02520 // Date       : 10/02
02521 //===============================================================================
02522 CubitStatus FacetModifyEngine::webcut_with_cylinder(DLIList<BodySM*> &webcut_body_list,
02523                                             double radius,
02524                                             const CubitVector &axis,
02525                                             const CubitVector &center,
02526                                             DLIList<BodySM*>& neighbor_imprint_list,
02527                                             DLIList<BodySM*>& results_list,
02528                                             ImprintType imprint_type,
02529                                             bool /*preview*/ )
02530 {
02531 
02532   MODIFY_CHECK_RETURN_FAILURE;
02533   
02534 CubitBox super_bbox;
02535 CubitStatus status;
02536 int i;
02537 CubitVector bodies_center, my_center, diagonal, my_axis;
02538 
02539   CubitBoolean delete_bodies = (GeometryModifyTool::instance()->get_new_ids() ?
02540                                 CUBIT_FALSE : CUBIT_TRUE);
02541 
02542   status = FacetQueryEngine::instance()->create_super_facet_bounding_box(
02543     webcut_body_list,super_bbox);
02544   std::vector<double> cutter_verts;
02545   std::vector<int> cutter_connections;
02546   int nr, nz;
02547   double length;
02548   
02549   diagonal = super_bbox.diagonal();
02550 //  length = 2.3*diagonal.length() + 2.0*center.length();
02551   bodies_center = super_bbox.center();
02552   length = 3.*sqrt((bodies_center.x() - center.x())*(bodies_center.x() - center.x()) +
02553                    (bodies_center.y() - center.y())*(bodies_center.y() - center.y()) +
02554                    (bodies_center.z() - center.z())*(bodies_center.z() - center.z()) );
02555   length += 3.*diagonal.length();
02556     //length = sqrt(length*length + radius*radius);
02557     //  bodies_center += center;
02558 
02559   nr = 30;
02560   nz = 5;
02561 
02562   //  Make the cutter surface.
02563   status = FBDataUtil::FBmake_cylinder(cutter_verts, cutter_connections, 
02564                   radius, length, nr, nz);
02565   my_center = center;
02566   my_axis = axis;
02567   status = FBDataUtil::rotate_FB_object(cutter_verts,my_axis,my_center);
02568 
02569   FacetboolInterface *fbint;
02570   bool cutter_is_plane = false;
02571   //  Now make the facetbool objects for the bodies.                  
02572   webcut_body_list.reset();                
02573   BodySM* body_sm;
02574   for ( i = webcut_body_list.size(); i > 0; i-- ) {
02575     CubitBoolean intersects;
02576     body_sm = webcut_body_list.get_and_step();
02577     fbint = new FacetboolInterface;
02578      status = fbint->webcut_FB(body_sm,cutter_verts,cutter_connections,
02579                                cutter_is_plane,delete_bodies,
02580                                intersects,results_list);   
02581     delete fbint;    
02582     if ( status == CUBIT_FAILURE )
02583     {
02584         PRINT_ERROR(" Unable to perform webcut.\n" );
02585         return CUBIT_FAILURE;
02586     }
02587 
02588     if ( status == CUBIT_SUCCESS && intersects )  
02589     {
02590       instance()->get_gqe()->delete_solid_model_entities(body_sm);
02591     }
02592     else
02593     {
02594       PRINT_INFO("INFO: Cutting Tool overlaps the original volume,\n"
02595                  "      Or cutting plane does not pass through volume.\n"
02596                  "         The original volume is unaffected.\n" );
02597     }
02598   }
02599 
02600   return status;
02601   
02602 }
02603 
02604 //===============================================================================
02605 // Function   : webcut_with_brick
02606 // Member Type: PUBLIC
02607 // Description: 
02608 // Author     : John Fowler
02609 // Date       : 10/02
02610 //===============================================================================
02611 CubitStatus FacetModifyEngine::webcut_with_brick( 
02612                                       DLIList<BodySM*>& /*webcut_body_list*/, 
02613                                       const CubitVector &/*center*/,
02614                                       const CubitVector* /*axes[3]*/, 
02615                                       const CubitVector &/*extension*/,
02616                                       DLIList<BodySM*> &/*neighbor_imprint_list*/,
02617                                       DLIList<BodySM*> &/*results_list*/,
02618                                       ImprintType imprint_type,
02619                                       bool /*preview*/)
02620 {
02621   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02622   return CUBIT_FAILURE;
02623 }
02624 
02625 //===============================================================================
02626 // Function   : webcut_with_planar_sheet
02627 // Member Type: PUBLIC
02628 // Description: 
02629 // Author     : John Fowler
02630 // Date       : 10/02
02631 //===============================================================================
02632 CubitStatus FacetModifyEngine::webcut_with_planar_sheet( 
02633                                           DLIList<BodySM*>& /*webcut_body_list*/,
02634                                           const CubitVector &/*center*/,
02635                                           const CubitVector* /*axes[2]*/,
02636                                           double /*width*/, 
02637                                           double /*height*/,
02638                                           DLIList<BodySM*> &/*neighbor_imprint_list*/,
02639                                           DLIList<BodySM*> &/*results_list*/,
02640                                           ImprintType imprint_type,
02641                                           bool /*preview*/)
02642 {
02643   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02644   return CUBIT_FAILURE;
02645 }
02646 
02647 //===============================================================================
02648 // Function   : webcut_with_curve_loop
02649 // Member Type: PUBLIC
02650 // Description: 
02651 // Author     : John Fowler
02652 // Date       : 10/02
02653 //===============================================================================
02654 CubitStatus FacetModifyEngine::webcut_with_curve_loop(
02655                                               DLIList<BodySM*> &/*webcut_body_list*/,
02656                                               DLIList<Curve*> &/*ref_edge_list*/,
02657                                               DLIList<BodySM*> &/*neighbor_imprint_list*/,
02658                                               DLIList<BodySM*>& /*results_list*/,
02659                                               ImprintType imprint_type,
02660                                               bool /*preview*/)
02661 {
02662   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02663   return CUBIT_FAILURE;
02664 }
02665 
02666 //===============================================================================
02667 // Function   : section
02668 // Member Type: PUBLIC
02669 // Description: 
02670 // Author     : John Fowler
02671 // Date       : 10/02
02672 //===============================================================================
02673 CubitStatus FacetModifyEngine::section( DLIList<BodySM*> &/*section_body_list*/,
02674                                         const CubitVector &/*point_1*/,
02675                                         const CubitVector &/*point_2*/,
02676                                         const CubitVector &/*point_3*/,
02677                                         DLIList<BodySM*>& /*new_body_list*/,
02678                                         bool /*keep_normal_side*/,
02679                                         bool /*keep_old*/,
02680                                         bool /*keep_both_sides*/)
02681 {
02682   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02683   return CUBIT_FAILURE;
02684 }
02685 
02686 //===============================================================================
02687 // Function   : split_body
02688 // Member Type: PUBLIC
02689 // Description: Splits multiple lumps in one body into separate bodies
02690 // Author     : Corey Ernst 
02691 // Date       : 08/04
02692 //===============================================================================
02693 CubitStatus FacetModifyEngine::split_body( BodySM *body_ptr,
02694                                            DLIList<BodySM*> &new_bodies )
02695 {
02696   MODIFY_CHECK_RETURN_FAILURE;
02697   
02698   //get the all lumps of input body
02699   DLIList<Lump*> lumps;
02700   body_ptr->lumps( lumps );
02701 
02702   if( lumps.size() == 1 )
02703   {
02704     new_bodies.append( body_ptr );
02705     return CUBIT_SUCCESS;
02706   }
02707 
02708   //for each lump except one first one, create a new body
02709   DLIList<Lump*> single_lump;
02710   lumps.reset();
02711   lumps.step();
02712   int i;
02713   FacetBody *tmp_facet_body = static_cast<FacetBody*>( body_ptr );
02714   for( i=lumps.size()-1; i--; )
02715   {
02716     BodySM *bodysm_ptr;
02717     single_lump.clean_out();
02718     tmp_facet_body->remove_lump( static_cast<FacetLump*>(lumps.get())); 
02719     single_lump.append( lumps.get_and_step() );
02720     make_facet_body(single_lump, bodysm_ptr);
02721     if( bodysm_ptr )
02722       new_bodies.append(bodysm_ptr);
02723   }
02724 
02725   new_bodies.append( body_ptr );
02726 
02727   return CUBIT_SUCCESS;
02728 }
02729 
02730 //===============================================================================
02731 // Function   : separate_surfaces
02732 // Member Type: PUBLIC
02733 // Description: Separates surfaces from sheet bodies into separate bodies.
02734 //              Connected surfaces will remain connected but be placed in a new
02735 //              body. NOT IMPLEMENTED
02736 // Author     : 
02737 // Date       : 
02738 //===============================================================================
02739 CubitStatus FacetModifyEngine::separate_surfaces( DLIList<Surface*> &surf_list,
02740                                                   DLIList<BodySM*> &new_bodies )
02741 {
02742   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02743   return CUBIT_FAILURE;
02744 }
02745 
02746 //===============================================================================
02747 // Function   : reverse_body
02748 // Member Type: PUBLIC
02749 // Description: Turn body inside-out
02750 // Author     : Jason Kraftcheck
02751 // Date       : 05/25/04
02752 //===============================================================================
02753 CubitStatus FacetModifyEngine::reverse_body( BodySM* body_ptr )
02754 {
02755   MODIFY_CHECK_RETURN_FAILURE;
02756   
02757   FacetBody* body = dynamic_cast<FacetBody*>(body_ptr);
02758   if (0 == body)
02759   {
02760     PRINT_ERROR("Non-facet body in FME::reverse.\n");
02761     return CUBIT_FAILURE;
02762   }
02763   
02764     // Flip CoFace senses
02765   DLIList<FacetShell*> shells;
02766   body->get_shells( shells );
02767   while (shells.size())
02768     shells.pop()->reverse();
02769   
02770   return CUBIT_SUCCESS;
02771 }
02772     
02773 
02774 
02775 //===============================================================================
02776 // Function   : split_periodic
02777 // Member Type: PUBLIC
02778 // Description: 
02779 // Author     : John Fowler
02780 // Date       : 10/02
02781 //===============================================================================
02782 CubitStatus FacetModifyEngine::split_periodic( BodySM * /*body_ptr*/,
02783                                                BodySM *& /*new_body*/ )
02784 {
02785   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02786   return CUBIT_FAILURE;
02787 }
02788 
02789 //===============================================================================
02790 // Function   : regularize_body
02791 // Member Type: PUBLIC
02792 // Description: 
02793 // Author     : John Fowler
02794 // Date       : 10/02
02795 //===============================================================================
02796 CubitStatus    FacetModifyEngine::regularize_body( BodySM * /*body_ptr*/,
02797                                                    BodySM *& /*new_body_ptr*/ )
02798 {
02799   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02800   return CUBIT_FAILURE;
02801 }
02802 
02803 //===============================================================================
02804 // Function   : regularize_refentity
02805 // Member Type: PUBLIC
02806 // Description: 
02807 // Author     : John Fowler
02808 // Date       : 10/02
02809 //===============================================================================
02810 CubitStatus  FacetModifyEngine::regularize_entity( GeometryEntity * /*old_entity_ptr*/,  
02811                                                       BodySM *& /*new_body_ptr*/)
02812 {
02813   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02814   return CUBIT_FAILURE;
02815 }
02816 
02817 CubitStatus  FacetModifyEngine::test_regularize_entity( GeometryEntity *)
02818 {
02819   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02820   return CUBIT_FAILURE;
02821 }
02822 
02823 //===============================================================================
02824 // Function   : offset_curves
02825 // Member Type: PUBLIC
02826 // Description: 
02827 // Author     : John Fowler
02828 // Date       : 10/02
02829 //===============================================================================
02830 CubitStatus FacetModifyEngine::offset_curves( DLIList<Curve*>& /*ref_edge_list*/, 
02831                                               DLIList<Curve*>&,
02832                                               double /*offset_distance*/,
02833                                               const CubitVector& /*offset_direction*/, 
02834                                               int /*gap_type*/ )
02835 {
02836   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02837   return CUBIT_FAILURE;
02838 }
02839 
02840 //===============================================================================
02841 // Function   : split_curve
02842 // Member Type: PUBLIC
02843 // Description: 
02844 // Author     : Alex Hays
02845 // Date       : 9/08
02846 //===============================================================================
02847 CubitStatus  FacetModifyEngine::split_curve( Curve* curve_to_split,
02848                                             const CubitVector& split_location,
02849                                             DLIList<Curve*>& created_curves )
02850 {
02851   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02852   return CUBIT_FAILURE;
02853 }
02854 
02855 //===============================================================================
02856 // Function   : trim_curve
02857 // Member Type: PUBLIC
02858 // Description: 
02859 // Author     : John Fowler
02860 // Date       : 10/02
02861 //===============================================================================
02862 Curve* FacetModifyEngine::trim_curve( Curve* /*trim_curve*/, 
02863                                       const CubitVector& /*trim_vector*/,
02864                                       const CubitVector& /*keep_vector*/,
02865                                       bool )
02866 {
02867   PRINT_ERROR("Option not supported for mesh based geometry.\n");
02868   return 0;
02869 }
02870 
02871 //===============================================================================
02872 // Function   : create_solid_bodies_from_surfs
02873 // Member Type: PUBLIC
02874 // Description: 
02875 // Author     : Steve Owen
02876 // Date       : 9/11/03
02877 //===============================================================================
02878 CubitStatus FacetModifyEngine::create_solid_bodies_from_surfs(DLIList<Surface*> & ref_face_list,
02879                                                       DLIList<BodySM*> &new_bodies,
02880                                                       bool keep_old,
02881                                                       bool heal,
02882                                                       bool sheet ) const
02883 {
02884   //MODIFY_CHECK_RETURN_FAILURE;
02885   
02886   // get the facets from the faces
02887 
02888   int ii;
02889   Surface *surf_ptr;
02890   FacetSurface *fsurf_ptr;
02891   DLIList<CubitFacet *> facet_list;
02892   DLIList<CubitPoint *> point_list;
02893 
02894   if (heal)
02895   {
02896     PRINT_WARNING("\"heal\" option for facet-based geometry is not supported.\n"); 
02897   }
02898 
02899   ref_face_list.reset();
02900   for(ii=0; ii<ref_face_list.size(); ii++)
02901   {
02902     surf_ptr = ref_face_list.get_and_step();
02903     fsurf_ptr = dynamic_cast<FacetSurface *>(surf_ptr);
02904     assert(fsurf_ptr != NULL);
02905     if (fsurf_ptr == NULL)
02906       return CUBIT_FAILURE;
02907     point_list.clean_out();
02908     fsurf_ptr->get_my_facets( facet_list, point_list );
02909   }
02910 
02911   // copy the facets
02912 
02913   DLIList<CubitFacet *> new_facet_list;
02914   DLIList<CubitPoint *> new_point_list;
02915   DLIList<CubitFacetEdge *> new_edge_list;
02916   FacetDataUtil::copy_facets( facet_list, new_facet_list, new_point_list, new_edge_list );
02917 
02918   // generate new geometry
02919 
02920   const char *file_name = NULL; 
02921   CubitBoolean use_feature_angle = CUBIT_FALSE; 
02922   double feature_angle = 0.0;
02923   int interp_order = 0;
02924   double tol=0.0;
02925   CubitBoolean smooth_non_manifold = CUBIT_FALSE;
02926   CubitBoolean split_surfaces = CUBIT_FALSE;
02927   CubitBoolean stitch = CUBIT_TRUE;
02928   CubitBoolean improve = CUBIT_TRUE;
02929   DLIList <CubitQuadFacet *> quad_facet_list;
02930   DLIList<Surface *> surface_list;
02931   FacetFileFormat file_format = FROM_FACET_LIST;
02932   CubitStatus rv = 
02933     FacetQueryEngine::instance()->import_facets( file_name, 
02934                                                use_feature_angle,
02935                                                feature_angle,
02936                                                tol,
02937                                                interp_order,
02938                                                smooth_non_manifold,
02939                                                split_surfaces,
02940                                                stitch,
02941                                                improve,
02942                                                quad_facet_list,
02943                                                new_facet_list,
02944                                                surface_list,
02945                                                file_format );
02946 
02947   BodySM *new_body = NULL;
02948   if (rv == CUBIT_SUCCESS)
02949   {
02950     surf_ptr = surface_list.get();
02951     new_body = surf_ptr->bodysm();
02952 
02953     if( sheet == false ) 
02954     {
02955       CubitVector centroid;
02956       double volume = 0.0;
02957       new_body->mass_properties( centroid, volume);
02958       if( volume <= 0.0 )
02959       {
02960         FacetQueryEngine::instance()->delete_solid_model_entities(new_body);
02961         PRINT_INFO("Failing...Resulting body has no volume.\n");
02962         return CUBIT_FAILURE; 
02963       }
02964     }
02965   
02966     // delete the old model
02967   
02968     if (!keep_old)
02969     {
02970       DLIList<BodySM*> mybody_list;
02971       DLIList<BodySM*> body_list;
02972       for(ii=0; ii<ref_face_list.size(); ii++)
02973       {
02974         mybody_list.clean_out();
02975         surf_ptr = ref_face_list.get_and_step();
02976         surf_ptr->bodysms(mybody_list);
02977         if (mybody_list.size() == 1)
02978         {
02979           body_list.append_unique( mybody_list.get() );
02980         }
02981       }
02982       if (body_list.size() > 0)
02983       {
02984         FacetQueryEngine::instance()->delete_solid_model_entities(body_list);
02985         //GeometryQueryTool::instance()->delete_Body( body_list );
02986       }
02987     }
02988   }
02989   else
02990   {
02991     new_body = NULL;
02992   }
02993 
02994   if( new_body  )
02995     new_bodies.append( new_body );
02996 
02997   return CUBIT_SUCCESS;
02998 }
02999 
03000 
03001 //===============================================================================
03002 // Function   : create_circle
03003 // Member Type: PUBLIC
03004 // Description: 
03005 // Author     : Corey McBride
03006 // Date       : 1/11
03007 //===============================================================================
03008 Curve* FacetModifyEngine::create_arc(const CubitVector& position,
03009                                double radius,
03010                                double start_angle,
03011                                double end_angle,
03012                                CubitVector plane,
03013                                bool preview )
03014 {
03015   MODIFY_CHECK_RETURN_NULL;
03016   
03017   return NULL;
03018 
03019 }
03020 //===============================================================================
03021 // Function   : create_circle
03022 // Member Type: PUBLIC
03023 // Description: 
03024 // Author     : Corey McBride
03025 // Date       : 4/11
03026 //===============================================================================
03027 Curve* FacetModifyEngine::create_arc_radius(const CubitVector &center,
03028                                             TBPoint* ref_vertex_start,
03029                                             TBPoint* ref_vertex_end, 
03030                                             const CubitVector &normal,
03031                                             double radius,
03032                                             bool full,
03033                                             bool preview)
03034 {
03035   MODIFY_CHECK_RETURN_NULL;
03036   
03037   return NULL;
03038 
03039 }
03040 
03041 //===============================================================================
03042 // Function   : create_arc_three
03043 // Member Type: PUBLIC
03044 // Description: 
03045 // Author     : John Fowler
03046 // Date       : 10/02
03047 //===============================================================================
03048 Curve* FacetModifyEngine::create_arc_three( TBPoint* /*ref_vertex1*/, 
03049                                             TBPoint* /*ref_vertex2*/,
03050                                             TBPoint* /*ref_vertex3*/, 
03051                                             bool /*full*/,
03052                                             bool /*preview*/ )
03053 {
03054   MODIFY_CHECK_RETURN_NULL;
03055   
03056   return NULL;
03057 
03058 }
03059 
03060 //===============================================================================
03061 // Function   : create_arc_three
03062 // Member Type: PUBLIC
03063 // Description: 
03064 // Author     : John Fowler
03065 // Date       : 10/02
03066 //===============================================================================
03067 Curve* FacetModifyEngine::create_arc_three( Curve* /*ref_edge1*/, 
03068                                             Curve* /*ref_edge2*/,
03069                                             Curve* /*ref_edge3*/, 
03070                                             bool /*full*/,
03071                                             bool /*preview*/   )
03072 {
03073   MODIFY_CHECK_RETURN_NULL;
03074   
03075   return NULL;
03076 }
03077 
03078 //===============================================================================
03079 // Function   : create_arc_center_edge
03080 // Member Type: PUBLIC
03081 // Description: 
03082 // Author     : John Fowler
03083 // Date       : 10/02
03084 //===============================================================================
03085 Curve* FacetModifyEngine::create_arc_center_edge( TBPoint* /*ref_vertex1*/, 
03086                                                   TBPoint* /*ref_vertex2*/,
03087                                                   TBPoint* /*ref_vertex3*/,
03088                                                   const CubitVector& /*normal*/, 
03089                                                   double /*radius*/,
03090                                                   bool /*full*/,
03091                                                   bool /*preview*/ ) 
03092 { 
03093   MODIFY_CHECK_RETURN_NULL;
03094   
03095   return NULL; 
03096 }
03097 
03098 CubitStatus 
03099 FacetModifyEngine::create_curve_combine( DLIList<Curve*>& curve_list, 
03100                                     Curve *&new_curve_ptr )
03101 {
03102   PRINT_ERROR("Curve combine is not implemented for facet based models\n");
03103   return CUBIT_FAILURE;
03104 }
03105 
03106 //===============================================================================
03107 // Function   : get_gqe
03108 // Member Type: PUBLIC
03109 // Description: get the facet geometry query engince instance pointer
03110 // Author     : John Fowler
03111 // Date       : 10/02
03112 //===============================================================================
03113 GeometryQueryEngine *FacetModifyEngine::get_gqe()
03114 {
03115   return FacetQueryEngine::instance();
03116 }
03117 
03118 //===============================================================================
03119 // Function   : is_modify_engine
03120 // Member Type: PUBLIC
03121 // Description: return CUBIT_TRUE if the tb_ptr belongs to this modify engine
03122 // Author     : John Fowler
03123 // Date       : 10/02
03124 //===============================================================================
03125 CubitBoolean FacetModifyEngine::is_modify_engine(const TopologyBridge *tb_ptr) const 
03126 {
03127   return tb_ptr->get_geometry_query_engine() == FacetQueryEngine::instance();
03128 }
03129 
03130 //===============================================================================
03131 // Function   : get_offset_intersections
03132 // Member Type: PUBLIC
03133 // Description: 
03134 // Author     : John Fowler
03135 // Date       : 10/02
03136 //===============================================================================
03137 CubitStatus FacetModifyEngine::get_offset_intersections( Curve* /*ref_edge1*/, 
03138                                                          Curve* /*ref_edge2*/,
03139                                                          DLIList<CubitVector>& /*intersection_list*/,
03140                                                          double /*offset*/,
03141                                                          CubitBoolean /*ext_first*/ )
03142 {
03143   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03144   return CUBIT_FAILURE;
03145 }
03146 
03147 //===============================================================================
03148 // Function   : get_offset_intersections
03149 // Member Type: PUBLIC
03150 // Description: 
03151 // Author     : John Fowler
03152 // Date       : 10/02
03153 //===============================================================================
03154 CubitStatus FacetModifyEngine::get_offset_intersections( Curve* /*ref_edge_ptr*/, 
03155                                                          Surface* /*ref_face_ptr*/,
03156                                                          DLIList<CubitVector> & /*intersection_list*/,
03157                                                          double /*offset*/,
03158                                                          CubitBoolean /*ext_surf*/ )
03159 {
03160   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03161   return CUBIT_FAILURE;
03162 }
03163 
03164 //===============================================================================
03165 // Function   : surface_intersection
03166 // Member Type: PUBLIC
03167 // Description: 
03168 // Author     : John Fowler
03169 // Date       : 10/02
03170 //===============================================================================
03171 CubitStatus FacetModifyEngine::surface_intersection( Surface * /*surface1_ptr*/,
03172                                                      Surface * /*surface2_ptr*/,
03173                                                      DLIList<Curve*> &/*inter_graph*/,
03174                                                      const double /*tol*/) const
03175 {
03176   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03177   return CUBIT_FAILURE;
03178 }
03179 
03180 //===============================================================================
03181 // Function   : get_mid_plane
03182 // Member Type: PUBLIC
03183 // Description: 
03184 // Author     : John Fowler
03185 // Date       : 10/02
03186 //===============================================================================
03187 CubitStatus FacetModifyEngine::get_mid_plane( const CubitVector & /*point_1*/,
03188                                               const CubitVector & /*point_2*/,
03189                                               const CubitVector & /*point_3*/,
03190                                               BodySM * /*body_to_trim_to*/,
03191                                               BodySM *& /*midplane_body*/ ) const
03192 {
03193   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03194   return CUBIT_FAILURE;
03195 }
03196 
03197 //===============================================================================
03198 // Function   : get_quadric_mid_surface
03199 // Member Type: PUBLIC
03200 // Description: 
03201 // Author     : Philippe Pebay
03202 // Date       : 03/06
03203 //===============================================================================
03204 CubitStatus FacetModifyEngine::get_spheric_mid_surface( Surface* surface_ptr1,
03205                             Surface* surface_ptr2,
03206                             BodySM* body_to_trim_to,
03207                             BodySM*& midsurface_body ) const
03208 {
03209   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03210   return CUBIT_FAILURE;
03211 }
03212 
03213 //===============================================================================
03214 // Function   : get_quadric_mid_surface
03215 // Member Type: PUBLIC
03216 // Description: 
03217 // Author     : Philippe Pebay
03218 // Date       : 03/06
03219 //===============================================================================
03220 CubitStatus FacetModifyEngine::get_conic_mid_surface( Surface* surface_ptr1,
03221                             Surface* surface_ptr2,
03222                             BodySM* body_to_trim_to,
03223                             BodySM*& midsurface_body ) const
03224 {
03225   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03226   return CUBIT_FAILURE;
03227 }
03228 
03229 //===============================================================================
03230 // Function   : get_quadric_mid_surface
03231 // Member Type: PUBLIC
03232 // Description: 
03233 // Author     : Philippe Pebay
03234 // Date       : 03/06
03235 //===============================================================================
03236 CubitStatus FacetModifyEngine::get_toric_mid_surface( Surface* surface_ptr1,
03237                             Surface* surface_ptr2,
03238                             BodySM* body_to_trim_to,
03239                             BodySM*& midsurface_body ) const
03240 {
03241   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03242   return CUBIT_FAILURE;
03243 }
03244 
03245 //=============================================================================
03246 // Function   : tweak_bend
03247 // Member Type: PUBLIC
03248 // Description: Bend solid bodies based on a bend radius and angle
03249 // Author     : 
03250 // Date       : 
03251 //=============================================================================
03252 CubitStatus FacetModifyEngine::tweak_bend(DLIList<BodySM*>& bend_bodies,
03253                                            DLIList<BodySM*>& new_bodysm_list,
03254                                            CubitVector& neutral_root,
03255                                            CubitVector& bend_axis,
03256                                            CubitVector& bend_direction,
03257                                            double radius,
03258                                            double angle,
03259                                            DLIList<CubitVector> &bend_regions,
03260                                            double width,
03261                                            CubitBoolean center_bend,
03262                                            int num_points,
03263                                            CubitBoolean keep_old_body,
03264                                            CubitBoolean preview ) const
03265 {
03266     PRINT_ERROR("Option not supported for mesh based geometry.\n");
03267     return CUBIT_FAILURE;
03268 }
03269 
03270 //=============================================================================
03271 // Function   : tweak_chamfer
03272 // Member Type: PUBLIC
03273 // Description: Chamfer curves on solid bodies.  The left and right offsets are
03274 //              with respect to the curve direction.  If the given right offset
03275 //              is negative, the left offset is used.  Users can preview to
03276 //              clarify the meaning of left and right.
03277 // Author     : 
03278 // Date       : 
03279 //=============================================================================
03280 CubitStatus FacetModifyEngine::tweak_chamfer( DLIList<Curve*> & /*curve_list*/, 
03281                                               double /*left_offset*/,
03282                                               DLIList<BodySM*> & /*new_bodysm_list*/,
03283                                               double /*right_offset*/,
03284                                               CubitBoolean /*keep_old_body*/,
03285                                               CubitBoolean /*preview*/ ) const
03286 {
03287   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03288   return CUBIT_FAILURE;
03289 }
03290 
03291 //=============================================================================
03292 // Function   : tweak_chamfer
03293 // Member Type: PUBLIC
03294 // Description: Chamfer vertices on solid or sheet bodies.  On a solid body 
03295 //              there can be up to 3 offsets; on a sheet body up to 2 offsets.
03296 //              The offsets are in the direction of the supplied edges.  If 
03297 //              multiple vertices are supplied, only one offset value is 
03298 //              allowed and the edges are not used.
03299 // Author     : 
03300 // Date       : 
03301 //=============================================================================
03302 CubitStatus
03303 FacetModifyEngine::tweak_chamfer( DLIList<TBPoint*> & /*point_list*/, 
03304                                   double /*offset1*/,
03305                                   DLIList<BodySM*> & /*new_bodysm_list*/,
03306                                   Curve * /*edge1*/,
03307                                   double /*offset2*/,
03308                                   Curve * /*edge2*/,
03309                                   double /*offset3*/,
03310                                   Curve * /*edge3*/,
03311                                   CubitBoolean /*keep_old_body*/,
03312                                   CubitBoolean /*preview*/ ) const
03313 {
03314   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03315   return CUBIT_FAILURE;
03316 }
03317 
03318 //=============================================================================
03319 // Function   : tweak_fillet
03320 // Member Type: PUBLIC
03321 // Description: Create a round fillet (or blend) at the given curves on solid 
03322 //              bodies.
03323 // Author     : 
03324 // Date       : 
03325 //=============================================================================
03326 CubitStatus FacetModifyEngine::tweak_fillet( DLIList<Curve*> & /*curve_list*/, 
03327                                              double /*radius*/,
03328                                              DLIList<BodySM*> & /*new_bodysm_list*/,
03329                                              CubitBoolean /*keep_old_body*/,
03330                                              CubitBoolean /*preview*/ ) const
03331 {
03332   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03333   return CUBIT_FAILURE;
03334 }
03335 
03336 //=============================================================================
03337 // Function   : tweak_fillet
03338 // Member Type: PUBLIC
03339 // Description: Create a round fillet (or blend) at the given curves on a solid 
03340 //              body.  The fillet has a variable radius from the start to the
03341 //              end of the curve.
03342 // Author     : 
03343 // Date       : 
03344 //=============================================================================
03345 CubitStatus FacetModifyEngine::tweak_fillet( Curve * /*curve_ptr*/, 
03346                                              double /*start_radius*/,
03347                                              double /*end_radius*/,
03348                                              BodySM *& /*new_bodysm_ptr*/,
03349                                              CubitBoolean /*keep_old_body*/,
03350                                              CubitBoolean /*preview*/ ) const
03351 {
03352   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03353   return CUBIT_FAILURE;
03354 }
03355 
03356 //=============================================================================
03357 // Function   : tweak_fillet
03358 // Member Type: PUBLIC
03359 // Description: Create a round fillet (or blend) at the given vertices on sheet
03360 //              bodies.
03361 // Author     : 
03362 // Date       : 
03363 //=============================================================================
03364 CubitStatus
03365 FacetModifyEngine::tweak_fillet( DLIList<TBPoint*> & /*ref_vertex_list*/, 
03366                                  double /*radius*/,
03367                                  DLIList<BodySM*> & /*new_bodysm_list*/,
03368                                  CubitBoolean /*keep_old_body*/,
03369                                  CubitBoolean /*preview*/ ) const
03370 {
03371   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03372   return CUBIT_FAILURE;
03373 }
03374 
03375 //=============================================================================
03376 // Function   : tweak_move
03377 // Member Type: PUBLIC
03378 // Description: Tweak specified faces of a volume or volumes along a vector.
03379 // Author     : 
03380 // Date       : 
03381 //=============================================================================
03382 CubitStatus FacetModifyEngine::tweak_move( DLIList<Surface*> & /*surface_list*/, 
03383                                            const CubitVector & /*delta*/,
03384                                            DLIList<BodySM*> & /*new_bodysm_list*/, 
03385                                            CubitBoolean /*keep_old_body*/,
03386                                            CubitBoolean /*preview*/ ) const
03387 {
03388   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03389   return CUBIT_FAILURE;
03390 }
03391 
03392 //=============================================================================
03393 // Function   : tweak_move
03394 // Member Type: PUBLIC
03395 // Description: Tweak specified curves of a sheet body along a vector.
03396 // Author     : 
03397 // Date       : 
03398 //=============================================================================
03399 CubitStatus FacetModifyEngine::tweak_move( DLIList<Curve*> & /*curve_list*/,
03400                                            const CubitVector & /*delta*/,
03401                                            DLIList<BodySM*> & /*new_bodysm_list*/, 
03402                                            CubitBoolean /*keep_old_body*/,
03403                                            CubitBoolean /*preview*/ ) const
03404 {
03405   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03406   return CUBIT_FAILURE;
03407 }
03408 
03409 //=============================================================================
03410 // Function   : tweak_offset
03411 // Member Type: PUBLIC
03412 // Description: Tweak specified faces of a volume or volumes by offsetting
03413 //              those faces by the offset distance.
03414 // Author     : 
03415 // Date       : 
03416 //=============================================================================
03417 CubitStatus FacetModifyEngine::tweak_offset( DLIList<Surface*> & /*surface_list*/, 
03418                                              double /*offset_distance*/,
03419                                              DLIList<Surface*> * /*add_surface_list_ptr*/, 
03420                                              DLIList<double> * /*add_offset_list_ptr*/,
03421                                              DLIList<BodySM*> & /*new_bodysm_list*/,
03422                                              CubitBoolean /*keep_old_body*/,
03423                                              CubitBoolean /*preview*/ ) const
03424 {
03425   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03426   return CUBIT_FAILURE;
03427 }
03428 
03429 //=============================================================================
03430 // Function   : tweak_offset
03431 // Member Type: PUBLIC
03432 // Description: Tweak specified curves of a sheet body or bodies by offsetting
03433 //              those curves by the offset distance.
03434 // Author     : 
03435 // Date       : 
03436 //=============================================================================
03437 CubitStatus FacetModifyEngine::tweak_offset( DLIList<Curve*> & /*curve_list*/,  
03438                                              double /*offset_distance*/,
03439                                              DLIList<Curve*> * /*add_curve_list_ptr*/, 
03440                                              DLIList<double> * /*add_offset_list_ptr*/,
03441                                              DLIList<BodySM*> & /*new_bodysm_list*/,
03442                                              CubitBoolean /*keep_old_body*/,
03443                                              CubitBoolean /*preview*/ ) const
03444 {
03445   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03446   return CUBIT_FAILURE;
03447 }
03448 
03449 //=============================================================================
03450 // Function   : tweak_remove
03451 // Member Type: PUBLIC
03452 // Description: Function to remove surfaces from a body and then extend the 
03453 //              remaining surfaces to fill the gap or hole.
03454 // Author     : 
03455 // Date       : 
03456 //=============================================================================
03457 CubitStatus FacetModifyEngine::tweak_remove( DLIList<Surface*> & /*surface_list*/,
03458                                              DLIList<BodySM*> & /*new_bodysm_list*/,
03459                                              CubitBoolean /*extend_adjoining*/,
03460                                              CubitBoolean /*keep_old_body*/,
03461                                              CubitBoolean /*preview*/ ) const
03462 {
03463   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03464   return CUBIT_FAILURE;
03465 }
03466 
03467 //=============================================================================
03468 // Function   : tweak_remove
03469 // Member Type: PUBLIC
03470 // Description: Function to remove curves from a sheet body and then extend the 
03471 //              remaining curves or fill the gap or hole.
03472 // Author     : 
03473 // Date       : 
03474 //=============================================================================
03475 CubitStatus FacetModifyEngine::tweak_remove( DLIList<Curve*> & /*curve_list*/,
03476                                              DLIList<BodySM*> & /*new_bodysm_list*/, 
03477                                              CubitBoolean /*keep_old_body*/,
03478                                              CubitBoolean /*preview*/ ) const
03479 {
03480   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03481   return CUBIT_FAILURE;
03482 }
03483 
03484 //=============================================================================
03485 // Function   : tweak_target
03486 // Member Type: PUBLIC
03487 // Description: Tweak specified faces of a volume or volumes up to a set of 
03488 //              target surfaces.
03489 // Author     : 
03490 // Date       : 
03491 //=============================================================================
03492 CubitStatus FacetModifyEngine::tweak_target( DLIList<Surface*> & /*surface_list*/,
03493                                              DLIList<Surface*> & /*target_surf_list*/,
03494                                              DLIList<BodySM*> & /*new_bodysm_list*/,
03495                                              CubitBoolean /*extend_flg*/,
03496                                              CubitPlane * /*limit_plane*/,
03497                                              CubitBoolean /*reverse_flg*/,
03498                                              CubitBoolean /*keep_old_body*/,
03499                                              CubitBoolean /*preview*/ ) const
03500 {
03501   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03502   return CUBIT_FAILURE;
03503 }
03504 
03505 //=============================================================================
03506 // Function   : tweak_target
03507 // Member Type: PUBLIC
03508 // Description: Tweak specified edges of a surface or set of surfaces (in sheet
03509 //              bodies) up to a set of target surfaces.
03510 // Author     : 
03511 // Date       : 
03512 //=============================================================================
03513 CubitStatus FacetModifyEngine::tweak_target( DLIList<Curve*> & /*curve_list*/,
03514                                              DLIList<Surface*> & /*target_surf_list*/, 
03515                                              DLIList<BodySM*> & /*new_bodysm_list*/,
03516                                              CubitBoolean /*extend_flg*/,
03517                                              CubitPlane * /*limit_plane*/,
03518                                              CubitBoolean /*reverse_flg*/,
03519                                              CubitBoolean /*keep_old_body*/,
03520                                              CubitBoolean /*preview*/,
03521                                              double /*max_area_increase = 0*/ ) const
03522 {
03523   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03524   return CUBIT_FAILURE;
03525 }
03526 
03527 //=============================================================================
03528 // Function   : tweak_target
03529 // Member Type: PUBLIC
03530 // Description: Tweak specified edges of a sheet body or bodies up to a set of
03531 //              target curves that is part of a sheet body.  The target is a
03532 //              set of surfaces created by thickening the owning surfaces of
03533 //              the target curves.
03534 // Author     : 
03535 // Date       : 
03536 //=============================================================================
03537 CubitStatus FacetModifyEngine::tweak_target( DLIList<Curve*> & /*curve_list*/,
03538                                              DLIList<Curve*> & /*target_curve_list*/, 
03539                                              DLIList<BodySM*> & /*new_bodysm_list*/,
03540                                              CubitBoolean /*extend_flg*/,
03541                                              CubitPlane * /*limit_plane*/,
03542                                              CubitBoolean /*reverse_flg*/,
03543                                              CubitBoolean /*keep_old_body*/,
03544                                              CubitBoolean /*preview*/,
03545                                              double /*max_area_increase = 0*/ ) const
03546 {
03547   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03548   return CUBIT_FAILURE;
03549 }
03550 
03551 //=============================================================================
03552 // Function   : tweak_target
03553 // Member Type: PUBLIC
03554 // Description: Tweak specified point of a sheet body to a given location.  The
03555 //              given point must be part of a planar surface or surfaces 
03556 //              attached to linear curves only.  The user specified which of 
03557 //              those surfaces to actually modify.  The given location will be
03558 //              projected to be on the given planar surface(s) before being
03559 //              used - this projected location must be the same on all surfaces.
03560 // Author     :
03561 // Date       :
03562 //=============================================================================
03563 CubitStatus FacetModifyEngine::tweak_target( TBPoint * /*point_ptr*/,
03564                                              DLIList<Surface*> & /*modify_surface_list*/,
03565                                              CubitVector & /*target_loc*/,
03566                                              BodySM *& /*new_bodysm_ptr*/,
03567                                              CubitBoolean /*keep_old_body*/,
03568                                              CubitBoolean /*preview*/ ) const
03569 {
03570   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03571   return CUBIT_FAILURE;
03572 }
03573 
03574 CubitStatus FacetModifyEngine::remove_curve_slivers( BodySM* /*body*/, 
03575                                                      double /*lengthlimit*/ ) const
03576 {
03577   PRINT_ERROR("Option not supported for mesh based geometry.\n");
03578   return CUBIT_FAILURE;
03579 }
03580 
03581 //================================================================================
03582 // Description: Creates a net surface.
03583 // Author     : Tyronne Lim
03584 // Date       : 08/18/03
03585 //================================================================================
03586 CubitStatus FacetModifyEngine::create_net_surface( DLIList<Surface*>& /*ref_face_list*/, 
03587                                                    BodySM *& /*new_body*/,
03588                                                    DLIList<DLIList<CubitVector*>*> & /*vec_lists_u*/, 
03589                                                    DLIList<DLIList<CubitVector*>*> & /*vec_lists_v*/, 
03590                                                    double /*net_tol*/, 
03591                                                    CubitBoolean /*heal*/ ) const
03592 {
03593    PRINT_ERROR("Function not implemented in this engine.\n");
03594    return CUBIT_FAILURE;
03595 }
03596 
03597 //================================================================================
03598 // Description: Creates a net surface.
03599 // Author     : Tyronne Lim
03600 // Date       : 08/18/03
03601 //================================================================================
03602 CubitStatus FacetModifyEngine::create_net_surface( DLIList<Curve*>& /*u_curves*/, 
03603                                                    DLIList<Curve*>& /*v_curves*/,
03604                                                    BodySM *& /*new_body*/, 
03605                                                    double /*net_tol*/, 
03606                                                    CubitBoolean /*heal*/ ) const
03607 {
03608    PRINT_ERROR("Function not implemented in this engine.\n");
03609    return CUBIT_FAILURE;
03610 }
03611 
03612 //================================================================================
03613 // Description: Creates an offset surface.
03614 // Author     : Tyronne Lim
03615 // Date       : 08/18/03
03616 //================================================================================
03617 CubitStatus FacetModifyEngine::create_offset_surface( Surface* /*ref_face_ptr*/, 
03618                                                       BodySM*& /*new_body*/, 
03619                                                       double /*offset_distance*/ ) const
03620 {
03621    PRINT_ERROR("Function not implemented in Facet engine.\n");
03622    return CUBIT_FAILURE;
03623 }
03624 
03625 //================================================================================
03626 // Description: Creates an offset sheet.
03627 // Author     : 
03628 // Date       :
03629 //================================================================================
03630 CubitStatus
03631 FacetModifyEngine::create_offset_sheet( DLIList<Surface*> & /*surface_list*/,
03632                                         double /*offset_distance*/,
03633                                         DLIList<Surface*> * /*add_surface_list_ptr*/,
03634                                         DLIList<double> * /*add_offset_list_ptr*/,
03635                                         DLIList<BodySM*> & /*new_body_list*/,
03636                                         CubitBoolean /*preview*/ ) const
03637 {
03638   PRINT_ERROR("Function not implemented in Facet engine.\n");
03639   return CUBIT_FAILURE;
03640 }
03641 
03642 //================================================================================
03643 // Description: Creates an offset body.
03644 // Author     : Tyronne Lim
03645 // Date       : 08/18/03
03646 //================================================================================
03647 CubitStatus FacetModifyEngine::create_offset_body( BodySM* body_ptr, 
03648                                                    BodySM*& new_bodysm, 
03649                                                    double offset_distance ) const
03650 {
03651   return FacetModifyEngine::instance()->
03652     create_shell_offset( body_ptr, new_bodysm, offset_distance );
03653 }
03654 
03655 //================================================================================
03656 // Description: Creates a skin surface.
03657 // Author     : Tyronne Lim
03658 // Date       : 08/18/03
03659 //================================================================================
03660 CubitStatus FacetModifyEngine::create_skin_surface( DLIList<Curve*>& /*curves*/, 
03661                                                     BodySM*& /*new_body*/,
03662                                                     DLIList<Curve*>& /*guides*/) const
03663 {
03664    PRINT_ERROR("Function not implemented in this engine.\n");
03665    return CUBIT_FAILURE;
03666 }
03667 
03668 //
03674 CubitStatus FacetModifyEngine::loft_surfaces_to_body( DLIList<Surface*> &surfaces,
03675                                              DLIList<double> &takeoff_factor_list,
03676                                              DLIList<Surface*> &takeoff_vector_surface_list,
03677                                              DLIList<CubitVector> &surface_takeoff_vector_list,
03678                                              DLIList<Curve*> &takeoff_vector_curve_list,
03679                                              DLIList<CubitVector> &curve_takeoff_vector_list,
03680                                              DLIList<Curve*> &guides,
03681                                              DLIList<TBPoint*> &match_vertices_list,
03682                                              BodySM*& new_body,
03683                                              CubitBoolean global_guides,
03684                                              CubitBoolean closed,
03685                                              CubitBoolean show_matching_curves,
03686                                              CubitBoolean preview
03687                                              )const 
03688   {
03689        PRINT_ERROR("Function not implemented in this engine.\n");
03690    return CUBIT_FAILURE;
03691   }
03692 
03693 
03694 //================================================================================
03695 // Description: Creates a surface.
03696 // Author     : Tyronne Lim
03697 // Date       : 08/18/03
03698 //================================================================================
03699 CubitStatus FacetModifyEngine::create_surface( DLIList<CubitVector*>& /*vec_list*/, 
03700                                                BodySM *& /*new_body*/, 
03701                                                Surface * /*ref_face_ptr*/,
03702                                                CubitBoolean /*project_points*/ ) const
03703 {
03704    PRINT_ERROR("Function not implemented in this engine.\n");
03705    return CUBIT_FAILURE;
03706 }
03707 
03708 CubitStatus FacetModifyEngine::create_surface( DLIList<TBPoint*> & /*points*/,
03709                                                BodySM *& /*new_body*/,
03710                                                Surface * /*on_surface*/) const
03711 {
03712    PRINT_ERROR("Function not implemented in this engine.\n");
03713    return CUBIT_FAILURE;
03714 }
03715 
03716 //================================================================================
03717 // Description: Creates a weld surface.
03718 // Author     : Tyronne Lim
03719 // Date       : 08/18/03
03720 //================================================================================
03721 CubitStatus FacetModifyEngine::create_weld_surface( CubitVector & /*root*/,
03722                                                     Surface * /*ref_face1*/, 
03723                                                     double /*leg1*/, 
03724                                                     Surface * /*ref_face2*/, 
03725                                                     double /*leg2*/,
03726                                                     BodySM *& /*new_body*/ ) const
03727 {
03728    PRINT_ERROR("Function not implemented in this engine.\n");
03729    return CUBIT_FAILURE;
03730 }
03731 
03732 
03733 CubitStatus FacetModifyEngine::stitch( DLIList<BodySM*> &bodies_to_stitch,
03734                                        DLIList<BodySM*> &new_bodies,
03735                                        bool tighten_gaps,
03736                                        double tolerance )const 
03737 {
03738    PRINT_ERROR("Function not implemented in this engine.\n");
03739    return CUBIT_FAILURE;
03740 }
03741 
03742 
03743 //================================================================================
03744 //    Facet-based geometry entities
03745 //    Methods for building specific facet-based geometry entities
03746 //================================================================================
03747 
03748 //================================================================================
03749 // Function   : make_facet_point
03750 // Member Type: PUBLIC
03751 // Description: create a new facet point given a pointer to the 
03752 //              associated CubitPoint
03753 // Author     : sjowen
03754 // Date       : 12/28/00
03755 //================================================================================
03756 CubitStatus FacetModifyEngine::make_facet_point( CubitPoint *thePoint,
03757                                                  TBPoint *&new_point_ptr )
03758 {
03759   //MODIFY_CHECK_RETURN_FAILURE;
03760   
03761   //We don't know in this function what to attach it to, so do that later.
03762   DLIList<Curve*> curves;
03763 
03764   FacetPoint *new_facet_point = new FacetPoint( thePoint, curves );
03765 
03766   new_point_ptr = (TBPoint*) new_facet_point;
03767 
03768   return CUBIT_SUCCESS;
03769 }
03770 
03771 //================================================================================
03772 // Function   : make_facet_point
03773 // Member Type: PUBLIC
03774 // Description: create a new facet point given its location
03775 // Author     : sjowen
03776 // Date       : 12/6/00
03777 //================================================================================
03778 CubitStatus FacetModifyEngine::make_facet_point( const CubitVector &location,
03779                                                  TBPoint *&new_point_ptr )
03780 {
03781 //  MODIFY_CHECK_RETURN_FAILURE;
03782   
03783   //We don't know in this function what to attach it to, so do that later.
03784   DLIList<Curve*> curves;
03785 
03786   FacetPoint *new_facet_point = new FacetPoint( location, curves );
03787 
03788   new_point_ptr = (TBPoint*) new_facet_point;
03789 
03790   return CUBIT_SUCCESS;
03791 }
03792 
03793 //================================================================================
03794 // Function   : make_facet_curve
03795 // Member Type: PUBLIC
03796 // Description: create a new facet curve
03797 //              (Assumes the curve will have an associated parent surface.
03798 //               Evaluations will be done on the surface -- uses the same
03799 //               order evaluations as the surface)
03800 // Author     : sjowen
03801 // Date       : 12/6/00
03802 //================================================================================
03803 CubitStatus FacetModifyEngine::make_facet_curve( TBPoint *start_ptr,
03804                                                  TBPoint *end_ptr, 
03805                                                  Curve *&new_curve_ptr,
03806                                                  CurveFacetEvalTool *eval_tool_ptr)
03807 {
03808   //MODIFY_CHECK_RETURN_FAILURE;
03809   
03810 
03811   //We don't know in this function what to attach it to, so do that later.
03812   DLIList<CoEdgeSM*> coedgesms; 
03813 
03814   FacetCurve *new_facet_curv = new FacetCurve( eval_tool_ptr, start_ptr, 
03815                                                end_ptr, coedgesms );
03816   new_curve_ptr = (Curve*) new_facet_curv;
03817 
03818   FacetPoint *facet_start_point = CAST_TO( start_ptr, FacetPoint );
03819   FacetPoint *facet_end_point = CAST_TO( end_ptr, FacetPoint );
03820   facet_start_point->add_curve( new_curve_ptr );
03821   facet_end_point->add_curve( new_curve_ptr );
03822 
03823   return CUBIT_SUCCESS;
03824 }
03825 
03826 //================================================================================
03827 // Function   : make_facet_curve
03828 // Member Type: PUBLIC
03829 // Description: create a new facet curve given its edge facets
03830 //              (this can be used for generating a facet curve representation
03831 //               that does not have a parent surface associated -- currently
03832 //               only linear evaluations are possible)
03833 // Author     : sjowen
03834 // Date       : 2/17/01
03835 //================================================================================
03836 CubitStatus FacetModifyEngine::make_facet_curve(
03837   TBPoint *start_ptr,              // endpoints on the curve
03838   TBPoint *end_ptr,
03839   DLIList<CubitFacetEdge*> &edge_list, // the ordered facet edges on this curve
03840   DLIList<CubitPoint*> &point_list,    // the ordered points on this curve
03841   Curve *&new_curve_ptr,          // return the new curve pointer
03842   CurveFacetEvalTool *curve_facet_tool )
03843 {
03844   //MODIFY_CHECK_RETURN_FAILURE;
03845   
03846   if ( curve_facet_tool == NULL )
03847   {
03848     curve_facet_tool = new CurveFacetEvalTool;
03849     CubitStatus status = curve_facet_tool->initialize( edge_list, point_list );
03850     if ( status != CUBIT_SUCCESS )
03851     {
03852         return status;
03853     }
03854   }
03855   if (!curve_facet_tool)
03856     return CUBIT_FAILURE;
03857 
03858   //We don't know in this function what to attach it to, so do that later.
03859   DLIList<CoEdgeSM*> coedgesms; 
03860 
03861   FacetCurve *new_facet_curv = new FacetCurve( curve_facet_tool, start_ptr, 
03862                                                end_ptr, coedgesms );
03863   new_curve_ptr = (Curve*) new_facet_curv;
03864 
03865   FacetPoint *facet_start_point = CAST_TO( start_ptr, FacetPoint );
03866   FacetPoint *facet_end_point = CAST_TO( end_ptr, FacetPoint );
03867   facet_start_point->add_curve( new_curve_ptr );
03868   facet_end_point->add_curve( new_curve_ptr );
03869 
03870   return CUBIT_SUCCESS;
03871 }
03872 
03873 //================================================================================
03874 // Function   : make_facet_coedge
03875 // Member Type: PUBLIC
03876 // Description: create a new facet coedge
03877 // Author     : sjowen
03878 // Date       : 12/6/00
03879 //================================================================================
03880 CubitStatus FacetModifyEngine::make_facet_coedge( Curve *curv_ptr,
03881                                                     CubitSense sense,
03882                                                     CoEdgeSM *&new_coedge_ptr )
03883 {
03884 //  MODIFY_CHECK_RETURN_FAILURE;
03885   
03886     //We don't know in this function what to attach it to, so do that later.
03887   LoopSM *loop_ptr = NULL;
03888 
03889     //Now create a new loop.
03890  
03891   FacetCoEdge *new_facet_coedge = new FacetCoEdge(curv_ptr, loop_ptr, sense);
03892 
03893   new_coedge_ptr = (CoEdgeSM*) new_facet_coedge;
03894 
03895   FacetCurve *facet_curve = CAST_TO( curv_ptr, FacetCurve );
03896   facet_curve->add_coedge( new_coedge_ptr );
03897 
03898   return CUBIT_SUCCESS;
03899 }
03900 
03901 //================================================================================
03902 // Function   : make_facet_loop
03903 // Member Type: PUBLIC
03904 // Description: create a new facet loop
03905 // Author     : sjowen
03906 // Date       : 12/6/00
03907 //================================================================================
03908 CubitStatus FacetModifyEngine::make_facet_loop( DLIList<CoEdgeSM*> &coedge_list,
03909                                                   LoopSM *&new_loop_ptr )
03910 {
03911   //MODIFY_CHECK_RETURN_FAILURE;
03912   
03913     //We don't know in this function what to attach it to, so do that later.
03914   Surface *surf_ptr = NULL;
03915 
03916     //Now create a new loop.
03917  
03918   FacetLoop *new_facet_loop = new FacetLoop(surf_ptr, coedge_list );
03919 
03920   new_loop_ptr = (LoopSM*) new_facet_loop;
03921   int ii;
03922   for ( ii = coedge_list.size(); ii > 0; ii-- )
03923   {
03924     CoEdgeSM* coedge_ptr = coedge_list.get_and_step();
03925     FacetCoEdge *facet_coedge = CAST_TO(coedge_ptr, FacetCoEdge);
03926     facet_coedge->add_loop(new_loop_ptr);
03927   }
03928   return CUBIT_SUCCESS;
03929 }
03930 
03931 //================================================================================
03932 // Function   : make_facet_surface
03933 // Member Type: PUBLIC
03934 // Description: create a new facet surface from Quad facets
03935 // Author     : sjowen
03936 // Date       : 12/6/00
03937 //================================================================================
03938 CubitStatus FacetModifyEngine::make_facet_surface(
03939   DLIList<CubitQuadFacet*> &quad_facet_list,
03940   DLIList<CubitPoint*> &point_list,
03941   DLIList<LoopSM*> &my_loops,
03942   int interp_order,
03943   double min_dot,
03944   Surface *&new_surface_ptr)
03945 {
03946  // MODIFY_CHECK_RETURN_FAILURE;
03947   
03948   CubitQuadFacet *qfacet;
03949   DLIList<CubitFacet*> facet_list;
03950   int ii;
03951 
03952   quad_facet_list.reset();
03953   for (ii=0; ii<quad_facet_list.size(); ii++)
03954   {
03955     qfacet = quad_facet_list.get_and_step();
03956     facet_list.append( qfacet->get_tri_facet( 0 ) );
03957     facet_list.append( qfacet->get_tri_facet( 1 ) );
03958   }
03959   return make_facet_surface( NULL, facet_list, point_list, my_loops, 
03960                              interp_order, min_dot,  new_surface_ptr );
03961 }
03962 
03963 //================================================================================
03964 // Function   : make_facet_surface
03965 // Member Type: PUBLIC
03966 // Description: create a new facet surface
03967 // Author     : sjowen
03968 // Date       : 12/6/00
03969 //================================================================================
03970 CubitStatus FacetModifyEngine::make_facet_surface( const CubitEvaluatorData *eval_data,
03971                                                    DLIList<CubitFacet*> &facet_list,
03972                                                    DLIList<CubitPoint*> &point_list,
03973                                                    DLIList<LoopSM*> &my_loops,
03974                                                    int interp_order,
03975                                                    double min_dot,
03976                                                    Surface *&new_surface_ptr,
03977                                                    CubitBoolean use_point_addresses,
03978                                                    FacetEvalTool *facet_eval_tool,
03979                                                    std::map<FacetCurve*, FacetCurve*> *hard_line_curve_map)
03980 {
03981   //MODIFY_CHECK_RETURN_FAILURE;
03982   
03983     //Create a new surface given the facets and point list.
03984   if (facet_eval_tool == NULL)
03985   {
03986     facet_eval_tool = new FacetEvalTool();
03987     if (CUBIT_SUCCESS != facet_eval_tool->initialize(facet_list, point_list, 
03988                                                      interp_order, min_dot ) )
03989     {
03990       return CUBIT_FAILURE;
03991     }
03992   }
03993     
03994     //We don't know in this function what to attach it to, so do that later.
03995   DLIList<ShellSM*> shellsms;
03996   FacetSurface *new_facet_surf;
03997 
03998     //Now create a new surface.
03999   if ( eval_data && eval_data->ask_type() == SPHERE_SURFACE_TYPE )
04000   {
04001       new_facet_surf = new FacetSurface( (const SphereEvaluatorData*)eval_data,
04002                                          facet_eval_tool,
04003                                          shellsms,
04004                                          my_loops );
04005   }
04006   else if ( eval_data && eval_data->ask_type() == CONE_SURFACE_TYPE )
04007   {
04008       new_facet_surf = new FacetSurface( (const CylinderEvaluatorData*)eval_data,
04009                                          facet_eval_tool,
04010                                          shellsms,
04011                                          my_loops );
04012   }
04013   else
04014   {
04015       new_facet_surf = new FacetSurface( facet_eval_tool,
04016                                          shellsms, my_loops );
04017   }
04018 
04019   new_surface_ptr = (Surface*) new_facet_surf;
04020   int ii;
04021   for ( ii = my_loops.size(); ii > 0; ii-- )
04022   {
04023     LoopSM* loop_ptr = my_loops.get_and_step();
04024     FacetLoop *facet_loop = CAST_TO(loop_ptr, FacetLoop);
04025     facet_loop->add_surface(new_surface_ptr);
04026   }
04027 
04028    // generate the curve facet evaluaion tools for each of the curves on this
04029    // surface - they are based on the surface evaluation tool
04030 
04031   DLIList<FacetCoEdge*> coedges;
04032   new_facet_surf->get_coedges( coedges );
04033   for (ii=0; ii<coedges.size(); ii++)
04034   {
04035     FacetCoEdge *coedgesm_ptr = coedges.get_and_step();
04036     DLIList<FacetCurve*> curve_list;
04037     coedgesm_ptr->get_curves( curve_list );
04038     FacetCurve *facet_curve =curve_list.get();
04039     CurveFacetEvalTool *eval_tool = facet_curve->get_eval_tool(); 
04040     if (eval_tool == NULL) 
04041     {
04042       TBPoint *start_point = facet_curve->start_point();
04043       TBPoint *end_point = facet_curve->end_point();
04044       FacetCoEdge *facet_coedge_ptr = CAST_TO( coedgesm_ptr, FacetCoEdge );
04045       CubitSense sense = facet_coedge_ptr->get_sense();
04046 
04047       CubitStatus status = CUBIT_SUCCESS;
04048       eval_tool = new CurveFacetEvalTool;
04049       if (!use_point_addresses)
04050       {
04051         CubitVector temp_vec1 = start_point->coordinates();
04052         CubitVector temp_vec2 = end_point->coordinates();
04053         
04054         std::vector<CubitVector> facet_point_positions;
04055 
04056         if( hard_line_curve_map )
04057         {
04058           std::map<FacetCurve*, FacetCurve*>::iterator map_iter;
04059           map_iter = hard_line_curve_map->find( facet_curve );
04060           if( map_iter != hard_line_curve_map->end() )
04061           {
04062             DLIList<CubitPoint*> facet_curve_pts;
04063             map_iter->second->get_points( facet_curve_pts );
04064             for( int k=facet_curve_pts.size(); k--; )
04065               facet_point_positions.push_back( facet_curve_pts.get_and_step()->coordinates() );
04066           }
04067         }
04068 
04069         if( facet_point_positions.size() )
04070         {
04071           CubitVector start = temp_vec1;
04072           if( sense != CUBIT_FORWARD )
04073           {            
04074             std::reverse( facet_point_positions.begin(), facet_point_positions.end() );            
04075             start = temp_vec2;
04076           }
04077           status = eval_tool->initialize( facet_eval_tool,
04078               start, facet_point_positions );                                      
04079         }
04080         else
04081           status = eval_tool->initialize( facet_eval_tool,
04082                                         temp_vec1,
04083                                         temp_vec2,
04084                                         sense );
04085         if ( status != CUBIT_SUCCESS )
04086         {
04087             delete eval_tool;
04088             return status;
04089         }
04090       }
04091       else
04092       {
04093         FacetPoint *start_facet_pt_ptr = CAST_TO( start_point, FacetPoint );
04094         FacetPoint *end_facet_pt_ptr = CAST_TO( end_point, FacetPoint );
04095         CubitPoint *start_pt = start_facet_pt_ptr->get_cubit_point();
04096         CubitPoint *end_pt = end_facet_pt_ptr->get_cubit_point();
04097         status = eval_tool->initialize( facet_eval_tool,
04098                                         start_pt,
04099                                         end_pt,
04100                                         sense );
04101         if ( status != CUBIT_SUCCESS )
04102         {
04103             delete eval_tool;
04104             return status;
04105         }
04106       }
04107       if( !eval_tool->has_good_curve_data() )
04108       {
04109         if (facet_curve->get_eval_tool() == NULL)
04110           delete eval_tool;
04111         return CUBIT_FAILURE;
04112       }
04113       facet_curve->set_eval_tool( eval_tool );
04114     }
04115   }
04116   return CUBIT_SUCCESS;
04117 }
04118 
04119 //================================================================================
04120 // Function   : make_facet_shell
04121 // Member Type: PUBLIC
04122 // Description: create a new facet shell
04123 // Author     : sjowen
04124 // Date       : 12/6/00
04125 //================================================================================
04126 CubitStatus FacetModifyEngine::make_facet_shell(DLIList<Surface*> &surface_list,
04127                                                   ShellSM *&new_shell_ptr)
04128 {
04129   
04130   //MODIFY_CHECK_RETURN_FAILURE;
04131   
04132   Lump* my_lump = NULL;
04133   FacetShell *new_facet_shell = new FacetShell(my_lump, surface_list);
04134   new_shell_ptr = (ShellSM*) new_facet_shell;
04135   int ii;
04136   for ( ii = surface_list.size(); ii > 0; ii-- )
04137   {
04138     Surface* surface_ptr = surface_list.get_and_step();
04139     FacetSurface *facet_surface = CAST_TO(surface_ptr, FacetSurface);
04140     facet_surface->add_shell(new_shell_ptr);
04141   }
04142   return CUBIT_SUCCESS;
04143 }
04144 
04145 //================================================================================
04146 // Function   : make_facet_lump
04147 // Member Type: PUBLIC
04148 // Description: create a new facet lump
04149 // Author     : sjowen
04150 // Date       : 12/6/00
04151 //================================================================================
04152 CubitStatus FacetModifyEngine::make_facet_lump(DLIList<ShellSM*> &shell_list,
04153                                                  Lump *&new_lump_ptr)
04154 {
04155   //MODIFY_CHECK_RETURN_FAILURE;
04156   
04157   
04158   FacetLump *new_facet_lump = new FacetLump(shell_list);
04159   new_lump_ptr = (Lump*) new_facet_lump;
04160   int ii;
04161   for ( ii = shell_list.size(); ii > 0; ii-- )
04162   {
04163     ShellSM* shell_ptr = shell_list.get_and_step();
04164     FacetShell *facet_shell = CAST_TO(shell_ptr, FacetShell);
04165     facet_shell->add_lump(new_lump_ptr);
04166   }
04167   return CUBIT_SUCCESS;
04168 }
04169 
04170 //================================================================================
04171 // Function   : make_facet_body
04172 // Member Type: PUBLIC
04173 // Description: create a new facet body
04174 // Author     : sjowen
04175 // Date       : 12/6/00
04176 //================================================================================
04177 CubitStatus FacetModifyEngine::make_facet_body(DLIList<Lump*> &lump_list,
04178                                                  BodySM *&new_body_ptr)
04179 {
04180   
04181  // MODIFY_CHECK_RETURN_FAILURE;
04182   
04183   FacetBody *new_facet_body = new FacetBody(lump_list);
04184   new_body_ptr = (BodySM*) new_facet_body;
04185     //Now attach the lower entites.
04186 
04187   int ii;
04188   for ( ii = lump_list.size(); ii > 0; ii-- )
04189   {
04190     Lump* lump_ptr = lump_list.get_and_step();
04191     FacetLump *facet_lump = CAST_TO(lump_ptr, FacetLump);
04192     facet_lump->add_body(new_body_ptr);
04193   }
04194   return CUBIT_SUCCESS;
04195 }
04196 
04197 //================================================================================
04198 // Function   : build_facet_surface
04199 // Member Type: PUBLIC
04200 // Description: same as build_facet_surface below, but takes a list of quad facets
04201 // Author     : sjowen
04202 // Date       : 4/30/01
04203 //================================================================================
04204 CubitStatus FacetModifyEngine::build_facet_surface(
04205   DLIList<CubitQuadFacet *> &quad_facet_list,
04206   DLIList<CubitPoint *>&point_list,  // fills this in if not provided
04207   double feature_angle,
04208   int interp_order,
04209   CubitBoolean smooth_non_manifold,
04210   CubitBoolean split_surfaces,
04211   DLIList<Surface *> &surface_list) 
04212 {
04213   //MODIFY_CHECK_RETURN_FAILURE;
04214   
04215   CubitQuadFacet *qfacet;
04216   DLIList<CubitFacet*> facet_list;
04217   int ii;
04218 
04219   quad_facet_list.reset();
04220   for (ii=0; ii<quad_facet_list.size(); ii++)
04221   {
04222     qfacet = quad_facet_list.get_and_step();
04223     facet_list.append( qfacet->get_tri_facet( 0 ) );
04224     facet_list.append( qfacet->get_tri_facet( 1 ) );
04225   }
04226   return build_facet_surface( NULL, facet_list, point_list, feature_angle, 
04227                              interp_order, smooth_non_manifold,
04228                              split_surfaces, surface_list );
04229 }
04230 
04231 //================================================================================
04232 // Function   : build_facet_surface
04233 // Member Type: PUBLIC
04234 // Description: same as build_facet_surface below, both quad and triangle facets
04235 // Author     : sjowen
04236 // Date       : 4/30/01
04237 //================================================================================
04238 CubitStatus FacetModifyEngine::build_facet_surface(
04239   DLIList<CubitQuadFacet *> &quad_facet_list,
04240   DLIList<CubitFacet *> &tri_facet_list,
04241   DLIList<CubitPoint *>&point_list,  // fills this in if not provided
04242   double feature_angle,
04243   int interp_order,
04244   CubitBoolean smooth_non_manifold,
04245   CubitBoolean split_surfaces,
04246   DLIList<Surface *> &surface_list) 
04247 {
04248   //MODIFY_CHECK_RETURN_FAILURE;
04249   
04250   CubitStatus rv = CUBIT_SUCCESS;
04251   CubitQuadFacet *qfacet;
04252   DLIList<CubitFacet*> facet_list;
04253   int ii;
04254   quad_facet_list.reset();
04255   for (ii=0; ii<quad_facet_list.size(); ii++)
04256   {
04257     qfacet = quad_facet_list.get_and_step();
04258     facet_list.append( qfacet->get_tri_facet( 0 ) );
04259     facet_list.append( qfacet->get_tri_facet( 1 ) );
04260   }
04261   facet_list += tri_facet_list;
04262 
04263   rv = build_facet_surface( NULL, facet_list, point_list, feature_angle, 
04264                             interp_order, smooth_non_manifold,
04265                             split_surfaces, surface_list );
04266   return rv; 
04267 }
04268 
04269 //================================================================================
04270 // Function   : build_cholla_surfaces
04271 // Member Type: PUBLIC
04272 // Description: create one or more surfaces from the list of facets.  Also creates
04273 //              the lower order entities.  Generate curves (split surfaces), based
04274 //              on feature angle.  If feature_angle < 0 then ignore feature_angle
04275 // Note       : This function is the main interface for Cubit to the Cholla library
04276 // Author     : sjowen
04277 // Date       : 4/26/01
04278 //================================================================================
04279 CubitStatus FacetModifyEngine::build_cholla_surfaces
04280 (
04281   DLIList<CubitFacet *> facet_list,
04282   DLIList<CubitPoint *> point_list,  // fills this in if not provided
04283   double feature_angle,
04284   int interp_order,
04285   CubitBoolean smooth_non_manifold,
04286   CubitBoolean split_surfaces,
04287   ChollaEngine *&cholla_ptr
04288 )
04289 {
04290   //MODIFY_CHECK_RETURN_FAILURE;
04291   
04292   CubitStatus rv = CUBIT_SUCCESS;
04293 
04294   // generate the edge and point lists from the facets
04295 
04296   DLIList<CubitFacetEdge *> edge_list;
04297   DLIList<FacetEntity*> pe_list;
04298   DLIList<FacetEntity *> pf_list;
04299   FacetDataUtil::get_edges( facet_list, edge_list );
04300   if (facet_list.size() > 0 && point_list.size() == 0)
04301     FacetDataUtil::get_points( facet_list, point_list );
04302 
04303   CAST_LIST( point_list, pf_list, FacetEntity );
04304   CAST_LIST( edge_list, pe_list, FacetEntity );
04305 
04306   // create the surfaces
04307 
04308   if (rv == CUBIT_SUCCESS)
04309   {
04310     DLIList<FacetEntity*> facet_entity_list;
04311     CAST_LIST( facet_list, facet_entity_list, FacetEntity );
04312     cholla_ptr = new ChollaEngine( facet_entity_list, 
04313                                    pe_list, pf_list );
04314     CubitBoolean use_feature_angle;
04315     if (feature_angle < 0.0)
04316       use_feature_angle = CUBIT_FALSE;
04317     else
04318       use_feature_angle = CUBIT_TRUE;
04319     rv = cholla_ptr->create_geometry( use_feature_angle, feature_angle, 
04320                                       interp_order, smooth_non_manifold, 
04321                                       split_surfaces );
04322     
04323   }
04324   return rv;
04325 }
04326 //================================================================================
04327 // Function   : build_facet_surface
04328 // Member Type: PUBLIC
04329 // Description: create one or more surfaces from the list of facets.  Also creates
04330 //              the lower order entities.  Generate curves (split surfaces), based
04331 //              on feature angle.  If feature_angle < 0 then ignore feature_angle
04332 // Note       : This function is the main interface for Cubit to the Cholla library
04333 // Author     : sjowen
04334 // Date       : 4/26/01
04335 //================================================================================
04336 CubitStatus FacetModifyEngine::build_facet_surface(
04337   const CubitEvaluatorData **eval_data,
04338   DLIList<CubitFacet *> &facet_list,
04339   DLIList<CubitPoint *> &point_list,  // fills this in if not provided
04340   double feature_angle,
04341   int interp_order,
04342   CubitBoolean smooth_non_manifold,
04343   CubitBoolean split_surfaces,
04344   DLIList<Surface *> &surface_list) 
04345 {
04346  // MODIFY_CHECK_RETURN_FAILURE;
04347   
04348   CubitStatus rv = CUBIT_SUCCESS;
04349 
04350   // generate the edge and point lists from the facets
04351 
04352   DLIList<CubitFacetEdge *> edge_list;
04353   DLIList<FacetEntity*> pe_list;
04354   DLIList<FacetEntity *> pf_list;
04355   FacetDataUtil::get_edges( facet_list, edge_list );
04356   if (point_list.size() == 0)
04357     FacetDataUtil::get_points( facet_list, point_list );
04358 
04359   CAST_LIST( point_list, pf_list, FacetEntity );
04360   CAST_LIST( edge_list, pe_list, FacetEntity );
04361 
04362   // create the surfaces
04363 
04364   if (rv == CUBIT_SUCCESS)
04365   {
04366     DLIList<FacetEntity*> facet_entity_list;
04367     CAST_LIST( facet_list, facet_entity_list, FacetEntity );
04368     ChollaEngine *cholla_ptr = new ChollaEngine( facet_entity_list, 
04369                                                  pe_list, pf_list );
04370     cholla_ptr->set_flip_flag(CUBIT_TRUE);
04371     CubitBoolean use_feature_angle;
04372     if (feature_angle < 0.0)
04373       use_feature_angle = CUBIT_FALSE;
04374     else
04375       use_feature_angle = CUBIT_TRUE;
04376     rv = cholla_ptr->create_geometry( use_feature_angle, feature_angle, 
04377                                       interp_order, smooth_non_manifold, 
04378                                       split_surfaces );
04379     
04380     // make CUBIT geometry out of the Cholla entities
04381 
04382     if (rv == CUBIT_SUCCESS)
04383     {
04384       DLIList<ChollaSurface *> cholla_surface_list;
04385       cholla_ptr->get_surfaces( cholla_surface_list );
04386       DLIList<ChollaCurve *> cholla_curve_list;
04387       cholla_ptr->get_curves( cholla_curve_list );
04388       DLIList<ChollaPoint *> cholla_point_list;
04389       cholla_ptr->get_points( cholla_point_list );
04390       rv = build_cholla_geometry(eval_data, cholla_surface_list, cholla_curve_list,
04391                                  cholla_point_list, use_feature_angle, 
04392                                  feature_angle, interp_order, surface_list);
04393     }
04394     cholla_ptr->delete_me();
04395     delete cholla_ptr;
04396   }
04397   return rv;
04398 }
04399 
04400 //===============================================================================
04401 // Function   : build_cholla_geometry
04402 // Member Type: PRIVATE
04403 // Description: build the CUBIT geometry based on the Facet entity class lists
04404 // Author     : sjowen
04405 // Date       : 10/02
04406 //===============================================================================
04407 CubitStatus FacetModifyEngine::build_cholla_geometry(
04408   const CubitEvaluatorData **eval_data,
04409   DLIList<ChollaSurface*> &cholla_surface_list,
04410   DLIList<ChollaCurve*> &cholla_curve_list,
04411   DLIList<ChollaPoint*> &cholla_point_list,
04412   CubitBoolean use_feature_angle, 
04413   double feature_angle, 
04414   int interp_order,
04415   DLIList<Surface *> &surface_list)
04416 {
04417 //  MODIFY_CHECK_RETURN_FAILURE;
04418   
04419   CubitStatus stat = CUBIT_SUCCESS;
04420 
04421   //- convert feature angle to a dot product
04422 
04423   double min_dot = 0.0;
04424   if (use_feature_angle)
04425   {
04426     if (feature_angle > 180.0) feature_angle = 180.0;
04427     if (feature_angle < 0.0) feature_angle = 0.0;
04428     double rad_angle = (180.0 - feature_angle) * CUBIT_PI / 180.0;
04429     min_dot = cos( rad_angle );
04430   }
04431 
04432   // build the CUBIT geometry based on Cholla entities
04433 
04434   stat = build_cholla_point_geometry( cholla_point_list );
04435   
04436   if (stat == CUBIT_SUCCESS)
04437     stat = build_cholla_curve_geometry( cholla_curve_list );
04438 
04439   if (stat == CUBIT_SUCCESS)
04440     stat = build_cholla_surface_geometry( eval_data,
04441                                           cholla_surface_list,
04442                                           interp_order, min_dot,
04443                                           surface_list);
04444 
04445   return stat;
04446 }
04447 
04448 //===============================================================================
04449 // Function   : build_cholla_point_geometry
04450 // Member Type: PRIVATE
04451 // Description: From the cholla point list, create geometric points for each
04452 // Author     : sjowen
04453 // Date       : 10/02
04454 //===============================================================================
04455 CubitStatus FacetModifyEngine::build_cholla_point_geometry(
04456   DLIList<ChollaPoint*> &cholla_point_list )
04457 {
04458  // MODIFY_CHECK_RETURN_FAILURE;
04459   
04460   CubitStatus stat = CUBIT_SUCCESS;
04461   int kk;
04462   //int mydebug = 0;
04463   for ( kk = cholla_point_list.size(); kk > 0; kk-- )
04464   {
04465     ChollaPoint *chpnt_ptr = cholla_point_list.get_and_step();
04466     TBPoint *point_ptr = (TBPoint *)chpnt_ptr->get_geometric_point();
04467     if (point_ptr == NULL)
04468     {
04469       FacetEntity *facet_ptr = chpnt_ptr->get_facets();
04470       CubitPoint *cp_ptr = CAST_TO( facet_ptr, CubitPoint );
04471       TBPoint *point = NULL;
04472       stat = make_facet_point( cp_ptr, point );
04473       if ( point == NULL || stat != CUBIT_SUCCESS )
04474       {
04475         PRINT_ERROR("Problems building mesh based points.\n");
04476         return stat;
04477       }
04478       point_ptr = (TBPoint *)point;
04479       chpnt_ptr->assign_geometric_point((void *)point_ptr);
04480     }
04481   }
04482   return stat;
04483 }
04484 
04485 //===============================================================================
04486 // Function   : build_cholla_curve_geometry
04487 // Member Type: PRIVATE
04488 // Description: From the cholla curve list, create geometric curves for each
04489 // Author     : sjowen
04490 // Date       : 10/02
04491 //===============================================================================
04492 CubitStatus FacetModifyEngine::build_cholla_curve_geometry(
04493   DLIList<ChollaCurve*> &cholla_curve_list )
04494 {
04495  // MODIFY_CHECK_RETURN_FAILURE;
04496   
04497   CubitStatus stat = CUBIT_SUCCESS;
04498   int kk;
04499   for ( kk = cholla_curve_list.size(); kk > 0; kk-- )
04500   {
04501     ChollaCurve *chcurv_ptr = cholla_curve_list.get_and_step();
04502     Curve *curv_ptr = (Curve *)chcurv_ptr->get_geometric_curve();
04503     if (curv_ptr == NULL)
04504     {
04505       DLIList<ChollaPoint*> fpoint_list = chcurv_ptr->get_points( );
04506       ChollaPoint *fpm0_ptr = fpoint_list.get_and_step();
04507       ChollaPoint *fpm1_ptr = fpoint_list.get_and_step();
04508       CubitPoint *start_point, *end_point;
04509       chcurv_ptr->get_ends( start_point, end_point );
04510       assert(start_point != NULL);
04511       assert(end_point != NULL);
04512       if (fpm0_ptr->get_facets() != start_point)
04513       {
04514         ChollaPoint *temp_ptr;
04515         temp_ptr = fpm0_ptr;
04516         fpm0_ptr = fpm1_ptr;
04517         fpm1_ptr = temp_ptr;
04518       }
04519       TBPoint *start_ptr = (TBPoint *) fpm0_ptr->get_geometric_point();
04520       TBPoint *end_ptr = (TBPoint *) fpm1_ptr->get_geometric_point();
04521       
04522       // if this is a curve without a parent surface then handle it 
04523       // differently.  (Curves with parents use the surface to evaluate to
04524       // With only a curve, it must evaluate to the curve)
04525       
04526       DLIList<ChollaSurface*> fsm_list = chcurv_ptr->get_surfaces();
04527       if (fsm_list.size() == 0)
04528       {
04529         DLIList<FacetEntity*> facet_list;
04530         DLIList<CubitPoint*> point_list;  // needs to be filled in
04531         facet_list = chcurv_ptr->get_facet_list();
04532         DLIList<CubitFacetEdge*> edge_list;
04533         CAST_LIST( facet_list, edge_list, CubitFacetEdge );
04534         if (stat != CUBIT_SUCCESS)
04535           return stat;
04536 
04537         // the CurveFacetEvalTool was computed in Cholla.  Retreive it
04538         // and pass it to make_facet_curve so it can store it with the 
04539         // new curve
04540         CurveFacetEvalTool *eval_tool_ptr = chcurv_ptr->get_eval_tool();
04541         if (eval_tool_ptr == NULL)
04542           return CUBIT_FAILURE;
04543         stat = make_facet_curve( start_ptr, end_ptr,
04544                                  edge_list, point_list,
04545                                  curv_ptr, eval_tool_ptr );
04546         if (stat == CUBIT_SUCCESS)
04547         {
04548           Curve *curvsm_ptr = CAST_TO( curv_ptr, Curve );
04549           GeometryQueryTool::instance()->make_free_RefEdge( curvsm_ptr );
04550         }
04551       }
04552       else
04553       {
04554         CurveFacetEvalTool *eval_tool_ptr = chcurv_ptr->get_eval_tool();
04555         if (eval_tool_ptr == NULL)
04556           return CUBIT_FAILURE;
04557         stat = make_facet_curve( start_ptr, end_ptr,
04558                                  curv_ptr, eval_tool_ptr );
04559         if ( curv_ptr == NULL || stat != CUBIT_SUCCESS )
04560         {
04561           PRINT_ERROR("Problems building mesh based curves.\n");
04562           return stat;
04563         }
04564       }
04565       chcurv_ptr->assign_geometric_curve((void *)curv_ptr);
04566     }
04567   }
04568   return stat;
04569 }
04570 
04571   
04572 //===============================================================================
04573 // Function   : build_cholla_loop_geometry
04574 // Member Type: PRIVATE
04575 // Description: From the cholla curve list of a surface, create geometric loops 
04576 // Author     : sjowen
04577 // Date       : 10/02
04578 //===============================================================================
04579 CubitStatus FacetModifyEngine::build_cholla_loop_geometry(
04580   DLIList<ChollaCurve*> &cholla_curve_list,   // curves on a surface
04581   ChollaSurface *chsurf_ptr,                    // the surface
04582   DLIList<LoopSM*> &loop_list,                  // append to this loop list
04583   int debug_draw )
04584 {
04585   //MODIFY_CHECK_RETURN_FAILURE;
04586   
04587   CubitStatus stat = CUBIT_SUCCESS;
04588 
04589   typedef CubitLoops<CoEdgeSM, CubitPoint>::CoEdge MyCoEdge;
04590   std::vector<MyCoEdge> coedges;
04591 
04592   // loop through and build co-edges
04593   for(int i=0; i<cholla_curve_list.size(); i++)
04594   {
04595     ChollaCurve* chcurv_ptr = cholla_curve_list[i];
04596 
04597     CubitSense orientation;
04598     stat = ChollaEngine::determine_curve_orientation( chsurf_ptr, 
04599                                      chcurv_ptr, orientation );
04600     if(stat == CUBIT_FAILURE)
04601       return CUBIT_FAILURE;
04602 
04603     CubitSense this_orientation = orientation == CUBIT_UNKNOWN ? CUBIT_FORWARD : orientation;
04604 
04605     CoEdgeSM *coedge_ptr = NULL;
04606     Curve *curv_ptr = (Curve *)chcurv_ptr->get_geometric_curve();
04607     stat = make_facet_coedge( curv_ptr, this_orientation, coedge_ptr );
04608     if ( coedge_ptr == NULL || stat != CUBIT_SUCCESS )
04609     {
04610       PRINT_ERROR("Problems building mesh based coedges.\n");
04611       return stat;
04612     }
04613 
04614     MyCoEdge coedge;
04615     coedge.curve = coedge_ptr;
04616     chcurv_ptr->get_ends( coedge.start, coedge.end );
04617     coedge.sense = this_orientation;
04618     coedges.push_back(coedge);
04619 
04620     if(orientation == CUBIT_UNKNOWN)
04621     {
04622       curv_ptr = (Curve *)chcurv_ptr->get_geometric_curve();
04623       stat = make_facet_coedge( curv_ptr, CUBIT_REVERSED, coedge_ptr );
04624       if ( coedge_ptr == NULL || stat != CUBIT_SUCCESS )
04625       {
04626         PRINT_ERROR("Problems building mesh based coedges.\n");
04627         return stat;
04628       }
04629 
04630       coedge.curve = coedge_ptr;
04631       coedge.sense = CUBIT_REVERSED;
04632       coedges.push_back(coedge);
04633     }
04634   }
04635 
04636   // compute loops from co-edges
04637   std::vector<std::vector<MyCoEdge*> > loops;
04638   CubitLoops<CoEdgeSM, CubitPoint>::make_loops(coedges, loops);
04639 
04640   // build loops
04641   for(size_t i=0; i<loops.size(); i++)
04642   {
04643     DLIList<CoEdgeSM*> coedge_list;
04644     for(size_t j=0; j<loops[i].size(); j++)
04645     {
04646       coedge_list.append(loops[i][j]->curve);
04647     }
04648     LoopSM *loop_ptr = NULL;
04649     stat = make_facet_loop( coedge_list, loop_ptr );
04650     if ( loop_ptr == NULL || stat != CUBIT_SUCCESS )
04651     {
04652       PRINT_ERROR("Problems building mesh based loops.\n");
04653       return stat;
04654     }
04655     loop_list.append( loop_ptr );
04656   }
04657       
04658   return stat;
04659 }
04660 
04661 //===============================================================================
04662 // Function   : build_cholla_surface_geometry (PRIVATE)
04663 // Member Type: PRIVATE
04664 // Description: From the facet surface list, create geometric surface,
04665 //              loops and coedges for each surface in the list
04666 // Author     : sjowen
04667 // Date       : 10/02
04668 //===============================================================================
04669 CubitStatus FacetModifyEngine::build_cholla_surface_geometry(
04670   const CubitEvaluatorData **eval_data,
04671   DLIList<ChollaSurface*> &cholla_surface_list,
04672   int interp_order,
04673   double min_dot,
04674   DLIList<Surface *> &surface_list)
04675 {
04676  // MODIFY_CHECK_RETURN_FAILURE;
04677   
04678   CubitStatus stat = CUBIT_SUCCESS;
04679   int ii, isurface;
04680 
04681   // make sure the facet flags have been reset
04682 
04683   ChollaCurve *chcurv_ptr;
04684   cholla_surface_list.reset();
04685   for ( isurface = 0; isurface < cholla_surface_list.size(); isurface++ )
04686   {
04687     ChollaSurface *chsurf_ptr = cholla_surface_list.get_and_step();
04688     chsurf_ptr->reset_facet_flags();
04689   }
04690 
04691   // now loop through surfaces and create them
04692 
04693   int mydebug = 0;
04694   cholla_surface_list.reset();
04695   for ( isurface = 0; isurface < cholla_surface_list.size(); isurface++ )
04696   {
04697     const CubitEvaluatorData *surf_eval_data = eval_data == NULL ? NULL : eval_data[isurface];
04698     ChollaSurface *chsurf_ptr = cholla_surface_list.get_and_step();
04699 
04700     DLIList<ChollaCurve*> chcurve_list;
04701     chsurf_ptr->get_curves( chcurve_list );
04702 
04703     // init flags for curves on this surface
04704 
04705     for (ii=0; ii< chcurve_list.size(); ii++)
04706     {
04707       chcurv_ptr = chcurve_list.get_and_step();
04708       chcurv_ptr->set_flag(0);
04709       if (mydebug)
04710       {
04711         chcurv_ptr->debug_draw();
04712       }
04713     }
04714 
04715     // generate loops - keep going until we have used all the curves in the list
04716 
04717     DLIList<LoopSM*> loop_list;
04718     int debug_draw = 0;
04719     stat = build_cholla_loop_geometry( chcurve_list, chsurf_ptr, 
04720                                        loop_list, debug_draw );
04721     if (stat != CUBIT_SUCCESS)
04722     {
04723       PRINT_ERROR("Can't build geometric loop from facets\n");
04724       return stat;
04725     }
04726 
04727     // create the surface
04728 
04729     Surface *surf_ptr = (Surface *)chsurf_ptr->get_geometric_surface();
04730     if (surf_ptr == NULL)
04731     {
04732       DLIList<FacetEntity*> facet_entity_list;
04733       DLIList<CubitPoint*> point_list;
04734       chsurf_ptr->get_points(point_list);
04735       chsurf_ptr->get_facets(facet_entity_list);
04736       DLIList<CubitFacet*> facet_list;
04737       CAST_LIST( facet_entity_list, facet_list, CubitFacet );
04738       FacetEvalTool *eval_tool_ptr = chsurf_ptr->get_eval_tool();
04739       if (eval_tool_ptr == NULL)
04740         return CUBIT_FAILURE;
04741       stat = make_facet_surface(surf_eval_data, facet_list,point_list,loop_list,
04742                                 interp_order,min_dot,surf_ptr, CUBIT_TRUE, eval_tool_ptr);
04743       if ( surf_ptr == NULL || stat != CUBIT_SUCCESS )
04744       {
04745         PRINT_ERROR("Problems building mesh based surfaces.\n");
04746         return stat;
04747       }
04748       chsurf_ptr->assign_geometric_surface((void *)surf_ptr);
04749       surface_list.append(surf_ptr);
04750     }
04751   }
04752   return stat;
04753 }
04754 
04755 //================================================================================
04756 // Description: improve the facets on a surface
04757 // Author     : Steve Owen
04758 // Date       : 8/28/2003
04759 //================================================================================
04760 CubitStatus FacetModifyEngine::improve_facets( RefFace *ref_face_ptr )
04761 {
04762   //MODIFY_CHECK_RETURN_FAILURE;
04763   
04764   //CubitStatus rv = CUBIT_SUCCESS;
04765 
04766   // This must be a facet-based surface - return now if it isn't
04767 
04768   Surface *surf_ptr = ref_face_ptr->get_surface_ptr();
04769   FacetSurface *fsurf_ptr = dynamic_cast<FacetSurface *>(surf_ptr);
04770   if (fsurf_ptr == NULL)
04771   {
04772     PRINT_ERROR("Couldn't improve facets on surface %d. It is not a facet-based geometry.\n",
04773                  ref_face_ptr->id());
04774     return CUBIT_FAILURE;
04775   }
04776 
04777   CubitPoint *point_ptr;
04778   DLIList<CubitPoint *> point_list;
04779   DLIList<CubitFacet *> facet_list;
04780   DLIList<CubitFacetEdge *> edge_list;
04781 
04782   // get the facets from the facet-based surface
04783 
04784   fsurf_ptr->get_my_facets(facet_list, point_list);
04785   FacetDataUtil::get_edges(facet_list, edge_list);
04786 
04787   // compute normals if necessary  
04788 
04789   int ii;
04790   for (ii=0; ii<point_list.size(); ii++)
04791   {
04792     point_ptr = point_list.get_and_step();
04793     point_ptr->normal();
04794   }
04795 
04796   // main clean loop
04797 
04798   CubitFacet *facet0, *facet1;
04799   CubitFacetData *cfacet0, *cfacet1;
04800   CubitPoint *pt0, *pt1, *pt2, *pt3;
04801   CubitFacetEdge *edge;
04802   CubitFacetEdgeData *cedge;
04803   int nflip = 0;
04804   CubitVector n0, n1, n2, n3;
04805   CubitVector c0, c1, c2, c3;
04806   double q0, q1, q2, q3;
04807   CubitVector nt0, nt1, nt2, nt3;
04808   DLIList<CubitFacet *>adj_facets;
04809   int nedges = edge_list.size();
04810   for(ii=0; ii<nedges; ii++)
04811   {
04812     edge = edge_list.get();
04813 
04814     // can't be a feature (edge is on a curve)
04815     if(edge->is_feature())
04816     {
04817       edge_list.step();
04818       continue;
04819     }
04820     
04821     pt0 = edge->point(0);
04822     pt1 = edge->point(1);
04823     adj_facets.clean_out();
04824     edge->facets( adj_facets );
04825 
04826     // must be 2 adjacent facets.
04827     if (adj_facets.size() != 2)
04828     {
04829       edge_list.step();
04830       continue;
04831     }
04832     facet0 = adj_facets.get_and_step();
04833     facet1 = adj_facets.get();
04834 
04835     // get the adjacent vertices, make sure we are oriented correctly 
04836     // - swap pt0 and pt1 if necessary
04837     pt2 = facet0->next_node(pt1);
04838     if(pt2 == pt0)
04839     {
04840       pt2 = pt0;
04841       pt0 = pt1;
04842       pt1 = pt2;
04843       pt2 = facet0->next_node(pt1);
04844     }
04845     pt3 = facet1->next_node(pt0);
04846 
04847     // get the normals from the vertices
04848     n0 = pt0->normal( facet0 );
04849     n1 = pt1->normal( facet0 );
04850     n2 = pt2->normal( facet0 );
04851     n3 = pt3->normal( facet1 );
04852     c0 = pt0->coordinates();
04853     c1 = pt1->coordinates();
04854     c2 = pt2->coordinates();
04855     c3 = pt3->coordinates();
04856 
04857     // compute triangle normals by averaging vertices
04858     nt0 = n0 + n1 + n2;
04859     nt0.normalize();
04860     nt1 = n0 + n1 + n3;
04861     nt1.normalize();
04862     nt2 = n0 + n2 + n3;
04863     nt2.normalize();
04864     nt3 = n1 + n2 + n3;
04865     nt3.normalize();
04866 
04867     // compute quality for each of the four tris... 2 existing tris
04868     // and the two potential tris if we flip
04869     q0 = FacetDataUtil::quality(c0, c1, c2, nt0);
04870     q1 = FacetDataUtil::quality(c1, c0, c3, nt1);
04871     q2 = FacetDataUtil::quality(c0, c3, c2, nt2);
04872     q3 = FacetDataUtil::quality(c1, c2, c3, nt3);
04873     q0 = CUBIT_MIN( q0, q1 );
04874     q2 = CUBIT_MIN( q2, q3 );
04875     if (q2 > q0)
04876     {
04877       // flip
04878 
04879       facet_list.remove( facet0 );  // these take too long - find another way to remove them
04880       facet_list.remove( facet1 );
04881       edge_list.change_to(NULL);
04882 
04883       cfacet0 = dynamic_cast<CubitFacetData *>( facet0 );
04884       cfacet1 = dynamic_cast<CubitFacetData *>( facet1 );
04885       cedge = dynamic_cast<CubitFacetEdgeData *>( edge );
04886       
04887       delete cfacet0;
04888       delete cfacet1;
04889       delete cedge;
04890 
04891       // get edges
04892 
04893       CubitFacetEdge *e[4];
04894       e[0] = pt2->get_edge( pt0 );
04895       e[1] = pt0->get_edge( pt3 );
04896       e[2] = pt3->get_edge( pt1 );
04897       e[3] = pt1->get_edge( pt2 );
04898       cedge = new CubitFacetEdgeData( pt2, pt3 );
04899       edge = dynamic_cast<CubitFacetEdge *>( cedge ); 
04900 
04901       cfacet0 = new CubitFacetData( edge, e[0], e[1] );
04902       cfacet1 = new CubitFacetData( edge, e[2], e[3] );
04903       facet0 = dynamic_cast<CubitFacet *>( cfacet0 );
04904       facet1 = dynamic_cast<CubitFacet *>( cfacet1 );
04905        
04906       edge_list.append( edge );
04907       facet_list.append( facet0 );
04908       facet_list.append( facet1 );
04909       
04910       nflip++;
04911     }
04912     edge_list.step();
04913   }
04914   edge_list.remove_all_with_value(NULL);
04915   assert(edge_list.size() == nedges);
04916   if (nflip > 0)
04917   {
04918     fsurf_ptr->get_eval_tool()->replace_facets(facet_list);
04919   }
04920   return CUBIT_SUCCESS;
04921 }
04922 
04923 
04924 //================================================================================
04925 // Description: smooth the facets on a surface
04926 // Author     : Steve Owen
04927 // Date       : 8/28/2003
04928 // Note: free_laplacian = TRUE will not project the node back to a tangent plane
04929 //       free_laplacian = FALSE will project to local tangent plane
04930 //================================================================================
04931 CubitStatus FacetModifyEngine::smooth_facets( RefFace *ref_face_ptr, int niter,
04932                                               CubitBoolean free_laplacian )
04933 {
04934   //MODIFY_CHECK_RETURN_FAILURE;
04935   
04936   CubitStatus rv = CUBIT_SUCCESS;
04937 
04938   // This must be a facet-based surface - return now if it isn't
04939 
04940   Surface *surf_ptr = ref_face_ptr->get_surface_ptr();
04941   FacetSurface *fsurf_ptr = dynamic_cast<FacetSurface *>(surf_ptr);
04942   if (fsurf_ptr == NULL)
04943   {
04944     PRINT_ERROR("Couldn't smooth facets on surface %d. It is not a facet-based geometry.\n",
04945                  ref_face_ptr->id());
04946     return CUBIT_FAILURE;
04947   }
04948 
04949   CubitPoint *point_ptr;
04950   DLIList<CubitPoint *>point_list;
04951 
04952   // get the points from the facet-basec surface
04953 
04954   fsurf_ptr->get_my_points(point_list);
04955 
04956   // compute normals if necessary  
04957 
04958   int ii, jj;
04959   for (ii=0; ii<point_list.size(); ii++)
04960   {
04961     point_ptr = point_list.get_and_step();
04962     point_ptr->normal();
04963     point_ptr->marked(0);
04964   }
04965 
04966   // get the points on the facet curves associated with this surface
04967 
04968   DLIList<CubitPoint *>cpoint_list;
04969   FacetCurve *fcurv_ptr;
04970   Curve *curv_ptr;
04971 
04972   int idx;
04973   DLIList<Curve *> curves;
04974   fsurf_ptr->curves(curves);
04975   FacetCurve **fcurve_array = new FacetCurve * [curves.size()];
04976   for (ii=0; ii<curves.size(); ii++)
04977   {
04978     idx = ii+1;
04979     curv_ptr = curves.get_and_step();
04980     fcurv_ptr = dynamic_cast<FacetCurve *>(curv_ptr);
04981     if (!fcurv_ptr)
04982     {
04983       PRINT_ERROR("Couldn't smooth facets on surface %d. At least one of it curves is not a facet-based geometry.\n",
04984                    ref_face_ptr->id());
04985       return CUBIT_FAILURE;
04986     }
04987 
04988     // mark the points on the curve with the index of the curve in the array
04989     // this will allow us to project the point back to the owning curve
04990 
04991     cpoint_list.clean_out();
04992     fcurv_ptr->get_points(cpoint_list);
04993     for (jj=0; jj<cpoint_list.size(); jj++)
04994     {
04995       point_ptr = cpoint_list.get_and_step();
04996       point_ptr->marked(  idx  );
04997     }
04998     fcurve_array[idx-1] = fcurv_ptr;
04999 
05000     // mark the vertices with a negative value so we don't touch them
05001 
05002     DLIList<TBPoint *> verts;
05003     fcurv_ptr->points(verts);
05004     for(jj=0; jj<verts.size(); jj++)
05005     {
05006       TBPoint *vert = verts.get_and_step();
05007       FacetPoint *fvert = dynamic_cast<FacetPoint *> (vert);
05008       fvert->get_cubit_point()->marked(-1);
05009     }
05010   }
05011   
05012   // laplacian smoothing
05013 
05014   DLIList<CubitPoint *> adj_points;
05015   int iter, nadj;
05016   CubitPoint *adj_point_ptr;
05017   CubitVector new_location; 
05018 
05019   for (iter = 0; iter < niter; iter++)
05020   {
05021     for (ii=0; ii<point_list.size(); ii++)
05022     {
05023       point_ptr = point_list.get_and_step();
05024 
05025       // don't smooth points at vertices
05026 
05027       if (point_ptr->marked() >= 0)
05028       {
05029         adj_points.clean_out();
05030         point_ptr->adjacent_points( adj_points );
05031         new_location.set(0.0, 0.0, 0.0);
05032         nadj=0;
05033         for (jj = 0; jj<adj_points.size(); jj++)
05034         {
05035           adj_point_ptr = adj_points.get_and_step();
05036           if (point_ptr->marked()) // is on a curve
05037           {
05038             // only use points on the same curve to influence the new location
05039             if (point_ptr->marked() == adj_point_ptr->marked()) 
05040             {
05041               new_location += adj_point_ptr->coordinates();
05042               nadj++;
05043             }
05044           }
05045 
05046           // interior nodes use all adjacent points
05047           else
05048           {
05049             new_location += adj_point_ptr->coordinates();
05050             nadj++;
05051           }
05052         }
05053         new_location /= nadj;
05054 
05055         // project it to a tangent plane defined at the point.
05056         // except if we are on a curve or we're using free-laplacian option
05057         if (!free_laplacian && point_ptr->marked() == 0)
05058           new_location = point_ptr->project_to_tangent_plane( new_location );
05059 
05060         // for points on a curve project to the curve definition
05061         if(point_ptr->marked() != 0)
05062         {
05063           const CubitVector temp = new_location;
05064           fcurve_array[point_ptr->marked()-1]->closest_point( temp, 
05065                                                             new_location );
05066         }
05067       
05068         if (point_ptr->check_inverted_facets(new_location) == CUBIT_SUCCESS)
05069         {
05070           point_ptr->set(new_location);
05071         }
05072       }
05073     }
05074 
05075     // update the normals
05076 
05077     for (ii=0; ii<point_list.size(); ii++)
05078     {
05079       point_ptr = point_list.get_and_step();
05080       point_ptr->compute_avg_normal();
05081     }
05082   }
05083 
05084   return rv;
05085 }
05086 
05087 //================================================================================
05088 // Description: create a shell that is the normal offset of the given shell
05089 // Author     : Steve Owen
05090 // Date       : 8/28/2003
05091 //================================================================================
05092 CubitStatus FacetModifyEngine::create_shell_offset( BodySM *bodysm_ptr, 
05093                                                     BodySM *&new_bodysm, double offset )
05094 {
05095  // MODIFY_CHECK_RETURN_FAILURE;
05096   
05097   // check that this is a facet body
05098 
05099   FacetBody *fbody_ptr = dynamic_cast<FacetBody *>(bodysm_ptr);
05100   if (fbody_ptr == NULL)
05101   {
05102     PRINT_ERROR("Body is not a facet-based geometry.  This command is intended for use with facetted models\n");
05103     return CUBIT_FAILURE;
05104   }
05105 
05106   // The facet and point lists
05107 
05108   DLIList<CubitPoint *> point_list;
05109   DLIList<CubitFacet *> facet_list;
05110   
05111   // get the surfaces.  Check that they are also all facet bodies
05112 
05113   int ii;
05114   Surface *surf_ptr;
05115   FacetSurface *fsurf_ptr;
05116   DLIList<Surface *> surface_list;
05117   fbody_ptr->surfaces( surface_list );
05118   for (ii=0; ii<surface_list.size(); ii++)
05119   {
05120     surf_ptr = surface_list.get_and_step();
05121     fsurf_ptr = dynamic_cast<FacetSurface *>(surf_ptr);
05122     if (fsurf_ptr == NULL)
05123     {
05124       PRINT_ERROR("At least one of the surfaces in Body is not facet-based geometry.\n"  
05125                   "This command is intended for use with facetted models\n");
05126       return CUBIT_FAILURE;
05127     }
05128     fsurf_ptr->get_my_facets(facet_list, point_list);
05129   }
05130 
05131   // create an array of points so we can reference them quickly when generating new facets
05132 
05133   CubitPoint **points = new CubitPoint * [point_list.size()];
05134 
05135   // make a unique set of points
05136 
05137   int id = 0;
05138   CubitPoint *point_ptr;
05139   for (ii=0; ii < point_list.size(); ii++)
05140   {
05141     point_list.get_and_step()->marked(1);
05142   }
05143   for (ii=0; ii<point_list.size(); ii++)
05144   {
05145     point_ptr = point_list.get_and_step();
05146     if (point_ptr->marked() == 1)
05147     {
05148       point_ptr->marked(0);
05149       points[id] = point_ptr;
05150       point_ptr->set_id( id );
05151       id ++;
05152     }
05153   }
05154   int npoints = id;
05155 
05156   // get the curves and mark any point on a curve as non-smoothable.
05157 
05158   int jj;
05159   Curve *curv_ptr;
05160   FacetCurve *fcurv_ptr;
05161   DLIList<Curve *> curve_list;
05162   fbody_ptr->curves( curve_list );
05163   for(ii=0; ii<curve_list.size(); ii++)
05164   {
05165     curv_ptr = curve_list.get_and_step();
05166     fcurv_ptr = dynamic_cast<FacetCurve *>(curv_ptr);
05167     if (fcurv_ptr == NULL)
05168     {
05169       PRINT_ERROR("At least one of the curves in Body is not a facet-based geometry.\n"  
05170                   "This command is intended for use with facetted models\n"); 
05171       return CUBIT_FAILURE;
05172     }
05173     point_list.clean_out();
05174     fcurv_ptr->get_points( point_list );
05175     for(jj=0; jj<point_list.size(); jj++)
05176     {
05177       point_ptr = point_list.get_and_step();
05178       point_ptr->marked(1);
05179     }
05180   }
05181 
05182   // smooth the normals to reduce chance of overlap on concave regions
05183 
05184   CubitVector new_normal, normal;
05185   const int niter = 3;
05186   int iter, nadj;
05187   CubitPoint *adj_point_ptr;
05188   DLIList<CubitPoint *> adj_points;
05189 
05190   for (iter = 0; iter < niter; iter++)
05191   {
05192     for (ii=0; ii<npoints; ii++)
05193     {
05194       point_ptr = points[ii];
05195 
05196       // don't smooth points on curves
05197 
05198       if (point_ptr->marked() != 1)
05199       {
05200         adj_points.clean_out();
05201         point_ptr->adjacent_points( adj_points );
05202         new_normal.set(0.0, 0.0, 0.0);
05203         nadj = adj_points.size();
05204         for (jj = 0; jj<nadj; jj++)
05205         {
05206           adj_point_ptr = adj_points.get_and_step();
05207           new_normal += adj_point_ptr->normal();
05208         }
05209         new_normal.normalize();
05210         point_ptr->normal(new_normal);
05211       }
05212     }
05213   }
05214 
05215   // generate a new set of points offset from the original
05216 
05217   CubitPointData *new_point;
05218   CubitVector new_location;
05219   CubitPoint **new_points = new CubitPoint * [npoints];
05220   for (ii=0; ii<npoints; ii++)
05221   {
05222     point_ptr = points[ii];
05223     new_location = point_ptr->coordinates() + point_ptr->normal() * offset;
05224     new_point = new CubitPointData( new_location );
05225     new_point->set_id( ii );
05226     new_points[ii] = (CubitPoint *) new_point;
05227   }
05228 
05229   // generate triangles for the new shell
05230 
05231   DLIList<CubitFacet *> fix_list;
05232   DLIList<CubitFacet *> orig_list;
05233   double dot;
05234   double mindot = 1.0;
05235   CubitFacet *facet_ptr, *new_facet_ptr;
05236   DLIList<CubitFacet *> new_facet_list;
05237   CubitPoint *p0, *p1, *p2;
05238   CubitPoint *np0, *np1, *np2;
05239   for(ii=0; ii<facet_list.size(); ii++)
05240   {
05241     facet_ptr = facet_list.get_and_step();
05242     facet_ptr->points( p0, p1, p2 );
05243     np0 = new_points[p0->id()];
05244     np1 = new_points[p1->id()];
05245     np2 = new_points[p2->id()];
05246     new_facet_ptr = (CubitFacet *) new CubitFacetData( np0, np1, np2 );
05247     new_facet_list.append( new_facet_ptr );
05248 
05249     // compare normals to see if we inverted anything
05250 
05251     normal = facet_ptr->normal();
05252     new_normal = new_facet_ptr->normal();
05253     dot = normal % new_normal;
05254     if (dot < mindot) mindot = dot;
05255     if (dot < 0.707)
05256     {
05257       new_facet_ptr->marked(1);
05258       fix_list.append( new_facet_ptr );
05259       orig_list.append( facet_ptr );
05260     }
05261   }
05262 
05263   // go back and try to uninvert tris if needed
05264 
05265   int kk;
05266   DLIList<CubitFacet *> problem_list;
05267   if (fix_list.size() > 0)
05268   {
05269     new_location.set(0.0, 0.0, 0.0); 
05270     for (iter = 0; iter < niter; iter++)
05271     {
05272       for (ii=0; ii<fix_list.size(); ii++)
05273       {
05274         facet_ptr = fix_list.get_and_step();
05275         point_list.clean_out();
05276         facet_ptr->points( point_list );
05277         for (jj=0; jj<point_list.size(); jj++)
05278         {
05279           point_ptr = point_list.get_and_step();
05280 
05281           // don't smooth marked points
05282 
05283           if (point_ptr->marked() != 1)
05284           {
05285             adj_points.clean_out();
05286             point_ptr->adjacent_points( adj_points );
05287             new_location.set(0.0, 0.0, 0.0);
05288             nadj = adj_points.size();
05289             for (kk = 0; kk<nadj; kk++)
05290             {
05291               adj_point_ptr = adj_points.get_and_step();
05292               new_location += adj_point_ptr->coordinates();
05293             }
05294             new_location /= nadj;
05295             point_ptr->set(new_location);
05296           }
05297         }
05298       }
05299     }
05300 
05301     // see if it worked
05302 
05303     fix_list.reset();
05304     orig_list.reset();
05305     for(ii=0; ii<fix_list.size(); ii++)
05306     {
05307       new_facet_ptr = fix_list.get_and_step();
05308       facet_ptr = orig_list.get_and_step();
05309       new_facet_ptr->update_plane();
05310       new_normal = new_facet_ptr->normal();
05311       normal = facet_ptr->normal();
05312       dot = normal % new_normal;
05313       if (dot < 0.707)
05314       {
05315         problem_list.append( new_facet_ptr );
05316       }
05317     }
05318   }
05319 
05320   // set the normals back the way they were and clean up
05321 
05322   for (ii=0; ii<npoints; ii++)
05323   {
05324     point_ptr = points[ii];
05325     point_ptr->compute_avg_normal();
05326   }
05327   delete [] points;
05328   delete [] new_points;
05329 
05330   // build the geometry
05331 
05332   const char *file_name = NULL;
05333   CubitBoolean use_feature_angle = CUBIT_TRUE;
05334   double feature_angle = 0.0;
05335   int interp_order = 0;
05336   CubitBoolean smooth_non_manifold = CUBIT_TRUE;
05337   CubitBoolean split_surfaces = CUBIT_FALSE;
05338   CubitBoolean stitch = CUBIT_FALSE;
05339   CubitBoolean improve = CUBIT_FALSE;
05340   DLIList<CubitQuadFacet *> quad_facet_list;
05341   DLIList<Surface *> new_surface_list;
05342   FacetFileFormat file_format = FROM_FACET_LIST;
05343 
05344   CubitStatus rv =
05345   FacetQueryEngine::instance()->import_facets( file_name, use_feature_angle, feature_angle, 0.0, 
05346                                    interp_order, smooth_non_manifold,
05347                                    split_surfaces, stitch, improve, quad_facet_list,
05348                                    new_facet_list, new_surface_list, file_format );
05349   
05350   if(problem_list.size() > 0)
05351   {
05352     PRINT_WARNING("Offset process on facet body, may have resulted in %d overalapping facets.\n"
05353                   "Check results carefully. Problem facet(s) are displayed in red.)\n", 
05354                   problem_list.size());
05355     for (ii=0; ii<problem_list.size(); ii++)
05356     {
05357       facet_ptr = problem_list.get_and_step();
05358       GfxDebug::draw_facet(facet_ptr, CUBIT_RED_INDEX);
05359     }
05360     GfxDebug::flush();
05361   }
05362 
05363   if( new_surface_list.size() )
05364   {
05365     new_bodysm = new_surface_list.get()->bodysm();
05366     if( !new_bodysm ) 
05367     {
05368       PRINT_ERROR("Problem offsetting Body\n");
05369       return CUBIT_FAILURE;
05370     }
05371   }
05372   else
05373   {
05374     PRINT_ERROR("Problem offsetting Body\n");
05375     return CUBIT_FAILURE;
05376   }
05377   return rv;
05378 }
05379 
05380 CubitStatus FacetModifyEngine::webcut_with_sweep_surfaces(
05381                                  DLIList<BodySM*> &blank_bodies,
05382                                  DLIList<Surface*> &surfaces,
05383                                  const CubitVector& sweep_vector,
05384                                  bool sweep_perp, 
05385                                  bool through_all,
05386                                  bool outward,
05387                                  bool up_to_next, 
05388                                  Surface *stop_surf, 
05389                                  Curve *curve_to_sweep_along, 
05390                                  DLIList<BodySM*> &/*neighbor_imprint_list*/,
05391                                  DLIList<BodySM*> &results_list,
05392                                  ImprintType imprint_type,
05393                                  bool /*preview*/)
05394 {
05395   PRINT_ERROR("Option not supported for mesh based geometry.\n");
05396   return CUBIT_FAILURE;
05397 }
05398 
05399 CubitStatus FacetModifyEngine::webcut_with_sweep_curves(
05400                                  DLIList<BodySM*> &blank_bodies,
05401                                  DLIList<Curve*> &curves,
05402                                  const CubitVector& sweep_vector,
05403                                  bool through_all, 
05404                                  Surface *stop_surf, 
05405                                  Curve *curve_to_sweep_along, 
05406                                  DLIList<BodySM*> &/*neighbor_imprint_list*/,
05407                                  DLIList<BodySM*> &results_list,
05408                                  ImprintType imprint_type,
05409                                  bool /*preview*/)
05410 {
05411   PRINT_ERROR("Option not supported for mesh based geometry.\n");
05412   return CUBIT_FAILURE;
05413 }
05414 
05415 CubitStatus FacetModifyEngine::webcut_with_sweep_surfaces_rotated(
05416                                  DLIList<BodySM*> &blank_bodies,
05417                                  DLIList<Surface*> &surfaces,
05418                                  const CubitVector &point, 
05419                                  const CubitVector &sweep_axis, 
05420                                  double angle, 
05421                                  Surface *stop_surf, 
05422                                  bool up_to_next, 
05423                                  DLIList<BodySM*> &/*neighbor_imprint_list*/,
05424                                  DLIList<BodySM*> &results_list,
05425                                  ImprintType imprint_type,
05426                                  bool /*preview*/)
05427 {
05428   PRINT_ERROR("Option not supported for mesh based geometry.\n");
05429   return CUBIT_FAILURE;
05430 }
05431 
05432 CubitStatus FacetModifyEngine::webcut_with_sweep_curves_rotated(
05433                                  DLIList<BodySM*> &blank_bodies,
05434                                  DLIList<Curve*> &curves,
05435                                  const CubitVector &point, 
05436                                  const CubitVector &sweep_axis, 
05437                                  double angle, 
05438                                  Surface *stop_surf, 
05439                                  DLIList<BodySM*> &/*neighbor_imprint_list*/,
05440                                  DLIList<BodySM*> &results_list,
05441                                  ImprintType imprint_type,
05442                                  bool /*preview*/)
05443 {
05444   PRINT_ERROR("Option not supported for mesh based geometry.\n");
05445   return CUBIT_FAILURE;
05446 }
05447 
05448 CubitStatus FacetModifyEngine::scale( BodySM *&body, const CubitVector& factors )
05449 {
05450   return FacetQueryEngine::instance()->scale( body, factors );
05451 }
05452 
05453 CubitStatus FacetModifyEngine::tolerant_imprint( DLIList<BodySM*> &bodies_in,
05454                                                  DLIList<BodySM*> &new_bodies,
05455                                                 double overlap_tol,
05456                                                 double imprint_tol,
05457                                    DLIList<TopologyBridge*> *new_tbs,
05458                                    DLIList<TopologyBridge*> *att_tbs )  const
05459 {
05460   PRINT_ERROR("Option not supported for mesh based geometry.\n");
05461   return CUBIT_FAILURE;
05462 }
05463 
05464 CubitStatus FacetModifyEngine::tolerant_imprint( DLIList<Surface*> &surfs_in,
05465       DLIList<BodySM*> &new_bodysm_list)  const
05466 {
05467   PRINT_ERROR("Option not supported for mesh based geometry.\n");
05468   return CUBIT_FAILURE;
05469 }
05470 
05471 CubitStatus FacetModifyEngine::tolerant_imprint_surface_with_curves( 
05472                                                    Surface * /*surface_to_imprint*/,
05473                                                    DLIList<Curve*> & /*curves*/,
05474                                                    DLIList<TopologyBridge*> &temporary_bridges,
05475                                                    BodySM *& /*new_body*/, 
05476                                                    DLIList<TopologyBridge*> *new_tbs,
05477                                                    DLIList<TopologyBridge*> *att_tbs) const 
05478 {
05479   PRINT_ERROR("Option not supported for mesh based geometry.\n");
05480   return CUBIT_FAILURE;
05481 }
05482 
05483 CubitStatus FacetModifyEngine::curve_surface_intersection( Surface * /*surface*/, 
05484                                                            Curve* /*curve*/,
05485                                                            DLIList<Curve*> &/*new_curves*/ ) const
05486 {
05487   PRINT_ERROR("Option not supported for mesh based geometry.\n");
05488   return CUBIT_FAILURE;
05489 }
05490 
05491 BodySM* FacetModifyEngine::create_body( VolumeFacets& volume,  std::map<FacetShapes*, GeometryEntity*>& entity_map,
05492                                        const FacetPointSet& points, int interp_order) const
05493 {
05494   FacetModifyEngine* self = const_cast<FacetModifyEngine*>(this);
05495   
05496   // loop and make points
05497   size_t num_points = points.size() / 3;
05498   DLIList<CubitPoint*> cubit_points(num_points);
05499   
05500   std::map<SurfaceFacets*, DLIList<CubitFacet*> > facet_map;
05501   std::map<CurveFacets*, DLIList<CubitFacetEdge*> > facet_edge_map;
05502   
05503   // create facets  (all facets must be created first so facet edges between surfaces are set up properly)
05504   self->create_facets(volume.surfaceTopology, points, interp_order, cubit_points, facet_map, facet_edge_map);
05505 
05506   // now create the topology on top of the facets that were created
05507   DLIList<Surface*> surface_list;
05508   DLIList<CubitSense> surface_sense_list;
05509   for(size_t i=0; i<volume.surfaceTopology.size(); i++)
05510   {
05511     SurfaceFacets* surf = volume.surfaceTopology[i].first;
05512     CubitSense sense = volume.surfaceTopology[i].second;
05513     if ( CUBIT_SUCCESS != self->process_topology(surf, sense, interp_order, cubit_points, facet_map, facet_edge_map, entity_map) )
05514       return NULL;
05515     surface_list.append((Surface*)entity_map[surf]);
05516     surface_sense_list.append(sense);
05517   }
05518 
05519   // finish creation of body from list of surfaces (shell, lump, etc...)
05520   BodySM *body_ptr = NULL;
05521   finish_facet_Body(surface_list, surface_sense_list, body_ptr);
05522   entity_map[&volume] = body_ptr->lump();
05523   return body_ptr;
05524 }
05525 
05526 #ifdef KCM_MESH_TO_GEOM  
05527 CubitStatus FacetModifyEngine::mesh2brep(std::vector<double> &xvals,
05528                         std::vector<double> &yvals,
05529                         std::vector<double> &zvals,
05530                         std::vector<unsigned int> &tri_connectivity,
05531                         DLIList<BodySM*> &new_body_sms) const
05532 {
05533   PRINT_ERROR("Option not supported for mesh based geometry.\n");
05534   return CUBIT_FAILURE;
05535 }
05536 #endif
05537 
05538 void FacetModifyEngine::create_facets(
05539     const std::vector<std::pair<SurfaceFacets*, CubitSense> >& surfaceTopology,
05540     const FacetPointSet& points,
05541     int interp_order,
05542     DLIList<CubitPoint*>& cubit_points,
05543     std::map<SurfaceFacets*, DLIList<CubitFacet*> >& facet_map,
05544     std::map<CurveFacets*, DLIList<CubitFacetEdge*> >& facet_edge_map)
05545 {
05546   // loop and make points
05547   size_t num_points = points.size() / 3;
05548   for(size_t i=0; i<num_points; i++)
05549   {
05550     cubit_points.append(new CubitPointData(CubitVector(points[i*3], points[i*3+1], points[i*3+2])));
05551   }
05552 
05553   DLIList<CubitFacet*> all_facets;
05554     
05555   // process facets for each surface
05556   for(size_t i=0; i<surfaceTopology.size(); i++)
05557   {
05558     CubitSense coface_sense = surfaceTopology[i].second;
05559     SurfaceFacets* surface = surfaceTopology[i].first;
05560 
05561     DLIList<CubitFacet*> surface_facets;
05562 
05563     for(size_t j=0; j<surface->facetConnectivity.size(); j+=3)
05564     {
05565       CubitFacetData* cfe;
05566       if(coface_sense == CUBIT_REVERSED)
05567       {
05568        cfe = new CubitFacetData(
05569           cubit_points[surface->facetConnectivity[j]],
05570           cubit_points[surface->facetConnectivity[j+2]],
05571           cubit_points[surface->facetConnectivity[j+1]]);
05572       }
05573       else
05574       {
05575        cfe = new CubitFacetData(
05576           cubit_points[surface->facetConnectivity[j]],
05577           cubit_points[surface->facetConnectivity[j+1]],
05578           cubit_points[surface->facetConnectivity[j+2]]);
05579       }
05580       surface_facets.append(cfe);
05581     }
05582 
05583     facet_map.insert(std::make_pair(surface, surface_facets));
05584     all_facets += surface_facets;
05585   }
05586 
05587   // make facet edges for curves
05588   DLIList<CubitFacetEdge*> feature_edges;
05589   std::map<SurfaceFacets*, DLIList<CubitFacet*> >::iterator facet_map_iter;
05590   for(facet_map_iter = facet_map.begin(); facet_map_iter != facet_map.end(); ++facet_map_iter)
05591   {
05592     SurfaceFacets* surface = facet_map_iter->first;
05593     int num_loops = surface->curveTopology.size();
05594     for(int i=0; i<num_loops; i++)
05595     {
05596       int num_curves = surface->curveTopology[i].size();
05597       for(int j=0; j<num_curves; j++)
05598       {
05599         CurveFacets* edge_facets = surface->curveTopology[i][j].first;
05600 
05601         if(facet_edge_map.find(edge_facets) == facet_edge_map.end())
05602         {
05603           DLIList<CubitFacetEdge*> curve_facets;
05604           const std::vector<int>& curve_pts = edge_facets->points;
05605           for(size_t k=0; k<curve_pts.size()-1; k++)
05606           {
05607             CubitPoint* p1 = cubit_points[curve_pts[k]];
05608             CubitPoint* p2 = cubit_points[curve_pts[k+1]];
05609             CubitFacetEdge* edge = new CubitFacetEdgeData(p1, p2);
05610             feature_edges.append(edge);
05611             curve_facets.append(edge);
05612             edge->set_as_feature();
05613           }
05614           facet_edge_map.insert(std::make_pair(edge_facets, curve_facets));
05615         }
05616       }
05617     }
05618   }
05619 
05620   // create facet edges for facets
05621   DLIList<CubitFacetEdge*> all_edges;
05622   FacetDataUtil::get_edges(all_facets, all_edges);
05623 
05624   // create features edges (this puts multiple normals when necessary on features)
05625   ChollaEngine::make_features( feature_edges, CUBIT_FALSE );
05626   
05627 }
05628 
05629 CubitStatus FacetModifyEngine::process_topology(SurfaceFacets* surface, CubitSense& coface_sense,
05630     int interp_order, const DLIList<CubitPoint*>& cubit_points,
05631     std::map<SurfaceFacets*, DLIList<CubitFacet*> >& facet_map, 
05632     std::map<CurveFacets*, DLIList<CubitFacetEdge*> >& facet_edge_map, 
05633     std::map<FacetShapes*, GeometryEntity*>& entity_map)
05634 {
05635 
05636   DLIList<CubitFacet*>& surface_facets = facet_map.find(surface)->second;
05637   DLIList<CubitPoint*> surface_points;
05638   for(int i=0; i<surface_facets.size(); i++)
05639   {
05640     surface_facets[i]->points(surface_points);
05641   }
05642   surface_points.uniquify_unordered();
05643   FacetEvalTool* surf_eval = new FacetEvalTool();
05644   if ( CUBIT_SUCCESS != surf_eval->initialize(surface_facets, surface_points, interp_order, -1.0 ) )
05645     return CUBIT_FAILURE;
05646 
05647   int num_loops = surface->curveTopology.size();
05648 
05649   DLIList<LoopSM*> loops;
05650 
05651   // loop through curves and construct them 
05652   // surfaces that are reversed are flipped so we have outward facing normals (do we really need to do this?)
05653   for(int i=0; i<num_loops; i++)
05654   {
05655     DLIList<CoEdgeSM*> current_loop;
05656     int num_curves = surface->curveTopology[i].size();
05657     for(int j=0; j<num_curves; j++)
05658     {
05659       CurveFacets* edge_facets = surface->curveTopology[i][j].first;
05660       CubitSense coedge_sense = surface->curveTopology[i][j].second;
05661       if(coface_sense == CUBIT_REVERSED)
05662       {
05663         coedge_sense = coedge_sense == CUBIT_FORWARD ? CUBIT_REVERSED : CUBIT_FORWARD;
05664       }
05665       process_topology(edge_facets, cubit_points, surf_eval, coedge_sense, facet_edge_map, entity_map);
05666       
05667       CoEdgeSM* tmp_coedge;
05668       make_facet_coedge((Curve*)entity_map[surface->curveTopology[i][j].first], coedge_sense, tmp_coedge);
05669 
05670       if(coface_sense == CUBIT_REVERSED)
05671       {
05672         current_loop.insert_first(tmp_coedge);
05673       }
05674       else
05675       {
05676         current_loop.append(tmp_coedge);
05677       }
05678     }
05679 
05680     // make loop
05681     LoopSM* tmp_loop;
05682     make_facet_loop(current_loop, tmp_loop);
05683     loops.append(tmp_loop);
05684   }
05685  
05686   // we've reversed it, so tell the caller
05687   if(coface_sense == CUBIT_REVERSED)
05688   {
05689     coface_sense = CUBIT_FORWARD;
05690   }
05691 
05692   Surface* surf_ptr;
05693   make_facet_surface(NULL, surface_facets, surface_points, loops, interp_order, -1.0,
05694                      surf_ptr, CUBIT_TRUE, surf_eval);
05695   entity_map[surface] = surf_ptr;
05696   return CUBIT_SUCCESS;
05697 }
05698 
05699 void FacetModifyEngine::process_topology(CurveFacets* curve,
05700     const DLIList<CubitPoint*>& cubit_points, FacetEvalTool* surf_eval, CubitSense sense,
05701     std::map<CurveFacets*, DLIList<CubitFacetEdge*> >& facet_edge_map, 
05702     std::map<FacetShapes*, GeometryEntity*>& entity_map)
05703 {
05704   // construct each point for the curves
05705 
05706   for(size_t j=0; j<2; j++)
05707   {
05708     VertexFacets* vertex_facets = curve->vertexTopology[j];
05709     if(entity_map.find(vertex_facets) == entity_map.end())
05710     {
05711       TBPoint* new_vertex;
05712       make_facet_point(cubit_points[vertex_facets->point], new_vertex);
05713       entity_map.insert(std::make_pair(vertex_facets, new_vertex));
05714     }
05715   }
05716     
05717   // construct the curve
05718   if(entity_map.find(curve) == entity_map.end())
05719   {
05720     DLIList<CubitFacetEdge*>& edge_list = facet_edge_map[curve];
05721     DLIList<CubitPoint*> point_list;
05722 
05723     for(int k=0; k<edge_list.size(); k++)
05724     {
05725       point_list.append(edge_list[k]->point(0));
05726     }
05727     point_list.append(edge_list[edge_list.size()-1]->point(1));
05728 
05729     CurveFacetEvalTool* curve_facet_tool = new CurveFacetEvalTool;
05730     CubitStatus status = curve_facet_tool->initialize( edge_list, point_list, surf_eval);
05731     if (CUBIT_SUCCESS != status) {
05732       PRINT_ERROR("Failed to intitialize a CurveFacetEvalTool.\n");
05733       return;
05734     }
05735     Curve* curve_ptr;
05736     make_facet_curve((TBPoint*)entity_map[curve->vertexTopology[0]], 
05737                      (TBPoint*)entity_map[curve->vertexTopology[1]], 
05738                      curve_ptr, curve_facet_tool);
05739     entity_map.insert(std::make_pair(curve, curve_ptr));
05740   }
05741 }
05742 
05743 // EOF
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines