Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2004 Sandia Corporation and Argonne National
5 : : Laboratory. Under the terms of Contract DE-AC04-94AL85000
6 : : with Sandia Corporation, the U.S. Government 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 : : [email protected], [email protected], [email protected],
24 : : [email protected], [email protected], [email protected]
25 : :
26 : : ***************************************************************** */
27 : : /*!
28 : : \file Randomize.cpp
29 : : \brief
30 : :
31 : : The Randomize Class is the concrete class that randomizes
32 : : the vertex positions.
33 : :
34 : : \author Michael Brewer
35 : : \date 2002-10-27
36 : : */
37 : :
38 : : #include "Randomize.hpp"
39 : : #include "MsqFreeVertexIndexIterator.hpp"
40 : : #include "MsqDebug.hpp"
41 : : #include <math.h>
42 : :
43 : : using namespace MBMesquite;
44 : :
45 [ - + ]: 2 : Randomize::~Randomize() {}
46 : :
47 : 0 : std::string Randomize::get_name() const
48 : : {
49 [ # # ]: 0 : return "Randomize";
50 : : }
51 : :
52 : 0 : PatchSet* Randomize::get_patch_set()
53 : : {
54 : 0 : return &patchSet;
55 : : }
56 : :
57 [ # # ][ # # ]: 0 : Randomize::Randomize() : mPercent( 0.5 ), patchSet( 1, true ) {}
58 : :
59 [ + - ][ + - ]: 1 : Randomize::Randomize( double percent ) : mPercent( percent ), patchSet( 1, true ) {}
60 : :
61 : 0 : void Randomize::initialize( PatchData& /*pd*/, MsqError& ) {}
62 : :
63 : 0 : void Randomize::initialize_mesh_iteration( PatchData& /*pd*/, MsqError& /*err*/ )
64 : : {
65 : : // cout << "- Executing Randomize::iteration_complete()\n";
66 : 0 : }
67 : :
68 : : /*!Function calculates a scale factor for the patch, then moves
69 : : the incident vertex randomly in each of the three coordinate
70 : : directions (relative to the scale factor multiplied by mPercent).
71 : : */
72 : 0 : static inline void randomize_vertex( PatchData& pd, size_t free_ind, double percent, MsqError& err )
73 : : {
74 : : size_t i;
75 : : short j;
76 [ # # ][ # # ]: 0 : const MsqVertex* verts = pd.get_vertex_array( err );MSQ_ERRRTN( err );
[ # # ][ # # ]
[ # # ][ # # ]
77 [ # # ]: 0 : const size_t num_vtx = pd.num_nodes();
78 : : // a scale w.r.t. the patch size
79 : 0 : double scale_factor = 0.0;
80 : : // a "random" number between -1 and 1
81 : 0 : double rand_double = 0.0;
82 : : // a "random" int
83 : 0 : int rand_int = 0;
84 [ # # ]: 0 : if( num_vtx <= 1 )
85 : : {
86 : : MSQ_PRINT( 1 )( "WARNING: Number of incident vertex is zero. Returning.\n" );
87 : 0 : return;
88 : : }
89 : :
90 [ # # ]: 0 : for( i = 0; i < num_vtx; ++i )
91 : : {
92 [ # # ][ # # ]: 0 : if( i != free_ind ) scale_factor += ( verts[i] - verts[free_ind] ).length();
[ # # ]
93 : : }
94 : 0 : scale_factor /= ( (double)num_vtx - 1.0 );
95 [ # # ]: 0 : Vector3D delta;
96 [ # # ]: 0 : for( j = 0; j < 3; ++j )
97 : : {
98 : 0 : rand_int = rand();
99 : : // number between 0 and 1000
100 : 0 : rand_int = rand_int % 1000;
101 : : // number between -1 and 1
102 : 0 : rand_double = ( ( (double)rand_int ) / 500.0 ) - 1.0;
103 [ # # ]: 0 : delta[j] = scale_factor * rand_double * percent;
104 : : }
105 [ # # ]: 0 : pd.move_vertex( delta, free_ind, err );
106 : :
107 : 0 : return;
108 : : }
109 : :
110 : 0 : void Randomize::optimize_vertex_positions( PatchData& pd, MsqError& err )
111 : : {
112 : : // cout << "- Executing Randomize::optimize_vertex_position()\n";
113 : :
114 : : // gets the array of coordinates for the patch and print it
115 : : // does the randomize smooth
116 [ # # ][ # # ]: 0 : MsqFreeVertexIndexIterator free_iter( pd, err );MSQ_ERRRTN( err );
[ # # ][ # # ]
[ # # ][ # # ]
117 [ # # ]: 0 : free_iter.reset();
118 [ # # ]: 0 : free_iter.next();
119 : : // find the free vertex.
120 [ # # ]: 0 : int m = free_iter.value();
121 [ # # ][ # # ]: 0 : randomize_vertex( pd, m, mPercent, err );MSQ_ERRRTN( err );
[ # # ][ # # ]
[ # # ][ # # ]
122 [ # # ][ # # ]: 0 : pd.snap_vertex_to_domain( m, err );MSQ_ERRRTN( err );
[ # # ][ # # ]
[ # # ][ # # ]
123 : : }
124 : :
125 : 0 : void Randomize::terminate_mesh_iteration( PatchData& /*pd*/, MsqError& /*err*/ )
126 : : {
127 : : // cout << "- Executing Randomize::iteration_complete()\n";
128 : 0 : }
129 : :
130 : 0 : void Randomize::cleanup()
131 : : {
132 : : // cout << "- Executing Randomize::iteration_end()\n";
133 [ + - ][ + - ]: 4 : }
|