Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhiestan committed Aug 19, 2017
2 parents e37ae58 + a19ad98 commit 0369905
Show file tree
Hide file tree
Showing 38 changed files with 4,165 additions and 75 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -18,6 +18,11 @@ The Regard3D source code is released under the [MIT license](http://opensource.o
Version history
---------------

###Version 0.9.2, 19.08.2017:
- Upgraded to OpenMVG 1.2, AssImp 4.0.1
- Added Fast-AKAZE, TBMR keypoint detectors
- Bugfix: Export of textured surfaces now works again (Issue #4)

###Version 0.9.1, 01.02.2017:
- Upgraded to OpenMVG 1.1
- Third-party programs (MVE, PoissonRecon) up to date
Expand Down
39 changes: 29 additions & 10 deletions src/CMakeLists.txt
Expand Up @@ -387,8 +387,8 @@ ENDIF(MSVC)

# AssImp
IF(WIN32 OR APPLE)
LIST(APPEND CMAKE_MODULE_PATH "${ASSIMP_DIR}/lib/cmake/assimp-3.1" )
LIST(APPEND CMAKE_PREFIX_PATH "${ASSIMP_DIR}/lib/cmake/assimp-3.1" )
LIST(APPEND CMAKE_MODULE_PATH "${ASSIMP_DIR}/lib/cmake/assimp-4.0" )
LIST(APPEND CMAKE_PREFIX_PATH "${ASSIMP_DIR}/lib/cmake/assimp-4.0" )
FIND_PACKAGE(assimp REQUIRED)
IF(WIN32)
IF(MSVC)
Expand Down Expand Up @@ -455,14 +455,20 @@ SET(OPENMVG_EXCLUDE_PATENTED ON)
#INCLUDE_DIRECTORIES(${OpenMVG_INCLUDE_DIRS})

FIND_PACKAGE(OpenMVG REQUIRED)
message("OPENMVG_LIBRARIES: ${OPENMVG_LIBRARIES}")
message("OPENMVG_INCLUDE_DIRS: ${OPENMVG_INCLUDE_DIRS}")
foreach(CURDIR ${OPENMVG_INCLUDE_DIRS})
IF(IS_DIRECTORY "${CURDIR}/third_party")
LIST(APPEND OPENMVG_INCLUDE_DIRS "${CURDIR}/third_party")
ENDIF()
endforeach()
message("OPENMVG_INCLUDE_DIRS: ${OPENMVG_INCLUDE_DIRS}")
INCLUDE_DIRECTORIES(${OPENMVG_INCLUDE_DIRS})

IF(DEFINED OPENMVG_VERSION)
SET(R3D_HAVE_OPENMVG_VERSION TRUE)
ENDIF(DEFINED OPENMVG_VERSION)

message("OPENMVG_LIBRARIES: ${OPENMVG_LIBRARIES}")

# VLFEAT (optional)
SET( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" )
FIND_PACKAGE(VLFEAT)
Expand Down Expand Up @@ -587,6 +593,10 @@ INCLUDE_DIRECTORIES(thirdparty/daisy/include)
ADD_SUBDIRECTORY(thirdparty/akaze)
INCLUDE_DIRECTORIES(thirdparty/akaze/lib)

# Fast-AKAZE
ADD_SUBDIRECTORY(thirdparty/fast-akaze)
INCLUDE_DIRECTORIES(thirdparty/fast-akaze)

# LIOP
ADD_SUBDIRECTORY(thirdparty/liop)
INCLUDE_DIRECTORIES(thirdparty/liop)
Expand Down Expand Up @@ -637,7 +647,7 @@ IF(WIN32)
ENDIF(WIN32)

# For Apple set the icns file containing icons
if(APPLE)
IF(APPLE)
# icon files to copy in the bundle
SET( OSX_ICON_FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/osx/regard3d.icns )
# set where in the bundle to put the icns files
Expand Down Expand Up @@ -668,7 +678,7 @@ IF(TARGET openMVG_SfM_Sequential)
ENDIF(TARGET openMVG_SfM_Sequential)

SET(REGARD3D_LINK_LIBRARIES ${REGARD3D_LINK_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES}
${Boost_LIBRARIES} ${PCL_LIBRARIES} daisy AKAZE liop ${OpenCV_LIBRARIES} ${OPENMVG_LIBRARIES}
${Boost_LIBRARIES} ${PCL_LIBRARIES} daisy AKAZE fast-akaze liop ${OpenCV_LIBRARIES} ${OPENMVG_LIBRARIES}
${CERES_LIBRARIES} ${GLOG_LIBRARIES} ${SuiteSparse_LIBRARIES} ${FLANN_LIBRARIES}
easyexif ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${ASSIMP_LIBRARIES} ${OPENGL_LIBRARIES}
optimized;minilog;debug;minilog_d tinyply)
Expand Down Expand Up @@ -700,6 +710,15 @@ IF(DEFINED R3D_ADDITIONAL_LINK_LIBRARIES)
SET(REGARD3D_LINK_LIBRARIES ${REGARD3D_LINK_LIBRARIES} ${R3D_ADDITIONAL_LINK_LIBRARIES})
ENDIF(DEFINED R3D_ADDITIONAL_LINK_LIBRARIES)

IF(APPLE)
# Add frameworks CoreText QuickLook ApplicationServices CoreServices
FIND_LIBRARY(CORE_TEXT_LIBRARY CoreText )
FIND_LIBRARY(QUICK_LOOK_LIBRARY QuickLook )
FIND_LIBRARY(APP_SERVICES_LIBRARY ApplicationServices )
FIND_LIBRARY(CORE_SERVICES_LIBRARY CoreServices )
SET(REGARD3D_LINK_LIBRARIES ${REGARD3D_LINK_LIBRARIES} ${CORE_TEXT_LIBRARY} ${QUICK_LOOK_LIBRARY} ${APP_SERVICES_LIBRARY} ${CORE_SERVICES_LIBRARY})
ENDIF(APPLE)

# Workaround for MSYS: Replace /c/path with c:/path
# MinGW doesn't like the /c/path syntax in linklibs.rsp
IF(MSYS)
Expand Down Expand Up @@ -738,13 +757,13 @@ IF(APPLE)
FILE(COPY "${CMAKE_BINARY_DIR}/../thirdparty_omp/poisson" DESTINATION "${CMAKE_BINARY_DIR}/Regard3D.app/Contents/MacOS")
FILE(COPY "${CMAKE_BINARY_DIR}/../thirdparty_omp/mve" DESTINATION "${CMAKE_BINARY_DIR}/Regard3D.app/Contents/MacOS")

# Copy libiomp5.dylib to executable directory
FIND_FILE(omp_dylib libiomp5.dylib PATHS ENV DYLD_LIBRARY_PATH)
# Copy libomp.dylib to executable directory
FIND_FILE(omp_dylib libomp.dylib PATHS ENV DYLD_LIBRARY_PATH "/Users/romanhiestand/dev/clang_openmp/clang+llvm-3.9.0-x86_64-apple-darwin/lib")
FILE(COPY ${omp_dylib} DESTINATION "${CMAKE_BINARY_DIR}/Regard3D.app/Contents/MacOS")

# Set search path of libiomp5.dylib to the executable path on OS X
# Set search path of libomp.dylib to the executable path on OS X
ADD_CUSTOM_COMMAND(TARGET Regard3D POST_BUILD
COMMAND install_name_tool -change libiomp5.dylib @executable_path/libiomp5.dylib "${CMAKE_BINARY_DIR}/Regard3D.app/Contents/MacOS/Regard3D" )
COMMAND install_name_tool -change libomp.dylib @executable_path/libomp.dylib "${CMAKE_BINARY_DIR}/Regard3D.app/Contents/MacOS/Regard3D" )
ENDIF(CMAKE_COMPILER_IS_GNUCC)

ELSE(OPENMP_FOUND)
Expand Down
2 changes: 2 additions & 0 deletions src/CommonIncludes.h
Expand Up @@ -9,7 +9,9 @@

#include "config.h"

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
15 changes: 9 additions & 6 deletions src/R3DComputeMatches.cpp
Expand Up @@ -63,14 +63,17 @@ void R3DComputeMatches::addImages(const ImageInfoVector &iiv)
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "openMVG/image/image.hpp"
#include "openMVG/features/features.hpp"
#include "openMVG/image/image_container.hpp"
#include "openMVG/image/pixel_types.hpp"
#include "openMVG/image/image_io.hpp"
#include "openMVG/features/feature.hpp"

/// Generic Image Collection image matching
#if defined(R3D_USE_OPENMVG_PRE08)
# include "openMVG/matching_image_collection/Matcher_AllInMemory.hpp"
#else
# include "openMVG/matching_image_collection/Matcher_Regions_AllInMemory.hpp"
//# include "openMVG/matching_image_collection/Matcher_Regions_AllInMemory.hpp"
#include "openMVG/matching_image_collection/Matcher_Regions.hpp"
#include "openMVG/sfm/sfm_data.hpp"
#include "openMVG/sfm/sfm_data_io.hpp"
#include "openMVG/sfm/pipelines/sfm_engine.hpp"
Expand Down Expand Up @@ -683,7 +686,7 @@ bool R3DComputeMatches::computeMatches(Regard3DFeatures::R3DFParams &params, boo
//---------------------------------------
openMVG::sfm::SfM_Data sfm_data;
if(!Load(sfm_data, sSfM_Data_Filename, openMVG::sfm::ESfM_Data(openMVG::sfm::VIEWS | openMVG::sfm::INTRINSICS))) {
std::cerr << std::endl
MLOG << std::endl
<< "The input SfM_Data file \"" << sSfM_Data_Filename << "\" cannot be read." << std::endl;
return false; // EXIT_FAILURE;
}
Expand Down Expand Up @@ -940,7 +943,7 @@ bool R3DComputeMatches::computeMatches(Regard3DFeatures::R3DFParams &params, boo
computePutativeDescriptorMatches<Regard3DFeatures::DescriptorR3D, Regard3DFeatures::KeypointSetR3D, MatcherR3D>
(vec_fileNames, sOutDir, map_PutativesMatches, fDistRatio);
#else
std::unique_ptr<Matcher_Regions_AllInMemory> collectionMatcher(new Matcher_Regions_AllInMemory(fDistRatio, ANN_L2));
std::unique_ptr<Matcher_Regions> collectionMatcher(new Matcher_Regions(fDistRatio, ANN_L2));
if(regions_provider->load(sfm_data, sMatchesDirectory, regions_type))
//if(collectionMatcher->loadData(regions_type, vec_fileNames, sMatchesDirectory))
{
Expand Down Expand Up @@ -981,7 +984,7 @@ bool R3DComputeMatches::computeMatches(Regard3DFeatures::R3DFParams &params, boo
// Load the features
std::shared_ptr<openMVG::sfm::Features_Provider> feats_provider = std::make_shared<openMVG::sfm::Features_Provider>();
if(!feats_provider->load(sfm_data, sMatchesDirectory, regions_type)) {
std::cerr << std::endl << "Invalid features." << std::endl;
MLOG << std::endl << "Invalid features." << std::endl;
return false; // EXIT_FAILURE;
}
ImageCollectionGeometricFilter collectionGeomFilter(&sfm_data, regions_provider);
Expand Down
126 changes: 103 additions & 23 deletions src/R3DModelOperations.cpp
Expand Up @@ -41,6 +41,13 @@
#include <pcl/io/vtk_lib_io.h>
#endif

#include <assimp/postprocess.h>
#include <assimp/version.h>
#include <assimp/scene.h>
#include <assimp/Importer.hpp>
#include <assimp/DefaultLogger.hpp>
#include <assimp/Exporter.hpp>

void R3DModelOperations::combineDenseModels(R3DProject::Densification *pDensification, int numModels)
{
wxString combinedModelName(wxT("pmvs_combined.ply"));
Expand Down Expand Up @@ -240,6 +247,9 @@ bool R3DModelOperations::exportSurface(R3DProject::Surface *pSurface, const wxSt

bool retVal = true;

Assimp::Importer imp;
Assimp::Exporter exp;

// Determine original surface file type
wxFileName exportFN(filename);
if(surfaceModelFN.GetExt().IsSameAs(wxT("ply"), false))
Expand All @@ -257,13 +267,20 @@ bool R3DModelOperations::exportSurface(R3DProject::Surface *pSurface, const wxSt
#endif
retVal = false;

std::string tmpfn("tmp/temp_surface.obj");
retVal &= (pcl::io::saveOBJFile(tmpfn, mesh, 7) == 0);
retVal &= wxCopyFile(wxString(tmpfn.c_str(), wxConvLibc), filename, true);
// const aiScene* pScene = imp.ReadFile(surfaceModelFNStr.c_str(), aiProcess_JoinIdenticalVertices);
// if(pScene == NULL)
// retVal = false;
// else
{
std::string tmpfn("tmp/temp_surface.obj");
retVal &= (pcl::io::saveOBJFile(tmpfn, mesh, 7) == 0);
//const aiReturn res = exp.Export(pScene, "obj", tmpfn.c_str());
retVal &= wxCopyFile(wxString(tmpfn.c_str(), wxConvLibc), filename, true);
}
}
else
{
// PointCloudLibrary does not support textures in PLY files
// PointCloudLibrary/AssImp does not support textures in PLY files
retVal = false;
}
}
Expand All @@ -279,16 +296,23 @@ bool R3DModelOperations::exportSurface(R3DProject::Surface *pSurface, const wxSt
{
if(pSurface->colorizationType_ == R3DProject::CTColoredVertices)
{
pcl::PolygonMesh mesh;
/* pcl::PolygonMesh mesh;
#if PCL_VERSION_COMPARE(<, 1, 7, 2)
if(pcl::io::loadPolygonFileOBJ(surfaceModelFNStr, mesh) == -1)
#else
if(pcl::io::loadOBJFile(surfaceModelFNStr, mesh) == -1)
#endif
retVal = false;
retVal = false;*/

std::string fn(filename.mb_str());
retVal = (pcl::io::savePLYFile(fn, mesh) == 0);
const aiScene* pScene = imp.ReadFile(surfaceModelFNStr.c_str(), aiProcess_JoinIdenticalVertices);
if(pScene == NULL)
retVal = false;
else
{
std::string fn(filename.mb_str());
//retVal = (pcl::io::savePLYFile(fn, mesh) == 0);
const aiReturn res = exp.Export(pScene, "ply", fn.c_str());
}
}
else
{
Expand All @@ -299,27 +323,83 @@ bool R3DModelOperations::exportSurface(R3DProject::Surface *pSurface, const wxSt
else
{
// Load and save OBJ
pcl::TextureMesh mesh;
/* pcl::TextureMesh mesh;
#if PCL_VERSION_COMPARE(<, 1, 7, 2)
if(pcl::io::loadPolygonFileOBJ(surfaceModelFNStr, mesh) == -1)
#else
if(pcl::io::loadOBJFile(surfaceModelFNStr, mesh) == -1)
#endif
retVal = false;*/
const aiScene* pScene = imp.ReadFile(surfaceModelFNStr.c_str(), aiProcess_JoinIdenticalVertices);
if(pScene == NULL)
retVal = false;
else
{
std::string exportNameC(exportFN.GetName().ToAscii()); // Converted to ASCII
wxString exportNameASCII(wxString::FromAscii(exportNameC.c_str()));

wxFileName tempFN(wxT("tmp"), exportNameASCII, wxT("obj"));
std::string tmpfn(std::string( tempFN.GetFullPath(wxPATH_UNIX).ToAscii() ));
const aiReturn res = exp.Export(pScene, "obj", tmpfn.c_str());
retVal &= wxCopyFile(tempFN.GetFullPath(), filename, true);

// Problem: We would like to eventually have 3 files:
// - Model file with name filename
// - Material file with same or similar name, but .mtl extension
// - Texture file with same or similar name (PNG format)
// This is a problem on Windows, since the pcl::io methods/AssImp only accept
// C-Strings (instead of Unicode) and the name of the material file is stored
// in the OBJ file.
// It is also unclear how the textual representation of the material file name
// and the texture file name is interpreted, since the OBJ and the material files
// are text files.
// Workaround: map name to ASCII as good as possble, use it to store
// OBJ file and material file. Rename OBJ file to user requested filename.
wxFileName materialInFN(tempFN), materialOutFN(filename);
materialInFN.SetExt(wxT("mtl"));
materialOutFN.SetName( exportNameASCII );
materialOutFN.SetExt(wxT("mtl"));
retVal &= wxCopyFile(materialInFN.GetFullPath(), materialOutFN.GetFullPath(), true);

bool hasTexture = false;
for(int i = 0; i < static_cast<int>(pScene->mNumMeshes); i++)
{
aiMesh *pMesh = pScene->mMeshes[i];
if(pMesh != NULL)
{
if(pMesh->GetNumUVChannels() > 0
&& pMesh->HasTextureCoords(0))
hasTexture = true;

if(hasTexture)
{
unsigned int usedMaterial = pMesh->mMaterialIndex;
if(usedMaterial < pScene->mNumMaterials)
{
const aiMaterial *pMaterial = pScene->mMaterials[usedMaterial];
unsigned int textureCount = pMaterial->GetTextureCount(aiTextureType_DIFFUSE);
for(unsigned int j = 0; j < textureCount; j++)
{
aiString path;
aiTextureMapping mapping;
unsigned int uvindex;
float blend;
aiTextureOp op;
aiTextureMapMode mapmode[3];
pMaterial->GetTexture(aiTextureType_DIFFUSE, j, &path, &mapping, &uvindex, &blend, &op, mapmode);

wxFileName textureFromFN(surfaceModelFN), textureToFN(filename);
textureFromFN.SetFullName( wxString( path.C_Str(), wxConvUTF8 ) );
textureToFN.SetFullName( wxString( path.C_Str(), wxConvUTF8 ) );
retVal &= wxCopyFile(textureFromFN.GetFullPath(), textureToFN.GetFullPath(), true);
}
}
}
}
}
}

// Problem: We would like to eventually have 3 files:
// - Model file with name filename
// - Material file with same or similar name, but .mtl extension
// - Texture file with same or similar name (PNG format)
// This is a problem on Windows, since the pcl::io methods only accept
// C-Strings (instead of Unicode) and the name of the material file is stored
// in the OBJ file.
// It is also unclear how the textual representation of the material file name
// and the texture file name is interpreted, since the OBJ and the material files
// are text files.
// Workaround: map name to ASCII as good as possble, use it to store
// OBJ file and material file. Rename OBJ file to user requested filename.
std::string exportNameC(exportFN.GetName().ToAscii()); // Converted to ASCII
/* std::string exportNameC(exportFN.GetName().ToAscii()); // Converted to ASCII
wxString exportNameASCII(wxString::FromAscii(exportNameC.c_str()));
// Copy texture files
Expand Down Expand Up @@ -348,7 +428,7 @@ bool R3DModelOperations::exportSurface(R3DProject::Surface *pSurface, const wxSt
materialInFN.SetExt(wxT("mtl"));
materialOutFN.SetName( exportNameASCII );
materialOutFN.SetExt(wxT("mtl"));
retVal &= wxCopyFile(materialInFN.GetFullPath(), materialOutFN.GetFullPath(), true);
retVal &= wxCopyFile(materialInFN.GetFullPath(), materialOutFN.GetFullPath(), true);*/
}
}
else
Expand Down
8 changes: 8 additions & 0 deletions src/R3DProject.cpp
Expand Up @@ -1056,6 +1056,10 @@ bool R3DProject::writeImageListTXT(const R3DProjectPaths &paths)
#if !defined(R3D_USE_OPENMVG_PRE08)
#include "openMVG/sfm/sfm_data.hpp"
#include "openMVG/sfm/sfm_data_io.hpp"
#include "openMVG/cameras/Camera_Pinhole.hpp"
#include "openMVG/cameras/Camera_Pinhole_Radial.hpp"
#include "openMVG/cameras/Camera_Pinhole_Fisheye.hpp"
#include "openMVG/cameras/Camera_IO.hpp"
#endif

bool R3DProject::writeSfmData(const R3DProjectPaths &paths)
Expand Down Expand Up @@ -1119,6 +1123,10 @@ bool R3DProject::writeSfmData(const R3DProjectPaths &paths)
intrinsic = std::make_shared<openMVG::cameras::Pinhole_Intrinsic_Radial_K3>
(width, height, focal, ppx, ppy, 0.0, 0.0, 0.0); // setup no distortion as initial guess
break;
case openMVG::cameras::PINHOLE_CAMERA_FISHEYE:
intrinsic = std::make_shared<openMVG::cameras::Pinhole_Intrinsic_Fisheye>
(width, height, focal, ppx, ppy, 0.0, 0.0, 0.0); // setup no distortion as initial guess
break;
default:
std::cout << "Unknown camera model: " << (int)e_User_camera_model << std::endl;
}
Expand Down

0 comments on commit 0369905

Please sign in to comment.