开发者

uniform sampling of a 3D model

开发者 https://www.devze.com 2023-02-16 23:00 出处:网络
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

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();    
}
0

精彩评论

暂无评论...
验证码 换一张
取 消