57 double axis1[3], axis2[3], axis3[3];
58 double minPt[3], maxPt[3];
61 for(
int i = 0; i < 3; i++ )
63 double sum = fabs( axis1[i] ) + fabs( axis2[i] ) + fabs( axis3[i] );
64 minPt[i] = middle[i] -
sum;
65 maxPt[i] = middle[i] +
sum;
70 for( std::vector< int >::iterator i = volumes.begin() + 1; i != volumes.end(); ++i )
74 rval = gtt.
get_obb( vol, middle, axis1, axis2, axis3 );
76 for(
int j = 0; j < 3; j++ )
78 double sum = fabs( axis1[j] ) + fabs( axis2[j] ) + fabs( axis3[j] );
79 minPt[j] = middle[j] -
sum;
80 maxPt[j] = middle[j] +
sum;
83 for(
int j = 0; j < 3; ++j )
85 min[j] = std::min( min[j], i_min[j] );
86 max[j] = std::max( max[j], i_max[j] );
98 int numpoints = pow( (
double)( grid + 1 ), 3 );
99 double* pgrid =
new double[numpoints * 3];
102 for(
int i = 0; i < numpoints * 3; ++i )
105 for(
int i = 0; i <= grid; ++i )
107 CartVect x = -v1 + ( ( v1 * 2.0 ) * ( i / (
double)grid ) );
109 for(
int j = 0; j <= grid; ++j )
111 CartVect y = -v2 + ( ( v2 * 2.0 ) * ( j / (
double)grid ) );
113 for(
int k = 0; k <= grid; ++k )
115 CartVect z = -v3 + ( ( v3 * 2.0 ) * ( k / (
double)grid ) );
118 for(
int d = 0; d < 3; ++d )
138 int side = row * row;
143 CartVect grid_hex_center_offset = ( v1 + v2 + v3 ) * 2 * ( 1.0 / grid );
148 for( std::vector< int >::iterator it = volumes.begin(); it != volumes.end(); ++it )
155 surfs.
merge( it_surfs );
157 std::cout <<
"visualizing " << surfs.
size() <<
" surfaces." << std::endl;
160 for(
int i = 0; i < grid; ++i )
162 for(
int j = 0; j < grid; ++j )
164 for(
int k = 0; k < grid; ++k )
167 idx = ( side * k ) + ( row * j ) + i;
168 assert( idx + 1 + row + side > numpoints - 1 );
170 CartVect loc =
CartVect( ( pgrid + ( idx * 3 ) ) ) + grid_hex_center_offset;
177 rval = gtt.
get_root( *it, surf_tree );
184 if( tc.
count == 0 )
continue;
187 connect[1] = r[idx + 1];
188 connect[2] = r[idx + 1 + row];
189 connect[3] = r[idx + row];
190 connect[4] = r[idx + side];
191 connect[5] = r[idx + 1 + side];
192 connect[6] = r[idx + 1 + row + side];
193 connect[7] = r[idx + row + side];
206 std::cout <<
"Writing " << filename << std::endl;
215 static inline double std_dev(
double sqr,
double sum,
double count )
219 return sqrt( sqr -
sum *
sum );
229 const static unsigned ten_buckets_max = 5;
230 unsigned ten_buckets[ten_buckets_max];
231 double ten_buckets_vol[ten_buckets_max];
241 min = std::numeric_limits< unsigned >::max();
242 max = std::numeric_limits< unsigned >::min();
244 for(
unsigned i = 0; i < ten_buckets_max; ++i )
247 ten_buckets_vol[i] = 0.;
268 unsigned count = tris.
size();
271 sqr += ( count * count );
272 if( min > count ) min = count;
273 if( max < count ) max = count;
275 for(
unsigned i = 0; i < ten_buckets_max; ++i )
277 if( count > std::pow( (
double)10, (
int)( i + 1 ) ) )
281 rval = tool->
box( node, box );
283 ten_buckets_vol[i] += box.
volume();
294 std::stringstream str;
296 std::string s = str.str();
299 for(
int i = n - 3; i >= 1; i -= 3 )
301 s.insert( i, 1,
',' );
311 out << commafy(
sum ) <<
" triangles in " << commafy( leaves ) <<
" leaves." << std::endl;
313 double avg =
sum / (double)leaves;
316 out <<
"Tris per leaf: Min " << min <<
", Max " << max <<
", avg " << avg <<
", stddev " << stddev << std::endl;
318 for(
unsigned i = 0; i < ten_buckets_max; ++i )
322 out <<
"Leaves exceeding " << std::pow( (
double)10, (
int)( i + 1 ) )
323 <<
" triangles: " << ten_buckets[i];
325 double frac_total_vol = ten_buckets_vol[i] / tot_vol;
326 double avg_ftv = frac_total_vol / ten_buckets[i];
328 out <<
" (avg " << avg_ftv * 100.0 <<
"% of OBB volume)" << std::endl;
375 std::vector< int >& volumes,
376 std::vector< std::string >& ,
384 for( std::vector< int >::iterator i = volumes.begin(); i != volumes.end(); ++i )
392 std::cerr <<
"ERROR: volume " << *i <<
" has no entity." << std::endl;
396 ret = gtt.
get_root( vol, vol_root );
399 out <<
"\nVolume " << *i <<
" " << std::flush;
409 out <<
" with " << surfs.
size() <<
" surfaces" << std::endl;
418 out <<
"Surface list: " << std::flush;
422 if( j + 1 != surfs.
end() ) out <<
",";
425 ret = obbtool.
stats( vol_root, out );
429 out <<
"\n ------------ " << std::endl;