11#include " collision_mesh.hpp"
22
33#include < ipc/distance/point_edge.hpp>
4-
54#include < ipc/utils/area_gradient.hpp>
65#include < ipc/utils/eigen_ext.hpp>
7- #include < ipc/utils/math.hpp>
86#include < ipc/utils/local_to_global.hpp>
97#include < ipc/utils/logger.hpp>
8+ #include < ipc/utils/math.hpp>
109#include < ipc/utils/unordered_map_and_set.hpp>
1110
12- #include < tbb/parallel_for.h>
1311#include < tbb/blocked_range.h>
12+ #include < tbb/parallel_for.h>
1413
1514namespace ipc {
1615
@@ -134,13 +133,11 @@ void CollisionMesh::construct_edges_to_faces()
134133{
135134 if (dim () == 2 )
136135 return ;
137-
136+
138137 m_edges_to_faces.setOnes (num_edges (), 2 );
139138 m_edges_to_faces *= -1 ;
140- for (int f = 0 ; f < m_faces_to_edges.rows (); f++)
141- {
142- for (int le = 0 ; le < 3 ; le++)
143- {
139+ for (int f = 0 ; f < m_faces_to_edges.rows (); f++) {
140+ for (int le = 0 ; le < 3 ; le++) {
144141 if (m_edges_to_faces (m_faces_to_edges (f, le), 0 ) < 0 )
145142 m_edges_to_faces (m_faces_to_edges (f, le), 0 ) = f;
146143 else if (m_edges_to_faces (m_faces_to_edges (f, le), 1 ) < 0 )
@@ -278,7 +275,7 @@ void CollisionMesh::init_areas()
278275 m_vertices_to_edges[m_edges (i, j)].push_back (i);
279276 }
280277 }
281-
278+
282279 m_vertices_to_faces.resize (num_vertices ());
283280 for (int i = 0 ; i < m_faces.rows (); i++) {
284281 for (int j = 0 ; j < m_faces.cols (); j++) {
@@ -513,9 +510,11 @@ Eigen::MatrixXi CollisionMesh::construct_faces_to_edges(
513510 return faces_to_edges;
514511}
515512
516- double CollisionMesh::edge_length (const int & edge_id) const
513+ double CollisionMesh::edge_length (const int & edge_id) const
517514{
518- return (m_rest_positions.row (m_edges (edge_id, 0 )) - m_rest_positions.row (m_edges (edge_id, 1 ))).norm ();
515+ return (m_rest_positions.row (m_edges (edge_id, 0 ))
516+ - m_rest_positions.row (m_edges (edge_id, 1 )))
517+ .norm ();
519518}
520519
521520double CollisionMesh::max_edge_length () const
@@ -526,59 +525,54 @@ double CollisionMesh::max_edge_length() const
526525 return val;
527526}
528527
529- std::vector<long > CollisionMesh::find_vertex_adjacent_vertices (const long &v) const
528+ std::vector<long >
529+ CollisionMesh::find_vertex_adjacent_vertices (const long & v) const
530530{
531531 std::vector<long > neighbors;
532- if (dim () == 2 )
533- {
532+ if (dim () == 2 ) {
534533 neighbors.assign (2 , -1 );
535- for (long i : vertex_edge_adjacencies ()[v])
536- {
534+ for (long i : vertex_edge_adjacencies ()[v]) {
537535 if (edges ()(i, 0 ) == v)
538536 neighbors[0 ] = edges ()(i, 1 );
539537 else if (edges ()(i, 1 ) == v)
540538 neighbors[1 ] = edges ()(i, 0 );
541539 else
542540 throw std::runtime_error (" Invalid edge-vertex adjacency!" );
543541 }
544- }
545- else
546- {
547- if (vertices_to_faces ()[v].size () > 0 )
548- {
549- // construct a map of neighboring vertices, it maps every neighbor to the next counter-clockwise neighbor
542+ } else {
543+ if (vertices_to_faces ()[v].size () > 0 ) {
544+ // construct a map of neighboring vertices, it maps every neighbor
545+ // to the next counter-clockwise neighbor
550546 std::unordered_map<long , long > map;
551- for (auto f : vertices_to_faces ()[v])
552- {
553- for (int lv = 0 ; lv < 3 ; lv++)
554- {
555- if (faces ()(f, lv) == v)
556- {
557- map[faces ()(f, (lv+1 )%3 )] = faces ()(f, (lv+2 )%3 );
547+ for (auto f : vertices_to_faces ()[v]) {
548+ for (int lv = 0 ; lv < 3 ; lv++) {
549+ if (faces ()(f, lv) == v) {
550+ map[faces ()(f, (lv + 1 ) % 3 )] =
551+ faces ()(f, (lv + 2 ) % 3 );
558552 break ;
559553 }
560554 }
561555 }
562556 if (vertices_to_faces ()[v].size () != map.size ())
563- throw std::runtime_error (" Non-manifold vertex! Map size smaller than neighbor!" );
564-
557+ throw std::runtime_error (
558+ " Non-manifold vertex! Map size smaller than neighbor!" );
559+
565560 // verify that the neighboring vertices form a loop
566561 auto iter = map.find (map.begin ()->first );
567- while (neighbors.empty () || iter->first != neighbors.front ())
568- {
562+ while (neighbors.empty () || iter->first != neighbors.front ()) {
569563 neighbors.push_back (iter->first );
570564 iter = map.find (iter->second );
571- if (iter == map.end ())
572- {
573- logger ().error (" neighbor faces {}, map {}" , vertices_to_faces ()[v].size (), map);
574- throw std::runtime_error (" Non-manifold vertex! Cannot find next neighbor!" );
565+ if (iter == map.end ()) {
566+ logger ().error (
567+ " neighbor faces {}, map {}" ,
568+ vertices_to_faces ()[v].size (), map);
569+ throw std::runtime_error (
570+ " Non-manifold vertex! Cannot find next neighbor!" );
575571 }
576572 }
577573 if (neighbors.size () != map.size ())
578574 throw std::runtime_error (" Non-manifold vertex!" );
579- }
580- else
581- {
575+ } else {
582576 for (int eid : vertices_to_edges ()[v])
583577 neighbors.push_back (
584578 edges ()(eid, 0 ) == v ? edges ()(eid, 1 ) : edges ()(eid, 0 ));
0 commit comments