Skip to content

Commit

Permalink
Merge pull request SINTEF-Geometry#366 from sbriseid/gotools_logging_…
Browse files Browse the repository at this point in the history
…spdlog

Gotools logging spdlog
  • Loading branch information
sbriseid authored Sep 24, 2024
2 parents 5345dd5 + 8d59427 commit 93a7678
Show file tree
Hide file tree
Showing 14 changed files with 794 additions and 431 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ IF(GoTools_ENABLE_OPENMP)
FIND_PACKAGE(OpenMP REQUIRED)
ENDIF()

# Logger. If not enabled then all output is written to the console.
OPTION(GoTools_ENABLE_LOGGER "Enable logger?" OFF)
if (GoTools_ENABLE_LOGGER)
add_definitions(-DGOTOOLS_LOG)
add_compile_definitions(GOTOOLS_LOG)
endif()

# CloudFlow specific logger.
OPTION(GoTools_ENABLE_CLOUDFLOW_LOGGER "Enable CloudFlow logger?" OFF)
if (GoTools_CLOUDFLOW_ENABLE_LOGGER)
add_definitions(-DGOTOOLS_CLOUDFLOW_LOG)
endif()

# Generate header with version info
Expand Down
9 changes: 9 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ OpenGL:
- If cmake does not find the gl.h and glu.h files they may be copied to the '~/Install/include/GL'
folder. If you are using Visual Studio and selected the C++ workload option in the installer then
the files should be located in a subfolder of "C:/Program Files (x86)/Windows Kits".

- For computers without working OpenGL drivers (typically the case for virtual machines) MESA may be
used (software rendering). In the folder with the application there is a library named
'opengl32sw.dll'. This library should be copied and renamed to 'opengl32.dll', which will then be
Expand All @@ -143,6 +144,14 @@ FreeGLUT:
- The include and library files should be placed in locations in the same manner as for PugiXML &
JsonCpp.

spdlog:
- Enabling logging requires spdlog. Off by default. When disabled all the log messages are written
to cerr.
- spdlog may be downloaded and built using Visual Studio:
https://github.com/gabime/spdlog
- The include and library files should be placed in locations in the same manner as for PugiXML &
JsonCpp.

CMake:
- In order to run the testst you should add $CMAKE_DIR/bin to the PATH, allowing ctest.exe to be
found.
Expand Down
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Dependencies:

Optional dependencies (disabled by default):
* OpenMP
* spdlog (required if enabling logging)

A few comments on the current distribution:
(1) You can generate doxygen information by typing 'doxygen' in the base directory.
Expand Down
10 changes: 10 additions & 0 deletions compositemodel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ SET(DEPLIBS
# )
# endif()

if (GoTools_ENABLE_LOGGER)
find_package(spdlog REQUIRED)
INCLUDE_DIRECTORIES(${spdlog_INCLUDE_DIR}) # Include spdlog directories
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(DEPLIBS ${DEPLIBS} ${SPDLOG_LIBRARIES} fmt)
ENDIF()
else()
message("Not defining GOTOOLS_LOG")
endif()

# MESSAGE("PUGIXML_LIBRARIES: ${PUGIXML_LIBRARIES}")
# MESSAGE("DEPLIBS: ${DEPLIBS}")

Expand Down
69 changes: 69 additions & 0 deletions compositemodel/cmake/Modules/Findspdlog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
########################################################################
# CMake module for finding spdlog
#
# The following variables will be defined:
#
# spdlog_FOUND
# spdlog_INCLUDE_DIR
# spdlog_LIBRARIES
#

find_path(spdlog_INCLUDE_DIR "spdlog/spdlog.h"
# PATHS "~/Install/spdlog/include"
PATHS "~/Install/include"
"C:/local/include"
"/usr/include/spdlog"
)

if(WIN32)
if(${MSVC_VERSION} EQUAL 1900)
set(MSVC_NAME "msvc2015_")
# MESSAGE("Visual Studio 2015!")
elseif((${MSVC_VERSION} GREATER_EQUAL 1920) AND (${MSVC_VERSION} LESS 1930))
# MESSAGE("Visual Studio 2019!")
set(MSVC_NAME "msvc2019_")
elseif((${MSVC_VERSION} GREATER_EQUAL 1930) AND (${MSVC_VERSION} LESS 1950))
set(MSVC_NAME "msvc2022_")
else()
message("MSVC version not supported or not installed!")
endif()
if(CMAKE_CL_64)
set(WIN_LIB_TYPE "64")
# message("The project is set to 64 bits!")
else()
set(WIN_LIB_TYPE "32")
# message("The project is set to 32 bits!")
endif()
endif()

find_library(spdlog_LIBRARY_DEBUG
NAMES spdlogd
PATHS "~/Install/${MSVC_NAME}lib${WIN_LIB_TYPE}/Debug"
"C:/local/${MSVC_NAME}lib${WIN_LIB_TYPE}/Debug"
)
#message("spdlog_LIBRARY_DEBUG: " ${spdlog_LIBRARY_DEBUG})

find_library(spdlog_LIBRARY_RELEASE
NAMES spdlog
PATHS "~/Install/${MSVC_NAME}lib${WIN_LIB_TYPE}/Release"
"C:/local/${MSVC_NAME}lib${WIN_LIB_TYPE}/Release"
)
#message("spdlog_LIBRARY_RELEASE: " ${spdlog_LIBRARY_RELEASE})

find_library(spdlog_LIBRARY
NAMES spdlog
PATHS "~/Install/${MSVC_NAME}lib${WIN_LIB_TYPE}/Release"
"C:/local/${MSVC_NAME}lib${WIN_LIB_TYPE}/Release"
)
#message("spdlog_LIBRARY: " ${spdlog_LIBRARY})

if(spdlog_LIBRARY_DEBUG)
set(spdlog_LIBRARIES ${spdlog_LIBRARIES} debug ${spdlog_LIBRARY_DEBUG})
endif()
if(spdlog_LIBRARY_RELEASE)
set(spdlog_LIBRARIES ${spdlog_LIBRARIES} optimized ${spdlog_LIBRARY_RELEASE})
endif()
if(spdlog_LIBRARY)
set(spdlog_LIBRARIES ${spdlog_LIBRARIES} ${spdlog_LIBRARY})
endif()
#message("spdlog_LIBRARIES: " ${spdlog_LIBRARIES})
49 changes: 25 additions & 24 deletions compositemodel/src/CompositeModelFileHandler.C
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/

#include "GoTools/compositemodel/CompositeModelFileHandler.h"
#include "GoTools/utils/Logger.h"
#include "GoTools/geometry/BoundedSurface.h"
#include "GoTools/geometry/Cylinder.h"
#include "GoTools/geometry/Plane.h"
Expand Down Expand Up @@ -101,7 +102,7 @@ void CompositeModelFileHandler::writeHeader(const std::string& file_content_info
// @@sbr201601 It makes sense to require all ID's to be unique.
// But this conflicts with ID's stored in topological objects handled in a
// write function separate from the geometries.
//MESSAGE("Consider clearing list of used ID's!");
LOG_WARN("Consider clearing list of used ID's!");
}


Expand Down Expand Up @@ -335,7 +336,7 @@ void CompositeModelFileHandler::writeFaces(std::ostream& os)
}
if (iter_face == faces_.end())
{
MESSAGE("Failed finding twin face!");
LOG_WARN("Failed finding twin face!");
}
else
{
Expand Down Expand Up @@ -410,7 +411,7 @@ void CompositeModelFileHandler::writeFaces(std::ostream& os)
}
if (iter_edge == edges_.end())
{
MESSAGE("Failed finding twin edge!");
LOG_WARN("Failed finding twin edge!");
}
else
{
Expand All @@ -431,10 +432,10 @@ void CompositeModelFileHandler::writeFaces(std::ostream& os)
space_cv->writeStandardHeader(fileout_no_twin);
space_cv->write(fileout_no_twin);
} else {
std::cout << "The ft_edge is missing the space curve!" << std::endl;
LOG_DEBUG("The ft_edge is missing the space curve!");
}
} else {
std::cout << "Not a CurveOnSurface, did not see that one coming!" << std::endl;
LOG_WARN("Not a CurveOnSurface, did not see that one coming!");
}
#endif
// std::cout << "Edge id " << edge_id << " has no twin. Is surf model not a closed shell?" << std::endl;
Expand All @@ -447,12 +448,12 @@ void CompositeModelFileHandler::writeFaces(std::ostream& os)

if (edge->face() == NULL)
{
std::cout << "Edge with id " << edge_id << " is missing it's face pointer!" << std::endl;
LOG_DEBUG("Edge with id " + std::to_string(edge_id) + " is missing its face pointer!");
}

bool orientation_ok = edge->orientationOK();
if (!orientation_ok) {
MESSAGE("Orientation is not OK!");
LOG_INFO("Orientation is not OK!");
}
int par_curve_id = -1;
int space_curve_id = -1;
Expand Down Expand Up @@ -495,7 +496,7 @@ void CompositeModelFileHandler::writeFaces(std::ostream& os)

if (vertex_start_id == vertex_end_id)
{
MESSAGE("Id of start and end vertex are identical, check that this is correct!");
LOG_INFO("Id of start and end vertex are identical, check that this is correct!");
}
shared_ptr<ParamCurve> geom_cv = edge->geomCurve();
shared_ptr<ParamCurve> par_cv, space_cv;
Expand Down Expand Up @@ -610,7 +611,7 @@ void CompositeModelFileHandler::writeFaces(std::ostream& os)
os << indent_ << "</Edge>\n";
}
#ifndef NDEBUG
std::cout << "Write: Number of edges without a twin: " << num_missing_twin << std::endl;
LOG_DEBUG("Write: Number of edges without a twin: " + std::to_string(num_missing_twin));

#if 0
std::string log_message_str("writeSurfaceModel: # edges: " + std::to_string(edges_.size()) +
Expand Down Expand Up @@ -663,7 +664,7 @@ vector<shared_ptr<GeomObject> > CompositeModelFileHandler::readGeomObj(const cha
pugi::xml_document xml_doc;
pugi::xml_parse_result result = xml_doc.load_file(filein);
#ifndef NDEBUG
std::cout << "Load result fetchGeomObj: " << result.description() << "." << std::endl;
LOG_DEBUG("Load result fetchGeomObj: " + std::string(result.description()) + ".");
#endif

Go::ObjectHeader obj_header;
Expand Down Expand Up @@ -718,7 +719,7 @@ SurfaceModel CompositeModelFileHandler::readSurfModel(const char* filein, int id
pugi::xml_document xml_doc;
pugi::xml_parse_result result = xml_doc.load_file(filein);
#ifndef NDEBUG
std::cout << "Load result fetchGeomObj: " << result.description() << "." << std::endl;
LOG_DEBUG("Load result fetchGeomObj: " + std::string(result.description()) + ".");
#endif

// If not previously done, read all faces and store them
Expand Down Expand Up @@ -754,7 +755,7 @@ vector<shared_ptr<SurfaceModel> > CompositeModelFileHandler::readSurfModels(cons
pugi::xml_document xml_doc;
pugi::xml_parse_result result = xml_doc.load_file(g22_filein);
#ifndef NDEBUG
std::cout << "Load result fetchGeomObj: " << result.description() << "." << std::endl;
LOG_DEBUG("Load result fetchGeomObj: " + std::string(result.description()) + ".");
#endif

// If not previously done, read all faces and store them
Expand Down Expand Up @@ -784,7 +785,7 @@ vector<shared_ptr<SurfaceModel> > CompositeModelFileHandler::readSurfModels(cons
pugi::xml_document xml_doc;
pugi::xml_parse_result result = xml_doc.load_file(filein);
#ifndef NDEBUG
std::cout << "Load result fetchGeomObj: " << result.description() << "." << std::endl;
LOG_DEBUG("Load result fetchGeomObj: " + std::string(result.description()) + ".");
#endif

// If not previously done, read all faces and store them
Expand Down Expand Up @@ -866,7 +867,7 @@ vector<shared_ptr<SurfaceModel> > CompositeModelFileHandler::readSurfModels(cons
pugi::xml_document xml_doc;
pugi::xml_parse_result result = xml_doc.load_file(filein);
#ifndef NDEBUG
std::cout << "Load result fetchGeomObj: " << result.description() << "." << std::endl;
LOG_DEBUG("Load result fetchGeomObj: " + std::string(result.description()) + ".");
#endif

// If not previously done, read all faces and store them
Expand Down Expand Up @@ -948,7 +949,7 @@ void CompositeModelFileHandler::readFaces(const char* filein)
shared_ptr<GeomObject> geom_obj = createGeomObject(obj_header);
if (geom_obj.get() == NULL)
{
std::cout << "readFaces(): Not yet supporting objects of type: " << obj_header.classType() << std::endl;
LOG_DEBUG("readFaces(): Not yet supporting objects of type: " + std::to_string(obj_header.classType()));
continue;
}

Expand Down Expand Up @@ -1148,14 +1149,14 @@ void CompositeModelFileHandler::readFaces(const char* filein)
shared_ptr<ParamCurve> cv = (cv_on_sf.get() != nullptr) ? cv_on_sf : space_cv;
if (cv.get() == nullptr)
{
cout << "DEBUG: Missing space curve, par curve misses the surface!" << endl;
LOG_WARN("Missing space curve, par curve misses the surface!");
}
assert(cv.get() != nullptr);

shared_ptr<ftEdge> edge(new ftEdge(cv, v1, v2, reversed));
bool orientation_ok = edge->orientationOK();
if (!orientation_ok) {
MESSAGE("Orientation is not OK!");
LOG_INFO("Orientation is not OK!");
}

twin_ids.push_back(std::make_pair(edge_id, twin_id));
Expand All @@ -1174,7 +1175,7 @@ void CompositeModelFileHandler::readFaces(const char* filein)
}

#ifndef NDEBUG
std::cout << "Read: Number of edges without a twin: " << num_missing_twin << std::endl;
LOG_DEBUG("Read: Number of edges without a twin: " + std::to_string(num_missing_twin));
#endif

// We connect the twins.
Expand Down Expand Up @@ -1386,20 +1387,20 @@ void CompositeModelFileHandler::readFaces(const char* filein)
}

#ifndef NDEBUG
std::cout << "\nnum_faces: " << num_faces << ", num_loops: " << num_loops <<
", num_edges: " << num_edges << ", num_nodes: " << num_nodes << std::endl;
LOG_DEBUG("\nnum_faces: " + std::to_string(num_faces) + ", num_loops: " + std::to_string(num_loops) +
", num_edges: " + std::to_string(num_edges) + ", num_nodes: " + std::to_string(num_nodes));

// We run through all edges and see if any is missing a face.
std::cout << "Checking edge face existence for " << edges2_.size() << " edges." << std::endl;
LOG_DEBUG("Checking edge face existence for " + std::to_string(edges2_.size()) + " edges.");
for (auto iter = edges2_.begin(); iter != edges2_.end(); ++iter)
{
if (iter->second->face() == NULL)
{
int edge_id = iter->first;
std::cout << "Edge with id " << edge_id << " is missing it's face!" << std::endl;
LOG_DEBUG("Edge with id " + std::to_string(edge_id) + " is missing it's face!");
}
}
std::cout << "Done checking edge face existence." << std::endl;
LOG_DEBUG("Done checking edge face existence.");
#endif

// We connect the face twins.
Expand Down Expand Up @@ -1483,7 +1484,7 @@ void CompositeModelFileHandler::readFaces(const char* filein)
}
else
{
std::cout << "createGeomObject(): Not yet supporting objects of type: " << obj_header.classType() << std::endl;
LOG_WARN("createGeomObject(): Not yet supporting objects of type: " + std::to_string(obj_header.classType()));
}

return geom_obj;
Expand Down
Loading

0 comments on commit 93a7678

Please sign in to comment.