changed dimension functions to constants to fix compilation on windows

metadata
Wenzel Jakob 2010-11-13 02:14:22 +01:00
parent e1fb65b170
commit f2f4f94bdf
4 changed files with 61 additions and 59 deletions

View File

@ -62,7 +62,7 @@ template <typename T> struct TAABB {
inline TAABB(const point_type &min, const point_type &max) inline TAABB(const point_type &min, const point_type &max)
: min(min), max(max) { : min(min), max(max) {
#if defined(MTS_DEBUG) #if defined(MTS_DEBUG)
for (int i=0; i<point_type::dim(); ++i) for (int i=0; i<point_type::dim; ++i)
SAssert(min[i] <= max[i]); SAssert(min[i] <= max[i]);
#endif #endif
} }
@ -79,7 +79,7 @@ template <typename T> struct TAABB {
/// Clip to another bounding box /// Clip to another bounding box
inline void clip(const TAABB &aabb) { inline void clip(const TAABB &aabb) {
for (int i=0; i<point_type::dim(); ++i) { for (int i=0; i<point_type::dim; ++i) {
min[i] = std::max(min[i], aabb.min[i]); min[i] = std::max(min[i], aabb.min[i]);
max[i] = std::min(max[i], aabb.max[i]); max[i] = std::min(max[i], aabb.max[i]);
} }
@ -114,7 +114,7 @@ template <typename T> struct TAABB {
/// Check whether a point lies on or inside the bounding box /// Check whether a point lies on or inside the bounding box
inline bool contains(const point_type &vec) const { inline bool contains(const point_type &vec) const {
for (int i=0; i<point_type::dim(); ++i) for (int i=0; i<point_type::dim; ++i)
if (vec[i] < min[i] || vec[i] > max[i]) if (vec[i] < min[i] || vec[i] > max[i])
return false; return false;
return true; return true;
@ -124,7 +124,7 @@ template <typename T> struct TAABB {
inline bool contains(const TAABB &aabb) const { inline bool contains(const TAABB &aabb) const {
if (!isValid()) if (!isValid())
return false; return false;
for (int i=0; i<point_type::dim(); ++i) for (int i=0; i<point_type::dim; ++i)
if (aabb.min[i] < min[i] || aabb.max[i] > max[i]) if (aabb.min[i] < min[i] || aabb.max[i] > max[i])
return false; return false;
return true; return true;
@ -132,7 +132,7 @@ template <typename T> struct TAABB {
/// Axis-aligned bounding box overlap test /// Axis-aligned bounding box overlap test
inline bool overlaps(const TAABB &aabb) const { inline bool overlaps(const TAABB &aabb) const {
for (int i=0; i<point_type::dim(); ++i) for (int i=0; i<point_type::dim; ++i)
if (max[i] < aabb.min[i] || min[i] > aabb.max[i]) if (max[i] < aabb.min[i] || min[i] > aabb.max[i])
return false; return false;
return true; return true;
@ -140,7 +140,7 @@ template <typename T> struct TAABB {
/// Expand the bounding box to contain another point /// Expand the bounding box to contain another point
inline void expandBy(const point_type &p) { inline void expandBy(const point_type &p) {
for (int i=0; i<point_type::dim(); ++i) { for (int i=0; i<point_type::dim; ++i) {
min[i] = std::min(min[i], p[i]); min[i] = std::min(min[i], p[i]);
max[i] = std::max(max[i], p[i]); max[i] = std::max(max[i], p[i]);
} }
@ -148,7 +148,7 @@ template <typename T> struct TAABB {
/// Expand the bounding box to contain another bounding box /// Expand the bounding box to contain another bounding box
inline void expandBy(const TAABB &aabb) { inline void expandBy(const TAABB &aabb) {
for (int i=0; i<point_type::dim(); ++i) { for (int i=0; i<point_type::dim; ++i) {
min[i] = std::min(min[i], aabb.min[i]); min[i] = std::min(min[i], aabb.min[i]);
max[i] = std::max(max[i], aabb.max[i]); max[i] = std::max(max[i], aabb.max[i]);
} }
@ -157,7 +157,7 @@ template <typename T> struct TAABB {
/// Calculate the point-AABB distance /// Calculate the point-AABB distance
inline value_type distanceTo(const point_type &p) const { inline value_type distanceTo(const point_type &p) const {
value_type result = 0; value_type result = 0;
for (int i=0; i<point_type::dim(); ++i) { for (int i=0; i<point_type::dim; ++i) {
value_type value = 0; value_type value = 0;
if (p[i] < min[i]) if (p[i] < min[i])
value = min[i] - p[i]; value = min[i] - p[i];
@ -170,7 +170,7 @@ template <typename T> struct TAABB {
/// Return whether this bounding box is valid /// Return whether this bounding box is valid
inline bool isValid() const { inline bool isValid() const {
for (int i=0; i<point_type::dim(); ++i) for (int i=0; i<point_type::dim; ++i)
if (max[i] < min[i]) if (max[i] < min[i])
return false; return false;
return true; return true;
@ -184,7 +184,7 @@ template <typename T> struct TAABB {
* is considered nonempty. * is considered nonempty.
*/ */
inline bool isEmpty() const { inline bool isEmpty() const {
for (int i=0; i<point_type::dim(); ++i) { for (int i=0; i<point_type::dim; ++i) {
if (max[i] > min[i]) if (max[i] > min[i])
return false; return false;
} }
@ -196,7 +196,7 @@ template <typename T> struct TAABB {
Vector d = max - min; Vector d = max - min;
int largest = 0; int largest = 0;
for (int i=1; i<point_type::dim(); ++i) for (int i=1; i<point_type::dim; ++i)
if (d[i] > d[largest]) if (d[i] > d[largest])
largest = i; largest = i;
return largest; return largest;
@ -207,7 +207,7 @@ template <typename T> struct TAABB {
Vector d = max - min; Vector d = max - min;
int shortest = 0; int shortest = 0;
for (int i=1; i<point_type::dim(); ++i) for (int i=1; i<point_type::dim; ++i)
if (d[i] < d[shortest]) if (d[i] < d[shortest])
shortest = i; shortest = i;
return shortest; return shortest;

View File

@ -33,6 +33,9 @@ template <typename T> struct TPoint2 {
T x, y; T x, y;
/// Number of dimensions
const static int dim = 2;
/** \brief Construct a new point without initializing it. /** \brief Construct a new point without initializing it.
* *
* This construtor is useful when the point will either not * This construtor is useful when the point will either not
@ -174,9 +177,6 @@ template <typename T> struct TPoint2 {
stream->writeElement<T>(y); stream->writeElement<T>(y);
} }
/// Return the number of dimensions
inline static int dim() { return 2; }
/// Return a readable string representation of this point /// Return a readable string representation of this point
std::string toString() const { std::string toString() const {
std::ostringstream oss; std::ostringstream oss;
@ -225,6 +225,9 @@ template <typename T> struct TPoint3 {
T x, y, z; T x, y, z;
/// Number of dimensions
const static int dim = 3;
/** \brief Construct a new point without initializing it. /** \brief Construct a new point without initializing it.
* *
* This construtor is useful when the point will either not * This construtor is useful when the point will either not
@ -368,8 +371,6 @@ template <typename T> struct TPoint3 {
stream->writeElement<T>(z); stream->writeElement<T>(z);
} }
/// Return the number of dimensions
inline static int dim() { return 3; }
/// Return a readable string representation of this point /// Return a readable string representation of this point
std::string toString() const { std::string toString() const {
@ -419,6 +420,9 @@ template <typename T> struct TPoint4 {
typedef TVector4<T> vector_type; typedef TVector4<T> vector_type;
T x, y, z, w; T x, y, z, w;
/// Number of dimensions
const static int dim = 4;
/** \brief Construct a new point without initializing it. /** \brief Construct a new point without initializing it.
* *
@ -564,10 +568,7 @@ template <typename T> struct TPoint4 {
stream->writeElement<T>(z); stream->writeElement<T>(z);
stream->writeElement<T>(w); stream->writeElement<T>(w);
} }
/// Return the number of dimensions
inline static int dim() { return 4; }
/// Return a readable string representation of this point /// Return a readable string representation of this point
std::string toString() const { std::string toString() const {
std::ostringstream oss; std::ostringstream oss;

View File

@ -33,6 +33,9 @@ template <typename T> struct TVector2 {
T x, y; T x, y;
/// Number of dimensions
const static int dim = 2;
/** \brief Construct a new vector without initializing it. /** \brief Construct a new vector without initializing it.
* *
* This construtor is useful when the vector will either not * This construtor is useful when the vector will either not
@ -168,9 +171,6 @@ template <typename T> struct TVector2 {
stream->writeElement<T>(y); stream->writeElement<T>(y);
} }
/// Return the number of dimensions
inline static int dim() { return 2; }
/// Return a readable string representation of this vector /// Return a readable string representation of this vector
std::string toString() const { std::string toString() const {
std::ostringstream oss; std::ostringstream oss;
@ -223,6 +223,9 @@ template <typename T> struct TVector3 {
typedef TPoint3<T> point_type; typedef TPoint3<T> point_type;
T x, y, z; T x, y, z;
/// Number of dimensions
const static int dim = 3;
/** \brief Construct a new vector without initializing it. /** \brief Construct a new vector without initializing it.
* *
@ -361,9 +364,6 @@ template <typename T> struct TVector3 {
stream->writeElement<T>(z); stream->writeElement<T>(z);
} }
/// Return the number of dimensions
inline static int dim() { return 3; }
/// Return a readable string representation of this vector /// Return a readable string representation of this vector
std::string toString() const { std::string toString() const {
std::ostringstream oss; std::ostringstream oss;
@ -427,6 +427,10 @@ template <typename T> struct TVector4 {
typedef TPoint4<T> point_type; typedef TPoint4<T> point_type;
T x, y, z, w; T x, y, z, w;
/// Number of dimensions
const static int dim = 3;
/** \brief Construct a new vector without initializing it. /** \brief Construct a new vector without initializing it.
* *
@ -567,9 +571,6 @@ template <typename T> struct TVector4 {
stream->writeElement<T>(w); stream->writeElement<T>(w);
} }
/// Return the number of dimensions
inline static int dim() { return 4; }
/// Return a readable string representation of this vector /// Return a readable string representation of this vector
std::string toString() const { std::string toString() const {
std::ostringstream oss; std::ostringstream oss;

View File

@ -1536,7 +1536,7 @@ protected:
aabb = cast()->getAABB(index); aabb = cast()->getAABB(index);
} }
for (int axis=0; axis<point_type::dim(); ++axis) { for (int axis=0; axis<point_type::dim; ++axis) {
float min = (float) aabb.min[axis], max = (float) aabb.max[axis]; float min = (float) aabb.min[axis], max = (float) aabb.max[axis];
if (min == max) { if (min == max) {
@ -1898,15 +1898,15 @@ protected:
/* Initially, the split plane is placed left of the scene /* Initially, the split plane is placed left of the scene
and thus all geometry is on its right side */ and thus all geometry is on its right side */
size_type numLeft[point_type::dim()], size_type numLeft[point_type::dim],
numRight[point_type::dim()]; numRight[point_type::dim];
for (int i=0; i<point_type::dim(); ++i) { for (int i=0; i<point_type::dim; ++i) {
numLeft[i] = 0; numLeft[i] = 0;
numRight[i] = primCount; numRight[i] = primCount;
} }
EdgeEvent *eventsByAxis[point_type::dim()]; EdgeEvent *eventsByAxis[point_type::dim];
int eventsByAxisCtr = 1; int eventsByAxisCtr = 1;
eventsByAxis[0] = eventStart; eventsByAxis[0] = eventStart;
@ -1957,7 +1957,7 @@ protected:
/* Keep track of the beginning of dimensions */ /* Keep track of the beginning of dimensions */
if (event < eventEnd && event->axis != axis) { if (event < eventEnd && event->axis != axis) {
KDAssert(eventsByAxisCtr < point_type::dim()); KDAssert(eventsByAxisCtr < point_type::dim);
eventsByAxis[eventsByAxisCtr++] = event; eventsByAxis[eventsByAxisCtr++] = event;
} }
@ -2035,9 +2035,9 @@ protected:
#if defined(MTS_KD_DEBUG) #if defined(MTS_KD_DEBUG)
/* Sanity checks. Everything should now be left of the split plane */ /* Sanity checks. Everything should now be left of the split plane */
for (int i=0; i<point_type::dim(); ++i) for (int i=0; i<point_type::dim; ++i)
KDAssert(numRight[i] == 0 && numLeft[i] == primCount); KDAssert(numRight[i] == 0 && numLeft[i] == primCount);
for (int i=1; i<point_type::dim(); ++i) for (int i=1; i<point_type::dim; ++i)
KDAssert(eventsByAxis[i]->axis == i && (eventsByAxis[i]-1)->axis == i-1); KDAssert(eventsByAxis[i]->axis == i && (eventsByAxis[i]-1)->axis == i-1);
#endif #endif
@ -2114,9 +2114,9 @@ protected:
EdgeEvent *leftEventsStart, *rightEventsStart; EdgeEvent *leftEventsStart, *rightEventsStart;
if (isLeftChild) { if (isLeftChild) {
leftEventsStart = eventStart; leftEventsStart = eventStart;
rightEventsStart = rightAlloc.allocate<EdgeEvent>(bestSplit.numRight * 2 * point_type::dim()); rightEventsStart = rightAlloc.allocate<EdgeEvent>(bestSplit.numRight * 2 * point_type::dim);
} else { } else {
leftEventsStart = leftAlloc.allocate<EdgeEvent>(bestSplit.numLeft * 2 * point_type::dim()); leftEventsStart = leftAlloc.allocate<EdgeEvent>(bestSplit.numLeft * 2 * point_type::dim);
rightEventsStart = eventStart; rightEventsStart = eventStart;
} }
@ -2134,10 +2134,10 @@ protected:
if (m_clip) { if (m_clip) {
EdgeEvent EdgeEvent
*leftEventsTempStart = leftAlloc.allocate<EdgeEvent>(primsLeft * 2 * point_type::dim()), *leftEventsTempStart = leftAlloc.allocate<EdgeEvent>(primsLeft * 2 * point_type::dim),
*rightEventsTempStart = rightAlloc.allocate<EdgeEvent>(primsRight * 2 * point_type::dim()), *rightEventsTempStart = rightAlloc.allocate<EdgeEvent>(primsRight * 2 * point_type::dim),
*newEventsLeftStart = leftAlloc.allocate<EdgeEvent>(primsBoth * 2 * point_type::dim()), *newEventsLeftStart = leftAlloc.allocate<EdgeEvent>(primsBoth * 2 * point_type::dim),
*newEventsRightStart = rightAlloc.allocate<EdgeEvent>(primsBoth * 2 * point_type::dim()); *newEventsRightStart = rightAlloc.allocate<EdgeEvent>(primsBoth * 2 * point_type::dim);
EdgeEvent *leftEventsTempEnd = leftEventsTempStart, EdgeEvent *leftEventsTempEnd = leftEventsTempStart,
*rightEventsTempEnd = rightEventsTempStart, *rightEventsTempEnd = rightEventsTempStart,
@ -2165,7 +2165,7 @@ protected:
KDAssert(rightNodeAABB.contains(clippedRight)); KDAssert(rightNodeAABB.contains(clippedRight));
if (clippedLeft.isValid() && clippedLeft.getSurfaceArea() > 0) { if (clippedLeft.isValid() && clippedLeft.getSurfaceArea() > 0) {
for (int axis=0; axis<point_type::dim(); ++axis) { for (int axis=0; axis<point_type::dim; ++axis) {
float min = (float) clippedLeft.min[axis], float min = (float) clippedLeft.min[axis],
max = (float) clippedLeft.max[axis]; max = (float) clippedLeft.max[axis];
@ -2187,7 +2187,7 @@ protected:
} }
if (clippedRight.isValid() && clippedRight.getSurfaceArea() > 0) { if (clippedRight.isValid() && clippedRight.getSurfaceArea() > 0) {
for (int axis=0; axis<point_type::dim(); ++axis) { for (int axis=0; axis<point_type::dim; ++axis) {
float min = (float) clippedRight.min[axis], float min = (float) clippedRight.min[axis],
max = (float) clippedRight.max[axis]; max = (float) clippedRight.max[axis];
@ -2214,10 +2214,10 @@ protected:
} }
} }
KDAssert((size_type) (leftEventsTempEnd - leftEventsTempStart) <= primsLeft * 2 * point_type::dim()); KDAssert((size_type) (leftEventsTempEnd - leftEventsTempStart) <= primsLeft * 2 * point_type::dim);
KDAssert((size_type) (rightEventsTempEnd - rightEventsTempStart) <= primsRight * 2 * point_type::dim()); KDAssert((size_type) (rightEventsTempEnd - rightEventsTempStart) <= primsRight * 2 * point_type::dim);
KDAssert((size_type) (newEventsLeftEnd - newEventsLeftStart) <= primsBoth * 2 * point_type::dim()); KDAssert((size_type) (newEventsLeftEnd - newEventsLeftStart) <= primsBoth * 2 * point_type::dim);
KDAssert((size_type) (newEventsRightEnd - newEventsRightStart) <= primsBoth * 2 * point_type::dim()); KDAssert((size_type) (newEventsRightEnd - newEventsRightStart) <= primsBoth * 2 * point_type::dim);
ctx.pruned += prunedLeft + prunedRight; ctx.pruned += prunedLeft + prunedRight;
/* Sort the events from overlapping prims */ /* Sort the events from overlapping prims */
@ -2256,8 +2256,8 @@ protected:
*rightEventsEnd++ = *event; *rightEventsEnd++ = *event;
} }
} }
KDAssert((size_type) (leftEventsEnd - leftEventsStart) <= bestSplit.numLeft * 2 * point_type::dim()); KDAssert((size_type) (leftEventsEnd - leftEventsStart) <= bestSplit.numLeft * 2 * point_type::dim);
KDAssert((size_type) (rightEventsEnd - rightEventsStart) <= bestSplit.numRight * 2 * point_type::dim()); KDAssert((size_type) (rightEventsEnd - rightEventsStart) <= bestSplit.numRight * 2 * point_type::dim);
} }
/* Shrink the edge event storage now that we know exactly how /* Shrink the edge event storage now that we know exactly how
@ -2343,8 +2343,8 @@ protected:
*/ */
struct MinMaxBins { struct MinMaxBins {
MinMaxBins(size_type nBins) : m_binCount(nBins) { MinMaxBins(size_type nBins) : m_binCount(nBins) {
m_minBins = new size_type[m_binCount*point_type::dim()]; m_minBins = new size_type[m_binCount*point_type::dim];
m_maxBins = new size_type[m_binCount*point_type::dim()]; m_maxBins = new size_type[m_binCount*point_type::dim];
} }
~MinMaxBins() { ~MinMaxBins() {
@ -2358,7 +2358,7 @@ protected:
void setAABB(const AABBType &aabb) { void setAABB(const AABBType &aabb) {
m_aabb = aabb; m_aabb = aabb;
m_binSize = m_aabb.getExtents() / (Float) m_binCount; m_binSize = m_aabb.getExtents() / (Float) m_binCount;
for (int axis=0; axis<point_type::dim(); ++axis) for (int axis=0; axis<point_type::dim; ++axis)
m_invBinSize[axis] = 1/m_binSize[axis]; m_invBinSize[axis] = 1/m_binSize[axis];
} }
@ -2373,13 +2373,13 @@ protected:
void bin(const Derived *derived, index_type *indices, void bin(const Derived *derived, index_type *indices,
size_type primCount) { size_type primCount) {
m_primCount = primCount; m_primCount = primCount;
memset(m_minBins, 0, sizeof(size_type) * point_type::dim() * m_binCount); memset(m_minBins, 0, sizeof(size_type) * point_type::dim * m_binCount);
memset(m_maxBins, 0, sizeof(size_type) * point_type::dim() * m_binCount); memset(m_maxBins, 0, sizeof(size_type) * point_type::dim * m_binCount);
const int64_t maxBin = m_binCount-1; const int64_t maxBin = m_binCount-1;
for (size_type i=0; i<m_primCount; ++i) { for (size_type i=0; i<m_primCount; ++i) {
const AABBType aabb = derived->getAABB(indices[i]); const AABBType aabb = derived->getAABB(indices[i]);
for (int axis=0; axis<point_type::dim(); ++axis) { for (int axis=0; axis<point_type::dim; ++axis) {
int64_t minIdx = (int64_t) ((aabb.min[axis] - m_aabb.min[axis]) int64_t minIdx = (int64_t) ((aabb.min[axis] - m_aabb.min[axis])
* m_invBinSize[axis]); * m_invBinSize[axis]);
int64_t maxIdx = (int64_t) ((aabb.max[axis] - m_aabb.min[axis]) int64_t maxIdx = (int64_t) ((aabb.max[axis] - m_aabb.min[axis])
@ -2403,7 +2403,7 @@ protected:
Float normalization = 2.0f / m_aabb.getSurfaceArea(); Float normalization = 2.0f / m_aabb.getSurfaceArea();
int binIdx = 0, leftBin = 0; int binIdx = 0, leftBin = 0;
for (int axis=0; axis<point_type::dim(); ++axis) { for (int axis=0; axis<point_type::dim; ++axis) {
vector_type extents = m_aabb.getExtents(); vector_type extents = m_aabb.getExtents();
size_type numLeft = 0, numRight = m_primCount; size_type numLeft = 0, numRight = m_primCount;
Float leftWidth = 0, rightWidth = extents[axis]; Float leftWidth = 0, rightWidth = extents[axis];