MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /** 00002 * MOAB, a Mesh-Oriented datABase, is a software component for creating, 00003 * storing and accessing finite element mesh data. 00004 * 00005 * Copyright 2004 Sandia Corporation. Under the terms of Contract 00006 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 00007 * retains certain rights in this software. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 */ 00015 00016 /** 00017 * \brief Class representing axis-aligned bounding box 00018 * \author Jason Kraftcheck ([email protected]) 00019 * \date August, 2006 00020 */ 00021 00022 #include "AxisBox.hpp" 00023 #include "moab/Range.hpp" 00024 #include <cassert> 00025 00026 namespace moab 00027 { 00028 00029 const char* const AXIS_BOX_TAG_NAME = "AXIS_BOX"; 00030 00031 ErrorCode AxisBox::get_tag( Tag& tag_out, Interface* interface, const char* tagname ) 00032 { 00033 assert( sizeof( AxisBox ) == 6 * sizeof( double ) ); 00034 00035 if( !tagname ) tagname = AXIS_BOX_TAG_NAME; 00036 00037 return interface->tag_get_handle( tagname, sizeof( AxisBox ), MB_TYPE_DOUBLE, tag_out, 00038 MB_TAG_DENSE | MB_TAG_CREAT | MB_TAG_BYTES ); 00039 } 00040 00041 ErrorCode AxisBox::calculate( AxisBox& box, EntityHandle set, Interface* interface ) 00042 { 00043 Range range; 00044 ErrorCode rval = interface->get_entities_by_handle( set, range ); 00045 if( MB_SUCCESS != rval ) return rval; 00046 00047 return calculate( box, range, interface ); 00048 } 00049 00050 ErrorCode AxisBox::calculate( AxisBox& box, const Range& entities, Interface* interface ) 00051 { 00052 ErrorCode rval; 00053 Range vertices; 00054 Range elements; 00055 00056 elements.merge( entities.upper_bound( MBVERTEX ), entities.lower_bound( MBENTITYSET ) ); 00057 rval = interface->get_adjacencies( elements, 0, false, vertices ); 00058 if( MB_SUCCESS != rval ) return rval; 00059 00060 vertices.merge( entities.begin(), entities.upper_bound( MBVERTEX ) ); 00061 00062 std::vector< double > coords( 3 * vertices.size() ); 00063 rval = interface->get_coords( vertices, &coords[0] ); 00064 if( MB_SUCCESS != rval ) return rval; 00065 00066 box = AxisBox(); 00067 std::vector< double >::const_iterator i = coords.begin(); 00068 for( ; i != coords.end(); i += 3 ) 00069 box |= &*i; 00070 00071 return MB_SUCCESS; 00072 } 00073 00074 } // namespace moab