MOAB: Mesh Oriented datABase  (version 5.4.1)
Randomize.cpp File Reference

The Randomize Class is the concrete class that randomizes the vertex positions. More...

#include "Randomize.hpp"
#include "MsqFreeVertexIndexIterator.hpp"
#include "MsqDebug.hpp"
#include <cmath> Include dependency graph for Randomize.cpp:

Go to the source code of this file.

## Functions

static void randomize_vertex (PatchData &pd, size_t free_ind, double percent, MsqError &err)

## Detailed Description

The Randomize Class is the concrete class that randomizes the vertex positions.

Date:
2002-10-27

Definition in file Randomize.cpp.

## Function Documentation

 static void randomize_vertex ( PatchData & pd, size_t free_ind, double percent, MsqError & err )  [inline, static]

Function calculates a scale factor for the patch, then moves the incident vertex randomly in each of the three coordinate directions (relative to the scale factor multiplied by mPercent).

Definition at line 72 of file Randomize.cpp.

Referenced by MBMesquite::Randomize::optimize_vertex_positions().

{
size_t i;
short j;
const MsqVertex* verts = pd.get_vertex_array( err );MSQ_ERRRTN( err );
const size_t num_vtx = pd.num_nodes();
// a scale w.r.t. the patch size
double scale_factor = 0.0;
// a "random" number between -1 and 1
double rand_double = 0.0;
// a "random" int
int rand_int = 0;
if( num_vtx <= 1 )
{
MSQ_PRINT( 1 )( "WARNING: Number of incident vertex is zero.  Returning.\n" );
return;
}

for( i = 0; i < num_vtx; ++i )
{
if( i != free_ind ) scale_factor += ( verts[i] - verts[free_ind] ).length();
}
scale_factor /= ( (double)num_vtx - 1.0 );
Vector3D delta;
for( j = 0; j < 3; ++j )
{
rand_int = rand();
// number between 0 and 1000
rand_int = rand_int % 1000;
// number between -1 and 1
rand_double = ( ( (double)rand_int ) / 500.0 ) - 1.0;
delta[j]    = scale_factor * rand_double * percent;
}
pd.move_vertex( delta, free_ind, err );

return;
}