File size: 3,764 Bytes
985c397 | 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 | // SPDX-License-Identifier: BSL-1.0
// 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 "Wm4ConvexHull1.h"
namespace Wm4
{
//----------------------------------------------------------------------------
template <class Real>
ConvexHull1<Real>::ConvexHull1 (int iVertexQuantity, Real* afVertex,
Real fEpsilon, bool bOwner, Query::Type eQueryType)
:
ConvexHull<Real>(iVertexQuantity,fEpsilon,bOwner,eQueryType)
{
assert(afVertex);
m_afVertex = afVertex;
std::vector<SortedVertex> kArray(m_iVertexQuantity);
int i;
for (i = 0; i < m_iVertexQuantity; i++)
{
kArray[i].Value = m_afVertex[i];
kArray[i].Index = i;
}
std::sort(kArray.begin(),kArray.end());
Real fRange = kArray[m_iVertexQuantity-1].Value - kArray[0].Value;
if (fRange >= m_fEpsilon)
{
m_iDimension = 1;
m_iSimplexQuantity = 2;
m_aiIndex = WM4_NEW int[2];
m_aiIndex[0] = kArray[0].Index;
m_aiIndex[1] = kArray[m_iVertexQuantity-1].Index;
}
}
//----------------------------------------------------------------------------
template <class Real>
ConvexHull1<Real>::~ConvexHull1 ()
{
if (m_bOwner)
{
WM4_DELETE[] m_afVertex;
}
}
//----------------------------------------------------------------------------
template <class Real>
const Real* ConvexHull1<Real>::GetVertices () const
{
return m_afVertex;
}
//----------------------------------------------------------------------------
template <class Real>
ConvexHull1<Real>::ConvexHull1 (const char* acFilename)
:
ConvexHull<Real>(0,(Real)0.0,false,Query::QT_REAL)
{
m_afVertex = nullptr;
bool bLoaded = Load(acFilename);
assert(bLoaded);
(void)bLoaded; // avoid warning in Release build
}
//----------------------------------------------------------------------------
template <class Real>
bool ConvexHull1<Real>::Load (const char* acFilename)
{
FILE* pkIFile = System::Fopen(acFilename,"rb");
if (!pkIFile)
{
return false;
}
ConvexHull<Real>::Load(pkIFile);
if (m_bOwner)
{
WM4_DELETE[] m_afVertex;
}
m_bOwner = true;
m_afVertex = WM4_NEW Real[m_iVertexQuantity];
size_t uiSize = sizeof(Real);
if (uiSize == 4)
{
System::Read4le(pkIFile,m_iVertexQuantity,m_afVertex);
}
else // uiSize == 8
{
System::Read8le(pkIFile,m_iVertexQuantity,m_afVertex);
}
System::Fclose(pkIFile);
return true;
}
//----------------------------------------------------------------------------
template <class Real>
bool ConvexHull1<Real>::Save (const char* acFilename) const
{
FILE* pkOFile = System::Fopen(acFilename,"wb");
if (!pkOFile)
{
return false;
}
ConvexHull<Real>::Save(pkOFile);
size_t uiSize = sizeof(Real);
if (uiSize == 4)
{
System::Write4le(pkOFile,m_iVertexQuantity,m_afVertex);
}
else // uiSize == 8
{
System::Write8le(pkOFile,m_iVertexQuantity,m_afVertex);
}
System::Fclose(pkOFile);
return true;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// explicit instantiation
//----------------------------------------------------------------------------
template WM4_FOUNDATION_ITEM
class ConvexHull1<float>;
template WM4_FOUNDATION_ITEM
class ConvexHull1<double>;
//----------------------------------------------------------------------------
}
|