nearest neighbor grid can now be specialized to be read only with a template parameter.
This commit is contained in:
parent
f9f4fa2972
commit
6fcc6722c4
@ -144,10 +144,11 @@ static void getListOfIndexesForEdgeAndGridSize(_Coordinate& start, _Coordinate&
|
|||||||
bresenham(x1*32768, y1*32768, x2*32768, y2*32768, indexList);
|
bresenham(x1*32768, y1*32768, x2*32768, y2*32768, indexList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<bool WriteAccess = false>
|
||||||
class NNGrid {
|
class NNGrid {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NNGrid() { ramIndexTable.resize((1024*1024), UINT_MAX); }
|
NNGrid() { ramIndexTable.resize((1024*1024), UINT_MAX); if( WriteAccess) { entries = new stxxl::vector<GridEdgeData>(); }}
|
||||||
|
|
||||||
NNGrid(const char* rif, const char* iif) {
|
NNGrid(const char* rif, const char* iif) {
|
||||||
ramIndexTable.resize((1024*1024), UINT_MAX);
|
ramIndexTable.resize((1024*1024), UINT_MAX);
|
||||||
@ -158,6 +159,11 @@ public:
|
|||||||
~NNGrid() {
|
~NNGrid() {
|
||||||
if(ramInFile.is_open()) ramInFile.close();
|
if(ramInFile.is_open()) ramInFile.close();
|
||||||
if(indexInFile.is_open()) indexInFile.close();
|
if(indexInFile.is_open()) indexInFile.close();
|
||||||
|
|
||||||
|
if (WriteAccess)
|
||||||
|
{
|
||||||
|
delete entries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenIndexFiles()
|
void OpenIndexFiles()
|
||||||
@ -183,7 +189,7 @@ public:
|
|||||||
getListOfIndexesForEdgeAndGridSize(start, target, indexList);
|
getListOfIndexesForEdgeAndGridSize(start, target, indexList);
|
||||||
for(int i = 0; i < indexList.size(); i++)
|
for(int i = 0; i < indexList.size(); i++)
|
||||||
{
|
{
|
||||||
entries.push_back(GridEdgeData(edge, indexList[i].first, indexList[i].second));
|
entries->push_back(GridEdgeData(edge, indexList[i].first, indexList[i].second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,18 +198,18 @@ public:
|
|||||||
double timestamp = get_timestamp();
|
double timestamp = get_timestamp();
|
||||||
//create index file on disk, old one is over written
|
//create index file on disk, old one is over written
|
||||||
indexOutFile.open(fileIndexOut, std::ios::out | std::ios::binary | std::ios::trunc);
|
indexOutFile.open(fileIndexOut, std::ios::out | std::ios::binary | std::ios::trunc);
|
||||||
cout << "sorting grid data consisting of " << entries.size() << " edges..." << flush;
|
cout << "sorting grid data consisting of " << entries->size() << " edges..." << flush;
|
||||||
//sort entries
|
//sort entries
|
||||||
stxxl::sort(entries.begin(), entries.end(), CompareGridEdgeDataByRamIndex(), 1024*1024*1024);
|
stxxl::sort(entries->begin(), entries->end(), CompareGridEdgeDataByRamIndex(), 1024*1024*1024);
|
||||||
cout << "ok in " << (get_timestamp() - timestamp) << "s" << endl;
|
cout << "ok in " << (get_timestamp() - timestamp) << "s" << endl;
|
||||||
std::vector<GridEdgeData> entriesInFileWithRAMSameIndex;
|
std::vector<GridEdgeData> entriesInFileWithRAMSameIndex;
|
||||||
unsigned indexInRamTable = entries.begin()->ramIndex;
|
unsigned indexInRamTable = entries->begin()->ramIndex;
|
||||||
unsigned lastPositionInIndexFile = 0;
|
unsigned lastPositionInIndexFile = 0;
|
||||||
unsigned numberOfUsedCells = 0;
|
unsigned numberOfUsedCells = 0;
|
||||||
unsigned maxNumberOfRAMCellElements = 0;
|
unsigned maxNumberOfRAMCellElements = 0;
|
||||||
cout << "writing data ..." << flush;
|
cout << "writing data ..." << flush;
|
||||||
Percent p(entries.size());
|
Percent p(entries->size());
|
||||||
for(stxxl::vector<GridEdgeData>::iterator vt = entries.begin(); vt != entries.end(); vt++)
|
for(stxxl::vector<GridEdgeData>::iterator vt = entries->begin(); vt != entries->end(); vt++)
|
||||||
{
|
{
|
||||||
p.printIncrement();
|
p.printIncrement();
|
||||||
if(vt->ramIndex != indexInRamTable)
|
if(vt->ramIndex != indexInRamTable)
|
||||||
@ -587,7 +593,7 @@ private:
|
|||||||
ofstream indexOutFile;
|
ofstream indexOutFile;
|
||||||
ifstream indexInFile;
|
ifstream indexInFile;
|
||||||
ifstream ramInFile;
|
ifstream ramInFile;
|
||||||
stxxl::vector<GridEdgeData> entries;
|
stxxl::vector<GridEdgeData> * entries;
|
||||||
std::vector<unsigned> ramIndexTable; //4 MB for first level index in RAM
|
std::vector<unsigned> ramIndexTable; //4 MB for first level index in RAM
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,11 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "NNGrid.h"
|
#include "NNGrid.h"
|
||||||
#include "PhantomNodes.h"
|
#include "PhantomNodes.h"
|
||||||
|
|
||||||
typedef NNGrid::NNGrid Grid;
|
typedef NNGrid::NNGrid<false> ReadOnlyGrid;
|
||||||
|
|
||||||
class NodeInformationHelpDesk{
|
class NodeInformationHelpDesk{
|
||||||
public:
|
public:
|
||||||
NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput) { numberOfNodes = 0; int2ExtNodeMap = new vector<_Coordinate>(); g = new Grid(ramIndexInput,fileIndexInput); }
|
NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput) { numberOfNodes = 0; int2ExtNodeMap = new vector<_Coordinate>(); g = new ReadOnlyGrid(ramIndexInput,fileIndexInput); }
|
||||||
~NodeInformationHelpDesk() { delete int2ExtNodeMap; delete g; }
|
~NodeInformationHelpDesk() { delete int2ExtNodeMap; delete g; }
|
||||||
void initNNGrid(ifstream& in)
|
void initNNGrid(ifstream& in)
|
||||||
{
|
{
|
||||||
@ -61,7 +61,7 @@ public:
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
vector<_Coordinate> * int2ExtNodeMap;
|
vector<_Coordinate> * int2ExtNodeMap;
|
||||||
Grid * g;
|
ReadOnlyGrid * g;
|
||||||
unsigned numberOfNodes;
|
unsigned numberOfNodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ using namespace std;
|
|||||||
|
|
||||||
typedef ContractionCleanup::Edge::EdgeData EdgeData;
|
typedef ContractionCleanup::Edge::EdgeData EdgeData;
|
||||||
typedef DynamicGraph<EdgeData>::InputEdge GridEdge;
|
typedef DynamicGraph<EdgeData>::InputEdge GridEdge;
|
||||||
typedef NNGrid::NNGrid Grid;
|
typedef NNGrid::NNGrid<true> WritableGrid;
|
||||||
|
|
||||||
vector<NodeInfo> * int2ExtNodeMap = new vector<NodeInfo>();
|
vector<NodeInfo> * int2ExtNodeMap = new vector<NodeInfo>();
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ int main (int argc, char *argv[])
|
|||||||
strcat(fileIndexOut, ".fileIndex");
|
strcat(fileIndexOut, ".fileIndex");
|
||||||
ofstream mapOutFile(nodeOut, ios::binary);
|
ofstream mapOutFile(nodeOut, ios::binary);
|
||||||
|
|
||||||
Grid * g = new Grid();
|
WritableGrid * g = new WritableGrid();
|
||||||
cout << "building grid ..." << flush;
|
cout << "building grid ..." << flush;
|
||||||
Percent p(edgeList.size());
|
Percent p(edgeList.size());
|
||||||
for(NodeID i = 0; i < edgeList.size(); i++)
|
for(NodeID i = 0; i < edgeList.size(); i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user