Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix division overflow in "Trivial per triangle" for 0-area faces #1558

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading