Skip to content

Commit

Permalink
ISSUE #599 Updated pmp with new filesystem shim for g++9
Browse files Browse the repository at this point in the history
  • Loading branch information
sebjf committed May 2, 2023
1 parent 090db2c commit c36c595
Show file tree
Hide file tree
Showing 22 changed files with 196 additions and 72 deletions.
2 changes: 1 addition & 1 deletion bouncer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(VERSION_MINOR 1_2)
include_directories(${Boost_INCLUDE_DIRS} ${MONGO_INCLUDE_DIR} ${ASSIMP_INCLUDE_DIR} ${OCCT_INCLUDE_DIR} ${IFCOPENSHELL_INCLUDE_DIR} ${ODA_INCLUDE_DIR} ${SYNCHRO_READER_INCLUDE_DIR} ${AWSSDK_INCLUDE_DIR} ${CRYPTOLENS_INCLUDE_DIR} src ../)

# == PMP ==
include_directories("D:/3drepo/bouncer/3drepobouncer_ISSUE599/bouncer/src/repo/manipulator/modeloptimizer")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/repo/manipulator/modeloptimizer)
add_definitions(-D_USE_MATH_DEFINES)
# ==

Expand Down
1 change: 0 additions & 1 deletion bouncer/src/repo/manipulator/modeloptimizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#If you need to import an extra library or something clever, do it on the CMakeLists.txt at the root level
#If you really need to overwrite this file, be aware that it will be overwritten if updateSources.py is executed.

include_directories(${CMAKE_CURRENT_LIST_DIR})

add_subdirectory(Eigen)
add_subdirectory(bvh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

add_subdirectory(algorithms)
add_subdirectory(io)
add_subdirectory(visualization)
set(SOURCES
${SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/SurfaceMesh.cpp
Expand Down
22 changes: 0 additions & 22 deletions bouncer/src/repo/manipulator/modeloptimizer/pmp/SurfaceMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,28 +1048,6 @@ void SurfaceMesh::remove_loop_helper(Halfedge h)
edeleted_[edge(h)] = true;
++deleted_edges_;
has_garbage_ = true;
}

void SurfaceMesh::remove_edges_helper(Halfedge h1, Halfedge h3)
{
// Reroutes the topology at vertex to_vertex(ha) around ha & hb, so that
// ha and hb no longer form part of the fan around the vertex.
// ha is in, and hb is out.

// Collect the halfedges involved in this operation

auto h1n = next_halfedge(h1);
auto h3p = prev_halfedge(h3);

// Connect h1n and h3p to eachother

set_next_halfedge(h3p, h1n);

// That operation may have bisected the




}

void SurfaceMesh::combine_edges(Halfedge h1, Halfedge h2)
Expand Down
18 changes: 14 additions & 4 deletions bouncer/src/repo/manipulator/modeloptimizer/pmp/SurfaceMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@
#pragma once

#include <vector>
#include <filesystem>

#include "pmp/Types.h"
#include "pmp/Properties.h"
#include "pmp/io/IOFlags.h"

namespace std {
namespace filesystem = std::experimental::filesystem;
namespace filesystem
{
class path
{
std::string inner;

public:
path(const char* s) { inner = std::string(s); }
path(std::string s) { inner = std::string(s); }

path extension() const { return path(inner.substr(inner.size() - 4)); }
std::string string() const { return inner; }
};
}
}

namespace pmp {
Expand Down Expand Up @@ -1912,8 +1924,6 @@ class SurfaceMesh
// Helper for halfedge collapse
void remove_loop_helper(Halfedge h);

void remove_edges_helper(Halfedge ha, Halfedge hb);

// are there any deleted entities?
inline bool has_garbage() const { return has_garbage_; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/Fairing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Features.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Geodesics.cpp
${CMAKE_CURRENT_SOURCE_DIR}/GraphViz.cpp
${CMAKE_CURRENT_SOURCE_DIR}/HoleFilling.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Manifold.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Merge.cpp
Expand All @@ -38,6 +39,7 @@ set(HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/Fairing.h
${CMAKE_CURRENT_SOURCE_DIR}/Features.h
${CMAKE_CURRENT_SOURCE_DIR}/Geodesics.h
${CMAKE_CURRENT_SOURCE_DIR}/GraphViz.h
${CMAKE_CURRENT_SOURCE_DIR}/Heap.h
${CMAKE_CURRENT_SOURCE_DIR}/HoleFilling.h
${CMAKE_CURRENT_SOURCE_DIR}/Manifold.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include "pmp/algorithms/GraphViz.h"

#include <unordered_map>
#include <unordered_set>

// https://dreampuf.github.io/GraphvizOnline

using namespace pmp;

GraphViz::GraphViz(SurfaceMesh& m):mesh(m) {
}

void GraphViz::add_edge_label(Halfedge h)
{
std::cout << h.idx();

if (mesh.is_boundary(h))
{
std::cout << "b";
}

std::cout << " (" << mesh.next_halfedge(h).idx();

if (mesh.is_boundary(mesh.next_halfedge(h)))
{
std::cout << "b";
}

std::cout << ", " << mesh.prev_halfedge(h).idx();

if (mesh.is_boundary(mesh.prev_halfedge(h)))
{
std::cout << "b";
}

std::cout << ")";
}

void GraphViz::draw_halfedge(Halfedge h)
{
std::string start = "_" + std::to_string(mesh.prev_halfedge(h).idx()) +
"to" + std::to_string(h.idx());
std::string end = "_" + std::to_string(h.idx()) + "to" +
std::to_string(mesh.next_halfedge(h).idx());

std::cout << start
<< "[label=\"\", shape=\"point\", width=0.1, height=0.1]\n";

std::cout << end
<< "[label=\"\", shape=\"point\", width=0.1, height=0.1]\n";

// Create fake vertex to reference

std::cout << start;

std::cout << " -> ";

auto to = mesh.to_vertex(h);
std::cout << end;

std::cout << " [label=\"";

std::cout << h.idx();

if (mesh.is_boundary(h))
{
std::cout << "b";
}

std::cout << "\"]\n";

std::cout << end << " -> " << to << " [len=0,\"arrowhead\"=none]\n";
}

void GraphViz::print_edge(Halfedge h)
{
auto e = mesh.edge(h);
if (edges.count(e.idx()) == 0)
{
edges.insert(e.idx());
}
else
{
return;
}

draw_halfedge(h);
draw_halfedge(mesh.opposite_halfedge(h));
}

void GraphViz::print_topology(Halfedge h)
{
print_topology(mesh.from_vertex(h));
print_topology(mesh.to_vertex(h));
}

void GraphViz::print_topology(Vertex v)
{
int n(0);
auto hit = mesh.halfedges(v);
auto hend = hit;
if (hit)
{
do
{
print_edge(mesh.prev_halfedge(*hit));
print_edge(mesh.next_halfedge(*hit));
print_edge(*hit);
} while (++hit != hend);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2011-2023 the Polygon Mesh Processing Library developers.
// Distributed under a MIT-style license, see LICENSE.txt for details.

#pragma once

#include "pmp/SurfaceMesh.h"

#include <set>

namespace pmp {

/**
* The GraphViz module renders sections of a mesh to Graphviz source. This is
* printed to the console. The output can be rendered by any Graphviz renderer.
* For example, https://dreampuf.github.io/GraphvizOnline can render graphs in
* the browser.
*/
class GraphViz
{
public:
GraphViz(SurfaceMesh& m);

void print_topology(Vertex v);
void print_topology(Halfedge h);

private:
std::set<IndexType> edges;
SurfaceMesh& mesh;
void add_edge_label(Halfedge h);
void print_edge(Halfedge h);
void draw_halfedge(Halfedge h);
};
} // namespace pmp
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
#pragma optimize("", off)

#include "pmp/algorithms/Merge.h"
#include "pmp/algorithms/Normals.h"

#include "pmp/algorithms/Diagnostics.h"
#include "pmp/utilities.h"

#include <unordered_map>
#include <unordered_set>
#include <set>

/**
* The Compression Algorithm combines vertices co-located in space.
* Only vertices with normals within the specified range are combined, in order
Expand Down Expand Up @@ -140,8 +132,6 @@ void Merge::merge_vertices()

merge_vertices(pair.first, pair.second);
}

pmp::check_mesh(mesh);
}

// Collapses /p v1 into /p v0 and deletes /p v1. Both /p v0 and /p v1 must be
Expand Down
2 changes: 0 additions & 2 deletions bouncer/src/repo/manipulator/modeloptimizer/pmp/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#pragma once

#include <filesystem>

#include "pmp/io/IOFlags.h"
#include "pmp/SurfaceMesh.h"

Expand Down
22 changes: 11 additions & 11 deletions bouncer/src/repo/manipulator/modeloptimizer/pmp/io/read_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

#include "pmp/io/read_obj.h"
#include <unordered_map>
#include <fstream>

namespace pmp {

void read_obj(SurfaceMesh& mesh, const std::filesystem::path& file)
void read_obj(SurfaceMesh& mesh, const std::filesystem::path& file)
{
std::ifstream in(file.string());
read_obj(mesh, in);
in.close();
}

void read_obj(SurfaceMesh& mesh, std::basic_istream<char>& in)
{
std::array<char, 200> s;
float x, y, z;
Expand Down Expand Up @@ -38,16 +46,11 @@ void read_obj(SurfaceMesh& mesh, const std::filesystem::path& file)
std::vector<Normal> all_normals;
std::vector<TexCoord> all_tex_coords;

// open file (in ASCII mode)
FILE* in = fopen(file.string().c_str(), "r");
if (!in)
throw IOException("Failed to open file: " + file.string());

// clear line once
memset(s.data(), 0, 200);

// parse line by line (currently only supports vertex all_positions & faces
while (in && !feof(in) && fgets(s.data(), 200, in))
while (!in.eof() && in.getline(s.data(), 200))
{
// comment
if (s[0] == '#' || isspace(s[0]))
Expand Down Expand Up @@ -210,9 +213,6 @@ void read_obj(SurfaceMesh& mesh, const std::filesystem::path& file)
if (!with_normals)
{
mesh.remove_vertex_property(vertex_normals);
}

fclose(in);
}
}}

} // namespace pmp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

#pragma once

#include <filesystem>

#include "pmp/SurfaceMesh.h"

namespace pmp {

void read_obj(SurfaceMesh& mesh, const std::filesystem::path& file);
void read_obj(SurfaceMesh& mesh, std::basic_istream<char>& in);

} // namespace pmp
3 changes: 0 additions & 3 deletions bouncer/src/repo/manipulator/modeloptimizer/pmp/io/read_off.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// Distributed under a MIT-style license, see LICENSE.txt for details.

#pragma once

#include <filesystem>

#include "pmp/SurfaceMesh.h"

namespace pmp {
Expand Down
2 changes: 0 additions & 2 deletions bouncer/src/repo/manipulator/modeloptimizer/pmp/io/read_pmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#pragma once

#include <filesystem>

#include "pmp/SurfaceMesh.h"

namespace pmp {
Expand Down
2 changes: 0 additions & 2 deletions bouncer/src/repo/manipulator/modeloptimizer/pmp/io/read_stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#pragma once

#include <filesystem>

#include "pmp/SurfaceMesh.h"

namespace pmp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// Distributed under a MIT-style license, see LICENSE.txt for details.

#pragma once

#include <filesystem>

#include "pmp/io/IOFlags.h"
#include "pmp/SurfaceMesh.h"

Expand Down
Loading

0 comments on commit c36c595

Please sign in to comment.