Skip to content
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

Put instant meshes batch process into a static library #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ datasets
*.vcxproj
*.filters
*.sdf
*.sln
*.sln
*.user
_Resharper*
45 changes: 25 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ if (MSVC)
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
elseif(APPLE)
# Try to auto-detect a suitable SDK
# Commented out for now -- causes a too new SDK to be selected on AppVeyor
Expand Down Expand Up @@ -147,33 +144,41 @@ elseif(WIN32)
set(EXTRA_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/resources/im.rc")
endif()

add_library(InstantMeshesLib
lib/include/common.h
lib/include/aabb.h
lib/include/meshio.h lib/src/meshio.cpp
lib/include/bvh.h lib/src/bvh.cpp
lib/include/smoothing.h lib/src/smoothing.cpp
lib/include/normal.h lib/src/normal.cpp
lib/include/dedge.h lib/src/dedge.cpp
lib/include/batch.h lib/src/batch.cpp
lib/include/subdivide.h lib/src/subdivide.cpp
lib/include/meshstats.h lib/src/meshstats.cpp
lib/include/hierarchy.h lib/src/hierarchy.cpp
lib/include/adjacency.h lib/src/adjacency.cpp
lib/include/serializer.h lib/src/serializer.cpp
lib/include/field.h lib/src/field.cpp
lib/include/extract.h lib/src/extract.cpp
lib/include/reorder.h lib/src/reorder.cpp
lib/include/cleanup.h lib/src/cleanup.cpp)

target_include_directories(InstantMeshesLib PRIVATE lib/include)

add_executable(InstantMeshes MACOSX_BUNDLE
resources.cpp
src/glutil.h src/glutil.cpp
src/widgets.h src/widgets.cpp
src/aabb.h
src/main.cpp src/common.h
src/meshio.h src/meshio.cpp
src/normal.h src/normal.cpp
src/adjacency.h src/adjacency.cpp
src/meshstats.h src/meshstats.cpp
src/hierarchy.h src/hierarchy.cpp
src/extract.h src/extract.cpp
src/main.cpp
src/viewer.h src/viewer.cpp
src/field.h src/field.cpp
src/bvh.h src/bvh.cpp
src/subdivide.h src/subdivide.cpp
src/reorder.h src/reorder.cpp
src/serializer.h src/serializer.cpp
src/batch.h src/batch.cpp
src/smoothcurve.h src/smoothcurve.cpp
src/cleanup.h src/cleanup.cpp
src/dedge.h src/dedge.cpp
ext/rply/rply.c
${EXTRA_SOURCE})

target_include_directories(InstantMeshes PRIVATE lib/include)

add_definitions(${NANOGUI_EXTRA_DEFS})
target_link_libraries(InstantMeshes tbb_static nanogui ${NANOGUI_EXTRA_LIBS})
target_link_libraries(InstantMeshes InstantMeshesLib tbb_static nanogui ${NANOGUI_EXTRA_LIBS})

set_target_properties(InstantMeshes PROPERTIES OUTPUT_NAME "Instant Meshes")

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/meshio.h → lib/include/meshio.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ load_mesh_or_pointcloud(const std::string &filename, MatrixXu &F,
extern void load_obj(const std::string &filename, MatrixXu &F, MatrixXf &V,
const ProgressCallback &progress = ProgressCallback());

extern void load_obj_pure_quad(const std::string& filename,
MatrixXu& F, MatrixXf& V, MatrixXf& N,
const ProgressCallback& progress = ProgressCallback());

extern void load_ply(const std::string &filename, MatrixXu &F, MatrixXf &V,
MatrixXf &N, bool pointcloud = false,
const ProgressCallback &progress = ProgressCallback());
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions lib/include/smoothing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
smoothing.h: smoothing & reprojection

This file is part of the implementation of

Instant Field-Aligned Meshes
Wenzel Jakob, Daniele Panozzo, Marco Tarini, and Olga Sorkine-Hornung
In ACM Transactions on Graphics (Proc. SIGGRAPH Asia 2015)

All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE.txt file.
*/

#pragma once

#include "common.h"
#include <set>

class BVH;

extern void smoothing(int smooth_iterations,
MatrixXu& F, MatrixXf& O, MatrixXf& N,
const std::set<uint32_t>& crease,
uint32_t nV, uint32_t nF,
Float scale = 1.0, BVH* bvh = nullptr,
int posy = 4, bool pure_quad = true);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
89 changes: 5 additions & 84 deletions src/extract.cpp → lib/src/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "reorder.h"
#include "bvh.h"
#include "cleanup.h"
#include "smoothing.h"
#include <tbb/concurrent_vector.h>
#include <parallel_stable_sort.h>
#include <unordered_set>
Expand Down Expand Up @@ -871,90 +872,10 @@ void extract_faces(std::vector<std::vector<TaggedLink> > &adj, MatrixXf &O,
cout << "Step 10: Running " << smooth_iterations << " smoothing & reprojection steps ..";
cout.flush();

std::vector<std::set<uint32_t>> adj_new(nV);
std::vector<tbb::spin_mutex> locks(nV);
tbb::parallel_for(
tbb::blocked_range<uint32_t>(0u, nF, GRAIN_SIZE),
[&](const tbb::blocked_range<uint32_t> &range) {
for (uint32_t f = range.begin(); f != range.end(); ++f) {
if (posy == 4 && F(2, f) == F(3, f)) {
/* Irregular face */
if (pure_quad) /* Should never get these when subdivision is on */
throw std::runtime_error("Internal error in extraction");
uint32_t i0 = F(0, f), i1 = F(1, f);
if (i0 < i1)
std::swap(i1, i0);
if (i0 == i1)
continue;
tbb::spin_mutex::scoped_lock lock1(locks[i0]);
tbb::spin_mutex::scoped_lock lock2(locks[i1]);
adj_new[i0].insert(i1);
adj_new[i1].insert(i0);
} else {
for (int j=0; j<F.rows(); ++j) {
uint32_t i0 = F(j, f), i1 = F((j+1)%F.rows(), f);
if (i0 < i1)
std::swap(i1, i0);
if (i0 == i1)
continue;
tbb::spin_mutex::scoped_lock lock1(locks[i0]);
tbb::spin_mutex::scoped_lock lock2(locks[i1]);
adj_new[i0].insert(i1);
adj_new[i1].insert(i0);
}
}
}
}
);

for (int it=0; it<smooth_iterations; ++it) {
MatrixXf O_prime(O.rows(), O.cols());
MatrixXf N_prime(O.rows(), O.cols());
cout << ".";
cout.flush();

tbb::parallel_for(
tbb::blocked_range<uint32_t>(0u, (uint32_t) O.cols(), GRAIN_SIZE),
[&](const tbb::blocked_range<uint32_t> &range) {
std::set<uint32_t> temp;
for (uint32_t i = range.begin(); i != range.end(); ++i) {
bool is_crease = crease.find(i) != crease.end();
if (adj_new[i].size() > 0 && !is_crease) {
Vector3f centroid = Vector3f::Zero(), avgNormal = Vector3f::Zero();
for (auto j : adj_new[i]) {
centroid += O.col(j);
avgNormal += N.col(j);
}
avgNormal += N.col(i);
centroid /= adj_new[i].size();
Matrix3f cov = Matrix3f::Zero();
for (auto j : adj_new[i])
cov += (O.col(j)-centroid) * (O.col(j)-centroid).transpose();
Vector3f n = cov.jacobiSvd(Eigen::ComputeFullU).matrixU().col(2).normalized();
n *= signum(avgNormal.dot(n));

if (bvh && bvh->F()->size() > 0) {
Ray ray1(centroid, n, 0, scale / 2);
Ray ray2(centroid, -n, 0, scale / 2);
uint32_t idx1 = 0, idx2 = 0;
Float t1 = 0, t2 = 0;
bvh->rayIntersect(ray1, idx1, t1);
bvh->rayIntersect(ray2, idx2, t2);
if (std::min(t1, t2) < scale*0.5f)
centroid = t1 < t2 ? ray1(t1) : ray2(t2);
}
O_prime.col(i) = centroid;
N_prime.col(i) = n;
} else {
O_prime.col(i) = O.col(i);
N_prime.col(i) = N.col(i);
}
}
}
);
O_prime.swap(O);
N_prime.swap(N);
}
smoothing(smooth_iterations, F, O, N,
crease, nV, nF, scale,
bvh, posy, pure_quad);

cout << " done. (took " << timeString(timer.reset()) << ")" << endl;
}

Expand Down
File renamed without changes.
File renamed without changes.
Loading