-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmain-inputcheck.cpp
138 lines (123 loc) · 6.33 KB
/
main-inputcheck.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*****************************************************************************************
* MIT License *
* *
* Copyright (c) 2022 G. Cherchi, F. Pellacini, M. Attene and M. Livesu *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION *
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Authors: *
* Gianmarco Cherchi ([email protected]) *
* https://www.gianmarcocherchi.com *
* *
* Fabio Pellacini ([email protected]) *
* https://pellacini.di.uniroma1.it *
* *
* Marco Attene ([email protected]) *
* https://www.cnr.it/en/people/marco.attene/ *
* *
* Marco Livesu ([email protected]) *
* http://pers.ge.imati.cnr.it/livesu/ *
* *
* ***************************************************************************************/
#ifdef _MSC_VER // Workaround for known bugs and issues on MSVC
#define _HAS_STD_BYTE 0 // https://developercommunity.visualstudio.com/t/error-c2872-byte-ambiguous-symbol/93889
#define NOMINMAX // https://stackoverflow.com/questions/1825904/error-c2589-on-stdnumeric-limitsdoublemin
#endif
#include <cinolib/meshes/trimesh.h>
#include <cinolib/find_intersections.h>
using namespace cinolib;
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
bool manifold(const Trimesh<> & m)
{
for(uint vid=0; vid<m.num_verts(); ++vid)
{
if(!m.vert_is_manifold(vid)) return false;
}
return true;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
bool watertight(const Trimesh<> & m)
{
for(uint eid=0; eid<m.num_edges(); ++eid)
{
if(m.edge_is_boundary(eid)) return false;
}
return true;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
bool local_orientation(const Trimesh<> & m)
{
std::vector<uint> visited(m.num_polys(),false);
for(uint pid=0; pid<m.num_polys(); ++pid)
{
if(visited[pid]) continue;
std::queue<uint> q;
q.push(pid);
visited[pid] = true;
while(!q.empty())
{
uint pid = q.front();
q.pop();
for(uint nbr : m.adj_p2p(pid))
{
uint eid = m.edge_shared(pid, nbr);
if(m.edge_is_CCW(eid,pid)==m.edge_is_CCW(eid,nbr)) return false;
if(!visited[nbr])
{
visited[nbr] = true;
q.push(nbr);
}
}
}
}
return true;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// WARNING: this is correct only if the mesh has a single connected component
bool global_orientation(const Trimesh<> & m)
{
vec3d O = m.bbox().min - vec3d(1,0,0); // surely external
double vol = 0;
for(uint pid=0; pid<m.num_polys(); ++pid)
{
// sum signed volumes
vol += tet_volume(m.poly_vert(pid,0),
m.poly_vert(pid,1),
m.poly_vert(pid,2), O);
}
// if faces are CCW volume is negative
return (vol<0);
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
bool intersection_free(const Trimesh<> & m)
{
std::set<ipair> intersections;
find_intersections(m, intersections);
return (intersections.empty());
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
int main(int argc, char **argv)
{
Trimesh<> m(argv[1]);
std::cout << "Manifold check: " << (manifold(m) ?"passed":"failed") << std::endl;
std::cout << "Watertight check: " << (watertight(m) ?"passed":"failed") << std::endl;
std::cout << "Local Orientation check: " << (local_orientation(m) ?"passed":"failed") << std::endl;
std::cout << "Global Orientation check: " << (global_orientation(m)?"passed":"failed") << std::endl;
std::cout << "Intersection check: " << (intersection_free(m) ?"passed":"failed") << std::endl;
return EXIT_SUCCESS;
}