Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: macOS build

on:
push:
branches: [ "master", "develop" ]
pull_request:
branches: [ "master", "develop" ]

permissions:
contents: read

jobs:
build-and-test:
name: Apple Silicon with OpenVDB
runs-on: macos-26

steps:
- uses: actions/checkout@v4

- name: Verify runner architecture
run: |
test "$(uname -m)" = "arm64"
clang++ --version

- name: Install dependencies
run: brew install cmake tclap boost openvdb tbb pkgconf cppunit eigen xz zstd c-blosc

# Keep these commands aligned with the macOS reproduction in issue #14.
- name: Configure CMake with OpenVDB
run: |
mkdir build
cd build
cmake -DMOD_OPENVDB=1 ../src

- name: Build
working-directory: build
run: make -j5

- name: Run unit tests
working-directory: build
run: ctest --output-on-failure
33 changes: 30 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#*************************************************************************/

cmake_minimum_required(VERSION 3.16)
project(den2obj VERSION 1.3.0 LANGUAGES CXX)
project(den2obj VERSION 1.3.1 LANGUAGES CXX)

option(USE_GCOV "Build with gcov coverage instrumentation" OFF)
option(MOD_OPENVDB "Enable OpenVDB support" OFF)
Expand Down Expand Up @@ -65,8 +65,35 @@ endif()

set(OPENVDB_LIBS "")
if(MOD_OPENVDB)
set(OPENVDB_LIBS openvdb tbb PkgConfig::BLOSC ZLIB::ZLIB)
message(STATUS "Compiling with OpenVDB module")
# OpenVDB currently installs a Find-module rather than a Config package.
# Locate that module relative to its headers so this works with Homebrew's
# /opt/homebrew prefix as well as Linux multiarch installations.
find_package(OpenVDB CONFIG QUIET)
if(NOT TARGET OpenVDB::openvdb)
find_path(OpenVDB_INCLUDE_DIR NAMES openvdb/openvdb.h)
if(NOT OpenVDB_INCLUDE_DIR)
message(FATAL_ERROR "Could not locate the OpenVDB headers")
endif()

get_filename_component(_OPENVDB_INSTALL_PREFIX "${OpenVDB_INCLUDE_DIR}" DIRECTORY)
find_path(OpenVDB_CMAKE_MODULE_DIR
NAMES FindOpenVDB.cmake
HINTS "${_OPENVDB_INSTALL_PREFIX}" ${CMAKE_PREFIX_PATH}
PATH_SUFFIXES
lib/cmake/OpenVDB
"lib/${CMAKE_LIBRARY_ARCHITECTURE}/cmake/OpenVDB"
share/cmake/OpenVDB
)
if(NOT OpenVDB_CMAKE_MODULE_DIR)
message(FATAL_ERROR "Could not locate OpenVDB's FindOpenVDB.cmake module")
endif()

list(PREPEND CMAKE_MODULE_PATH "${OpenVDB_CMAKE_MODULE_DIR}")
find_package(OpenVDB REQUIRED)
endif()

set(OPENVDB_LIBS OpenVDB::openvdb)
message(STATUS "Compiling with OpenVDB module: ${OpenVDB_VERSION}")
endif()

file(GLOB SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
Expand Down
2 changes: 1 addition & 1 deletion src/d2o_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>

#include "math.h"
#include "den2obj_math.h"

namespace D2OFormat {

Expand Down
6 changes: 3 additions & 3 deletions src/math.h → src/den2obj_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* *
**************************************************************************/

#ifndef _MATRICES_H
#define _MATRICES_H
#ifndef DEN2OBJ_MATH_H
#define DEN2OBJ_MATH_H

#include <Eigen/Dense>

Expand All @@ -33,4 +33,4 @@ template <typename T> T sgn(T val) {
return (T(0) < val) - (val < T(0));
}

#endif // _MATRICES_H
#endif // DEN2OBJ_MATH_H
2 changes: 1 addition & 1 deletion src/generator_benzene_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef _GENERATOR_BENZENE_DATA_H
#define _GENERATOR_BENZENE_DATA_H

#include "math.h"
#include "den2obj_math.h"

namespace GeneratorData {

Expand Down
2 changes: 1 addition & 1 deletion src/generator_sto3g_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef _GENERATOR_STO3G_DATA_H
#define _GENERATOR_STO3G_DATA_H

#include "math.h"
#include "den2obj_math.h"

namespace GeneratorData {

Expand Down
2 changes: 1 addition & 1 deletion src/isosurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "edgetable.h"
#include "triangletable.h"
#include "scalar_field.h"
#include "math.h"
#include "den2obj_math.h"

#define PRECISION_LIMIT 0.000000001

Expand Down
38 changes: 32 additions & 6 deletions src/isosurface_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@

#include "isosurface_mesh.h"

#ifdef _OPENMP
#include <omp.h>
#endif

namespace {

size_t get_max_thread_count() {
#ifdef _OPENMP
return static_cast<size_t>(omp_get_max_threads());
#else
return 1;
#endif
}

size_t get_thread_number() {
#ifdef _OPENMP
return static_cast<size_t>(omp_get_thread_num());
#else
return 0;
#endif
}

} // namespace

/**
* @brief build isosurface mesh object
*
Expand Down Expand Up @@ -176,14 +200,16 @@ void IsoSurfaceMesh::write_obj(const std::string& filename, const std::string& h
outfile << "o " << name << std::endl;

// calculate number of threads
size_t nrthreads = omp_get_max_threads();
omp_set_num_threads(nrthreads); // always allocate max threads
std::stringstream local[nrthreads];
const size_t nrthreads = get_max_thread_count();
#ifdef _OPENMP
omp_set_num_threads(static_cast<int>(nrthreads)); // always allocate max threads
#endif
std::vector<std::stringstream> local(nrthreads);

// parallel writing vertices
#pragma omp parallel
{
size_t threadnum = omp_get_thread_num();
const size_t threadnum = get_thread_number();

// calculate size
size_t rem = this->vertices.size() % nrthreads;
Expand Down Expand Up @@ -215,7 +241,7 @@ void IsoSurfaceMesh::write_obj(const std::string& filename, const std::string& h

#pragma omp parallel
{
size_t threadnum = omp_get_thread_num();
const size_t threadnum = get_thread_number();

// calculate size
size_t rem = this->normals.size() % nrthreads;
Expand Down Expand Up @@ -249,7 +275,7 @@ void IsoSurfaceMesh::write_obj(const std::string& filename, const std::string& h

#pragma omp parallel
{
size_t threadnum = omp_get_thread_num();
const size_t threadnum = get_thread_number();

// calculate size
size_t rem = (this->indices.size() / 3) % nrthreads;
Expand Down
3 changes: 1 addition & 2 deletions src/isosurface_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
#include <fstream>
#include <set>
#include <vector>
#include <omp.h>
#include <boost/filesystem.hpp>

#include "math.h"
#include "den2obj_math.h"
#include "isosurface.h"
#include "check_endian.h"

Expand Down
2 changes: 1 addition & 1 deletion src/scalar_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <boost/iostreams/filter/lzma.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>

#include "math.h"
#include "den2obj_math.h"
#include "float_parser.h"
#include "periodic_table.h"
#include "d2o_format.h"
Expand Down
1 change: 1 addition & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
pkg_check_modules(CPPUNIT REQUIRED IMPORTED_TARGET cppunit)
add_library(unittest STATIC unittest.cpp)
target_compile_features(unittest PUBLIC cxx_std_17)
target_link_libraries(unittest PRIVATE PkgConfig::CPPUNIT)

set(EXECUTABLES TestIsosurface TestScalarField TestD2OFileFormat TestGenerator)

Expand Down
6 changes: 6 additions & 0 deletions src/test/test_file_creation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

#include "test_file_creation.h"

#ifdef _OPENMP
#include <omp.h>
#endif

CPPUNIT_TEST_SUITE_REGISTRATION( TestFileCreation );

void TestFileCreation::setUp() {
Expand All @@ -44,8 +48,10 @@ void TestFileCreation::test_obj_file() {
}

TestFileCreation::MeshReference TestFileCreation::generate_mesh() const {
#ifdef _OPENMP
// set number of threads to 1
omp_set_num_threads(1);
#endif

// read scalar field
ScalarField sf("co_2pi_x.cub", ScalarFieldInputFileType::SFF_CUB);
Expand Down
Loading