I seek for a method/algorithm for uniform sampling of the surface of 3D models in C++. I have found methods for uniform sampling of unit sphere such as this and this but I 开发者_如何学Goneed something that would work also for more complex 3D models that may also be concave. thanks in advance
What I do: My model consists of many different primitives (triangles, quads, disks, cylinder...). For each primitive I can implement a random picking method (e.g. http://mathworld.wolfram.com/TrianglePointPicking.html). Each primitve can compute its surface Area. The higher the area of the primitive the higher its probability to generate a random point. In my model I build a cumulative list like this
class Model{
// ...
vector<pair<double, Primitive*> > primitives_;
}
void Model::AddPrimitive(Primitive* p)
{
double area = p->Area();
if (!primitves_.empty())
area += primitives_.back().first;
primitives_.push_back(make_pair(area, p));
}
When I generate a random point on the model I first choose a random primitive and then a random point on this primitive.
Point Model::RandomPoint()
{
double maxArea = primitives_.back().first;
double rnd = maxArea * Uniform01(); // random in [0; maxArea]
Iterator it = std::lower_bound(
primitives_.begin(), primitives_.end(), rnd, FirstLess());
return it->second->RandomPoint();
}
精彩评论