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 // *****************************************************************
13 #include <cstdlib>
15 #include "MathTools.h"
16 
17 // *****************************************************************
18 // implementation of CGraphLookupTable
19 // *****************************************************************
20 // construction / destruction
21 CGraphPyramidLookupTable::CGraphPyramidLookupTable(int nMaxZenithBins, int nMaxAzimuthBins)
22 {
23  m_nMaxZenithBins = nMaxZenithBins;
24  m_nMaxAzimuthBins = nMaxAzimuthBins;
25 
26  m_nSubDivision = 2;
27  m_nLevels = 0;
28 
29  CGraphLookupTable* pTable;
30 
31  while (nMaxZenithBins != 0)
32  {
33  pTable = new CGraphLookupTable(nMaxZenithBins, nMaxAzimuthBins);
34 
35  m_Tables.push_back(pTable);
36 
37  // printf("Level %d: zenithbins: %d, azimuithbins: %d\n", m_nLevels, nMaxZenithBins, nMaxAzimuthBins);
38 
39  m_nLevels++;
40  nMaxZenithBins /= m_nSubDivision;
41  nMaxAzimuthBins /= m_nSubDivision;
42  }
43 
44 }
45 
47 {
48  std::list<CGraphLookupTable*>::iterator iter = m_Tables.begin();
49 
50  while (iter != m_Tables.end())
51  {
52  delete *iter;
53 
54  iter++;
55  }
56 }
57 
59 {
60  std::list<CGraphLookupTable*>::iterator iter = m_Tables.begin();
61 
62  while (iter != m_Tables.end())
63  {
64  (*iter)->buildLookupTable(pGraph);
65 
66  iter++;
67  }
68 }
69 
70 int CGraphPyramidLookupTable::getClosestNode(Eigen::Vector3d position)
71 {
72  TSphereCoord coords;
73  MathTools::convert(position, coords);
74 
75  return getClosestNode(coords);
76 }
77 
79 {
80  bool bFinished = false;
81  std::list<CGraphLookupTable*>::iterator iter = m_Tables.begin();
82  int nIndex = -1;
83 
84  int L = 0;
85 
86  while (iter != m_Tables.end())
87  {
88  nIndex = (*iter)->getClosestNode(position, bFinished);
89  // printf("Result in level %d: index %d, finished: %d\n",L,nIndex,bFinished);
90 
91  if (bFinished)
92  {
93  break;
94  }
95 
96  L++;
97  iter++;
98  }
99 
100  if (!bFinished)
101  {
102  printf("CGraphPyramidLookupTable:: no closest node found\n");
103  exit(1);
104  }
105 
106  return nIndex;
107 }
108 
CGraphLookupTable
Definition: GraphLookupTable.h:21
GraphPyramidLookupTable.h
CGraphPyramidLookupTable::getClosestNode
int getClosestNode(Eigen::Vector3d position)
Definition: GraphPyramidLookupTable.cpp:70
MathTools.h
CGraphPyramidLookupTable::buildLookupTable
void buildLookupTable(CSphericalGraph *pGraph)
Definition: GraphPyramidLookupTable.cpp:58
CSphericalGraph
Definition: SphericalGraph.h:93
TSphereCoord
Definition: Structs.h:22
MathTools::convert
static void convert(TSphereCoord in, Eigen::Vector3d &out)
Definition: MathTools.cpp:401
CGraphPyramidLookupTable::~CGraphPyramidLookupTable
~CGraphPyramidLookupTable()
Definition: GraphPyramidLookupTable.cpp:46
CGraphPyramidLookupTable::CGraphPyramidLookupTable
CGraphPyramidLookupTable(int nMaxZenithBins, int nMaxAzimuthBins)
Definition: GraphPyramidLookupTable.cpp:21