cgma
GeometryModifyTool.cpp File Reference
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include <sstream>
#include "GeometryModifyTool.hpp"
#include "CubitDefines.h"
#include "GeometryDefines.h"
#include "GeometryEntity.hpp"
#include "GeometryQueryTool.hpp"
#include "MergeTool.hpp"
#include "SurfaceOverlapTool.hpp"
#include "GeometryQueryEngine.hpp"
#include "OldUnmergeCode.hpp"
#include "GeometryModifyEngine.hpp"
#include "AnalyticGeometryTool.hpp"
#include "DAG.hpp"
#include "TopologyBridge.hpp"
#include "ModelQueryEngine.hpp"
#include "CADefines.hpp"
#include "GeomMeasureTool.hpp"
#include "LocalToleranceTool.hpp"
#include "RefEntity.hpp"
#include "RefEntityFactory.hpp"
#include "RefEntityName.hpp"
#include "BasicTopologyEntity.hpp"
#include "RefVertex.hpp"
#include "RefEdge.hpp"
#include "RefFace.hpp"
#include "RefVolume.hpp"
#include "CoVertex.hpp"
#include "CoEdge.hpp"
#include "CoFace.hpp"
#include "CoVolume.hpp"
#include "Chain.hpp"
#include "Loop.hpp"
#include "Shell.hpp"
#include "Body.hpp"
#include "Lump.hpp"
#include "Surface.hpp"
#include "Curve.hpp"
#include "Point.hpp"
#include "BodySM.hpp"
#include "ShellSM.hpp"
#include "LoopSM.hpp"
#include "CoEdgeSM.hpp"
#include "CubitAttrib.hpp"
#include "CubitVector.hpp"
#include "CubitPlane.hpp"
#include "CubitTransformMatrix.hpp"
#include "GfxPreview.hpp"
#include "AppUtil.hpp"
#include "DLIList.hpp"
#include "CubitMessage.hpp"
#include "SettingHandler.hpp"
#include "CastTo.hpp"
#include "CpuTimer.hpp"
#include "BridgeManager.hpp"
#include "SplitSurfaceTool.hpp"
#include "OffsetSplitTool.hpp"
#include "AutoMidsurfaceTool.hpp"
#include "TDSurfaceOverlap.hpp"
#include "GfxDebug.hpp"
#include "CubitUndo.hpp"

Go to the source code of this file.

Functions

CubitStatus prepare_surface_sweep (DLIList< BodySM * > &blank_bodies, DLIList< Surface * > &surfaces, const CubitVector &sweep_vector, bool sweep_perp, bool through_all, bool outward, bool up_to_next, Surface *stop_surf, Curve *curve_to_sweep_along, BodySM *&cutting_tool_ptr, const CubitVector *point=NULL, double *angle=NULL)
CubitStatus webcut_w_cylinder (DLIList< BodySM * > &webcut_body_list, double radius, const CubitVector &axis, const CubitVector &center, DLIList< BodySM * > &neighbor_imprint_list, DLIList< BodySM * > &results_list, ImprintType imprint_type=NO_IMPRINT)
CubitStatus get_planar_mid_surface (RefFace *ref_face1, RefFace *ref_face2, BodySM *body_sm_to_trim_to, BodySM *&midsurface_body_sm, GeometryModifyEngine *gme_ptr)

Function Documentation

CubitStatus get_planar_mid_surface ( RefFace ref_face1,
RefFace ref_face2,
BodySM body_sm_to_trim_to,
BodySM *&  midsurface_body_sm,
GeometryModifyEngine gme_ptr 
)

Definition at line 12267 of file GeometryModifyTool.cpp.

{
    CubitVector normal_1, normal_2, point_1, point_2, point_3;
    CubitPlane plane_1, plane_2;
    CubitVector p_mid, n_mid;

    point_1 = ref_face1->center_point();
    point_2 = ref_face2->center_point();

    normal_1 = ref_face1->normal_at(point_1);
    normal_2 = ref_face2->normal_at(point_2);

    plane_1 = CubitPlane(normal_1,point_1);
    plane_2 = CubitPlane(normal_2,point_2);

    if(point_1 == point_2)
    {
      PRINT_ERROR( "In GeometryModifyTool:: get_planar_mid_surface\n"
           "       Since both surfaces share the same point, the midsurface is not well-defined\n");
      return CUBIT_FAILURE;
    }
    else
    {
      CubitVector temp1 = point_2;
      temp1 = plane_1.project(temp1);
      temp1 -= point_2;
      if ( temp1.length_squared() < GEOMETRY_RESABS*GEOMETRY_RESABS )
    {
    PRINT_ERROR("In GeometryModifyTool:: get_planar_mid_surface\n"
            "       Since both planes are the same, the midsurface is not well-defined.\n");
    return CUBIT_FAILURE;
    }
    }

    if ( ( normal_1.about_equal( normal_2 ) ) || ( (-normal_1).about_equal( normal_2 ) ) )
    {
      p_mid = (point_1+point_2)/2;
      n_mid = plane_1.normal();
    }
    else
    {
      CubitVector direction_of_line;
      plane_1.intersect(plane_2,p_mid,direction_of_line);
      direction_of_line.normalize();

      // Find if point_1 and point_2 are on the line of intersection
      // If they are, then the mid-plane is not well-defined
      CubitVector p1 = point_1-p_mid;
      CubitVector p2 = point_2-p_mid;
      p1.normalize();
      p2.normalize();

      if(p1==direction_of_line || p1==-direction_of_line)
      {
    PRINT_ERROR("In GeometryModifyTool:: get_planar_mid_surface\n"
            "       P1 is on the line of intersection.\n");
    return CUBIT_FAILURE;
      }

      if(p2==direction_of_line || p2==-direction_of_line)
      {
    PRINT_ERROR("In GeometryModifyTool:: get_planar_mid_surface\n"
            "       P2 is on the line of intersection.\n");
    return CUBIT_FAILURE;
      }

      CubitVector v1 = p1 - (p1%direction_of_line)*direction_of_line;
      v1.normalize();

      CubitVector v2 = p2 - (p2%direction_of_line)*direction_of_line;
      v2.normalize();

      n_mid = v1 - v2;
      n_mid.normalize();
    }

    CubitPlane mid_plane(n_mid, p_mid);
    point_1 = p_mid;

    //find three points that will define the infinite plane from the
    //mid plane.through the point in any direction just not along the
    //normal direction
    CubitVector Xdir(1,0,0), Ydir(0,1,0);
    CubitVector direction1;

    if ( ( ! n_mid.about_equal( Xdir ) ) && ( ! (-n_mid).about_equal( Xdir ) ) )
      direction1 = Xdir + n_mid;
    else
      direction1 = Ydir + n_mid;

    point_2 = p_mid + direction1;
    point_2 = mid_plane.project(point_2);

    direction1 = point_2-point_1;
    CubitVector direction2 = direction1*n_mid;
    point_3 = point_1 + direction2;

    CubitStatus ret = gme_ptr->get_mid_plane(point_1, point_2, point_3,
                          body_sm_to_trim_to, midsurface_body_sm );
    return ret;
}
CubitStatus prepare_surface_sweep ( DLIList< BodySM * > &  blank_bodies,
DLIList< Surface * > &  surfaces,
const CubitVector sweep_vector,
bool  sweep_perp,
bool  through_all,
bool  outward,
bool  up_to_next,
Surface stop_surf,
Curve curve_to_sweep_along,
BodySM *&  cutting_tool_ptr,
const CubitVector point = NULL,
double *  angle = NULL 
)

Definition at line 21363 of file GeometryModifyTool.cpp.

{
  GeometryModifyEngine* gme = GeometryModifyTool::instance()->
                                  get_engine(blank_bodies.get());

  if(surfaces.size() == 0 )
    return CUBIT_FAILURE;

  DLIList<GeometryEntity*> ref_ent_list;
  Surface * temp_face = NULL;
  for(int i = 0; i < surfaces.size(); i++)
    {
      //copy the faces before sweep
      temp_face = gme->make_Surface(surfaces.get_and_step());
      if (temp_face)
        ref_ent_list.append((GeometryEntity*)temp_face);
    }

  BodySM* to_body = NULL;
  CubitStatus stat = CUBIT_SUCCESS;
  if(up_to_next && blank_bodies.size() > 1) //unite all bland_bodies
    {
       DLIList<BodySM*> newBodies;
       DLIList<BodySM*> copied_bodies;
       for(int i = 0; i < blank_bodies.size(); i++)
         copied_bodies.append(gme->copy_body(blank_bodies.get_and_step()));

       stat = gme->unite(copied_bodies, newBodies);
       if(stat == CUBIT_FAILURE)
         {
           PRINT_ERROR("Cannot use 'up_to_next' option with specified geometry\n");
           PRINT_INFO("Try the 'stop surface <id>' option instead\n");
           return stat;
         }
       to_body = newBodies.get();
    }

  else if(up_to_next && blank_bodies.size() == 1)
    to_body = gme->copy_body(blank_bodies.get());

  DLIList<BodySM*> swept_bodies;
  if (point && angle) //sweep_surface_rotated
    stat = gme->sweep_rotational(ref_ent_list,swept_bodies,*point,
                           sweep_vector, *angle,0, 0.0,0,false,false,
                           false,stop_surf, to_body);

  else
  {
    CubitVector tmp_sweep_vector = sweep_vector;

    //get model bbox info...will scale sweep vector by its diagonal
    //so that we go far enough
    if( through_all || stop_surf || up_to_next)
    {
      CubitBox bounding_box = GeometryQueryTool::instance()->model_bounding_box();
      tmp_sweep_vector.normalize();
      tmp_sweep_vector*=(2*bounding_box.diagonal().length());
    }

    //see if we're sweeping along a specified curve
    if( curve_to_sweep_along )
      {
        DLIList<Curve*> curves_to_sweep_along;
        curves_to_sweep_along.append(curve_to_sweep_along);
        stat = gme->sweep_along_curve(ref_ent_list, swept_bodies,
                                 curves_to_sweep_along, 0.0,0,false,stop_surf,
                                 to_body);
      }

    else if (sweep_perp )
      stat = gme->sweep_perpendicular(ref_ent_list, swept_bodies,
                                 tmp_sweep_vector.length(),0.0,0,!outward,false,
                                 stop_surf, to_body);
    else
      stat = gme->sweep_translational(ref_ent_list, swept_bodies,
                                 tmp_sweep_vector,0.0,0, false, false, stop_surf,
                                 to_body);
  }

  if(stat == CUBIT_FAILURE || swept_bodies.size() == 0)
    {
       //delete copied faces
       GeometryEntity * temp_entity = NULL;
       for(int i = ref_ent_list.size();i--;)
         {
            temp_entity = ref_ent_list.get_and_step();
            if (temp_entity)
              gme->get_gqe()->delete_solid_model_entities( (Surface*)temp_entity);
         }

       return stat;
    }

  //if there are more than 1, unite them all
  DLIList<BodySM*>  newBodies;
  if (swept_bodies.size() > 1)
     stat = gme->unite(swept_bodies, newBodies);
  else
     newBodies = swept_bodies;

  if(stat == CUBIT_FAILURE || newBodies.size()!= 1)
    {
       PRINT_ERROR("webcut tool body is not created from occ.\n");
       //delete the swept_bodies
       BodySM* tmp_body = NULL;
       for (int i = swept_bodies.size(); i--;)
         {
           tmp_body= swept_bodies.get_and_step();
           if (tmp_body)
             gme->get_gqe()->delete_solid_model_entities(tmp_body);
         }

       //delete copied faces
       GeometryEntity * temp_entity = NULL;
       for(int i = ref_ent_list.size();i--;)
         {
            temp_entity = ref_ent_list.get_and_step();
            if (temp_entity)
              gme->get_gqe()->delete_solid_model_entities( (Surface*)temp_entity);
         }
       return CUBIT_FAILURE;
    }

    cutting_tool_ptr = newBodies.get();
    return stat;
}
CubitStatus webcut_w_cylinder ( DLIList< BodySM * > &  webcut_body_list,
double  radius,
const CubitVector axis,
const CubitVector center,
DLIList< BodySM * > &  neighbor_imprint_list,
DLIList< BodySM * > &  results_list,
ImprintType  imprint_type = NO_IMPRINT 
)

Definition at line 21993 of file GeometryModifyTool.cpp.

{
  GeometryModifyEngine* gme = 0;
  gme = GeometryModifyTool::instance()->
                    get_engine(webcut_body_list.get());
  assert(gme);

  double max_size =  0.;
  //lets find the distance to the center for each body and take
  //the max.
  double curr;
  CubitVector cent_bod;
  CubitBox bounding_box;
  BodySM *body_ptr;
  bounding_box = webcut_body_list[0]->bounding_box();
  cent_bod =  bounding_box.center();
  cent_bod = cent_bod - center;
  curr = cent_bod.length();
  if ( curr > max_size )
     max_size = curr;


  for ( int ii = webcut_body_list.size()-1; ii > 0; ii-- )
    {
      body_ptr = webcut_body_list[ii];
      bounding_box |= body_ptr->bounding_box();
      cent_bod = body_ptr->bounding_box().center();
      cent_bod = cent_bod - center;
      curr = cent_bod.length();
      if ( curr > max_size )
        max_size = curr;
    }

  curr = bounding_box.diagonal().length();

  if ( curr > max_size )
     max_size = curr;

  double height = 0.0;
  if ( center.x() > max_size )
    {
      height = 500.0 * center.x();
    }
  else if ( center.y() > max_size )
    {
      height = 500.0 * center.y();
    }
  else if ( center.z() > max_size )
    {
      height = 500.0 * center.z();
    }
  else
    {
      height = 500.0 * max_size;
    }

  //lets make certain we have a valid height..
  if ( height < GEOMETRY_RESABS )
    {
      height = 500.0;
    }

  BodySM *cutting_tool_ptr = gme->cylinder( height, radius, radius, radius );

  if( cutting_tool_ptr == NULL )
    return CUBIT_FAILURE;

  //transform the cyclinder to cernter and axis
  // The current frustum is centered on the z axis.
  CubitVector axis2(0., 0., 1.0 );
  //now find the normal to the current axis and axis we want to be
  //at. This normal is where we will rotate about.
  CubitVector normal_axis = axis2 * axis;
  if ( normal_axis.length() > CUBIT_RESABS )
    {
       //angle in degrees.
       double angle = normal_axis.vector_angle( axis2, axis );
       gme->get_gqe()->rotate(cutting_tool_ptr, normal_axis, angle);
    }
  gme->get_gqe()->translate(cutting_tool_ptr, center);

  CubitStatus stat = gme->webcut( webcut_body_list, cutting_tool_ptr,
              neighbor_imprint_list, results_list, imprint_type) ;

  // Delete the BodySM that was created to be used as a tool
  gme->get_gqe()->delete_solid_model_entities(cutting_tool_ptr) ;

  return stat;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines