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.cpp
28 : : * \brief Implementation of MBMesquite::TagVertexMesh class
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #include "Mesquite.hpp"
33 : : #include "TagVertexMesh.hpp"
34 : : #include "MsqError.hpp"
35 : : #include "MsqVertex.hpp"
36 : :
37 : : namespace MBMesquite
38 : : {
39 : :
40 : 0 : std::string TagVertexMesh::get_name() const
41 : : {
42 [ # # ]: 0 : std::string result( "TagVertexMesh(\"" );
43 [ # # ]: 0 : result += tagName;
44 [ # # ]: 0 : result += "\")";
45 : 0 : return result;
46 : : }
47 : :
48 : 10 : void TagVertexMesh::initialize( Mesh* mesh, std::string name, MsqError& err )
49 : : {
50 [ + - ]: 10 : MeshDecorator::set_mesh( mesh );
51 [ + - ]: 10 : tagName = name;
52 : :
53 [ + - ][ + - ]: 10 : tagHandle = get_mesh()->tag_get( tagName, err );
54 : : // If tag isn't defined yet, we're done for now.
55 [ + - ][ + + ]: 10 : if( err.error_code() == MsqError::TAG_NOT_FOUND )
56 : : {
57 [ + - ]: 7 : err.clear();
58 : 10 : return;
59 : : }
60 [ + - ][ - + ]: 3 : else if( MSQ_CHKERR( err ) )
[ # # ][ # # ]
[ - + ]
61 : 0 : return;
62 : :
63 : : // If tag is already defined, make sure it is the correct type.
64 [ + - ]: 3 : std::string t_name;
65 : : Mesh::TagType type;
66 : : unsigned length;
67 [ + - ][ + - ]: 3 : tag_properties( tagHandle, t_name, type, length, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
68 [ + - ][ - + ]: 3 : if( !( type == Mesh::DOUBLE && length == 3 ) && !( type == Mesh::BYTE && length == 3 * sizeof( double ) ) )
[ # # ][ # # ]
69 : : MSQ_SETERR( err )
70 [ # # ][ # # ]: 0 : ( MsqError::TAG_ALREADY_EXISTS, "Tag \"%s\" has invalid type or size.", tagName.c_str() );
71 : :
72 : : // If tag is already defined and init was true, reset tag
73 : : // values.
74 [ + - ]: 3 : haveTagHandle = true;
75 : : }
76 : :
77 : 6 : double TagVertexMesh::loop_over_mesh( MeshDomainAssoc* mesh_and_domain, const Settings*, MsqError& err )
78 : : {
79 : 6 : Mesh* mesh = mesh_and_domain->get_mesh();
80 [ - + ]: 6 : if( mesh != get_mesh() )
81 : : {
82 : : MSQ_SETERR( err )
83 : : ( "InstructionQueue and TagVertexMesh have different "
84 : : "MBMesquite::Mesh instances. Cannot initialize TagVertexMesh",
85 [ # # ]: 0 : MsqError::INVALID_MESH );
86 : 0 : return 0.0;
87 : : }
88 : :
89 : 6 : copy_all_coordinates( err );
90 [ - + ][ # # ]: 6 : MSQ_ERRZERO( err );
[ - + ]
91 : 6 : return 0.0;
92 : : }
93 : :
94 : 6 : void TagVertexMesh::copy_all_coordinates( MsqError& err )
95 : : {
96 [ + - ]: 6 : if( !haveTagHandle )
97 : : {
98 [ + - ][ + - ]: 12 : tagHandle = get_mesh()->tag_create( tagName, Mesh::DOUBLE, 3, 0, err );MSQ_ERRRTN( err );
[ + - ][ - + ]
[ # # ][ # # ]
[ - + ]
99 : 6 : haveTagHandle = true;
100 : : }
101 : :
102 [ + - ]: 6 : std::vector< Mesh::VertexHandle > handles;
103 [ + - ][ + - ]: 6 : get_all_vertices( handles, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
104 [ - + ]: 6 : if( handles.empty() ) return;
105 : :
106 [ + - ][ + - ]: 12 : std::vector< MsqVertex > coords( handles.size() );
107 [ + - ][ + - ]: 6 : get_mesh()->vertices_get_coordinates( arrptr( handles ), arrptr( coords ), handles.size(), err );MSQ_ERRRTN( err );
[ + - ][ + - ]
[ + - ][ - + ]
[ # # ][ # # ]
[ - + ]
108 : :
109 [ + - ][ + - ]: 12 : std::vector< double > data( 3 * handles.size() );
110 : 6 : std::vector< double >::iterator j = data.begin();
111 [ + - ]: 6 : std::vector< MsqVertex >::const_iterator i = coords.begin();
112 [ + - ][ + + ]: 11121 : while( i != coords.end() )
113 : : {
114 [ + - ][ + - ]: 11115 : i->get_coordinates( &*j );
[ + - ]
115 [ + - ]: 11115 : ++i;
116 [ + - ]: 11115 : j += 3;
117 : : }
118 : :
119 [ + - ][ + - ]: 12 : tag_set_vertex_data( tagHandle, handles.size(), arrptr( handles ), arrptr( data ), err );MSQ_ERRRTN( err );
[ + - ][ + - ]
[ - + ][ # # ]
[ # # ][ - + ]
[ + - ]
120 : : }
121 : :
122 : 10 : void TagVertexMesh::check_remove_tag( MsqError& err )
123 : : {
124 [ + + ][ + + ]: 10 : if( cleanUpTag && haveTagHandle )
125 : : {
126 [ - + ][ # # ]: 6 : tag_delete( tagHandle, err );MSQ_ERRRTN( err );
[ - + ]
127 : : }
128 : 10 : haveTagHandle = false;
129 : : }
130 : :
131 : 10 : TagVertexMesh::TagVertexMesh( MsqError& err, Mesh* real_mesh, bool clean_up, std::string name )
132 [ + - ]: 10 : : tagHandle( 0 ), haveTagHandle( false ), cleanUpTag( clean_up )
133 : : {
134 [ + - ][ + - ]: 10 : if( name.size() == 0 ) name = "MsqAltCoords";
135 [ + - ][ + - ]: 10 : initialize( real_mesh, name, err );MSQ_CHKERR( err );
[ + - ][ - + ]
[ # # ][ # # ]
136 : 10 : }
137 : :
138 : 20 : TagVertexMesh::~TagVertexMesh()
139 : : {
140 : 10 : MsqError err;
141 : 10 : check_remove_tag( err );
142 [ - + ]: 10 : }
143 : :
144 : 0 : void TagVertexMesh::set_mesh( Mesh* mesh, MsqError& err )
145 : : {
146 [ # # ][ # # ]: 0 : check_remove_tag( err );MSQ_ERRRTN( err );
[ # # ]
147 [ # # ][ # # ]: 0 : initialize( mesh, tagName, err );MSQ_ERRRTN( err );
[ # # ][ # # ]
148 : : }
149 : :
150 : 0 : void TagVertexMesh::set_tag_name( std::string name, MsqError& err )
151 : : {
152 [ # # ][ # # ]: 0 : check_remove_tag( err );MSQ_ERRRTN( err );
[ # # ]
153 [ # # ][ # # ]: 0 : initialize( get_mesh(), name, err );MSQ_ERRRTN( err );
[ # # ][ # # ]
[ # # ]
154 : : }
155 : :
156 : 0 : void TagVertexMesh::clear( MsqError& err )
157 : : {
158 [ # # ]: 0 : if( haveTagHandle )
159 : : {
160 [ # # ][ # # ]: 0 : copy_all_coordinates( err );MSQ_CHKERR( err );
161 : : }
162 : 0 : }
163 : :
164 : 5822157 : void TagVertexMesh::vertices_get_coordinates( const VertexHandle vert_array[], MsqVertex* coordinates, size_t num_vtx,
165 : : MsqError& err )
166 : : {
167 [ - + ]: 5822157 : if( !num_vtx ) return;
168 [ + + ]: 5822157 : if( !haveTagHandle )
169 : : {
170 [ - + ][ # # ]: 1011057 : get_mesh()->vertices_get_coordinates( vert_array, coordinates, num_vtx, err );MSQ_ERRRTN( err );
[ - + ]
171 : : }
172 : : else
173 : : {
174 [ + - ]: 4811100 : std::vector< double > coords( num_vtx * 3 );
175 [ + - ][ + - ]: 4811100 : get_mesh()->tag_get_vertex_data( tagHandle, num_vtx, vert_array, arrptr( coords ), err );MSQ_ERRRTN( err );
[ + - ][ + - ]
[ - + ][ # # ]
[ # # ][ - + ]
176 : 4811100 : MsqVertex* coordinates_end = coordinates + num_vtx;
177 [ + - ]: 4811100 : std::vector< double >::const_iterator i = coords.begin();
178 [ + + ][ + - ]: 24055500 : while( coordinates != coordinates_end )
179 : : {
180 [ + - ][ + - ]: 19244400 : coordinates->set( &*i );
181 [ + - ]: 19244400 : i += 3;
182 : 19244400 : ++coordinates;
183 : 5822157 : }
184 : : }
185 : : }
186 : :
187 : 0 : void TagVertexMesh::vertex_set_coordinates( VertexHandle vertex, const Vector3D& coordinates, MsqError& err )
188 : : {
189 [ # # ]: 0 : if( !haveTagHandle )
190 : : {
191 [ # # ][ # # ]: 0 : tagHandle = get_mesh()->tag_create( tagName, Mesh::DOUBLE, 3, 0, err );MSQ_ERRRTN( err );
[ # # ]
192 : 0 : haveTagHandle = true;
193 [ # # ][ # # ]: 0 : copy_all_coordinates( err );MSQ_ERRRTN( err );
[ # # ]
194 : : }
195 : :
196 [ # # ][ # # ]: 0 : get_mesh()->tag_set_vertex_data( tagHandle, 1, &vertex, coordinates.to_array(), err );MSQ_ERRRTN( err );
[ # # ]
197 : : }
198 : :
199 : : //*************** Tags ***********
200 : :
201 : 0 : TagHandle TagVertexMesh::tag_create( const std::string& tag_name, TagType type, unsigned length,
202 : : const void* default_value, MsqError& err )
203 : : {
204 : : // Don't allow access to internal tag for vertex coordinates.
205 : : // This prevents accidental layering of multiple instances of
206 : : // TagVertexMesh with the same tag name.
207 [ # # ]: 0 : if( tag_name == tagName )
208 : : {
209 : : MSQ_SETERR( err )
210 [ # # ]: 0 : ( "Attempt to access internal tag data using tag interface.", MsqError::TAG_ALREADY_EXISTS );
211 : 0 : return (TagHandle)0;
212 : : }
213 : :
214 : 0 : return get_mesh()->tag_create( tag_name, type, length, default_value, err );
215 : : }
216 : :
217 : 0 : TagHandle TagVertexMesh::tag_get( const std::string& name, MsqError& err )
218 : : {
219 : : // Don't allow access to internal tag for vertex coordinates.
220 : : // This prevents accidental layering of multiple instances of
221 : : // TagVertexMesh with the same tag name.
222 [ # # ]: 0 : if( name == tagName )
223 : : {
224 : : MSQ_SETERR( err )
225 [ # # ]: 0 : ( "Attempt to access internal tag data using tag interface.", MsqError::INVALID_ARG );
226 : 0 : return (TagHandle)0;
227 : : }
228 : :
229 : 0 : return get_mesh()->tag_get( name, err );
230 : : }
231 : :
232 : 0 : void TagVertexMesh::release()
233 : : {
234 [ # # ]: 0 : MsqError err;
235 [ # # ]: 0 : clear( err );
236 [ # # ]: 0 : check_remove_tag( err );
237 : 0 : haveTagHandle = false;
238 [ # # ]: 0 : MeshDecorator::release();
239 : 0 : }
240 : :
241 : 6 : void TagVertexMesh::initialize_queue( MeshDomainAssoc*, const Settings*, MsqError& ) {}
242 : :
243 [ + - ][ + - ]: 16 : } // namespace MBMesquite
|