13 #include ApproxMVBB_TypeDefs_INCLUDE_FILE 29 double const**theList,
35 using namespace Diameter;
45 double const**theList,
52 using namespace Diameter;
59 int newEstimateIsSmallerThanCurrentEstimate;
62 TypeListOfSegments theDoubleNormals;
80 int suspicion_of_convex_hull = 0;
83 double epsilon = _epsilon_;
84 double bound, upperBound = 0.0;
86 double upperSquareDiameter = 0.0;
88 theDoubleNormals.n = 0;
89 theDoubleNormals.nalloc = 0;
90 theDoubleNormals.seg = NULL;
96 if ( first < 0 || last < 0 )
return( -1.0 );
115 newEstimateIsSmallerThanCurrentEstimate = 0;
134 if ( theDoubleNormals.nalloc > 0 ) free( theDoubleNormals.seg );
144 _reduction_mode_in_iterative_ );
145 if ( _reduction_mode_in_iterative_ == 1 )
147 if ( verboseWhenReducing )
151 suspicion_of_convex_hull = 1;
152 _reduction_mode_of_diameter_ = 0;
153 _reduction_mode_of_dbleNorm_ = 0;
163 if ( theDoubleNormals.nalloc > 0 ) free( theDoubleNormals.seg );
197 if ( theDoubleNormals.nalloc > 0 ) free( theDoubleNormals.seg );
205 newEstimateIsSmallerThanCurrentEstimate = 1;
224 if ( theDoubleNormals.nalloc > 0 ) free( theDoubleNormals.seg );
228 for ( n = theDoubleNormals.n-2; n >= 0 ; n-- )
232 theDoubleNormals.seg[ n ] = theSeg;
236 if ( theSeg.squareDiameter <= theDoubleNormals.seg[ n ].squareDiameter &&
237 theSeg.squareDiameter > theDoubleNormals.seg[ n-1 ].squareDiameter )
239 theDoubleNormals.seg[ n ] = theSeg;
244 theDoubleNormals.seg[ n ] = theDoubleNormals.seg[ n-1 ];
252 while ( newEstimateIsSmallerThanCurrentEstimate == 0 );
259 if ( _reduction_mode_in_iterative_ > 0 && _reduction_mode_of_diameter_ == 1 )
260 _reduction_mode_of_diameter_ = 0;
264 theList, f, &newlast, dim,
265 _reduction_mode_of_diameter_ );
266 if ( _reduction_mode_of_diameter_ == 1 ||
267 _reduction_mode_of_diameter_ == 2 )
269 if ( verboseWhenReducing )
273 suspicion_of_convex_hull = 1;
274 _reduction_mode_of_dbleNorm_ = 0;
289 if ( theDoubleNormals.nalloc > 0 ) free( theDoubleNormals.seg );
296 upperSquareDiameter = theDiam->
squareDiameter * (1.0 + epsilon) * (1.0 + epsilon);
300 theList, f, &index2, dim, 0 );
306 if ( theDoubleNormals.nalloc > 0 ) free( theDoubleNormals.seg );
312 for ( k=f+1; k<=index2; k++ )
317 if ( upperBound < bound ) upperBound = bound;
319 return( upperBound );
331 if ( _tight_bounds_ )
334 if ( index1 < index2 )
336 for ( k=index1+1; k<=index2; k++ )
341 if ( upperBound < bound ) upperBound = bound;
347 upperBound = upperSquareDiameter;
355 for ( n = theDoubleNormals.n-1; n >= 0; n -- )
384 if ( tryToReduceQ && theDoubleNormals.n > 1 )
387 for ( k = 0; k < theDoubleNormals.n; k ++ )
388 theDoubleNormals.seg[k].reduction_mode = _reduction_mode_of_dbleNorm_;
397 fdn = theDoubleNormals.n-2;
404 ldn = theDoubleNormals.n-2;
409 for ( n = fdn; n != (ldn+idn) && index >= f ; n += idn )
423 theList, f, &index, dim, 0 );
424 if ( i >= index )
continue;
438 if ( _tight_bounds_ )
440 for ( k = i+1; k <= index; k++ )
442 bound = 4.0 *
_ScalarProduct( theList[k], theDoubleNormals.seg[ n ].extremity1,
443 theList[k], theDoubleNormals.seg[ n ].extremity2, dim ) +
444 theDoubleNormals.seg[ n ].squareDiameter;
445 if ( upperBound < bound ) upperBound = bound;
460 if ( _tight_bounds_ )
464 theList, index+1, &newlast, dim,
465 theDoubleNormals.seg[ n ].reduction_mode,
467 if ( upperBound < bound ) upperBound = bound;
473 theList, index+1, &newlast, dim,
474 theDoubleNormals.seg[ n ].reduction_mode );
477 if ( theDoubleNormals.seg[ n ].reduction_mode == 1 ||
478 theDoubleNormals.seg[ n ].reduction_mode == 2 )
481 if ( verboseWhenReducing )
485 suspicion_of_convex_hull = 1;
486 for ( k = 0; k < theDoubleNormals.n; k ++ )
487 theDoubleNormals.seg[k].reduction_mode = 0;
506 theSeg.extremity1 = (
double*)NULL;
507 theSeg.extremity2 = (
double*)NULL;
508 theSeg.squareDiameter = 0.0;
524 if ( upperBound < newEstimate ) upperBound = newEstimate;
525 if ( upperSquareDiameter < newEstimate ) upperSquareDiameter = newEstimate;
537 theDoubleNormals.seg[ n ] = theSeg;
550 if ( theDoubleNormals.nalloc > 0 ) free( theDoubleNormals.seg );
560 for ( i=f; i<=index; i++ )
561 for ( j=i+1; j<=l; j++ )
569 if ( newEstimate > upperBound ) upperBound = newEstimate;
572 return( upperBound );
578 for ( i=f; i<=index; i++ )
579 for ( j=i+1; j<=l; j++ )
587 if ( newEstimate > upperBound ) upperBound = newEstimate;
590 return( upperBound );
594 for ( i=f; i<=index; i++ )
595 for ( j=i+1; j<=l; j++ )
603 if ( newEstimate > upperBound ) upperBound = newEstimate;
606 return( upperBound );
int _GetReductionModeOfDiameter()
APPROXMVBB_EXPORT int _FarthestPointFromSphere(TypeSegment *theSeg, double const **theList, const int first, int *last, const int dim, const int _reduction_mode_)
These are some container definitions.
double const * extremity2
double estimateDiameter(Diameter::TypeSegment *theDiam, double const **theList, const int first, const int last, const int dim, double epsilon)
APPROXMVBB_EXPORT double _MaximalSegmentInOneList(TypeSegment *theSeg, const int index, double const **theList, int *first, int *last, const int dim)
APPROXMVBB_EXPORT double _SquareDistance3D(double const *a, double const *b)
int getRandomInt(unsigned int min, unsigned int max)
APPROXMVBB_EXPORT double _QuadraticDiameterInTwoLists(TypeSegment *theDiam, int *index1, int *index2, double const **theList1, const int first1, const int last1, double const **theList2, const int first2, const int last2, const int dim)
int _GetReductionModeOfDbleNorm()
APPROXMVBB_EXPORT int _AddSegmentToList(TypeSegment *s, TypeListOfSegments *list)
APPROXMVBB_EXPORT int _LastPointOutsideSphereWithDiameter(TypeSegment *theSeg, double constsquareDiameter, double const **theList, const int first, int *last, const int dim, const int _reduction_mode_)
int _GetReductionModeInIterative()
APPROXMVBB_EXPORT double _ScalarProduct(double const *a, double const *b, double const *c, double const *d, const int dim)
int _reduction_mode_in_iterative_
int _reduction_mode_of_diameter_
APPROXMVBB_EXPORT double _SquareDistance2D(double const *a, double const *b)
double estimateDiameterInOneList(Diameter::TypeSegment *theDiam, double const **theList, const int first, const int last, const int dim, double _epsilon_)
int _GetVerboseWhenReducing()
void _SetReductionModeOfDiameter(int m)
double const * extremity1
void _SetReductionModeOfDbleNorm(int m)
int _reduction_mode_of_dbleNorm_
void _SetReductionModeInIterative(int m)
void _DoNotTryToReduceQ()
APPROXMVBB_EXPORT int _LastPointOutsideSphereAndBoundWithDiameter(TypeSegment *theSeg, double constsquareDiameter, double const **theList, const int first, int *last, const int dim, const int _reduction_mode_, double *bound)
APPROXMVBB_EXPORT double _SquareDistance(double const *a, double const *b, const int dim)