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

Implemented Fuselage Profile Type: Rectangle (Issue #909) #1005

Merged
merged 58 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0341aff
added skeleton for optional rectangular profile wire
Jan 26, 2024
5585f36
added rectangle testfiles
Jan 31, 2024
c423d12
added test
Jan 31, 2024
6053781
added function buildWireRectangle
Jan 31, 2024
e88bd66
made function build wire with negative cornerradius
Feb 7, 2024
99a504b
added test
Feb 8, 2024
b0aa945
added typecheck
Feb 8, 2024
bb076de
added testsfunctions
Feb 21, 2024
428b688
update function
Feb 26, 2024
2fb50df
added check for valid shapes
Feb 26, 2024
9ebaa60
added constructor that takes parameter of type std::vector<gp_Pnt>
Feb 28, 2024
7b00675
added constructors to take parameters of type std::vector<gp_Pnt>
Feb 28, 2024
98891d4
fixed new constructor
Feb 28, 2024
bb23bba
updated function to build wire from point list
Mar 4, 2024
199d7c7
fixed initialization in new constructor
Mar 4, 2024
79125b5
updated xml-files and added test
Mar 5, 2024
cd41cb2
rewrote function to build wire from one edge
Mar 12, 2024
2b4677d
added testcase
Mar 12, 2024
4d3ca07
added testfiles
Mar 12, 2024
4979829
implemented funktion
Mar 12, 2024
a666615
rectanglewirde built counter-cockwise-> reversed
Mar 20, 2024
f0896d9
adjusted orientation of rectangle wire
Mar 20, 2024
737feef
joined testcases in two xml files
Apr 11, 2024
7632787
moved documentation
Apr 11, 2024
5be8939
removed unnecessary xml file
Apr 11, 2024
9332b8d
modified testfiles
Apr 16, 2024
7f6dd02
updated function to make it work with rectangle profiles
Apr 16, 2024
6a1b595
added boolean expression
Apr 29, 2024
fb99786
Merge branch 'master' into rectangle
Apr 30, 2024
a205ebb
updated values
Apr 30, 2024
bb8e7bd
updated docstring
Apr 30, 2024
2f9882c
updated docstring
Apr 30, 2024
c3b4491
update
May 15, 2024
75c31ca
updated constructors
May 15, 2024
75606c0
updated code regarding pull request suggestions
May 23, 2024
db5bfdb
Merge branch 'updateRectangle' into rectangle
May 23, 2024
f9192ca
added check for curve degree
May 28, 2024
67be429
Update src/fuselage/CCPACSFuselageProfiles.cpp
merakulix Jun 3, 2024
1ac277a
update comment on curve degree
Jun 3, 2024
78a837f
Merge branch 'rectangle' of https://github.com/DLR-SC/tigl into recta…
Jun 3, 2024
49bc34e
added test for CTiglPointsToBSplineInterpolation
Jun 4, 2024
8f32a4c
moved wire tests to tiglCommonFunctions.cpp
Jul 2, 2024
c7bf073
merged master branch
Jul 2, 2024
343c48e
Update src/fuselage/CCPACSFuselageProfile.cpp
merakulix Jul 4, 2024
b8dada1
Update src/common/tiglcommonfunctions.cpp
merakulix Jul 4, 2024
f14c31f
removed redundant check
Jul 11, 2024
a13eea2
added test
Jul 11, 2024
0fe2758
added check vor valid inputs
Jul 11, 2024
4234fba
added test for invalid inputs in cpacs file
Jul 15, 2024
13281fb
fixed file mixup
Jul 15, 2024
8475ecb
added translation to arc circle
Aug 19, 2024
e7db244
update test
Aug 19, 2024
1f7a12a
update test
Aug 19, 2024
bed7bfa
updated rectangle profile to use 'CFunctionToBSpline'
Aug 19, 2024
0fa67b8
update some formatting issues
Aug 20, 2024
0a3f7d8
merge master
Aug 20, 2024
4b29d5e
change function call
Aug 26, 2024
571a2ef
Update src/common/tiglcommonfunctions.cpp
joergbrech Sep 2, 2024
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
119 changes: 119 additions & 0 deletions src/common/tiglcommonfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "CTiglRelativelyPositionedComponent.h"
#include "CTiglProjectPointOnCurveAtAngle.h"
#include "CTiglBSplineAlgorithms.h"
#include "CTiglPointsToBSplineInterpolation.h"

#include "Standard_Version.hxx"

Expand Down Expand Up @@ -119,6 +120,7 @@
#include <ShapeAnalysis_FreeBounds.hxx>



#include <list>
#include <algorithm>
#include <cassert>
Expand All @@ -127,6 +129,7 @@

#include "Debugging.h"


namespace
{
struct IsSame
Expand Down Expand Up @@ -1156,6 +1159,122 @@ TopoDS_Wire BuildWireFromEdges(const TopoDS_Shape& edges)
return result;
}

opencascade::handle<Geom_BSplineCurve> ApproximateArcOfCircleToRationalBSpline(double radius, size_t nb_points, double uMin, double uMax, double y_position, double z_position)
{
std::vector<gp_Pnt> arcPnts(nb_points);
std::vector<double> alpha = LinspaceWithBreaks(uMin, uMax, nb_points);
size_t index = 0;
for (double a : alpha){
arcPnts.at(index++) = (gp_Pnt(0., y_position + radius * std::cos(a), z_position + radius* std::sin(a)));
}
return tigl::CTiglPointsToBSplineInterpolation(arcPnts).Curve();
}

TopoDS_Wire BuildWireRectangle(const double heightToWidthRatio, const double cornerRadius, const double tol)
{
int nb_points(0);

if(cornerRadius<0.||cornerRadius>0.5){
throw tigl::CTiglError("Invalid input for corner radius. Must be in range: 0 <= cornerRadius <= 0.5");
}

std::vector<Handle(Geom_BSplineCurve)> curves;

// build half upper line from gp_points
std::vector<gp_Pnt> linePntsUpperRightHalf;
linePntsUpperRightHalf.push_back(gp_Pnt(0.,0.,0.5*heightToWidthRatio));
linePntsUpperRightHalf.push_back(gp_Pnt(0.,0.5-cornerRadius,0.5*heightToWidthRatio));
opencascade::handle<Geom_BSplineCurve> lowerLineRightHalf = tigl::CTiglPointsToBSplineInterpolation(linePntsUpperRightHalf).Curve();
curves.push_back(lowerLineRightHalf);

if (!(cornerRadius == 0.0)){
//calculate the number of points required to maintain the minimum distance (<tol) between the bisector of two neighboring points on an arc circle
nb_points = std::round(M_PI/(acos(1-tol/cornerRadius)));
merakulix marked this conversation as resolved.
Show resolved Hide resolved
//build upper right arc
double y0 = 0.5 - cornerRadius;
double z0 = 0.5 * heightToWidthRatio - cornerRadius;
auto ArcCurve = ApproximateArcOfCircleToRationalBSpline(cornerRadius, nb_points, 0., M_PI/2., y0, z0);
ArcCurve->Reverse();
curves.push_back(ArcCurve);
}

// build right line from gp_Pnts
std::vector<gp_Pnt> linePnts_right;
linePnts_right.push_back(gp_Pnt(0., 0.5, 0.5 * heightToWidthRatio - cornerRadius));
linePnts_right.push_back(gp_Pnt(0., 0.5, -0.5 * heightToWidthRatio + cornerRadius));
opencascade::handle<Geom_BSplineCurve> rightLine = tigl::CTiglPointsToBSplineInterpolation(linePnts_right).Curve();
curves.push_back(rightLine);

if (!(cornerRadius == 0.0)){
//build lower right arc
double y0 = 0.5 - cornerRadius;
double z0 = - 0.5 * heightToWidthRatio + cornerRadius;
auto ArcCurve = ApproximateArcOfCircleToRationalBSpline(cornerRadius, nb_points, M_PI*(3./2.), M_PI*2., y0, z0);
ArcCurve->Reverse();
curves.push_back(ArcCurve);
}

// build lower line from gp_points
std::vector<gp_Pnt> linePnts_lower;
linePnts_lower.push_back(gp_Pnt(0.,(0.5-cornerRadius),-0.5*heightToWidthRatio));
linePnts_lower.push_back(gp_Pnt(0.,(-0.5+cornerRadius),-0.5*heightToWidthRatio));
opencascade::handle<Geom_BSplineCurve> lowerLine = tigl::CTiglPointsToBSplineInterpolation(linePnts_lower).Curve();

curves.push_back(lowerLine);

if (!(cornerRadius == 0.)){
// build lower left arc
double y0 = - 0.5 + cornerRadius;
double z0 = -0.5 * heightToWidthRatio + cornerRadius;
auto ArcCurve = ApproximateArcOfCircleToRationalBSpline(cornerRadius, nb_points, M_PI, M_PI*(3./2.), y0, z0);
ArcCurve->Reverse();
curves.push_back(ArcCurve);
}

//build left line from gp_points
std::vector<gp_Pnt> linePnts_left;
linePnts_left.push_back(gp_Pnt(0.,-0.5,-0.5 * heightToWidthRatio + cornerRadius));
linePnts_left.push_back(gp_Pnt(0.,-0.5,0.5 * heightToWidthRatio - cornerRadius));
opencascade::handle<Geom_BSplineCurve> leftLine = tigl::CTiglPointsToBSplineInterpolation(linePnts_left).Curve();
curves.push_back(leftLine);

if (!(cornerRadius == 0.)) {
// build upper left arc
double y0 = - 0.5 + cornerRadius;
double z0 = 0.5 * heightToWidthRatio - cornerRadius;
auto ArcCurve = ApproximateArcOfCircleToRationalBSpline(cornerRadius, nb_points, M_PI/2., M_PI, y0, z0);
ArcCurve->Reverse();
curves.push_back(ArcCurve);
}

// build half upper line from gp_points
std::vector<gp_Pnt> linePntsUpperLeftHalf;
linePntsUpperLeftHalf.push_back(gp_Pnt(0.,-(0.5-cornerRadius),0.5*heightToWidthRatio));
linePntsUpperLeftHalf.push_back(gp_Pnt(0.,0.,0.5*heightToWidthRatio));
opencascade::handle<Geom_BSplineCurve> upperLineLeftHalf = tigl::CTiglPointsToBSplineInterpolation(linePntsUpperLeftHalf).Curve();
curves.push_back(upperLineLeftHalf);

opencascade::handle<Geom_BSplineCurve> curve = tigl::CTiglBSplineAlgorithms::concatCurves(curves);

// workaround for lofting algorithm not working with curves of degree '1' (i.e. concatenated lines)
// if guide curves are involved, the lofter doesn't generate a valid geometry without thowing an error
// This only occurs if the cornerRadius is zero and the profile is a rectangle, which in theory could
// just have degree 1.
if (curve->Degree()<2){
curve->IncreaseDegree(2);
}
joergbrech marked this conversation as resolved.
Show resolved Hide resolved

TopoDS_Wire wire;
if(!curve.IsNull())
{
joergbrech marked this conversation as resolved.
Show resolved Hide resolved
wire = BuildWireFromEdges(BRepBuilderAPI_MakeEdge(curve).Edge());
}
if(wire.IsNull()){
throw tigl::CTiglError("Error building profile wire");
}
return wire;
}

void BuildWiresFromConnectedEdges(const TopoDS_Shape& shape, TopTools_ListOfShape& wireList)
{
// get list of edges from passed shape
Expand Down
29 changes: 28 additions & 1 deletion src/common/tiglcommonfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include <algorithm>
#include "UniquePtr.h"



typedef std::map<std::string, PNamedShape> ShapeMap;

// helper function for std::find
Expand Down Expand Up @@ -269,6 +271,31 @@ TIGL_EXPORT TopoDS_Wire BuildWire(const gp_Pnt& p1, const gp_Pnt& p2);
// Method for building a wire out of the edges from the passed geometry
TIGL_EXPORT TopoDS_Wire BuildWireFromEdges(const TopoDS_Shape& edges);

/**
* @brief ApproximateArcOfCircleToRationalBSpline
* The result of this function is a non-rational B-Spline curve that approximates an arc of circle in the y-z plane. Its center is given by the y- and z-position.
* The angle is given in rad.
* The direction of rotation is counter-clockwise, starting with alpha=0 on the positive y-axis, with z=0.
* @param cornerRadius Radius of the circle
* @param nb_points Number of points used for interpolation
* @param uMin Starting parameter in rad. Range: [0,2*Pi]
* @param uMax
* @param y_position
* @param z_position
* @return opencascade::handle<Geom_BSplineCurve>
*/
TIGL_EXPORT opencascade::handle<Geom_BSplineCurve> ApproximateArcOfCircleToRationalBSpline(double cornerRadius, size_t nb_points, double uMin = 0, double uMax = M_PI/4 ,
double y_position = 0., double z_position = 0.);

/**
* @brief BuildWireRectangle Builds a rectangular wire in (y,z) - plane with width 1, center of coordinate system is the center of the rectangle
* @param heightToWidthRatio
* @param cornerRadius
* @param tol
* @return
*/
TIGL_EXPORT TopoDS_Wire BuildWireRectangle(const double heightToWidthRatio, const double cornerRadius =0.0, const double tol= 1e-3);

// Returns a list of wires built from all connected edges in the passed shape
TIGL_EXPORT void BuildWiresFromConnectedEdges(const TopoDS_Shape& shape, TopTools_ListOfShape& wireList);

Expand Down Expand Up @@ -358,7 +385,7 @@ TIGL_EXPORT double NormalizeAngleDeg(double angleDeg);
// Creates a linear spaces array but with some additional breaking points
// If the breaking points are very close to a point, the point will be replaced
// Else, the breaking point will be inserted
TIGL_EXPORT std::vector<double> LinspaceWithBreaks(double umin, double umax, size_t n_values, const std::vector<double>& breaks);
TIGL_EXPORT std::vector<double> LinspaceWithBreaks(double umin, double umax, size_t n_values, const std::vector<double>& breaks = {});

// Transforms a shape accourding to the given coordinate transformation
TIGL_EXPORT TopoDS_Shape TransformedShape(const tigl::CTiglTransformation& transformationToGlobal, TiglCoordinateSystem cs, const TopoDS_Shape& shape);
Expand Down
Loading
Loading