2

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 need something that would work also for more complex 3D models that may also be concave. thanks in advance

Community
  • 1
  • 1
theosem
  • 1,174
  • 3
  • 10
  • 22

1 Answers1

3

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();    
}
brainjam
  • 18,863
  • 8
  • 57
  • 82
hansmaad
  • 18,417
  • 9
  • 53
  • 94
  • hi hansmaad, thanks for answering. this is an interesting approach so I will test it and post any comments. thanks again – theosem Mar 16 '11 at 13:29
  • Hi tsemer, I wrote this solution last week. I am happy that some one else can test it:) The results __look__ good and the performance is ok for me. Pls tell me if you found mistakes ore better techniques. – hansmaad Mar 16 '11 at 15:17