Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeomTSTT.cpp
Go to the documentation of this file.
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 
36 #include <sidl_cxx.hh>
37 #include "TSTTB.hh"
38 #include "TSTTM.hh"
39 #include "TSTTR.hh"
40 #include "TSTTG.hh"
41 #include "GeomTSTT.hpp"
42 #include "MsqDebug.hpp"
43 #include "MsqVertex.hpp"
44 #include "MsqError.hpp"
45 #include "TSTTUtil.hpp"
46 
47 namespace Mesquite
48 {
49 
56 {
57 public:
58 
60  GeomTSTTCommon( TSTTG::Geometry& geom ) throw (TSTTB::Error );
61 
62  virtual ~GeomTSTTCommon();
63 
68  void move_to( void* geom_handle, Vector3D& coord ) const throw( TSTTB::Error );
69 
75  void normal ( void* geom_handle, Vector3D& coord ) const throw( TSTTB::Error );
76 
82  void normal ( void* geom_handle, Vector3D coords[], unsigned count ) const
83  throw( TSTTB::Error );
84 
89  void closest_and_normal( void* geom_handle,
90  const Vector3D& position,
91  Vector3D& closest,
92  Vector3D& normal ) const
93  throw (TSTTB::Error);
94 
96  mutable TSTTG::Shape geomIface;
97 
99  mutable sidl::array<void*> geomHandles;
101  mutable sidl::array<double> positionsIn, positionsOut, normalsOut;
102 };
103 
104 
105 /* General MeshDomain on TSTT implementation */
106 
107 class DomainTSTT : public GeomTSTT, protected GeomTSTTCommon
108 {
109 public:
110 
111  DomainTSTT( TSTTG::Geometry& geom,
112  TSTTM::Mesh& mesh,
113  TSTTR::Relate& relate ) throw( TSTTB::Error );
114 
115  virtual ~DomainTSTT();
116 
117  DomainHint hint() const;
118 
119  void snap_to( Mesh::EntityHandle entity_handle,
120  Vector3D& coordinat ) const;
121 
122  void normal_at( Mesh::EntityHandle entity_handle,
123  Vector3D& coordinate ) const;
124 
125  void normal_at( Mesh::EntityHandle handle,
126  Vector3D coordinates[],
127  unsigned count,
128  MsqError& err ) const;
129 
130  void closest_point( Mesh::EntityHandle handle,
131  const Vector3D& position,
132  Vector3D& closest,
133  Vector3D& normal,
134  MsqError& err ) const;
135 
136 protected:
137 
139  void* geom_from_mesh( void* handle ) const throw( TSTTB::Error );
140 
141 private:
142 
144  mutable TSTTG::Topology topoIface;
146  mutable TSTTM::Mesh meshIface;
148  mutable TSTTR::Relate relateIface;
149 
151  mutable sidl::array<void*> oneMeshHandle;
153  mutable sidl::array<TSTTG::GentityType> oneTypeOut;
154 };
155 
156 
157 /* Specialized one-geometry-entity MeshDomain on TSTT implementation */
158 
159 class GeomEntTSTT : public GeomTSTT, protected GeomTSTTCommon
160 {
161 public:
162 
163  GeomEntTSTT( TSTTG::Geometry& geom,
164  void* geom_ent_handle ) throw( TSTTB::Error );
165 
166  virtual ~GeomEntTSTT();
167 
168  DomainHint hint() const;
169 
170  void snap_to( Mesh::EntityHandle entity_handle,
171  Vector3D& coordinat ) const;
172 
173  void normal_at( Mesh::EntityHandle entity_handle,
174  Vector3D& coordinate ) const;
175 
176 
177  void normal_at( Mesh::EntityHandle handle,
178  Vector3D coordinates[],
179  unsigned count,
180  MsqError& err ) const;
181 
182  void closest_point( Mesh::EntityHandle handle,
183  const Vector3D& position,
184  Vector3D& closest,
185  Vector3D& normal,
186  MsqError& err ) const;
187 private:
188 
191 };
192 
193 
194 
195 
196 /***************** GeomTSTT base class methods *********************/
197 
198 GeomTSTT* GeomTSTT::create( TSTTG::Geometry& geom,
199  TSTTM::Mesh& mesh,
200  TSTTR::Relate& relate,
201  MsqError& err )
202 {
203  try {
204  return new DomainTSTT( geom, mesh, relate );
205  }
206  catch (TSTTB::Error& tstt_err ) {
208  }
209  return 0;
210 }
211 
212 GeomTSTT* GeomTSTT::create( TSTTG::Geometry& geom,
213  void* geom_ent_handle,
214  MsqError& err )
215 {
216  try {
217  return new GeomEntTSTT( geom, geom_ent_handle );
218  }
219  catch (TSTTB::Error& tstt_err ) {
221  }
222  return 0;
223 }
224 
225 
227 
228 
229 
230 
231 /***************** DomainTSTT class methods *********************/
232 
233 DomainTSTT::DomainTSTT( TSTTG::Geometry& geom,
234  TSTTM::Mesh& mesh,
235  TSTTR::Relate& relate )
236  throw ( TSTTB::Error )
237  : GeomTSTTCommon( geom ),
238  topoIface( geom ),
239  meshIface(mesh),
240  relateIface( relate ),
241  oneMeshHandle( alloc_sidl_vector<void*>(1) ),
242  oneTypeOut( alloc_sidl_vector<TSTTG::GentityType>(1) )
243 {
244 }
245 
247 
248 
250  { return NO_DOMAIN_HINT; }
251 
253  Vector3D& coordinate ) const
254 {
255  try {
256  void* geom = geom_from_mesh( (void*)handle );
257  if (geom)
258  move_to( geom, coordinate );
259  }
260  catch (TSTTB::Error& tstt_err ) {
261  process_tstt_error(tstt_err);
262  }
263 }
264 
266  Vector3D& coordinate ) const
267 {
268  try {
269  void* geom = geom_from_mesh( (void*)handle );
270  if (geom)
271  normal( geom, coordinate );
272  }
273  catch (TSTTB::Error& tstt_err ) {
274  process_tstt_error(tstt_err);
275  }
276 }
277 
279  Vector3D coordinates[],
280  unsigned count,
281  MsqError& err ) const
282 {
283  try {
284  void* geom = geom_from_mesh( (void*)handle );
285  if (!geom) {
287  return;
288  }
289 
290  normal( geom, coordinates, count );
291  }
292  catch (TSTTB::Error& tstt_err ) {
294  }
295 }
296 
298  const Vector3D& position,
299  Vector3D& closest,
300  Vector3D& normal,
301  MsqError& err ) const
302 {
303  try {
304  void* geom = geom_from_mesh( (void*)handle );
305  if (!geom) {
307  return;
308  }
309 
310  closest_and_normal( geom, position, closest, normal );
311  }
312  catch (TSTTB::Error& tstt_err ) {
314  }
315 }
316 
317 
318 void* DomainTSTT::geom_from_mesh( void* mesh_ent_handle ) const
319  throw ( TSTTB::Error )
320 {
321  int junk;
322  oneMeshHandle.set( 0, mesh_ent_handle );
323  relateIface.getMeshRelatedEntities( &geomIface,
324  &meshIface,
325  oneMeshHandle, 1,
326  geomHandles, junk );
327  // get dimension
328  junk = 1;
329  topoIface.gentityGetType( geomHandles, 1, oneTypeOut, junk );
330 
331  return oneTypeOut[0] == TSTTG::GentityType_GREGION ? 0 : geomHandles.get(0);
332 }
333 
334 
335 
336 
337 /***************** GeomEntTSTT class methods *********************/
338 
339 GeomEntTSTT::GeomEntTSTT( TSTTG::Geometry& geom, void* geom_ent_handle )
340  throw ( TSTTB::Error )
341  : GeomTSTTCommon( geom ),
342  geomEntHandle( geom_ent_handle )
343 {
344 }
345 
347 
349  { return SMOOTH_DOMAIN; }
350 
351 
353  Vector3D& coordinate ) const
354 {
355  try {
356  move_to( geomEntHandle, coordinate );
357  }
358  catch (TSTTB::Error& tstt_err ) {
359  process_tstt_error(tstt_err);
360  }
361 }
362 
364  Vector3D& coordinate ) const
365 {
366  try {
367  normal( geomEntHandle, coordinate );
368  }
369  catch (TSTTB::Error& tstt_err ) {
370  process_tstt_error(tstt_err);
371  }
372 }
373 
374 
376  Vector3D coordinates[],
377  unsigned count,
378  MsqError& err ) const
379 {
380  try {
381  normal( geomEntHandle, coordinates, count );
382  }
383  catch (TSTTB::Error& tstt_err ) {
385  }
386 }
387 
389  const Vector3D& position,
390  Vector3D& closest,
391  Vector3D& normal,
392  MsqError& err ) const
393 {
394  try {
395  closest_and_normal( geomEntHandle, position, closest, normal );
396  }
397  catch (TSTTB::Error& tstt_err ) {
399  }
400 }
401 
402 
403 
404 
405 /***************** GeomTSTTCommon class methods *********************/
406 
407 GeomTSTTCommon::GeomTSTTCommon( TSTTG::Geometry& geom ) throw ( TSTTB::Error )
408  : geomIface( geom ),
409  geomHandles( alloc_sidl_vector<void*>(1) ),
410  positionsIn( alloc_sidl_vector<double>(3) )
411 {
412 }
413 
415 
416 
417 
418 void GeomTSTTCommon::move_to( void* geom, Vector3D& coord ) const
419  throw ( TSTTB::Error )
420 {
421  // going to assume this in the following reinterpret_cast, so
422  // check to make sure it is true
423  assert( sizeof(Vector3D) == 3*sizeof(double) );
424 
425  memcpy( convert_from_sidl_vector(positionsIn), &coord, 3*sizeof(double) );
426  positionsOut = convert_to_sidl_vector( reinterpret_cast<double*>(&coord), 3 );
427  *convert_from_sidl_vector( geomHandles ) = geom;
428 
429  int junk = 3;
430  geomIface.gentityClosestPoint( geomHandles, 1,
431  positionsIn, 3,
432  positionsOut, junk );
433 }
434 
435 
436 
437 void GeomTSTTCommon::normal( void* geom, Vector3D& coord ) const
438  throw ( TSTTB::Error )
439 {
440  // going to assume this in the following reinterpret_cast, so
441  // check to make sure it is true
442  assert( sizeof(Vector3D) == 3*sizeof(double) );
443 
444  memcpy( convert_from_sidl_vector(positionsIn), &coord, 3*sizeof(double) );
445  normalsOut = convert_to_sidl_vector( reinterpret_cast<double*>(&coord), 3 );
446  *convert_from_sidl_vector( geomHandles ) = geom;
447 
448  int junk;
449  geomIface.gentityNormal( geomHandles, 1,
450  positionsIn, 3,
451  normalsOut, junk );
452 }
453 
454 void GeomTSTTCommon::normal( void* geom, Vector3D coords[], unsigned count ) const
455  throw ( TSTTB::Error )
456 {
457  // going to assume this in the following reinterpret_cast, so
458  // check to make sure it is true
459  assert( sizeof(Vector3D) == 3*sizeof(double) );
460 
461  if (positionsIn.upper(0)+1 < 3*(int)count)
462  positionsIn = positionsIn.create1d( 3*count );
463  memcpy( convert_from_sidl_vector(positionsIn), coords, 3*count*sizeof(double) );
464 
465  normalsOut = convert_to_sidl_vector( reinterpret_cast<double*>(coords), 3*count );
466 
467  if (geomHandles.upper(0)+1 < (int)count)
468  geomHandles = geomHandles.create1d( count );
469  void** ptr = convert_from_sidl_vector( geomHandles );
470  for (void** end = ptr + count; ptr != end; ++ptr)
471  *ptr = geom;
472 
473  int junk;
474  geomIface.gentityNormal( geomHandles, count,
475  positionsIn, 3*count,
476  normalsOut, junk );
477 }
478 
480  const Vector3D& position,
481  Vector3D& closest,
482  Vector3D& normal ) const
483  throw (TSTTB::Error)
484 {
485  // going to assume this in the following reinterpret_cast, so
486  // check to make sure it is true
487  assert( sizeof(Vector3D) == 3*sizeof(double) );
488 
489  memcpy( convert_from_sidl_vector(positionsIn), &position, 3*sizeof(double) );
490  positionsOut = convert_to_sidl_vector( reinterpret_cast<double*>(&closest), 3 );
491  normalsOut = convert_to_sidl_vector( reinterpret_cast<double*>(&normal), 3 );
492  *convert_from_sidl_vector( geomHandles ) = geom;
493 
494  int junk1, junk2;
495  geomIface.gentityClosestPointAndNormal( geomHandles, 1,
496  positionsIn, 3,
497  positionsOut, junk1,
498  normalsOut, junk2 );
499 }
500 
501 } // namespace Mesquite
502 
sidl::array< double > normalsOut
Definition: GeomTSTT.cpp:101
void move_to(void *geom_handle, Vector3D &coord) const
Evaluate the closest point to the input position on the specified geometric entity and return the res...
Definition: GeomTSTT.cpp:418
TSTTG::Topology topoIface
TSTT interface implementation used to get dimension of geometric entities.
Definition: GeomTSTT.cpp:144
DomainHint hint() const
Give a hint about the nature of the domain for better performance.
Definition: GeomTSTT.cpp:348
sidl::array< void * > geomHandles
Temporary storage for geometry entity handles.
Definition: GeomTSTT.cpp:99
void normal(void *geom_handle, Vector3D &coord) const
Given a geometric entity and a position, evaluate the normal on the geometric entity at the closest p...
Definition: GeomTSTT.cpp:437
void normal_at(Mesh::EntityHandle entity_handle, Vector3D &coordinate) const
Returns the normal of the domain to which &quot;entity_handle&quot; is constrained.
Definition: GeomTSTT.cpp:363
virtual ~GeomEntTSTT()
Definition: GeomTSTT.cpp:346
void snap_to(Mesh::EntityHandle entity_handle, Vector3D &coordinat) const
Modifies &quot;coordinate&quot; so that it lies on the domain to which &quot;entity_handle&quot; is constrained.
Definition: GeomTSTT.cpp:252
TSTTM::Mesh meshIface
TSTT interface used to query mesh entity properties.
Definition: GeomTSTT.cpp:146
virtual ~GeomTSTT()
Definition: GeomTSTT.cpp:226
Used to hold the error state and return it to the application.
void normal_at(Mesh::EntityHandle entity_handle, Vector3D &coordinate) const
Returns the normal of the domain to which &quot;entity_handle&quot; is constrained.
Definition: GeomTSTT.cpp:265
DomainHint
A hint on the characteristics of the domain that Mesquite may use to determine what, if any, scheme to use to cache characteristics of the geometric domain.
void * geomEntHandle
A handle for the geometry entity to evaluate.
Definition: GeomTSTT.cpp:190
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
void * EntityHandle
Opaque EntityHandle type and tag type.
int coord[NPANE][NROW *NCOL][3]
Definition: blastest.C:86
sidl::array< double > positionsOut
Definition: GeomTSTT.cpp:101
static GeomTSTT * create(TSTTG::Geometry &geom, TSTTM::Mesh &mesh, TSTTR::Relate &assoc, MsqError &err)
Create MeshDommain from TSTT classification and geometry interfaces.
Definition: GeomTSTT.cpp:198
void closest_and_normal(void *geom_handle, const Vector3D &position, Vector3D &closest, Vector3D &normal) const
Given a geometric entity and a position, get point on the geometric entity closest to the input posit...
Definition: GeomTSTT.cpp:479
TSTTG::Shape geomIface
TSTT geometry interface implementation to query.
Definition: GeomTSTT.cpp:96
void snap_to(Mesh::EntityHandle entity_handle, Vector3D &coordinat) const
Modifies &quot;coordinate&quot; so that it lies on the domain to which &quot;entity_handle&quot; is constrained.
Definition: GeomTSTT.cpp:352
Common code for specific implementations of MeshDomain on TSTT interfaces.
Definition: GeomTSTT.cpp:55
static T * convert_from_sidl_vector(sidl::array< T > &array)
static sidl::array< T > convert_to_sidl_vector(T *array, size_t size)
DomainTSTT(TSTTG::Geometry &geom, TSTTM::Mesh &mesh, TSTTR::Relate &relate)
Definition: GeomTSTT.cpp:233
invalid function argument passed
void closest_point(Mesh::EntityHandle handle, const Vector3D &position, Vector3D &closest, Vector3D &normal, MsqError &err) const
evaluate closest point and normal
Definition: GeomTSTT.cpp:297
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
A base class describing a Mesquite::MeshDomain implemented on top of the TSTT geometry and classifica...
DomainHint hint() const
Give a hint about the nature of the domain for better performance.
Definition: GeomTSTT.cpp:249
sidl::array< TSTTG::GentityType > oneTypeOut
Temporary storage for geometry entity type.
Definition: GeomTSTT.cpp:153
TSTTR::Relate relateIface
TSTT interface implementation for mesh-&gt;geometry association.
Definition: GeomTSTT.cpp:148
void closest_point(Mesh::EntityHandle handle, const Vector3D &position, Vector3D &closest, Vector3D &normal, MsqError &err) const
evaluate closest point and normal
Definition: GeomTSTT.cpp:388
virtual ~DomainTSTT()
Definition: GeomTSTT.cpp:246
void * geom_from_mesh(void *handle) const
Get geometric entity owning a mesh entity.
Definition: GeomTSTT.cpp:318
sidl::array< double > positionsIn
Temporary storate for input and output vectors.
Definition: GeomTSTT.cpp:101
sidl::array< void * > oneMeshHandle
Temporary storage for mesh entity handles.
Definition: GeomTSTT.cpp:151
static msq_std::string process_tstt_error(TSTTB::Error &tstt_err)
GeomEntTSTT(TSTTG::Geometry &geom, void *geom_ent_handle)
Definition: GeomTSTT.cpp:339
GeomTSTTCommon(TSTTG::Geometry &geom)
Definition: GeomTSTT.cpp:407