| 1 | //------------------------------------------------------------------------- |
|---|
| 2 | // Filename : Body.cpp |
|---|
| 3 | // |
|---|
| 4 | // Purpose : This file contains the implementation of the class |
|---|
| 5 | // Body. |
|---|
| 6 | // |
|---|
| 7 | // Special Notes : |
|---|
| 8 | // |
|---|
| 9 | // Creator : |
|---|
| 10 | // |
|---|
| 11 | // Creation Date : |
|---|
| 12 | // |
|---|
| 13 | // Owner : |
|---|
| 14 | //------------------------------------------------------------------------- |
|---|
| 15 | |
|---|
| 16 | #include <assert.h> |
|---|
| 17 | #include "CubitDefines.h" |
|---|
| 18 | #include "CubitMessage.hpp" |
|---|
| 19 | #include "CubitBox.hpp" |
|---|
| 20 | |
|---|
| 21 | #include "BodySM.hpp" |
|---|
| 22 | #include "Body.hpp" |
|---|
| 23 | |
|---|
| 24 | #include "CoVolume.hpp" |
|---|
| 25 | #include "CoEdge.hpp" |
|---|
| 26 | |
|---|
| 27 | #include "RefVolume.hpp" |
|---|
| 28 | #include "RefFace.hpp" |
|---|
| 29 | #include "RefEdge.hpp" |
|---|
| 30 | #include "DLIList.hpp" |
|---|
| 31 | #include "RefEntityFactory.hpp" |
|---|
| 32 | #include "GeometryQueryTool.hpp" |
|---|
| 33 | #include "GeometryQueryEngine.hpp" |
|---|
| 34 | #include "CastTo.hpp" |
|---|
| 35 | |
|---|
| 36 | //------------------------------------------------------------------------- |
|---|
| 37 | // Purpose : Default constructor. |
|---|
| 38 | // |
|---|
| 39 | // Special Notes : |
|---|
| 40 | // |
|---|
| 41 | // Creator : Xuechen Liu |
|---|
| 42 | // |
|---|
| 43 | // Creation Date : 08/06/96 |
|---|
| 44 | //------------------------------------------------------------------------- |
|---|
| 45 | Body::Body() |
|---|
| 46 | { |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | //------------------------------------------------------------------------- |
|---|
| 50 | // Purpose : A constructor with a pointer to an TopologyBridge |
|---|
| 51 | // as input. |
|---|
| 52 | // |
|---|
| 53 | // Special Notes : |
|---|
| 54 | // |
|---|
| 55 | // Creator : Xuechen Liu |
|---|
| 56 | // |
|---|
| 57 | // Creation Date : 08/06/96 |
|---|
| 58 | //------------------------------------------------------------------------- |
|---|
| 59 | Body::Body(BodySM* OSMEPtr) |
|---|
| 60 | { |
|---|
| 61 | // Set the new Body's OSME pointer |
|---|
| 62 | if (OSMEPtr != NULL) |
|---|
| 63 | { |
|---|
| 64 | set_topology_bridge(OSMEPtr) ; |
|---|
| 65 | } |
|---|
| 66 | else |
|---|
| 67 | { |
|---|
| 68 | PRINT_ERROR("In the Body(OSME*) constructor\n"); |
|---|
| 69 | PRINT_ERROR(" Input OSME pointer is NULL\n"); |
|---|
| 70 | assert(OSMEPtr != NULL); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | // Set the Entity ID for this new Body |
|---|
| 74 | entityId = RefEntityFactory::instance()->next_body_id(); |
|---|
| 75 | |
|---|
| 76 | copied_from_body_id = 0; |
|---|
| 77 | |
|---|
| 78 | // read and initialize attributes |
|---|
| 79 | auto_read_cubit_attrib(); |
|---|
| 80 | auto_actuate_cubit_attrib(); |
|---|
| 81 | |
|---|
| 82 | // Assign a default entity name |
|---|
| 83 | assign_default_name(); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | //------------------------------------------------------------------------- |
|---|
| 87 | // Purpose : The destructor |
|---|
| 88 | // |
|---|
| 89 | // Special Notes : |
|---|
| 90 | // |
|---|
| 91 | // Creator : Raikanta Sahu |
|---|
| 92 | // |
|---|
| 93 | // Creation Date : 10/22/96 |
|---|
| 94 | //------------------------------------------------------------------------- |
|---|
| 95 | Body::~Body() |
|---|
| 96 | { |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | //------------------------------------------------------------------------- |
|---|
| 101 | // Purpose : Get BodySM ptr |
|---|
| 102 | // |
|---|
| 103 | // Special Notes : |
|---|
| 104 | // |
|---|
| 105 | // Creator : Jason Kraftcheck |
|---|
| 106 | // |
|---|
| 107 | // Creation Date : 07/23/03 |
|---|
| 108 | //------------------------------------------------------------------------- |
|---|
| 109 | BodySM* Body::get_body_sm_ptr() const |
|---|
| 110 | { |
|---|
| 111 | TopologyBridge* bridge = bridge_manager()->topology_bridge(); |
|---|
| 112 | return dynamic_cast<BodySM*>(bridge); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | //* Method: copiedFromId |
|---|
| 116 | //** Sets the Id of the body that this body was copied from |
|---|
| 117 | //*== |
|---|
| 118 | |
|---|
| 119 | void Body::copiedFromId( int Id ) |
|---|
| 120 | { |
|---|
| 121 | copied_from_body_id = Id; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | //* Method: copiedFromId |
|---|
| 125 | //** Returns the Id of the body that this body was copied from |
|---|
| 126 | //*== |
|---|
| 127 | |
|---|
| 128 | int Body::copiedFromId () |
|---|
| 129 | { |
|---|
| 130 | return copied_from_body_id; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | /* This is wrong for misc. arrangements of non-manifold topology |
|---|
| 134 | * -- j.kraftcheck |
|---|
| 135 | |
|---|
| 136 | CubitBoolean Body::is_sheet_body() |
|---|
| 137 | { |
|---|
| 138 | //This function just checks for bodies which have a single coedge |
|---|
| 139 | // on a RefEdge, which would indicate an open sheet body. This |
|---|
| 140 | // function will not find sheet bodies which are closed... |
|---|
| 141 | DLIList<CoEdge*> co_edges; |
|---|
| 142 | this->co_edges( co_edges ); |
|---|
| 143 | DLIList<RefEdge*> edge_list_1, edge_list_2; |
|---|
| 144 | int i; |
|---|
| 145 | for( i = co_edges.size(); i > 0; i-- ) |
|---|
| 146 | { |
|---|
| 147 | CoEdge* this_co_edge = co_edges.get_and_step(); |
|---|
| 148 | RefEdge* this_ref_edge = this_co_edge->get_ref_edge_ptr(); |
|---|
| 149 | if( edge_list_1.is_in_list( this_ref_edge ) ) |
|---|
| 150 | { |
|---|
| 151 | edge_list_2.append( this_ref_edge ); |
|---|
| 152 | } |
|---|
| 153 | else |
|---|
| 154 | { |
|---|
| 155 | edge_list_1.append_unique( this_ref_edge ); |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | //subtract edge_list_2 from edge_list_1 |
|---|
| 160 | DLIList<RefEdge*> temp_list = edge_list_1; |
|---|
| 161 | for( i = temp_list.size(); i > 0; i-- ) |
|---|
| 162 | { |
|---|
| 163 | RefEdge* this_edge = temp_list.get_and_step(); |
|---|
| 164 | if( edge_list_2.is_in_list( this_edge ) ) |
|---|
| 165 | { |
|---|
| 166 | edge_list_1.remove( this_edge ); |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | if( edge_list_1.size() > 0 ) |
|---|
| 171 | { |
|---|
| 172 | for( i = edge_list_1.size(); i > 0; i-- ) |
|---|
| 173 | { |
|---|
| 174 | if( edge_list_1.get_and_step()->geometry_type() != POINT_CURVE_TYPE ) |
|---|
| 175 | return CUBIT_TRUE; |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | return CUBIT_FALSE; |
|---|
| 179 | } |
|---|
| 180 | */ |
|---|
| 181 | |
|---|
| 182 | //------------------------------------------------------------------------- |
|---|
| 183 | // Purpose : Check if this body contains only sheet volumes. |
|---|
| 184 | // |
|---|
| 185 | // Special Notes : |
|---|
| 186 | // |
|---|
| 187 | // Creator : Jason Kraftcheck |
|---|
| 188 | // |
|---|
| 189 | // Creation Date : 01/15/04 |
|---|
| 190 | //------------------------------------------------------------------------- |
|---|
| 191 | CubitBoolean Body::is_sheet_body() |
|---|
| 192 | { |
|---|
| 193 | DLIList<RefVolume*> volumes; |
|---|
| 194 | ref_volumes(volumes); |
|---|
| 195 | while (volumes.size()) |
|---|
| 196 | if (!volumes.pop()->is_sheet()) |
|---|
| 197 | return CUBIT_FALSE; |
|---|
| 198 | return CUBIT_TRUE; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | CubitVector Body::center_point() |
|---|
| 202 | { |
|---|
| 203 | return bounding_box().center(); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | CubitPointContainment Body::point_containment( CubitVector &point ) |
|---|
| 207 | { |
|---|
| 208 | return get_body_sm_ptr()->point_containment( point ); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | CubitBoolean Body::get_mass_props(CubitVector &cofg) |
|---|
| 212 | { |
|---|
| 213 | double vol; |
|---|
| 214 | CubitStatus result = get_body_sm_ptr()->mass_properties(cofg, vol); |
|---|
| 215 | return result ? CUBIT_TRUE : CUBIT_FALSE; |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | //------------------------------------------------------------------------- |
|---|
| 219 | // Purpose : Get the bounding box of the object. |
|---|
| 220 | // |
|---|
| 221 | // Special Notes : This function assumes that a Body's spatial extent is |
|---|
| 222 | // defined by the set of RefVolumes it "owns". |
|---|
| 223 | // |
|---|
| 224 | // Creator : Malcolm J. Panthaki |
|---|
| 225 | // |
|---|
| 226 | // Creation Date : 10/23/96 |
|---|
| 227 | //------------------------------------------------------------------------- |
|---|
| 228 | CubitBox Body::bounding_box() |
|---|
| 229 | { |
|---|
| 230 | // Get the list of RefVolumes. Perform the union of the bounding |
|---|
| 231 | // boxes of all the RefVolumes to obtain the bounding box of |
|---|
| 232 | // the Body. |
|---|
| 233 | DLIList<RefVolume*> ref_volume_list ; |
|---|
| 234 | /*CubitStatus status = */ |
|---|
| 235 | ref_volumes(ref_volume_list); |
|---|
| 236 | |
|---|
| 237 | if ( ref_volume_list.size() == 0 ) |
|---|
| 238 | { |
|---|
| 239 | CubitVector vec(0.0, 0.0, 0.0); |
|---|
| 240 | return CubitBox( vec, vec ); |
|---|
| 241 | } |
|---|
| 242 | RefVolume* ref_volume_ptr = NULL ; |
|---|
| 243 | |
|---|
| 244 | ref_volume_list.reset() ; |
|---|
| 245 | CubitBox result_box = ref_volume_list.get_and_step()->bounding_box(); |
|---|
| 246 | for(int i = 1 ; i < ref_volume_list.size() ; i++) |
|---|
| 247 | { |
|---|
| 248 | ref_volume_ptr = ref_volume_list.get_and_step() ; |
|---|
| 249 | result_box |= ref_volume_ptr->bounding_box() ; |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | return result_box ; |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | double Body::measure() |
|---|
| 257 | { |
|---|
| 258 | DLIList<RefVolume*> volumes; |
|---|
| 259 | ref_volumes(volumes); |
|---|
| 260 | double volume = 0.0; |
|---|
| 261 | for (int i = volumes.size(); i > 0; i--) |
|---|
| 262 | { |
|---|
| 263 | volume += volumes.get_and_step()->measure(); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | return volume; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | CubitString Body::measure_label() |
|---|
| 270 | { |
|---|
| 271 | return "volume"; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | int Body::validate() |
|---|
| 275 | { |
|---|
| 276 | int error = 0; |
|---|
| 277 | |
|---|
| 278 | // Perform general RefEntity checks (measure > 0) |
|---|
| 279 | error += RefEntity::validate(); |
|---|
| 280 | |
|---|
| 281 | // check the body from acis |
|---|
| 282 | BodySM* osme_ptr = get_body_sm_ptr(); |
|---|
| 283 | DLIList <TopologyEntity*> bad_entities; |
|---|
| 284 | if ( osme_ptr != NULL ) |
|---|
| 285 | { |
|---|
| 286 | |
|---|
| 287 | error += osme_ptr->validate( entity_name(), bad_entities); |
|---|
| 288 | } |
|---|
| 289 | else |
|---|
| 290 | { |
|---|
| 291 | PRINT_WARNING("\tWARNING: Null underlying solid modeling body for %s, (%s %d)\n", |
|---|
| 292 | entity_name().c_str(), class_name(), id()); |
|---|
| 293 | error++; |
|---|
| 294 | } |
|---|
| 295 | return error; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | void Body::color(int value) |
|---|
| 299 | { |
|---|
| 300 | int i; |
|---|
| 301 | DLIList<RefVolume*> refVolumeList; |
|---|
| 302 | ref_volumes ( refVolumeList ); |
|---|
| 303 | |
|---|
| 304 | refVolumeList.reset(); |
|---|
| 305 | for (i = refVolumeList.size(); i--; ) |
|---|
| 306 | refVolumeList.get_and_step()->color(value); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | int Body::color() const |
|---|
| 310 | { |
|---|
| 311 | return RefEntity::color(); |
|---|
| 312 | } |
|---|
| 313 | |
|---|