remove memset from meshtree.h

This commit is contained in:
alemuntoni 2021-10-19 12:14:31 +02:00
parent 70ac3d8248
commit 5e17997b37
1 changed files with 190 additions and 148 deletions

View File

@ -125,18 +125,25 @@ namespace vcg {
return count;
}
void Process(vcg::AlignPair::Param &ap, MeshTree::Param &mtp) {
char buf[1024];
std::sprintf(buf, "Starting Processing of %i glued meshes out of %zu meshes\n", gluedNum(), nodeMap.size());
cb(0, buf);
void Process(vcg::AlignPair::Param& ap, MeshTree::Param& mtp)
{
std::array<char, 1024> buf;
std::sprintf(
buf.data(),
"Starting Processing of %i glued meshes out of %zu meshes\n",
gluedNum(),
nodeMap.size());
cb(0, buf.data());
/******* Occupancy Grid Computation *************/
std::memset(buf, '\0', 1024);
std::sprintf(buf, "Computing Overlaps %i glued meshes...\n", gluedNum());
cb(0, buf);
buf.fill('\0');
std::sprintf(buf.data(), "Computing Overlaps %i glued meshes...\n", gluedNum());
cb(0, buf.data());
OG.Init(static_cast<int>(nodeMap.size()), vcg::Box3<ScalarType>::Construct(gluedBBox()), mtp.OGSize);
OG.Init(
static_cast<int>(nodeMap.size()),
vcg::Box3<ScalarType>::Construct(gluedBBox()),
mtp.OGSize);
for (auto& ni : nodeMap) {
MeshTree::MeshNode* mn = ni.second;
@ -154,7 +161,6 @@ namespace vcg {
// count existing arcs within current error threshold
float percentileThr = 0;
if (!resultList.empty()) {
vcg::Distribution<float> H;
for (auto& li : resultList) {
H.Add(li.err);
@ -166,9 +172,10 @@ namespace vcg {
std::size_t totalArcNum = 0;
int preservedArcNum = 0, recalcArcNum = 0;
while(totalArcNum < OG.SVA.size() && OG.SVA[totalArcNum].norm_area > mtp.arcThreshold)
{
AlignPair::Result *curResult = findResult(OG.SVA[totalArcNum].s, OG.SVA[totalArcNum].t);
while (totalArcNum < OG.SVA.size() &&
OG.SVA[totalArcNum].norm_area > mtp.arcThreshold) {
AlignPair::Result* curResult =
findResult(OG.SVA[totalArcNum].s, OG.SVA[totalArcNum].t);
if (curResult) {
if (curResult->err < percentileThr) {
++preservedArcNum;
@ -188,23 +195,28 @@ namespace vcg {
// if there are no arcs at all complain and return
if (totalArcNum == 0) {
std::memset(buf, '\0', 1024);
std::sprintf(buf, "\n Failure. There are no overlapping meshes?\n No candidate alignment arcs. Nothing Done.\n");
cb(0, buf);
buf.fill('\0');
std::sprintf(
buf.data(),
"\n Failure. There are no overlapping meshes?\n No candidate alignment arcs. "
"Nothing Done.\n");
cb(0, buf.data());
return;
}
int num_max_thread = 1;
#ifdef _OPENMP
if (totalArcNum > 32) num_max_thread = omp_get_max_threads();
if (totalArcNum > 32)
num_max_thread = omp_get_max_threads();
#endif
std::memset(buf, '\0', 1024);
std::sprintf(buf, "Arc with good overlap %6zu (on %6zu)\n", totalArcNum, OG.SVA.size());
cb(0, buf);
buf.fill('\0');
std::sprintf(
buf.data(), "Arc with good overlap %6zu (on %6zu)\n", totalArcNum, OG.SVA.size());
cb(0, buf.data());
std::memset(buf, '\0', 1024);
std::sprintf(buf, " %6i preserved %i Recalc \n", preservedArcNum, recalcArcNum);
cb(0, buf);
buf.fill('\0');
std::sprintf(buf.data(), " %6i preserved %i Recalc \n", preservedArcNum, recalcArcNum);
cb(0, buf.data());
bool hasValidAlign = false;
@ -212,13 +224,17 @@ namespace vcg {
// on windows, omp does not support unsigned types for indices on cycles
for (int i = 0; i < static_cast<int>(totalArcNum); ++i) {
std::fprintf(stdout,"%4i -> %4i Area:%5i NormArea:%5.3f\n",OG.SVA[i].s,OG.SVA[i].t,OG.SVA[i].area,OG.SVA[i].norm_area);
std::fprintf(
stdout,
"%4i -> %4i Area:%5i NormArea:%5.3f\n",
OG.SVA[i].s,
OG.SVA[i].t,
OG.SVA[i].area,
OG.SVA[i].norm_area);
AlignPair::Result* curResult = findResult(OG.SVA[i].s, OG.SVA[i].t);
// // missing arc and arc with great error must be recomputed.
if (curResult->err >= percentileThr) {
ProcessArc(OG.SVA[i].s, OG.SVA[i].t, *curResult, ap);
curResult->area = OG.SVA[i].norm_area;
@ -227,44 +243,65 @@ namespace vcg {
std::pair<double, double> dd = curResult->computeAvgErr();
#pragma omp critical
std::memset(buf, '\0', 1024);
std::sprintf(buf, "(%3i/%3zu) %2i -> %2i Aligned AvgErr dd=%f -> dd=%f \n", i+1,totalArcNum,OG.SVA[i].s,OG.SVA[i].t,dd.first,dd.second);
cb(0, buf);
buf.fill('\0');
std::sprintf(
buf.data(),
"(%3i/%3zu) %2i -> %2i Aligned AvgErr dd=%f -> dd=%f \n",
i + 1,
totalArcNum,
OG.SVA[i].s,
OG.SVA[i].t,
dd.first,
dd.second);
cb(0, buf.data());
}
else {
#pragma omp critical
std::memset(buf, '\0', 1024);
std::sprintf(buf, "(%3i/%3zu) %2i -> %2i Failed Alignment of one arc %s\n",i+1,totalArcNum,OG.SVA[i].s,OG.SVA[i].t,vcg::AlignPair::errorMsg(curResult->status));
cb(0, buf);
buf.fill('\0');
std::sprintf(
buf.data(),
"(%3i/%3zu) %2i -> %2i Failed Alignment of one arc %s\n",
i + 1,
totalArcNum,
OG.SVA[i].s,
OG.SVA[i].t,
vcg::AlignPair::errorMsg(curResult->status));
cb(0, buf.data());
}
}
}
// if there are no valid arcs complain and return
if (!hasValidAlign) {
std::memset(buf, '\0', 1024);
std::sprintf(buf, "\n Failure. No successful arc among candidate Alignment arcs. Nothing Done.\n");
cb(0, buf);
buf.fill('\0');
std::sprintf(
buf.data(),
"\n Failure. No successful arc among candidate Alignment arcs. Nothing "
"Done.\n");
cb(0, buf.data());
return;
}
vcg::Distribution<float> H; // stat for printing
for (auto& li : resultList) {
if (li.isValid()) H.Add(li.err);
if (li.isValid())
H.Add(li.err);
}
std::memset(buf, '\0', 1024);
std::sprintf(buf, "Completed Mesh-Mesh Alignment: Avg Err %5.3f; Median %5.3f; 90%% %5.3f\n", H.Avg(), H.Percentile(0.5f), H.Percentile(0.9f));
cb(0, buf);
buf.fill('\0');
std::sprintf(
buf.data(),
"Completed Mesh-Mesh Alignment: Avg Err %5.3f; Median %5.3f; 90%% %5.3f\n",
H.Avg(),
H.Percentile(0.5f),
H.Percentile(0.9f));
cb(0, buf.data());
ProcessGlobal(ap);
}
void ProcessGlobal(vcg::AlignPair::Param &ap) {
char buff[1024];
std::memset(buff, '\0', 1024);
void ProcessGlobal(vcg::AlignPair::Param& ap)
{
/************** Preparing Matrices for global alignment *************/
std::vector<int> GluedIdVec;
std::vector<vcg::Matrix44d> GluedTrVec;
@ -272,7 +309,6 @@ namespace vcg {
std::map<int, std::string> names;
for (auto& ni : nodeMap) {
MeshTree::MeshNode* mn = ni.second;
if (mn->glued) {
GluedIdVec.push_back(mn->Id());
@ -292,7 +328,13 @@ namespace vcg {
AG.BuildGraph(ResVecPtr, GluedTrVec, GluedIdVec);
float StartGlobErr = 0.001f;
while (!AG.GlobalAlign(names, StartGlobErr, 100, ap.MatchMode == vcg::AlignPair::Param::MMRigid, stdout, cb)) {
while (!AG.GlobalAlign(
names,
StartGlobErr,
100,
ap.MatchMode == vcg::AlignPair::Param::MMRigid,
stdout,
cb)) {
StartGlobErr *= 2;
AG.BuildGraph(ResVecPtr, GluedTrVec, GluedIdVec);
}
@ -304,9 +346,9 @@ namespace vcg {
for (std::size_t ii = 0; ii < GluedTrVecOut.size(); ++ii) {
MM(GluedIdVec[ii])->cm.Tr.Import(GluedTrVecOut[ii]);
}
std::sprintf(buff, "Completed Global Alignment (error bound %6.4f)\n", StartGlobErr);
cb(0, buff);
std::string str =
"Completed Global Alignment (error bound " + std::to_string(StartGlobErr) + ")\n";
cb(0, str.c_str());
}
void ProcessArc(int fixId, int movId, vcg::AlignPair::Result &result, vcg::AlignPair::Param ap) {