Timestamps have been changed to millisec using QTime functions.

This commit is contained in:
Paolo Cignoni cignoni 2009-07-22 16:15:11 +00:00
parent 2056a5c026
commit cbc102e729
2 changed files with 39 additions and 44 deletions

View File

@ -39,6 +39,8 @@
#include <vcg/complex/trimesh/point_sampling.h>
#include <meshlabplugins/edit_pickpoints/pickedPoints.h>
#include <qdatetime.h>
using namespace std;
using namespace vcg;
@ -97,7 +99,7 @@ template<class MESH_TYPE> class Consensus
float threshold; //consensus % to win consensus;
bool normalEqualization; //to use normal equalization in consensus
bool paint; //to paint mMov according to consensus
void (*log)(const char * f, ... ); //pointer to log function
void (*log)(int level, const char * f, ... ); //pointer to log function
Parameters()
{
@ -377,11 +379,12 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
int numWonShortCons;
int numWonFullCons;
int numMatches;
time_t time;
time_t matchingTime;
time_t shortConsTime;
time_t fullConsTime;
time_t initTime;
int totalTime;
int baseSelectionTime;
int matchingTime;
int shortConsTime;
int fullConsTime;
int initTime;
QString errorMsg;
Result(){
@ -393,11 +396,12 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
numWonShortCons = 0;
numWonFullCons = 0;
numMatches = 0;
time = 0;
totalTime = 0;
initTime = 0;
matchingTime = 0;
shortConsTime = 0;
fullConsTime = 0;
baseSelectionTime = 0;
errorMsg = "An unkown error occurred.";
}
};
@ -438,8 +442,8 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
Result& init(MeshType& mFix, MeshType& mMov, Parameters& param)
{
time_t start, end; //timers
time(&start);
QTime timer; //timers
timer.start();
//extract features
vecFFix = FeatureAlignment::extractFeatures(param.numFixFeatureSelected, mFix, FeatureAlignment::UNIFORM_SAMPLING);
@ -461,16 +465,15 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
consParam.normalEqualization = param.normalEqualization;
cons.Init(consParam);
time(&end);
res.initTime = int(difftime(end,start));
res.initTime = timer.elapsed();
return res;
}
Result& align(MeshType& mFix, MeshType& mMov, Parameters& param, CallBackPos *cb=NULL)
{
time_t start, end, start_loop, end_loop; //timers
time(&start);
QTime tot_timer, timer; //timers
tot_timer.start();
if(param.nBase>int(vecFMov->size())){ setError(2,res); return res; } //not enough features to pick a base
if(param.k>int(vecFFix->size())){ setError(3, res); return res; } //not enough features to pick k neighboors
@ -503,7 +506,6 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
float progBar = 0.0f;
float offset = 30.0f/param.ransacIter;
time(&start_loop);
//loop of ransac iterations to find all possible matches at once
for(int i = 0; i<param.ransacIter; i++)
{
@ -542,8 +544,8 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
assert(candidates->size()==matchesVec->size());
}
time(&end_loop);
res.matchingTime = int(difftime(end_loop,start_loop));
//res.matchingTime = int(difftime(end_loop,start_loop));
res.numMatches = candidates->size();
//sort candidates by summed point distances
@ -552,7 +554,7 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
//variable needed for progress bar callback
offset = (40.0f/math::Min(param.maxNumShortConsensus,int(candidates->size())));
time(&start_loop);
//time(&start_loop);
//evaluetes at most first g candidates
for(unsigned int j=0; j<candidates->size() && j<param.maxNumShortConsensus; j++)
{
@ -569,8 +571,7 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
if((*candidates)[j].shortCons >= short_cons_succ) res.numWonShortCons++; //count how many won, and use this as bound later
}
time(&end_loop);
res.shortConsTime = int(difftime(end_loop,start_loop));
//res.shortConsTime = int(difftime(end_loop,start_loop));
//sort candidates by short consensus
sort(candidates->begin(), candidates->end(), CandidateType::SortByScore);
@ -578,7 +579,7 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
//variables needed for progress bar callback
offset = (40.0f/math::Min(param.maxNumFullConsensus,int(candidates->size())));
time(&start_loop);
//time(&start_loop);
//evaluetes at most maxNumFullConsensus candidates beetween those who won short consensus
for(int j=0; j<res.numWonShortCons && j<param.maxNumFullConsensus; j++)
{
@ -607,10 +608,8 @@ template<class MESH_TYPE, class FEATURE_TYPE> class FeatureAlignment
}
}
time(&end_loop);
time(&end);
res.fullConsTime = int(difftime(end_loop,start_loop));
res.time = (difftime(end,start));
//res.fullConsTime = int(difftime(end_loop,start_loop));
res.totalTime = tot_timer.elapsed();
//if flag 'points' is checked, clear old picked points and save the new points
if(param.pickPoints){

View File

@ -39,7 +39,7 @@ using namespace std;
using namespace vcg;
GLLogStream *glLog;
void mylogger(const char * f, ... )
void mylogger(int level, const char * f, ... )
{
char buf[4096];
va_list marker;
@ -47,7 +47,7 @@ void mylogger(const char * f, ... )
vsprintf(buf,f,marker);
va_end( marker );
glLog->Log(GLLogStream::DEBUG,buf);
glLog->Log(level,buf);
}
FilterFeatureAlignment::FilterFeatureAlignment()
@ -258,23 +258,23 @@ bool FilterFeatureAlignment::logResult(FilterIDType filter, typename ALIGNER_TYP
case AF_MATCHING:{
switch(res.exitCode){
case ResultType::ALIGNED :
case ResultType::NOT_ALIGNED : {mylogger("Matching done: %i matches, %i sec.", res.numMatches, res.time); return true;}
case ResultType::NOT_ALIGNED : {mylogger(GLLogStream::FILTER,"Matching done: %i matches, %i msec.", res.numMatches, res.totalTime); return true;}
case ResultType::FAILED : {errorMsg = res.errorMsg; return false; }
default : assert(0);
}
}
case AF_RIGID_TRANSFORMATION:{
switch(res.exitCode){
case ResultType::ALIGNED : {mylogger("Transformations computed: %i computed, %i matches, %i sec.", res.numWonFullCons, res.numMatches, res.time); return true;}
case ResultType::NOT_ALIGNED : {mylogger("No trasformations computed: %i matches, %i sec.", res.numMatches, res.time); return true;}
case ResultType::ALIGNED : {mylogger(GLLogStream::FILTER,"Transformations computed: %i computed, %i matches, %i msec.", res.numWonFullCons, res.numMatches, res.totalTime); return true;}
case ResultType::NOT_ALIGNED : {mylogger(GLLogStream::FILTER,"No trasformations computed: %i matches, %i msec.", res.numMatches, res.totalTime); return true;}
case ResultType::FAILED : {errorMsg = res.errorMsg; return false; }
default : assert(0);
}
}
case AF_RANSAC:{
switch(res.exitCode){
case ResultType::ALIGNED : {mylogger("Alignemnt found: %.2f%% consensus, %i matches, %i iter. skipped, %i sec.", res.bestConsensus, res.numMatches, res.numSkippedIter, res.time); return true;}
case ResultType::NOT_ALIGNED : {mylogger("Alignemnt not found: %i matches, %i iter. skipped, %i sec.", res.numMatches, res.numSkippedIter, res.time); return true;}
case ResultType::ALIGNED : {mylogger(GLLogStream::FILTER,"Alignemnt found: %.2f%% consensus.", res.bestConsensus); return true;}
case ResultType::NOT_ALIGNED : {mylogger(GLLogStream::FILTER,"Alignemnt not found."); return true;}
case ResultType::FAILED : {errorMsg = res.errorMsg; return false; }
default : assert(0);
}
@ -516,8 +516,6 @@ template<class MESH_TYPE, class FEATURE_TYPE> bool FilterFeatureAlignment::Compu
template<class ALIGNER_TYPE>
bool FilterFeatureAlignment::ExtractionOperation(MeshModel& m, typename ALIGNER_TYPE::Parameters& param, CallBackPos *cb)
{
//typedef MESH_TYPE MeshType;
//typedef FEATURE_TYPE FeatureType;
typedef ALIGNER_TYPE AlignerType;
typedef typename AlignerType::MeshType MeshType;
typedef typename AlignerType::FeatureType FeatureType;
@ -546,8 +544,8 @@ typename ALIGNER_TYPE::Result FilterFeatureAlignment::MatchingOperation(MeshMode
typedef typename AlignerType::FeatureType FeatureType;
typedef typename AlignerType::Result ResultType;
time_t start, end;
time(&start); //start timer
QTime timer;
timer.start(); //start timer
//create vectors to hold tuples of bases and matches
vector<FeatureType**>* baseVec = new vector<FeatureType**>();
@ -567,8 +565,7 @@ typename ALIGNER_TYPE::Result FilterFeatureAlignment::MatchingOperation(MeshMode
AlignerType::CleanTuplesVector(baseVec, true);
AlignerType::CleanTuplesVector(matchesVec, true);
time(&end); //stop timer
res.time = (int)difftime(end,start);
res.totalTime = timer.elapsed();
return res;
}
@ -583,8 +580,8 @@ typename ALIGNER_TYPE::Result FilterFeatureAlignment::RigidTransformationOperati
typedef typename AlignerType::Result ResultType;
typedef Matrix44<ScalarType> Matrix44Type;
time_t start, end;
time(&start); //start timer
QTime timer;
timer.start(); //start timer
//create vectors to hold tuples of bases and matches
vector<FeatureType**>* baseVec = new vector<FeatureType**>();
@ -615,8 +612,7 @@ typename ALIGNER_TYPE::Result FilterFeatureAlignment::RigidTransformationOperati
AlignerType::CleanTuplesVector(baseVec, true);
AlignerType::CleanTuplesVector(matchesVec, true);
time(&end); //stop timer
res.time = (int)difftime(end,start);
res.totalTime = timer.elapsed();
return res; //all right
}
@ -714,7 +710,7 @@ for(int h=0; h<4; h++)
trialsInitTotTime+=res.initTime;
res = aligner.align(mFix.cm, mMov.cm, param);
trialsTotTime+=res.time;
trialsTotTime+=res.totalTime;
if(res.exitCode==ResultType::ALIGNED)numWon++;
if(res.exitCode==ResultType::FAILED) return res; //failure: stop everything and return error
}
@ -722,8 +718,8 @@ for(int h=0; h<4; h++)
probSucc = numWon/float(trials); //k = prob succ in 1 iteration
meanTime = trialsTotTime/float(trials); //t=sec elapsed to perform N ransac iterations
meanInitTime = trialsInitTotTime/float(trials);
failPerSec = std::pow(1-probSucc,1.0f/meanTime); //fail rate per sec is: (1-k)^(1/t)
fprintf(file,"%i#%.2f#%.2f#%.2f#%.2f\n", param.ransacIter, meanInitTime, meanTime, probSucc, failPerSec); fflush(file);
failPerSec = std::pow(1-probSucc,1.0f/(meanTime/1000)); //fail rate per sec is: (1-k)^(1/t)
fprintf(file,"%i#%.2f#%.2f#%.2f#%.2f\n", param.ransacIter, meanInitTime/1000, meanTime/1000, probSucc, failPerSec); fflush(file);
numWon = 0; trialsTotTime = 0; trialsInitTotTime=0; progBar=0.0f;
param.ransacIter+=step;
}