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 MsqIGeom.cpp 00029 \brief 00030 00031 00032 \author Jason Kraftcheck 00033 \date 2007-08-14 00034 */ 00035 00036 #include "MsqIGeom.hpp" 00037 #include "MsqDebug.hpp" 00038 #include "MsqVertex.hpp" 00039 #include "MsqError.hpp" 00040 #include "MsqIBase.hpp" 00041 00042 namespace MBMesquite 00043 { 00044 00045 /***************** MsqIGeom class methods *********************/ 00046 00047 MsqIGeom::MsqIGeom( iGeom_Instance geom, iBase_EntityHandle geom_ent_handle ) 00048 : MsqCommonIGeom( geom ), geomEntHandle( geom_ent_handle ) 00049 { 00050 } 00051 00052 MsqIGeom::~MsqIGeom() {} 00053 00054 void MsqIGeom::snap_to( Mesh::VertexHandle, Vector3D& coordinate ) const 00055 { 00056 int ierr = move_to( geomEntHandle, coordinate ); 00057 if( iBase_SUCCESS != ierr ) process_itaps_error( ierr ); 00058 } 00059 00060 void MsqIGeom::vertex_normal_at( Mesh::VertexHandle, Vector3D& coordinate ) const 00061 { 00062 int ierr = normal( geomEntHandle, coordinate ); 00063 if( iBase_SUCCESS != ierr ) process_itaps_error( ierr ); 00064 } 00065 00066 void MsqIGeom::element_normal_at( Mesh::ElementHandle, Vector3D& coordinate ) const 00067 { 00068 int ierr = normal( geomEntHandle, coordinate ); 00069 if( iBase_SUCCESS != ierr ) process_itaps_error( ierr ); 00070 } 00071 00072 void MsqIGeom::vertex_normal_at( const Mesh::VertexHandle*, Vector3D coordinates[], unsigned count, 00073 MsqError& err ) const 00074 { 00075 int ierr = normal( geomEntHandle, coordinates, count ); 00076 if( iBase_SUCCESS != ierr ) MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR ); 00077 } 00078 00079 void MsqIGeom::closest_point( Mesh::VertexHandle /*handle*/, const Vector3D& position, Vector3D& closest, 00080 Vector3D& p_normal, MsqError& err ) const 00081 { 00082 int ierr = closest_and_normal( geomEntHandle, position, closest, p_normal ); 00083 if( iBase_SUCCESS != ierr ) MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR ); 00084 } 00085 00086 void MsqIGeom::domain_DoF( const Mesh::VertexHandle*, unsigned short* dof_array, size_t num_vertices, 00087 MsqError& err ) const 00088 { 00089 unsigned short dim; 00090 int ierr = get_dimension( &geomEntHandle, &dim, 1 ); 00091 if( iBase_SUCCESS != ierr ) MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR ); 00092 std::fill( dof_array, dof_array + num_vertices, dim ); 00093 } 00094 00095 /***************** GeomTSTTCommon class methods *********************/ 00096 00097 MsqCommonIGeom::MsqCommonIGeom( iGeom_Instance geom ) : geomIFace( geom ) {} 00098 00099 MsqCommonIGeom::~MsqCommonIGeom() {} 00100 00101 int MsqCommonIGeom::move_to( iBase_EntityHandle geom, Vector3D& coord ) const 00102 { 00103 double x, y, z; 00104 int ierr; 00105 iGeom_getEntClosestPt( geomIFace, geom, coord[0], coord[1], coord[2], &x, &y, &z, &ierr ); 00106 coord.set( x, y, z ); 00107 return ierr; 00108 } 00109 00110 int MsqCommonIGeom::normal( iBase_EntityHandle geom, Vector3D& coord ) const 00111 { 00112 double i, j, k; 00113 int ierr; 00114 iGeom_getEntNrmlXYZ( geomIFace, geom, coord[0], coord[1], coord[2], &i, &j, &k, &ierr ); 00115 coord.set( i, j, k ); 00116 return ierr; 00117 } 00118 00119 int MsqCommonIGeom::normal( iBase_EntityHandle geom, Vector3D coords[], unsigned count ) const 00120 { 00121 geomHandles.resize( count, geom ); 00122 return normal( arrptr( geomHandles ), coords, count ); 00123 } 00124 00125 int MsqCommonIGeom::normal( const iBase_EntityHandle* geom_handles, Vector3D coords[], unsigned count ) const 00126 { 00127 // going to assume this in the following reinterpret_cast, so 00128 // check to make sure it is true 00129 assert( sizeof( Vector3D ) == 3 * sizeof( double ) ); 00130 00131 // copy input coordinates into array 00132 coordArray.clear(); 00133 coordArray.insert( coordArray.begin(), &coords[0][0], &coords[0][0] + 3 * count ); 00134 00135 // define junk variables required for ITAPS "consistancy" 00136 int junk_1 = count * 3, junk_2 = count * 3; 00137 double* norm_ptr = &coords[0][0]; 00138 00139 // get the normals 00140 int ierr; 00141 iGeom_getArrNrmlXYZ( geomIFace, geom_handles, count, iBase_INTERLEAVED, arrptr( coordArray ), count * 3, &norm_ptr, 00142 &junk_1, &junk_2, &ierr ); 00143 00144 return ierr; 00145 } 00146 00147 int MsqCommonIGeom::closest_and_normal( iBase_EntityHandle geom, const Vector3D& position, Vector3D& closest, 00148 Vector3D& p_normal ) const 00149 { 00150 int ierr; 00151 iGeom_getEntNrmlPlXYZ( geomIFace, geom, position[0], position[1], position[2], &closest[0], &closest[1], 00152 &closest[2], &p_normal[0], &p_normal[1], &p_normal[2], &ierr ); 00153 return ierr; 00154 } 00155 00156 int MsqCommonIGeom::get_dimension( const iBase_EntityHandle* geom_handle, unsigned short* dof_out, size_t count ) const 00157 { 00158 int ierr; 00159 typeArray.resize( count ); 00160 00161 // define junk variables required for ITAPS "consistancy" 00162 int junk_1 = count, junk_2 = count; 00163 int* type_ptr = arrptr( typeArray ); 00164 00165 // get the types 00166 iGeom_getArrType( geomIFace, geom_handle, count, &type_ptr, &junk_1, &junk_2, &ierr ); 00167 00168 // convert from int to unsigned short 00169 std::copy( typeArray.begin(), typeArray.end(), dof_out ); 00170 return ierr; 00171 } 00172 00173 } // namespace MBMesquite