add docu
This commit is contained in:
58
Doc/Tutorial/12-predicates/predicates.cc
Normal file
58
Doc/Tutorial/12-predicates/predicates.cc
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||||
|
#include <OpenMesh/Core/Mesh/DefaultTriMesh.hh>
|
||||||
|
#include <OpenMesh/Core/Utils/PropertyManager.hh>
|
||||||
|
#include <OpenMesh/Core/Utils/Predicates.hh>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using MyMesh = OpenMesh::TriMesh;
|
||||||
|
|
||||||
|
bool is_divisible_by_3(OpenMesh::FaceHandle vh) { return vh.idx() % 3 == 0; }
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
using namespace OpenMesh::Predicates; // for easier access to predicates
|
||||||
|
|
||||||
|
// Read command line options
|
||||||
|
MyMesh mesh;
|
||||||
|
if (argc != 4) {
|
||||||
|
std::cerr << "Usage: " << argv[0] << " infile" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const std::string infile = argv[1];
|
||||||
|
|
||||||
|
// Read mesh file
|
||||||
|
if (!OpenMesh::IO::read_mesh(mesh, infile)) {
|
||||||
|
std::cerr << "Error: Cannot read mesh from " << infile << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count boundary vertices
|
||||||
|
std::cout << "Mesh contains " << mesh.vertices().count_if(Boundary()) << " boundary vertices";
|
||||||
|
|
||||||
|
// Selected inner vertices
|
||||||
|
std::cout << "These are the selected inner vertices: " << std::endl;
|
||||||
|
for (auto vh : mesh.vertices().filtered(!Boundary() && Selected()))
|
||||||
|
std::cout << vh.idx() << ", ";
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
// Faces whose id is divisible by 3
|
||||||
|
auto vec = mesh.faces().filtered(is_divisible_by_3).to_vector();
|
||||||
|
std::cout << "There are " << vec.size() << " faces whose id is divisible by 3" << std::endl;
|
||||||
|
|
||||||
|
// Faces which are tagged or whose id is not divisible by 3
|
||||||
|
auto vec2 = mesh.faces().filtered(Tagged() || !make_predicate(is_divisible_by_3)).to_vector();
|
||||||
|
std::cout << "There are " << vec2.size() << " faces which are tagged or whose id is not divisible by 3" << std::endl;
|
||||||
|
|
||||||
|
// Edges that are longer than 10 or shorter than 2
|
||||||
|
OpenMesh::EProp<bool> longer_than_10(mesh);
|
||||||
|
for (auto eh : mesh.edges())
|
||||||
|
longer_than_10[eh] = mesh.calc_edge_length(eh) > 10;
|
||||||
|
std::cout << "There are " <<
|
||||||
|
mesh.edges().count_if(make_predicate(longer_than_10) || make_predicate([&](OpenMesh::EdgeHandle eh) { return mesh.calc_edge_length(eh) < 2; })) <<
|
||||||
|
" edges which are shorter than 2 or longer than 10" << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -83,6 +83,7 @@ repeatedly replacing each vertex' position by the center of gravity
|
|||||||
\li \ref tutorial_03
|
\li \ref tutorial_03
|
||||||
\li \ref tutorial_04
|
\li \ref tutorial_04
|
||||||
\li \ref tutorial_11
|
\li \ref tutorial_11
|
||||||
|
\li \ref tutorial_12
|
||||||
\li \ref tutorial_05
|
\li \ref tutorial_05
|
||||||
\li \ref tutorial_06
|
\li \ref tutorial_06
|
||||||
\li \ref tutorial_07
|
\li \ref tutorial_07
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ Similarily we compute the update vector as the laplace of the freshly computed l
|
|||||||
|
|
||||||
Finally, we apply the update after damping it by a factor of -0.5.
|
Finally, we apply the update after damping it by a factor of -0.5.
|
||||||
|
|
||||||
\skipline udpate points
|
\skipline update points
|
||||||
\until bi_laplace
|
\until bi_laplace
|
||||||
|
|
||||||
Below is the complete source code:
|
Below is the complete source code:
|
||||||
|
|||||||
38
Doc/tutorial_12.docu
Normal file
38
Doc/tutorial_12.docu
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/** \page tutorial_12 Filtering ranges with predicates
|
||||||
|
|
||||||
|
This examples shows:
|
||||||
|
- How to use predicates to filter which elements of a mesh you want iterate over
|
||||||
|
|
||||||
|
In the previous tutorial we discussed already that the ranges returned by functions like all_vertices(), voh_range() or outgoing_halfedges() provide a few helpful methods such as avg() or to_vector(). Another interesting method is filtered() which requires as argument something that can be called for an element of the range and returns a bool. The resulting range will then only iterate over elements for which the filter returs true.
|
||||||
|
The filter can be a lambda, a function pointer, a property manager holding a bool property, or a functor object such as the predicates defined in <OpenMesh/Core/Utils/Predicates.hh>. The predefined predicates can check the status of a mesh element and test if they are boundary.
|
||||||
|
With their help you can for example count all boundary vertices:
|
||||||
|
|
||||||
|
\dontinclude 12-predicates/predicates.cc
|
||||||
|
\skipline Count boundary vertices
|
||||||
|
\until boundary vertices
|
||||||
|
|
||||||
|
Predicates can be composed using the operators ||, &&, and !. This enables you to specify precisely which elements you want process in your loop, e.g. inner vertices that are selected:
|
||||||
|
|
||||||
|
\skipline Selected inner vertices
|
||||||
|
\until std::cout << std::endl
|
||||||
|
|
||||||
|
As mentioned above, the filter argument can be anything returning a bool for a given input, e.g. a function pointer:
|
||||||
|
|
||||||
|
\skipline Faces whose id is divisible by 3
|
||||||
|
\until faces whose id is divisible by 3
|
||||||
|
|
||||||
|
However, function pointers, lambdas etc are not composable. Fortunately, you can use make_predicate to turn them into composable predicates:
|
||||||
|
|
||||||
|
|
||||||
|
\skipline Faces which are tagged or whose id is not divisible by 3
|
||||||
|
\until faces which are tagged or whose id is not divisible by 3
|
||||||
|
|
||||||
|
Below is the complete source code:
|
||||||
|
|
||||||
|
\include 12-predicates/predicates.cc
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
@@ -34,6 +34,7 @@ repeatedly replacing each vertex' position by the center of gravity
|
|||||||
<li> \subpage tutorial_03
|
<li> \subpage tutorial_03
|
||||||
<li> \subpage tutorial_04
|
<li> \subpage tutorial_04
|
||||||
<li> \subpage tutorial_11
|
<li> \subpage tutorial_11
|
||||||
|
<li> \subpage tutorial_12
|
||||||
<li> \subpage tutorial_05
|
<li> \subpage tutorial_05
|
||||||
<li> \subpage tutorial_06
|
<li> \subpage tutorial_06
|
||||||
<li> \subpage tutorial_07
|
<li> \subpage tutorial_07
|
||||||
|
|||||||
Reference in New Issue
Block a user