Skip to content

Commit

Permalink
Merge pull request #811 from DLR-SC/808_tiglwinggetsegmentetaxsi_igno…
Browse files Browse the repository at this point in the history
…res_getpointbehaviour

Respect PointBehaviour for tiglWingGetSegmentEtaXsi
  • Loading branch information
rainman110 authored Jun 16, 2021
2 parents e05dfb1 + 1833e84 commit 59ae251
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 94 deletions.
9 changes: 9 additions & 0 deletions TIGLViewer/scripts/globaldefs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
function EtaXsi(eta, xsi) {
this.eta = eta;
this.xsi = xsi;
}

EtaXsi.prototype.toString = function() {
return '{\n eta:' + this.eta + ',\n xsi:' + this.xsi + '\n}';
}

function Point3d(x,y,z) {
this.x = x;
this.y = y;
Expand Down
44 changes: 44 additions & 0 deletions TIGLViewer/src/TIGLScriptProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,50 @@ QScriptValue TIGLScriptProxy::controlSurfaceSetControlParameter(QString controlS
}


QScriptValue TIGLScriptProxy::wingSetGetPointBehaviour (int behaviour)
{
TiglGetPointBehavior b = onLinearLoft;
if (behaviour == 0) {
b = asParameterOnSurface;
}
else {
b = onLinearLoft;
}

TiglReturnCode ret = ::tiglWingSetGetPointBehavior(getTiglHandle(), b);
if (ret != TIGL_SUCCESS) {
return context()->throwError(tiglGetErrorString(ret));
}
else {
return QScriptValue::UndefinedValue;
}
}

QScriptValue TIGLScriptProxy::wingGetSegmentEtaXsi(int wingIdx, double px, double py, double pz)
{
double eta, xsi;
int segmentIndex, isOnTop;

TiglReturnCode ret = ::tiglWingGetSegmentEtaXsi(getTiglHandle(), wingIdx, px, py, pz, &segmentIndex, &eta, &xsi, &isOnTop);

if (ret != TIGL_SUCCESS) {
return context()->throwError(tiglGetErrorString(ret));
}
else {
QScriptValue EtaXsiCtor = engine()->globalObject().property("EtaXsi");
QScriptValue etaxsi = EtaXsiCtor.construct(QScriptValueList() << eta << xsi);

QScriptValue obj = engine()->newObject();

obj.setProperty("etaxsi", etaxsi);
obj.setProperty("isOnTop", isOnTop);
obj.setProperty("segmentIndex", segmentIndex);
return obj;
}

}


QScriptValue TIGLScriptProxy::getShape(QString uid)
{
if (!_app->getDocument()) {
Expand Down
7 changes: 5 additions & 2 deletions TIGLViewer/src/TIGLScriptProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public slots:
QScriptValue getWingCount();
QString getVersion();
QScriptValue componentGetHashCode (QString componentUID);

// exports
QScriptValue exportComponent (QString uid, QString filename, double deflection);
QScriptValue exportConfiguration (QString filename, bool fuseAllShapes, double deflection);
Expand Down Expand Up @@ -92,7 +92,10 @@ public slots:
QScriptValue wingGetSpan(QString wingUID);
QScriptValue wingGetSegmentVolume (int wingIndex, int segmentIndex);
QScriptValue controlSurfaceSetControlParameter(QString controlSurfaceUID, double controlParameter);

QScriptValue wingSetGetPointBehaviour (int behaviour);
QScriptValue wingGetSegmentEtaXsi(int wingIdx, double px, double py, double pz);


QString getErrorString(int errorCode);
QScriptValue getShape(QString uid);

Expand Down
5 changes: 1 addition & 4 deletions src/api/tigl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,7 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglWingSetGetPointBehavior(TiglCPACSConfigura
tigl::CCPACSConfiguration& config = manager.GetConfiguration(cpacsHandle);
for(int wingIndex = 1; wingIndex <= config.GetWingCount(); ++wingIndex ) {
tigl::CCPACSWing& wing = config.GetWing(wingIndex);
for (int segmentIndex = 1; segmentIndex <= wing.GetSegmentCount(); ++segmentIndex) {
tigl::CCPACSWingSegment& segment = wing.GetSegment(segmentIndex);
segment.SetGetPointBehavior(behavior);
}
wing.SetGetPointBehavior(behavior);
}

return TIGL_SUCCESS;
Expand Down
3 changes: 2 additions & 1 deletion src/geometry/CTiglTriangularizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ bool CTiglTriangularizer::writeWingSegmentMeta(tigl::ITiglGeometricComponent &se
}

double eta = 0., xsi = 0.;
segment.GetEtaXsi(baryCenter.Get_gp_Pnt(), eta, xsi);
gp_Pnt pDummy;
segment.GetEtaXsi(baryCenter.Get_gp_Pnt(), eta, xsi, pDummy, onLinearLoft);
polys.currentObject().setPolyDataReal(iPoly, "eta", eta);
polys.currentObject().setPolyDataReal(iPoly, "xsi", xsi);

Expand Down
38 changes: 24 additions & 14 deletions src/wing/CCPACSWing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,13 @@ CTiglTransformation CCPACSWing::GetPositioningTransformation(std::string section
// Gets the upper point in absolute (world) coordinates for a given segment, eta, xsi
gp_Pnt CCPACSWing::GetUpperPoint(int segmentIndex, double eta, double xsi)
{
return ((CCPACSWingSegment &) GetSegment(segmentIndex)).GetUpperPoint(eta, xsi);
return ((CCPACSWingSegment &) GetSegment(segmentIndex)).GetUpperPoint(eta, xsi, getPointBehavior);
}

// Gets the upper point in absolute (world) coordinates for a given segment, eta, xsi
gp_Pnt CCPACSWing::GetLowerPoint(int segmentIndex, double eta, double xsi)
{
return ((CCPACSWingSegment &) GetSegment(segmentIndex)).GetLowerPoint(eta, xsi);
return ((CCPACSWingSegment &) GetSegment(segmentIndex)).GetLowerPoint(eta, xsi, getPointBehavior);
}

// Gets a point on the chord surface in absolute (world) coordinates for a given segment, eta, xsi
Expand Down Expand Up @@ -769,17 +769,9 @@ int CCPACSWing::GetSegmentEtaXsi(const gp_Pnt& point, double& eta, double& xsi,
CCPACSWingSegment& segment2 = (CCPACSWingSegment&) GetSegment(segmentFound+1);

double eta1, eta2, xsi1, xsi2;
segment1.GetEtaXsi(point, eta1, xsi1);
segment2.GetEtaXsi(point, eta2, xsi2);

// Get the points on the chord face
double eta1p = max(0.0, min(1.0, eta1));
double eta2p = max(0.0, min(1.0, eta2));
double xsi1p = max(0.0, min(1.0, xsi1));
double xsi2p = max(0.0, min(1.0, xsi2));

gp_Pnt p1 = segment1.GetChordPoint(eta1p, xsi1p);
gp_Pnt p2 = segment2.GetChordPoint(eta2p, xsi2p);
gp_Pnt p1, p2;
segment1.GetEtaXsi(point, eta1, xsi1, p1, getPointBehavior);
segment2.GetEtaXsi(point, eta2, xsi2, p2, getPointBehavior);

double d1 = p1.Distance(point);
double d2 = p2.Distance(point);
Expand Down Expand Up @@ -807,7 +799,8 @@ int CCPACSWing::GetSegmentEtaXsi(const gp_Pnt& point, double& eta, double& xsi,
else {

CCPACSWingSegment& segment = (CCPACSWingSegment&) GetSegment(segmentFound);
segment.GetEtaXsi(point, eta, xsi);
gp_Pnt pTmp;
segment.GetEtaXsi(point, eta, xsi, pTmp, getPointBehavior);

// TODO: do we need that here?
onTop = segment.GetIsOnTop(point);
Expand Down Expand Up @@ -983,6 +976,23 @@ PNamedShape CCPACSWing::GetWingCleanShape() const
return *wingCleanShape;
}

// Sets the GetPoint behavior to asParameterOnSurface or onLinearLoft
void CCPACSWing::SetGetPointBehavior(TiglGetPointBehavior behavior)
{
getPointBehavior = behavior;
}

// Gets the getPointBehavior
TiglGetPointBehavior const CCPACSWing::GetGetPointBehavior() const
{
return getPointBehavior;
}

// Gets the getPointBehavior
TiglGetPointBehavior CCPACSWing::GetGetPointBehavior()
{
return getPointBehavior;
}
namespace
{

Expand Down
10 changes: 10 additions & 0 deletions src/wing/CCPACSWing.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ friend class CTiglWingBuilder;
// Returns the wing shape without any extended flaps
TIGL_EXPORT PNamedShape GetWingCleanShape() const;

// Sets the getPointBehavior to asParameterOnSurface or onLinearLoft
TIGL_EXPORT void SetGetPointBehavior(TiglGetPointBehavior behavior = asParameterOnSurface);

// Gets the getPointBehavior
TIGL_EXPORT TiglGetPointBehavior const GetGetPointBehavior() const;
TIGL_EXPORT TiglGetPointBehavior GetGetPointBehavior();

protected:

struct LocatedGuideCurves
Expand Down Expand Up @@ -230,6 +237,9 @@ friend class CTiglWingBuilder;
FusedElementsContainerType fusedElements; /**< Stores already fused segments */
double myVolume; /**< Volume of this Wing */


TiglGetPointBehavior getPointBehavior {asParameterOnSurface};

friend class CCPACSWingSegment;
friend class CCPACSWingComponentSegment;
};
Expand Down
9 changes: 3 additions & 6 deletions src/wing/CCPACSWingComponentSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,13 +958,10 @@ const CCPACSWingSegment* CCPACSWingComponentSegment::findSegment(double x, doubl
for (SegmentList::const_iterator segit = segments.begin(); segit != segments.end(); ++segit) {
try {
double eta, xsi;
(*segit)->GetEtaXsi(pnt, eta, xsi);
gp_Pnt pointProjected = (*segit)->GetChordPoint(eta, xsi);
gp_Pnt currentPoint;
(*segit)->GetEtaXsi(pnt, eta, xsi, currentPoint, onLinearLoft);

// Get nearest point on this segment
double nextEta = Clamp(eta, 0., 1.);
double nextXsi = Clamp(xsi, 0., 1.);
gp_Pnt currentPoint = (*segit)->GetChordPoint(nextEta, nextXsi);
gp_Pnt pointProjected = (*segit)->GetChordPoint(eta, xsi);

double currentDist = currentPoint.Distance(pointProjected);
if (currentDist < deviation) {
Expand Down
114 changes: 91 additions & 23 deletions src/wing/CCPACSWingSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,13 @@ PNamedShape CCPACSWingSegment::BuildLoft() const
}

// Gets the upper point in relative wing coordinates for a given eta and xsi
gp_Pnt CCPACSWingSegment::GetUpperPoint(double eta, double xsi) const
gp_Pnt CCPACSWingSegment::GetUpperPoint(double eta, double xsi, TiglGetPointBehavior getPointBehavior) const
{
return GetPoint(eta, xsi, true, GLOBAL_COORDINATE_SYSTEM, getPointBehavior);
}

// Gets the lower point in relative wing coordinates for a given eta and xsi
gp_Pnt CCPACSWingSegment::GetLowerPoint(double eta, double xsi) const
gp_Pnt CCPACSWingSegment::GetLowerPoint(double eta, double xsi, TiglGetPointBehavior getPointBehavior) const
{
return GetPoint(eta, xsi, false, GLOBAL_COORDINATE_SYSTEM, getPointBehavior);
}
Expand Down Expand Up @@ -584,6 +584,30 @@ void CCPACSWingSegment::etaXsiToUV(bool isFromUpper, double eta, double xsi, dou
}
}

void CCPACSWingSegment::uvToEtaXsi(bool isFromUpper, double u, double v, double& eta, double& xsi) const
{


Handle(Geom_Surface) surf;
if (isFromUpper) {
surf = GetUpperSurface();
}
else {
surf = GetLowerSurface();
}

double umin, umax, vmin, vmax;
surf->Bounds(umin,umax,vmin, vmax);
if (isFromUpper) {
xsi = (u - umin) / (umax - umin);
eta = (v - vmin) / (vmax - vmin);
}
else {
xsi = (u - umax) / (umin - umax);
eta = (v - vmin) / (vmax - vmin);
}
}

double CCPACSWingSegment::GetSurfaceArea(bool fromUpper,
double eta1, double xsi1,
double eta2, double xsi2,
Expand Down Expand Up @@ -877,11 +901,72 @@ gp_Pnt CCPACSWingSegment::GetChordNormal(double eta, double xsi) const
}

// Returns xsi as parametric distance from a given point on the surface
void CCPACSWingSegment::GetEtaXsi(gp_Pnt pnt, double& eta, double& xsi) const
void CCPACSWingSegment::GetEtaXsi(gp_Pnt pnt, double& eta, double& xsi, gp_Pnt& projectedPoint, TiglGetPointBehavior behavior) const
{
CTiglPoint tmpPnt(pnt.XYZ());
if (ChordFace().translate(tmpPnt, &eta, &xsi) != TIGL_SUCCESS) {
throw tigl::CTiglError("Cannot determine eta, xsi coordinates of current point in CCPACSWingSegment::GetEtaXsi!", TIGL_MATH_ERROR);
if (behavior == onLinearLoft) {

CTiglPoint tmpPnt(pnt.XYZ());
if (ChordFace().translate(tmpPnt, &eta, &xsi) != TIGL_SUCCESS) {
throw tigl::CTiglError("Cannot determine eta, xsi coordinates of current point in CCPACSWingSegment::GetEtaXsi!", TIGL_MATH_ERROR);
}

eta = Clamp(eta, 0., 1.);
xsi = Clamp(xsi, 0., 1.);

CTiglPoint ptmp;
ChordFace().translate(eta, xsi, &ptmp);
projectedPoint = ptmp.Get_gp_Pnt();

}
else {
// GetUpperSurface()
double maxdist = 10000;
double dist = maxdist;
double u,v;

bool onUpper;

GeomAPI_ProjectPointOnSurf projUpper(pnt, GetUpperSurface());


if (projUpper.NbPoints() > 0 && projUpper.LowerDistance() < dist) {
dist = projUpper.LowerDistance();
projUpper.LowerDistanceParameters(u, v);
uvToEtaXsi(true, u, v, eta, xsi);
onUpper = true;
}


GeomAPI_ProjectPointOnSurf projLower(pnt, GetLowerSurface());

if (projLower.NbPoints() > 0 && projLower.LowerDistance() < dist) {
dist = projLower.LowerDistance();
projLower.LowerDistanceParameters(u, v);
uvToEtaXsi(false, u, v, eta, xsi);
onUpper = false;

}

if (dist == maxdist) {
throw tigl::CTiglError("Cannot determine eta, xsi coordinates of current point in CCPACSWingSegment::GetEtaXsi!", TIGL_MATH_ERROR);
}
else {
double etaTmp = Clamp(eta, 0., 1.);
double xsiTmp = Clamp(xsi, 0., 1.);

etaXsiToUV(onUpper, etaTmp, xsiTmp, u, v);


// compute projected point
if (onUpper) {
projectedPoint = GetUpperSurface()->Value(u,v);
}
else {
projectedPoint = GetLowerSurface()->Value(u,v);
}
}


}
}

Expand Down Expand Up @@ -1163,23 +1248,6 @@ TopoDS_Shape CCPACSWingSegment::GetTrailingEdgeShape(TiglCoordinateSystem refere
return GetParent()->GetParent<CCPACSWing>()->GetTransformationMatrix().Inverted().Transform(s);
}

// Sets the GetPoint behavior to asParameterOnSurface or onLinearLoft
void CCPACSWingSegment::SetGetPointBehavior(TiglGetPointBehavior behavior)
{
getPointBehavior = behavior;
}

// Gets the getPointBehavior
TiglGetPointBehavior const CCPACSWingSegment::GetGetPointBehavior() const
{
return getPointBehavior;
}

// Gets the getPointBehavior
TiglGetPointBehavior CCPACSWingSegment::GetGetPointBehavior()
{
return getPointBehavior;
}

} // end namespace tigl

Expand Down
Loading

0 comments on commit 59ae251

Please sign in to comment.