void HYDROData_DTM::GetProperties( const Handle_HYDROData_Profile& theProfile,
gp_Pnt& theLowestPoint, gp_Vec2d& theDir,
- bool isNormalDir,
double& theZMin, double& theZMax )
{
theLowestPoint = theProfile->GetBottomPoint();
theProfile->GetRightPoint( aRight, true, true );
double x = aRight.X()-aLeft.X();
double y = aRight.Y()-aLeft.Y();
- if( isNormalDir )
- theDir = gp_Vec2d( -y, x );
- else
- theDir = gp_Vec2d( x, y );
+ theDir = gp_Vec2d( x, y );
HYDROData_Profile::ProfilePoints points = theProfile->GetProfilePoints();
int lo = points.Lower();
return Handle(Geom2d_Curve)();
}
+#include <GCE2d_MakeSegment.hxx>
+#include <Geom2dAPI_InterCurveCurve.hxx>
+bool IsCooriented( const Handle_HYDROData_Profile& theProfile1,
+ const Handle_HYDROData_Profile& theProfile2 )
+{
+ if( theProfile1==theProfile2 )
+ return true;
+
+ gp_XY lp1, rp1, lp2, rp2;
+ theProfile1->GetLeftPoint(lp1);
+ theProfile1->GetRightPoint(rp1);
+ theProfile2->GetLeftPoint(lp2);
+ theProfile2->GetRightPoint(rp2);
+
+ GCE2d_MakeSegment s1(lp1, lp2);
+ GCE2d_MakeSegment s2(rp1, rp2);
+
+ Geom2dAPI_InterCurveCurve inter;
+ inter.Init(s1, s2);
+ if (inter.NbPoints() == 0)
+ return true;
+ else
+ return false;
+}
+
Handle_Geom2d_BSplineCurve HYDROData_DTM::CreateHydraulicAxis(
const std::vector<Handle_HYDROData_Profile>& theProfiles,
std::vector<double>& theDistances )
{
size_t n = theProfiles.size();
+ if( n==1 )
+ Handle_Geom2d_BSplineCurve();
+
Handle_Geom2d_BSplineCurve aResult;
Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, (int)n );
for( size_t i = 1; i <= n; i++ )
{
Handle_HYDROData_Profile aProfile = theProfiles[i-1];
+ Handle_HYDROData_Profile aPrevProfile = i==1 ? theProfiles[i-1] : theProfiles[i-2];
+ Handle_HYDROData_Profile aNextProfile = i==n ? theProfiles[i-1] : theProfiles[i];
+
+ if( !IsCooriented( aProfile, aNextProfile ) )
+ {
+ gp_XY lp, rp;
+ aProfile->GetLeftPoint( lp, true );
+ aProfile->GetRightPoint( rp, true );
+ aProfile->SetLeftPoint( rp, true );
+ aProfile->SetRightPoint( lp, true );
+ }
aProfile->Update();
gp_Pnt aLowest;
- gp_Vec2d aTangent;
+ gp_Vec2d aNormal;
double zmin, zmax;
- GetProperties( aProfile, aLowest, aTangent, true, zmin, zmax );
- aTangent.Normalize();
+
+ gp_XYZ curP = aProfile->GetBottomPoint();
+ gp_XY curP2d = gp_XY(curP.X(), curP.Y());
+
+ gp_XYZ nextP;
+ if( i==n )
+ nextP = aPrevProfile->GetBottomPoint(true);
+ else
+ nextP = aNextProfile->GetBottomPoint(true);
+
+ gp_XY nextP2d = gp_XY(nextP.X(), nextP.Y());
+
+ gp_Vec2d aPrTangent;
+ GetProperties( aProfile, aLowest, aPrTangent, zmin, zmax );
+ aNormal.SetCoord( -aPrTangent.Y(), aPrTangent.X() );
+
+ gp_Vec2d aDirToNextProfile(nextP2d.X() - curP2d.X(), nextP2d.Y() - curP2d.Y() );
+ if( i==n )
+ aDirToNextProfile.Reverse();
+ if (aNormal.Dot(aDirToNextProfile) < 0)
+ aNormal.Reverse();
+
+ aNormal.Normalize();
points->SetValue( (int)i, gp_Pnt2d( aLowest.X(), aLowest.Y() ) );
- tangents.SetValue( (int)i, aTangent );
+ tangents.SetValue( (int)i, aNormal );
flags->SetValue( (int)i, Standard_True );
}
// Transformation of the coordinate systems
gp_Pnt aLowest;
double zmin, zmax;
- GetProperties( theProfile, aLowest, theDir, false, zmin, zmax );
+ GetProperties( theProfile, aLowest, theDir, zmin, zmax );
gp_Ax3 aStd3d( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( 1, 0, 0 ) );
gp_Ax3 aLocal( gp_Pnt( aLowest.X(), aLowest.Y(), 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( theDir.X(), theDir.Y(), 0 ) );
gp_Pnt lowestA, lowestB;
gp_Vec2d dirA, dirB;
- GetProperties( theProfileA, lowestA, dirA, false, zminA, zmaxA );
- GetProperties( theProfileB, lowestB, dirB, false, zminB, zmaxB );
+ GetProperties( theProfileA, lowestA, dirA, zminA, zmaxA );
+ GetProperties( theProfileB, lowestB, dirB, zminB, zmaxB );
double hmax = max( zmaxA-zminA, zmaxB-zminB );
gp_Pnt aLowest;
gp_Vec2d aDir;
double aZMin, aZMax;
- GetProperties( theProfiles[0], aLowest, aDir, true, aZMin, aZMax );
+ GetProperties( theProfiles[0], aLowest, aDir, aZMin, aZMax );
int aNbZSteps = (aZMax-aZMin)/theDDZ;
if( aNbSteps > ( 1<<16 ) || aNbZSteps > ( 1<<16 ) )
gp_Pnt lp;
gp_Vec2d dd;
double zmin, zmax;
- HYDROData_DTM::GetProperties( aProfile, lp, dd, false, zmin, zmax );
+ HYDROData_DTM::GetProperties( aProfile, lp, dd, zmin, zmax );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
- HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
+ /* HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );*/
aDoc->Close();
}