Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Brep Surface - trimmed integration (Part 1 - Outer loop) #13072

Merged
merged 4 commits into from
Feb 3, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace Kratos
solution = Clipper2Lib::RectClip(rectangle, all_loops);

const double span_area = std::abs(Clipper2Lib::Area(rectangle.AsPath()));
double clip_area = std::abs(Clipper2Lib::Area(solution[0]));
double clip_area = 0.0;
if (solution.size() > 0)
{
clip_area = std::abs(Clipper2Lib::Area(solution[0]));
Expand Down
48 changes: 31 additions & 17 deletions kratos/utilities/geometry_utilities/brep_trimming_utilities.h
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with the changes but we need to be sure that the chosen tolerances are robust enough. I think the tests for this will be provided in the 3rd PR regarding trimming, won't they?

Copy link
Contributor

Choose a reason for hiding this comment

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

How rigid is your function interface? If not much, you could pass in the tolerance as an argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, all the stuff with the tolerances will be discussed in other PR: This one just remedies the general problem related the outer trimming.

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,32 @@ namespace Kratos
//Triangulation
static void Triangulate_OPT(const Clipper2Lib::Path64& polygon, std::vector<Matrix>& triangles, const double factor)
{
if (polygon.size() == 4)
array_1d<double, 2> p1, p2, p3, p4;
int bestvertex;
double weight = 0;
double d1 = 0.0, d2 = 0.0;
double minweight = std::numeric_limits<double>::max();
Diagonal diagonal, newdiagonal;

std::queue<Diagonal> diagonals;

IndexType n = polygon.size();
std::vector< Clipper2Lib::Point64 > const& points = polygon;

//if first and last point are coincide, neglect the last point
double p0_x, p0_y, pn_x, pn_y, dpx, dpy;
p0_x = BrepTrimmingUtilities::IntPointToDoublePoint(points[0], factor)[0];
p0_y = BrepTrimmingUtilities::IntPointToDoublePoint(points[0], factor)[1];
pn_x = BrepTrimmingUtilities::IntPointToDoublePoint(points[n - 1], factor)[0];
pn_y = BrepTrimmingUtilities::IntPointToDoublePoint(points[n - 1], factor)[1];
dpx = pn_x - p0_x;
dpy = pn_y - p0_y;

if(sqrt((dpx*dpx+dpy*dpy)) < 1e-9){
n = n - 1;
}

if (n == 3) //special case with only one triangle
{
Matrix triangle(3, 2);
triangle(0, 0) = BrepTrimmingUtilities::IntPointToDoublePoint(polygon[0], factor)[0];
Expand All @@ -90,17 +115,6 @@ namespace Kratos
return;
}

array_1d<double, 2> p1, p2, p3, p4;
int bestvertex;
double weight = 0;
double d1, d2 = 0.0;
double minweight = std::numeric_limits<double>::max();
Diagonal diagonal, newdiagonal;

std::list<Diagonal> diagonals;

IndexType n = polygon.size();
std::vector< Clipper2Lib::Point64 > const& points = polygon;
matrix<DPState> dpstates(n, n);

//init states and visibility
Expand Down Expand Up @@ -181,11 +195,11 @@ namespace Kratos

newdiagonal.index1 = 0;
newdiagonal.index2 = n - 1;
diagonals.push_back(newdiagonal);
diagonals.push(newdiagonal);

while (!diagonals.empty()) {
diagonal = *(diagonals.begin());
diagonals.pop_front();
diagonal = diagonals.front();
diagonals.pop();

bestvertex = dpstates(diagonal.index2, diagonal.index1).bestvertex;
if (bestvertex == -1) {
Expand All @@ -208,12 +222,12 @@ namespace Kratos
if (bestvertex > (diagonal.index1 + 1)) {
newdiagonal.index1 = diagonal.index1;
newdiagonal.index2 = bestvertex;
diagonals.push_back(newdiagonal);
diagonals.push(newdiagonal);
}
if (diagonal.index2 > (bestvertex + 1)) {
newdiagonal.index1 = bestvertex;
newdiagonal.index2 = diagonal.index2;
diagonals.push_back(newdiagonal);
diagonals.push(newdiagonal);
}
}
}
Expand Down
Loading