diff --git a/include/Vector.h b/include/Vector.h index 18c46b8e..488955fa 100644 --- a/include/Vector.h +++ b/include/Vector.h @@ -25,21 +25,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include "boost/cstdint.hpp" -#include namespace PolyVox { - //template class Matrix; //Forward declaration - ///Represents a vector in space. template class Vector - : boost::addable< Vector // Vector + Vector - , boost::subtractable< Vector // Vector - Vector - , boost::dividable2< Vector, Type // Vector / Type - , boost::multipliable2< Vector, Type // Vector * Type, Type * Vector - , boost::equality_comparable1< Vector // Vector != Vector - > > > > > { public: ///Constructor. @@ -113,24 +104,38 @@ namespace PolyVox }; //Non-member overloaded operators. - //!Multiplication operator. - //template - //Vector operator*(const Vector& lhs, const Matrix& rhs) throw(); - //!Multiplication operator. - //template - //Vector operator*(const Matrix& lhs, const Vector& rhs) throw(); + ///Addition operator. + template + Vector operator+(const Vector& lhs, const Vector& rhs) throw(); + ///Subtraction operator. + template + Vector operator-(const Vector& lhs, const Vector& rhs) throw(); + ///Multiplication operator. + template + Vector operator*(const Vector& lhs, const Type& rhs) throw(); + ///Division operator. + template + Vector operator/(const Vector& lhs, const Type& rhs) throw(); ///Stream insertion operator. template std::ostream& operator<<(std::ostream& os, const Vector& vector) throw(); //Some handy typedefs + ///A 3D Vector of floats. typedef Vector<3,float> Vector3DFloat; + ///A 3D Vector of doubles. typedef Vector<3,double> Vector3DDouble; + ///A 3D Vector of signed 8-bit values. typedef Vector<3,boost::int8_t> Vector3DInt8; + ///A 3D Vector of unsigned 8-bit values. typedef Vector<3,boost::uint8_t> Vector3DUint8; + ///A 3D Vector of signed 16-bit values. typedef Vector<3,boost::int16_t> Vector3DInt16; + ///A 3D Vector of unsigned 16-bit values. typedef Vector<3,boost::uint16_t> Vector3DUint16; + ///A 3D Vector of signed 32-bit values. typedef Vector<3,boost::int32_t> Vector3DInt32; + ///A 3D Vector of unsigned 32-bit values. typedef Vector<3,boost::uint32_t> Vector3DUint32; diff --git a/include/Vector.inl b/include/Vector.inl index 2560fd16..c084edca 100644 --- a/include/Vector.inl +++ b/include/Vector.inl @@ -194,22 +194,7 @@ namespace PolyVox return false; } return false; - } - - /** - Subtraction operator subtracts corresponding elements of one Vector from the other. - \param rhs Vector to subtract - \return The resulting Vector. - */ - template - inline Vector& Vector::operator-=(const Vector& rhs) throw() - { - for(boost::uint32_t ct = 0; ct < Size; ++ct) - { - m_tElements[ct] -= rhs.m_tElements[ct]; - } - return *this; - } + } /** Addition operator adds corresponding elements of the two Vectors. @@ -226,6 +211,21 @@ namespace PolyVox return *this; } + /** + Subtraction operator subtracts corresponding elements of one Vector from the other. + \param rhs Vector to subtract + \return The resulting Vector. + */ + template + inline Vector& Vector::operator-=(const Vector& rhs) throw() + { + for(boost::uint32_t ct = 0; ct < Size; ++ct) + { + m_tElements[ct] -= rhs.m_tElements[ct]; + } + return *this; + } + /** Multiplication operator multiplies each element of the Vector by a number. \param rhs the number the Vector is multiplied by. @@ -256,56 +256,6 @@ namespace PolyVox return *this; } - /** - Multiplies a Vector and a Matrix. - - NOTE: Although the Vector class does not distinguish between row and column vectors, the Vector - must conceptually be in row form for this operation to make sense. - \param lhs The Vector to be multiplied - \param rhs The Matrix to multiply by. - \return The resulting Vector - */ - /*template - Vector operator*(const Vector& lhs, const Matrix& rhs) throw() - { - Type tZero = static_cast(0); - Vector result(tZero,tZero,tZero); - for(boost::uint32_t colCt = 0; colCt < Size; ++colCt) - { - for(boost::uint32_t rowCt = 0; rowCt < Size; ++rowCt) - { - //result(colCt) += lhs(rowCt) * rhs(rowCt, colCt); - result.set(colCt, result(colCt) + (lhs(rowCt) * rhs(rowCt, colCt))); - } - } - return result; - }*/ - - /** - Multiplies a Matrix and a Vector. - - NOTE: Although the Vector class does not distinguish between row and column vectors, the Vector - must conceptually be in column form for this operation to make sense. - \param lhs The Matrix to be multiplied - \param rhs The Vector to multiply by. - \return The resulting Vector - */ - /*template - Vector operator*(const Matrix& lhs, const Vector& rhs) throw() - { - Type tZero = static_cast(0); - Vector result(tZero,tZero,tZero); - for(boost::uint32_t rowCt = 0; rowCt < Size; ++rowCt) - { - for(boost::uint32_t colCt = 0; colCt < Size; ++colCt) - { - //result(rowCt) += lhs(rowCt,colCt) * rhs(colCt); - result.set(rowCt, result(rowCt) + (lhs(rowCt,colCt) * rhs(colCt))); - } - } - return result; - }*/ - /** Enables the Vector to be used intuitively with output streams such as cout. \param os The output stream to write to. @@ -525,4 +475,60 @@ namespace PolyVox m_tElements[ct] /= static_cast(length); } } + + /** + Addition operator adds corresponding elements of the two Vectors. + \param lhs Vector to add to. + \param rhs Vector to add. + \return The resulting Vector. + */ + template + Vector operator+(const Vector& lhs, const Vector& rhs) throw() + { + Vector result = lhs; + result += rhs; + return result; + } + + /** + Subtraction operator subtracts corresponding elements of one Vector from the other. + \param lhs Vector to subtract from. + \param rhs Vector to subtract. + \return The resulting Vector. + */ + template + Vector operator-(const Vector& lhs, const Vector& rhs) throw() + { + Vector result = lhs; + result -= rhs; + return result; + } + + /** + Multiplication operator multiplies each element of the Vector by a number. + \param lhs the Vector to multiply. + \param rhs the number the Vector is multiplied by. + \return The resulting Vector. + */ + template + Vector operator*(const Vector& lhs, const Type& rhs) throw() + { + Vector result = lhs; + result *= rhs; + return result; + } + + /** + Division operator divides each element of the Vector by a number. + \param lhs the Vector to divide. + \param rhs the number the Vector is divided by. + \return The resulting Vector. + */ + template + Vector operator/(const Vector& lhs, const Type& rhs) throw() + { + Vector result = lhs; + result /= rhs; + return result; + } }//namespace Thermite diff --git a/source/SurfaceExtractors.cpp b/source/SurfaceExtractors.cpp index 83e3ce24..07cda5f3 100644 --- a/source/SurfaceExtractors.cpp +++ b/source/SurfaceExtractors.cpp @@ -383,7 +383,7 @@ namespace PolyVox volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ+1.0)); } const Vector3DFloat gradCeil = computeSobelGradient(volIter); - result = ((gradFloor + gradCeil) * -1.0); + result = ((gradFloor + gradCeil) * -1.0f); if(result.lengthSquared() < 0.0001) { //Operation failed - fall back on simple gradient estimation @@ -407,7 +407,7 @@ namespace PolyVox volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ+1.0)); } const Vector3DFloat gradCeil = computeCentralDifferenceGradient(volIter); - result = ((gradFloor + gradCeil) * -1.0); + result = ((gradFloor + gradCeil) * -1.0f); if(result.lengthSquared() < 0.0001) { //Operation failed - fall back on simple gradient estimation @@ -785,7 +785,7 @@ namespace PolyVox volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ+1.0)); } const Vector3DFloat gradCeil = computeSobelGradient(volIter); - result = ((gradFloor + gradCeil) * -1.0); + result = ((gradFloor + gradCeil) * -1.0f); if(result.lengthSquared() < 0.0001) { //Operation failed - fall back on simple gradient estimation @@ -809,7 +809,7 @@ namespace PolyVox volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ+1.0)); } const Vector3DFloat gradCeil = computeSmoothCentralDifferenceGradient(volIter); - result = ((gradFloor + gradCeil) * -1.0); + result = ((gradFloor + gradCeil) * -1.0f); if(result.lengthSquared() < 0.0001) { //Operation failed - fall back on simple gradient estimation