Skip to content

Commit

Permalink
Merge pull request #108 from STORM-IRIT/add_happly
Browse files Browse the repository at this point in the history
Rewrite PLY IO using Happly
  • Loading branch information
nmellado authored Feb 3, 2022
2 parents d2b569c + b222c0e commit 483e4d5
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 511 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build*/
*build*
*.user
assets/demo*
.vscode/*
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "3rdparty/stb"]
path = 3rdparty/stb
url = https://github.com/nothings/stb.git
[submodule "3rdparty/happly"]
path = 3rdparty/happly
url = https://github.com/nmwsharp/happly.git
1 change: 1 addition & 0 deletions 3rdparty/happly
Submodule happly added at cfa261
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OPTION (OpenGR_USE_WEIGHTED_LCP "Use gaussian weights for point samples when com
################################################################################
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src/)
set(THIRDPARTY_DIR ${PROJECT_SOURCE_DIR}/3rdparty)
set(ASSETS_DIR ${PROJECT_SOURCE_DIR}/assets)
set(SCRIPTS_DIR ${PROJECT_SOURCE_DIR}/scripts)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
Expand Down Expand Up @@ -100,7 +101,7 @@ if( NOT EIGEN3_INCLUDE_DIR )
find_package(Eigen3 QUIET)
if( (NOT Eigen3_FOUND) OR EIGEN_VERSION_NUMBER VERSION_LESS 3.3 )

set(EIGEN3_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/3rdparty/Eigen")
set(EIGEN3_INCLUDE_DIR "${THIRDPARTY_DIR}/Eigen")

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

if( NOT EXISTS ${STB_INCLUDE_DIR}/stb.h )
execute_process(COMMAND git submodule update --init -- ${STB_INCLUDE_DIR}
Expand Down
2 changes: 1 addition & 1 deletion apps/ExtPointBinding/ext/pointadapter_extlib1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ struct PointAdapter {
m_color (Eigen::Map<const VectorType >( p.color ))
{ }


inline const Eigen::Map< const VectorType >& pos() const { return m_pos; }
inline const Eigen::Map< const VectorType >& normal() const { return m_normal; }
inline const Eigen::Map< const VectorType >& color() const { return m_color; }
inline const Eigen::Map< const VectorType >& rgb() const { return m_color; }

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

}
Expand Down
2 changes: 2 additions & 0 deletions apps/ExtPointBinding/ext/pointadapter_extlib2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ struct PointAdapter {
inline const Eigen::Map< const VectorType >& color() const { return m_color; }
inline const Eigen::Map< const VectorType >& rgb() const { return m_color; }

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

};

}
Expand Down
17 changes: 16 additions & 1 deletion apps/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@ set(io_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB_RECURSE io_sources ${io_ROOT}/*.cc)
file(GLOB_RECURSE io_headers ${io_ROOT}/*.h ${io_ROOT}/*.hpp)

## Happly: automatic configuration:
## 1. if HAPPLY_INCLUDE_DIR is set, use it directly
## 2. if any, use system version
## 3. otherwise, download (if required) and use submodule
if( NOT HAPPLY_INCLUDE_DIR )
set(HAPPLY_INCLUDE_DIR "${THIRDPARTY_DIR}/happly")

if( NOT EXISTS ${HAPPLY_INCLUDE_DIR}/happly.h )
execute_process(COMMAND git submodule update --init -- ${HAPPLY_INCLUDE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif( NOT EXISTS ${HAPPLY_INCLUDE_DIR}/happly.h )
endif( NOT HAPPLY_INCLUDE_DIR )
include_directories(${HAPPLY_INCLUDE_DIR})
message(STATUS "HAPPLY root path: ${HAPPLY_INCLUDE_DIR}")

add_library(opengr_apps_io STATIC ${io_sources} ${io_headers})
target_include_directories(opengr_apps_io PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
target_include_directories(opengr_apps_io PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${HAPPLY_INCLUDE_DIR})

find_package(Filesystem QUIET)
if(CXX_FILESYSTEM_HAVE_FS)
Expand Down
4 changes: 2 additions & 2 deletions apps/io/gr/io/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ IOManager::formatPolyworksMatrix(
/// Limits dependency on stb just to compilation of the library
////////////////////////////////////////////////////////////////////////////////
unsigned char*
IOManager::stbi_load_(char const *filename, int *x, int *y, int *comp, int req_comp)
IOManager::stbi_load_(const string& filename, int *x, int *y, int *comp, int req_comp)
{
return stbi_load(filename, x, y, comp, req_comp);
return stbi_load(filename.c_str(), x, y, comp, req_comp);
}

void
Expand Down
48 changes: 27 additions & 21 deletions apps/io/gr/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,23 @@


struct tripple {
int a;
int b;
int c;
int n1;
int n2;
int n3;
int t1;
int t2;
int t3;
tripple() {}
tripple(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
int a {-1};
int b {-1};
int c {-1};
int n1 {-1};
int n2 {-1};
int n3 {-1};
int t1 {-1};
int t2 {-1};
int t3 {-1};
inline tripple() {}
inline tripple(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
// defaulted comparison operators are a C++20 extension, so we need to write it explicitely
inline bool operator==(const tripple& o) const {
return a==o.a && b==o.b && c==o.c &&
n1==o.n1 && n2==o.n2 && n3==o.n3 &&
t1==o.t1 && t2==o.t2 && t3==o.t3;
}
};

class IOManager{
Expand All @@ -37,9 +43,10 @@ class IOManager{
};

public:
// Obj read/write simple functions.
/// Obj read/write simple functions.
/// \warning For ply files: loads only vertices positions and attributes (faces are ignored)
template<typename Scalar>
bool ReadObject(const char *name,
bool ReadObject(const std::string& name,
std::vector<gr::Point3D<Scalar> > &v,
std::vector<Eigen::Matrix2f> &tex_coords,
std::vector<typename gr::Point3D<Scalar>::VectorType> &normals,
Expand All @@ -51,7 +58,7 @@ class IOManager{
typename NormalRange,
typename TrisRange,
typename MTLSRange>
bool WriteObject(const char *name,
bool WriteObject(const std::string& name,
const PointRange &v,
const TextCoordRange &tex_coords,
const NormalRange &normals,
Expand All @@ -64,7 +71,7 @@ class IOManager{
private:
template<typename Scalar>
bool
ReadPly(const char *name,
ReadPly(const std::string& name,
std::vector<gr::Point3D<Scalar> > &v,
std::vector<typename gr::Point3D<Scalar>::VectorType> &normals);

Expand All @@ -81,12 +88,12 @@ class IOManager{
*/
template<typename Scalar>
bool
ReadPtx(const char *name,
ReadPtx(const std::string& name,
std::vector<gr::Point3D<Scalar> > &v);

template<typename Scalar>
bool
ReadObj(const char *name,
ReadObj(const std::string& name,
std::vector<gr::Point3D<Scalar> > &v,
std::vector<Eigen::Matrix2f> &tex_coords,
std::vector<typename gr::Point3D<Scalar>::VectorType> &normals,
Expand All @@ -95,7 +102,7 @@ class IOManager{

template<typename PointRange, typename NormalRange>
bool
WritePly(std::string name,
WritePly(const std::string& name,
const PointRange &v,
const NormalRange &normals);

Expand All @@ -105,7 +112,7 @@ class IOManager{
typename TrisRange,
typename MTLSRange>
bool
WriteObj(std::string name,
WriteObj(const std::string& name,
const PointRange &v,
const TexCoordRange &tex_coords,
const NormalRange &normals,
Expand All @@ -126,7 +133,7 @@ class IOManager{
/// Limits dependency on stb just to compilation of the library by compiling
/// required stbi methods to object files at library compilation.
unsigned char*
stbi_load_(char const *filename, int *x, int *y, int *comp, int req_comp);
stbi_load_(const std::string& name, int *x, int *y, int *comp, int req_comp);

void
stbi_image_free_(void *retval_from_stbi_load);
Expand All @@ -138,5 +145,4 @@ class IOManager{
}; // class IOMananger

#include "io.hpp"
#include "io_ply.h"

Loading

0 comments on commit 483e4d5

Please sign in to comment.