MOAB: Mesh Oriented datABase
(version 5.2.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2004 Lawrence Livermore National Laboratory. Under 00005 the terms of Contract B545069 with the University of Wisconsin -- 00006 Madison, Lawrence Livermore National Laboratory retains certain 00007 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 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 kraftche@cae.wisc.edu 00024 00025 ***************************************************************** */ 00026 00027 /*! 00028 \file MsqIRel.cpp 00029 \brief 00030 00031 00032 \author Jason Kraftcheck 00033 \date 2007-08-14 00034 */ 00035 00036 #include "MsqIRel.hpp" 00037 #include "MsqDebug.hpp" 00038 #include "MsqVertex.hpp" 00039 #include "MsqError.hpp" 00040 #include "MsqIBase.hpp" 00041 00042 namespace MBMesquite 00043 { 00044 00045 /***************** DomainTSTT class methods *********************/ 00046 00047 MsqIRel::MsqIRel( iGeom_Instance geom, iRel_Instance relate_iface, iRel_PairHandle relate_instance ) 00048 : MsqCommonIGeom( geom ), relateIface( relate_iface ), relateInstance( relate_instance ) 00049 { 00050 } 00051 00052 MsqIRel::~MsqIRel() {} 00053 00054 void MsqIRel::snap_to( Mesh::VertexHandle handle, Vector3D& coordinate ) const 00055 { 00056 int ierr, dim; 00057 iBase_EntityHandle geom; 00058 00059 ierr = geom_from_mesh( handle, geom, dim ); 00060 if( iBase_SUCCESS != ierr ) 00061 { 00062 process_itaps_error( ierr ); 00063 return; 00064 } 00065 00066 if( dim < 3 ) 00067 { 00068 ierr = move_to( geom, coordinate ); 00069 if( iBase_SUCCESS != ierr ) 00070 { 00071 process_itaps_error( ierr ); 00072 return; 00073 } 00074 } 00075 } 00076 00077 void MsqIRel::vertex_normal_at( Mesh::VertexHandle handle, Vector3D& coordinate ) const 00078 { 00079 int ierr, dim; 00080 iBase_EntityHandle geom; 00081 00082 ierr = geom_from_mesh( handle, geom, dim ); 00083 if( iBase_SUCCESS != ierr ) 00084 { 00085 process_itaps_error( ierr ); 00086 return; 00087 } 00088 00089 if( dim == 2 ) 00090 { 00091 ierr = normal( geom, coordinate ); 00092 if( iBase_SUCCESS != ierr ) 00093 { 00094 process_itaps_error( ierr ); 00095 return; 00096 } 00097 } 00098 else 00099 { 00100 assert( 0 ); 00101 } 00102 } 00103 00104 void MsqIRel::element_normal_at( Mesh::ElementHandle handle, Vector3D& coordinate ) const 00105 { 00106 MsqIRel::vertex_normal_at( handle, coordinate ); 00107 } 00108 00109 void MsqIRel::vertex_normal_at( const Mesh::VertexHandle* handle, Vector3D coordinates[], unsigned count, 00110 MsqError& err ) const 00111 { 00112 int ierr, dim; 00113 iBase_EntityHandle geom; 00114 for( unsigned i = 0; i < count; ++i ) 00115 { 00116 ierr = geom_from_mesh( handle[i], geom, dim ); 00117 if( iBase_SUCCESS != ierr ) 00118 { 00119 process_itaps_error( ierr ); 00120 return; 00121 } 00122 00123 if( dim != 2 ) 00124 { 00125 MSQ_SETERR( err ) 00126 ( "Cannot get normal for non-surface geometry", MsqError::INVALID_ARG ); 00127 return; 00128 } 00129 00130 ierr = normal( geom, coordinates[i] ); 00131 if( iBase_SUCCESS != ierr ) 00132 { 00133 process_itaps_error( ierr ); 00134 return; 00135 } 00136 } 00137 } 00138 00139 void MsqIRel::domain_DoF( const Mesh::VertexHandle* handle_array, unsigned short* dof_array, size_t count, 00140 MsqError& err ) const 00141 { 00142 int ierr; 00143 00144 geomHandles.resize( count ); 00145 ierr = geom_from_mesh( handle_array, arrptr( geomHandles ), dof_array, count ); 00146 if( iBase_SUCCESS != ierr ) 00147 { 00148 MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR ); 00149 return; 00150 } 00151 } 00152 00153 void MsqIRel::closest_point( Mesh::VertexHandle handle, const Vector3D& position, Vector3D& closest, Vector3D& p_normal, 00154 MsqError& err ) const 00155 { 00156 int ierr, dim; 00157 iBase_EntityHandle geom; 00158 00159 ierr = geom_from_mesh( handle, geom, dim ); 00160 if( iBase_SUCCESS != ierr ) 00161 { 00162 MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR ); 00163 return; 00164 } 00165 00166 if( dim != 2 ) 00167 { 00168 MSQ_SETERR( err )( "Cannot get normal for non-surface geometry", MsqError::INVALID_ARG ); 00169 return; 00170 } 00171 00172 ierr = closest_and_normal( geom, position, closest, p_normal ); 00173 if( iBase_SUCCESS != ierr ) 00174 { 00175 MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR ); 00176 return; 00177 } 00178 } 00179 00180 int MsqIRel::geom_from_mesh( Mesh::EntityHandle mesh_ent_handle, iBase_EntityHandle& geom_handle, int& geom_dim ) const 00181 { 00182 // get geometric entity 00183 int ierr; 00184 iRel_getEntEntRelation( relateIface, relateInstance, (iBase_EntityHandle)mesh_ent_handle, true, &geom_handle, 00185 &ierr ); 00186 if( iBase_SUCCESS != ierr ) return ierr; 00187 00188 // get dimension of geometric entities 00189 int one = 1, one_too = 1, *type_ptr = &geom_dim; 00190 iGeom_getArrType( geomIFace, &geom_handle, 1, &type_ptr, &one, &one_too, &ierr ); 00191 if( iBase_SUCCESS != ierr ) return ierr; 00192 00193 return iBase_SUCCESS; 00194 } 00195 00196 int MsqIRel::geom_from_mesh( const Mesh::EntityHandle* handles, iBase_EntityHandle* geom_handles, unsigned short* dims, 00197 size_t count ) const 00198 { 00199 int ierr, dim; 00200 for( size_t i = 0; i < count; ++i ) 00201 { 00202 ierr = geom_from_mesh( handles[i], geom_handles[i], dim ); 00203 if( iBase_SUCCESS != ierr ) return ierr; 00204 dims[i] = dim; 00205 } 00206 00207 return iBase_SUCCESS; 00208 } 00209 00210 } // namespace MBMesquite