@@ -16,26 +16,34 @@ namespace ipc::rigid {
1616// / MeshData
1717// =============================================================================
1818
19- const glm::vec3 MeshData::EDGE_COLOR (0 .0 , 0 .0 , 0 .0 ); // #000000
19+ const glm::vec3 MeshData::EDGE_COLOR (1 .0 , 1 .0 , 1 .0 ); // #FFFFFF
2020const glm::vec3
2121 MeshData::STATIC_COLOR (0xB3 / 255.0 , 0xB3 / 255.0 , 0xB3 / 255.0 ); // #B3B3B3
2222// const glm::vec3 MeshData::KINEMATIC_COLOR(1.0, 0.5, 0.0); // #FF8000
2323const glm::vec3 MeshData::KINEMATIC_COLOR (
2424 0xE3 / 255.0 , 0x82 / 255.0 , 0x1C / 255.0 ); // #E3821C
2525
2626void MeshData::set_mesh (
27- const Eigen::MatrixXd& V ,
27+ const Eigen::MatrixXd& _V ,
2828 const Eigen::MatrixXi& E,
2929 const Eigen::MatrixXi& F,
3030 const std::vector<int >& CE2E,
3131 const std::vector<int >& CV2V)
3232{
33- ps_surface_mesh = ps::registerSurfaceMesh (" mesh" , V, F);
33+ const int dim = _V.cols ();
34+ Eigen::MatrixXd V (_V.rows (), 3 );
35+ V.leftCols (dim) = _V;
36+ if (dim == 2 ) {
37+ V.col (2 ).setZero ();
38+ }
3439
35- ps_velocities = ps_surface_mesh->addVertexVectorQuantity (
36- " velocities" , Eigen::MatrixXd::Zero (V.rows (), V.cols ()));
37- ps_velocities->setEnabled (false );
38- ps_velocities->setVectorColor (velocity_color);
40+ if (F.size () > 0 ) {
41+ ps_surface_mesh = ps::registerSurfaceMesh (" mesh" , V, F);
42+ ps_velocities = ps_surface_mesh->addVertexVectorQuantity (
43+ " velocities" , Eigen::MatrixXd::Zero (V.rows (), V.cols ()));
44+ ps_velocities->setEnabled (false );
45+ ps_velocities->setVectorColor (velocity_color);
46+ }
3947
4048 if (CE2E.size () > 0 ) {
4149 Eigen::MatrixXi CE;
@@ -51,9 +59,14 @@ void MeshData::set_mesh(
5159
5260 if (CE.rows () != 0 ) {
5361 ps_codim_edges = ps::registerCurveNetwork (" edges" , CE_V, CE_E);
54- ps_codim_edges->setRadius (5e-4 );
55- ps_codim_edges->setColor (EDGE_COLOR);
62+ ps_codim_edges->setRadius (dim == 2 ? 1e-3 : 5e-4 );
63+ if (dim == 3 ) {
64+ ps_codim_edges->setColor (EDGE_COLOR);
65+ }
5666 }
67+ } else if (ps_codim_edges != nullptr ) {
68+ ps::removeStructure (ps_codim_edges);
69+ ps_codim_edges = nullptr ;
5770 }
5871
5972 if (CV2V.size () > 0 ) {
@@ -65,11 +78,21 @@ void MeshData::set_mesh(
6578 ps_codim_points = ps::registerPointCloud (" vertices" , CV);
6679 ps_codim_points->setPointRadius (5e-4 );
6780 ps_codim_points->setPointColor (EDGE_COLOR);
81+ } else if (ps_codim_points != nullptr ) {
82+ ps::removeStructure (ps_codim_points);
83+ ps_codim_points = nullptr ;
6884 }
6985}
7086
71- void MeshData::update_vertices (const Eigen::MatrixXd& V )
87+ void MeshData::update_vertices (const Eigen::MatrixXd& _V )
7288{
89+ const int dim = _V.cols ();
90+ Eigen::MatrixXd V (_V.rows (), 3 );
91+ V.leftCols (dim) = _V;
92+ if (dim == 2 ) {
93+ V.col (2 ).setZero ();
94+ }
95+
7396 if (ps_surface_mesh != nullptr ) {
7497 ps_surface_mesh->updateVertexPositions (V);
7598 }
@@ -95,19 +118,33 @@ void MeshData::update_velocities(const Eigen::MatrixXd& velocities)
95118
96119void MeshData::set_vertex_types (const Eigen::VectorXi& vertex_types)
97120{
98- if (ps_surface_mesh != nullptr ) {
99- std::vector<glm::vec3> colors (vertex_types.size ());
100- for (int i = 0 ; i < vertex_types.size (); i++) {
101- if (vertex_types (i) == 0 ) {
102- colors[i] = STATIC_COLOR;
103- } else if (vertex_types (i) == 1 ) {
104- colors[i] = KINEMATIC_COLOR;
105- } else {
106- colors[i] = mesh_color; // Default color for other types
107- }
121+ std::vector<glm::vec3> colors (vertex_types.size ());
122+ for (int i = 0 ; i < vertex_types.size (); i++) {
123+ if (vertex_types (i) == 0 ) {
124+ colors[i] = STATIC_COLOR;
125+ } else if (vertex_types (i) == 1 ) {
126+ colors[i] = KINEMATIC_COLOR;
127+ } else {
128+ colors[i] = mesh_color; // Default color for other types
108129 }
109- ps_surface_mesh->addVertexColorQuantity (" type" , colors)
110- ->setEnabled (true );
130+ }
131+ if (ps_surface_mesh != nullptr ) {
132+ ps_surface_mesh->addVertexColorQuantity (" type" , colors);
133+ } else if (ps_codim_edges != nullptr ) {
134+ ps_codim_edges->addNodeColorQuantity (" type" , colors);
135+ }
136+ }
137+
138+ void MeshData::set_vertex_ids (const Eigen::VectorXi& ids)
139+ {
140+ if (ps_surface_mesh != nullptr ) {
141+ auto tmp = ps_surface_mesh->addVertexScalarQuantity (" id" , ids);
142+ tmp->setEnabled (true );
143+ tmp->setColorMap (" rainbow" );
144+ } else if (ps_codim_edges != nullptr ) {
145+ auto tmp = ps_codim_edges->addNodeScalarQuantity (" id" , ids);
146+ tmp->setEnabled (true );
147+ tmp->setColorMap (" rainbow" );
111148 }
112149}
113150
@@ -118,17 +155,16 @@ void MeshData::set_vertex_types(const Eigen::VectorXi& vertex_types)
118155void CoMData::set_coms (const ipc::rigid::PosesD& poses)
119156{
120157 int dim = poses.size () ? poses[0 ].dim () : 0 ;
121- Eigen::MatrixXd coms (poses.size (), dim);
122- std::vector<Eigen::MatrixXd> principle_axes (
123- dim, Eigen::MatrixXd (poses.size (), dim));
158+ Eigen::MatrixXd coms = Eigen::MatrixXd::Zero (poses.size (), 3 );
159+ std::vector<Eigen::MatrixXd> principle_axes (dim, coms);
124160
125161 for (int i = 0 ; i < poses.size (); i++) {
126- coms.row (i) = poses[i].position ;
162+ coms.row (i). head (dim) = poses[i].position ;
127163 MatrixMax3d R = poses[i].construct_rotation_matrix ();
128164 for (int j = 0 ; j < dim; j++) {
129165 VectorMax3d axis = VectorMax3d::Zero (dim);
130166 axis (j) = 1 ;
131- principle_axes[j].row (i) = R * axis;
167+ principle_axes[j].row (i). head (dim) = R * axis;
132168 }
133169 }
134170
@@ -150,21 +186,20 @@ void CoMData::set_coms(const ipc::rigid::PosesD& poses)
150186void CoMData::update_coms (const ipc::rigid::PosesD& poses)
151187{
152188 int dim = poses.size () ? poses[0 ].dim () : 0 ;
153- Eigen::MatrixXd coms (poses.size (), dim);
154- std::vector<Eigen::MatrixXd> principle_axes (
155- dim, Eigen::MatrixXd (poses.size (), dim));
189+ Eigen::MatrixXd coms = Eigen::MatrixXd::Zero (poses.size (), 3 );
190+ std::vector<Eigen::MatrixXd> principle_axes (dim, coms);
156191
157192 for (int i = 0 ; i < poses.size (); i++) {
158- coms.row (i) = poses[i].position ;
193+ coms.row (i). head (dim) = poses[i].position ;
159194 MatrixMax3d R = poses[i].construct_rotation_matrix ();
160195 for (int j = 0 ; j < dim; j++) {
161196 VectorMax3d axis = VectorMax3d::Zero (dim);
162197 axis (j) = 1 ;
163- principle_axes[j].row (i) = R * axis;
198+ principle_axes[j].row (i). head (dim) = R * axis;
164199 }
165200 }
166201
167- ps_coms-> updatePointPositions ( coms);
202+ ps_coms = ps::registerPointCloud ( " CoMs " , coms);
168203
169204 for (int j = 0 ; j < dim; j++) {
170205 ps_coms->addVectorQuantity (
0 commit comments