Skip to content

Commit 483e4d5

Browse files
authored
Merge pull request #108 from STORM-IRIT/add_happly
Rewrite PLY IO using Happly
2 parents d2b569c + b222c0e commit 483e4d5

File tree

17 files changed

+325
-511
lines changed

17 files changed

+325
-511
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
build*/
1+
*build*
22
*.user
33
assets/demo*
44
.vscode/*

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "3rdparty/stb"]
55
path = 3rdparty/stb
66
url = https://github.com/nothings/stb.git
7+
[submodule "3rdparty/happly"]
8+
path = 3rdparty/happly
9+
url = https://github.com/nmwsharp/happly.git

3rdparty/happly

Submodule happly added at cfa2611

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OPTION (OpenGR_USE_WEIGHTED_LCP "Use gaussian weights for point samples when com
2222
################################################################################
2323
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
2424
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src/)
25+
set(THIRDPARTY_DIR ${PROJECT_SOURCE_DIR}/3rdparty)
2526
set(ASSETS_DIR ${PROJECT_SOURCE_DIR}/assets)
2627
set(SCRIPTS_DIR ${PROJECT_SOURCE_DIR}/scripts)
2728
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
@@ -100,7 +101,7 @@ if( NOT EIGEN3_INCLUDE_DIR )
100101
find_package(Eigen3 QUIET)
101102
if( (NOT Eigen3_FOUND) OR EIGEN_VERSION_NUMBER VERSION_LESS 3.3 )
102103

103-
set(EIGEN3_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/3rdparty/Eigen")
104+
set(EIGEN3_INCLUDE_DIR "${THIRDPARTY_DIR}/Eigen")
104105

105106
if( NOT EXISTS ${EIGEN3_INCLUDE_DIR}/signature_of_eigen3_matrix_library )
106107
execute_process(COMMAND git submodule update --init -- ${EIGEN3_INCLUDE_DIR}
@@ -116,7 +117,7 @@ message(STATUS "Eigen3 root path: ${EIGEN3_INCLUDE_DIR}")
116117
## 2. if any, and version >= 3.3.x, use system version
117118
## 3. otherwise, download (if required) and use submodule
118119
if( NOT STB_INCLUDE_DIR )
119-
set(STB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/3rdparty/stb")
120+
set(STB_INCLUDE_DIR "${THIRDPARTY_DIR}/stb")
120121

121122
if( NOT EXISTS ${STB_INCLUDE_DIR}/stb.h )
122123
execute_process(COMMAND git submodule update --init -- ${STB_INCLUDE_DIR}

apps/ExtPointBinding/ext/pointadapter_extlib1.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ struct PointAdapter {
2424
m_color (Eigen::Map<const VectorType >( p.color ))
2525
{ }
2626

27-
2827
inline const Eigen::Map< const VectorType >& pos() const { return m_pos; }
2928
inline const Eigen::Map< const VectorType >& normal() const { return m_normal; }
3029
inline const Eigen::Map< const VectorType >& color() const { return m_color; }
3130
inline const Eigen::Map< const VectorType >& rgb() const { return m_color; }
3231

32+
inline bool hasColor() const { return (m_color.array() > Scalar(0)).all(); } // invalid colors are encoded with -1
3333
};
3434

3535
}

apps/ExtPointBinding/ext/pointadapter_extlib2.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct PointAdapter {
2828
inline const Eigen::Map< const VectorType >& color() const { return m_color; }
2929
inline const Eigen::Map< const VectorType >& rgb() const { return m_color; }
3030

31+
inline bool hasColor() const { return (m_color.array() > Scalar(0)).all(); } // invalid colors are encoded with -1
32+
3133
};
3234

3335
}

apps/io/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@ set(io_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
77
file(GLOB_RECURSE io_sources ${io_ROOT}/*.cc)
88
file(GLOB_RECURSE io_headers ${io_ROOT}/*.h ${io_ROOT}/*.hpp)
99

10+
## Happly: automatic configuration:
11+
## 1. if HAPPLY_INCLUDE_DIR is set, use it directly
12+
## 2. if any, use system version
13+
## 3. otherwise, download (if required) and use submodule
14+
if( NOT HAPPLY_INCLUDE_DIR )
15+
set(HAPPLY_INCLUDE_DIR "${THIRDPARTY_DIR}/happly")
16+
17+
if( NOT EXISTS ${HAPPLY_INCLUDE_DIR}/happly.h )
18+
execute_process(COMMAND git submodule update --init -- ${HAPPLY_INCLUDE_DIR}
19+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
20+
endif( NOT EXISTS ${HAPPLY_INCLUDE_DIR}/happly.h )
21+
endif( NOT HAPPLY_INCLUDE_DIR )
22+
include_directories(${HAPPLY_INCLUDE_DIR})
23+
message(STATUS "HAPPLY root path: ${HAPPLY_INCLUDE_DIR}")
24+
1025
add_library(opengr_apps_io STATIC ${io_sources} ${io_headers})
11-
target_include_directories(opengr_apps_io PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
26+
target_include_directories(opengr_apps_io PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${HAPPLY_INCLUDE_DIR})
1227

1328
find_package(Filesystem QUIET)
1429
if(CXX_FILESYSTEM_HAVE_FS)

apps/io/gr/io/io.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ IOManager::formatPolyworksMatrix(
6565
/// Limits dependency on stb just to compilation of the library
6666
////////////////////////////////////////////////////////////////////////////////
6767
unsigned char*
68-
IOManager::stbi_load_(char const *filename, int *x, int *y, int *comp, int req_comp)
68+
IOManager::stbi_load_(const string& filename, int *x, int *y, int *comp, int req_comp)
6969
{
70-
return stbi_load(filename, x, y, comp, req_comp);
70+
return stbi_load(filename.c_str(), x, y, comp, req_comp);
7171
}
7272

7373
void

apps/io/gr/io/io.h

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@
1717

1818

1919
struct tripple {
20-
int a;
21-
int b;
22-
int c;
23-
int n1;
24-
int n2;
25-
int n3;
26-
int t1;
27-
int t2;
28-
int t3;
29-
tripple() {}
30-
tripple(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
20+
int a {-1};
21+
int b {-1};
22+
int c {-1};
23+
int n1 {-1};
24+
int n2 {-1};
25+
int n3 {-1};
26+
int t1 {-1};
27+
int t2 {-1};
28+
int t3 {-1};
29+
inline tripple() {}
30+
inline tripple(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
31+
// defaulted comparison operators are a C++20 extension, so we need to write it explicitely
32+
inline bool operator==(const tripple& o) const {
33+
return a==o.a && b==o.b && c==o.c &&
34+
n1==o.n1 && n2==o.n2 && n3==o.n3 &&
35+
t1==o.t1 && t2==o.t2 && t3==o.t3;
36+
}
3137
};
3238

3339
class IOManager{
@@ -37,9 +43,10 @@ class IOManager{
3743
};
3844

3945
public:
40-
// Obj read/write simple functions.
46+
/// Obj read/write simple functions.
47+
/// \warning For ply files: loads only vertices positions and attributes (faces are ignored)
4148
template<typename Scalar>
42-
bool ReadObject(const char *name,
49+
bool ReadObject(const std::string& name,
4350
std::vector<gr::Point3D<Scalar> > &v,
4451
std::vector<Eigen::Matrix2f> &tex_coords,
4552
std::vector<typename gr::Point3D<Scalar>::VectorType> &normals,
@@ -51,7 +58,7 @@ class IOManager{
5158
typename NormalRange,
5259
typename TrisRange,
5360
typename MTLSRange>
54-
bool WriteObject(const char *name,
61+
bool WriteObject(const std::string& name,
5562
const PointRange &v,
5663
const TextCoordRange &tex_coords,
5764
const NormalRange &normals,
@@ -64,7 +71,7 @@ class IOManager{
6471
private:
6572
template<typename Scalar>
6673
bool
67-
ReadPly(const char *name,
74+
ReadPly(const std::string& name,
6875
std::vector<gr::Point3D<Scalar> > &v,
6976
std::vector<typename gr::Point3D<Scalar>::VectorType> &normals);
7077

@@ -81,12 +88,12 @@ class IOManager{
8188
*/
8289
template<typename Scalar>
8390
bool
84-
ReadPtx(const char *name,
91+
ReadPtx(const std::string& name,
8592
std::vector<gr::Point3D<Scalar> > &v);
8693

8794
template<typename Scalar>
8895
bool
89-
ReadObj(const char *name,
96+
ReadObj(const std::string& name,
9097
std::vector<gr::Point3D<Scalar> > &v,
9198
std::vector<Eigen::Matrix2f> &tex_coords,
9299
std::vector<typename gr::Point3D<Scalar>::VectorType> &normals,
@@ -95,7 +102,7 @@ class IOManager{
95102

96103
template<typename PointRange, typename NormalRange>
97104
bool
98-
WritePly(std::string name,
105+
WritePly(const std::string& name,
99106
const PointRange &v,
100107
const NormalRange &normals);
101108

@@ -105,7 +112,7 @@ class IOManager{
105112
typename TrisRange,
106113
typename MTLSRange>
107114
bool
108-
WriteObj(std::string name,
115+
WriteObj(const std::string& name,
109116
const PointRange &v,
110117
const TexCoordRange &tex_coords,
111118
const NormalRange &normals,
@@ -126,7 +133,7 @@ class IOManager{
126133
/// Limits dependency on stb just to compilation of the library by compiling
127134
/// required stbi methods to object files at library compilation.
128135
unsigned char*
129-
stbi_load_(char const *filename, int *x, int *y, int *comp, int req_comp);
136+
stbi_load_(const std::string& name, int *x, int *y, int *comp, int req_comp);
130137

131138
void
132139
stbi_image_free_(void *retval_from_stbi_load);
@@ -138,5 +145,4 @@ class IOManager{
138145
}; // class IOMananger
139146

140147
#include "io.hpp"
141-
#include "io_ply.h"
142148

0 commit comments

Comments
 (0)