48 #if MB_ORIENTED_BOX_UNIT_VECTORS
52 #if MB_ORIENTED_BOX_UNIT_VECTORS
56 #if MB_ORIENTED_BOX_UNIT_VECTORS
77 #if MB_ORIENTED_BOX_UNIT_VECTORS
78 double t = ( m % ( p - b ) );
80 double t = ( m % ( p - b ) ) / ( m % m );
88 CartVect len( ax1_len, ax2_len, ax3_len );
94 std::swap( len[0], len[2] );
98 else if( len[1] < len[0] )
100 std::swap( len[0], len[1] );
103 if( len[1] > len[2] )
105 std::swap( len[1], len[2] );
109 #if MB_ORIENTED_BOX_UNIT_VECTORS
116 #if MB_ORIENTED_BOX_OUTER_RADIUS
124 axes =
Matrix3( axes_in[0], axes_in[1], axes_in[2],
false );
138 #if MB_ORIENTED_BOX_OUTER_RADIUS
139 const int rad_size = 1;
141 const int rad_size = 0;
143 #if MB_ORIENTED_BOX_UNIT_VECTORS
144 const int SIZE = rad_size + 15;
146 const int SIZE = rad_size + 12;
148 assert(
sizeof(
OrientedBox ) == SIZE *
sizeof(
double ) );
171 CartVect min( std::numeric_limits< double >::max() ), max( -std::numeric_limits< double >::max() );
177 for(
int d = 0; d < 3; ++d )
180 if( t < min[d] ) min[d] = t;
181 if( t > max[d] ) max[d] = t;
191 const CartVect mid = 0.5 * ( min + max );
195 CartVect range = 0.5 * ( max - min );
196 if( range[2] < range[1] )
198 if( range[2] < range[0] )
200 std::swap( range[0], range[2] );
204 else if( range[1] < range[0] )
206 std::swap( range[0], range[1] );
209 if( range[1] > range[2] )
211 std::swap( range[1], range[2] );
216 #if MB_ORIENTED_BOX_UNIT_VECTORS
224 #if MB_ORIENTED_BOX_OUTER_RADIUS
287 for(
int j = 2; j < conn_len; ++j )
289 EntityHandle vertices[3] = { conn[0], conn[j - 1], conn[j] };
291 rval = instance->
get_coords( vertices, 3, coords[0].array() );
295 const CartVect edge0 = coords[1] - coords[0];
296 const CartVect edge1 = coords[2] - coords[0];
297 const CartVect centroid = ( coords[0] + coords[1] + coords[2] ) / 3;
298 const double tri_area2 = ( edge0 * edge1 ).
length();
299 result.
area += tri_area2;
300 result.
center += tri_area2 * centroid;
330 const Range& vertices )
332 if( data.
area <= 0.0 )
358 #if MB_ORIENTED_BOX_UNIT_VECTORS
359 return fabs( from_center %
axes.
col( 0 ) ) -
length[0] <= tol &&
363 for(
int i = 0; i < 3; ++i )
375 unsigned data_length,
376 const Range& vertices )
380 for(
const CovarienceData*
const end = data + data_length; data != end; ++data )
445 const double normal_par_dir,
446 const double half_extent,
447 const double* nonneg_ray_len,
448 const double* neg_ray_len )
451 const double extent_pos_diff = half_extent - normal_par_pos;
456 assert( 0 <= *nonneg_ray_len );
457 if( normal_par_dir > 0 )
459 if( *nonneg_ray_len * normal_par_dir >= extent_pos_diff && extent_pos_diff >= 0 )
return true;
461 else if( normal_par_dir < 0 )
463 if( *nonneg_ray_len * normal_par_dir <= extent_pos_diff && extent_pos_diff <= 0 )
return true;
468 if( normal_par_dir > 0 )
470 if( extent_pos_diff >= 0 )
return true;
472 else if( normal_par_dir < 0 )
474 if( extent_pos_diff <= 0 )
return true;
481 assert( 0 >= *neg_ray_len );
482 if( normal_par_dir > 0 )
484 if( *neg_ray_len * normal_par_dir <= extent_pos_diff && extent_pos_diff < 0 )
return true;
486 else if( normal_par_dir < 0 )
488 if( *neg_ray_len * normal_par_dir >= extent_pos_diff && extent_pos_diff > 0 )
return true;
501 const double* nonneg_ray_len,
502 const double* neg_ray_len )
const
506 const double dist_s = cx % ray_direction;
507 const double dist_sq = cx % cx - ( dist_s * dist_s );
514 if( dist_sq > max_diagsq )
return false;
521 assert( 0 <= *nonneg_ray_len );
525 assert( 0 >= *neg_ray_len );
526 max_len = std::max( *nonneg_ray_len, -( *neg_ray_len ) );
530 max_len = *nonneg_ray_len;
532 const double temp = fabs( dist_s ) - max_len;
533 if( 0.0 < temp && temp * temp > max_diagsq )
return false;
544 if( *nonneg_ray_len > dist_s )
return true;
554 if( neg_ray_len && *neg_ray_len < dist_s )
return true;
563 CartVect par_dir = B * ray_direction;
568 const double half_x =
length[0] + reps;
569 const double half_y =
length[1] + reps;
570 const double half_z =
length[2] + reps;
573 if( ( par_pos[0] > half_x && par_dir[0] >= 0 ) || ( par_pos[0] < -half_x && par_dir[0] <= 0 ) )
return false;
575 if( ( par_pos[1] > half_y && par_dir[1] >= 0 ) || ( par_pos[1] < -half_y && par_dir[1] <= 0 ) )
return false;
577 if( ( par_pos[2] > half_z && par_dir[2] >= 0 ) || ( par_pos[2] < -half_z && par_dir[2] <= 0 ) )
return false;
581 if( par_pos[0] <= half_x && par_pos[0] >= -half_x && par_pos[1] <= half_y && par_pos[1] >= -half_y &&
582 par_pos[2] <= half_z && par_pos[2] >= -half_z )
586 if( fabs( par_dir[0] * ( half_z - par_pos[2] ) + par_dir[2] * par_pos[0] ) <=
587 fabs( par_dir[2] * half_x ) &&
588 fabs( par_dir[1] * ( half_z - par_pos[2] ) + par_dir[2] * par_pos[1] ) <=
589 fabs( par_dir[2] * half_y ) &&
590 check_ray_limits( par_pos[2], par_dir[2], half_z, nonneg_ray_len, neg_ray_len ) )
592 if( fabs( par_dir[0] * ( -half_z - par_pos[2] ) + par_dir[2] * par_pos[0] ) <= fabs( par_dir[2] * half_x ) &&
593 fabs( par_dir[1] * ( -half_z - par_pos[2] ) + par_dir[2] * par_pos[1] ) <= fabs( par_dir[2] * half_y ) &&
594 check_ray_limits( par_pos[2], par_dir[2], -half_z, nonneg_ray_len, neg_ray_len ) )
598 if( fabs( par_dir[0] * ( half_y - par_pos[1] ) + par_dir[1] * par_pos[0] ) <= fabs( par_dir[1] * half_x ) &&
599 fabs( par_dir[2] * ( half_y - par_pos[1] ) + par_dir[1] * par_pos[2] ) <= fabs( par_dir[1] * half_z ) &&
600 check_ray_limits( par_pos[1], par_dir[1], half_y, nonneg_ray_len, neg_ray_len ) )
602 if( fabs( par_dir[0] * ( -half_y - par_pos[1] ) + par_dir[1] * par_pos[0] ) <= fabs( par_dir[1] * half_x ) &&
603 fabs( par_dir[2] * ( -half_y - par_pos[1] ) + par_dir[1] * par_pos[2] ) <= fabs( par_dir[1] * half_z ) &&
604 check_ray_limits( par_pos[1], par_dir[1], -half_y, nonneg_ray_len, neg_ray_len ) )
608 if( fabs( par_dir[1] * ( half_x - par_pos[0] ) + par_dir[0] * par_pos[1] ) <= fabs( par_dir[0] * half_y ) &&
609 fabs( par_dir[2] * ( half_x - par_pos[0] ) + par_dir[0] * par_pos[2] ) <= fabs( par_dir[0] * half_z ) &&
610 check_ray_limits( par_pos[0], par_dir[0], half_x, nonneg_ray_len, neg_ray_len ) )
612 if( fabs( par_dir[1] * ( -half_x - par_pos[0] ) + par_dir[0] * par_pos[1] ) <= fabs( par_dir[0] * half_y ) &&
613 fabs( par_dir[2] * ( -half_x - par_pos[0] ) + par_dir[0] * par_pos[2] ) <= fabs( par_dir[0] * half_z ) &&
614 check_ray_limits( par_pos[0], par_dir[0], -half_x, nonneg_ray_len, neg_ray_len ) )
623 int signs[8][3] = { { -1, -1, -1 }, { 1, -1, -1 }, { 1, 1, -1 }, { -1, 1, -1 },
624 { -1, -1, 1 }, { 1, -1, 1 }, { 1, 1, 1 }, { -1, 1, 1 } };
626 std::vector< EntityHandle > vertices;
627 for(
int i = 0; i < 8; ++i )
630 for(
int j = 0; j < 3; ++j )
632 #if MB_ORIENTED_BOX_UNIT_VECTORS
635 coords += signs[i][j] *
axes.
col( j );
645 vertices.push_back( handle );
663 #if MB_ORIENTED_BOX_UNIT_VECTORS
666 for(
int i = 0; i < 3; ++i )
668 if( local[i] < -
length[i] )
670 else if( local[i] >
length[i] )
678 for(
int i = 0; i < 3; ++i )
680 if( local[i] < -1.0 )
682 else if( local[i] > 1.0 )