AABB getAABB() const { AABB aabb; aabb.expandBy(m_objectToWorld(Point(-1, -1, 0))); aabb.expandBy(m_objectToWorld(Point( 1, -1, 0))); aabb.expandBy(m_objectToWorld(Point( 1, 1, 0))); aabb.expandBy(m_objectToWorld(Point(-1, 1, 0))); return aabb; }
AABB getAABB() const { std::set<Float> times; m_objectToWorld->collectKeyframes(times); AABB aabb; for (std::set<Float>::iterator it = times.begin(); it != times.end(); ++it) { const Transform &trafo = m_objectToWorld->eval(*it); aabb.expandBy(trafo(Point( 1, 0, 0))); aabb.expandBy(trafo(Point(-1, 0, 0))); aabb.expandBy(trafo(Point( 0, 1, 0))); aabb.expandBy(trafo(Point( 0, -1, 0))); } return aabb; }
AABB getAABB() const { AABB bounds; bounds.expandBy(m_sampleToCamera(Point(0, 0, 0))); bounds.expandBy(m_sampleToCamera(Point(1, 1, 0))); return m_worldTransform->getSpatialBounds(bounds); }
AABB AnimatedTransform::getSpatialBounds(const AABB &aabb) const { AABB result; if (m_tracks.size() == 0) { for (int j=0; j<8; ++j) result.expandBy(m_transform(aabb.getCorner(j))); } else { /* Compute approximate bounds */ int nSteps = 100; AABB1 timeBounds = getTimeBounds(); Float step = timeBounds.getExtents().x / (nSteps-1); for (int i=0; i<nSteps; ++i) { const Transform &trafo = eval(timeBounds.min.x + step * i); for (int j=0; j<8; ++j) result.expandBy(trafo(aabb.getCorner(j))); } } return result; }
AABB Triangle::getClippedAABB(const Point *positions, const AABB &aabb) const { /* Reserve room for some additional vertices */ Point3d vertices1[MAX_VERTS], vertices2[MAX_VERTS]; int nVertices = 3; /* The kd-tree code will frequently call this function with almost-collapsed AABBs. It's extremely important not to introduce errors in such cases, otherwise the resulting tree will incorrectly remove triangles from the associated nodes. Hence, do the following computation in double precision! */ for (int i=0; i<3; ++i) vertices1[i] = Point3d(positions[idx[i]]); for (int axis=0; axis<3; ++axis) { nVertices = sutherlandHodgman(vertices1, nVertices, vertices2, axis, aabb.min[axis], true); nVertices = sutherlandHodgman(vertices2, nVertices, vertices1, axis, aabb.max[axis], false); } AABB result; for (int i=0; i<nVertices; ++i) { #if defined(SINGLE_PRECISION) for (int j=0; j<3; ++j) { /* Now this is really paranoid! */ double pos_d = vertices1[i][j]; float pos_f = (float) pos_d; float pos_roundedDown, pos_roundedUp; if (pos_f < pos_d) { /* Float value is too small */ pos_roundedDown = pos_f; pos_roundedUp = nextafterf(pos_f, std::numeric_limits<float>::infinity()); } else if (pos_f > pos_d) { /* Float value is too large */ pos_roundedUp = pos_f; pos_roundedDown = nextafterf(pos_f, -std::numeric_limits<float>::infinity()); } else { /* Double value is exactly representable */ pos_roundedDown = pos_roundedUp = pos_f; } result.min[j] = std::min(result.min[j], pos_roundedDown); result.max[j] = std::max(result.max[j], pos_roundedUp); } #else result.expandBy(vertices1[i]); #endif } result.clip(aabb); return result; }
AABB AnimatedTransform::getTranslationBounds() const { if (m_tracks.size() == 0) { Point p = m_transform(Point(0.0f)); return AABB(p, p); } AABB aabb; for (size_t i=0; i<m_tracks.size(); ++i) { const AbstractAnimationTrack *absTrack = m_tracks[i]; switch (absTrack->getType()) { case AbstractAnimationTrack::ETranslationX: case AbstractAnimationTrack::ETranslationY: case AbstractAnimationTrack::ETranslationZ: { int idx = absTrack->getType() - AbstractAnimationTrack::ETranslationX; const FloatTrack *track = static_cast<const FloatTrack *>(absTrack); for (size_t j=0; j<track->getSize(); ++j) { Float value = track->getValue(j); aabb.max[idx] = std::max(aabb.max[idx], value); aabb.min[idx] = std::min(aabb.min[idx], value); } } break; case AbstractAnimationTrack::ETranslationXYZ: { const VectorTrack *track = static_cast<const VectorTrack *>(absTrack); for (size_t j=0; j<track->getSize(); ++j) aabb.expandBy(Point(track->getValue(j))); } break; default: break; } } for (int i=0; i<3; ++i) { if (aabb.min[i] > aabb.max[i]) aabb.min[i] = aabb.max[i] = 0.0f; } return aabb; }