Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ add WildMagic algorithm to compute minimum volume oriented box
- Loading branch information
Showing
22 changed files
with
5,428 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Geometric Tools, LLC | ||
// Copyright (c) 1998-2010 | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// http://www.boost.org/LICENSE_1_0.txt | ||
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt | ||
// | ||
// File Version: 4.10.0 (2009/11/18) | ||
|
||
#include "Wm4FoundationPCH.h" | ||
#include "Wm4ApprGaussPointsFit2.h" | ||
#include "Wm4Eigen.h" | ||
|
||
namespace Wm4 | ||
{ | ||
//---------------------------------------------------------------------------- | ||
template <class Real> | ||
Box2<Real> GaussPointsFit2 (int iQuantity, const Vector2<Real>* akPoint) | ||
{ | ||
Box2<Real> kBox(Vector2<Real>::ZERO,Vector2<Real>::UNIT_X, | ||
Vector2<Real>::UNIT_Y,(Real)1.0,(Real)1.0); | ||
|
||
// compute the mean of the points | ||
kBox.Center = akPoint[0]; | ||
int i; | ||
for (i = 1; i < iQuantity; i++) | ||
{ | ||
kBox.Center += akPoint[i]; | ||
} | ||
Real fInvQuantity = ((Real)1.0)/iQuantity; | ||
kBox.Center *= fInvQuantity; | ||
|
||
// compute the covariance matrix of the points | ||
Real fSumXX = (Real)0.0, fSumXY = (Real)0.0, fSumYY = (Real)0.0; | ||
for (i = 0; i < iQuantity; i++) | ||
{ | ||
Vector2<Real> kDiff = akPoint[i] - kBox.Center; | ||
fSumXX += kDiff.X()*kDiff.X(); | ||
fSumXY += kDiff.X()*kDiff.Y(); | ||
fSumYY += kDiff.Y()*kDiff.Y(); | ||
} | ||
|
||
fSumXX *= fInvQuantity; | ||
fSumXY *= fInvQuantity; | ||
fSumYY *= fInvQuantity; | ||
|
||
// setup the eigensolver | ||
Eigen<Real> kES(2); | ||
kES(0,0) = fSumXX; | ||
kES(0,1) = fSumXY; | ||
kES(1,0) = fSumXY; | ||
kES(1,1) = fSumYY; | ||
kES.IncrSortEigenStuff2(); | ||
|
||
for (i = 0; i < 2; i++) | ||
{ | ||
kBox.Extent[i] = kES.GetEigenvalue(i); | ||
kES.GetEigenvector(i,kBox.Axis[i]); | ||
} | ||
|
||
return kBox; | ||
} | ||
//---------------------------------------------------------------------------- | ||
|
||
//---------------------------------------------------------------------------- | ||
// explicit instantiation | ||
//---------------------------------------------------------------------------- | ||
template WM4_FOUNDATION_ITEM | ||
Box2<float> GaussPointsFit2<float> (int, const Vector2<float>*); | ||
|
||
template WM4_FOUNDATION_ITEM | ||
Box2<double> GaussPointsFit2<double> (int, const Vector2<double>*); | ||
//---------------------------------------------------------------------------- | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Geometric Tools, LLC | ||
// Copyright (c) 1998-2010 | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// http://www.boost.org/LICENSE_1_0.txt | ||
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt | ||
// | ||
// File Version: 4.10.0 (2009/11/18) | ||
|
||
#ifndef WM4APPRGAUSSPOINTSFIT2_H | ||
#define WM4APPRGAUSSPOINTSFIT2_H | ||
|
||
#include "Wm4FoundationLIB.h" | ||
#include "Wm4Box2.h" | ||
|
||
namespace Wm4 | ||
{ | ||
|
||
// Fit points with a Gaussian distribution. The center is the mean of the | ||
// points, the axes are the eigenvectors of the covariance matrix, and the | ||
// extents are the eigenvalues of the covariance matrix and are returned in | ||
// increasing order. The quantites are stored in a Box2<Real> just to have a | ||
// single container. | ||
template <class Real> WM4_FOUNDATION_ITEM | ||
Box2<Real> GaussPointsFit2 (int iQuantity, const Vector2<Real>* akPoint); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Geometric Tools, LLC | ||
// Copyright (c) 1998-2010 | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// http://www.boost.org/LICENSE_1_0.txt | ||
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt | ||
// | ||
// File Version: 4.10.0 (2009/11/18) | ||
|
||
#include "Wm4FoundationPCH.h" | ||
#include "Wm4ApprGaussPointsFit3.h" | ||
#include "Wm4Eigen.h" | ||
|
||
namespace Wm4 | ||
{ | ||
//---------------------------------------------------------------------------- | ||
template <class Real> | ||
Box3<Real> GaussPointsFit3 (int iQuantity, const Vector3<Real>* akPoint) | ||
{ | ||
Box3<Real> kBox(Vector3<Real>::ZERO,Vector3<Real>::UNIT_X, | ||
Vector3<Real>::UNIT_Y,Vector3<Real>::UNIT_Z,(Real)1.0,(Real)1.0, | ||
(Real)1.0); | ||
|
||
// compute the mean of the points | ||
kBox.Center = akPoint[0]; | ||
int i; | ||
for (i = 1; i < iQuantity; i++) | ||
{ | ||
kBox.Center += akPoint[i]; | ||
} | ||
Real fInvQuantity = ((Real)1.0)/iQuantity; | ||
kBox.Center *= fInvQuantity; | ||
|
||
// compute the covariance matrix of the points | ||
Real fSumXX = (Real)0.0, fSumXY = (Real)0.0, fSumXZ = (Real)0.0; | ||
Real fSumYY = (Real)0.0, fSumYZ = (Real)0.0, fSumZZ = (Real)0.0; | ||
for (i = 0; i < iQuantity; i++) | ||
{ | ||
Vector3<Real> kDiff = akPoint[i] - kBox.Center; | ||
fSumXX += kDiff.X()*kDiff.X(); | ||
fSumXY += kDiff.X()*kDiff.Y(); | ||
fSumXZ += kDiff.X()*kDiff.Z(); | ||
fSumYY += kDiff.Y()*kDiff.Y(); | ||
fSumYZ += kDiff.Y()*kDiff.Z(); | ||
fSumZZ += kDiff.Z()*kDiff.Z(); | ||
} | ||
|
||
fSumXX *= fInvQuantity; | ||
fSumXY *= fInvQuantity; | ||
fSumXZ *= fInvQuantity; | ||
fSumYY *= fInvQuantity; | ||
fSumYZ *= fInvQuantity; | ||
fSumZZ *= fInvQuantity; | ||
|
||
// setup the eigensolver | ||
Eigen<Real> kES(3); | ||
kES(0,0) = fSumXX; | ||
kES(0,1) = fSumXY; | ||
kES(0,2) = fSumXZ; | ||
kES(1,0) = fSumXY; | ||
kES(1,1) = fSumYY; | ||
kES(1,2) = fSumYZ; | ||
kES(2,0) = fSumXZ; | ||
kES(2,1) = fSumYZ; | ||
kES(2,2) = fSumZZ; | ||
kES.IncrSortEigenStuff3(); | ||
|
||
for (i = 0; i < 3; i++) | ||
{ | ||
kBox.Extent[i] = kES.GetEigenvalue(i); | ||
kES.GetEigenvector(i,kBox.Axis[i]); | ||
} | ||
|
||
return kBox; | ||
} | ||
//---------------------------------------------------------------------------- | ||
|
||
//---------------------------------------------------------------------------- | ||
// explicit instantiation | ||
//---------------------------------------------------------------------------- | ||
template WM4_FOUNDATION_ITEM | ||
Box3<float> GaussPointsFit3<float> (int, const Vector3<float>*); | ||
|
||
template WM4_FOUNDATION_ITEM | ||
Box3<double> GaussPointsFit3<double> (int, const Vector3<double>*); | ||
//---------------------------------------------------------------------------- | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Geometric Tools, LLC | ||
// Copyright (c) 1998-2010 | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// http://www.boost.org/LICENSE_1_0.txt | ||
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt | ||
// | ||
// File Version: 4.10.0 (2009/11/18) | ||
|
||
#ifndef WM4APPRGAUSSPOINTSFIT3_H | ||
#define WM4APPRGAUSSPOINTSFIT3_H | ||
|
||
#include "Wm4FoundationLIB.h" | ||
#include "Wm4Box3.h" | ||
|
||
namespace Wm4 | ||
{ | ||
|
||
// Fit points with a Gaussian distribution. The center is the mean of the | ||
// points, the axes are the eigenvectors of the covariance matrix, and the | ||
// extents are the eigenvalues of the covariance matrix and are returned in | ||
// increasing order. The quantites are stored in a Box3<Real> just to have a | ||
// single container. | ||
template <class Real> WM4_FOUNDATION_ITEM | ||
Box3<Real> GaussPointsFit3 (int iQuantity, const Vector3<Real>* akPoint); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Geometric Tools, LLC | ||
// Copyright (c) 1998-2010 | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// http://www.boost.org/LICENSE_1_0.txt | ||
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt | ||
// | ||
// File Version: 4.10.0 (2009/11/18) | ||
|
||
#ifndef WM4BOX2_H | ||
#define WM4BOX2_H | ||
|
||
#include "Wm4FoundationLIB.h" | ||
#include "Wm4Vector2.h" | ||
|
||
namespace Wm4 | ||
{ | ||
|
||
template <class Real> | ||
class Box2 | ||
{ | ||
public: | ||
// A box has center C, axis directions U[0] and U[1] (both unit-length | ||
// vectors), and extents e[0] and e[1] (both nonnegative numbers). A | ||
// point X = C+y[0]*U[0]+y[1]*U[1] is inside or on the box whenever | ||
// |y[i]| <= e[i] for all i. | ||
|
||
// construction | ||
Box2 (); // uninitialized | ||
Box2 (const Vector2<Real>& rkCenter, const Vector2<Real>* akAxis, | ||
const Real* afExtent); | ||
Box2 (const Vector2<Real>& rkCenter, const Vector2<Real>& rkAxis0, | ||
const Vector2<Real>& rkAxis1, Real fExtent0, Real fExtent1); | ||
|
||
void ComputeVertices (Vector2<Real> akVertex[4]) const; | ||
|
||
Vector2<Real> Center; | ||
Vector2<Real> Axis[2]; // must be an orthonormal set of vectors | ||
Real Extent[2]; // must be nonnegative | ||
}; | ||
|
||
#include "Wm4Box2.inl" | ||
|
||
typedef Box2<float> Box2f; | ||
typedef Box2<double> Box2d; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Geometric Tools, LLC | ||
// Copyright (c) 1998-2010 | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// http://www.boost.org/LICENSE_1_0.txt | ||
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt | ||
// | ||
// File Version: 4.10.0 (2009/11/18) | ||
|
||
//---------------------------------------------------------------------------- | ||
template <class Real> | ||
Box2<Real>::Box2 () | ||
{ | ||
// uninitialized | ||
} | ||
//---------------------------------------------------------------------------- | ||
template <class Real> | ||
Box2<Real>::Box2 (const Vector2<Real>& rkCenter, const Vector2<Real>* akAxis, | ||
const Real* afExtent) | ||
: | ||
Center(rkCenter) | ||
{ | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
Axis[i] = akAxis[i]; | ||
Extent[i] = afExtent[i]; | ||
} | ||
} | ||
//---------------------------------------------------------------------------- | ||
template <class Real> | ||
Box2<Real>::Box2 (const Vector2<Real>& rkCenter, const Vector2<Real>& rkAxis0, | ||
const Vector2<Real>& rkAxis1, Real fExtent0, Real fExtent1) | ||
: | ||
Center(rkCenter) | ||
{ | ||
Axis[0] = rkAxis0; | ||
Axis[1] = rkAxis1; | ||
Extent[0] = fExtent0; | ||
Extent[1] = fExtent1; | ||
} | ||
//---------------------------------------------------------------------------- | ||
template <class Real> | ||
void Box2<Real>::ComputeVertices (Vector2<Real> akVertex[4]) const | ||
{ | ||
Vector2<Real> akEAxis[2] = | ||
{ | ||
Axis[0]*Extent[0], | ||
Axis[1]*Extent[1] | ||
}; | ||
|
||
akVertex[0] = Center - akEAxis[0] - akEAxis[1]; | ||
akVertex[1] = Center + akEAxis[0] - akEAxis[1]; | ||
akVertex[2] = Center + akEAxis[0] + akEAxis[1]; | ||
akVertex[3] = Center - akEAxis[0] + akEAxis[1]; | ||
} | ||
//---------------------------------------------------------------------------- |
Oops, something went wrong.