-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
211 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#include "rxmesh/attribute.h" | ||
#include "rxmesh/diff/scalar.h" | ||
|
||
namespace rxmesh { | ||
|
||
class RXMeshStatic; | ||
|
||
template <typename T, int Size, bool WithHessian, typename HandleT> | ||
class DiffAttribute : public Attribute<Scalar<T, Size, WithHessian>, HandleT> | ||
{ | ||
public: | ||
using PassiveType = T; | ||
using ScalarType = Scalar<T, Size, WithHessian>; | ||
|
||
|
||
DiffAttribute() : Attribute<ScalarType, HandleT>() | ||
{ | ||
} | ||
|
||
explicit DiffAttribute(const char* name, | ||
uint32_t num_attributes, // not used | ||
locationT location, | ||
layoutT layout, // not used | ||
const RXMeshStatic* rxmesh) | ||
: Attribute<ScalarType, HandleT>(name, | ||
num_attributes, | ||
location, | ||
layout, | ||
rxmesh) | ||
{ | ||
} | ||
|
||
private: | ||
}; | ||
|
||
template <typename T, int Size, bool WithHessian> | ||
using DiffVertexAttribute = DiffAttribute<T, Size, WithHessian, VertexHandle>; | ||
|
||
template <typename T, int Size, bool WithHessian> | ||
using DiffEdgeAttribute = DiffAttribute<T, Size, WithHessian, EdgeHandle>; | ||
|
||
template <typename T, int Size, bool WithHessian> | ||
using DiffFaceAttribute = DiffAttribute<T, Size, WithHessian, FaceHandle>; | ||
|
||
} // namespace rxmesh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "rxmesh/rxmesh_static.h" | ||
|
||
#include "rxmesh/diff/scalar.h" | ||
|
||
|
||
template <typename T, int Size, bool WithHessian> | ||
void populate(rxmesh::RXMeshStatic& rx, | ||
rxmesh::DiffVertexAttribute<T, Size, WithHessian>& v, | ||
rxmesh::Scalar<T, Size, WithHessian> val) | ||
{ | ||
rx.for_each_vertex( | ||
rxmesh::DEVICE, | ||
[v, val] __device__(const rxmesh::VertexHandle vh) { v(vh) = val; }); | ||
|
||
EXPECT_EQ(cudaDeviceSynchronize(), cudaSuccess); | ||
} | ||
|
||
|
||
TEST(DiffAttribute, Simple) | ||
{ | ||
// write diff vertex attribute on the device and verify it on the host | ||
using namespace rxmesh; | ||
|
||
RXMeshStatic rx(STRINGIFY(INPUT_DIR) "sphere3.obj"); | ||
|
||
auto v_attr = *rx.add_diff_vertex_attribute<float, 1, true>("v"); | ||
|
||
rx.for_each_vertex(HOST, [&](const VertexHandle& vh) { v_attr(vh) = 1; }); | ||
|
||
auto val = Scalar<float, 1, true>::known_derivatives(2.0, 3.0, 4.0); | ||
|
||
populate<float>(rx, v_attr, val); | ||
|
||
v_attr.move(DEVICE, HOST); | ||
|
||
bool is_okay = true; | ||
|
||
rx.for_each_vertex( | ||
HOST, | ||
[&](const VertexHandle& vh) { | ||
if (v_attr(vh).val != val.val || v_attr(vh).grad != val.grad || | ||
v_attr(vh).Hess != val.Hess) { | ||
is_okay = false; | ||
} | ||
}, | ||
NULL, | ||
false); | ||
|
||
EXPECT_TRUE(is_okay); | ||
|
||
EXPECT_EQ(cudaDeviceSynchronize(), cudaSuccess); | ||
|
||
// #if USE_POLYSCOPE | ||
// rx.get_polyscope_mesh()->addVertexScalarQuantity("vAttr", v_attr); | ||
// polyscope::show(); | ||
// #endif | ||
} |
Oops, something went wrong.