Program Listing for File Debug.hpp

Return to documentation for file (include/lvr2/util/Debug.hpp)

/*
 * Debug.hpp
 *
 * Collection of functions to debug mesh generation.
 *
 * @date 18.07.2017
 * @author Johan M. von Behren <johan@vonbehren.eu>
 */

#ifndef LVR2_UTIL_DEBUG_H_
#define LVR2_UTIL_DEBUG_H_

#include <boost/iostreams/device/null.hpp>
#include <array>
#include <fstream>
#include <vector>

using std::array;
using std::string;
using std::vector;

#include "lvr2/geometry/Handles.hpp"
#include "lvr2/geometry/BaseMesh.hpp"
#include "lvr2/algorithm/ClusterPainter.hpp"
#include "lvr2/algorithm/ColorAlgorithms.hpp"

namespace lvr2
{

inline std::ostream& dout()
{
    // To have a "null" ostream, it's apparently a good idea to use an
    // unopened file, as no one ever checks the error state or sth. Source:
    //
    // https://stackoverflow.com/a/8244052/2408867
    static bool isDebug = getenv("LVR2_MESH_DEBUG") != nullptr;
    static std::ofstream unopenedFile;

    return isDebug ? cout : unopenedFile;
}

template<typename BaseVecT>
void writeDebugMesh(
    const BaseMesh<BaseVecT>& mesh,
    string filename = "debug.ply",
    RGB8Color color = {255, 0, 0}
);

template<typename BaseVecT>
vector<vector<VertexHandle>> getDuplicateVertices(const BaseMesh<BaseVecT>& mesh);

template<typename BaseVecT>
void writeDebugContourMesh(
    const BaseMesh<BaseVecT>& mesh,
    string filename = "debug-contours.ply",
    RGB8Color connectedColor = {0, 255, 0},
    RGB8Color contourColor = {0, 0, 255},
    RGB8Color bugColor = {255, 0, 0}
);

#ifdef NDEBUG
#define DOINDEBUG(...) ;
#else
#define DOINDEBUG(...) __VA_ARGS__
#endif

} // namespace lvr2

#include "lvr2/util/Debug.tcc"

#endif /* LVR2_UTIL_DEBUG_H_ */