Skip to content

Commit

Permalink
add support to load/save OBJ
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcseacave committed Oct 10, 2015
1 parent fba29be commit c121ffc
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 156 deletions.
2 changes: 1 addition & 1 deletion apps/ReconstructMesh/ReconstructMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int main(int argc, LPCTSTR* argv)
if (!scene.Load(MAKE_PATH_SAFE(OPT::strInputFileName)) || scene.mesh.IsEmpty())
return EXIT_FAILURE;
// save mesh
scene.mesh.Save(MAKE_PATH_SAFE(Util::getFullFileName(OPT::strOutputFileName) + _T(".ply")));
scene.mesh.Save(MAKE_PATH_SAFE(OPT::strOutputFileName));
} else {
if (OPT::strMeshFileName.IsEmpty()) {
// load point-cloud and reconstruct a coarse mesh
Expand Down
4 changes: 2 additions & 2 deletions apps/RefineMesh/RefineMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ bool Initialize(size_t argc, LPCTSTR* argv)
("max-views", boost::program_options::value<unsigned>(&OPT::nMaxViews)->default_value(8), "maximum number of neighbor images used to refine the mesh")
("decimate", boost::program_options::value<float>(&OPT::fDecimateMesh)->default_value(0.f), "decimation factor in range [0..1] to be applied to the input surface before refinement (0 - auto, 1 - disabled)")
("close-holes", boost::program_options::value<unsigned>(&OPT::nCloseHoles)->default_value(30), "try to close small holes in the input surface (0 - disabled)")
("ensure-edge-size", boost::program_options::value<unsigned>(&OPT::nEnsureEdgeSize)->default_value(1), "ensure edge size and improve vertex valence of the input surface (0 - disabled)")
("ensure-edge-size", boost::program_options::value<unsigned>(&OPT::nEnsureEdgeSize)->default_value(1), "ensure edge size and improve vertex valence of the input surface (0 - disabled, 1 - auto, 2 - force)")
("max-face-area", boost::program_options::value<unsigned>(&OPT::nMaxFaceArea)->default_value(64), "maximum face area projected in any pair of images that is not subdivided (0 - disabled)")
("scales", boost::program_options::value<unsigned>(&OPT::nScales)->default_value(3), "how many iterations to run mesh optimization on multi-scale images")
("scale-step", boost::program_options::value<float>(&OPT::fScaleStep)->default_value(0.5f), "image scale factor used at each mesh optimization step")
("reduce-memory", boost::program_options::value<unsigned>(&OPT::nReduceMemory)->default_value(1), "recompute some data in order to reduce memory requirements")
("alternate-pair", boost::program_options::value<unsigned>(&OPT::nAlternatePair)->default_value(0), "refine mesh using an image pair alternatively as reference (0 - both, 1 - alternate, 2 - only left, 3 - only right)")
("regularity-weight", boost::program_options::value<float>(&OPT::fRegularityWeight)->default_value(0.1f), "scalar regularity weight to balance between photo-consistency and regularization terms during mesh optimization")
("regularity-weight", boost::program_options::value<float>(&OPT::fRegularityWeight)->default_value(0.2f), "scalar regularity weight to balance between photo-consistency and regularization terms during mesh optimization")
("rigidity-elasticity-ratio", boost::program_options::value<float>(&OPT::fRatioRigidityElasticity)->default_value(0.9f), "scalar ratio used to compute the regularity gradient as a combination of rigidity and elasticity")
("gradient-step", boost::program_options::value<float>(&OPT::fGradientStep)->default_value(45.05f), "gradient step to be used instead (0 - auto)")
("planar-vertex-ratio", boost::program_options::value<float>(&OPT::fPlanarVertexRatio)->default_value(0.f), "threshold used to remove vertices on planar patches (0 - disabled)")
Expand Down
4 changes: 3 additions & 1 deletion apps/TextureMesh/TextureMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ float fOutlierThreshold;
float fRatioDataSmoothness;
bool bGlobalSeamLeveling;
bool bLocalSeamLeveling;
unsigned nTextureSizeMultiple;
unsigned nRectPackingHeuristic;
uint32_t nColEmpty;
unsigned nArchiveType;
Expand Down Expand Up @@ -100,6 +101,7 @@ bool Initialize(size_t argc, LPCTSTR* argv)
("cost-smoothness-ratio", boost::program_options::value<float>(&OPT::fRatioDataSmoothness)->default_value(0.1f), "ratio used to adjust the preference for more compact patches (1 - best quality/worst compactness, ~0 - worst quality/best compactness)")
("global-seam-leveling", boost::program_options::value<bool>(&OPT::bGlobalSeamLeveling)->default_value(true), "generate uniform texture patches using global seam leveling")
("local-seam-leveling", boost::program_options::value<bool>(&OPT::bLocalSeamLeveling)->default_value(true), "generate uniform texture patch borders using local seam leveling")
("texture-size-multiple", boost::program_options::value<unsigned>(&OPT::nTextureSizeMultiple)->default_value(0), "texture size should be a multiple of this value (0 - power of two)")
("patch-packing-heuristic", boost::program_options::value<unsigned>(&OPT::nRectPackingHeuristic)->default_value(3), "specify the heuristic used when deciding where to place a new patch (0 - best fit, 3 - good speed, 100 - best speed)")
("empty-color", boost::program_options::value<uint32_t>(&OPT::nColEmpty)->default_value(0x00FF7F27), "color used for faces not covered by any image")
;
Expand Down Expand Up @@ -211,7 +213,7 @@ int main(int argc, LPCTSTR* argv)
return EXIT_FAILURE;
}
TD_TIMER_START();
if (!scene.TextureMesh(OPT::nResolutionLevel, OPT::nMinResolution, OPT::fOutlierThreshold, OPT::fRatioDataSmoothness, OPT::bGlobalSeamLeveling, OPT::bLocalSeamLeveling, OPT::nRectPackingHeuristic, Pixel8U(OPT::nColEmpty)))
if (!scene.TextureMesh(OPT::nResolutionLevel, OPT::nMinResolution, OPT::fOutlierThreshold, OPT::fRatioDataSmoothness, OPT::bGlobalSeamLeveling, OPT::bLocalSeamLeveling, OPT::nTextureSizeMultiple, OPT::nRectPackingHeuristic, Pixel8U(OPT::nColEmpty)))
return EXIT_FAILURE;
VERBOSE("Mesh texturing completed: %u vertices, %u faces (%s)", scene.mesh.vertices.GetSize(), scene.mesh.faces.GetSize(), TD_TIMER_GET_FMT().c_str());

Expand Down
15 changes: 2 additions & 13 deletions libs/Common/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ class TPoint2 : public cv::Point_<TYPE>
#ifdef _USE_EIGEN
inline TPoint2(const EVec& rhs) { operator EVec& () = rhs; }
#endif
inline TPoint2(const TYPE& _x) : Base(_x,_x) {}
explicit inline TPoint2(const TYPE& _x) : Base(_x,_x) {}
inline TPoint2(const TYPE& _x, const TYPE& _y) : Base(_x,_y) {}
explicit inline TPoint2(const cv::Point3_<TYPE>& pt) : Base(pt.x/pt.z,pt.y/pt.z) {}

Expand Down Expand Up @@ -1378,7 +1378,7 @@ class TPoint3 : public cv::Point3_<TYPE>
#ifdef _USE_EIGEN
inline TPoint3(const EVec& rhs) { operator EVec& () = rhs; }
#endif
inline TPoint3(const TYPE& _x) : Base(_x,_x,_x) {}
explicit inline TPoint3(const TYPE& _x) : Base(_x,_x,_x) {}
inline TPoint3(const TYPE& _x, const TYPE& _y, const TYPE& _z) : Base(_x,_y,_z) {}
template <typename T> inline TPoint3(const cv::Point_<T>& pt, const T& _z=T(1)) : Base(pt.x,pt.y,_z) {}
template <typename T1, typename T2> inline TPoint3(const cv::Point_<T1>& pt, const T2& _z) : Base(pt.x,pt.y,_z) {}
Expand Down Expand Up @@ -1832,7 +1832,6 @@ struct TPixel {
typedef typename ColorType<TYPE>::alt_type ALT;
typedef TYPE Type;
typedef TPoint3<TYPE> Pnt;
typedef TMatrix<TYPE,3,1> Vec;
static const TPixel BLACK;
static const TPixel WHITE;
static const TPixel GRAY;
Expand All @@ -1847,7 +1846,6 @@ struct TPixel {
template <typename T> inline TPixel(const TPixel<T>& p) : r(TYPE(p.r)), g(TYPE(p.g)), b(TYPE(p.b)) {}
inline TPixel(TYPE _r, TYPE _g, TYPE _b) : r(_r), g(_g), b(_b) {}
inline TPixel(const Pnt& col) : c0(col.x), c1(col.y), c2(col.z) {}
inline TPixel(const Vec& col) : c0(col[0]), c1(col[1]), c2(col[2]) {}
inline TPixel(uint32_t col) : r((col>>16)&0xFF), g((col>>8)&0xFF), b(col&0xFF) {}
// set/get from default type
inline void set(TYPE _r, TYPE _g, TYPE _b) { r = _r; g = _g; b = _b; }
Expand All @@ -1867,9 +1865,6 @@ struct TPixel {
// access as vector equivalent
inline operator const Pnt& () const { return *((const Pnt*)this); }
inline operator Pnt& () { return *((Pnt*)this); }
// access as vector equivalent
inline operator const Vec& () const { return *((const Vec*)this); }
inline operator Vec& () { return *((Vec*)this); }
// access as cv::Scalar equivalent
inline operator cv::Scalar () const { return cv::Scalar(c[0], c[1], c[2], TYPE(0)); }
// compare
Expand Down Expand Up @@ -1936,7 +1931,6 @@ struct TColor {
typedef TYPE Type;
typedef TPixel<TYPE> Pxl;
typedef TPoint3<TYPE> Pnt;
typedef TMatrix<TYPE,4,1> Vec;
static const TColor BLACK;
static const TColor WHITE;
static const TColor GRAY;
Expand All @@ -1953,11 +1947,9 @@ struct TColor {
inline TColor(const Pxl& col, TYPE _a=ColorType<TYPE>::ONE) : r(col.r), g(col.g), b(col.b), a(_a) {}
#if _COLORMODE == _COLORMODE_BGR
inline TColor(const Pnt& col, TYPE _a=ColorType<TYPE>::ONE) : b(col.x), g(col.y), r(col.z), a(_a) {}
inline TColor(const Vec& col, TYPE _a=ColorType<TYPE>::ONE) : b(col[0]), g(col[1]), r(col[2]), a(_a) {}
#endif
#if _COLORMODE == _COLORMODE_RGB
inline TColor(const Pnt& col, TYPE _a=ColorType<TYPE>::ONE) : r(col.x), g(col.y), b(col.z), a(_a) {}
inline TColor(const Vec& col, TYPE _a=ColorType<TYPE>::ONE) : r(col[0]), g(col[1]), b(col[2]), a(_a) {}
#endif
inline TColor(uint32_t col) : r((col>>16)&0xFF), g((col>>8)&0xFF), b(col&0xFF), a((col>>24)&0xFF) {}
// set/get from default type
Expand All @@ -1979,9 +1971,6 @@ struct TColor {
// access as point equivalent
inline operator const Pnt& () const { return *((const Pnt*)this); }
inline operator Pnt& () { return *((Pnt*)this); }
// access as vector equivalent
inline operator const Vec& () const { return *((const Vec*)this); }
inline operator Vec& () { return *((Vec*)this); }
// access as cv::Scalar equivalent
inline operator cv::Scalar () const { return cv::Scalar(c[0], c[1], c[2], c[3]); }
// compare
Expand Down
1 change: 1 addition & 0 deletions libs/IO/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#endif
#include "EXIF.h"
#include "PLY.h"
#include "OBJ.h"
#include "TinyXML2.h"
/*----------------------------------------------------------------*/

Expand Down
Loading

0 comments on commit c121ffc

Please sign in to comment.