Skip to content

Commit 23c80c6

Browse files
committed
support auto build neighbor geometry
1 parent cc6ff71 commit 23c80c6

File tree

4 files changed

+87
-9
lines changed

4 files changed

+87
-9
lines changed

RenderingFrameWork/src/renderable.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,74 @@
44
*/
55

66
#include "renderable.h"
7+
8+
void HINAVIEWER::RENDERABLE::Renderable::build_neighbors()
9+
{
10+
if (V_.rows() == 0)
11+
return;
12+
13+
int vertices_per_face = 3; // triangle mesh only
14+
15+
VE_.clear();
16+
VF_.clear();
17+
EVF_.clear();
18+
FE_.clear();
19+
20+
VE_.resize(V_.rows());
21+
VF_.resize(V_.rows());
22+
FE_.resize(F_.rows());
23+
EVF_.reserve(E_.rows());
24+
25+
for (int i = 0; i < F_.rows(); ++i)
26+
{
27+
FE_[i].resize(vertices_per_face);
28+
for (int j = 0; j < vertices_per_face; ++j)
29+
{
30+
const unsigned int v_index = F_.row(i)(j);
31+
32+
bool found = false;
33+
for (auto &face_index: VF_[v_index])
34+
{
35+
if (face_index == i)
36+
{
37+
found = true;
38+
break;
39+
}
40+
}
41+
42+
if (!found)
43+
VF_[v_index].emplace_back(i);
44+
45+
const unsigned int ev1 = F_.row(i)(j);
46+
const unsigned int ev2 = F_.row(i)((j + 1) % 3);
47+
unsigned int edge = 0xffffffff;
48+
for (auto &edge_index: VE_[ev1])
49+
if ((EVF_[edge_index][0] == ev1 || EVF_[edge_index][0] == ev2) && (EVF_[edge_index][1] == ev1 || EVF_[edge_index][1] == ev2))
50+
edge = edge_index;
51+
if (edge == 0xffffffff)
52+
{
53+
EVF_.emplace_back(std::vector<unsigned int>({ev1, ev2, static_cast<unsigned int>(i), 0xffffffff}));
54+
edge = EVF_.size() - 1;
55+
VE_[ev1].emplace_back(edge);
56+
VE_[ev2].emplace_back(edge);
57+
} else
58+
EVF_[edge][3] = i;
59+
60+
FE_[i][j] = edge;
61+
}
62+
}
63+
64+
E_.resize(EVF_.size(), 2);
65+
for (int i = 0; i < EVF_.size(); ++i)
66+
E_.row(i) = Eigen::RowVector2i(EVF_[i][0], EVF_[i][1]);
67+
68+
for (auto &evf: EVF_)
69+
{
70+
if (evf[3] == 0xffffffff)
71+
{
72+
is_closed_ = false;
73+
return;
74+
}
75+
}
76+
is_closed_ = true;
77+
}

RenderingFrameWork/src/renderable.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "../eigen_types.h"
1010

11+
#include <vector>
1112
#include <string>
1213

1314
namespace HINAVIEWER::RENDERABLE
@@ -17,14 +18,22 @@ namespace HINAVIEWER::RENDERABLE
1718
public:
1819
virtual void init_geometry(const std::string &path) = 0;
1920

21+
void build_neighbors();
22+
2023
public:
2124
bool is_recorded_ = false;
2225
int ID_ = -1; // invalid unless recorded
2326

2427
public:
25-
Eigen::MatrixXd V_;
26-
Eigen::MatrixXi F_;
27-
Eigen::MatrixXi E_;
28+
Eigen::MatrixXd V_; // Vertices - size = [#vertices x 3], row = [x, y, z]
29+
Eigen::MatrixXi F_; // Faces - size = [#faces x 3], row = [v1_index, v2_index, v3_index]
30+
Eigen::MatrixXi E_; // Edges - size = [#edges x 2], row = [v1_index, v2_index]
31+
32+
std::vector<std::vector<unsigned int>> VE_; // Vertex-edges - size = [#vertices x ?], row = [edge1_index, edge2_index, ... ...]
33+
std::vector<std::vector<unsigned int>> VF_; // Vertex-faces - size = [#faces x ?], row = [face1_index, face2_index, ... ...]
34+
std::vector<std::vector<unsigned int>> FE_; // Face-edges - size = [#faces x 3], row = [edge1_index, edge2_index, edge3_index]
35+
std::vector<std::vector<unsigned int>> EVF_; // Edge-vertices-faces - size = [#edges x 4], row = [v1_index, v2_index, face1_index, face2_index]
36+
bool is_closed_;
2837
};
2938
}
3039

SimulationFrameWork/src/objects.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
#include "objects.h"
77

8-
#include "cmake-build-release/_deps/libigl-src/include/igl/edges.h"
9-
#include "cmake-build-release/_deps/libigl-src/include/igl/readOBJ.h"
10-
#include "cmake-build-release/_deps/libigl-src/include/igl/readPLY.h"
8+
#include <igl/readOBJ.h>
9+
#include <igl/readPLY.h>
1110

1211
void HINASIM::SimObject::init_geometry(const std::string &path)
1312
{
@@ -27,7 +26,7 @@ void HINASIM::SimObject::init_geometry(const std::string &path)
2726
else if (model_type == "ply")
2827
igl::readPLY(path, V_, F_);
2928

30-
igl::edges(F_, E_);
29+
build_neighbors(); // Edges info would be auto build ourselves
3130

3231
if (V_.rows() > 0)
3332
init_physical_state();
@@ -119,7 +118,7 @@ void HINASIM::Cloth::init_geometry()
119118

120119
custom_init_geometry(V_, F_);
121120

122-
igl::edges(F_, E_);
121+
build_neighbors(); // Edges info would be auto build ourselves
123122

124123
if (V_.rows() > 0)
125124
init_physical_state();

SimulationFrameWork/test/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ int main()
3030
HINASIM::Cloth cloth(30, 30, 20, 20);
3131
cloth.init_geometry();
3232
HINASIM::DistanceConstraint dc_cloth(cloth.q_, cloth.E_);
33-
3433
func(pbd_viewer, pbd_sim, cloth, dc_cloth);
3534

3635

0 commit comments

Comments
 (0)