Skip to content

Commit

Permalink
Merge 926bbc0 into a8b4454
Browse files Browse the repository at this point in the history
  • Loading branch information
dsieger committed Aug 17, 2020
2 parents a8b4454 + 926bbc0 commit a3d576f
Show file tree
Hide file tree
Showing 27 changed files with 229 additions and 143 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ This project aims to adhere to [Semantic Versioning](https://semver.org/spec/v2.
- Add post-increment iterators and make low level functions to add elements
public. This makes it possible to use CGAL algorithms on a PMP SurfaceMesh.
Thanks to @afabri for contributing the changes!
- Add PMP_INSTALL option to CMake.

## [1.2.1] 2020-05-10

Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Expand Up @@ -22,6 +22,7 @@ option(PMP_BUILD_APPS "Build the PMP applications" ON)
option(PMP_BUILD_EXAMPLES "Build the PMP examples" ON)
option(PMP_BUILD_TESTS "Build the PMP test programs" ON)
option(PMP_BUILD_DOCS "Build the PMP documentation" ON)
option(PMP_INSTALL "Install the PMP library and headers" ON)

# set output paths
set(PROJECT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
Expand Down Expand Up @@ -195,7 +196,7 @@ set(CPACK_SOURCE_IGNORE_FILES "/build/;/.git/;~$;${CPACK_SOURCE_IGNORE_FILES}")
set(CPACK_SOURCE_GENERATOR "ZIP")
include(CPack)

if(NOT EMSCRIPTEN)
if(NOT EMSCRIPTEN AND PMP_INSTALL)

# Generate package configuration files
include(CMakePackageConfigHelpers)
Expand Down Expand Up @@ -224,7 +225,7 @@ if(NOT EMSCRIPTEN)
endif()

# add uninstall target if none is defined
if(NOT TARGET uninstall)
if(NOT TARGET uninstall AND PMP_INSTALL)

configure_file("${CMAKE_MODULE_PATH}/cmake_uninstall.cmake.in"
cmake_uninstall.cmake IMMEDIATE @ONLY)
Expand Down
2 changes: 1 addition & 1 deletion src/pmp/CMakeLists.txt
Expand Up @@ -34,7 +34,7 @@ if(${CMAKE_VERSION} VERSION_GREATER "3.6.0")
endif()


if(NOT EMSCRIPTEN)
if(NOT EMSCRIPTEN AND PMP_INSTALL)

target_include_directories(pmp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../>
Expand Down
14 changes: 7 additions & 7 deletions src/pmp/SurfaceMesh.cpp
Expand Up @@ -298,17 +298,17 @@ Face SurfaceMesh::add_face(const std::vector<Vertex>& vertices)
{
if (!is_boundary(vertices[i]))
{
std::cerr << "SurfaceMesh::add_face: complex vertex\n";
return Face();
auto what = "SurfaceMesh::add_face: Complex vertex.";
throw TopologyException(what);
}

halfedges[i] = find_halfedge(vertices[i], vertices[ii]);
isNew[i] = !halfedges[i].is_valid();

if (!isNew[i] && !is_boundary(halfedges[i]))
{
std::cerr << "SurfaceMesh::add_face: complex edge\n";
return Face();
auto what = "SurfaceMesh::add_face: Complex edge.";
throw TopologyException(what);
}
}

Expand Down Expand Up @@ -342,9 +342,9 @@ Face SurfaceMesh::add_face(const std::vector<Vertex>& vertices)
// ok ?
if (boundaryNext == innerNext)
{
std::cerr
<< "SurfaceMeshT::add_face: patch re-linking failed\n";
return Face();
auto what =
"SurfaceMesh::add_face: Patch re-linking failed.";
throw TopologyException(what);
}

// other halfedges' handles
Expand Down
39 changes: 21 additions & 18 deletions src/pmp/SurfaceMesh.h
Expand Up @@ -993,7 +993,8 @@ class SurfaceMesh
//! add a new vertex with position \p p
Vertex add_vertex(const Point& p);

//! add a new face with vertex list \p vertices
//! \brief Add a new face with vertex list \p vertices
//! \throw TopologyException in case a topological error occurs.
//! \sa add_triangle, add_quad
Face add_face(const std::vector<Vertex>& vertices);

Expand Down Expand Up @@ -1822,28 +1823,28 @@ class SurfaceMesh
//! \name Allocate new elements
//!@{

//! allocate a new vertex, resize vertex properties accordingly.
//! \brief Allocate a new vertex, resize vertex properties accordingly.
//! \throw AllocationException in case of failure to allocate a new vertex.
Vertex new_vertex()
{
if (vertices_size() == PMP_MAX_INDEX - 1)
{
std::cerr
<< "new_vertex: cannot allocate vertex, max. index reached"
<< std::endl;
return Vertex();
auto what =
"SurfaceMesh: cannot allocate vertex, max. index reached";
throw AllocationException(what);
}
vprops_.push_back();
return Vertex(vertices_size() - 1);
}

//! allocate a new edge, resize edge and halfedge properties accordingly.
//! \brief Allocate a new edge, resize edge and halfedge properties accordingly.
//! \throw AllocationException in case of failure to allocate a new edge.
Halfedge new_edge()
{
if (halfedges_size() == PMP_MAX_INDEX - 1)
{
std::cerr << "new_edge: cannot allocate edge, max. index reached"
<< std::endl;
return Halfedge();
auto what = "SurfaceMesh: cannot allocate edge, max. index reached";
throw AllocationException(what);
}

eprops_.push_back();
Expand All @@ -1856,16 +1857,18 @@ class SurfaceMesh
return h0;
}

//! allocate a new edge, resize edge and halfedge properties accordingly.
//! \brief Allocate a new edge, resize edge and halfedge properties accordingly.
//! \throw AllocationException in case of failure to allocate a new edge.
//! \param start starting Vertex of the new edge
//! \param end end Vertex of the new edge
Halfedge new_edge(Vertex start, Vertex end)
{
assert(start != end);

if (halfedges_size() == PMP_MAX_INDEX - 1)
{
std::cerr << "new_edge: cannot allocate edge, max. index reached"
<< std::endl;
return Halfedge();
auto what = "SurfaceMesh: cannot allocate edge, max. index reached";
throw AllocationException(what);
}

eprops_.push_back();
Expand All @@ -1881,14 +1884,14 @@ class SurfaceMesh
return h0;
}

//! allocate a new face, resize face properties accordingly.
//! \brief Allocate a new face, resize face properties accordingly.
//! \throw AllocationException in case of failure to allocate a new face.
Face new_face()
{
if (faces_size() == PMP_MAX_INDEX - 1)
{
std::cerr << "new_face: cannot allocate face, max. index reached"
<< std::endl;
return Face();
auto what = "SurfaceMesh: cannot allocate face, max. index reached";
throw AllocationException(what);
}

fprops_.push_back();
Expand Down
12 changes: 5 additions & 7 deletions src/pmp/SurfaceMeshIO.cpp
Expand Up @@ -468,10 +468,7 @@ bool read_off_ascii(SurfaceMesh& mesh, FILE* in, const bool has_normals,
vertices[j] = Vertex(idx);
lp += nc;
}
if (vertices.size() == nv)
mesh.add_face(vertices);
else
std::cerr << "OFF: fail to read face " << i << std::endl;
mesh.add_face(vertices);
}

return true;
Expand Down Expand Up @@ -1188,15 +1185,16 @@ bool SurfaceMeshIO::write_stl(const SurfaceMesh& mesh)
{
if (!mesh.is_triangle_mesh())
{
std::cerr << "write_stl: not a triangle mesh!" << std::endl;
auto what = "SurfaceMeshIO::write_stl: Not a triangle mesh.";
throw InvalidInputException(what);
return false;
}

auto fnormals = mesh.get_face_property<Normal>("f:normal");
if (!fnormals)
{
std::cerr << "write_stl: no face normals present!" << std::endl;
return false;
auto what = "SurfaceMeshIO::write_stl: No face normals present.";
throw InvalidInputException(what);
}

std::ofstream ofs(filename_.c_str());
Expand Down
37 changes: 37 additions & 0 deletions src/pmp/Types.h
Expand Up @@ -5,6 +5,8 @@

#include <cstdint>

#include <stdexcept>

#include "pmp/MatVec.h"

//! \def PMP_ASSERT(x)
Expand Down Expand Up @@ -73,6 +75,41 @@ struct IOFlags
bool use_halfedge_texcoords = false; //!< read / write halfedge texcoords
};

//! \brief Exception indicating invalid input passed to a function.
//! \details This exception should be used to signal violation of a
//! precondition, e.g., if an algorithm expects a pure triangle mesh but a
//! general polygon mesh is passed instead.
class InvalidInputException : public std::invalid_argument
{
public:
InvalidInputException(const std::string& what) : std::invalid_argument(what)
{
}
};

//! \brief Exception indicating failure so solve an equation system.
class SolverException : public std::runtime_error
{
public:
SolverException(const std::string& what) : std::runtime_error(what) {}
};

//! \brief Exception indicating failure to allocate a new resource.
//! \details This exception signals an error resulting from an attempt to exceed
//! implementation-defined allocation limits.
class AllocationException : public std::length_error
{
public:
AllocationException(const std::string& what) : std::length_error(what) {}
};

//! \brief Exception indicating a topological error has occurred.
class TopologyException : public std::logic_error
{
public:
TopologyException(const std::string& what) : std::logic_error(what) {}
};

//! @}

//! \defgroup core core
Expand Down
4 changes: 3 additions & 1 deletion src/pmp/algorithms/CMakeLists.txt
Expand Up @@ -3,6 +3,8 @@
file(GLOB HEADERS ./algorithms/*.h)
file(GLOB SOURCES ./algorithms/*.cpp)

install(FILES ${HEADERS} DESTINATION include/pmp/algorithms)
if (PMP_INSTALL)
install(FILES ${HEADERS} DESTINATION include/pmp/algorithms)
endif()

target_sources(pmp PRIVATE "${SOURCES}" "${HEADERS}")
5 changes: 2 additions & 3 deletions src/pmp/algorithms/Heap.h
Expand Up @@ -110,7 +110,8 @@ class Heap : private std::vector<HeapEntry>
upheap(pos);
}

//! check heap condition
//! \brief Check heap condition.
//! \return \c true if heap condition is satisfied, \c false if not.
bool check()
{
bool ok(true);
Expand All @@ -120,13 +121,11 @@ class Heap : private std::vector<HeapEntry>
if (((j = left(i)) < size()) &&
interface_.greater(entry(i), entry(j)))
{
std::cerr << "Heap condition violated\n";
ok = false;
}
if (((j = right(i)) < size()) &&
interface_.greater(entry(i), entry(j)))
{
std::cerr << "Heap condition violated\n";
ok = false;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/pmp/algorithms/SurfaceFairing.cpp
Expand Up @@ -116,9 +116,8 @@ void SurfaceFairing::fair(unsigned int k)
// we need locked vertices as boundary constraints
if (vertices.size() == mesh_.n_vertices())
{
std::cerr << "SurfaceFairing: need locked vertices as boundary "
"constraints.\n";
return;
auto what = "SurfaceFairing: Missing boundary constraints.";
throw InvalidInputException(what);
}

// construct matrix & rhs
Expand Down Expand Up @@ -162,7 +161,7 @@ void SurfaceFairing::fair(unsigned int k)

if (solver.info() != Eigen::Success)
{
std::cerr << "SurfaceFairing: Could not solve linear system\n";
throw SolverException("SurfaceFairing: Failed to solve linear system.");
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/pmp/algorithms/SurfaceFairing.h
Expand Up @@ -28,6 +28,7 @@ class SurfaceFairing
void minimize_curvature() { fair(2); }

//! compute surface by solving k-harmonic equation
//! \throw SolverException in case of failure to solve the linear system
void fair(unsigned int k = 2);

private:
Expand Down

0 comments on commit a3d576f

Please sign in to comment.