Skip to content

Commit 93b397c

Browse files
authored
Merge pull request #2067 from Idclip/anisotropic_surfacing
Introduced Anisotropic Surfacing Kernels and PCA methods
2 parents cbda14e + c2bc66e commit 93b397c

16 files changed

+4198
-909
lines changed

openvdb/openvdb/Types.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,77 @@ using PointDataIndex32 = PointIndex<Index32, 1>;
182182
using PointDataIndex64 = PointIndex<Index64, 1>;
183183

184184

185+
////////////////////////////////////////
186+
187+
/// @brief Macros to help determine whether or not a class has a particular
188+
/// member function.
189+
/// @details These macros work by instantiating unique templated instances
190+
/// of helper structs for a particular member function signature and name
191+
/// which can then be queried.
192+
/// - The first macro, INVOKABLE, defines a helper struct which determines
193+
/// if a member function can be called with a given set of argument types.
194+
/// Note that the return type is not provided.
195+
/// - The second macro defines a helper struct which determines if the
196+
/// member function exists with the _exact_ same signature, including
197+
/// all argument and function attributes (const-ness, noexcept, etc)
198+
///
199+
/// Use the first solution if all you want to determine is whether a given
200+
/// method can be called, and the second if you need exact resolution.
201+
/// @code
202+
/// // example class
203+
/// struct MyClass { int test(double) { return 0; } };
204+
///
205+
/// // The following examples work from the struct type created by:
206+
/// OPENVDB_INIT_INVOKABLE_MEMBER_FUNCTION(test);
207+
///
208+
/// // Will assert true!
209+
/// static_assert(OPENVDB_HAS_INVOKABLE_MEMBER_FUNCTION(MyClass, test, double));
210+
/// // Will assert true, int can be converted to double
211+
/// static_assert(OPENVDB_HAS_INVOKABLE_MEMBER_FUNCTION(MyClass, test, int));
212+
/// // Will assert false, needs at least one argument
213+
/// static_assert(OPENVDB_HAS_INVOKABLE_MEMBER_FUNCTION(MyClass, test);
214+
///
215+
///
216+
/// // The following examples work from the struct type created by:
217+
/// OPENVDB_INIT_MEMBER_FUNCTION(test);
218+
///
219+
/// // Will assert fail
220+
/// static_assert(OPENVDB_HAS_MEMBER_FUNCTION(MyClass, test, void(MyClass::*)(double)));
221+
/// // Only case where this assert true
222+
/// static_assert(OPENVDB_HAS_MEMBER_FUNCTION(MyClass, test, int(MyClass::*)(double)));
223+
///
224+
/// @endcode
225+
#define OPENVDB_INIT_INVOKABLE_MEMBER_FUNCTION(F) \
226+
template <typename ClassT, typename... Args> \
227+
struct HasInvokableMemberFunction_##F { \
228+
private: \
229+
template <typename T> \
230+
static auto check(T*) -> \
231+
decltype(std::declval<T>(). \
232+
F(std::declval<Args>()...), std::true_type()); \
233+
template <typename T> \
234+
static auto check(...) -> std::false_type; \
235+
public: \
236+
static constexpr bool value = \
237+
decltype(check<ClassT>(nullptr))::value; \
238+
};
239+
#define OPENVDB_HAS_INVOKABLE_MEMBER_FUNCTION(T, F, ...) \
240+
HasInvokableMemberFunction_##F<T, __VA_ARGS__>::value
241+
242+
#define OPENVDB_INIT_MEMBER_FUNCTION(F) \
243+
template<typename ClassT, typename Signature> \
244+
struct HasMemberFunction_##F { \
245+
template <typename U, U> struct sigmatch; \
246+
template <typename U> static std::true_type \
247+
check(sigmatch<Signature, &U::F>*); \
248+
template <typename> static std::false_type check(...); \
249+
static const bool value = std::is_same<std::true_type, \
250+
decltype(check<ClassT>(nullptr))>::value; \
251+
};
252+
#define OPENVDB_HAS_MEMBER_FUNCTION(T, F, S) \
253+
HasMemberFunction_##F<T, S>::value
254+
255+
185256
////////////////////////////////////////
186257

187258

openvdb/openvdb/math/Mat.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ MatType
213213
rotation(Axis axis, typename MatType::value_type angle)
214214
{
215215
using T = typename MatType::value_type;
216-
T c = static_cast<T>(cos(angle));
217-
T s = static_cast<T>(sin(angle));
216+
T c = static_cast<T>(std::cos(angle));
217+
T s = static_cast<T>(std::sin(angle));
218218

219219
MatType result;
220220
result.setIdentity();
@@ -256,9 +256,9 @@ rotation(const Vec3<typename MatType::value_type> &_axis, typename MatType::valu
256256
Vec3<T> axis(_axis.unit());
257257

258258
// compute trig properties of angle:
259-
T c(cos(double(angle)));
260-
T s(sin(double(angle)));
261-
T t(1 - c);
259+
const T c = static_cast<T>(std::cos(double(angle)));
260+
const T s = static_cast<T>(std::sin(double(angle)));
261+
const T t = T(1) - c;
262262

263263
MatType result;
264264
// handle diagonal elements

openvdb/openvdb/math/Mat3.h

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -680,48 +680,47 @@ pivot(int i, int j, Mat3<T>& S, Vec3<T>& D, Mat3<T>& Q)
680680

681681
double Sjj_minus_Sii = D[j] - D[i];
682682

683-
if (fabs(Sjj_minus_Sii) * (10*math::Tolerance<T>::value()) > fabs(Sij)) {
683+
if (std::abs(Sjj_minus_Sii) * (10*math::Tolerance<T>::value()) > std::abs(Sij)) {
684684
tan_of_theta = Sij / Sjj_minus_Sii;
685685
} else {
686686
/// pivot on Sij
687687
cotan_of_2_theta = 0.5*Sjj_minus_Sii / Sij ;
688688

689689
if (cotan_of_2_theta < 0.) {
690690
tan_of_theta =
691-
-1./(sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) - cotan_of_2_theta);
691+
-1./(std::sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) - cotan_of_2_theta);
692692
} else {
693693
tan_of_theta =
694-
1./(sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) + cotan_of_2_theta);
694+
1./(std::sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) + cotan_of_2_theta);
695695
}
696696
}
697697

698-
cosin_of_theta = 1./sqrt( 1. + tan_of_theta * tan_of_theta);
698+
cosin_of_theta = 1./std::sqrt( 1. + tan_of_theta * tan_of_theta);
699699
sin_of_theta = cosin_of_theta * tan_of_theta;
700700
z = tan_of_theta * Sij;
701701
S(i,j) = 0;
702-
D[i] -= z;
703-
D[j] += z;
702+
D[i] -= T(z);
703+
D[j] += T(z);
704704
for (int k = 0; k < i; ++k) {
705705
temp = S(k,i);
706-
S(k,i) = cosin_of_theta * temp - sin_of_theta * S(k,j);
707-
S(k,j)= sin_of_theta * temp + cosin_of_theta * S(k,j);
706+
S(k,i) = T(cosin_of_theta * temp - sin_of_theta * S(k,j));
707+
S(k,j) = T(sin_of_theta * temp + cosin_of_theta * S(k,j));
708708
}
709709
for (int k = i+1; k < j; ++k) {
710710
temp = S(i,k);
711-
S(i,k) = cosin_of_theta * temp - sin_of_theta * S(k,j);
712-
S(k,j) = sin_of_theta * temp + cosin_of_theta * S(k,j);
711+
S(i,k) = T(cosin_of_theta * temp - sin_of_theta * S(k,j));
712+
S(k,j) = T(sin_of_theta * temp + cosin_of_theta * S(k,j));
713713
}
714714
for (int k = j+1; k < n; ++k) {
715715
temp = S(i,k);
716-
S(i,k) = cosin_of_theta * temp - sin_of_theta * S(j,k);
717-
S(j,k) = sin_of_theta * temp + cosin_of_theta * S(j,k);
716+
S(i,k) = T(cosin_of_theta * temp - sin_of_theta * S(j,k));
717+
S(j,k) = T(sin_of_theta * temp + cosin_of_theta * S(j,k));
718+
}
719+
for (int k = 0; k < n; ++k) {
720+
temp = Q(k,i);
721+
Q(k,i) = T(cosin_of_theta * temp - sin_of_theta * Q(k,j));
722+
Q(k,j) = T(sin_of_theta * temp + cosin_of_theta * Q(k,j));
718723
}
719-
for (int k = 0; k < n; ++k)
720-
{
721-
temp = Q(k,i);
722-
Q(k,i) = cosin_of_theta * temp - sin_of_theta*Q(k,j);
723-
Q(k,j) = sin_of_theta * temp + cosin_of_theta*Q(k,j);
724-
}
725724
}
726725

727726
} // namespace mat3_internal
@@ -758,7 +757,7 @@ diagonalizeSymmetricMatrix(const Mat3<T>& input, Mat3<T>& Q, Vec3<T>& D,
758757
double er = 0;
759758
for (int i = 0; i < n; ++i) {
760759
for (int j = i+1; j < n; ++j) {
761-
er += fabs(S(i,j));
760+
er += std::abs(S(i,j));
762761
}
763762
}
764763
if (std::abs(er) < math::Tolerance<T>::value()) {
@@ -773,12 +772,12 @@ diagonalizeSymmetricMatrix(const Mat3<T>& input, Mat3<T>& Q, Vec3<T>& D,
773772
for (int i = 0; i < n; ++i) {
774773
for (int j = i+1; j < n; ++j){
775774

776-
if ( fabs(D[i]) * (10*math::Tolerance<T>::value()) > fabs(S(i,j))) {
775+
if ( std::abs(D[i]) * (10*math::Tolerance<T>::value()) > std::abs(S(i,j))) {
777776
/// value too small to pivot on
778777
S(i,j) = 0;
779778
}
780-
if (fabs(S(i,j)) > max_element) {
781-
max_element = fabs(S(i,j));
779+
if (std::abs(S(i,j)) > max_element) {
780+
max_element = std::abs(S(i,j));
782781
ip = i;
783782
jp = j;
784783
}

openvdb/openvdb/points/AttributeArray.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,6 @@ class AttributeHandle
817817
template <bool IsUnknownCodec>
818818
typename std::enable_if<!IsUnknownCodec, ValueType>::type get(Index index) const;
819819

820-
// local copy of AttributeArray (to preserve compression)
821-
AttributeArray::Ptr mLocalArray;
822-
823820
Index mStrideOrTotalSize;
824821
Index mSize;
825822
bool mCollapseOnDestruction;

0 commit comments

Comments
 (0)