From f472d2421f82c15467a7a42d9392e3b494883f12 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Tue, 11 Aug 2015 14:49:18 +0200 Subject: [PATCH] =?utf8?q?tentative=20utilisation=20ligne=20altitude,=20no?= =?utf8?q?n=20disponible,=20probleme=20precision=20trac=C3=A9=20ligne=20gu?= =?utf8?q?ide?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/HYDROData/HYDROData_ChannelAltitude.cxx | 94 ++++++++++++++++++--- 1 file changed, 80 insertions(+), 14 deletions(-) diff --git a/src/HYDROData/HYDROData_ChannelAltitude.cxx b/src/HYDROData/HYDROData_ChannelAltitude.cxx index 1b956fea..1b1111c4 100644 --- a/src/HYDROData/HYDROData_ChannelAltitude.cxx +++ b/src/HYDROData/HYDROData_ChannelAltitude.cxx @@ -78,6 +78,7 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c return aResAltitude; } DEBTRACE("aChannel: " << aChannel->GetName().toStdString()); + Handle(HYDROData_Polyline3D) aGuideLine = aChannel->GetGuideLine(); if (aGuideLine.IsNull()) { @@ -85,6 +86,27 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c return aResAltitude; } DEBTRACE("aGuideLine: " << aGuideLine->GetName().toStdString()); + + Handle(HYDROData_PolylineXY) aGuideXY = aGuideLine->GetPolylineXY(); + if (aGuideXY.IsNull()) + { + DEBTRACE("aGuideXY.IsNull()"); + return aResAltitude; + } + DEBTRACE("aGuideXY: " << aGuideXY->GetName().toStdString()); + + Handle(HYDROData_ProfileUZ) aGuideUZ = aGuideLine->GetProfileUZ(); + if (aGuideUZ.IsNull()) + { + aGuideUZ = aGuideLine->GetChildProfileUZ(); // profile obtained from bathymetry + } + if (aGuideUZ.IsNull()) + { + DEBTRACE("aGuideUZ.IsNull()"); + return aResAltitude; + } + DEBTRACE("aGuideUZ: " << aGuideUZ->GetName().toStdString()); + Handle (HYDROData_Profile) aProfile = aChannel->GetProfile(); if (aProfile.IsNull()) { @@ -94,14 +116,17 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c // --- See GEOMImpl_ProjectionDriver.cxx - TopoDS_Shape aShape = aGuideLine->GetShape3D(); - double middleZ = -9999; - aGuideLine->GetMiddleZ(middleZ); // use the middle Z value of the 3d line to help the projection. - if (middleZ < -9000) - { - DEBTRACE("the middle Z value of the 3d line is incorrect"); - } - gp_Pnt P1(thePoint.X(), thePoint.Y(), middleZ); +// TopoDS_Shape aShape = aGuideLine->GetShape3D(); +// double middleZ = -9999; +// aGuideLine->GetMiddleZ(middleZ); // use the middle Z value of the 3d line to help the projection. +// if (middleZ < -9000) +// { +// DEBTRACE("the middle Z value of the 3d line is incorrect"); +// } +// gp_Pnt P1(thePoint.X(), thePoint.Y(), middleZ); + + TopoDS_Shape aShape = aGuideXY->GetShape(); + gp_Pnt P1(thePoint.X(), thePoint.Y(), 0); TopoDS_Shape aPoint = BRepBuilderAPI_MakeVertex(P1).Shape(); if (aPoint.IsNull() || aShape.IsNull()) @@ -234,18 +259,28 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c // Normalize parameter. TopoDS_Edge aSupportEdge = TopoDS::Edge(aSupportShape); Standard_Real aF, aL; - BRep_Tool::Range(aSupportEdge, aF, aL); - if (Abs(aL - aF) <= aTolConf) { DEBTRACE("Projection aborted : degenerated projection edge"); return aResAltitude; } + aParam = (aParam - aF)/(aL - aF); + + // Compute edge index. + TopExp_Explorer anExp(aShape, TopAbs_EDGE); + int anIndex = 0; + for (; anExp.More(); anExp.Next(), anIndex++) + { + if (aSupportShape.IsSame(anExp.Current())) + { + break; + } + } // Construct a projection vertex. const gp_Pnt &aPntProj = aDistShSh.PointOnShape2(i); - TopoDS_Shape aProj = BRepBuilderAPI_MakeVertex(aPntProj).Shape(); +// TopoDS_Shape aProj = BRepBuilderAPI_MakeVertex(aPntProj).Shape(); DEBTRACE("projection: (" << aPntProj.X() << ", " << aPntProj.Y() << ", " << aPntProj.Z() << ")"); gp_XY aProjXY = gp_XY(aPntProj.X(), aPntProj.Y()); aProjXY.Subtract(thePoint); @@ -275,16 +310,47 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c DEBTRACE("Projection aborted : non centered profile"); return aResAltitude; } + + // get the point with the same param on altitude profile + double zRef = 0; //aPntProj.Z(); + TopoDS_Shape aShapeUZ = aGuideUZ->GetShape(); + if (!aShapeUZ.IsNull()) + { + TopExp_Explorer anExpUZ(aShapeUZ, TopAbs_EDGE); + TopoDS_Edge anEdgeUZ; + int anI = 0; + for (; anExpUZ.More(); anExpUZ.Next(), anI++) + { + if (anI == anIndex) + { + anEdgeUZ = TopoDS::Edge(anExpUZ.Current()); + break; + } + } + if (!anEdgeUZ.IsNull()) + { + double anEdgePars[2]; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdgeUZ, anEdgePars[0], anEdgePars[1]); + gp_Pnt aVal; + aCurve->D0(aParam, aVal); + DEBTRACE("altitude point: " << aVal.X() << " "<< aVal.Y() << " "<< aVal.Z()); + zRef = aVal.Y(); + } + else zRef = 20; + } + else zRef = 20; + + // distance on section to get altitude if (i1 == aProfilePoints.Size()) // distance >= profile width { - aResAltitude = aPntProj.Z() + pt1.Y(); + aResAltitude = zRef + pt1.Y(); } else { double z = pt1.Y() + (pt2.Y() - pt1.Y())*(distance -pt1.X())/(pt2.X()-pt1.X()); - aResAltitude = aPntProj.Z() + z; + aResAltitude = zRef + z; } - DEBTRACE("altitude: " << aResAltitude << " delta: " << aResAltitude - aPntProj.Z()); + DEBTRACE("altitude: " << aResAltitude << " delta: " << aResAltitude - zRef); return aResAltitude; } } -- 2.39.2