Skip to content

Commit 902cbf7

Browse files
committed
add mesh class
1 parent 1ba762c commit 902cbf7

551 files changed

Lines changed: 210116 additions & 46 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,26 @@ if (NOT CMAKE_VERSION VERSION_LESS "3.1")
44
cmake_policy(SET CMP0054 NEW)
55
endif()
66

7+
add_custom_target(build_all_3rd_party_libs
8+
COMMAND ${CMAKE_COMMAND} -E echo "Custom target build_all_3rd_party_libs reached."
9+
)
10+
711
project(cupoch)
812

13+
if(WIN32 AND NOT CYGWIN)
14+
set(DEF_INSTALL_CMAKE_DIR CMake)
15+
else()
16+
set(DEF_INSTALL_CMAKE_DIR lib/cmake/cupoch)
17+
endif()
18+
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
19+
"Installation directory for CMake files")
20+
921
option(BUILD_UNIT_TESTS "Build the Cupoch unit tests" ON)
1022
option(BUILD_EIGEN3 "Use the Eigen3 that comes with Cupoch" ON)
1123
option(BUILD_GLEW "Build glew from source" OFF)
1224
option(BUILD_GLFW "Build glfw from source" OFF)
25+
option(BUILD_PNG "Build png from source" OFF)
26+
option(BUILD_JPEG "Build jpeg-turbo from source" ON)
1327
option(BUILD_PYBIND11 "Build pybind11 from source" ON)
1428
option(BUILD_PYTHON_MODULE "Build the python module" ON)
1529
option(STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" OFF)
@@ -117,6 +131,13 @@ set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}
117131
-Xcudafe "--diag_suppress=virtual_function_decl_hidden"
118132
${CUDA_ARCH})
119133

134+
# 3rd-party projects that are added with external_project_add will be installed
135+
# with this prefix. E.g.
136+
# - 3RDPARTY_INSTALL_PREFIX: Open3D/build/3rdparty_install
137+
# - Headers: Open3D/build/3rdparty_install/include/extern_lib.h
138+
# - Libraries: Open3D/build/3rdparty_install/lib/extern_lib.a
139+
set(3RDPARTY_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/3rdparty_install")
140+
120141
add_subdirectory(third_party)
121142

122143
include_directories(

src/cupoch/geometry/geometry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class Geometry {
88
enum class GeometryType {
99
Unspecified = 0,
1010
PointCloud = 1,
11+
MeshBase = 5,
12+
TriangleMesh = 6,
13+
Image = 8,
1114
};
1215

1316
public:

src/cupoch/geometry/geometry2d.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#include "cupoch/geometry/geometry.h"
4+
#include <Eigen/Core>
5+
6+
namespace cupoch {
7+
namespace geometry {
8+
9+
/// \class Geometry2D
10+
///
11+
/// \brief The base geometry class for 2D geometries.
12+
///
13+
/// Main class for 2D geometries, Derives all data from Geometry Base class.
14+
class Geometry2D : public Geometry {
15+
public:
16+
~Geometry2D() override {}
17+
18+
protected:
19+
/// \brief Parameterized Constructor.
20+
///
21+
/// \param type type of object based on GeometryType
22+
Geometry2D(GeometryType type) : Geometry(type, 2) {}
23+
24+
public:
25+
Geometry& Clear() override = 0;
26+
bool IsEmpty() const override = 0;
27+
/// Returns min bounds for geometry coordinates.
28+
virtual Eigen::Vector2f GetMinBound() const = 0;
29+
/// Returns max bounds for geometry coordinates.
30+
virtual Eigen::Vector2f GetMaxBound() const = 0;
31+
};
32+
33+
}
34+
}

src/cupoch/geometry/geometry3d.cu

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,26 @@ struct transform_normals_functor {
4141
};
4242
}
4343

44-
Eigen::Vector3f cupoch::geometry::ComputeMinBound(const thrust::device_vector<Eigen::Vector3f>& points) {
44+
Eigen::Vector3f Geometry3D::ComputeMinBound(const thrust::device_vector<Eigen::Vector3f>& points) const {
4545
if (points.empty()) return Eigen::Vector3f::Zero();
4646
Eigen::Vector3f init = points[0];
4747
return thrust::reduce(points.begin(), points.end(), init, elementwise_min_functor());
4848
}
4949

50-
Eigen::Vector3f cupoch::geometry::ComputeMaxBound(const thrust::device_vector<Eigen::Vector3f>& points) {
50+
Eigen::Vector3f Geometry3D::ComputeMaxBound(const thrust::device_vector<Eigen::Vector3f>& points) const {
5151
if (points.empty()) return Eigen::Vector3f::Zero();
5252
Eigen::Vector3f init = points[0];
5353
return thrust::reduce(points.begin(), points.end(), init, elementwise_max_functor());
5454
}
5555

56-
Eigen::Vector3f cupoch::geometry::ComuteCenter(const thrust::device_vector<Eigen::Vector3f>& points) {
56+
Eigen::Vector3f Geometry3D::ComuteCenter(const thrust::device_vector<Eigen::Vector3f>& points) const {
5757
Eigen::Vector3f init = Eigen::Vector3f::Zero();
5858
if (points.empty()) return init;
5959
Eigen::Vector3f sum = thrust::reduce(points.begin(), points.end(), init, thrust::plus<Eigen::Vector3f>());
6060
return sum / points.size();
6161
}
6262

63-
void cupoch::geometry::ResizeAndPaintUniformColor(thrust::device_vector<Eigen::Vector3f>& colors,
63+
void Geometry3D::ResizeAndPaintUniformColor(thrust::device_vector<Eigen::Vector3f>& colors,
6464
const size_t size,
6565
const Eigen::Vector3f& color) {
6666
colors.resize(size);
@@ -78,26 +78,26 @@ void cupoch::geometry::ResizeAndPaintUniformColor(thrust::device_vector<Eigen::V
7878
thrust::fill(colors.begin(), colors.end(), clipped_color);
7979
}
8080

81-
void cupoch::geometry::TransformPoints(const Eigen::Matrix4f& transformation,
82-
thrust::device_vector<Eigen::Vector3f>& points) {
81+
void Geometry3D::TransformPoints(const Eigen::Matrix4f& transformation,
82+
thrust::device_vector<Eigen::Vector3f>& points) {
8383
transform_points_functor func(transformation);
8484
thrust::for_each(points.begin(), points.end(), func);
8585
}
8686

87-
void cupoch::geometry::TransformPoints(cudaStream_t stream, const Eigen::Matrix4f& transformation,
88-
thrust::device_vector<Eigen::Vector3f>& points) {
87+
void Geometry3D::TransformPoints(cudaStream_t stream, const Eigen::Matrix4f& transformation,
88+
thrust::device_vector<Eigen::Vector3f>& points) {
8989
transform_points_functor func(transformation);
9090
thrust::for_each(thrust::cuda::par.on(stream), points.begin(), points.end(), func);
9191
}
9292

93-
void cupoch::geometry::TransformNormals(const Eigen::Matrix4f& transformation,
94-
thrust::device_vector<Eigen::Vector3f>& normals) {
93+
void Geometry3D::TransformNormals(const Eigen::Matrix4f& transformation,
94+
thrust::device_vector<Eigen::Vector3f>& normals) {
9595
transform_normals_functor func(transformation);
9696
thrust::for_each(normals.begin(), normals.end(), func);
9797
}
9898

99-
void cupoch::geometry::TransformNormals(cudaStream_t stream, const Eigen::Matrix4f& transformation,
100-
thrust::device_vector<Eigen::Vector3f>& normals) {
99+
void Geometry3D::TransformNormals(cudaStream_t stream, const Eigen::Matrix4f& transformation,
100+
thrust::device_vector<Eigen::Vector3f>& normals) {
101101
transform_normals_functor func(transformation);
102102
thrust::for_each(thrust::cuda::par.on(stream), normals.begin(), normals.end(), func);
103103
}

src/cupoch/geometry/geometry3d.h

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
#pragma once
2-
#include <cupoch/utility/eigen.h>
2+
#include "cupoch/geometry/geometry.h"
3+
#include "cupoch/utility/eigen.h"
34
#include <thrust/device_vector.h>
45

56
namespace cupoch {
67
namespace geometry {
78

8-
Eigen::Vector3f ComputeMinBound(const thrust::device_vector<Eigen::Vector3f>& points);
9-
10-
Eigen::Vector3f ComputeMaxBound(const thrust::device_vector<Eigen::Vector3f>& points);
11-
12-
Eigen::Vector3f ComuteCenter(const thrust::device_vector<Eigen::Vector3f>& points);
13-
14-
void ResizeAndPaintUniformColor(thrust::device_vector<Eigen::Vector3f>& colors,
15-
const size_t size,
16-
const Eigen::Vector3f& color);
17-
18-
void TransformPoints(const Eigen::Matrix4f& transformation,
19-
thrust::device_vector<Eigen::Vector3f>& points);
20-
21-
void TransformPoints(cudaStream_t stream, const Eigen::Matrix4f& transformation,
22-
thrust::device_vector<Eigen::Vector3f>& points);
23-
24-
void TransformNormals(const Eigen::Matrix4f& transformation,
25-
thrust::device_vector<Eigen::Vector3f>& normals);
26-
27-
void TransformNormals(cudaStream_t stream, const Eigen::Matrix4f& transformation,
28-
thrust::device_vector<Eigen::Vector3f>& normals);
9+
class Geometry3D : public Geometry {
10+
public:
11+
~Geometry3D() override {}
12+
13+
protected:
14+
/// \brief Parameterized Constructor.
15+
///
16+
/// \param type type of object based on GeometryType.
17+
Geometry3D(GeometryType type) : Geometry(type, 3) {}
18+
19+
public:
20+
Eigen::Vector3f ComputeMinBound(const thrust::device_vector<Eigen::Vector3f>& points) const;
21+
22+
Eigen::Vector3f ComputeMaxBound(const thrust::device_vector<Eigen::Vector3f>& points) const;
23+
24+
Eigen::Vector3f ComuteCenter(const thrust::device_vector<Eigen::Vector3f>& points) const;
25+
26+
void ResizeAndPaintUniformColor(thrust::device_vector<Eigen::Vector3f>& colors,
27+
const size_t size,
28+
const Eigen::Vector3f& color);
29+
30+
void TransformPoints(const Eigen::Matrix4f& transformation,
31+
thrust::device_vector<Eigen::Vector3f>& points);
32+
33+
void TransformPoints(cudaStream_t stream, const Eigen::Matrix4f& transformation,
34+
thrust::device_vector<Eigen::Vector3f>& points);
35+
36+
void TransformNormals(const Eigen::Matrix4f& transformation,
37+
thrust::device_vector<Eigen::Vector3f>& normals);
38+
39+
void TransformNormals(cudaStream_t stream, const Eigen::Matrix4f& transformation,
40+
thrust::device_vector<Eigen::Vector3f>& normals);
41+
};
2942

3043
}
3144
}

src/cupoch/geometry/image.cu

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#include "cupoch/geometry/image.h"
2+
3+
using namespace cupoch;
4+
using namespace cupoch::geometry;
5+
6+
namespace {
7+
8+
struct vertical_flip_functor {
9+
vertical_flip_functor(const uint8_t* src, int width, int height,
10+
int bytes_per_pixel, uint8_t* dst)
11+
: src_(src), width_(width), height_(height), bytes_per_pixel_(bytes_per_pixel), dst_(dst) {};
12+
const uint8_t* src_;
13+
const int width_;
14+
const int height_;
15+
const int bytes_per_pixel_;
16+
uint8_t* dst_;
17+
__device__
18+
void operator() (size_t idx) {
19+
const int y = idx / width_;
20+
const int x = idx % width_;
21+
memcpy(&dst_[(height_ - y - 1) * width_ * bytes_per_pixel_ + x], &src_[idx], bytes_per_pixel_ * sizeof(uint8_t));
22+
}
23+
};
24+
25+
struct horizontal_flip_functor {
26+
horizontal_flip_functor(const uint8_t* src, int width, int height,
27+
int bytes_per_pixel, uint8_t* dst)
28+
: src_(src), width_(width), height_(height), bytes_per_pixel_(bytes_per_pixel), dst_(dst) {};
29+
const uint8_t* src_;
30+
const int width_;
31+
const int height_;
32+
const int bytes_per_pixel_;
33+
uint8_t* dst_;
34+
__device__
35+
void operator() (size_t idx) {
36+
const int y = idx / width_;
37+
const int x = idx % width_;
38+
memcpy(&dst_[y * width_ * bytes_per_pixel_ + (width_ - x - 1)], &src_[idx], bytes_per_pixel_ * sizeof(uint8_t));
39+
}
40+
};
41+
42+
}
43+
44+
45+
Image::Image() : Geometry2D(Geometry::GeometryType::Image) {}
46+
Image::~Image() {}
47+
48+
Image &Image::Clear() {
49+
width_ = 0;
50+
height_ = 0;
51+
num_of_channels_ = 0;
52+
bytes_per_channel_ = 0;
53+
data_.clear();
54+
return *this;
55+
}
56+
57+
bool Image::IsEmpty() const {
58+
return !HasData();
59+
}
60+
61+
Eigen::Vector2f Image::GetMinBound() const {
62+
return Eigen::Vector2f(0.0, 0.0);
63+
}
64+
65+
Eigen::Vector2f Image::GetMaxBound() const {
66+
return Eigen::Vector2f(width_, height_);
67+
}
68+
69+
thrust::host_vector<uint8_t> Image::GetData() const {
70+
thrust::host_vector<uint8_t> data = data_;
71+
return data;
72+
}
73+
74+
void Image::SetData(const thrust::host_vector<uint8_t>& data) {
75+
data_ = data;
76+
}
77+
78+
bool Image::TestImageBoundary(float u,
79+
float v,
80+
float inner_margin /* = 0.0 */) const {
81+
return (u >= inner_margin && u < width_ - inner_margin &&
82+
v >= inner_margin && v < height_ - inner_margin);
83+
}
84+
85+
std::shared_ptr<Image> Image::FlipVertical() const {
86+
auto output = std::make_shared<Image>();
87+
output->Prepare(width_, height_, num_of_channels_, bytes_per_channel_);
88+
89+
vertical_flip_functor func(thrust::raw_pointer_cast(data_.data()), width_, height_,
90+
num_of_channels_ * bytes_per_channel_,
91+
thrust::raw_pointer_cast(output->data_.data()));
92+
thrust::for_each(thrust::make_counting_iterator<size_t>(0), thrust::make_counting_iterator(data_.size()), func);
93+
return output;
94+
}
95+
96+
std::shared_ptr<Image> Image::FlipHorizontal() const {
97+
auto output = std::make_shared<Image>();
98+
output->Prepare(width_, height_, num_of_channels_, bytes_per_channel_);
99+
100+
horizontal_flip_functor func(thrust::raw_pointer_cast(data_.data()), width_, height_,
101+
num_of_channels_ * bytes_per_channel_,
102+
thrust::raw_pointer_cast(output->data_.data()));
103+
thrust::for_each(thrust::make_counting_iterator<size_t>(0), thrust::make_counting_iterator(data_.size()), func);
104+
return output;
105+
}
106+
107+
void Image::AllocateDataBuffer() {
108+
data_.resize(width_ * height_ * num_of_channels_ * bytes_per_channel_);
109+
}

0 commit comments

Comments
 (0)