1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
// Geometric Tools, LLC
// Copyright (c) 1998-2014
// 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: 5.0.1 (2010/10/01)
#include "Wm5MathematicsPCH.h"
#include "Wm5ConvexHull.h"
#include "Wm5Memory.h"
namespace Wm5
{
//----------------------------------------------------------------------------
template <typename Real>
ConvexHull<Real>::ConvexHull (int numVertices, Real epsilon, bool owner,
Query::Type queryType)
:
mQueryType(queryType),
mNumVertices(numVertices),
mDimension(0),
mNumSimplices(0),
mIndices(0),
mEpsilon(epsilon),
mOwner(owner)
{
assertion(mNumVertices > 0 && mEpsilon >= (Real)0, "Invalid inputs\n");
}
//----------------------------------------------------------------------------
template <typename Real>
ConvexHull<Real>::~ConvexHull ()
{
delete1(mIndices);
}
//----------------------------------------------------------------------------
template <typename Real>
int ConvexHull<Real>::GetQueryType () const
{
return mQueryType;
}
//----------------------------------------------------------------------------
template <typename Real>
int ConvexHull<Real>::GetNumVertices () const
{
return mNumVertices;
}
//----------------------------------------------------------------------------
template <typename Real>
Real ConvexHull<Real>::GetEpsilon () const
{
return mEpsilon;
}
//----------------------------------------------------------------------------
template <typename Real>
bool ConvexHull<Real>::GetOwner () const
{
return mOwner;
}
//----------------------------------------------------------------------------
template <typename Real>
int ConvexHull<Real>::GetDimension () const
{
return mDimension;
}
//----------------------------------------------------------------------------
template <typename Real>
int ConvexHull<Real>::GetNumSimplices () const
{
return mNumSimplices;
}
//----------------------------------------------------------------------------
template <typename Real>
const int* ConvexHull<Real>::GetIndices () const
{
return mIndices;
}
//----------------------------------------------------------------------------
template <typename Real>
bool ConvexHull<Real>::Load (FileIO& inFile)
{
delete1(mIndices);
// Fixed-size members.
int type;
inFile.Read(sizeof(int), &type);
mQueryType = (Query::Type)type;
inFile.Read(sizeof(int), &mNumVertices);
inFile.Read(sizeof(int), &mDimension);
inFile.Read(sizeof(int), &mNumSimplices);
inFile.Read(sizeof(Real), &mEpsilon);
// Variable-size members.
int numIndices;
inFile.Read(sizeof(int), &numIndices);
if (1 <= mDimension && mDimension <= 3)
{
assertion(numIndices == (mDimension+1)*mNumSimplices,
"Inconsistent index count\n");
mIndices = new1<int>(numIndices);
inFile.Read(sizeof(int), numIndices, mIndices);
return true;
}
mIndices = 0;
return mDimension == 0;
}
//----------------------------------------------------------------------------
template <typename Real>
bool ConvexHull<Real>::Save (FileIO& outFile) const
{
// Fixed-size members.
int type = (int)mQueryType;
outFile.Write(sizeof(int), &type);
outFile.Write(sizeof(int), &mNumVertices);
outFile.Write(sizeof(int), &mDimension);
outFile.Write(sizeof(int), &mNumSimplices);
outFile.Write(sizeof(Real), &mEpsilon);
// The member mOwner is not streamed because on a Load call, this
// object will allocate the vertices and own this memory.
// Variable-size members.
int numIndices;
if (1 <= mDimension && mDimension <= 3)
{
numIndices = (mDimension+1)*mNumSimplices;
outFile.Write(sizeof(int), &numIndices);
outFile.Write(sizeof(int), numIndices, mIndices);
return true;
}
numIndices = 0;
outFile.Write(sizeof(int), &numIndices);
return mDimension == 0;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Explicit instantiation.
//----------------------------------------------------------------------------
template WM5_MATHEMATICS_ITEM
class ConvexHull<float>;
template WM5_MATHEMATICS_ITEM
class ConvexHull<double>;
//----------------------------------------------------------------------------
}
|