Skip to content
Open
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
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are having a war on versions on this file... which is very user dependent. I think we should remove it and add it to .gitignore.

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"]
}
12 changes: 8 additions & 4 deletions src/app/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ 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"];
Expand All @@ -160,7 +161,7 @@ meshlib::meshers::StaircaseMesherOptions readStaircaseMesherOptions(const nlohma
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 +171,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 +208,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
23 changes: 21 additions & 2 deletions src/app/vtkIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vtkCellData.h>
#include <vtkCellType.h>
#include <vtkTriangle.h>
#include <vtkTetra.h>
#include <vtkQuad.h>
#include <vtkLine.h>
#include <vtkVertex.h>
Expand Down Expand Up @@ -76,6 +77,7 @@ Element vtkCellToElement(vtkCell* cell)
vtkVertex* vertex = nullptr;
vtkLine* line = nullptr;
vtkTriangle* triangle = nullptr;
vtkTetra* tetra = nullptr;

switch (cell->GetCellType()) {
case VTK_VERTEX:
Expand All @@ -102,6 +104,17 @@ 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;
}

return elem;
Expand Down Expand Up @@ -131,6 +144,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 @@ -169,8 +183,13 @@ vtkSmartPointer<vtkStringArray> toVTKGroupNamesArray(const Mesh& mesh)
groupNamesArray->SetName("groupNames");
groupNamesArray->SetNumberOfComponents(1);

for (const auto& group : mesh.groups) {
groupNamesArray->InsertNextValue(group.name.c_str());
// for (const auto& group : mesh.groups) {
// groupNamesArray->InsertNextValue(group.name.c_str());
// }
for (auto g = 0; g < mesh.groups.size(); g++) {
for (auto e = 0; e < mesh.groups[g].elements.size(); e++) {
groupNamesArray->InsertNextValue( mesh.groups[g].name.c_str() );
}
}

return groupNamesArray;
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
27 changes: 27 additions & 0 deletions src/cgal/filler/Slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ void Slice::add(const Polylines2& polylines, const Priority& pr)
}
}

void Slice::remove(const Polylines2& polylines, const Priority& pr)
{
SliceData& sd = data_[pr];

for (const auto& p : polylines) {
if (p.size() == 1) {
continue;
}
auto r{ removeSegmentsContainedInAnyAxis(p) };
for (const auto& rr : r){
sd.lines.erase(std::find(sd.lines.begin(), sd.lines.end(), rr));
}
}
}

FillingState::FillingState(const FillingType& t) :
type{ t },
priority_{ 0 }
Expand Down Expand Up @@ -261,6 +276,18 @@ void Slice::add(const HPolygonSet& polygons, const Priority& pr)
removeInSuperiorPriorities(pr);
}

void Slice::remove(const HPolygonSet& polygons, const Priority& pr)
{
if (polygons.isEmpty()) {
return;
}

SliceData& sd = data_[pr];
sd.surfaces.difference(polygons);

removeInSuperiorPriorities(pr);
}

void Slice::mergeLines(const Slice& lhs)
{
for (const auto& [pr, sd] : lhs.data_) {
Expand Down
2 changes: 2 additions & 0 deletions src/cgal/filler/Slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ class Slice {
FillingState getFillingState(const ArrayIndex&) const;

void add(const Polylines2&, const Priority&);
void remove(const Polylines2&, const Priority&);
void addAsPolygon(const Polylines2&, const Priority&);
void add(const HPolygonSet&, const Priority&);
void remove(const HPolygonSet&, const Priority&);
void mergeLines(const Slice& lhs);
void buildSearchMap();
void buildTriangulations();
Expand Down
5 changes: 4 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ add_library(tessellator-core
"Staircaser.cpp"
)

target_link_libraries(tessellator-core tessellator-utils)
target_link_libraries(tessellator-core
tessellator-utils
tessellator-cgal
CGAL::CGAL)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CGAL was optional. Is it required for volumes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid so. To have the volumes filled Filler is used, and it uses CGAL

1 change: 0 additions & 1 deletion src/core/Slicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ void orient(const Coordinates& coords,
}
}


Slicer::Slicer(const Mesh& input, const std::vector<Element::Type>& dimensionPolicy, const SlicerOptions& opts) :
GridTools(input.grid),
opts_(opts)
Expand Down
7 changes: 5 additions & 2 deletions src/core/Slicer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class Slicer : public utils::GridTools {

Slicer(const Mesh&, const std::vector<Element::Type>& dimensionPolicy = {}, const SlicerOptions& opts = SlicerOptions());
Mesh getMesh() const { return mesh_; };


static Elements buildTrianglesFromPath(const std::vector<Coordinate>&, const std::vector<CoordinateId>&);

private:
Expand Down Expand Up @@ -53,6 +51,11 @@ class Slicer : public utils::GridTools {
const Cell&, const Coordinate&,
const Cell&, const Coordinate&) const;

// IdSet buildGroupIntersectionsWithGridPlanes(
// Coordinates& sCoords,
// const std::vector<Element>& elements);


};

}
Expand Down
1 change: 0 additions & 1 deletion src/meshers/MesherBaseOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace meshlib::meshers {

class MesherBaseOptions {
public:
bool isVolume = false;
std::set<GroupId> volumeGroups{};
};

Expand Down
Loading
Loading