New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes to support matrix grid type instantiation #723
Conversation
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
openvdb/Grid.h
Outdated
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN | ||
const auto value = zeroVal<ValueType>() + tolerance; | ||
OPENVDB_NO_TYPE_CONVERSION_WARNING_END | ||
const auto value = math::cwiseAdd(zeroVal<ValueType>(), tolerance); | ||
this->tree().prune(static_cast<ValueType>(value)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other option I've been considering is to simply add explicit functionality to Grid::prune which branches on matrix types - something like:
auto addTolerance(auto& a, float tol) { return a + tol; }
template<size_t SIZE, typename T>
auto addTolerance(Mat<SIZE, T>& a, float tol) { // do cwiseadd }
prune(float a)
{
auto value = addTolerance(zeroVal<ValueType>(), a);
....
}
I think I'd actually prefer this, if we assume the following:
cwiseAdd
is only necessary as we are still debating if/whatoperator+
should perform on matrix types with scalarsGrid::prune
itself is to be deprecated.
openvdb/math/Math.h
Outdated
@@ -62,6 +62,8 @@ template<> inline std::string zeroVal<std::string>() { return ""; } | |||
/// Return the @c bool value that corresponds to zero. | |||
template<> inline bool zeroVal<bool>() { return false; } | |||
|
|||
namespace math { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important: This moves the below inline std::string operator+
ops into the math namespace so ADL picks them up from cwiseAdd
openvdb/math/Mat.h
Outdated
/// Array style reference to ith row | ||
T* operator[](int i) { return &(mm[i*SIZE]); } | ||
const T* operator[](int i) const { return &(mm[i*SIZE]); } | ||
//@} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also fixes Mat3<T>(Mat<3, T>& in)
and the same for Mat4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the < defined for matrices, but I recall we had it defined for fixed vectors so were stuck.
Vector classes derive from
Weighing up the options here, this change does mean that Mat could derive from Tuple which will be awesome and a change that I think is long overdue. However I agree that this definition isn't great - I can't remember exactly what we concluded would be better default behaviour? |
Okay so I dug through our old conversation on this. Forgetting deriving from |
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
@jmlait I've made this change, I think it's a lot close to what you originally proposed. Take a look and let me know what you think |
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
…ids are supported Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
I went back and forth with different approaches to get this to work. It's not ideal, but the only aim here is to allow grid types to be instantiated with VDB matrix types. Notes:
operator+
on non POD/VDB types. This means that anycwiseAdd
must fall back tooperator+
. This further means that SFINAE cannot be used in Math.h (cwise must be agnostic to any types) and instead has to be specialised by the matrix classes.Mat3<Type>(Mat<3<type>&) Mat4<Type>(Mat<4, Type>)
constructors are actually broken (cannot be compiled). Moving theMat:: operator[]
to the base class inadvertently fixes this.operator+
into the math namespace to get ADL to work.Signed-off-by: Nick Avramoussis 4256455+Idclip@users.noreply.github.com