Skip to content

Commit

Permalink
Merge pull request #3 from fspindle/feat_disable_miniz
Browse files Browse the repository at this point in the history
WITH_MINIZ CMake option
  • Loading branch information
fspindle authored Jun 10, 2024
2 parents f95b137 + 7f25066 commit b567f44
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 52 deletions.
21 changes: 12 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -780,17 +780,18 @@ endif()
# ----------------------------------------------------------------------------
# Build-in 3rd parties. Should be after c++ standard potential modification
# ----------------------------------------------------------------------------
VP_OPTION(WITH_PTHREAD "" "" "Build pthread as built-in library" "" ON IF (WIN32 OR MINGW) AND (NOT WINRT))
VP_OPTION(WITH_PTHREAD "" "" "Use pthread as built-in library" "" ON IF (WIN32 OR MINGW) AND (NOT WINRT))
# Since C99 is not supported by MSVC 2010 or prior, we disable apriltag if MSVC < 2012
VP_OPTION(WITH_APRILTAG "" "" "Build AprilTag as built-in library" "" ON IF (USE_THREADS OR USE_PTHREAD OR WITH_PTHREAD) AND (NOT WINRT) AND (NOT MSVC_VERSION LESS 1700))
VP_OPTION(WITH_APRILTAG_BIG_FAMILY "" "" "Build AprilTag big family (41h12, 48h12, 49h12, 52h13)" "" OFF IF WITH_APRILTAG)
VP_OPTION(WITH_ATIDAQ "" "" "Build atidaq-c as built-in library" "" ON IF USE_COMEDI AND NOT WINRT)
VP_OPTION(WITH_CLIPPER "" "" "Build clipper as built-in library" "" ON IF USE_OPENCV)
VP_OPTION(WITH_LAPACK "" "" "Build lapack as built-in library" "" ON IF NOT USE_LAPACK)
VP_OPTION(WITH_QBDEVICE "" "" "Build qbdevice-api as built-in library" "" ON IF (NOT WINRT) AND (NOT IOS))
VP_OPTION(WITH_TAKKTILE2 "" "" "Build Right Hand takktile2 driver as built-in library" "" ON IF (NOT WIN32) AND (NOT WINRT) AND (NOT IOS) AND (NOT ANDROID))
VP_OPTION(WITH_APRILTAG "" "" "Use AprilTag as built-in library" "" ON IF (USE_THREADS OR USE_PTHREAD OR WITH_PTHREAD) AND (NOT WINRT) AND (NOT MSVC_VERSION LESS 1700))
VP_OPTION(WITH_APRILTAG_BIG_FAMILY "" "" "Use AprilTag big family (41h12, 48h12, 49h12, 52h13)" "" OFF IF WITH_APRILTAG)
VP_OPTION(WITH_MINIZ "" "" "Use npz related I/O as built-in functions" "" ON)
VP_OPTION(WITH_ATIDAQ "" "" "Use atidaq-c as built-in library" "" ON IF USE_COMEDI AND NOT WINRT)
VP_OPTION(WITH_CLIPPER "" "" "Use clipper as built-in library" "" ON IF USE_OPENCV)
VP_OPTION(WITH_LAPACK "" "" "Use lapack as built-in library" "" ON IF NOT USE_LAPACK)
VP_OPTION(WITH_QBDEVICE "" "" "Use qbdevice-api as built-in library" "" ON IF (NOT WINRT) AND (NOT IOS))
VP_OPTION(WITH_TAKKTILE2 "" "" "Use Right Hand takktile2 driver as built-in library" "" ON IF (NOT WIN32) AND (NOT WINRT) AND (NOT IOS) AND (NOT ANDROID))
VP_OPTION(WITH_CATCH2 "" "" "Use catch2 built-in library" "" ON)
VP_OPTION(WITH_POLOLU "" "" "Build rapa pololu as built-in library" "" ON IF (NOT WINRT) AND (NOT IOS) AND (NOT ANDROID))
VP_OPTION(WITH_POLOLU "" "" "Use rapa pololu as built-in library" "" ON IF (NOT WINRT) AND (NOT IOS) AND (NOT ANDROID))
VP_OPTION(WITH_PUGIXML "" "" "Use pugixml built-in third-party" "" ON)
VP_OPTION(WITH_SIMDLIB "" "" "Use simdlib built-in third-party" "" ON)
VP_OPTION(WITH_STBIMAGE "" "" "Use std_image built-in third-party" "" ON)
Expand Down Expand Up @@ -1149,6 +1150,7 @@ VP_SET(VISP_HAVE_SIMDLIB TRUE IF (BUILD_MODULE_visp_core AND WITH_SIMDLIB))
VP_SET(VISP_HAVE_STBIMAGE TRUE IF (BUILD_MODULE_visp_core AND WITH_STBIMAGE))
VP_SET(VISP_HAVE_TINYEXR TRUE IF (BUILD_MODULE_visp_core AND WITH_TINYEXR))
VP_SET(VISP_HAVE_PUGIXML TRUE IF (BUILD_MODULE_visp_core AND WITH_PUGIXML))
VP_SET(VISP_HAVE_MINIZ TRUE IF (BUILD_MODULE_visp_core AND WITH_MINIZ))

VP_SET(VISP_HAVE_QUALISYS TRUE IF (BUILD_MODULE_visp_sensor AND USE_QUALISYS))
VP_SET(VISP_HAVE_VICON TRUE IF (BUILD_MODULE_visp_sensor AND USE_VICON))
Expand Down Expand Up @@ -1743,6 +1745,7 @@ status(" Use OpenCV:" USE_OPENCV THEN "yes (ver ${OpenCV_VE
status(" Use stb_image (built-in):" WITH_STBIMAGE THEN "yes (ver ${STBIMAGE_VERSION})" ELSE "no")
status(" Use TinyEXR (built-in):" WITH_TINYEXR THEN "yes (ver ${TINYEXR_VERSION})" ELSE "no")
status(" Use simdlib (built-in):" WITH_SIMDLIB THEN "yes" ELSE "no")
status(" Use npz I/O (built-in):" WITH_MINIZ THEN "yes" ELSE "no")
status("")
status(" Real robots: ")
status(" Use Afma4:" USE_AFMA4 THEN "yes" ELSE "no")
Expand Down
1 change: 1 addition & 0 deletions cmake/templates/VISPConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ set(VISP_HAVE_LIBFREENECT_AND_DEPENDENCIES "@VISP_HAVE_LIBFREENECT_AND_DEPENDENC
set(VISP_HAVE_LIBFREENECT_OLD "@VISP_HAVE_LIBFREENECT_OLD@")
set(VISP_HAVE_LIBUSB_1 "@VISP_HAVE_LIBUSB_1@")
set(VISP_HAVE_MAVSDK "@VISP_HAVE_MAVSDK@")
set(VISP_HAVE_MINIZ "@VISP_HAVE_MINIZ@")
set(VISP_HAVE_MKL "@VISP_HAVE_MKL@")
set(VISP_HAVE_NETLIB "@VISP_HAVE_NETLIB@")
set(VISP_HAVE_NULLPTR "@VISP_HAVE_NULLPTR@")
Expand Down
3 changes: 3 additions & 0 deletions cmake/templates/vpConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ namespace vp = VISP_NAMESPACE_NAME;
// Always define pugixml for compatibility.
#cmakedefine VISP_HAVE_PUGIXML

// Defined if basisu_miniz is used internally
#cmakedefine VISP_HAVE_MINIZ

// Defined if XML2 library available.
#cmakedefine VISP_HAVE_XML2

Expand Down
1 change: 1 addition & 0 deletions doc/config-doxygen.in
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,7 @@ PREDEFINED = @DOXYGEN_SHOULD_SKIP_THIS@ \
VISP_HAVE_LIBFREENECT_AND_DEPENDENCIES \
VISP_HAVE_LIBUSB_1 \
VISP_HAVE_MAVSDK \
VISP_HAVE_MINIZ \
VISP_HAVE_NLOHMANN_JSON \
VISP_HAVE_NULLPTR \
VISP_HAVE_OCCIPITAL_STRUCTURE \
Expand Down
24 changes: 21 additions & 3 deletions example/device/framegrabber/readRealSenseData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
#endif
#endif

#ifdef VISP_HAVE_MINIZ
#define GETOPTARGS "ci:e:jbzodh"
#else
#define GETOPTARGS "ci:e:jbodh"
#endif

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
Expand All @@ -90,7 +94,9 @@ void usage(const char *name, const char *badparam)
<< " [-c]"
<< " [-j]"
<< " [-b]"
#ifdef VISP_HAVE_MINIZ
<< " [-z]"
#endif
<< " [-o]"
<< " [-d]"
<< " [--help,-h]"
Expand All @@ -111,9 +117,11 @@ void usage(const char *name, const char *badparam)
<< " -b" << std::endl
<< " Depth and Pointcloud streams are saved in binary format." << std::endl
<< std::endl
#ifdef VISP_HAVE_MINIZ
<< " -z" << std::endl
<< " Pointcloud stream is saved in NPZ format." << std::endl
<< std::endl
#endif
<< " -o" << std::endl
<< " Save color images in PNG format (lossless) in a new folder." << std::endl
<< std::endl
Expand Down Expand Up @@ -153,9 +161,11 @@ bool getOptions(int argc, const char *argv[], std::string &input_directory, std:
case 'b':
force_binary_format = true;
break;
#ifdef VISP_HAVE_MINIZ
case 'z':
read_npz = true;
break;
#endif
case 'o':
save_video = true;
break;
Expand Down Expand Up @@ -242,6 +252,7 @@ bool readData(int cpt, const std::string &input_directory, const std::string &pa
}
}
}
#ifdef VISP_HAVE_MINIZ
else {
visp::cnpy::npz_t npz_data = visp::cnpy::npz_load(filename_depth);

Expand All @@ -259,6 +270,11 @@ bool readData(int cpt, const std::string &input_directory, const std::string &pa
const bool copyData = true;
I_depth_raw = vpImage<uint16_t>(depth_data_ptr, height, width, copyData);
}
#else
else {
throw(vpIoException(vpIoException::ioError, "Cannot open non-binary depth file when npz I/O functions are disabled."));
}
#endif
}

// Read pointcloud
Expand Down Expand Up @@ -295,6 +311,7 @@ bool readData(int cpt, const std::string &input_directory, const std::string &pa
}
}
}
#ifdef VISP_HAVE_MINIZ
else if (read_npz) {
visp::cnpy::npz_t npz_data = visp::cnpy::npz_load(filename_pointcloud);

Expand Down Expand Up @@ -324,17 +341,18 @@ bool readData(int cpt, const std::string &input_directory, const std::string &pa
}
}
}
#endif
else {
#if defined(VISP_HAVE_PCL_IO)
if (pcl::io::loadPCDFile<pcl::PointXYZ>(filename_pointcloud, *point_cloud) == -1) {
std::cerr << "Cannot read PCD: " << filename_pointcloud << std::endl;
}
}
#else
throw(vpIoException(vpIoException::ioError, "Cannot read pcd file without PCL io module"));
#endif
}
}
#endif
}
}

return true;
}
Expand Down
43 changes: 33 additions & 10 deletions example/device/framegrabber/saveRealSenseData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#endif

#include <visp3/core/vpImageConvert.h>
#include <visp3/core/vpIoException.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpXmlParserCamera.h>
#include <visp3/gui/vpDisplayGDI.h>
Expand All @@ -74,7 +75,11 @@
#define USE_REALSENSE2
#endif

#ifdef VISP_HAVE_MINIZ
#define GETOPTARGS "se:o:acdpzijCf:bvh"
#else
#define GETOPTARGS "se:o:acdpijCf:bvh"
#endif

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
Expand All @@ -93,7 +98,9 @@ void usage(const char *name, const char *badparam, int fps)
<< " [-d]"
<< " [-p]"
<< " [-b]"
#ifdef VISP_HAVE_MINIZ
<< " [-z]"
#endif
<< " [-i]"
<< " [-j]"
<< " [-C]"
Expand Down Expand Up @@ -127,9 +134,11 @@ void usage(const char *name, const char *badparam, int fps)
<< " -b" << std::endl
<< " Force depth and pointcloud to be saved in (little-endian) binary format." << std::endl
<< std::endl
#ifdef VISP_HAVE_MINIZ
<< " -z" << std::endl
<< " Pointcloud is saved in NPZ format." << std::endl
<< std::endl
#endif
<< " -i" << std::endl
<< " Add infrared stream to saved data when -s option is enabled." << std::endl
<< std::endl
Expand Down Expand Up @@ -212,9 +221,11 @@ bool getOptions(int argc, const char *argv[], bool &save, std::string &pattern,
case 'v':
depth_hist_visu = true;
break;
#ifdef VISP_HAVE_MINIZ
case 'z':
save_pcl_npz_format = true;
break;
#endif
case 'b':
save_force_binary_format = true;
break;
Expand Down Expand Up @@ -364,7 +375,7 @@ class vpFrameQueue
ptr_infraredImg = std::make_unique<vpImage<unsigned char>>(m_queueInfrared.front());
m_queueInfrared.pop();
}
}
}

bool empty()
{
Expand All @@ -387,7 +398,7 @@ class vpFrameQueue
std::queue<vpImage<unsigned char>> m_queueInfrared;
size_t m_maxQueueSize;
std::mutex m_mutex;
};
};

class vpStorageWorker
{
Expand Down Expand Up @@ -469,6 +480,7 @@ class vpStorageWorker
}
}
}
#ifdef VISP_HAVE_MINIZ
else {
ss << m_directory << "/depth_image_" << m_save_pattern << ".npz";
snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
Expand Down Expand Up @@ -496,6 +508,11 @@ class vpStorageWorker
std::vector<uint16_t> I_depth_raw_vec(ptr_depthImg->bitmap, ptr_depthImg->bitmap + ptr_depthImg->getSize());
visp::cnpy::npz_save(filename_depth, "data", I_depth_raw_vec.data(), { height, width }, "a");
}
#else
else {
throw(vpIoException(vpIoException::ioError, "Cannot manage non-binary files when npz I/O functions are disabled."));
}
#endif
}

if (m_save_pointcloud && ptr_pointCloud) {
Expand Down Expand Up @@ -557,7 +574,8 @@ class vpStorageWorker
}
}
else if (m_save_pcl_npz_format) {
// Write Npz headers
#ifdef VISP_HAVE_MINIZ
// Write Npz headers
std::vector<char> vec_filename(filename_point_cloud.begin(), filename_point_cloud.end());
// Null-terminated character is handled at reading
// For null-terminated character handling, see:
Expand Down Expand Up @@ -596,6 +614,9 @@ class vpStorageWorker
#endif
// Write data
visp::cnpy::npz_save(filename_point_cloud, "data", vec_pcl.data(), { height, width, channels }, "a");
#else
throw(vpIoException(vpIoException::fatalError, "Cannot save in npz format when npz I/O functions are disabled."));
#endif
}
else {
#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_IO) && defined(VISP_HAVE_PCL_COMMON)
Expand Down Expand Up @@ -684,7 +705,9 @@ int main(int argc, const char *argv[])
std::cout << "save_jpeg: " << save_jpeg << std::endl;
std::cout << "stream_fps: " << stream_fps << std::endl;
std::cout << "depth_hist_visu: " << depth_hist_visu << std::endl;
#ifdef VISP_HAVE_MINIZ
std::cout << "save_pcl_npz_format: " << save_pcl_npz_format << std::endl;
#endif
std::cout << "save_force_binary_format: " << save_force_binary_format << std::endl;
std::cout << "click_to_save: " << click_to_save << std::endl;

Expand Down Expand Up @@ -912,10 +935,10 @@ int main(int argc, const char *argv[])
#else
if (save_pointcloud) {
ptr_pointCloud = std::make_unique<std::vector<vpColVector>>(pointCloud);
}
}
save_queue.push(ptr_colorImg, ptr_depthImg, ptr_pointCloud, ptr_infraredImg);
#endif
}
}

double delta_time = vpTime::measureTimeMs() - start;
vec_delta_time.push_back(delta_time);
Expand Down Expand Up @@ -959,10 +982,10 @@ int main(int argc, const char *argv[])
#else
if (save_pointcloud) {
ptr_pointCloud = std::make_unique<std::vector<vpColVector>>(pointCloud);
}
}
save_queue.push(ptr_colorImg, ptr_depthImg, ptr_pointCloud, ptr_infraredImg);
#endif
}
}
break;

case vpMouseButton::button2:
Expand All @@ -972,10 +995,10 @@ int main(int argc, const char *argv[])
quit = true;
save_queue.cancel();
break;
}
}
}
}
}
}

double mean_vec_delta_time = vpMath::getMean(vec_delta_time);
double median_vec_delta_time = vpMath::getMedian(vec_delta_time);
Expand All @@ -998,5 +1021,5 @@ int main()
std::cout << "pugixml built-in 3rdparty is requested." << std::endl;
#endif
return EXIT_SUCCESS;
}
}
#endif
6 changes: 4 additions & 2 deletions example/robot-simulator/afma6/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ foreach(cpp ${example_cpp})
endif()

# Add test
get_filename_component(target ${cpp} NAME_WE)
add_test(${target} ${target} -c ${OPTION_TO_DESACTIVE_DISPLAY})
# Workaround for github action issue when using std::mutex by removing the test
# See https://github.com/actions/runner-images/issues/10020
# get_filename_component(target ${cpp} NAME_WE)
# add_test(${target} ${target} -c ${OPTION_TO_DESACTIVE_DISPLAY})
endforeach()
6 changes: 4 additions & 2 deletions example/robot-simulator/viper850/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ foreach(cpp ${example_cpp})
endif()

# Add test
get_filename_component(target ${cpp} NAME_WE)
add_test(${target} ${target} -c ${OPTION_TO_DESACTIVE_DISPLAY})
# Workaround for github action issue when using std::mutex by removing the test
# See https://github.com/actions/runner-images/issues/10020
# get_filename_component(target ${cpp} NAME_WE)
# add_test(${target} ${target} -c ${OPTION_TO_DESACTIVE_DISPLAY})
endforeach()
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpIoTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static inline unsigned long vp_mz_crc32(unsigned long crc, const unsigned char *
return ~crcu32;
}

#ifdef VISP_HAVE_MINIZ
namespace cnpy
{
// Copyright (C) 2011 Carl Rogers
Expand Down Expand Up @@ -385,6 +386,7 @@ template<typename T> std::vector<char> create_npy_header(const std::vector<size_
}

} // namespace cnpy
#endif
} // namespace VISP_NAMESPACE_NAME
#endif

Expand Down
Loading

0 comments on commit b567f44

Please sign in to comment.