Skip to content

Commit

Permalink
adjust prim unmerge/filter impls
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxx1987 committed Sep 3, 2024
1 parent 0ddb25f commit 45508c6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion projects/Alembic/ReadAlembic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ static std::shared_ptr<PrimitiveObject> foundABCSubd(Alembic::AbcGeom::ISubDSche
}
if (!prim->loops.has_attr("uvs")) {
if (!read_done) {
log_warn("[alembic] Not found uv, auto fill zero.");
// log_warn("[alembic] Not found uv, auto fill zero.");
}
prim->uvs.resize(1);
prim->uvs[0] = zeno::vec2f(0, 0);
Expand Down
2 changes: 1 addition & 1 deletion zeno/include/zeno/funcs/PrimitiveUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ZENO_API void primLineDistance(PrimitiveObject *prim, std::string resAttr, int s
ZENO_API void prim_set_abcpath(PrimitiveObject* prim, std::string path_name);
ZENO_API void prim_set_faceset(PrimitiveObject* prim, std::string faceset_name);

ZENO_API void primFilterVerts(PrimitiveObject *prim, std::string tagAttr, int tagValue, bool isInversed = false, std::string revampAttrO = {}, std::string method = "verts");
ZENO_API void primFilterVerts(PrimitiveObject *prim, std::string tagAttr, int tagValue, bool isInversed = false, std::string revampAttrO = {}, std::string method = "verts", int* aux = nullptr, int aux_size = 0, bool use_aux = false);

ZENO_API void primMarkIsland(PrimitiveObject *prim, std::string tagAttr);
ZENO_API std::vector<std::shared_ptr<PrimitiveObject>> primUnmergeVerts(PrimitiveObject *prim, std::string tagAttr);
Expand Down
1 change: 1 addition & 0 deletions zeno/include/zeno/types/AttrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ struct AttrVector {
for (auto &[key, val] : attrs) {
std::visit([&](auto &val) { val.resize(size); }, val);
}
shrink_to_fit();
}

void clear() {
Expand Down
38 changes: 27 additions & 11 deletions zeno/src/nodes/neo/PrimFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ namespace zeno {
static void primRevampVerts(PrimitiveObject *prim, std::vector<int> const &revamp);
static void primRevampFaces(PrimitiveObject *prim, std::vector<uint8_t> const &unrevamp);

ZENO_API void primFilterVerts(PrimitiveObject *prim, std::string tagAttr, int tagValue, bool isInversed, std::string revampAttrO, std::string method) {
ZENO_API void primFilterVerts(PrimitiveObject *prim,
std::string tagAttr,
int tagValue,
bool isInversed,
std::string revampAttrO,
std::string method,
int* aux, int aux_size,
bool use_aux) {
if (method == "faces") {
std::vector<uint8_t> unrevamp(prim->size());
auto const &tagArr = prim->verts.attr<int>(tagAttr);
Expand Down Expand Up @@ -41,18 +48,27 @@ ZENO_API void primFilterVerts(PrimitiveObject *prim, std::string tagAttr, int ta
}
} else {
std::vector<int> revamp;
revamp.reserve(prim->size());
auto const &tagArr = prim->verts.attr<int>(tagAttr);
if (!isInversed) {
if(aux_size==0 && use_aux == false) {
revamp.reserve(prim->size());
auto const &tagArr = prim->verts.attr<int>(tagAttr);
if (!isInversed) {
for (int i = 0; i < prim->size(); i++) {
if (tagArr[i] == tagValue)
revamp.emplace_back(i);
if (tagArr[i] == tagValue)
revamp.emplace_back(i);
}
} else {
} else {
for (int i = 0; i < prim->size(); i++) {
if (tagArr[i] != tagValue)
revamp.emplace_back(i);
if (tagArr[i] != tagValue)
revamp.emplace_back(i);
}
}
} else
{
revamp.resize(aux_size);
for(int i=0;i<aux_size;i++)
{
revamp[i] = aux[i];
}
}
primRevampVerts(prim, revamp);
if (!revampAttrO.empty()) {
Expand All @@ -63,7 +79,8 @@ ZENO_API void primFilterVerts(PrimitiveObject *prim, std::string tagAttr, int ta

template <class T>
static void revamp_vector(std::vector<T> &arr, std::vector<int> const &revamp) {
std::vector<T> newarr(arr.size());
std::vector<T> newarr(revamp.size());
#pragma omp parallel for
for (int i = 0; i < revamp.size(); i++) {
newarr[i] = arr[revamp[i]];
}
Expand Down Expand Up @@ -337,7 +354,6 @@ static void primRevampVerts(PrimitiveObject *prim, std::vector<int> const &revam

}
}

static void primRevampFaces(PrimitiveObject *prim, std::vector<uint8_t> const &unrevamp) {
if ((0
|| prim->tris.size()
Expand Down
11 changes: 10 additions & 1 deletion zeno/src/nodes/neo/PrimUnmerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ ZENO_API std::vector<std::shared_ptr<PrimitiveObject>> primUnmergeVerts(Primitiv
}

#if 1
std::vector<std::vector<int>> aux_arrays;
aux_arrays.resize(tagMax);
for (int tag = 0; tag < tagMax; tag++) {
aux_arrays[tag].resize(0);
}
//auto const &tagArr = prim->verts.attr<int>(tagAttr);
for (int i = 0; i < prim->size(); i++) {
aux_arrays[tagArr[i]].emplace_back(i);
}
for (int tag = 0; tag < tagMax; tag++) {
primList[tag]->assign(prim);
primFilterVerts(primList[tag].get(), tagAttr, tag);
primFilterVerts(primList[tag].get(), tagAttr, tag, false, {}, "verts", aux_arrays[tag].data(), aux_arrays[tag].size(),true);
}

#else
Expand Down

0 comments on commit 45508c6

Please sign in to comment.