MOAB: Mesh Oriented datABase
(version 5.4.1)
|
Store alternate vertex coordinates in tags. More...
#include <TagVertexMesh.hpp>
Public Member Functions | |
TagVertexMesh (MsqError &err, Mesh *real_mesh, bool clean_up_tag_data=true, std::string tag_name="") | |
virtual | ~TagVertexMesh () |
void | set_mesh (Mesh *real_mesh, MsqError &err) |
Change the Mesh instance used as the real mesh. | |
void | should_clean_up_tag_data (bool value) |
Set tag cleanup behavior. | |
bool | will_clean_up_tag_data () const |
Will tag storing alternate coordinates be destroyed. | |
std::string | get_tag_name () const |
Get name of tag used to store alternate vertex coordinates. | |
void | set_tag_name (std::string name, MsqError &err) |
Set tag name used to store alternate vertex coordinates. | |
void | clear (MsqError &err) |
clear all alternate vertex coordinate values | |
virtual void | vertices_get_coordinates (const VertexHandle vert_array[], MsqVertex *coordinates, size_t num_vtx, MsqError &err) |
Get/set location of a vertex. | |
virtual void | vertex_set_coordinates (VertexHandle vertex, const Vector3D &coordinates, MsqError &err) |
virtual TagHandle | tag_create (const std::string &tag_name, TagType type, unsigned length, const void *default_value, MsqError &err) |
Create a tag. | |
virtual TagHandle | tag_get (const std::string &name, MsqError &err) |
Get handle for existing tag, by name. | |
virtual void | release () |
virtual double | loop_over_mesh (MeshDomainAssoc *mesh_and_domain, const Settings *settings, MsqError &err) |
virtual std::string | get_name () const |
Get string name for use in diagnostic and status output. | |
virtual void | initialize_queue (MeshDomainAssoc *mesh_and_domain, const Settings *settings, MsqError &err) |
Called at start of instruction queue processing. | |
Private Member Functions | |
void | initialize (Mesh *mesh, std::string name, MsqError &) |
common code for constructor, set_mesh, and set_tag_name | |
void | copy_all_coordinates (MsqError &err) |
copy real coordinate values into tag data | |
void | check_remove_tag (MsqError &err) |
if cleanUpTag, delete tag and clear handle | |
Private Attributes | |
std::string | tagName |
TagHandle | tagHandle |
bool | haveTagHandle |
bool | cleanUpTag |
Store alternate vertex coordinates in tags.
This class implements a decorator pattern for the MBMesquite::Mesh interface where alternate vertex coordinates are stored in a tag on the original mesh. The vertex coordinates are the same as that of the decorated Mesh interface until they are set. Once the coorindates of a vertex are set using an instance of this class, the modified vertex coordinates will be stored in a tag and returned from subsequent queries of the vertex coordinates through this interface.
The tag used to store alternate vertex coordinates is created and set for all vertices when the coordinates of the any vertex are changed. The tag type is a vector of three doubles.
Inserting an instance of this class into an InstructionQueue will result in true vertex coordinates being copied into the alternate coordinate values maintained by this class at that point in the instruction queue.
Definition at line 60 of file TagVertexMesh.hpp.
MBMesquite::TagVertexMesh::TagVertexMesh | ( | MsqError & | err, |
Mesh * | real_mesh, | ||
bool | clean_up_tag_data = true , |
||
std::string | tag_name = "" |
||
) |
real_mesh | The mesh from which to aquire topology information and vertex coordinates, and upon which to store tags. |
clean_up_tag_data | If true, tag storing alternate vertex coordinates will be removed when this object is destroyed. |
tag_name | Name of tag in which to store alternate vertex coordinates. |
Definition at line 131 of file TagVertexMesh.cpp.
References initialize(), and MSQ_CHKERR.
: tagHandle( 0 ), haveTagHandle( false ), cleanUpTag( clean_up ) { if( name.size() == 0 ) name = "MsqAltCoords"; initialize( real_mesh, name, err );MSQ_CHKERR( err ); }
MBMesquite::TagVertexMesh::~TagVertexMesh | ( | ) | [virtual] |
Destroy tag data for alternate coordinates if clean_up_tag_data is true.
Definition at line 138 of file TagVertexMesh.cpp.
References check_remove_tag().
{ MsqError err; check_remove_tag( err ); }
void MBMesquite::TagVertexMesh::check_remove_tag | ( | MsqError & | err | ) | [private] |
if cleanUpTag, delete tag and clear handle
Definition at line 122 of file TagVertexMesh.cpp.
References cleanUpTag, haveTagHandle, MSQ_ERRRTN, MBMesquite::MeshDecorator::tag_delete(), and tagHandle.
Referenced by release(), set_mesh(), set_tag_name(), and ~TagVertexMesh().
{ if( cleanUpTag && haveTagHandle ) { tag_delete( tagHandle, err );MSQ_ERRRTN( err ); } haveTagHandle = false; }
void MBMesquite::TagVertexMesh::clear | ( | MsqError & | err | ) |
clear all alternate vertex coordinate values
Clear all alternate vertex coordinate values and revert to coordinates as stored in real mesh.
Definition at line 156 of file TagVertexMesh.cpp.
References copy_all_coordinates(), haveTagHandle, and MSQ_CHKERR.
Referenced by release().
{ if( haveTagHandle ) { copy_all_coordinates( err );MSQ_CHKERR( err ); } }
void MBMesquite::TagVertexMesh::copy_all_coordinates | ( | MsqError & | err | ) | [private] |
copy real coordinate values into tag data
Definition at line 94 of file TagVertexMesh.cpp.
References MBMesquite::arrptr(), MBMesquite::Mesh::DOUBLE, MBMesquite::MeshDecorator::get_all_vertices(), MBMesquite::MeshDecorator::get_mesh(), haveTagHandle, MSQ_ERRRTN, MBMesquite::Mesh::tag_create(), MBMesquite::MeshDecorator::tag_set_vertex_data(), tagHandle, tagName, and MBMesquite::Mesh::vertices_get_coordinates().
Referenced by clear(), loop_over_mesh(), and vertex_set_coordinates().
{ if( !haveTagHandle ) { tagHandle = get_mesh()->tag_create( tagName, Mesh::DOUBLE, 3, 0, err );MSQ_ERRRTN( err ); haveTagHandle = true; } std::vector< Mesh::VertexHandle > handles; get_all_vertices( handles, err );MSQ_ERRRTN( err ); if( handles.empty() ) return; std::vector< MsqVertex > coords( handles.size() ); get_mesh()->vertices_get_coordinates( arrptr( handles ), arrptr( coords ), handles.size(), err );MSQ_ERRRTN( err ); std::vector< double > data( 3 * handles.size() ); std::vector< double >::iterator j = data.begin(); std::vector< MsqVertex >::const_iterator i = coords.begin(); while( i != coords.end() ) { i->get_coordinates( &*j ); ++i; j += 3; } tag_set_vertex_data( tagHandle, handles.size(), arrptr( handles ), arrptr( data ), err );MSQ_ERRRTN( err ); }
std::string MBMesquite::TagVertexMesh::get_name | ( | ) | const [virtual] |
Get string name for use in diagnostic and status output.
Implements MBMesquite::Instruction.
Definition at line 40 of file TagVertexMesh.cpp.
References tagName.
{ std::string result( "TagVertexMesh(\"" ); result += tagName; result += "\")"; return result; }
std::string MBMesquite::TagVertexMesh::get_tag_name | ( | ) | const [inline] |
Get name of tag used to store alternate vertex coordinates.
Definition at line 123 of file TagVertexMesh.hpp.
Referenced by MBMesquite::DeformingDomainWrapper::store_initial_mesh().
{ return tagName; }
void MBMesquite::TagVertexMesh::initialize | ( | Mesh * | mesh, |
std::string | name, | ||
MsqError & | err | ||
) | [private] |
common code for constructor, set_mesh, and set_tag_name
Definition at line 48 of file TagVertexMesh.cpp.
References MBMesquite::Mesh::BYTE, MBMesquite::MsqError::clear(), MBMesquite::Mesh::DOUBLE, MBMesquite::MsqError::error_code(), MBMesquite::MeshDecorator::get_mesh(), haveTagHandle, MBMesquite::length(), MSQ_CHKERR, MSQ_ERRRTN, MSQ_SETERR, set_mesh(), MBMesquite::MsqError::TAG_ALREADY_EXISTS, MBMesquite::Mesh::tag_get(), MBMesquite::MsqError::TAG_NOT_FOUND, MBMesquite::MeshDecorator::tag_properties(), tagHandle, and tagName.
Referenced by set_mesh(), set_tag_name(), and TagVertexMesh().
{ MeshDecorator::set_mesh( mesh ); tagName = name; tagHandle = get_mesh()->tag_get( tagName, err ); // If tag isn't defined yet, we're done for now. if( err.error_code() == MsqError::TAG_NOT_FOUND ) { err.clear(); return; } else if( MSQ_CHKERR( err ) ) return; // If tag is already defined, make sure it is the correct type. std::string t_name; Mesh::TagType type; unsigned length; tag_properties( tagHandle, t_name, type, length, err );MSQ_ERRRTN( err ); if( !( type == Mesh::DOUBLE && length == 3 ) && !( type == Mesh::BYTE && length == 3 * sizeof( double ) ) ) MSQ_SETERR( err ) ( MsqError::TAG_ALREADY_EXISTS, "Tag \"%s\" has invalid type or size.", tagName.c_str() ); // If tag is already defined and init was true, reset tag // values. haveTagHandle = true; }
void MBMesquite::TagVertexMesh::initialize_queue | ( | MeshDomainAssoc * | mesh_and_domain, |
const Settings * | settings, | ||
MsqError & | err | ||
) | [virtual] |
Called at start of instruction queue processing.
Do any preliminary global initialization, consistency checking, etc. Default implementation does nothing.
Implements MBMesquite::Instruction.
Definition at line 246 of file TagVertexMesh.cpp.
{}
double MBMesquite::TagVertexMesh::loop_over_mesh | ( | MeshDomainAssoc * | mesh_and_domain, |
const Settings * | settings, | ||
MsqError & | err | ||
) | [virtual] |
Virtual fuction implementing primary functionaliy of instruction instance.
Implements MBMesquite::Instruction.
Definition at line 77 of file TagVertexMesh.cpp.
References copy_all_coordinates(), MBMesquite::MeshDecorator::get_mesh(), MBMesquite::MeshDomainAssoc::get_mesh(), MBMesquite::MsqError::INVALID_MESH, mesh, MSQ_ERRZERO, and MSQ_SETERR.
{ Mesh* mesh = mesh_and_domain->get_mesh(); if( mesh != get_mesh() ) { MSQ_SETERR( err ) ( "InstructionQueue and TagVertexMesh have different " "MBMesquite::Mesh instances. Cannot initialize TagVertexMesh", MsqError::INVALID_MESH ); return 0.0; } copy_all_coordinates( err ); MSQ_ERRZERO( err ); return 0.0; }
void MBMesquite::TagVertexMesh::release | ( | ) | [virtual] |
Instead of deleting a Mesh when you think you are done, call release(). In simple cases, the implementation could just call the destructor. More sophisticated implementations may want to keep the Mesh object to live longer than Mesquite is using it.
Reimplemented from MBMesquite::MeshDecorator.
Definition at line 237 of file TagVertexMesh.cpp.
References check_remove_tag(), clear(), and haveTagHandle.
{ MsqError err; clear( err ); check_remove_tag( err ); haveTagHandle = false; MeshDecorator::release(); }
void MBMesquite::TagVertexMesh::set_mesh | ( | Mesh * | real_mesh, |
MsqError & | err | ||
) |
Change the Mesh instance used as the real mesh.
Change the Mesh instance orignially specified in the constructor. Note: Calling this function changes the handle space for mesh entities, invalidating any previous handle values, iterators, etc. returned by the class instance. Note: If clean_up_tag_data is true, calling this function will remove any stored alternate vertex coordinates from the previous mesh.
Definition at line 144 of file TagVertexMesh.cpp.
References check_remove_tag(), initialize(), MSQ_ERRRTN, and tagName.
Referenced by initialize().
{ check_remove_tag( err );MSQ_ERRRTN( err ); initialize( mesh, tagName, err );MSQ_ERRRTN( err ); }
void MBMesquite::TagVertexMesh::set_tag_name | ( | std::string | name, |
MsqError & | err | ||
) |
Set tag name used to store alternate vertex coordinates.
Change the tag name used to store alternate vertex coordinates. Note: Changing the tag name will result in the loss of any alternate vertex coordinates saved using the previous tag name. Note: If clean_up_tag_data is true, calling this function will result in the removal of the previous tag and any coordinates stored using that tag.
init | If the new tag already exists, any coordinates stored in that tag will be used if this argument is false. If this argument is true, the alternate coordinate values will be initialized to the true coordinate values in the real Mesh. |
Definition at line 150 of file TagVertexMesh.cpp.
References check_remove_tag(), MBMesquite::MeshDecorator::get_mesh(), initialize(), and MSQ_ERRRTN.
{ check_remove_tag( err );MSQ_ERRRTN( err ); initialize( get_mesh(), name, err );MSQ_ERRRTN( err ); }
void MBMesquite::TagVertexMesh::should_clean_up_tag_data | ( | bool | value | ) | [inline] |
Set tag cleanup behavior.
If true, class will remove any tag data storing alternate vertex coordinates from the real mesh when a) the real Mesh instance is changed or b) this object instance is destroted.
Definition at line 111 of file TagVertexMesh.hpp.
References value().
{ cleanUpTag = value; }
TagHandle MBMesquite::TagVertexMesh::tag_create | ( | const std::string & | tag_name, |
TagType | type, | ||
unsigned | length, | ||
const void * | default_value, | ||
MsqError & | err | ||
) | [virtual] |
Create a tag.
Create a user-defined data type that can be attached to any element or vertex in the mesh. For an opaque or undefined type, use type=BYTE and length=sizeof(..).
tag_name | A unique name for the data object |
type | The type of the data |
length | Number of values per entity (1->scalar, >1 ->vector) |
default_value | Default value to assign to all entities - may be NULL |
Reimplemented from MBMesquite::MeshDecorator.
Definition at line 203 of file TagVertexMesh.cpp.
References MBMesquite::MeshDecorator::get_mesh(), MSQ_SETERR, MBMesquite::MsqError::TAG_ALREADY_EXISTS, MBMesquite::Mesh::tag_create(), and tagName.
{ // Don't allow access to internal tag for vertex coordinates. // This prevents accidental layering of multiple instances of // TagVertexMesh with the same tag name. if( tag_name == tagName ) { MSQ_SETERR( err ) ( "Attempt to access internal tag data using tag interface.", MsqError::TAG_ALREADY_EXISTS ); return (TagHandle)0; } return get_mesh()->tag_create( tag_name, type, length, default_value, err ); }
TagHandle MBMesquite::TagVertexMesh::tag_get | ( | const std::string & | name, |
MsqError & | err | ||
) | [virtual] |
Get handle for existing tag, by name.
Check for the existance of a tag given it's name and if it exists return a handle for it. If the specified tag does not exist, zero should be returned WITHOUT flagging an error.
Reimplemented from MBMesquite::MeshDecorator.
Definition at line 222 of file TagVertexMesh.cpp.
References MBMesquite::MeshDecorator::get_mesh(), MBMesquite::MsqError::INVALID_ARG, MSQ_SETERR, MBMesquite::Mesh::tag_get(), and tagName.
{ // Don't allow access to internal tag for vertex coordinates. // This prevents accidental layering of multiple instances of // TagVertexMesh with the same tag name. if( name == tagName ) { MSQ_SETERR( err ) ( "Attempt to access internal tag data using tag interface.", MsqError::INVALID_ARG ); return (TagHandle)0; } return get_mesh()->tag_get( name, err ); }
void MBMesquite::TagVertexMesh::vertex_set_coordinates | ( | VertexHandle | vertex, |
const Vector3D & | coordinates, | ||
MsqError & | err | ||
) | [virtual] |
Reimplemented from MBMesquite::MeshDecorator.
Definition at line 189 of file TagVertexMesh.cpp.
References copy_all_coordinates(), MBMesquite::Mesh::DOUBLE, MBMesquite::MeshDecorator::get_mesh(), haveTagHandle, MSQ_ERRRTN, MBMesquite::Mesh::tag_create(), MBMesquite::Mesh::tag_set_vertex_data(), tagHandle, tagName, and MBMesquite::Vector3D::to_array().
Referenced by TagVertexMeshTest::test_alternate_name(), TagVertexMeshTest::test_cleanup(), TagVertexMeshTest::test_save_coordinates(), and TagVertexMeshTest::test_vertex_coordinates().
{ if( !haveTagHandle ) { tagHandle = get_mesh()->tag_create( tagName, Mesh::DOUBLE, 3, 0, err );MSQ_ERRRTN( err ); haveTagHandle = true; copy_all_coordinates( err );MSQ_ERRRTN( err ); } get_mesh()->tag_set_vertex_data( tagHandle, 1, &vertex, coordinates.to_array(), err );MSQ_ERRRTN( err ); }
void MBMesquite::TagVertexMesh::vertices_get_coordinates | ( | const VertexHandle | vert_array[], |
MsqVertex * | coordinates, | ||
size_t | num_vtx, | ||
MsqError & | err | ||
) | [virtual] |
Get/set location of a vertex.
Reimplemented from MBMesquite::MeshDecorator.
Definition at line 164 of file TagVertexMesh.cpp.
References MBMesquite::arrptr(), MBMesquite::MeshDecorator::get_mesh(), haveTagHandle, MSQ_ERRRTN, MBMesquite::Vector3D::set(), MBMesquite::Mesh::tag_get_vertex_data(), tagHandle, and MBMesquite::Mesh::vertices_get_coordinates().
Referenced by TagVertexMeshTest::test_alternate_name(), TagVertexMeshTest::test_cleanup(), TagVertexMeshTest::test_reference_mesh(), TagVertexMeshTest::test_save_coordinates(), and TagVertexMeshTest::test_vertex_coordinates().
{ if( !num_vtx ) return; if( !haveTagHandle ) { get_mesh()->vertices_get_coordinates( vert_array, coordinates, num_vtx, err );MSQ_ERRRTN( err ); } else { std::vector< double > coords( num_vtx * 3 ); get_mesh()->tag_get_vertex_data( tagHandle, num_vtx, vert_array, arrptr( coords ), err );MSQ_ERRRTN( err ); MsqVertex* coordinates_end = coordinates + num_vtx; std::vector< double >::const_iterator i = coords.begin(); while( coordinates != coordinates_end ) { coordinates->set( &*i ); i += 3; ++coordinates; } } }
bool MBMesquite::TagVertexMesh::will_clean_up_tag_data | ( | ) | const [inline] |
Will tag storing alternate coordinates be destroyed.
Definition at line 117 of file TagVertexMesh.hpp.
{ return cleanUpTag; }
bool MBMesquite::TagVertexMesh::cleanUpTag [private] |
Definition at line 66 of file TagVertexMesh.hpp.
Referenced by check_remove_tag().
bool MBMesquite::TagVertexMesh::haveTagHandle [private] |
Definition at line 65 of file TagVertexMesh.hpp.
Referenced by check_remove_tag(), clear(), copy_all_coordinates(), initialize(), release(), vertex_set_coordinates(), and vertices_get_coordinates().
Definition at line 64 of file TagVertexMesh.hpp.
Referenced by check_remove_tag(), copy_all_coordinates(), initialize(), vertex_set_coordinates(), and vertices_get_coordinates().
std::string MBMesquite::TagVertexMesh::tagName [private] |
Definition at line 63 of file TagVertexMesh.hpp.
Referenced by copy_all_coordinates(), get_name(), initialize(), set_mesh(), tag_create(), tag_get(), and vertex_set_coordinates().