Commit d36952bc authored by Martin Marinov's avatar Martin Marinov Committed by GitHub Enterprise

Add DEB_index_mesh (#13)

* Add functionality to store index mesh in OBJ and OFF formats; Add DEB_index_mesh_out[_if]
* Switch DEB_index_mesh_out to obj format
* Add TEST_if()
parent 836d6d8e
......@@ -4,6 +4,7 @@ set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/DebError.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebFile.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebFileOut.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebIndexMeshOut.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebOut.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebTime.hh
${CMAKE_CURRENT_SOURCE_DIR}/DebUtils.hh
......@@ -15,6 +16,7 @@ set(my_sources
${CMAKE_CURRENT_SOURCE_DIR}/DebCallStack.cc
${CMAKE_CURRENT_SOURCE_DIR}/DebFile.cc
${CMAKE_CURRENT_SOURCE_DIR}/DebFileOut.cc
${CMAKE_CURRENT_SOURCE_DIR}/DebIndexMeshOut.cc
${CMAKE_CURRENT_SOURCE_DIR}/DebStream.cc
PARENT_SCOPE
)
// (C) Copyright 2019 by Autodesk, Inc.
// (C) Copyright 2020 by Autodesk, Inc.
#include "DebFileOut.hh"
#include <string>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <limits>
namespace Debug {
......@@ -34,4 +36,66 @@ std::string set_filename_extension(const char* _flnm, const char* _ext)
return flnm;
}
#define SAVE_MESH(EXT, COORD_TYPE, INDEX_TYPE) \
template void save_mesh_##EXT(const char* const, const size_t, \
const COORD_TYPE* const, const int, const size_t, \
const INDEX_TYPE* const)
template <typename CoordT, typename IndexT>
void save_mesh_obj(const char* const _flnm, const size_t _pnt_nmbr,
const CoordT* const _crds, const int _face_size, const size_t _face_nmbr,
const IndexT* const _indcs)
{
std::ofstream strm(set_filename_extension(_flnm, "obj")); // open
strm.imbue(std::locale("C")); // C-locale
strm << std::setprecision(std::numeric_limits<CoordT>::max_digits10);
for (size_t i = 0, n = 3 * _pnt_nmbr; i < n; i += 3)
{
strm << "v " << _crds[i] << ' ' << _crds[i + 1] << ' ' << _crds[i + 2]
<< std::endl;
}
for (size_t i = 0, n = _face_size * _face_nmbr; i < n;)
{ // stream quads
strm << 'f';
for (int j = 0; j < _face_size; ++j)
strm << ' ' << _indcs[i++] + 1; // OBJ indexing starts at 1
strm << std::endl;
}
}
SAVE_MESH(obj, double, int);
SAVE_MESH(obj, float, int);
SAVE_MESH(obj, double, unsigned int);
SAVE_MESH(obj, float, unsigned int);
template <typename CoordT, typename IndexT>
void save_mesh_off(const char* const _flnm, const size_t _pnt_nmbr,
const CoordT* const _crds, const int _face_size, const size_t _face_nmbr,
const IndexT* const _indcs)
{
std::ofstream strm(set_filename_extension(_flnm, "off")); // open
strm.imbue(std::locale("C")); // C-locale
strm << std::setprecision(std::numeric_limits<CoordT>::max_digits10);
strm << "OFF" << std::endl; // write header
strm << _pnt_nmbr << ' ' << _face_nmbr << std::endl;
for (size_t i = 0, n = 3 * _pnt_nmbr; i < n; i += 3)
strm << _crds[i] << ' ' << _crds[i + 1] << ' ' << _crds[i + 2] << std::endl;
for (size_t i = 0, n = _face_size * _face_nmbr; i < n;)
{ // stream quads
strm << _face_size;
for (int j = 0; j < _face_size; ++j)
strm << ' ' << _indcs[i++];
strm << std::endl;
}
}
SAVE_MESH(off, double, int);
SAVE_MESH(off, float, int);
SAVE_MESH(off, double, unsigned int);
SAVE_MESH(off, float, unsigned int);
} // Debug
// (C) Copyright 2019 by Autodesk, Inc.
// (C) Copyright 2020 by Autodesk, Inc.
#ifndef BASE_DEBFILEOUT_HH_INCLUDED
#define BASE_DEBFILEOUT_HH_INCLUDED
......@@ -7,20 +7,34 @@
#include <string>
#include <Base/Config/BaseDefines.hh>
namespace Debug {
namespace Debug
{
//! Make a file name composing the input arguments:
// prefix_filname_[suffix_]#count#.ext
// #count#_prefix_filename[_suffix].ext
// count is a number that increase any time the function is called,
// it is expressed with 4 decimal digits filled with zeros.
BASEDLLEXPORT
std::string make_filename(const char* _prfx, const char* _flnm,
const char* _ext, const char* _sfx = nullptr);
std::string make_filename(const char* _prfx, const char* _flnm,
const char* _ext, const char* _sfx = nullptr);
//! Replace or add the supplied extension to the filename
BASEDLLEXPORT
std::string set_filename_extension(const char* _flnm, const char* _ext);
} // Debug
//! Save a mesh in obj format, supports int/uint and double/float
template <typename CoordT, typename IndexT>
void save_mesh_obj(const char* const _flnm, const size_t _pnt_nmbr,
const CoordT* const _crds, const int _face_size, const size_t _face_nmbr,
const IndexT* const _indcs);
//! Save a mesh in off format, supports int/uint and double/float
template <typename CoordT, typename IndexT>
void save_mesh_off(const char* const _flnm, const size_t _pnt_nmbr,
const CoordT* const _crds, const int _face_size, const size_t _face_nmbr,
const IndexT* const _indcs);
} // namespace Debug
#endif // DEB_ON
......
// (C) Copyright 2020 by Autodesk, Inc.
#include "Base/Code/Quality.hh"
#include "Base/Security/Mandatory.hh"
#include "DebIndexMeshOut.hh"
#include "DebFileOut.hh"
#ifdef DEB_ON
namespace Debug
{
namespace IndexMeshOut
{
template <typename CoordT, typename IndexT>
bool save(Enter& deb, const char* const _flnm, const size_t _pnt_nmbr,
const CoordT* const _crds, const int _face_size, const size_t _face_nmbr,
const IndexT* const _indcs)
{
const auto mesh_flnm = make_filename("mesh", _flnm, "obj");
try
{
save_mesh_obj(
mesh_flnm.c_str(), _pnt_nmbr, _crds, _face_size, _face_nmbr, _indcs);
DEB_line(0, "Saved mesh as " << mesh_flnm);
return true;
}
catch (...)
{
DEB_warning(0, "Failed to save mesh as " << mesh_flnm);
return false;
}
}
#define SAVE_MESH(COORD_TYPE, INDEX_TYPE) \
template bool save(Enter&, const char* const, const size_t, \
const COORD_TYPE* const, const int, const size_t, \
const INDEX_TYPE* const)
SAVE_MESH(double, int);
SAVE_MESH(float, int);
SAVE_MESH(double, unsigned int);
SAVE_MESH(float, unsigned int);
} // namespace IndexMeshOut
} // namespace Debug
#endif // DEB_ON
// (C) Copyright 2020 by Autodesk, Inc.
#ifndef BASE_DEB_INDEX_MESH_OUT_HH_INCLUDED
#define BASE_DEB_INDEX_MESH_OUT_HH_INCLUDED
#include <Base/Debug/DebOut.hh>
#include <Base/Utils/IOutputStream.hh>
#ifndef DEB_ON
#define DEB_index_mesh_out_if(CC, LL, FF, MM) { PROGRESS_TICK; }
#define DEB_index_mesh_out(LL, FF, MM) { PROGRESS_TICK; }
#else // ifndef DEB_ON
namespace Debug
{
namespace IndexMeshOut
{
template <typename CoordT, typename IndexT>
bool save(Enter& deb, const char* const _flnm, const size_t _pnt_nmbr,
const CoordT* const _crds, const int _face_size, const size_t _face_nmbr,
const IndexT* const _indcs);
template <class PointArrayT, class IndexArrayT>
bool save(Enter& deb, const char* const _flnm, const PointArrayT& _pnts,
const int _face_size, const IndexArrayT& _indcs)
{
return save(deb, _flnm, _pnts.size(), &_pnts[0][0], _face_size,
_indcs.size() / _face_size, _indcs.data());
}
} // namespace IndexMeshOut
} // namespace Debug
#define DEB_index_mesh_out_if(CC, LL, FF, PNTS, FS, INDCS) \
DEB_if(CC, LL, Debug::IndexMeshOut::save(deb, FF, PNTS, FS, INDCS))
#define DEB_index_mesh_out(LL, FF, PNTS, FS, INDCS) \
DEB_index_mesh_out_if(true, LL, FF, PNTS, FS, INDCS)
#endif // ifndef DEB_ON
#endif // BASE_DEB_INDEX_MESH_OUT_HH_INCLUDED
// (C) Copyright 2019 by Autodesk, Inc.
// (C) Copyright 2020 by Autodesk, Inc.
#ifndef BASE_ICHECKSUM_HH_INCLUDE
#define BASE_ICHECKSUM_HH_INCLUDE
......@@ -6,6 +6,7 @@
#ifndef TEST_ON
#define TEST(CHKSM, RCRD)
#define TEST_if(CNDT, CHKSM, RCRD)
#else
......@@ -197,6 +198,7 @@ const Registry& registry();
}//namespace Test
#define TEST(CHKSM, RCRD) { if (CHKSM.allow()) { CHKSM.RCRD; } }
#define TEST_if(CNDT, CHKSM, RCRD) { if (CNDT) TEST(CHKSM, RCRD) }
#endif//TEST_ON
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment