Skip to content

Commit

Permalink
Merge pull request #1558 from nh2/issue-1557-fix-trivial-per-triangle…
Browse files Browse the repository at this point in the history
…-division-overflow-main

Fix division overflow in "Trivial per triangle" for 0-area faces
  • Loading branch information
alemuntoni authored Dec 17, 2024
2 parents ad55b47 + 694483c commit c6e230c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/meshlabplugins/filter_texture/filter_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,17 @@ std::map<std::string, QVariant> FilterTexturePlugin::applyFilter(
}

// Creates buckets containing each halfening level triangles (a histogram)
int buckSize = (int)ceil(log_2(maxArea/minArea) + DBL_EPSILON);
// Using the logarithm law
// log_2(maxArea / minArea)
// = log_2(maxArea) - log_2(minArea)
// but the latter does not overflow the division if `minArea = DBL_MIN`
// as set above for `area == 0`.
int buckSize = (int)ceil(log_2(maxArea) - log_2(minArea) + DBL_EPSILON);
std::vector<std::vector<uint> > buckets(buckSize);
for (uint i=0; i<areas.size(); ++i)
if (areas[i]>=0)
{
int slot = (int)ceil(log_2(maxArea/areas[i]) + DBL_EPSILON) - 1;
int slot = (int)ceil(log_2(maxArea) - log_2(areas[i]) + DBL_EPSILON) - 1;
assert(slot < buckSize && slot >= 0);
buckets[slot].push_back(i);
}
Expand Down

0 comments on commit c6e230c

Please sign in to comment.