Final Corrs.bin

The file is binary file. Assume int is a 32-bit little-endian integer,
and double is a 64-bit little-endian floating-point number.

File content:
~~~~ Field ~~~~ ~~~~ Comment ~~~~
int NModels Number of models contained in this file and database
Repeated NModels times:
    int ModelID int NPoints ModelID the same as in ModelNames.txt,
NPoints indicates number of points on the model
Repeated NPoints times:
        int VertexID int NCorrs VertexID vertex id of a point on model ModelID
NCorrs number of points that correspond the point VertexID
Repeated NCorrs times:
            int ModelID2 int VertexID2 double CorrValue ModelID2 index of a model with corresponding point
VertexID2 vertex id on a corresponding model
CorrValue correspondence value: f(p1, p2)
-29349234 Indicates the end of the file
(might be used to test that
read was successful).







C++ code that created the file (reference)

void CollectionDiffuseDynamicGraph::WriteFinalCorrespondences()
{
VKString mainDir = m_pDB->GetCollectionDir(m_sCollectionName);
VKString outFile = mainDir + "/FinalCorrs.bin";
m_pDB->CreateDirsOnPathToFile(outFile);

VKString outModelNames = mainDir + "/ModelNames.txt";
std::ofstream textStream(outModelNames.c_str());
textStream<<"NumModels "<<m_pDB->NumModels()<<"\n";
for (int i=0; i<m_pDB->NumModels(); i++)
textStream<<i<<" "<<m_pDB->GetModelByID(i)->ModelGeometryFile().c_str()<<"\n";
textStream.close();

FILE * file = fopen(outFile.c_str(), "wb");
assert(file!=NULL);
// write number of models
fwrite(&m_iNumModels, sizeof(int), 1, file);

// rows: modelID NPoints
// repeat NPoints times:
// VertexID for the point on modelID
// NCorrs = number of correspondences for the point,
// repeat NCorrs times
// correspondence: modelID, vertexID, value

for (int i=0; i<m_iNumModels; i++) // for each model
{
Model3D * model = m_pDB->GetModelByID(i);
PointSet * pnts = model->PointCloud();

int nPnts = pnts->NumPoints();
fwrite(&i, sizeof(int), 1, file); // write model ID
fwrite(&nPnts, sizeof(int), 1, file); // write number of points on a model

for (int j=0; j<pnts->NumPoints(); j++) // for each point on a model
{
ModelPoint pFrom = pnts->GetPoint(j);
std::vector<ModelPoint> corrs;
bool valid;
int vID = pFrom.NearestVertex(&valid);
assert(valid);
fwrite(&vID, sizeof(int), 1, file); // write vertex ID

GetCorrs(pFrom, &corrs);
int nCorrs = (int)corrs.size();
fwrite(&nCorrs, sizeof(int), 1, file); // write number of correspondences
for (int c=0; c<(int)corrs.size(); c++)
{
double val = DiffusedCorrValue(pFrom, corrs[c]);
int modelID = corrs[c].GetModel()->ModelID();
int v2ID = corrs[c].NearestVertex(&valid);
assert(valid);
fwrite(&modelID, sizeof(int), 1, file);
fwrite(&v2ID, sizeof(int), 1, file);
fwrite(&val, sizeof(double), 1, file);
}
}
}

int checksum = -29349234;
fwrite(&checksum, sizeof(int), 1, file); //checksum

fclose(file);
}