Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2006 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 : : (2006) [email protected]
24 : :
25 : : ***************************************************************** */
26 : :
27 : : /** \file TagVertexMesh.hpp
28 : : * \brief Definition of MBMesquite::TagVertexMesh class
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #ifndef MSQ_TAG_VERTEX_MESH_HPP
33 : : #define MSQ_TAG_VERTEX_MESH_HPP
34 : :
35 : : #include "Mesquite.hpp"
36 : : #include "MeshDecorator.hpp"
37 : : #include "Instruction.hpp"
38 : :
39 : : namespace MBMesquite
40 : : {
41 : :
42 : : /**\brief Store alternate vertex coordinates in tags.
43 : : *
44 : : * This class implements a decorator pattern for the MBMesquite::Mesh
45 : : * interface where alternate vertex coordinates are stored in a tag
46 : : * on the original mesh. The vertex coordinates are the same as that
47 : : * of the decorated Mesh interface until they are set. Once the coorindates
48 : : * of a vertex are set using an instance of this class, the modified
49 : : * vertex coordinates will be stored in a tag and returned from subsequent
50 : : * queries of the vertex coordinates through this interface.
51 : : *
52 : : * The tag used to store alternate vertex coordinates is created and set
53 : : * for all vertices when the coordinates of the any vertex are changed.
54 : : * The tag type is a vector of three doubles.
55 : : *
56 : : * Inserting an instance of this class into an InstructionQueue will result
57 : : * in true vertex coordinates being copied into the alternate coordinate
58 : : * values maintained by this class at that point in the instruction queue.
59 : : */
60 : : class MESQUITE_EXPORT TagVertexMesh : public MeshDecorator, public Instruction
61 : : {
62 : : private:
63 : : std::string tagName; //< Name of tag storing vertex coordinates
64 : : TagHandle tagHandle; //< Handle of tag storing vertex coordinates
65 : : bool haveTagHandle; //< True if tagHandle is set
66 : : bool cleanUpTag; //< If true, destroy tag in destructor
67 : :
68 : : /**\brief common code for constructor, set_mesh, and set_tag_name */
69 : : void initialize( Mesh* mesh, std::string name, MsqError& );
70 : : /**\brief copy real coordinate values into tag data */
71 : : void copy_all_coordinates( MsqError& err );
72 : : /**\brief if cleanUpTag, delete tag and clear handle */
73 : : void check_remove_tag( MsqError& err );
74 : :
75 : : public:
76 : : /**
77 : : *\param real_mesh The mesh from which to aquire topology information
78 : : * and vertex coordinates, and upon which to store
79 : : * tags.
80 : : *\param clean_up_tag_data If true, tag storing alternate vertex
81 : : * coordinates will be removed when this object
82 : : * is destroyed.
83 : : *\param tag_name Name of tag in which to store alternate vertex coordinates.
84 : : */
85 : : TagVertexMesh( MsqError& err, Mesh* real_mesh, bool clean_up_tag_data = true, std::string tag_name = "" );
86 : :
87 : : /** Destroy tag data for alternate coordinates if
88 : : * clean_up_tag_data is true.
89 : : */
90 : : virtual ~TagVertexMesh();
91 : :
92 : : /**\brief Change the Mesh instance used as the real mesh.
93 : : *
94 : : * Change the Mesh instance orignially specified in the
95 : : * constructor.
96 : : * Note: Calling this function changes the handle space for
97 : : * mesh entities, invalidating any previous handle values,
98 : : * iterators, etc. returned by the class instance.
99 : : * Note: If clean_up_tag_data is true, calling this function
100 : : * will remove any stored alternate vertex coordinates
101 : : * from the previous mesh.
102 : : */
103 : : void set_mesh( Mesh* real_mesh, MsqError& err );
104 : :
105 : : /**\brief Set tag cleanup behavior
106 : : *
107 : : * If true, class will remove any tag data storing alternate
108 : : * vertex coordinates from the real mesh when a) the real Mesh
109 : : * instance is changed or b) this object instance is destroted.
110 : : */
111 : : void should_clean_up_tag_data( bool value )
112 : : {
113 : : cleanUpTag = value;
114 : : }
115 : :
116 : : /**\brief Will tag storing alternate coordinates be destroyed. */
117 : : bool will_clean_up_tag_data() const
118 : : {
119 : : return cleanUpTag;
120 : : }
121 : :
122 : : /**\brief Get name of tag used to store alternate vertex coordinates. */
123 : 3 : std::string get_tag_name() const
124 : : {
125 : 3 : return tagName;
126 : : }
127 : :
128 : : /**\brief Set tag name used to store alternate vertex coordinates
129 : : *
130 : : * Change the tag name used to store alternate vertex coordinates.
131 : : * Note: Changing the tag name will result in the loss of any
132 : : * alternate vertex coordinates saved using the previous
133 : : * tag name.
134 : : * Note: If clean_up_tag_data is true, calling this function
135 : : * will result in the removal of the previous tag and
136 : : * any coordinates stored using that tag.
137 : : *\param init If the new tag already exists, any
138 : : * coordinates stored in that tag will be used if this
139 : : * argument is false. If this argument is true, the
140 : : * alternate coordinate values will be initialized to
141 : : * the true coordinate values in the real Mesh.
142 : : */
143 : : void set_tag_name( std::string name, MsqError& err );
144 : :
145 : : /**\brief clear all alternate vertex coordinate values
146 : : *
147 : : * Clear all alternate vertex coordinate values and
148 : : * revert to coordinates as stored in real mesh.
149 : : */
150 : : void clear( MsqError& err );
151 : :
152 : : virtual void vertices_get_coordinates( const VertexHandle vert_array[], MsqVertex* coordinates, size_t num_vtx,
153 : : MsqError& err );
154 : :
155 : : virtual void vertex_set_coordinates( VertexHandle vertex, const Vector3D& coordinates, MsqError& err );
156 : :
157 : : //*************** Tags ***********
158 : :
159 : : virtual TagHandle tag_create( const std::string& tag_name, TagType type, unsigned length, const void* default_value,
160 : : MsqError& err );
161 : :
162 : : virtual TagHandle tag_get( const std::string& name, MsqError& err );
163 : :
164 : : //**************** Memory Management ****************
165 : :
166 : : virtual void release();
167 : :
168 : : //**************** Instruction ****************
169 : :
170 : : virtual double loop_over_mesh( MeshDomainAssoc* mesh_and_domain, const Settings* settings, MsqError& err );
171 : :
172 : : virtual std::string get_name() const;
173 : :
174 : : //!\brief Called at start of instruction queue processing
175 : : //!
176 : : //! Do any preliminary global initialization, consistency checking,
177 : : //! etc. Default implementation does nothing.
178 : : virtual void initialize_queue( MeshDomainAssoc* mesh_and_domain, const Settings* settings, MsqError& err );
179 : : };
180 : :
181 : : } // namespace MBMesquite
182 : :
183 : : #endif
|