Remove tbb vectors

This commit is contained in:
Julian Stahl 2022-09-15 11:34:18 +02:00
parent 4b28956f0e
commit 31d9d1a1b8
8 changed files with 57 additions and 80 deletions

View File

@ -2,12 +2,10 @@
#include <CGAL/Cartesian_grid_domain.h>
#include <CGAL/Dual_contouring_3.h>
#include <CGAL/Marching_cubes_3.h>
#include <CGAL/TC_marching_cubes_3.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/TC_marching_cubes_3.h>
#include <CGAL/boost/graph/IO/OFF.h>
#include <tbb/concurrent_vector.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_3 Point;
@ -15,8 +13,8 @@ typedef typename Kernel::Vector_3 Vector;
typedef CGAL::Cartesian_grid_3<Kernel> Grid;
typedef tbb::concurrent_vector<Point> Point_range;
typedef tbb::concurrent_vector<std::vector<std::size_t>> Polygon_range;
typedef std::vector<Point> Point_range;
typedef std::vector<std::vector<std::size_t>> Polygon_range;
FT sign(FT value) {
return (value > 0) - (value < 0);
@ -24,7 +22,7 @@ FT sign(FT value) {
int main() {
// create a cartesian grid with 100^3 grid points and the bounding box [-1, 1]^3
Grid grid(100, 100, 100, {-1, -1, -1, 1, 1, 1});
Grid grid(7, 7, 7, {-1, -1, -1, 1, 1, 1});
// calculate the value at all grid points
for (std::size_t x = 0; x < grid.xdim(); x++) {
@ -37,28 +35,33 @@ int main() {
// manhattan distance to the origin
grid.value(x, y, z) = std::max({std::abs(pos_x), std::abs(pos_y), std::abs(pos_z)});
// the normal depends on the side of the cube
grid.gradient(x, y, z) = Vector(0, 0, 0);
if (grid.value(x, y, z) == std::abs(pos_x)) {
grid.gradient(x, y, z) += Vector(sign(pos_x), 0, 0);
}
if (grid.value(x, y, z) == std::abs(pos_y)) {
grid.gradient(x, y, z) += Vector(0, sign(pos_y), 0);
}
if (grid.value(x, y, z) == std::abs(pos_z)) {
grid.gradient(x, y, z) += Vector(0, 0, sign(pos_z));
}
const FT length_sq = grid.gradient(x, y, z).squared_length();
if (length_sq > 0.00001) {
grid.gradient(x, y, z) /= CGAL::approximate_sqrt(length_sq);
}
}
}
}
auto cube_gradient = [](const Point& p) {
// the normal depends on the side of the cube
const FT max_value = std::max({std::abs(p.x()), std::abs(p.y()), std::abs(p.z())});
Vector g(0, 0, 0);
if (max_value == std::abs(p.x())) {
g += Vector(sign(p.x()), 0, 0);
}
if (max_value == std::abs(p.y())) {
g += Vector(0, sign(p.y()), 0);
}
if (max_value == std::abs(p.z())) {
g += Vector(0, 0, sign(p.z()));
}
const FT length_sq = g.squared_length();
if (length_sq > 0.00001) {
g /= CGAL::approximate_sqrt(length_sq);
}
return g;
};
// create a domain from the grid
CGAL::Isosurfacing::Cartesian_grid_domain<Kernel> domain(grid);
CGAL::Isosurfacing::Cartesian_grid_domain<Kernel, decltype(cube_gradient)> domain(grid, cube_gradient);
// prepare collections for the results
Point_range points_mc, points_tmc, points_dc;
@ -66,7 +69,7 @@ int main() {
// execute marching cubes, topologically correct marching cubes and dual contouring with an isovalue of 0.8
CGAL::Isosurfacing::make_triangle_mesh_using_marching_cubes(domain, 0.88, points_mc, polygons_mc);
//CGAL::Isosurfacing::make_triangle_mesh_using_tmc(domain, 0.88, points_tmc, polygons_tmc);
CGAL::Isosurfacing::make_triangle_mesh_using_tmc(domain, 0.88, points_tmc, polygons_tmc);
CGAL::Isosurfacing::make_quad_mesh_using_dual_contouring(domain, 0.88, points_dc, polygons_dc);
// save the results in the OFF format

View File

@ -2,15 +2,14 @@
#include <CGAL/Implicit_domain.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/boost/graph/IO/OFF.h>
#include <tbb/concurrent_vector.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef typename Kernel::FT FT;
typedef typename Kernel::Vector_3 Vector;
typedef typename Kernel::Point_3 Point;
typedef tbb::concurrent_vector<Point> Point_range;
typedef tbb::concurrent_vector<std::vector<std::size_t>> Polygon_range;
typedef std::vector<Point> Point_range;
typedef std::vector<std::vector<std::size_t>> Polygon_range;
#ifndef M_PI
#define M_PI 3.141592653589793238462643383279502884L

View File

@ -1,9 +1,8 @@
#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/Cartesian_grid_3.h>
#include <CGAL/Cartesian_grid_domain.h>
#include <CGAL/Dual_contouring_3.h>
#include <CGAL/Implicit_domain.h>
#include <CGAL/Side_of_triangle_mesh.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
@ -16,8 +15,6 @@ typedef typename Kernel::FT FT;
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Vector_3 Vector;
typedef CGAL::Cartesian_grid_3<Kernel> Grid;
typedef CGAL::Surface_mesh<Point> Mesh;
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
@ -27,14 +24,9 @@ typedef CGAL::AABB_tree<Traits> Tree;
typedef std::vector<Point> Point_range;
typedef std::vector<std::vector<std::size_t>> Polygon_range;
inline Kernel::FT distance_to_mesh(const Tree& tree, const Point& p) {
const Point& x = tree.closest_point(p);
return std::sqrt((p - x).squared_length());
}
int main() {
const std::string input_name = "../data/bunny.off";
const int n_voxels = 20;
const std::string input_name = "../../../data/bunny.off";
const Vector grid_spacing(0.005, 0.005, 0.005);
const FT offset_value = 0.01;
Mesh mesh_input;
@ -54,30 +46,21 @@ int main() {
CGAL::Side_of_triangle_mesh<Mesh, CGAL::GetGeomTraits<Mesh>::type> sotm(mesh_input);
Grid grid(n_voxels, n_voxels, n_voxels, aabb_grid);
CGAL::Isosurfacing::Cartesian_grid_domain<Kernel> domain(grid);
auto mesh_distance = [&tree](const Point& p) {
const Point& x = tree.closest_point(p);
return std::sqrt((p - x).squared_length());
};
for (std::size_t z = 0; z < grid.zdim(); z++) {
for (std::size_t y = 0; y < grid.ydim(); y++) {
for (std::size_t x = 0; x < grid.xdim(); x++) {
auto mesh_normal = [&tree](const Point& p) {
const Point& x = tree.closest_point(p);
const Vector n = p - x;
return n / std::sqrt(n.squared_length());
};
const FT pos_x = x * grid.get_spacing()[0] + grid.get_bbox().xmin();
const FT pos_y = y * grid.get_spacing()[1] + grid.get_bbox().ymin();
const FT pos_z = z * grid.get_spacing()[2] + grid.get_bbox().zmin();
const Point p(pos_x, pos_y, pos_z);
grid.value(x, y, z) = distance_to_mesh(tree, p);
// const bool is_inside = (sotm(p) == CGAL::ON_BOUNDED_SIDE);
// if (is_inside) {
// grid.value(x, y, z) *= -1;
//}
// TODO: mormals
}
}
}
// create a domain with bounding box [-1, 1]^3 and grid spacing 0.02
CGAL::Isosurfacing::Implicit_domain<Kernel, decltype(mesh_distance), decltype(mesh_normal)> domain(
aabb_grid, grid_spacing, mesh_distance, mesh_normal);
Point_range points;
Polygon_range polygons;

View File

@ -32,7 +32,7 @@ struct Refine_one_eighth {
auto coords = node.global_coordinates();
const std::size_t depth_factor = std::size_t(1) << (max_depth_ - node.depth());
for (int i = 0; i < Octree_wrapper_::Octree::Node::Dimension::value; ++i) {
coords[i] *= (uint32_t) depth_factor;
coords[i] *= (uint32_t)depth_factor;
}
return coords;

View File

@ -5,16 +5,14 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/boost/graph/IO/OFF.h>
#include <tbb/concurrent_vector.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_3 Point;
typedef CGAL::Cartesian_grid_3<Kernel> Grid;
typedef tbb::concurrent_vector<Point> Point_range;
typedef tbb::concurrent_vector<std::vector<std::size_t>> Polygon_range;
typedef std::vector<Point> Point_range;
typedef std::vector<std::vector<std::size_t>> Polygon_range;
int main() {
// create a cartesian grid with 100^3 grid points and the bounding box [-1, 1]^3

View File

@ -3,14 +3,13 @@
#include <CGAL/Marching_cubes_3.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/boost/graph/IO/OFF.h>
#include <tbb/concurrent_vector.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef typename Kernel::Vector_3 Vector;
typedef typename Kernel::Point_3 Point;
typedef tbb::concurrent_vector<Point> Point_range;
typedef tbb::concurrent_vector<std::vector<std::size_t>> Polygon_range;
typedef std::vector<Point> Point_range;
typedef std::vector<std::vector<std::size_t>> Polygon_range;
int main() {
// distance to the origin

View File

@ -1,19 +1,16 @@
#include <CGAL/Cartesian_grid_3.h>
#include <CGAL/Cartesian_grid_domain.h>
#include <CGAL/Dual_contouring_3.h>
#include <CGAL/Marching_cubes_3.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/boost/graph/IO/OFF.h>
#include <tbb/concurrent_vector.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_3 Point;
typedef CGAL::Cartesian_grid_3<Kernel> Grid;
typedef tbb::concurrent_vector<Point> Point_range;
typedef tbb::concurrent_vector<std::vector<std::size_t>> Polygon_range;
typedef std::vector<Point> Point_range;
typedef std::vector<std::vector<std::size_t>> Polygon_range;
int main() {
@ -37,7 +34,7 @@ int main() {
Polygon_range polygons;
// execute marching cubes with an isovalue of 2.9
CGAL::Isosurfacing::make_quad_mesh_using_dual_contouring(domain, 2.9, points, polygons);
CGAL::Isosurfacing::make_triangle_mesh_using_marching_cubes(domain, 2.9, points, polygons);
// save the result in the OFF format
CGAL::IO::write_OFF("result.off", points, polygons);

View File

@ -9,8 +9,6 @@
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/IO/OFF.h>
#include <tbb/concurrent_vector.h>
#include <iostream>
typedef CGAL::Simple_cartesian<double> Kernel;
@ -26,8 +24,8 @@ typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef tbb::concurrent_vector<Point> Point_range;
typedef tbb::concurrent_vector<std::vector<std::size_t>> Polygon_range;
typedef std::vector<Point> Point_range;
typedef std::vector<std::vector<std::size_t>> Polygon_range;
// computes the distance of a point p from the mesh with the use of a AABB_tree
@ -37,9 +35,9 @@ inline Kernel::FT distance_to_mesh(const Tree& tree, const Point& p) {
}
int main() {
const std::string input_name = "../data/bunny.off";
const std::string input_name = "../../../data/bunny.off";
const int n_voxels = 20;
const FT offset_value = 0.01;
const FT offset_value = -0.03;
// load the original mesh
Mesh mesh_input;