update documentation

This commit is contained in:
Max Lyon
2019-11-06 11:41:41 +01:00
parent f47228003e
commit 3a2791c436
8 changed files with 22818 additions and 7 deletions

View File

@@ -70,7 +70,12 @@ struct SmartRangeT
{
// TODO: Someone with better c++ knowledge may improve the code below.
/** @brief Computes the sum of elements.
*
* Computes the sum of all elements in the range after applying the functor \p f.
*
* @param f Functor that is applied to all elements before computing the sum
*/
template <typename Functor>
auto sum(Functor&& f) -> decltype (f(std::declval<HandleT>())+f(std::declval<HandleT>()))
{
@@ -86,6 +91,12 @@ struct SmartRangeT
return sum;
}
/** @brief Computes the average of elements.
*
* Computes the average of all elements in the range after applying the functor \p f.
*
* @param f Functor that is applied to all elements before computing the average.
*/
template <typename Functor>
auto avg(Functor&& f) -> decltype (1.0 * (f(std::declval<HandleT>())+f(std::declval<HandleT>())))
{
@@ -105,6 +116,15 @@ struct SmartRangeT
return (1.0 / n_elements) * sum;
}
/** @brief Convert range to array.
*
* Converts the range of elements into an array of objects returned by functor \p f.
* The size of the array needs to be provided by the user. If the size is larger than the number of
* elements in the range, the remaining entries of the array will be uninitialized.
*
* @param f Functor that is applied to all elements before putting them into the array. If no functor is provided
* the array will contain the handles.
*/
template <int n, typename Functor = Identity>
auto to_array(Functor&& f = {}) -> std::array<typename std::remove_reference<decltype (f(std::declval<HandleT>()))>::type, n>
{
@@ -118,6 +138,13 @@ struct SmartRangeT
return res;
}
/** @brief Convert range to vector.
*
* Converts the range of elements into a vector of objects returned by functor \p f.
*
* @param f Functor that is applied to all elements before putting them into the vector. If no functor is provided
* the vector will contain the handles.
*/
template <typename Functor = Identity>
auto to_vector(Functor&& f = {}) -> std::vector<typename std::remove_reference<decltype (f(std::declval<HandleT>()))>::type>
{
@@ -128,7 +155,12 @@ struct SmartRangeT
return res;
}
/** @brief Compute minimum.
*
* Computes the minimum of all objects returned by functor \p f.
*
* @param f Functor that is applied to all elements before computing minimum.
*/
template <typename Functor>
auto min(Functor&& f) -> typename std::remove_reference<decltype (f(std::declval<HandleT>()))>::type
{
@@ -148,6 +180,12 @@ struct SmartRangeT
return res;
}
/** @brief Compute maximum.
*
* Computes the maximum of all objects returned by functor \p f.
*
* @param f Functor that is applied to all elements before computing maximum.
*/
template <typename Functor>
auto max(Functor&& f) -> typename std::remove_reference<decltype (f(std::declval<HandleT>()))>::type
{
@@ -167,6 +205,13 @@ struct SmartRangeT
return res;
}
/** @brief Computes minimum and maximum.
*
* Computes the minimum and maximum of all objects returned by functor \p f. Result is returned as std::pair
* containing minimum as first and maximum as second element.
*
* @param f Functor that is applied to all elements before computing maximum.
*/
template <typename Functor>
auto minmax(Functor&& f) -> std::pair<typename std::remove_reference<decltype (f(std::declval<HandleT>()))>::type,
typename std::remove_reference<decltype (f(std::declval<HandleT>()))>::type>

View File

@@ -226,6 +226,7 @@ class PropertyManager {
* Create a wrapper around an existing property. Lifetime is not managed.
*
* @param mesh The mesh on which to create the property.
* @param property_handle Handle to an existing property that should be wrapped.
*/
PropertyManager(PolyConnectivity& mesh, PROPTYPE property_handle) : mesh_(mesh), prop_(property_handle), retain_(true), name_() {
}

File diff suppressed because it is too large Load Diff

View File

@@ -446,14 +446,14 @@ TEST_F(OpenMeshTutorials, using_iterators_and_circulators) {
TEST_F(OpenMeshTutorials, using_custom_properties) {
MyMesh mesh;
bool ok = OpenMesh::IO::read_mesh(mesh, "output.off");
EXPECT_TRUE(ok) << "Cannot read mesh from file 'output.off'";
bool ok = OpenMesh::IO::read_mesh(mesh, "cube_noisy.off");
EXPECT_TRUE(ok) << "Cannot read mesh from file 'cube_noisy.off'";
const int iterations = 100;
{
// Add a vertex property storing the computed centers of gravity
auto cog = OpenMesh::makeTemporaryProperty<OpenMesh::VertexHandle, MyMesh::Point>(mesh);
auto cog = OpenMesh::VProp<MyMesh::Point>(mesh);
// Smooth the mesh several times
for (int i = 0; i < iterations; ++i) {
@@ -484,8 +484,8 @@ TEST_F(OpenMeshTutorials, using_custom_properties) {
TEST_F(OpenMeshTutorials, using_STL_algorithms) {
MyMeshWithTraits mesh;
bool ok = OpenMesh::IO::read_mesh(mesh, "output.off");
EXPECT_TRUE(ok) << "Cannot read mesh from file 'output.off'";
bool ok = OpenMesh::IO::read_mesh(mesh, "cube_noisy.off");
EXPECT_TRUE(ok) << "Cannot read mesh from file 'cube_noisy.off'";
SmootherT<MyMeshWithTraits> smoother(mesh);
smoother.smooth(100);
@@ -882,4 +882,44 @@ TEST_F(OpenMeshTutorials, collapsing_edges) {
// Our mesh now looks like in the illustration above after the collapsing.
}
TEST_F(OpenMeshTutorials, using_smart_handles_and_smart_ranges) {
MyMesh mesh;
bool ok = OpenMesh::IO::read_mesh(mesh, "cube_noisy.off");
EXPECT_TRUE(ok) << "Cannot read mesh from file 'cube_noisy.off'";
const int iterations = 100;
{
// Add a vertex property storing the laplace vector
auto laplace = OpenMesh::VProp<MyMesh::Point>(mesh);
// Add a vertex property storing the laplace of the laplace
auto bi_laplace = OpenMesh::VProp<MyMesh::Point>(mesh);
// Get a propertymanager of the points property of the mesh to use as functor
auto points = OpenMesh::getPointsProperty(mesh);
// Smooth the mesh several times
for (int i = 0; i < iterations; ++i) {
// Iterate over all vertices to compute laplace vector
for (const auto& vh : mesh.vertices())
laplace(vh) = vh.vertices().avg(points) - points(vh);
// Iterate over all vertices to compte update vectors as the negative of the laplace of the laplace damped by 0.5
for (const auto& vh : mesh.vertices())
bi_laplace(vh) = (vh.vertices().avg(laplace) - laplace(vh));
// update points
for (const auto& vh : mesh.vertices())
points(vh) += -0.5 * bi_laplace(vh);
}
} // The laplace and update properties are removed is removed from the mesh at the end of this scope.
// write mesh
ok = OpenMesh::IO::write_mesh(mesh, "smoothed_smart_output.off");
EXPECT_TRUE(ok) << "Cannot write mesh to file 'smoothed_smart_output.off'";
}
}