MinSphere3x::MinSphere3x (int iQuantity, const Vector3x* akPoint, Sphere3x& rkMinimal, fixed fEpsilon) { m_fEpsilon = fEpsilon; m_aoUpdate[0] = 0; m_aoUpdate[1] = &MinSphere3x::UpdateSupport1; m_aoUpdate[2] = &MinSphere3x::UpdateSupport2; m_aoUpdate[3] = &MinSphere3x::UpdateSupport3; m_aoUpdate[4] = &MinSphere3x::UpdateSupport4; Support kSupp; fixed fDistDiff; if (iQuantity >= 1) { // create identity permutation (0,1,...,iQuantity-1) Vector3x** apkPerm = WG_NEW Vector3x*[iQuantity]; int i; for (i = 0; i < iQuantity; i++) { apkPerm[i] = (Vector3x*)&akPoint[i]; } // generate random permutation for (i = iQuantity-1; i > 0; i--) { int j = rand() % (i+1); if (j != i) { Vector3x* pSave = apkPerm[i]; apkPerm[i] = apkPerm[j]; apkPerm[j] = pSave; } } rkMinimal = ExactSphere1(*apkPerm[0]); kSupp.Quantity = 1; kSupp.Index[0] = 0; i = 1; while (i < iQuantity) { if (!kSupp.Contains(i,apkPerm,m_fEpsilon)) { if (!Contains(*apkPerm[i],rkMinimal,fDistDiff)) { UpdateFunction oUpdate = m_aoUpdate[kSupp.Quantity]; Sphere3x kSph =(this->*oUpdate)(i,apkPerm,kSupp); if (kSph.Radius > rkMinimal.Radius) { rkMinimal = kSph; i = 0; continue; } } } i++; } WG_DELETE[] apkPerm; }
MinSphere3<Real>::MinSphere3 ( int numPoints, const Vector3<Real>* points, Sphere3<Real>& minimal, Real epsilon ) : mEpsilon( epsilon ) { mUpdate[0] = 0; mUpdate[1] = &MinSphere3<Real>::UpdateSupport1; mUpdate[2] = &MinSphere3<Real>::UpdateSupport2; mUpdate[3] = &MinSphere3<Real>::UpdateSupport3; mUpdate[4] = &MinSphere3<Real>::UpdateSupport4; Support support; Real distDiff; if ( numPoints >= 1 ) { // Create identity permutation (0,1,...,numPoints-1). Vector3<Real>** permuted = new1<Vector3<Real>*>( numPoints ); int i; for ( i = 0; i < numPoints; ++i ) { permuted[i] = ( Vector3<Real>* )&points[i]; } // Generate random permutation. for ( i = numPoints - 1; i > 0; --i ) { int j = rand() % ( i + 1 ); if ( j != i ) { Vector3<Real>* save = permuted[i]; permuted[i] = permuted[j]; permuted[j] = save; } } minimal = ExactSphere1( *permuted[0] ); support.Quantity = 1; support.Index[0] = 0; i = 1; while ( i < numPoints ) { if ( !support.Contains( i, permuted, mEpsilon ) ) { if ( !Contains( *permuted[i], minimal, distDiff ) ) { UpdateFunction update = mUpdate[support.Quantity]; Sphere3<Real> sphere = ( this->*update )( i, permuted, support ); if ( sphere.Radius > minimal.Radius ) { minimal = sphere; i = 0; continue; } } } i++; } delete1( permuted ); } else { assertion( false, "Input must contain points\n" ); } minimal.Radius = Math<Real>::Sqrt( minimal.Radius ); }