moab
AxisBox.cpp
Go to the documentation of this file.
00001 
00023 #include "AxisBox.hpp"
00024 #include "moab/Range.hpp"
00025 #include <assert.h>
00026 
00027 namespace moab {
00028 
00029 const char* const AXIS_BOX_TAG_NAME = "AXIS_BOX";
00030 
00031 
00032 ErrorCode AxisBox::get_tag( Tag& tag_out,
00033                                 Interface* interface,
00034                                 const char* tagname )
00035 {
00036   assert( sizeof(AxisBox) == 6*sizeof(double) );
00037   
00038   if (!tagname)
00039     tagname = AXIS_BOX_TAG_NAME;
00040  
00041   return interface->tag_get_handle( tagname,
00042                                     sizeof(AxisBox),
00043                                     MB_TYPE_DOUBLE,
00044                                     tag_out,
00045                                     MB_TAG_DENSE|MB_TAG_CREAT|MB_TAG_BYTES );
00046 }
00047 
00048 ErrorCode AxisBox::calculate( AxisBox& box,
00049                                   EntityHandle set,
00050                                   Interface* interface )
00051 {
00052   Range range;
00053   ErrorCode rval = interface->get_entities_by_handle( set, range );
00054   if (MB_SUCCESS != rval)
00055     return rval;
00056   
00057   return calculate( box, range, interface );
00058 }
00059 
00060 ErrorCode AxisBox::calculate( AxisBox& box,
00061                                   const Range& entities,
00062                                   Interface* interface )
00063 {
00064   ErrorCode rval;
00065   Range vertices;
00066   Range elements;
00067   
00068   elements.merge( entities.upper_bound(MBVERTEX), entities.lower_bound(MBENTITYSET) );
00069   rval = interface->get_adjacencies( elements, 0, false, vertices );
00070   if (MB_SUCCESS != rval)
00071     return rval;
00072   
00073   vertices.merge( entities.begin(), entities.upper_bound(MBVERTEX) );
00074   
00075   std::vector<double> coords( 3*vertices.size() );
00076   rval = interface->get_coords( vertices, &coords[0] );
00077   if (MB_SUCCESS != rval)
00078     return rval;
00079   
00080   box = AxisBox();
00081   std::vector<double>::const_iterator i = coords.begin();
00082   for (; i != coords.end(); i += 3)
00083     box |= &*i;
00084   
00085   return MB_SUCCESS;
00086 }
00087   
00088 } // namespace moab
00089 
00090 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines