2 #include "distfunc.h"
\r
14 DistFunc::~DistFunc()
\r
18 for (unsigned i = 0; i < m_uCount; ++i)
\r
26 float DistFunc::GetDist(unsigned uIndex1, unsigned uIndex2) const
\r
28 return m_Dists[VectorIndex(uIndex1, uIndex2)];
\r
31 unsigned DistFunc::GetCount() const
\r
36 void DistFunc::SetCount(unsigned uCount)
\r
39 if (uCount <= m_uCacheCount)
\r
42 m_Dists = new float[VectorLength()];
\r
43 m_Names = new char *[m_uCount];
\r
44 m_Ids = new unsigned[m_uCount];
\r
45 m_uCacheCount = uCount;
\r
47 memset(m_Names, 0, m_uCount*sizeof(char *));
\r
48 memset(m_Ids, 0xff, m_uCount*sizeof(unsigned));
\r
49 memset(m_Dists, 0, VectorLength()*sizeof(float));
\r
52 void DistFunc::SetDist(unsigned uIndex1, unsigned uIndex2, float dDist)
\r
54 m_Dists[VectorIndex(uIndex1, uIndex2)] = dDist;
\r
55 m_Dists[VectorIndex(uIndex2, uIndex1)] = dDist;
\r
58 unsigned DistFunc::VectorIndex(unsigned uIndex1, unsigned uIndex2) const
\r
60 assert(uIndex1 < m_uCount && uIndex2 < m_uCount);
\r
61 return uIndex1*m_uCount + uIndex2;
\r
64 unsigned DistFunc::VectorLength() const
\r
66 return m_uCount*m_uCount;
\r
69 void DistFunc::SetName(unsigned uIndex, const char szName[])
\r
71 assert(uIndex < m_uCount);
\r
72 m_Names[uIndex] = strsave(szName);
\r
75 void DistFunc::SetId(unsigned uIndex, unsigned uId)
\r
77 assert(uIndex < m_uCount);
\r
78 m_Ids[uIndex] = uId;
\r
81 const char *DistFunc::GetName(unsigned uIndex) const
\r
83 assert(uIndex < m_uCount);
\r
84 return m_Names[uIndex];
\r
87 unsigned DistFunc::GetId(unsigned uIndex) const
\r
89 assert(uIndex < m_uCount);
\r
90 return m_Ids[uIndex];
\r
93 void DistFunc::LogMe() const
\r
95 Log("DistFunc::LogMe count=%u\n", m_uCount);
\r
97 for (unsigned i = 0; i < m_uCount; ++i)
\r
102 for (unsigned i = 0; i < m_uCount; ++i)
\r
103 Log(" %7.7s", m_Names[i] ? m_Names[i] : "");
\r
106 for (unsigned i = 0; i < m_uCount; ++i)
\r
108 Log("%4u %10.10s : ", i, m_Names[i] ? m_Names[i] : "");
\r
109 for (unsigned j = 0; j <= i; ++j)
\r
110 Log(" %7.4g", GetDist(i, j));
\r