Developer Documentation
Loading...
Searching...
No Matches
predicates.cc
1
2#include <OpenMesh/Core/IO/MeshIO.hh>
3#include <OpenMesh/Core/Mesh/DefaultTriMesh.hh>
4#include <OpenMesh/Core/Utils/PropertyManager.hh>
5#include <OpenMesh/Core/Utils/Predicates.hh>
6
7#include <iostream>
8#include <vector>
9
11
12bool is_divisible_by_3(OpenMesh::FaceHandle vh) { return vh.idx() % 3 == 0; }
13
14int main(int argc, char** argv)
15{
16 using namespace OpenMesh::Predicates; // for easier access to predicates
17
18 // Read command line options
19 MyMesh mesh;
20 if (argc != 4) {
21 std::cerr << "Usage: " << argv[0] << " infile" << std::endl;
22 return 1;
23 }
24 const std::string infile = argv[1];
25
26 // Read mesh file
27 if (!OpenMesh::IO::read_mesh(mesh, infile)) {
28 std::cerr << "Error: Cannot read mesh from " << infile << std::endl;
29 return 1;
30 }
31
32 // Count boundary vertices
33 std::cout << "Mesh contains " << mesh.vertices().count_if(Boundary()) << " boundary vertices";
34
35 // Selected inner vertices
36 std::cout << "These are the selected inner vertices: " << std::endl;
37 for (auto vh : mesh.vertices().filtered(!Boundary() && Selected()))
38 std::cout << vh.idx() << ", ";
39 std::cout << std::endl;
40
41 // Faces whose id is divisible by 3
42 auto vec = mesh.faces().filtered(is_divisible_by_3).to_vector();
43 std::cout << "There are " << vec.size() << " faces whose id is divisible by 3" << std::endl;
44
45 // Faces which are tagged or whose id is not divisible by 3
46 auto vec2 = mesh.faces().filtered(Tagged() || !make_predicate(is_divisible_by_3)).to_vector();
47 std::cout << "There are " << vec2.size() << " faces which are tagged or whose id is not divisible by 3" << std::endl;
48
49 // Edges that are longer than 10 or shorter than 2
50 OpenMesh::EProp<bool> longer_than_10(mesh);
51 for (auto eh : mesh.edges())
52 longer_than_10[eh] = mesh.calc_edge_length(eh) > 10;
53 std::cout << "There are " <<
54 mesh.edges().count_if(make_predicate(longer_than_10) || make_predicate([&](OpenMesh::EdgeHandle eh) { return mesh.calc_edge_length(eh) < 2; })) <<
55 " edges which are shorter than 2 or longer than 10" << std::endl;
56
57}
58
int idx() const
Get the underlying index of this handle.
Definition Handles.hh:69
Scalar calc_edge_length(EdgeHandle _eh) const
Compute normals for all primitives.
Definition PolyMeshT.hh:434
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition MeshIO.hh:95
Handle for a edge entity.
Definition Handles.hh:135
Handle for a face entity.
Definition Handles.hh:142