00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 namespace Wm4
00018 {
00019
00020 template <int N, class Real>
00021 UniqueVerticesTriangles<N,Real>::UniqueVerticesTriangles (int iTQuantity,
00022 const TTuple<N,Real>* akInVertex, int& riOutVQuantity,
00023 TTuple<N,Real>*& rakOutVertex, int*& raiOutIndex)
00024 {
00025 assert(iTQuantity > 0 && akInVertex);
00026
00027 ConstructUniqueVertices(3*iTQuantity,akInVertex,riOutVQuantity,
00028 rakOutVertex);
00029
00030
00031
00032
00033 int iIQuantity = 3*iTQuantity;
00034 raiOutIndex = WM4_NEW int[iIQuantity];
00035 size_t uiSize = iIQuantity*sizeof(int);
00036 System::Memcpy(raiOutIndex,uiSize,m_aiInToOutMapping,uiSize);
00037 }
00038
00039 template <int N, class Real>
00040 UniqueVerticesTriangles<N,Real>::UniqueVerticesTriangles (int iInVQuantity,
00041 const TTuple<N,Real>* akInVertex, int iTQuantity, const int* aiInIndex,
00042 int& riOutVQuantity, TTuple<N,Real>*& rakOutVertex, int*& raiOutIndex)
00043 {
00044 assert(iInVQuantity > 0 && akInVertex && iTQuantity > 0 && aiInIndex);
00045
00046 ConstructUniqueVertices(iInVQuantity,akInVertex,riOutVQuantity,
00047 rakOutVertex);
00048
00049
00050
00051 int iIQuantity = 3*iTQuantity;
00052 raiOutIndex = WM4_NEW int[iIQuantity];
00053 for (int i = 0; i < iIQuantity; i++)
00054 {
00055 assert(0 <= aiInIndex[i] && aiInIndex[i] < iInVQuantity);
00056 raiOutIndex[i] = m_aiInToOutMapping[aiInIndex[i]];
00057 assert(0 <= raiOutIndex[i] && raiOutIndex[i] < riOutVQuantity);
00058 }
00059 }
00060
00061 template <int N, class Real>
00062 UniqueVerticesTriangles<N,Real>::~UniqueVerticesTriangles ()
00063 {
00064 WM4_DELETE[] m_aiInToOutMapping;
00065 }
00066
00067 template <int N, class Real>
00068 int UniqueVerticesTriangles<N,Real>::GetOutputIndexFor (int iInputIndex) const
00069 {
00070 assert(0 <= iInputIndex && iInputIndex < m_iInVQuantity);
00071 return m_aiInToOutMapping[iInputIndex];
00072 }
00073
00074 template <int N, class Real>
00075 void UniqueVerticesTriangles<N,Real>::ConstructUniqueVertices (
00076 int iInVQuantity, const TTuple<N,Real>* akInVertex, int& riOutVQuantity,
00077 TTuple<N,Real>*& rakOutVertex)
00078 {
00079
00080 m_iInVQuantity = iInVQuantity;
00081 m_aiInToOutMapping = WM4_NEW int[m_iInVQuantity];
00082 std::map<TTuple<N,Real>,int> kTable;
00083 m_iOutVQuantity = 0;
00084 typename std::map<TTuple<N,Real>,int>::iterator pkIter;
00085 for (int i = 0; i < m_iInVQuantity; i++)
00086 {
00087 pkIter = kTable.find(akInVertex[i]);
00088 if (pkIter != kTable.end())
00089 {
00090
00091
00092 m_aiInToOutMapping[i] = pkIter->second;
00093 }
00094 else
00095 {
00096
00097 kTable.insert(std::make_pair(akInVertex[i],m_iOutVQuantity));
00098 m_aiInToOutMapping[i] = m_iOutVQuantity;
00099 m_iOutVQuantity++;
00100 }
00101 }
00102
00103
00104 riOutVQuantity = m_iOutVQuantity;
00105 rakOutVertex = WM4_NEW TTuple<N,Real>[m_iOutVQuantity];
00106 for (pkIter = kTable.begin(); pkIter != kTable.end(); pkIter++)
00107 {
00108 assert(0 <= pkIter->second && pkIter->second < m_iOutVQuantity);
00109 rakOutVertex[pkIter->second] = pkIter->first;
00110 }
00111 }
00112
00113 }