Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2007 Sandia National Laboratories. Developed at the
5 : : University of Wisconsin--Madison under SNL contract number
6 : : 624796. The U.S. Government and the University of Wisconsin
7 : : retain certain rights to 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 : : (2007) [email protected]
24 : :
25 : : ***************************************************************** */
26 : :
27 : : /** \file XYRectangle.cpp
28 : : * \brief
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #include "Mesquite.hpp"
33 : : #include "XYRectangle.hpp"
34 : : #include "MsqError.hpp"
35 : : #include "MsqVertex.hpp"
36 : :
37 : : namespace MBMesquite
38 : : {
39 : :
40 : 2 : XYRectangle::XYRectangle( double w, double h, double x, double y, double z, Plane p )
41 [ + - ]: 2 : : normalDir( p ), widthDir( ( p + 1 ) % 3 ), heightDir( ( p + 2 ) % 3 )
42 : : {
43 : 2 : minCoords[0] = maxCoords[0] = x;
44 : 2 : minCoords[1] = maxCoords[1] = y;
45 : 2 : minCoords[2] = maxCoords[2] = z;
46 : 2 : maxCoords[widthDir] += w;
47 : 2 : maxCoords[heightDir] += h;
48 : 2 : }
49 : :
50 : 2 : void XYRectangle::setup( Mesh* mesh, MsqError& err )
51 : : {
52 : 2 : const double epsilon = 1e-4;
53 [ + - ][ + - ]: 2 : if( maxCoords[widthDir] - minCoords[widthDir] <= epsilon ||
54 [ - + ]: 2 : maxCoords[heightDir] - minCoords[heightDir] <= epsilon ||
55 : 2 : maxCoords[normalDir] - minCoords[normalDir] > epsilon )
56 : : {
57 [ # # ][ # # ]: 0 : MSQ_SETERR( err )( "Invalid rectangle dimensions", MsqError::INVALID_STATE );
58 : 2 : return;
59 : : }
60 : :
61 : 2 : mConstraints.clear();
62 : :
63 [ + - ]: 2 : std::vector< Mesh::EntityHandle > vertices;
64 [ + - ][ + - ]: 2 : mesh->get_all_vertices( vertices, err );MSQ_ERRRTN( err );
[ - + ][ # # ]
[ # # ][ - + ]
65 [ - + ]: 2 : if( vertices.empty() )
66 : : {
67 [ # # ][ # # ]: 0 : MSQ_SETERR( err )( "Empty mesh", MsqError::INVALID_MESH );
68 : 0 : return;
69 : : }
70 : :
71 [ + - ][ + - ]: 4 : std::vector< MsqVertex > coords( vertices.size() );
72 [ + - ][ + - ]: 2 : mesh->vertices_get_coordinates( arrptr( vertices ), arrptr( coords ), coords.size(), err );MSQ_ERRRTN( err );
[ + - ][ + - ]
[ - + ][ # # ]
[ # # ][ - + ]
73 : :
74 [ + + ][ + - ]: 20 : for( size_t i = 0; i < vertices.size(); ++i )
75 : : {
76 [ + + ]: 72 : for( int d = 0; d < 3; ++d )
77 : : {
78 [ + + ]: 54 : if( d == normalDir ) continue;
79 [ + - ][ + - ]: 36 : if( minCoords[d] - coords[i][d] > epsilon || coords[i][d] - maxCoords[d] > epsilon )
[ + - ][ + - ]
[ + - ][ - + ]
[ - + ]
80 : : {
81 : : MSQ_SETERR( err )
82 [ # # ][ # # ]: 0 : ( MsqError::INVALID_MESH, "Invalid vertex coordinate: (%f,%f,%f)\n", coords[i][0], coords[i][1],
[ # # ][ # # ]
83 [ # # ][ # # ]: 0 : coords[i][2] );
[ # # ][ # # ]
84 : 0 : return;
85 : : }
86 [ + - ][ + - ]: 36 : else if( coords[i][d] - minCoords[d] < epsilon )
[ + + ]
87 : : {
88 [ + - ]: 12 : VertexConstraint c( d, minCoords[d] );
89 [ + - ][ + - ]: 12 : mConstraints.insert( constraint_t::value_type( vertices[i], c ) );
[ + - ]
90 : : }
91 [ + - ][ + - ]: 24 : else if( maxCoords[d] - coords[i][d] < epsilon )
[ + + ]
92 : : {
93 [ + - ]: 12 : VertexConstraint c( d, maxCoords[d] );
94 [ + - ][ + - ]: 12 : mConstraints.insert( constraint_t::value_type( vertices[i], c ) );
[ + - ]
95 : : }
96 : : }
97 : 2 : }
98 : : }
99 : :
100 : 297 : void XYRectangle::snap_to( Mesh::VertexHandle vertex, Vector3D& coordinate ) const
101 : : {
102 : : // everything gets moved into the plane
103 [ + - ]: 297 : coordinate[normalDir] = minCoords[normalDir];
104 : : // apply other constraints
105 [ + - ]: 297 : constraint_t::const_iterator i = mConstraints.lower_bound( vertex );
106 [ + - ][ + - ]: 550 : for( ; i != mConstraints.end() && i->first == vertex; ++i )
[ + - ][ + - ]
[ + + ][ + - ]
[ + + # # ]
107 [ + - ][ + - ]: 253 : coordinate[i->second.axis] = i->second.coord;
[ + - ]
108 : 297 : }
109 : :
110 : 116 : void XYRectangle::vertex_normal_at( Mesh::VertexHandle /*handle*/, Vector3D& norm ) const
111 : : {
112 : 116 : norm.set( 0, 0, 0 );
113 : 116 : norm[normalDir] = 1.0;
114 : 116 : }
115 : :
116 : 3865 : void XYRectangle::element_normal_at( Mesh::ElementHandle /*handle*/, Vector3D& norm ) const
117 : : {
118 : 3865 : norm.set( 0, 0, 0 );
119 : 3865 : norm[normalDir] = 1.0;
120 : 3865 : }
121 : :
122 : 0 : void XYRectangle::vertex_normal_at( const Mesh::VertexHandle* /*vertices*/, Vector3D normals[], unsigned count,
123 : : MsqError& ) const
124 : : {
125 [ # # ]: 0 : Vector3D norm( 0, 0, 0 );
126 [ # # ]: 0 : norm[normalDir] = 1.0;
127 [ # # ]: 0 : std::fill( normals, normals + count, norm );
128 : 0 : }
129 : :
130 : 45 : void XYRectangle::closest_point( Mesh::VertexHandle vertex, const Vector3D& position, Vector3D& closest,
131 : : Vector3D& normal, MsqError& ) const
132 : : {
133 : 45 : normal = position;
134 : 45 : vertex_normal_at( vertex, normal );
135 : 45 : closest = position;
136 : 45 : closest[2] = 0;
137 : 45 : }
138 : :
139 : 72 : void XYRectangle::domain_DoF( const Mesh::VertexHandle* vertices, unsigned short* dof_array, size_t num_handles,
140 : : MsqError& ) const
141 : : {
142 [ + + ]: 508 : for( unsigned i = 0; i < num_handles; ++i )
143 : : {
144 : : // everything is at least constrained to XY-plane
145 : 436 : dof_array[i] = 2;
146 : : // each additional constraint reduces degrees of freedom
147 [ + - ]: 436 : constraint_t::const_iterator j = mConstraints.lower_bound( vertices[i] );
148 [ + - ][ + - ]: 952 : for( ; j != mConstraints.end() && j->first == vertices[i]; ++j )
[ + + ][ + - ]
[ + + ][ + - ]
[ + + # # ]
149 : 516 : --dof_array[i];
150 : : }
151 : 72 : }
152 : :
153 [ + - ][ + - ]: 8 : } // namespace MBMesquite
|