8000 Replace boost::graph with graphlite by elalish · Pull Request #92 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace boost::graph with graphlite #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/manifold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install dependencies
run: |
apt-get -y update
DEBIAN_FRONTEND=noninteractive apt install -y libglm-dev libassimp-dev libboost-graph-dev libcgal-dev
DEBIAN_FRONTEND=noninteractive apt install -y libglm-dev libassimp-dev libcgal-dev
- name: Build CUDA
run: |
mkdir buildCUDA
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ IF(MANIFOLD_USE_CPP)
ENDIF(MANIFOLD_USE_CPP)

add_subdirectory(utilities)
add_subdirectory(third_party)
add_subdirectory(collider)
add_subdirectory(polygon)
add_subdirectory(manifold)
add_subdirectory(third_party)
add_subdirectory(meshIO)
add_subdirectory(samples)
add_subdirectory(test)
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ RUN apt-get -y update && apt-get -y install \
cmake \
libglm-dev \
libassimp-dev \
libboost-graph-dev \
libcgal-dev
# RUN DEBIAN_FRONTEND=noninteractive apt-get -y install cuda-drivers
COPY . /usr/src
Expand Down
4 changes: 1 addition & 3 deletions manifold/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
project (manifold)

find_package(Boost COMPONENTS graph REQUIRED)

add_library(${PROJECT_NAME} src/manifold.cu src/constructors.cu src/impl.cu src/properties.cu src/sort.cu src/edge_op.cu src/face_op.cu src/smoothing.cu src/boolean3.cu src/boolean_result.cu)

set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_ARCHITECTURES 61)

target_include_directories( ${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include )
target_link_libraries( ${PROJECT_NAME}
PUBLIC utilities
PRIVATE collider polygon ${MANIFOLD_OMP_INCLUDE} Boost::graph
PRIVATE collider polygon ${MANIFOLD_OMP_INCLUDE} graphlite
)

target_compile_options(${PROJECT_NAME}
Expand Down
33 changes: 12 additions & 21 deletions manifold/src/constructors.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

#include <thrust/sequence.h>

#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>

#include "graph.h"
#include "impl.cuh"
#include "polygon.h"

Expand Down Expand Up @@ -58,21 +55,6 @@ struct UpdateHalfedge {
}
};

int ConnectedComponents(VecDH<int>& components, int numVert,
const VecDH<Halfedge>& halfedges) {
boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> graph(
numVert);
for (int i = 0; i < halfedges.size(); ++i) {
const Halfedge halfedge = halfedges.H()[i];
if (halfedge.IsForward()) {
boost::add_edge(halfedge.startVert, halfedge.endVert, graph);
}
}
components.resize(numVert);
int numComponent = boost::connected_components(graph, components.H().data());
return numComponent;
}

struct Equals {
int val;
__host__ __device__ bool operator()(int x) { return x == val; }
Expand Down Expand Up @@ -455,14 +437,23 @@ Manifold Manifold::Compose(const std::vector<Manifold>& manifolds) {
* containing a copy of the original. It is the inverse operation of Compose().
*/
std::vector<Manifold> Manifold::Decompose() const {
VecDH<int> vertLabel;
int numLabel = ConnectedComponents(vertLabel, NumVert(), pImpl_->halfedge_);
Graph graph;
for (int i = 0; i < NumVert(); ++i) {
graph.add_nodes(i);
}
for (const Halfedge& halfedge : pImpl_->halfedge_) {
if (halfedge.IsForward())
graph.add_edge(halfedge.startVert, halfedge.endVert);
}
std::vector<int> components;
const int numLabel = ConnectedComponents(components, graph);

if (numLabel == 1) {
std::vector<Manifold> meshes(1);
meshes[0] = *this;
return meshes;
}
VecDH<int> vertLabel(components);

std::vector<Manifold> meshes(numLabel);
for (int i = 0; i < numLabel; ++i) {
Expand Down
18 changes: 9 additions & 9 deletions manifold/src/impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
#include <thrust/logical.h>

#include <algorithm>
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
#include <map>

#include "graph.h"
#include "impl.cuh"

namespace {
Expand Down Expand Up @@ -415,16 +413,18 @@ int Manifold::Impl::InitializeNewReference(
triPropertiesD.cptrD(), propertiesD.cptrD(),
propertyToleranceD.cptrD(), numProps, precision_}));

boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> graph(
NumTri());
Graph graph;
for (int i = 0; i < NumTri(); ++i) {
graph.add_nodes(i);
}
for (int i = 0; i < face2face.size(); ++i) {
const thrust::pair<int, int> edge = face2face.H()[i];
if (edge.first < 0) continue;
boost::add_edge(edge.first, edge.second, graph);
graph.add_edge(edge.first, edge.second);
}
std::vector<int> components(NumTri());
const int numComponent =
boost::connected_components(graph, components.data());

std::vector<int> components;
const int numComponent = ConnectedComponents(components, graph);

std::vector<int> comp2tri(numComponent, -1);
for (int tri = 0; tri < NumTri(); ++tri) {
Expand Down
6 changes: 3 additions & 3 deletions test/mesh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ TEST(Manifold, GetMesh) {
Identical(mesh_out, mesh_out2);
}

TEST(Manifold, Regression) {
TEST(Manifold, Determinism) {
Manifold manifold(ImportMesh("data/gyroidpuzzle.ply"));
EXPECT_TRUE(manifold.IsManifold());

Manifold manifold1 = manifold;
manifold1.Translate(glm::vec3(5.0f));
int num_overlaps = manifold.NumOverlaps(manifold1);
ASSERT_EQ(num_overlaps, 228677);
ASSERT_EQ(num_overlaps, 229611);

Mesh mesh_out = manifold.GetMesh();
Manifold manifold2(mesh_out);
Expand Down Expand Up @@ -727,7 +727,7 @@ TEST(Boolean, Gyroid) {

EXPECT_TRUE(result.IsManifold());
EXPECT_TRUE(result.MatchesTriNormals());
EXPECT_LE(result.NumDegenerateTris(), 33);
EXPECT_LE(result.NumDegenerateTris(), 42);
EXPECT_EQ(result.Decompose().size(), 1);
auto prop = result.GetProperties();
EXPECT_NEAR(prop.volume, 7692, 1);
Expand Down
2 changes: 1 addition & 1 deletion test/samples_test.cpp
10000
Original file line number Diff line numberDiff line change
Expand Up @@ -158,7 +158,7 @@ TEST(Samples, Frame) {
TEST(Samples, Bracelet) {
Manifold bracelet = StretchyBracelet();
CheckManifold(bracelet);
EXPECT_LE(bracelet.NumDegenerateTris(), 21);
EXPECT_LE(bracelet.NumDegenerateTris(), 22);
EXPECT_EQ(bracelet.Genus(), 1);
if (options.exportModels) ExportMesh("bracelet.glb", bracelet.GetMesh(), {});
}
Expand Down
3 changes: 2 additions & 1 deletion third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(google_test)
add_subdirectory(google_test)
add_subdirectory(graphlite)
10 changes: 10 additions & 0 deletions third_party/graphlite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
project (graphlite)

add_library(${PROJECT_NAME} src/connected_components.cpp)

target_include_directories(${PROJECT_NAME}
PUBLIC ${PROJECT_SOURCE_DIR}/include
)

target_compile_options(${PROJECT_NAME} PRIVATE ${MANIFOLD_FLAGS})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
7 changes: 7 additions & 0 deletions third_party/graphlite/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2021 Guohao Dou

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 27 additions & 0 deletions third_party/graphlite/include/graph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 Emmett Lalish
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once
#include "graph_lite.h"

namespace manifold {

typedef typename graph_lite::Graph<
int, void, void, graph_lite::EdgeDirection::UNDIRECTED,
graph_lite::MultiEdge::DISALLOWED, graph_lite::SelfLoop::DISALLOWED,
graph_lite::Map::UNORDERED_MAP, graph_lite::Container::VEC>
Graph;

int ConnectedComponents(std::vector<int>& components, const Graph& g);
} // namespace manifold
Loading
0