MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2007 Sandia National Laboratories. Developed at the 00005 University of Wisconsin--Madison under SNL contract number 00006 624796. The U.S. Government and the University of Wisconsin 00007 retain certain rights to 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 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 (lgpl.txt) along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 (2007) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 /** \file XYRectangle.cpp 00028 * \brief 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "Mesquite.hpp" 00033 #include "XYRectangle.hpp" 00034 #include "MsqError.hpp" 00035 #include "MsqVertex.hpp" 00036 00037 namespace MBMesquite 00038 { 00039 00040 XYRectangle::XYRectangle( double w, double h, double x, double y, double z, Plane p ) 00041 : normalDir( p ), widthDir( ( p + 1 ) % 3 ), heightDir( ( p + 2 ) % 3 ) 00042 { 00043 minCoords[0] = maxCoords[0] = x; 00044 minCoords[1] = maxCoords[1] = y; 00045 minCoords[2] = maxCoords[2] = z; 00046 maxCoords[widthDir] += w; 00047 maxCoords[heightDir] += h; 00048 } 00049 00050 void XYRectangle::setup( Mesh* mesh, MsqError& err ) 00051 { 00052 const double epsilon = 1e-4; 00053 if( maxCoords[widthDir] - minCoords[widthDir] <= epsilon || 00054 maxCoords[heightDir] - minCoords[heightDir] <= epsilon || 00055 maxCoords[normalDir] - minCoords[normalDir] > epsilon ) 00056 { 00057 MSQ_SETERR( err )( "Invalid rectangle dimensions", MsqError::INVALID_STATE ); 00058 return; 00059 } 00060 00061 mConstraints.clear(); 00062 00063 std::vector< Mesh::EntityHandle > vertices; 00064 mesh->get_all_vertices( vertices, err );MSQ_ERRRTN( err ); 00065 if( vertices.empty() ) 00066 { 00067 MSQ_SETERR( err )( "Empty mesh", MsqError::INVALID_MESH ); 00068 return; 00069 } 00070 00071 std::vector< MsqVertex > coords( vertices.size() ); 00072 mesh->vertices_get_coordinates( arrptr( vertices ), arrptr( coords ), coords.size(), err );MSQ_ERRRTN( err ); 00073 00074 for( size_t i = 0; i < vertices.size(); ++i ) 00075 { 00076 for( int d = 0; d < 3; ++d ) 00077 { 00078 if( d == normalDir ) continue; 00079 if( minCoords[d] - coords[i][d] > epsilon || coords[i][d] - maxCoords[d] > epsilon ) 00080 { 00081 MSQ_SETERR( err ) 00082 ( MsqError::INVALID_MESH, "Invalid vertex coordinate: (%f,%f,%f)\n", coords[i][0], coords[i][1], 00083 coords[i][2] ); 00084 return; 00085 } 00086 else if( coords[i][d] - minCoords[d] < epsilon ) 00087 { 00088 VertexConstraint c( d, minCoords[d] ); 00089 mConstraints.insert( constraint_t::value_type( vertices[i], c ) ); 00090 } 00091 else if( maxCoords[d] - coords[i][d] < epsilon ) 00092 { 00093 VertexConstraint c( d, maxCoords[d] ); 00094 mConstraints.insert( constraint_t::value_type( vertices[i], c ) ); 00095 } 00096 } 00097 } 00098 } 00099 00100 void XYRectangle::snap_to( Mesh::VertexHandle vertex, Vector3D& coordinate ) const 00101 { 00102 // everything gets moved into the plane 00103 coordinate[normalDir] = minCoords[normalDir]; 00104 // apply other constraints 00105 constraint_t::const_iterator i = mConstraints.lower_bound( vertex ); 00106 for( ; i != mConstraints.end() && i->first == vertex; ++i ) 00107 coordinate[i->second.axis] = i->second.coord; 00108 } 00109 00110 void XYRectangle::vertex_normal_at( Mesh::VertexHandle /*handle*/, Vector3D& norm ) const 00111 { 00112 norm.set( 0, 0, 0 ); 00113 norm[normalDir] = 1.0; 00114 } 00115 00116 void XYRectangle::element_normal_at( Mesh::ElementHandle /*handle*/, Vector3D& norm ) const 00117 { 00118 norm.set( 0, 0, 0 ); 00119 norm[normalDir] = 1.0; 00120 } 00121 00122 void XYRectangle::vertex_normal_at( const Mesh::VertexHandle* /*vertices*/, 00123 Vector3D normals[], 00124 unsigned count, 00125 MsqError& ) const 00126 { 00127 Vector3D norm( 0, 0, 0 ); 00128 norm[normalDir] = 1.0; 00129 std::fill( normals, normals + count, norm ); 00130 } 00131 00132 void XYRectangle::closest_point( Mesh::VertexHandle vertex, 00133 const Vector3D& position, 00134 Vector3D& closest, 00135 Vector3D& normal, 00136 MsqError& ) const 00137 { 00138 normal = position; 00139 vertex_normal_at( vertex, normal ); 00140 closest = position; 00141 closest[2] = 0; 00142 } 00143 00144 void XYRectangle::domain_DoF( const Mesh::VertexHandle* vertices, 00145 unsigned short* dof_array, 00146 size_t num_handles, 00147 MsqError& ) const 00148 { 00149 for( unsigned i = 0; i < num_handles; ++i ) 00150 { 00151 // everything is at least constrained to XY-plane 00152 dof_array[i] = 2; 00153 // each additional constraint reduces degrees of freedom 00154 constraint_t::const_iterator j = mConstraints.lower_bound( vertices[i] ); 00155 for( ; j != mConstraints.end() && j->first == vertices[i]; ++j ) 00156 --dof_array[i]; 00157 } 00158 } 00159 00160 } // namespace MBMesquite