1 /* *****************************************************************
2 MESQUITE -- The Mesh Quality Improvement Toolkit
3
4 Copyright 2004 Lawrence Livermore National Laboratory. Under
5 the terms of Contract B545069 with the University of Wisconsin --
6 Madison, Lawrence Livermore National Laboratory retains certain
7 rights in this software.
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 (lgpl.txt) along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23 kraftche@cae.wisc.edu
24
25 ***************************************************************** */
26
27 /*!
28 \file MsqIGeom.cpp
29 \brief
30
31
32 \author Jason Kraftcheck
33 \date 2007-08-14
34 */
35
36 #include "MsqIGeom.hpp"
37 #include "MsqDebug.hpp"
38 #include "MsqVertex.hpp"
39 #include "MsqError.hpp"
40 #include "MsqIBase.hpp"
41
42 namespace MBMesquite
43 {
44
45
46
47
48 /***************** MsqIGeom class methods *********************/
49
MsqIGeom(iGeom_Instance geom,iBase_EntityHandle geom_ent_handle)50 MsqIGeom::MsqIGeom( iGeom_Instance geom, iBase_EntityHandle geom_ent_handle )
51 : MsqCommonIGeom( geom ),
52 geomEntHandle( geom_ent_handle )
53 {
54 }
55
~MsqIGeom()56 MsqIGeom::~MsqIGeom() {}
57
58
snap_to(Mesh::VertexHandle,Vector3D & coordinate) const59 void MsqIGeom::snap_to( Mesh::VertexHandle,
60 Vector3D& coordinate ) const
61 {
62 int ierr = move_to( geomEntHandle, coordinate );
63 if (iBase_SUCCESS != ierr)
64 process_itaps_error(ierr);
65 }
66
vertex_normal_at(Mesh::VertexHandle,Vector3D & coordinate) const67 void MsqIGeom::vertex_normal_at( Mesh::VertexHandle,
68 Vector3D& coordinate ) const
69 {
70 int ierr = normal( geomEntHandle, coordinate );
71 if (iBase_SUCCESS != ierr)
72 process_itaps_error(ierr);
73 }
74
element_normal_at(Mesh::ElementHandle,Vector3D & coordinate) const75 void MsqIGeom::element_normal_at( Mesh::ElementHandle,
76 Vector3D& coordinate ) const
77 {
78 int ierr = normal( geomEntHandle, coordinate );
79 if (iBase_SUCCESS != ierr)
80 process_itaps_error(ierr);
81 }
82
83
vertex_normal_at(const Mesh::VertexHandle *,Vector3D coordinates[],unsigned count,MsqError & err) const84 void MsqIGeom::vertex_normal_at( const Mesh::VertexHandle*,
85 Vector3D coordinates[],
86 unsigned count,
87 MsqError& err ) const
88 {
89 int ierr = normal( geomEntHandle, coordinates, count );
90 if (iBase_SUCCESS != ierr)
91 MSQ_SETERR(err)(process_itaps_error(ierr), MsqError::INTERNAL_ERROR);
92 }
93
closest_point(Mesh::VertexHandle,const Vector3D & position,Vector3D & closest,Vector3D & p_normal,MsqError & err) const94 void MsqIGeom::closest_point( Mesh::VertexHandle /*handle*/,
95 const Vector3D& position,
96 Vector3D& closest,
97 Vector3D& p_normal,
98 MsqError& err ) const
99 {
100 int ierr = closest_and_normal( geomEntHandle, position, closest, p_normal );
101 if (iBase_SUCCESS != ierr)
102 MSQ_SETERR(err)(process_itaps_error(ierr), MsqError::INTERNAL_ERROR);
103 }
104
domain_DoF(const Mesh::VertexHandle *,unsigned short * dof_array,size_t num_vertices,MsqError & err) const105 void MsqIGeom::domain_DoF( const Mesh::VertexHandle* ,
106 unsigned short* dof_array,
107 size_t num_vertices,
108 MsqError& err ) const
109 {
110 unsigned short dim;
111 int ierr = get_dimension( &geomEntHandle, &dim, 1 );
112 if (iBase_SUCCESS != ierr)
113 MSQ_SETERR(err)(process_itaps_error(ierr), MsqError::INTERNAL_ERROR);
114 std::fill( dof_array, dof_array + num_vertices, dim );
115 }
116
117
118
119
120 /***************** GeomTSTTCommon class methods *********************/
121
MsqCommonIGeom(iGeom_Instance geom)122 MsqCommonIGeom::MsqCommonIGeom( iGeom_Instance geom )
123 : geomIFace( geom )
124 {
125 }
126
~MsqCommonIGeom()127 MsqCommonIGeom::~MsqCommonIGeom() {}
128
129
130
move_to(iBase_EntityHandle geom,Vector3D & coord) const131 int MsqCommonIGeom::move_to( iBase_EntityHandle geom, Vector3D& coord ) const
132 {
133 double x, y, z;
134 int ierr;
135 iGeom_getEntClosestPt( geomIFace, geom, coord[0], coord[1], coord[2], &x, &y, &z, &ierr );
136 coord.set( x, y, z );
137 return ierr;
138 }
139
140
141
normal(iBase_EntityHandle geom,Vector3D & coord) const142 int MsqCommonIGeom::normal( iBase_EntityHandle geom, Vector3D& coord ) const
143 {
144 double i, j, k;
145 int ierr;
146 iGeom_getEntNrmlXYZ( geomIFace, geom, coord[0], coord[1], coord[2], &i, &j, &k, &ierr );
147 coord.set( i, j, k );
148 return ierr;
149 }
150
normal(iBase_EntityHandle geom,Vector3D coords[],unsigned count) const151 int MsqCommonIGeom::normal( iBase_EntityHandle geom, Vector3D coords[], unsigned count ) const
152 {
153 geomHandles.resize( count, geom );
154 return normal( arrptr(geomHandles), coords, count );
155 }
156
normal(const iBase_EntityHandle * geom_handles,Vector3D coords[],unsigned count) const157 int MsqCommonIGeom::normal( const iBase_EntityHandle* geom_handles,
158 Vector3D coords[],
159 unsigned count ) const
160 {
161 // going to assume this in the following reinterpret_cast, so
162 // check to make sure it is true
163 assert( sizeof(Vector3D) == 3*sizeof(double) );
164
165 // copy input coordinates into array
166 coordArray.clear();
167 coordArray.insert( coordArray.begin(), &coords[0][0], &coords[0][0] + 3*count );
168
169 // define junk variables required for ITAPS "consistancy"
170 int junk_1 = count*3, junk_2 = count*3;
171 double* norm_ptr = &coords[0][0];
172
173 // get the normals
174 int ierr;
175 iGeom_getArrNrmlXYZ( geomIFace,
176 geom_handles,
177 count,
178 iBase_INTERLEAVED,
179 arrptr(coordArray),
180 count*3,
181 &norm_ptr,
182 &junk_1,
183 &junk_2,
184 &ierr );
185
186 return ierr;
187 }
188
closest_and_normal(iBase_EntityHandle geom,const Vector3D & position,Vector3D & closest,Vector3D & p_normal) const189 int MsqCommonIGeom::closest_and_normal( iBase_EntityHandle geom,
190 const Vector3D& position,
191 Vector3D& closest,
192 Vector3D& p_normal ) const
193 {
194 int ierr;
195 iGeom_getEntNrmlPlXYZ( geomIFace, geom,
196 position[0], position[1], position[2],
197 &closest[0], &closest[1], &closest[2],
198 &p_normal[0], &p_normal[1], &p_normal[2],
199 &ierr );
200 return ierr;
201 }
202
203
get_dimension(const iBase_EntityHandle * geom_handle,unsigned short * dof_out,size_t count) const204 int MsqCommonIGeom::get_dimension( const iBase_EntityHandle* geom_handle,
205 unsigned short* dof_out,
206 size_t count ) const
207 {
208 int ierr;
209 typeArray.resize( count );
210
211 // define junk variables required for ITAPS "consistancy"
212 int junk_1 = count, junk_2 = count;
213 int* type_ptr = arrptr(typeArray);
214
215 // get the types
216 iGeom_getArrType( geomIFace, geom_handle, count, &type_ptr, &junk_1, &junk_2, &ierr );
217
218 // convert from int to unsigned short
219 std::copy( typeArray.begin(), typeArray.end(), dof_out );
220 return ierr;
221 }
222
223 } // namespace Mesquite
224
225