예제 #1
0
bool zCompare(RTShape *lhs, RTShape *rhs) {
  BoundingBox lBox = lhs->getBoundingBox();
  BoundingBox rBox = rhs->getBoundingBox();

  if (lBox.getOrigin().z() < rBox.getOrigin().z()) {
    return true;
  }

  if ((lBox.getOrigin().z() + lBox.getDelta().z())
      < (rBox.getOrigin().z() + rBox.getDelta().z()) ) {
    return true;
  }

  return false;

}
예제 #2
0
float SurfaceAreaHeuristic::findMedian(BoundingBox box, vector<RTShape*> shapes, int axis) {
  
  _box = box;
  _axis = axis;
  _shapes = &shapes;

  sort();

  float cost;
  float bestpos = 0;
  if (shapes.size() == 0) {
    return 0;
  }
  float bestcost = calculateCost(shapes[0]->getBoundingBox().getOrigin().get(axis),0);

  float bmin = box.getOrigin().get(axis);
  float bmax = box.getOrigin().get(axis) + box.getDelta().get(axis);
  
  vector<RTShape*>::iterator it;
  int i=0; 
  for (it = shapes.begin(); it != shapes.end(); ++it) {
    BoundingBox sBox = (*it)->getBoundingBox();

    float min = sBox.getOrigin().get(axis);
    float max = sBox.getOrigin().get(axis) + sBox.getDelta().get(axis);

    if ((cost = calculateCost(min,i)) < bestcost && min > bmin && fabs(min - bmin) > 0.0001) {
      //DPRINTF("%f %f %f\n", min, bmin, min-bmin);
      bestcost = cost; bestpos = min;
    }
    

    //DPRINTF("%d\n", cost);

    if ((cost = calculateCost(max,i)) < bestcost && max < bmax && fabs(max - bmax) > 0.0001) {
      bestcost = cost; bestpos = max;
    }
    //DPRINTF("%d\n", cost);

    i += 1;
  }

  //DPRINTF("\n"); box.print();

  //DPRINTF("%d %d %f\n", i, axis, bestpos);
  return bestpos;
}
예제 #3
0
TEST(RTPolySet, boundingBoxShouldBeUnionOfTriangles) {

  RTPolySet ps;
  RTTriangle t1(Vector(0,0,0), Vector(1,0,0), Vector(1,0,1));
  ps.addTriangle(t1);
  RTTriangle t2(Vector(5,5,5), Vector(6,6,5), Vector(6,6,6));
  ps.addTriangle(t2);

  BoundingBox box = ps.getBoundingBox();

  VECTOR_EQUAL(0,0,0, box.getOrigin());
  VECTOR_EQUAL(6,6,6, box.getDelta());

}