Skip to content

Commit

Permalink
Merge pull request #895 from Idclip/revert_node_union_changes
Browse files Browse the repository at this point in the history
Revert Node Union changes (ABI breaking)
  • Loading branch information
Idclip authored Dec 7, 2020
2 parents 931843a + d126c18 commit 2912576
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 93 deletions.
5 changes: 0 additions & 5 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ Version 7.2.0 - In Development
- tools::csgUnion, tools::csgIntersection and tools::csgDifference now use
the new parallel breadth-first algorithms for much faster performance.
- Extended tree::NodeManager to allow for use with a const tree.
- Vector, Matrix and Quaternion types now satisfy the Trivial Type requirement.
Their empty constructors and copy constructors have been removed (and are left
to the compiler to define).
- Added math::Abs, math::cwiseAdd, math::cwiseLessThan and
math::cwiseGreaterThan methods for Matrix types. Matrix grids can now be
instantiated.
Expand Down Expand Up @@ -52,8 +49,6 @@ Version 7.2.0 - In Development
tools::CsgVisitorIntersection and tools::CsgVisitorDifference. The CSG
tools now use the parallel breath-first algorithms.
- Moved openvdb::TypeList from Types.h into its own header TypeList.h
- Removed an unnecessary specialization of NodeUnion and CopyTraits from
NodeUnion.h. Replaced std::is_pod usage with std::is_trivially_copyable.

Build:
- Removed the Makefiles.
Expand Down
5 changes: 0 additions & 5 deletions doc/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ Improvements:
parallel breadth-first algorithms for much faster performance.
- Extended @vdblink::tree::NodeManager NodeManager@endlink to allow for use with
a const tree.
- Vector, Matrix and Quaternion types now satisfy the Trivial Type requirement.
Their empty constructors and copy constructors have been removed (and are left
to the compiler to define).
- Added @vdblink::math::Abs Abs@endlink, @vdblink::math::cwiseAdd cwiseAdd@endlink,
@vdblink::math::cwiseLessThan cwiseLessThan@endlink and
@vdblink::math::cwiseGreaterThan cwiseGreaterThan@endlink methods for Matrix types.
Expand Down Expand Up @@ -69,8 +66,6 @@ API changes:
tools::CsgVisitorIntersection and tools::CsgVisitorDifference. The CSG tools
now use the parallel breath-first algorithms.
- Moved openvdb::TypeList from Types.h into its own header TypeList.h
- Removed an unnecessary specialization of @vdblink::tree::NodeUnion NodeUnion@endlink
and CopyTraits from NodeUnion.h. Replaced std::is_pod usage with std::is_trivially_copyable.

@par
Build:
Expand Down
25 changes: 20 additions & 5 deletions openvdb/openvdb/math/Mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,31 @@ class Mat
using ValueType = T;
enum SIZE_ { size = SIZE };

/// Trivial constructor, the matrix is NOT initialized
/// @note destructor, copy constructor, assignment operator and
/// move constructor are left to be defined by the compiler (default)
Mat() = default;

// Number of cols, rows, elements
static unsigned numRows() { return SIZE; }
static unsigned numColumns() { return SIZE; }
static unsigned numElements() { return SIZE*SIZE; }

/// Default ctor. Does nothing. Required because declaring a copy (or
/// other) constructor means the default constructor gets left out.
Mat() { }

/// Copy constructor. Used when the class signature matches exactly.
Mat(Mat const &src) {
for (unsigned i(0); i < numElements(); ++i) {
mm[i] = src.mm[i];
}
}

Mat& operator=(Mat const& src) {
if (&src != this) {
for (unsigned i = 0; i < numElements(); ++i) {
mm[i] = src.mm[i];
}
}
return *this;
}

/// @return string representation of matrix
/// Since output is multiline, optional indentation argument prefixes
/// each newline with that much white space. It does not indent
Expand Down
18 changes: 11 additions & 7 deletions openvdb/openvdb/math/Mat3.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ class Mat3: public Mat<3, T>
using value_type = T;
using ValueType = T;
using MyBase = Mat<3, T>;

/// Trivial constructor, the matrix is NOT initialized
/// @note destructor, copy constructor, assignment operator and
/// move constructor are left to be defined by the compiler (default)
Mat3() = default;
Mat3() {}

/// Constructor given the quaternion rotation, e.g. Mat3f m(q);
/// The quaternion is normalized and used to construct the matrix
Expand Down Expand Up @@ -96,6 +93,16 @@ class Mat3: public Mat<3, T>
MyBase::mm[8] = static_cast<T>(a[8]);
} // constructor1Test

/// Copy constructor
Mat3(const Mat<3, T> &m)
{
for (int i=0; i<3; ++i) {
for (int j=0; j<3; ++j) {
MyBase::mm[i*3 + j] = m[i][j];
}
}
}

/// Conversion constructor
template<typename Source>
explicit Mat3(const Mat3<Source> &m)
Expand Down Expand Up @@ -834,9 +841,6 @@ using Mat3s = Mat3<float>;
using Mat3d = Mat3<double>;
using Mat3f = Mat3d;

OPENVDB_IS_POD(Mat3s)
OPENVDB_IS_POD(Mat3d)

} // namespace math


Expand Down
17 changes: 11 additions & 6 deletions openvdb/openvdb/math/Mat4.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class Mat4: public Mat<4, T>
using MyBase = Mat<4, T>;

/// Trivial constructor, the matrix is NOT initialized
/// @note destructor, copy constructor, assignment operator and
/// move constructor are left to be defined by the compiler (default)
Mat4() = default;
Mat4() {}

/// Constructor given array of elements, the ordering is in row major form:
/** @verbatim
Expand Down Expand Up @@ -102,6 +100,16 @@ class Mat4: public Mat<4, T>
}
}

/// Copy constructor
Mat4(const Mat<4, T> &m)
{
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
MyBase::mm[i*4 + j] = m[i][j];
}
}
}

/// Conversion constructor
template<typename Source>
explicit Mat4(const Mat4<Source> &m)
Expand Down Expand Up @@ -1354,9 +1362,6 @@ using Mat4s = Mat4<float>;
using Mat4d = Mat4<double>;
using Mat4f = Mat4d;

OPENVDB_IS_POD(Mat4s)
OPENVDB_IS_POD(Mat4d)

} // namespace math


Expand Down
10 changes: 0 additions & 10 deletions openvdb/openvdb/math/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@
#define OPENVDB_NO_FP_EQUALITY_WARNING_END
#endif


#ifdef OPENVDB_IS_POD
#undef OPENVDB_IS_POD
#endif
#define OPENVDB_IS_POD(Type) \
static_assert(std::is_standard_layout<Type>::value, \
#Type" must be a POD type (satisfy StandardLayoutType.)"); \
static_assert(std::is_trivial<Type>::value, \
#Type" must be a POD type (satisfy TrivialType.)");

namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
Expand Down
28 changes: 22 additions & 6 deletions openvdb/openvdb/math/Quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class Quat
static const int size = 4;

/// Trivial constructor, the quaternion is NOT initialized
/// @note destructor, copy constructor, assignment operator and
/// move constructor are left to be defined by the compiler (default)
Quat() = default;
Quat() {}

/// Constructor with four arguments, e.g. Quatf q(1,2,3,4);
Quat(T x, T y, T z, T w)
Expand Down Expand Up @@ -189,6 +187,16 @@ class Quat
}
}

/// Copy constructor
Quat(const Quat &q)
{
mm[0] = q.mm[0];
mm[1] = q.mm[1];
mm[2] = q.mm[2];
mm[3] = q.mm[3];

}

/// Reference to the component, e.g. q.x() = 4.5f;
T& x() { return mm[0]; }
T& y() { return mm[1]; }
Expand Down Expand Up @@ -297,6 +305,17 @@ class Quat
Vec3<T> eulerAngles(RotationOrder rotationOrder) const
{ return math::eulerAngles(Mat3<T>(*this), rotationOrder); }

/// Assignment operator
Quat& operator=(const Quat &q)
{
mm[0] = q.mm[0];
mm[1] = q.mm[1];
mm[2] = q.mm[2];
mm[3] = q.mm[3];

return *this;
}

/// Equality operator, does exact floating point comparisons
bool operator==(const Quat &q) const
{
Expand Down Expand Up @@ -600,9 +619,6 @@ Mat3<T> bezLerp(const Mat3<T0> &m1, const Mat3<T0> &m2,
using Quats = Quat<float>;
using Quatd = Quat<double>;

OPENVDB_IS_POD(Quats)
OPENVDB_IS_POD(Quatd)

} // namespace math


Expand Down
31 changes: 24 additions & 7 deletions openvdb/openvdb/math/Tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <cmath>
#include <sstream>
#include <string>
#include <type_traits>


namespace openvdb {
Expand All @@ -26,18 +25,36 @@ struct Conversion {};
/// @class Tuple "Tuple.h"
/// A base class for homogenous tuple types
template<int SIZE, typename T>
class Tuple
{
class Tuple {
public:
using value_type = T;
using ValueType = T;

static const int size = SIZE;

/// Trivial constructor, the Tuple is NOT initialized
/// @note destructor, copy constructor, assignment operator and
/// move constructor are left to be defined by the compiler (default)
Tuple() = default;
/// @brief Default ctor. Does nothing.
/// @details This is required because declaring a copy (or other) constructor
/// prevents the compiler from synthesizing a default constructor.
Tuple() {}

/// Copy constructor. Used when the class signature matches exactly.
Tuple(Tuple const& src) {
for (int i = 0; i < SIZE; ++i) {
mm[i] = src.mm[i];
}
}

/// @brief Assignment operator
/// @details This is required because declaring a copy (or other) constructor
/// prevents the compiler from synthesizing a default assignment operator.
Tuple& operator=(Tuple const& src) {
if (&src != this) {
for (int i = 0; i < SIZE; ++i) {
mm[i] = src.mm[i];
}
}
return *this;
}

/// @brief Conversion constructor.
/// @details Tuples with different value types and different sizes can be
Expand Down
10 changes: 2 additions & 8 deletions openvdb/openvdb/math/Vec2.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class Vec2: public Tuple<2, T>
using ValueType = T;

/// Trivial constructor, the vector is NOT initialized
/// @note destructor, copy constructor, assignment operator and
/// move constructor are left to be defined by the compiler (default)
Vec2() = default;
Vec2() {}

/// @brief Construct a vector all of whose components have the given value.
explicit Vec2(T val) { this->mm[0] = this->mm[1] = val; }
Expand Down Expand Up @@ -356,6 +354,7 @@ class Vec2: public Tuple<2, T>
static Vec2<T> ones() { return Vec2<T>(1, 1); }
};


/// Multiply each element of the given vector by @a scalar and return the result.
template <typename S, typename T>
inline Vec2<typename promote<S, T>::type> operator*(S scalar, const Vec2<T> &v)
Expand Down Expand Up @@ -532,11 +531,6 @@ using Vec2ui = Vec2<uint32_t>;
using Vec2s = Vec2<float>;
using Vec2d = Vec2<double>;

OPENVDB_IS_POD(Vec2i)
OPENVDB_IS_POD(Vec2ui)
OPENVDB_IS_POD(Vec2s)
OPENVDB_IS_POD(Vec2d)

} // namespace math
} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb
Expand Down
9 changes: 1 addition & 8 deletions openvdb/openvdb/math/Vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class Vec3: public Tuple<3, T>
using ValueType = T;

/// Trivial constructor, the vector is NOT initialized
/// @note destructor, copy constructor, assignment operator and
/// move constructor are left to be defined by the compiler (default)
Vec3() = default;
Vec3() {}

/// @brief Construct a vector all of whose components have the given value.
explicit Vec3(T val) { this->mm[0] = this->mm[1] = this->mm[2] = val; }
Expand Down Expand Up @@ -663,11 +661,6 @@ using Vec3ui = Vec3<uint32_t>;
using Vec3s = Vec3<float>;
using Vec3d = Vec3<double>;

OPENVDB_IS_POD(Vec3i)
OPENVDB_IS_POD(Vec3ui)
OPENVDB_IS_POD(Vec3s)
OPENVDB_IS_POD(Vec3d)

} // namespace math
} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb
Expand Down
9 changes: 1 addition & 8 deletions openvdb/openvdb/math/Vec4.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class Vec4: public Tuple<4, T>
using ValueType = T;

/// Trivial constructor, the vector is NOT initialized
/// @note destructor, copy constructor, assignment operator and
/// move constructor are left to be defined by the compiler (default)
Vec4() = default;
Vec4() {}

/// @brief Construct a vector all of whose components have the given value.
explicit Vec4(T val) { this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] = val; }
Expand Down Expand Up @@ -561,11 +559,6 @@ using Vec4ui = Vec4<uint32_t>;
using Vec4s = Vec4<float>;
using Vec4d = Vec4<double>;

OPENVDB_IS_POD(Vec4i)
OPENVDB_IS_POD(Vec4ui)
OPENVDB_IS_POD(Vec4s)
OPENVDB_IS_POD(Vec4d)

} // namespace math
} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb
Expand Down
Loading

0 comments on commit 2912576

Please sign in to comment.