cgma
Body.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : Body.cpp
00003 //
00004 // Purpose       : This file contains the implementation of the class
00005 //                  Body. 
00006 //
00007 // Special Notes :
00008 //
00009 // Creator       : 
00010 //
00011 // Creation Date : 
00012 //
00013 // Owner         : 
00014 //-------------------------------------------------------------------------
00015 
00016 #include <assert.h>
00017 #include "CubitDefines.h"
00018 #include "CubitMessage.hpp"
00019 #include "CubitBox.hpp"
00020 
00021 #include "BodySM.hpp"
00022 #include "Body.hpp"
00023 
00024 #include "CoVolume.hpp"
00025 #include "CoEdge.hpp"
00026 
00027 #include "RefVolume.hpp"
00028 #include "RefFace.hpp"
00029 #include "RefEdge.hpp"
00030 #include "DLIList.hpp"
00031 #include "RefEntityFactory.hpp"
00032 #include "GeometryQueryTool.hpp"
00033 #include "GeometryQueryEngine.hpp"
00034 #include "CastTo.hpp"
00035 
00036 
00037 //-------------------------------------------------------------------------
00038 // Purpose       : Default constructor.
00039 //
00040 // Special Notes :
00041 //
00042 // Creator       : Xuechen Liu
00043 //
00044 // Creation Date : 08/06/96
00045 //-------------------------------------------------------------------------
00046 Body::Body()
00047 {
00048 }
00049 
00050 //-------------------------------------------------------------------------
00051 // Purpose       : A constructor with a pointer to an TopologyBridge
00052 //                 as input.
00053 //
00054 // Special Notes :
00055 //
00056 // Creator       : Xuechen Liu
00057 //
00058 // Creation Date : 08/06/96
00059 //-------------------------------------------------------------------------
00060 Body::Body(BodySM* OSMEPtr)
00061 {
00062    // Set the new Body's OSME pointer
00063    if (OSMEPtr != NULL)
00064    { 
00065       set_topology_bridge(OSMEPtr) ;
00066    }
00067    else
00068    {
00069       PRINT_ERROR("In the Body(OSME*) constructor\n");
00070       PRINT_ERROR("       Input OSME pointer is NULL\n");
00071       assert(OSMEPtr != NULL);
00072    }
00073 
00074    // Set the Entity ID for this new Body
00075    entityId = RefEntityFactory::instance()->next_body_id();
00076 
00077      // read and initialize attributes
00078    auto_read_cubit_attrib();
00079    auto_actuate_cubit_attrib();
00080 
00081      // Assign a default entity name
00082    assign_default_name();   
00083 }
00084 
00085 //-------------------------------------------------------------------------
00086 // Purpose       : The destructor
00087 //
00088 // Special Notes :
00089 //
00090 // Creator       : Raikanta Sahu
00091 //
00092 // Creation Date : 10/22/96
00093 //-------------------------------------------------------------------------
00094 Body::~Body()
00095 {
00096 }
00097 
00098 
00099 //-------------------------------------------------------------------------
00100 // Purpose       : Get BodySM ptr
00101 //
00102 // Special Notes : 
00103 //
00104 // Creator       : Jason Kraftcheck
00105 //
00106 // Creation Date : 07/23/03
00107 //-------------------------------------------------------------------------
00108 BodySM* Body::get_body_sm_ptr() const
00109 {
00110   TopologyBridge* bridge = bridge_manager()->topology_bridge();
00111   return dynamic_cast<BodySM*>(bridge);
00112 }
00113 
00114 //-------------------------------------------------------------------------
00115 // Purpose       : Check if this body contains only sheet volumes.
00116 //
00117 // Special Notes : 
00118 //
00119 // Creator       : Jason Kraftcheck
00120 //
00121 // Creation Date : 01/15/04
00122 //-------------------------------------------------------------------------
00123 CubitBoolean Body::is_sheet_body()
00124 {
00125   DLIList<RefVolume*> volumes;
00126   ref_volumes(volumes);
00127   while (volumes.size())
00128     if (!volumes.pop()->is_sheet())
00129       return CUBIT_FALSE;
00130   return CUBIT_TRUE;
00131 }
00132  
00133 CubitVector Body::center_point()
00134 {
00135   return bounding_box().center();
00136 }
00137 
00138 CubitPointContainment Body::point_containment( CubitVector &point )
00139 {
00140   return get_body_sm_ptr()->point_containment( point );
00141 }
00142 
00143 CubitBoolean Body::get_mass_props(CubitVector &cofg)
00144 {
00145   double vol;
00146   CubitStatus result = get_body_sm_ptr()->mass_properties(cofg, vol);
00147   return result ? CUBIT_TRUE : CUBIT_FALSE;
00148 }
00149 
00150 //-------------------------------------------------------------------------
00151 // Purpose       : Get the bounding box of the object.
00152 //
00153 // Special Notes : This function assumes that a Body's spatial extent is
00154 //                 defined by the set of RefVolumes it "owns".
00155 //
00156 // Creator       : Malcolm J. Panthaki
00157 //
00158 // Creation Date : 10/23/96
00159 //-------------------------------------------------------------------------
00160 CubitBox Body::bounding_box()
00161 {
00162    // Get the list of RefVolumes. Perform the union of the bounding
00163    // boxes of all the RefVolumes to obtain the bounding box of 
00164    // the Body.
00165    DLIList<RefVolume*> ref_volume_list ;
00166    /*CubitStatus status = */
00167    ref_volumes(ref_volume_list);
00168 
00169    if ( ref_volume_list.size() == 0 )
00170    {
00171      CubitVector vec(0.0, 0.0, 0.0);
00172      return CubitBox( vec, vec );
00173    }
00174    RefVolume* ref_volume_ptr = NULL ;
00175 
00176    ref_volume_list.reset() ;
00177    CubitBox result_box = ref_volume_list.get_and_step()->bounding_box();
00178    for(int i = 1 ; i < ref_volume_list.size() ; i++)
00179    {
00180       ref_volume_ptr = ref_volume_list.get_and_step() ;
00181       result_box |= ref_volume_ptr->bounding_box() ;
00182    }
00183 
00184    return result_box ;
00185 }
00186 
00187 
00188 double Body::measure()
00189 {
00190   DLIList<RefVolume*> volumes;
00191   ref_volumes(volumes);
00192   double volume = 0.0;
00193   for (int i = volumes.size(); i > 0; i--)
00194   {
00195      volume += volumes.get_and_step()->measure();
00196   }
00197   
00198   return volume;
00199 }
00200 
00201 CubitString Body::measure_label()
00202 {
00203   return "volume";
00204 }
00205 
00206 int Body::validate()
00207 {
00208   int error = 0;
00209 
00210       // Perform general RefEntity checks (measure > 0)
00211   error += RefEntity::validate();
00212   
00213     // check the body from acis
00214   BodySM* osme_ptr = get_body_sm_ptr();
00215   DLIList <TopologyEntity*> bad_entities;
00216   if ( osme_ptr != NULL )
00217   {
00218     
00219     error += osme_ptr->validate( entity_name(), bad_entities);
00220   }
00221   else 
00222   {
00223     PRINT_WARNING("\tWARNING: Null underlying solid modeling body for %s, (%s %d)\n",
00224                   entity_name().c_str(), class_name(), id());
00225     error++;
00226   }
00227   return error;
00228 }
00229 
00230 void Body::color(int value)
00231 {
00232   int i;
00233   DLIList<RefVolume*> refVolumeList;
00234   ref_volumes ( refVolumeList );
00235 
00236   refVolumeList.reset();
00237   for (i = refVolumeList.size(); i--; )
00238     refVolumeList.get_and_step()->color(value);
00239 }
00240 
00241 int Body::color() const
00242 {
00243   return RefEntity::color();
00244 }
00245 
00246 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines