GraphPyramidLookupTable.cpp
Go to the documentation of this file.
1 // *****************************************************************
2 // Filename: GraphLookupTable.cpp
3 // Copyright: Kai Welke, Chair Prof. Dillmann (IAIM),
4 // Institute for Computer Science and Engineering (CSE),
5 // University of Karlsruhe. All rights reserved.
6 // Author: Kai Welke
7 // Date: 10.10.2008
8 // *****************************************************************
9 
10 // *****************************************************************
11 // includes
12 // *****************************************************************
14 
15 #include <cstdlib>
16 
17 #include "MathTools.h"
18 
19 // *****************************************************************
20 // implementation of CGraphLookupTable
21 // *****************************************************************
22 // construction / destruction
23 CGraphPyramidLookupTable::CGraphPyramidLookupTable(int nMaxZenithBins, int nMaxAzimuthBins)
24 {
25  m_nMaxZenithBins = nMaxZenithBins;
26  m_nMaxAzimuthBins = nMaxAzimuthBins;
27 
28  m_nSubDivision = 2;
29  m_nLevels = 0;
30 
31  CGraphLookupTable* pTable;
32 
33  while (nMaxZenithBins != 0)
34  {
35  pTable = new CGraphLookupTable(nMaxZenithBins, nMaxAzimuthBins);
36 
37  m_Tables.push_back(pTable);
38 
39  // printf("Level %d: zenithbins: %d, azimuithbins: %d\n", m_nLevels, nMaxZenithBins, nMaxAzimuthBins);
40 
41  m_nLevels++;
42  nMaxZenithBins /= m_nSubDivision;
43  nMaxAzimuthBins /= m_nSubDivision;
44  }
45 }
46 
48 {
49  std::list<CGraphLookupTable*>::iterator iter = m_Tables.begin();
50 
51  while (iter != m_Tables.end())
52  {
53  delete *iter;
54 
55  iter++;
56  }
57 }
58 
59 void
61 {
62  std::list<CGraphLookupTable*>::iterator iter = m_Tables.begin();
63 
64  while (iter != m_Tables.end())
65  {
66  (*iter)->buildLookupTable(pGraph);
67 
68  iter++;
69  }
70 }
71 
72 int
74 {
75  TSphereCoord coords;
76  MathTools::convert(position, coords);
77 
78  return getClosestNode(coords);
79 }
80 
81 int
83 {
84  bool bFinished = false;
85  std::list<CGraphLookupTable*>::iterator iter = m_Tables.begin();
86  int nIndex = -1;
87 
88  int L = 0;
89 
90  while (iter != m_Tables.end())
91  {
92  nIndex = (*iter)->getClosestNode(position, bFinished);
93  // printf("Result in level %d: index %d, finished: %d\n",L,nIndex,bFinished);
94 
95  if (bFinished)
96  {
97  break;
98  }
99 
100  L++;
101  iter++;
102  }
103 
104  if (!bFinished)
105  {
106  printf("CGraphPyramidLookupTable:: no closest node found\n");
107  exit(1);
108  }
109 
110  return nIndex;
111 }
CGraphLookupTable
Definition: GraphLookupTable.h:22
GraphPyramidLookupTable.h
CGraphPyramidLookupTable::getClosestNode
int getClosestNode(Eigen::Vector3d position)
Definition: GraphPyramidLookupTable.cpp:73
MathTools.h
CGraphPyramidLookupTable::buildLookupTable
void buildLookupTable(CSphericalGraph *pGraph)
Definition: GraphPyramidLookupTable.cpp:60
CSphericalGraph
Definition: SphericalGraph.h:105
TSphereCoord
Definition: Structs.h:23
MathTools::convert
static void convert(TSphereCoord in, Eigen::Vector3d &out)
Definition: MathTools.cpp:440
CGraphPyramidLookupTable::~CGraphPyramidLookupTable
~CGraphPyramidLookupTable()
Definition: GraphPyramidLookupTable.cpp:47
CGraphPyramidLookupTable::CGraphPyramidLookupTable
CGraphPyramidLookupTable(int nMaxZenithBins, int nMaxAzimuthBins)
Definition: GraphPyramidLookupTable.cpp:23