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
9 changes: 5 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ jobs:
matrix:
preset: [
{"os": windows-2022, "name": "msbuild"},
{"os": ubuntu-latest, "name": "gnu"}
{"os": ubuntu-latest, "name": "gnu"},
{"os": ubuntu-latest, "name": "gnu-cgal"}
]
build-type: ["Debug", "Release"]
build-type: ["Release"]

fail-fast: false

Expand Down Expand Up @@ -85,7 +86,7 @@ jobs:
run: build/bin/${{matrix.build-type}}/tessellator_tests.exe

- name: Ubuntu configure and build
if: matrix.preset.name=='gnu'
if: matrix.preset.os=='ubuntu-latest'
run: |
configured=0
for attempt in 1 2 3; do
Expand All @@ -99,5 +100,5 @@ jobs:
cmake --build build -j

- name: Ubuntu Run tests
if: matrix.preset.name=='gnu'
if: matrix.preset.os=='ubuntu-latest'
run: build/bin/tessellator_tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ src/*.json

.vs/
.vscode/settings.json
.vscode/settings.dev.json
.vscode/launch.json
.vscode/tasks.json

Expand Down
8 changes: 2 additions & 6 deletions .vscode/settings.dev.json
Comment thread
lmdiazangulo marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
"C_Cpp.intelliSenseEngine": "disabled",
"clangd.arguments": ["-log=verbose",
"-pretty",
"--background-index",
"--background-index",
"--query-driver=/usr/bin/g++"
],
"clangd.fallbackFlags": ["-std=c++17"],
"lldb.showDisassembly": "never",
"lldb.launch.preRunCommands": [
"settings set target.import-std-module true"
]
"clangd.fallbackFlags": ["-std=c++17"]
}
8 changes: 6 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Uses **CMake 3.20+** with presets and vcpkg for dependency management.
cmake --preset gnu -S . -B build
cmake --build build -j

# Optional CGAL algorithms
cmake --preset gnu-cgal
cmake --build --preset gnu-cgal -j

# Windows (MSBuild)
cmake --preset msbuild -S . -B build
cmake --build build --config Release -j
Expand All @@ -72,7 +76,7 @@ cmake --build build --config Release -j
### CMake Options

- `TESSELLATOR_ENABLE_TESTS` (ON by default) – Build test suite
- `TESSELLATOR_ENABLE_CGAL` (ON by default) – Enable CGAL-based geometry operations
- `TESSELLATOR_ENABLE_CGAL` (OFF by default) – Enable CGAL-based geometry operations
- `TESSELLATOR_EXECUTION_POLICIES` (OFF by default) – Parallel execution policies

### Dependencies
Expand All @@ -94,7 +98,7 @@ To set up locally, create a `CMakeUserPreset.json` file:
"VCPKG_ROOT": "~/workspace/vcpkg/"
},
"cacheVariables": {
"TESSELLATOR_ENABLE_CGAL": true
"TESSELLATOR_ENABLE_CGAL": false
},
"inherits": "gnu"
}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS OFF)


option(TESSELLATOR_ENABLE_TESTS "Compile tests" ON)
option(TESSELLATOR_ENABLE_CGAL "Compile using CGAL library" ON)
option(TESSELLATOR_ENABLE_CGAL "Compile using CGAL library" OFF)
option(TESSELLATOR_EXECUTION_POLICIES OFF)
option(DOCKER_EXPORT_COMPILE_COMMANDS "Information for the 'clangd' linter extension" OFF)
option(TESSELLATOR_LOAD_APP "Compile app" OFF)
Expand Down
22 changes: 17 additions & 5 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "FILEPATH",
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
},
"TESSELLATOR_ENABLE_CGAL": true
"TESSELLATOR_ENABLE_CGAL": false
}
},
{
Expand All @@ -26,9 +26,17 @@
{
"name": "gnu",
"displayName": "GNU g++ compiler",
"generator": "Ninja",
"inherits": "default"
},
{
"name": "gnu-cgal",
"displayName": "GNU g++ compiler with CGAL",
"inherits": "gnu",
"binaryDir": "build-cgal/",
"cacheVariables": {
"TESSELLATOR_ENABLE_CGAL": true
}
},
{
"name": "gnu-dbg",
"displayName": "GNU g++ compiler - Debug",
Expand All @@ -49,7 +57,7 @@
"CMAKE_PREFIX_PATH": "/usr/local",
"CMAKE_FIND_ROOT_PATH": "/usr/local",
"TESSELLATOR_ENABLE_TESTS": "ON",
"TESSELLATOR_ENABLE_CGAL": "ON",
"TESSELLATOR_ENABLE_CGAL": "OFF",
"DOCKER_EXPORT_COMPILE_COMMANDS": "ON"
},
"environment": {
Expand All @@ -68,7 +76,7 @@
"CMAKE_PREFIX_PATH": "/usr/local",
"CMAKE_FIND_ROOT_PATH": "/usr/local",
"TESSELLATOR_ENABLE_TESTS": "ON",
"TESSELLATOR_ENABLE_CGAL": "ON",
"TESSELLATOR_ENABLE_CGAL": "OFF",
"DOCKER_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_CXX_FLAGS_INIT": "-g3"
},
Expand All @@ -89,6 +97,10 @@
{
"name": "docker-dbg",
"configurePreset": "docker-dbg"
},
{
"name": "gnu-cgal",
"configurePreset": "gnu-cgal"
}
]
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Tessellator is a mesher focused on generate meshes and data structures which are
## Compilation

When using presets, make sure to define the environment variable `VCPKG_ROOT` to your `vcpkg` installation.
The standard presets build without CGAL; use the `gnu-cgal` preset for the optional CGAL algorithms.
This can be done using a `CMakeUserPreset.json` file, for example:

```json
Expand All @@ -33,7 +34,7 @@ This can be done using a `CMakeUserPreset.json` file, for example:
"VCPKG_ROOT": "~/workspace/vcpkg/"
},
"cacheVariables": {
"TESSELLATOR_ENABLE_CGAL": true
"TESSELLATOR_ENABLE_CGAL": false
},
"inherits": "gnu"
}
Expand Down Expand Up @@ -114,6 +115,7 @@ This optional entry configures the meshing algorithm and its options. If not spe

For **staircase** mesher:
- `compress`: (boolean, default: false) Enables surface compression to merge adjacent coplanar quads into larger surfaces
- `splitHexahedra`: (boolean, default: false) Splits filled volumes into one conforming hexahedron per occupied grid cell

For **conformal** mesher:
- `edgePoints`: Controls edge point snapping behavior
Expand Down
16 changes: 12 additions & 4 deletions src/app/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,22 @@ meshlib::meshers::StaircaseMesherOptions readStaircaseMesherOptions(const nlohma
}

meshlib::meshers::StaircaseMesherOptions res;

res.isVolume = isVolume;
if (isVolume){
res.volumeGroups.insert(0);
}
if (mesherConfig.contains("options") &&
mesherConfig["options"].contains("compress")) {
res.compress = mesherConfig["options"]["compress"];
}
if (mesherConfig.contains("options") &&
mesherConfig["options"].contains("splitHexahedra")) {
res.splitHexahedra = mesherConfig["options"]["splitHexahedra"];
}

return res;
}

meshlib::meshers::ConformalMesherOptions readConformalMesherOptions(const nlohmann::json& fileData, const std::optional<nlohmann::json>& override)
meshlib::meshers::ConformalMesherOptions readConformalMesherOptions(const nlohmann::json& fileData, bool isVolume, const std::optional<nlohmann::json>& override)
{
nlohmann::json mesherConfig;
if (override.has_value()) {
Expand All @@ -170,6 +175,9 @@ meshlib::meshers::ConformalMesherOptions readConformalMesherOptions(const nlohma
}

meshlib::meshers::ConformalMesherOptions res;
if (isVolume){
res.volumeGroups.insert(0);
}
if (mesherConfig.contains("options")) {
res.snapperOptions.edgePoints = mesherConfig["options"]["edgePoints"];
res.snapperOptions.forbiddenLength = mesherConfig["options"]["forbiddenLength"];
Expand Down Expand Up @@ -204,7 +212,7 @@ std::unique_ptr<meshlib::meshers::MesherBase> buildMesher(const Mesh& in, const
readStaircaseMesherOptions(fileData, objDef.isVolume, objDef.mesherOverride)
});
} else if (mesherType == meshlib::app::conformal_mesher) {
return std::make_unique<meshlib::meshers::ConformalMesher>(meshlib::meshers::ConformalMesher{in, readConformalMesherOptions(fileData, objDef.mesherOverride)});
return std::make_unique<meshlib::meshers::ConformalMesher>(meshlib::meshers::ConformalMesher{in, readConformalMesherOptions(fileData, objDef.isVolume, objDef.mesherOverride)});
} else {
throw std::runtime_error("Unsupported mesher type");
}
Expand Down
32 changes: 32 additions & 0 deletions src/app/vtkIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include <vtkCellData.h>
#include <vtkCellType.h>
#include <vtkTriangle.h>
#include <vtkTetra.h>
#include <vtkHexahedron.h>
#include <vtkQuad.h>
#include <vtkCellArray.h>
#include <vtkLine.h>
#include <vtkVertex.h>
#include <vtkUnstructuredGrid.h>
Expand Down Expand Up @@ -76,6 +79,8 @@ Element vtkCellToElement(vtkCell* cell)
vtkVertex* vertex = nullptr;
vtkLine* line = nullptr;
vtkTriangle* triangle = nullptr;
vtkTetra* tetra = nullptr;
vtkHexahedron* hexahedron = nullptr;

switch (cell->GetCellType()) {
case VTK_VERTEX:
Expand All @@ -102,6 +107,26 @@ Element vtkCellToElement(vtkCell* cell)
};
elem.type = meshlib::Element::Type::Surface;
break;

case VTK_TETRA:
tetra = vtkTetra::SafeDownCast(cell);
elem.vertices = {
CoordinateId(tetra->GetPointIds()->GetId(0)),
CoordinateId(tetra->GetPointIds()->GetId(1)),
CoordinateId(tetra->GetPointIds()->GetId(2)),
CoordinateId(tetra->GetPointIds()->GetId(3))
};
elem.type = meshlib::Element::Type::Volume;
break;

case VTK_HEXAHEDRON:
hexahedron = vtkHexahedron::SafeDownCast(cell);
elem.vertices.reserve(8);
for (vtkIdType id = 0; id < 8; ++id) {
elem.vertices.push_back(CoordinateId(hexahedron->GetPointIds()->GetId(id)));
}
elem.type = meshlib::Element::Type::Volume;
break;
}

return elem;
Expand Down Expand Up @@ -131,6 +156,7 @@ Mesh vtuToMesh(vtkUnstructuredGrid* vtu)
}
} else {
mesh.groups.resize(1);
auto k = vtu->GetNumberOfCells();
mesh.groups[0].elements.reserve(vtu->GetNumberOfCells());
for (vtkIdType i = 0; i < vtu->GetNumberOfCells(); i++) {
mesh.groups[0].elements.push_back(
Expand Down Expand Up @@ -205,6 +231,12 @@ vtkSmartPointer<vtkUnstructuredGrid> elementsToVTU(const Mesh& mesh)
} else if (elem.isNode()) {
cellTypes.push_back(VTK_VERTEX);
cell = vtkSmartPointer<vtkVertex>::New();
} else if (elem.isTetrahedron()) {
cellTypes.push_back(VTK_TETRA);
cell = vtkSmartPointer<vtkTetra>::New();
} else if (elem.isHexahedron()) {
cellTypes.push_back(VTK_HEXAHEDRON);
cell = vtkSmartPointer<vtkHexahedron>::New();
} else {
throw std::runtime_error("Unsupported element type");
}
Expand Down
32 changes: 30 additions & 2 deletions src/cgal/filler/Filler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,29 @@ void sliceAlignedByGrid(
);
}

void sliceAlignedByGridAndRemove(
Filler::GridSlices& slices,
const Polyhedron& m,
const Grid& g,
const Priority& priority)
{

auto polygons{ buildGridPlanesPolygons(makeFacesCCWOriented(m), g)};
const std::array<Axis, 3> axis{ X, Y, Z };

std::for_each(
#ifdef TESSELLATOR_EXECUTION_POLICIES
std::execution::par,
#endif
axis.begin(), axis.end(),
[&](const auto& x) {
for (const auto& [i, polygon] : polygons[x]) {
slices[x][i].remove(polygon, priority);
}
}
);
}

Priority Filler::getGroupPriority(const GroupId& gId) const
{
if (gId < groupPriorities_.size()) {
Expand Down Expand Up @@ -508,7 +531,8 @@ FillerPolyhedrons buildFillerPolyhedrons(
Filler::Filler(
const Mesh& volumeMesh,
const Mesh& surfaceMesh,
const std::vector<Priority>& groupPriorities)
const std::vector<Priority>& groupPriorities,
const FillerMode& fillerMode)
{
utils::meshTools::checkNoNullAreasExist(volumeMesh);
utils::meshTools::checkNoNullAreasExist(surfaceMesh);
Expand Down Expand Up @@ -547,7 +571,11 @@ Filler::Filler(
log("Slicing surfaces", 2);
sliceNonAlignedByGrid(slices_, fP.surfaces, grid_, pr, SlicingMode::Surface);
log("Slicing aligned", 2);
sliceAlignedByGrid(slices_, fP.aligned, grid_, pr);
if (fillerMode == FillerMode::insideAndOutside) {
sliceAlignedByGrid(slices_, fP.aligned, grid_, pr);
} else if (fillerMode == FillerMode::onlyInside){
sliceAlignedByGridAndRemove(slices_, fP.aligned, grid_, pr);
}
log("Building segments arrays", 2);
buildSegmentsArray(segmentsArray_, fP.aligned, grid_, pr);
buildSegmentsArray(segmentsArray_, fP.volumes, grid_, pr);
Expand Down
18 changes: 14 additions & 4 deletions src/cgal/filler/Filler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@

namespace meshlib::cgal::filler {

enum class FillerMode{
insideAndOutside,
onlyInside
};


class Filler {
public:
public:
using Slices = std::map<SliceNumber, Slice>;
using GridSlices = std::array<Slices, 3>;
using SegmentsArray = std::map<ArrayIndex, Segments>;
using GridSegmentsArray = std::array<SegmentsArray, 3>;


FillerMode mode = FillerMode::insideAndOutside;

Filler(
const Mesh& volumeMesh,
const Mesh& surfaceMesh = Mesh(),
const std::vector<Priority>& groupPriorities = std::vector<Priority>());
const std::vector<Priority>& groupPriorities = std::vector<Priority>(),
const FillerMode& mode = FillerMode::insideAndOutside);
Filler(const Filler&) = delete;
Filler(Filler&&) = default;
Filler& operator=(const Filler&) = delete;
Expand All @@ -32,7 +41,7 @@ class Filler {
FillingState getFillingState(const CellIndex&) const;

Mesh getMeshFilling() const;

GridSlices getSlices() const {return slices_;};
private:
GridSlices slices_;
GridSegmentsArray segmentsArray_;
Expand All @@ -42,6 +51,7 @@ class Filler {

void mergeGroupsWithSamePriority(Groups& vGroups, Groups& sGroups);


};


Expand Down
Loading
Loading