MOAB: Mesh Oriented datABase  (version 5.4.1)
MsqIGeom.cpp
Go to the documentation of this file.
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     [email protected]
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*,
00073                                  Vector3D coordinates[],
00074                                  unsigned count,
00075                                  MsqError& err ) const
00076 {
00077     int ierr = normal( geomEntHandle, coordinates, count );
00078     if( iBase_SUCCESS != ierr ) MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR );
00079 }
00080 
00081 void MsqIGeom::closest_point( Mesh::VertexHandle /*handle*/,
00082                               const Vector3D& position,
00083                               Vector3D& closest,
00084                               Vector3D& p_normal,
00085                               MsqError& err ) const
00086 {
00087     int ierr = closest_and_normal( geomEntHandle, position, closest, p_normal );
00088     if( iBase_SUCCESS != ierr ) MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR );
00089 }
00090 
00091 void MsqIGeom::domain_DoF( const Mesh::VertexHandle*,
00092                            unsigned short* dof_array,
00093                            size_t num_vertices,
00094                            MsqError& err ) const
00095 {
00096     unsigned short dim;
00097     int ierr = get_dimension( &geomEntHandle, &dim, 1 );
00098     if( iBase_SUCCESS != ierr ) MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR );
00099     std::fill( dof_array, dof_array + num_vertices, dim );
00100 }
00101 
00102 /***************** GeomTSTTCommon class methods *********************/
00103 
00104 MsqCommonIGeom::MsqCommonIGeom( iGeom_Instance geom ) : geomIFace( geom ) {}
00105 
00106 MsqCommonIGeom::~MsqCommonIGeom() {}
00107 
00108 int MsqCommonIGeom::move_to( iBase_EntityHandle geom, Vector3D& coord ) const
00109 {
00110     double x, y, z;
00111     int ierr;
00112     iGeom_getEntClosestPt( geomIFace, geom, coord[0], coord[1], coord[2], &x, &y, &z, &ierr );
00113     coord.set( x, y, z );
00114     return ierr;
00115 }
00116 
00117 int MsqCommonIGeom::normal( iBase_EntityHandle geom, Vector3D& coord ) const
00118 {
00119     double i, j, k;
00120     int ierr;
00121     iGeom_getEntNrmlXYZ( geomIFace, geom, coord[0], coord[1], coord[2], &i, &j, &k, &ierr );
00122     coord.set( i, j, k );
00123     return ierr;
00124 }
00125 
00126 int MsqCommonIGeom::normal( iBase_EntityHandle geom, Vector3D coords[], unsigned count ) const
00127 {
00128     geomHandles.resize( count, geom );
00129     return normal( arrptr( geomHandles ), coords, count );
00130 }
00131 
00132 int MsqCommonIGeom::normal( const iBase_EntityHandle* geom_handles, Vector3D coords[], unsigned count ) const
00133 {
00134     // going to assume this in the following reinterpret_cast, so
00135     // check to make sure it is true
00136     assert( sizeof( Vector3D ) == 3 * sizeof( double ) );
00137 
00138     // copy input coordinates into array
00139     coordArray.clear();
00140     coordArray.insert( coordArray.begin(), &coords[0][0], &coords[0][0] + 3 * count );
00141 
00142     // define junk variables required for ITAPS "consistancy"
00143     int junk_1 = count * 3, junk_2 = count * 3;
00144     double* norm_ptr = &coords[0][0];
00145 
00146     // get the normals
00147     int ierr;
00148     iGeom_getArrNrmlXYZ( geomIFace, geom_handles, count, iBase_INTERLEAVED, arrptr( coordArray ), count * 3, &norm_ptr,
00149                          &junk_1, &junk_2, &ierr );
00150 
00151     return ierr;
00152 }
00153 
00154 int MsqCommonIGeom::closest_and_normal( iBase_EntityHandle geom,
00155                                         const Vector3D& position,
00156                                         Vector3D& closest,
00157                                         Vector3D& p_normal ) const
00158 {
00159     int ierr;
00160     iGeom_getEntNrmlPlXYZ( geomIFace, geom, position[0], position[1], position[2], &closest[0], &closest[1],
00161                            &closest[2], &p_normal[0], &p_normal[1], &p_normal[2], &ierr );
00162     return ierr;
00163 }
00164 
00165 int MsqCommonIGeom::get_dimension( const iBase_EntityHandle* geom_handle, unsigned short* dof_out, size_t count ) const
00166 {
00167     int ierr;
00168     typeArray.resize( count );
00169 
00170     // define junk variables required for ITAPS "consistancy"
00171     int junk_1 = count, junk_2 = count;
00172     int* type_ptr = arrptr( typeArray );
00173 
00174     // get the types
00175     iGeom_getArrType( geomIFace, geom_handle, count, &type_ptr, &junk_1, &junk_2, &ierr );
00176 
00177     // convert from int to unsigned short
00178     std::copy( typeArray.begin(), typeArray.end(), dof_out );
00179     return ierr;
00180 }
00181 
00182 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines