Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/zenustech/zeno
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxx1987 committed Sep 3, 2024
2 parents 45508c6 + 04f6022 commit 37a6bea
Show file tree
Hide file tree
Showing 62 changed files with 3,808 additions and 51,456 deletions.
8 changes: 4 additions & 4 deletions projects/Alembic/GetAlembicPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct GetAlembicPrim : INode {
prim = get_alembic_prim(abctree, index);
}
if (get_input2<bool>("flipFrontBack")) {
primFlipFaces(prim.get());
primFlipFaces(prim.get(), true);
}
if (get_input2<bool>("triangulate")) {
zeno::primTriangulate(prim.get());
Expand Down Expand Up @@ -198,7 +198,7 @@ struct AllAlembicPrim : INode {
}
auto outprim = zeno::primMerge(prims->getRaw<PrimitiveObject>());
if (get_input2<bool>("flipFrontBack")) {
primFlipFaces(outprim.get());
primFlipFaces(outprim.get(), true);
}
if (get_input2<int>("triangulate") == 1) {
zeno::primTriangulate(outprim.get());
Expand Down Expand Up @@ -297,7 +297,7 @@ struct AlembicPrimList : INode {
for (auto &prim: new_prims->arr) {
auto _prim = std::dynamic_pointer_cast<PrimitiveObject>(prim);
if (get_input2<bool>("flipFrontBack")) {
primFlipFaces(_prim.get());
primFlipFaces(_prim.get(), true);
}
if (get_input2<bool>("splitByFaceset") && get_input2<bool>("killDeadVerts")) {
primKillDeadVerts(_prim.get());
Expand Down Expand Up @@ -457,7 +457,7 @@ struct ImportAlembicPrim : INode {
outprim = get_alembic_prim(abctree, index);
}
}
primFlipFaces(outprim.get());
primFlipFaces(outprim.get(), true);
if (get_input2<bool>("triangulate")) {
zeno::primTriangulate(outprim.get());
}
Expand Down
10 changes: 5 additions & 5 deletions projects/CUDA/SpatialAccel.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct ZenoLBvh {
Vector<Box> box{orderedBvs.get_allocator(), 1};
if (numLeaves <= 2) {
using TV = typename Box::TV;
box.setVal(Box{TV::uniform(limits<value_type>::max()), TV::uniform(limits<value_type>::lowest())});
box.setVal(Box{TV::uniform(detail::deduce_numeric_max<value_type>()), TV::uniform(detail::deduce_numeric_lowest<value_type>())});
pol(Collapse{numLeaves}, [bvh = proxy<space>(*this), box = proxy<space>(box)] ZS_LAMBDA(int vi) mutable {
auto bv = bvh.getNodeBV(vi);
for (int d = 0; d != dim; ++d) {
Expand Down Expand Up @@ -239,13 +239,13 @@ void ZenoLBvh<dim, lane_width, Index, Value, Allocator>::build(zs::CudaExecution
auto lOffsets = proxy<space>(leafOffsets);

// total bounding volume
const auto defaultBox = Box{TV::uniform(limits<value_type>::max()), TV::uniform(limits<value_type>::lowest())};
const auto defaultBox = Box{TV::uniform(detail::deduce_numeric_max<value_type>()), TV::uniform(detail::deduce_numeric_lowest<value_type>())};
Vector<Box> wholeBox{primBvs.get_allocator(), 1};
wholeBox.setVal(defaultBox);
policy(primBvs, [box = proxy<space>(wholeBox), execTag] ZS_LAMBDA(const Box &bv) mutable {
for (int d = 0; d != dim; ++d) {
atomic_min(execTag, &box(0)._min[d], bv._min[d] - 10 * limits<T>::epsilon());
atomic_max(execTag, &box(0)._max[d], bv._max[d] + 10 * limits<T>::epsilon());
atomic_min(execTag, &box(0)._min[d], bv._min[d] - 10 * detail::deduce_numeric_epsilon<T>());
atomic_max(execTag, &box(0)._max[d], bv._max[d] + 10 * detail::deduce_numeric_epsilon<T>());
}
});

Expand Down Expand Up @@ -624,7 +624,7 @@ void ZenoLBvh<dim, lane_width, Index, Value, Allocator>::refit(zs::CudaExecution
// refit
#if 0
policy(orderedBvs, [] ZS_LAMBDA(auto &bv) {
bv = Box{TV::uniform(limits<value_type>::max()), TV::uniform(limits<value_type>::lowest())};
bv = Box{TV::uniform(detail::deduce_numeric_max<value_type>()), TV::uniform(detail::deduce_numeric_lowest<value_type>())};
});
#endif
policy(Collapse{numLeaves}, [primBvs = proxy<space>(primBvs), orderedBvs = proxy<space>(orderedBvs),
Expand Down
14 changes: 7 additions & 7 deletions projects/CUDA/Structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ struct ZenoParticles : IObjectClone<ZenoParticles> {
using namespace zs;
constexpr execspace_e space = RM_CVREF_T(pol)::exec_tag::value;
constexpr auto defaultBv =
bv_t{vec3f::constant(zs::limits<zs::f32>::max()), vec3f::constant(zs::limits<zs::f32>::lowest())};
bv_t{vec3f::constant(zs::detail::deduce_numeric_max<zs::f32>()), vec3f::constant(zs::detail::deduce_numeric_lowest<zs::f32>())};
if (!particles)
return defaultBv;

Expand All @@ -357,14 +357,14 @@ struct ZenoParticles : IObjectClone<ZenoParticles> {
y = xn[1];
z = xn[2];
});
zs::reduce(pol, std::begin(X), std::end(X), std::begin(res), zs::limits<zs::f32>::max(), getmin<zs::f32>{});
zs::reduce(pol, std::begin(X), std::end(X), std::begin(res) + 3, zs::limits<zs::f32>::lowest(),
zs::reduce(pol, std::begin(X), std::end(X), std::begin(res), zs::detail::deduce_numeric_max<zs::f32>(), getmin<zs::f32>{});
zs::reduce(pol, std::begin(X), std::end(X), std::begin(res) + 3, zs::detail::deduce_numeric_lowest<zs::f32>(),
getmax<zs::f32>{});
zs::reduce(pol, std::begin(Y), std::end(Y), std::begin(res) + 1, zs::limits<zs::f32>::max(), getmin<zs::f32>{});
zs::reduce(pol, std::begin(Y), std::end(Y), std::begin(res) + 4, zs::limits<zs::f32>::lowest(),
zs::reduce(pol, std::begin(Y), std::end(Y), std::begin(res) + 1, zs::detail::deduce_numeric_max<zs::f32>(), getmin<zs::f32>{});
zs::reduce(pol, std::begin(Y), std::end(Y), std::begin(res) + 4, zs::detail::deduce_numeric_lowest<zs::f32>(),
getmax<zs::f32>{});
zs::reduce(pol, std::begin(Z), std::end(Z), std::begin(res) + 2, zs::limits<zs::f32>::max(), getmin<zs::f32>{});
zs::reduce(pol, std::begin(Z), std::end(Z), std::begin(res) + 5, zs::limits<zs::f32>::lowest(),
zs::reduce(pol, std::begin(Z), std::end(Z), std::begin(res) + 2, zs::detail::deduce_numeric_max<zs::f32>(), getmin<zs::f32>{});
zs::reduce(pol, std::begin(Z), std::end(Z), std::begin(res) + 5, zs::detail::deduce_numeric_lowest<zs::f32>(),
getmax<zs::f32>{});
res = res.clone({memsrc_e::host, -1});
return bv_t{vec3f{res[0], res[1], res[2]}, vec3f{res[3], res[4], res[5]}};
Expand Down
12 changes: 6 additions & 6 deletions projects/CUDA/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ constexpr bool pt_accd(VecT p, VecT t0, VecT t1, VecT t2, VecT dp, VecT dt0,
dt2 -= mov;
dp -= mov;
T dispMag2Vec[3] = {dt0.l2NormSqr(), dt1.l2NormSqr(), dt2.l2NormSqr()};
T tmp = zs::limits<T>::lowest();
T tmp = zs::detail::deduce_numeric_lowest<T>();
for (int i = 0; i != 3; ++i)
if (dispMag2Vec[i] > tmp)
tmp = dispMag2Vec[i];
Expand Down Expand Up @@ -343,7 +343,7 @@ ee_accd(VecT ea0, VecT ea1, VecT eb0, VecT eb1, VecT dea0, VecT dea1, VecT deb0,
T dists[] = {(ea0 - eb0).l2NormSqr(), (ea0 - eb1).l2NormSqr(),
(ea1 - eb0).l2NormSqr(), (ea1 - eb1).l2NormSqr()};
{
dist2_cur = zs::limits<T>::max();
dist2_cur = zs::detail::deduce_numeric_max<T>();
for (const auto &dist : dists)
if (dist < dist2_cur)
dist2_cur = dist;
Expand Down Expand Up @@ -378,7 +378,7 @@ ee_accd(VecT ea0, VecT ea1, VecT eb0, VecT eb1, VecT dea0, VecT dea1, VecT deb0,
T dists[] = {(ea0 - eb0).l2NormSqr(), (ea0 - eb1).l2NormSqr(),
(ea1 - eb0).l2NormSqr(), (ea1 - eb1).l2NormSqr()};
{
dist2_cur = zs::limits<T>::max();
dist2_cur = zs::detail::deduce_numeric_max<T>();
for (const auto &dist : dists)
if (dist < dist2_cur)
dist2_cur = dist;
Expand Down Expand Up @@ -568,7 +568,7 @@ void find_intersection_free_stepsize(Pol &pol, ZenoParticles &zstets,
atomic_min(exec_cuda, &finalAlpha[0], alpha);
});
// zs::reduce(pol, std::begin(surfAlphas), std::end(surfAlphas),
// std::begin(finalAlpha), limits<T>::max(), getmin<T>{});
// std::begin(finalAlpha), detail::deduce_numeric_max<T>(), getmin<T>{});
auto surfAlpha = finalAlpha.getVal();
fmt::print(fg(fmt::color::dark_cyan),
"surface alpha: {}, default stepsize: {}\n", surfAlpha, stepSize);
Expand Down Expand Up @@ -708,7 +708,7 @@ void find_boundary_intersection_free_stepsize(Pol &pol, ZenoParticles &zstets,
});
});
// zs::reduce(pol, std::begin(surfAlphas), std::end(surfAlphas),
// std::begin(finalAlpha), limits<T>::max(), getmin<T>{});
// std::begin(finalAlpha), detail::deduce_numeric_max<T>(), getmin<T>{});
auto surfAlpha = finalAlpha.getVal();
stepSize = surfAlpha;
fmt::print(fg(fmt::color::dark_cyan),
Expand Down Expand Up @@ -758,7 +758,7 @@ void find_boundary_intersection_free_stepsize(Pol &pol, ZenoParticles &zstets,
});
#if 0
zs::reduce(pol, std::begin(surfEdgeAlphas), std::end(surfEdgeAlphas),
std::begin(finalAlpha), limits<T>::max(), getmin<T>{});
std::begin(finalAlpha), detail::deduce_numeric_max<T>(), getmin<T>{});
stepSize = std::min(surfAlpha, finalAlpha.getVal());
#else
stepSize = finalAlpha.getVal();
Expand Down
18 changes: 9 additions & 9 deletions projects/CUDA/iw_query/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ struct QueryNearestPoints : INode {
gmin = vertices[i][d];
gmax = vertices[i][d];
});
reduce(pol, std::begin(gmins), std::end(gmins), std::begin(ret), limits<float>::max(), getmin<float>{});
reduce(pol, std::begin(gmins), std::end(gmins), std::begin(ret), detail::deduce_numeric_max<float>(), getmin<float>{});
gbv._min[d] = ret.getVal();
reduce(pol, std::begin(gmaxs), std::end(gmaxs), std::begin(ret), limits<float>::lowest(), getmax<float>{});
reduce(pol, std::begin(gmaxs), std::end(gmaxs), std::begin(ret), detail::deduce_numeric_lowest<float>(), getmax<float>{});
gbv._max[d] = ret.getVal();
}
int axis = 0; // x-axis by default
Expand Down Expand Up @@ -130,8 +130,8 @@ struct QueryNearestPoints : INode {
{
int cnt = 0;
for (int i = 0; i < vertices.size() - 1; ++i) {
if ((keys[i] >= limits<float>::epsilon() || keys[i] <= -limits<float>::epsilon()) &&
(keys[i + 1] >= limits<float>::epsilon() || keys[i + 1] <= -limits<float>::epsilon()))
if ((keys[i] >= detail::deduce_numeric_epsilon<float>() || keys[i] <= -detail::deduce_numeric_epsilon<float>()) &&
(keys[i + 1] >= detail::deduce_numeric_epsilon<float>() || keys[i + 1] <= -detail::deduce_numeric_epsilon<float>()))
if (keys[i] > keys[i + 1]) {
printf("order is wrong at [%d] ... %e, %e...\n", i, keys[i], keys[i + 1]);
cnt++;
Expand Down Expand Up @@ -172,7 +172,7 @@ struct QueryNearestPoints : INode {
pol(enumerate(pos, locs, dists, ids, cps),
[&xs, &indices, axis](int i, const auto &xi, const int loc, float &dist, int &id, vec3f &cp) {
int l = loc + 1;
float d2 = limits<float>::max();
float d2 = detail::deduce_numeric_max<float>();
int j = -1;
int cnt = 0;
while (l < xs.size() && cnt++ < 128) {
Expand Down Expand Up @@ -265,7 +265,7 @@ struct QueryNearestPoints : INode {
pol(enumerate(pos, dists, ids, cps), [&pos, &vertices, &locs, &xs, &indices, bvh = proxy<space>(bvh), axis](
int i, const zeno::vec3f &p, float &dist, int &id, zeno::vec3f &cp) {
auto target = vertices[id];
if (auto d = zeno::length(p - target); std::abs(d - dist) > limits<float>::epsilon())
if (auto d = zeno::length(p - target); std::abs(d - dist) > detail::deduce_numeric_epsilon<float>())
fmt::print("actual dist {}, cp ({}, {}, {}); calced dist {}, cp ({}, {}, {}). \n", d, target[0],
target[1], target[2], dist, cp[0], cp[1], cp[2]);
const int loc = locs[i];
Expand All @@ -275,7 +275,7 @@ struct QueryNearestPoints : INode {
auto key = xi[axis];
int l = loc + 1;
while (l < xs.size() && zs::sqr(xs[l][axis] - key) < dist2) {
if (auto d2 = zeno::lengthSquared(xs[l] - xi); std::sqrt(d2) + limits<float>::epsilon() < dist) {
if (auto d2 = zeno::lengthSquared(xs[l] - xi); std::sqrt(d2) + detail::deduce_numeric_epsilon<float>() < dist) {
fmt::print("[{}] found nearer pair! real id should be {} ({}), not {} ({})\n", i, indices[l],
std::sqrt(d2), id, std::sqrt(dist2));
return;
Expand All @@ -284,7 +284,7 @@ struct QueryNearestPoints : INode {
}
l = loc;
while (l >= 0 && zs::sqr(xs[l][axis] - key) < dist2) {
if (auto d2 = zeno::lengthSquared(xs[l] - xi); std::sqrt(d2) + limits<float>::epsilon() < dist) {
if (auto d2 = zeno::lengthSquared(xs[l] - xi); std::sqrt(d2) + detail::deduce_numeric_epsilon<float>() < dist) {
fmt::print("[{}] found nearer pair! real id should be {} ({}), not {} ({})\n", i, indices[l],
std::sqrt(d2), id, dist);
return;
Expand All @@ -302,7 +302,7 @@ struct QueryNearestPoints : INode {
timer.tick();
pol(zip(range(pos.size()), locs),
[&locs, &xs, &vertices, &indices, &pos, &ids, &dists, &cps, axis](int i, const int loc) {
float dist2 = limits<float>::max();
float dist2 = detail::deduce_numeric_max<float>();
int id = -1;
auto xi = pos[i];
auto key = xi[axis];
Expand Down
6 changes: 3 additions & 3 deletions projects/CUDA/remesh/simplification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ struct PolyReduceLite : INode {
// zeno::log_warn(fmt::format("begin iter {}\n", i));
/// evaluate vert curvatures
pol(range(pos.size()), [&](int i) {
vertEdgeCosts[i] = std::make_pair(limits<float>::max(), std::make_pair(i, -1));
vertEdgeCosts[i] = std::make_pair(detail::deduce_numeric_max<float>(), std::make_pair(i, -1));
if (vertVerts[i].size() == 0 || vertDiscard[i]) {
return;
}

auto cost = limits<float>::max();
auto cost = detail::deduce_numeric_max<float>();
for (auto j : vertVerts[i]) {
if (vertDiscard[j])
continue;
Expand Down Expand Up @@ -105,7 +105,7 @@ struct PolyReduceLite : INode {
/// sort edges for collapse
auto pair = std::reduce(
std::begin(vertEdgeCosts), std::end(vertEdgeCosts),
std::make_pair(limits<float>::max(), std::make_pair(-1, -1)),
std::make_pair(detail::deduce_numeric_max<float>(), std::make_pair(-1, -1)),
[](const std::pair<float, std::pair<int, int>> &a, const std::pair<float, std::pair<int, int>> &b) {
if (a.first < b.first)
return a;
Expand Down
18 changes: 17 additions & 1 deletion projects/CUDA/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
#include "zensim/execution/ConcurrencyPrimitive.hpp"
#include "zensim/visitors/Print.hpp"

#if 0
#include "glm/glm.hpp"
#include "glm/gtx/quaternion.hpp"
#include <zeno/utils/log.h>
#endif

namespace zeno {

struct spinlock {
Expand Down Expand Up @@ -442,6 +448,16 @@ struct ZSLinkTest : INode {
void apply() override {
using namespace zs;
constexpr auto space = execspace_e::openmp;

#if 0
glm::vec3 v{1, 2, 3};
glm::mat3 m;
glm::quat q= {1, 0, 0, 0};
zeno::log_info("glm vec3: {}", v);
zeno::log_info("glm mat3: {}", m);
zeno::log_info("glm quat: {}", q);
#endif

#if 0
using namespace zs;
zs::initialize_openvdb();
Expand Down Expand Up @@ -839,7 +855,7 @@ struct TestAdaptiveGrid : INode {
auto cc = c.cast<f32>() / 3;
auto vv = zsagv.iSample(0, cc);
openvdb::FloatGrid::ValueType vref = sampler.isSample(openvdb::Vec3R(cc[0], cc[1], cc[2]));
if (zs::abs(vref - vv) >= limits<float>::epsilon()) {
if (zs::abs(vref - vv) >= detail::deduce_numeric_epsilon<float>()) {
fmt::print(fg(fmt::color::green), "sampled value is {} ({}) at {}, {}, {}\n", v, vv, vref, cc[0], cc[1],
cc[2]);
}
Expand Down
3 changes: 2 additions & 1 deletion projects/CUDA/test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ struct ZSCULinkTest : INode {
{
zs::VdbGrid<3, float, zs::index_sequence<3, 4, 5>> ag;
using TT = RM_CVREF_T(ag);
fmt::print("adaptive grid type: {}\n", zs::get_var_type_str(ag));
fmt::print("adaptive grid type: {}\n",
zs::get_var_type_str(ag).asChars());
// fmt::print("tile bits: {}\n", zs::get_type_str<TT::tile_bits_type>());
// fmt::print("hierarchy bits: {}\n",
// zs::get_type_str<TT::hierarchy_bits_type>());
Expand Down
2 changes: 1 addition & 1 deletion projects/CUDA/test1.cu
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct ZSCUMathTest : INode {
constexpr int n = 100;
using TV = zs::vec<float, 3>;
//TV m_X[4] = {TV{0, 0, 0}, TV{0, 1, 0}, TV{0, 0, -1}, TV{0, 0, 1}};
TV m_X[4] = {TV{0, 0, 0}, TV{0, 1, 0}, TV{0, 0, -1}, TV{-limits<float>::epsilon() * 5, 1, -1}};
TV m_X[4] = {TV{0, 0, 0}, TV{0, 1, 0}, TV{0, 0, -1}, TV{-detail::deduce_numeric_epsilon<float>() * 5, 1, -1}};
auto ra = zs::dihedral_angle(m_X[2], m_X[0], m_X[1], m_X[3], exec_seq);
auto grad = zs::dihedral_angle_gradient(m_X[2], m_X[0], m_X[1], m_X[3], exec_seq);
auto hess = zs::dihedral_angle_hessian(m_X[2], m_X[0], m_X[1], m_X[3], exec_seq);
Expand Down
2 changes: 1 addition & 1 deletion projects/CUDA/utils/Groom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ struct GenerateHairs : INode {
auto [id, _] = lbvhv.find_nearest(
pi,
[&](int j, float &dist, int &id) {
float d = zs::limits<float>::max();
float d = zs::detail::deduce_numeric_max<float>();
d = zs::dist_pp(pi, vec3::from_array(verts[loops[polys[j][0]]]));

if (d < dist) {
Expand Down
Loading

0 comments on commit 37a6bea

Please sign in to comment.