Skip to content

Commit

Permalink
add flag to disable event logging to console; update tutorials and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chitalu committed Oct 6, 2023
1 parent 4399ba6 commit 6dd6c36
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 30 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# MCUT_BUILD_TESTS [default=OFF] - Build the tests (implicit dependancy on GoogleTest)
# MCUT_BUILD_TUTORIALS [default=OFF] - Build tutorials
# MCUT_BUILD_WITH_COMPUTE_HELPER_THREADPOOL [default=ON] - Build as configurable multi-threaded library
# MCUT_BUILD_WITH_API_EVENT_LOGGING [default=OFF] - Build with logging functionality which dumps event creation and destruction notices to the console
#
# This script will define the following CMake cache variables:
#
Expand Down Expand Up @@ -117,6 +118,8 @@ option(MCUT_BUILD_WITH_COMPUTE_HELPER_THREADPOOL "Configure to build MCUT engine
if (MCUT_TOPLEVEL_PROJECT AND NOT MCUT_BUILD_TUTORIALS)
option(MCUT_BUILD_TUTORIALS "Configure to build MCUT tutorials" ON)
endif()
option(MCUT_BUILD_WITH_API_EVENT_LOGGING "Configure to build MCUT with event logging to console" OFF)

#
# machine-precision-numbers library targets
#
Expand All @@ -143,6 +146,11 @@ if (MCUT_BUILD_WITH_COMPUTE_HELPER_THREADPOOL)
list(APPEND preprocessor_defs -DMCUT_WITH_COMPUTE_HELPER_THREADPOOL=1)
endif()

if (MCUT_BUILD_WITH_API_EVENT_LOGGING)
list(APPEND preprocessor_defs -DMCUT_WITH_API_EVENT_LOGGING=1)
endif()


if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
list(APPEND compilation_flags -Wall -Wextra)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
Expand Down
2 changes: 2 additions & 0 deletions include/mcut/internal/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ class mini_timer {
~mini_timer()
{
if (m_valid) {
#ifdef MCUT_WITH_API_EVENT_LOGGING
const std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
const std::chrono::milliseconds elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_start);
unsigned long long elapsed_ = elapsed.count();
log_msg("[MCUT][PROF:" << std::this_thread::get_id() << "]: \"" << m_name << "\" ("<< elapsed_ << "ms)");
#endif // #ifdef MCUT_WITH_API_EVENT_LOGGING
}
}
void set_invalid()
Expand Down
7 changes: 5 additions & 2 deletions include/mcut/internal/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ pair<T> make_pair(const T a, const T b)
return pair<T>(a, b);
}



#ifdef MCUT_WITH_API_EVENT_LOGGING
// Threadsafe logging to console which prevents std::cerr from mixing strings when
// concatenating with the operator<< multiple time per string, across multiple
// threads.
Expand All @@ -251,6 +250,10 @@ pair<T> make_pair(const T a, const T b)
ss << msg_str << std::endl; \
std::cerr << ss.str() << std::flush; \
}
#else
// no-op
#define log_msg(msg_str)
#endif

// used to marked/label unused function parameters to prevent warnings
#define UNUSED(x) [&x] {}()
Expand Down
4 changes: 2 additions & 2 deletions source/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9475,7 +9475,7 @@ void dispatch(output_t& output, const input_t& input)
m1_polygons_colored.reserve(m1_polygons_colored.size() + cs_face_count);

// reference to the list connected components (see declaration for details)
//std::map<std::size_t, std::vector<std::pair<std::shared_ptr<hmesh_t>, connected_component_info_t>>>& separated_stitching_CCs = color_to_separated_connected_ccsponents[color_id]; // insert
std::map<std::size_t, std::vector<std::pair<std::shared_ptr<hmesh_t>, connected_component_info_t>>>& separated_stitching_CCs = color_to_separated_connected_ccsponents[color_id]; // insert

std::unordered_map<int, int>& m0_to_m1_face_colored = SAFE_ACCESS(color_to_m0_to_m1_face, color_id); // note: containing mappings only for traced source mesh polygons initially!
m0_to_m1_face_colored.reserve(m0_polygons.size());
Expand Down Expand Up @@ -10457,7 +10457,7 @@ void dispatch(output_t& output, const input_t& input)

// save meshes and dump
#if 0
if (input.keep_fragments_sealed_inside_exhaustive || input.keep_fragments_sealed_outside_exhaustive) {
/*if (input.keep_fragments_sealed_inside_exhaustive || input.keep_fragments_sealed_outside_exhaustive)*/ {
///////////////////////////////////////////////////////////////////////////
// create the sealed meshes defined by the [current] set of traced polygons
///////////////////////////////////////////////////////////////////////////
Expand Down
81 changes: 80 additions & 1 deletion tests/source/booleanOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,91 @@ struct BooleanOperation {
std::vector<uint32_t> meshFaceSizes;
};

static void MCAPI_PTR mcDebugOutput_(McDebugSource source,
McDebugType type,
unsigned int id,
McDebugSeverity severity,
size_t length,
const char* message,
const void* userParam)
{

//printf("Debug message ( %d ), length=%zu\n%s\n--\n", id, length, message);
//printf("userParam=%p\n", userParam);

std::string debug_src;
switch (source) {
case MC_DEBUG_SOURCE_API:
debug_src = "API";
break;
case MC_DEBUG_SOURCE_KERNEL:
debug_src = "KERNEL";
break;
case MC_DEBUG_SOURCE_ALL:
break;
}
std::string debug_type;
switch (type) {
case MC_DEBUG_TYPE_ERROR:
debug_type = "ERROR";
break;
case MC_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
debug_type = "DEPRECATION";
break;
case MC_DEBUG_TYPE_OTHER:
//printf("Type: Other");
debug_type = "OTHER";
break;
case MC_DEBUG_TYPE_ALL:
break;

}

std::string severity_str;

switch (severity) {
case MC_DEBUG_SEVERITY_HIGH:
severity_str = "HIGH";
break;
case MC_DEBUG_SEVERITY_MEDIUM:
severity_str = "MEDIUM";
break;
case MC_DEBUG_SEVERITY_LOW:
severity_str = "LOW";
break;
case MC_DEBUG_SEVERITY_NOTIFICATION:
severity_str = "NOTIFICATION";
break;
case MC_DEBUG_SEVERITY_ALL:
break;
}

printf("MCUT[%d:%p,%s:%s:%s:%zu] %s\n", id, userParam, debug_src.c_str(), debug_type.c_str(), severity_str.c_str(), length, message);
}

UTEST_F_SETUP(BooleanOperation)
{
// create with no flags (default)
EXPECT_EQ(mcCreateContext(&utest_fixture->myContext, 0), MC_NO_ERROR);
EXPECT_EQ(mcCreateContext(&utest_fixture->myContext, MC_DEBUG), MC_NO_ERROR);
EXPECT_TRUE(utest_fixture->myContext != nullptr);

// config debug output
// -----------------------
McSize numBytes = 0;
McFlags contextFlags;
EXPECT_EQ(mcGetInfo(utest_fixture->myContext, MC_CONTEXT_FLAGS, 0, nullptr, &numBytes), MC_NO_ERROR);


EXPECT_TRUE(sizeof(McFlags) == numBytes);

EXPECT_EQ(mcGetInfo(utest_fixture->myContext, MC_CONTEXT_FLAGS, numBytes, &contextFlags, nullptr), MC_NO_ERROR);


if (contextFlags & MC_DEBUG) {
EXPECT_EQ(mcDebugMessageCallback(utest_fixture->myContext, mcDebugOutput_, nullptr), MC_NO_ERROR);
EXPECT_EQ(mcDebugMessageControl(utest_fixture->myContext, McDebugSource::MC_DEBUG_SOURCE_ALL, McDebugType::MC_DEBUG_TYPE_ALL, McDebugSeverity::MC_DEBUG_SEVERITY_ALL, true), MC_NO_ERROR);
}

utest_fixture->srcMeshVertices = {
-1.f, -1.f, 1.f, // 0
1.f, -1.f, 1.f, // 1
Expand Down
29 changes: 4 additions & 25 deletions tutorials/QuerySeamVerticesSorted/QuerySeamVerticesSorted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,26 +546,7 @@ void readOBJ(

int main()
{
{
double* pVertices = NULL;
double* pNormals = NULL;
double* pTexcCoords = NULL;
uint32_t* pFaceSizes = NULL;
uint32_t* pFaceVertexIndices = NULL;
uint32_t* pFaceVertexTexCoordIndices;
uint32_t* pFaceVertexNormalIndices;
uint32_t numVertices = 0;
uint32_t numNormals = 0;
uint32_t numTexCoords = 0;
uint32_t numFaces = 0;

readOBJ(DATA_DIR "/brad/cube-quads-normals.obj", &pVertices, &pNormals,
&pTexcCoords, &pFaceSizes, &pFaceVertexIndices, &pFaceVertexTexCoordIndices,
&pFaceVertexNormalIndices, &numVertices, &numNormals,
&numTexCoords, &numFaces);

printf("done!\n");
}

double* srcMeshVertices = NULL;
uint32_t* srcMeshFaceIndices = NULL;
uint32_t* srcMeshFaceSizes = NULL;
Expand All @@ -580,11 +561,9 @@ int main()

McResult api_err = MC_NO_ERROR;

// const char* srcMeshFilePath = DATA_DIR "/source-mesh.off";
// const char* cutMeshFilePath = DATA_DIR "/cut-mesh.off";
const char* srcMeshFilePath = DATA_DIR "/brad/source-mesh.off";
const char* cutMeshFilePath = DATA_DIR "/brad/cut-mesh.off";

const char* srcMeshFilePath = DATA_DIR "/source-mesh.off";
const char* cutMeshFilePath = DATA_DIR "/cut-mesh.off";

printf(">> source-mesh file: %s\n", srcMeshFilePath);
printf(">> cut-mesh file: %s\n", cutMeshFilePath);

Expand Down

0 comments on commit 6dd6c36

Please sign in to comment.