return res;
}
-void HYDROData_DTM::Bank::reserve( int theNbPoints )
-{
- myPoints.reserve( theNbPoints );
- myDirs.reserve( theNbPoints );
-}
-
-void HYDROData_DTM::Bank::push_back( const gp_Pnt& thePnt, const gp_Dir& theTangent )
-{
- myPoints.push_back( thePnt );
- myDirs.push_back( theTangent );
-}
-
-void HYDROData_DTM::Bank::clear()
-{
- myPoints.clear();
- myDirs.clear();
-}
-
-TopoDS_Edge HYDROData_DTM::Bank::createEdge3d() const
-{
- size_t n = myPoints.size();
- if( n<2 )
- return TopoDS_Edge();
-
- Handle_Geom_BSplineCurve aCurve;
-
- Handle(TColgp_HArray1OfPnt) points = new TColgp_HArray1OfPnt( 1, (int)n );
- TColgp_Array1OfVec tangents( 1, (int)n );
- Handle(TColStd_HArray1OfBoolean) flags = new TColStd_HArray1OfBoolean( 1, (int)n );
-
- for( size_t i = 1; i <= n; i++ )
- {
- gp_Pnt aPnt = myPoints[i-1];
- gp_Vec aVec = myDirs[i-1];
- points->SetValue( (int)i, aPnt );
- tangents.SetValue( (int)i, aVec );
- flags->SetValue( (int)i, Standard_True );
- }
-
- GeomAPI_Interpolate anInterpolator( points, Standard_False, Standard_False );
- anInterpolator.Load( tangents, flags );
- anInterpolator.Perform();
- if( anInterpolator.IsDone() )
- {
- aCurve = anInterpolator.Curve();
- return BRepBuilderAPI_MakeEdge( aCurve ).Edge();
- }
- else
- return TopoDS_Edge();
-}
double step = GetSpatialStep();
const double EPS = 1E-3;
AltitudePoints points;
-
- myLeft.clear();
- myRight.clear();
+ AltitudePoints left;
+ AltitudePoints right;
+ std::vector<AltitudePoints> main_profiles;
+
if( ddz>EPS && step>EPS )
- points = Interpolate( profiles, ddz, step, &myLeft, &myRight );
+ points = Interpolate( profiles, ddz, step, left, right, main_profiles );
+
SetAltitudePoints( points );
+ //SetTopShape(); //2d
+ //SetShape3D(); //3d
}
#include <BRepLib_MakeEdge2d.hxx>
void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve,
- AltitudePoints& thePoints,
- Bank* theLeft, Bank* theRight, double dz )
+ AltitudePoints& thePoints, double dz )
{
Geom2dAdaptor_Curve anAdaptor( theHydraulicAxis );
TopoDS_Edge E2d = BRepLib_MakeEdge2d(theHydraulicAxis).Edge();
profile_dir.Normalize();
size_t n = theMidCurve.size();
- double min_param = 1E+15;
- double max_param = -1E+15;
- double z1, z2;
+ std::map<double, AltitudePoint> sorted_points;
for( size_t i=0; i<n; i++ )
{
double param1 = theMidCurve[i].U - theWidthCurve[i].U / 2;
double z = theMidCurve[i].Z;
- if( param1 < min_param )
- {
- min_param = param1;
- z1 = z;
- }
- if( param2 < min_param )
- {
- min_param = param2;
- z1 = z;
- }
- if( param1 > max_param )
- {
- max_param = param1;
- z2 = z;
- }
- if( param2 > max_param )
- {
- max_param = param2;
- z2 = z;
- }
-
AltitudePoint p3d_1( p1.X(), p1.Y(), z ), p3d_2( p2.X(), p2.Y(), z );
- thePoints.push_back( p3d_1 );
- thePoints.push_back( p3d_2 );
- }
- if( theLeft )
- {
- gp_Pnt2d left2d = point.Translated( min_param * profile_dir );
- gp_Pnt left( left2d.X(), left2d.Y(), z1 );
- theLeft->push_back( left, tangent_n );
- }
- if( theRight )
- {
- gp_Pnt2d right2d = point.Translated( max_param * profile_dir );
- gp_Pnt right( right2d.X(), right2d.Y(), z2 );
- theRight->push_back( right, tangent_n );
+ sorted_points[param1] = p3d_1;
+ sorted_points[param2] = p3d_2;
}
+
+ thePoints.reserve( sorted_points.size() );
+ std::map<double, AltitudePoint>::const_iterator it = sorted_points.begin(), last = sorted_points.end();
+ for( ; it!=last; it++ )
+ thePoints.push_back( it->second );
}
inline double max( double a, double b )
#include <BRepLib_MakeWire.hxx>
-HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate
+std::vector<HYDROData_Bathymetry::AltitudePoints> HYDROData_DTM::Interpolate
( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
const Handle_HYDROData_Profile& theProfileA,
double theXCurvA,
const Handle_HYDROData_Profile& theProfileB,
double theXCurvB,
- double theDDZ, int theNbSteps, bool isAddSecond,
- Bank* theLeft, Bank* theRight )
+ double theDDZ, int theNbSteps, bool isAddSecond )
{
double zminA, zmaxA, zminB, zmaxB;
gp_Pnt lowestA, lowestB;
size_t p = mid.size();
size_t q = p>0 ? 2*mid[0].size() : 1;
- AltitudePoints points;
- points.reserve( p*q );
+ std::vector<AltitudePoints> points;
+ points.resize( p );
+
for( size_t i=0; i<p; i++ )
- CurveTo3D( theHydraulicAxis, mid[i], wid[i], points, theLeft, theRight, dz );
+ {
+ points[i].reserve( q );
+ CurveTo3D( theHydraulicAxis, mid[i], wid[i], points[i], dz );
+ }
- BRepLib_MakeWire WM;
- for (int i =0; i < theLeft->myPoints.size() - 1; i++)
- WM.Add(BRepLib_MakeEdge(theLeft->myPoints[i], theLeft->myPoints[i+1]).Edge());
- TopoDS_Wire W = WM.Wire();
return points;
}
HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate
( const std::vector<Handle_HYDROData_Profile>& theProfiles,
double theDDZ, double theSpatialStep,
- Bank* theLeft,
- Bank* theRight )
+ AltitudePoints& theLeft,
+ AltitudePoints& theRight,
+ std::vector<AltitudePoints>& theMainProfiles )
{
AltitudePoints points;
size_t n = theProfiles.size();
if( aHydraulicAxis.IsNull() )
return points;
- int aNbStepsComplete = 0;
- for( size_t i=0, n1=n-1; i<n1; i++ )
- {
- double aDistance = distances[i+1]-distances[i];
- aNbStepsComplete += ( int(aDistance/theSpatialStep) /*+ 1*/ );
- }
- if( theLeft )
- theLeft->reserve( aNbStepsComplete );
- if( theRight )
- theRight->reserve( aNbStepsComplete );
-
+ theMainProfiles.reserve( n );
+
for( size_t i=0, n1=n-1; i<n1; i++ )
{
double aDistance = distances[i+1]-distances[i];
- int aNbSteps = int(aDistance/theSpatialStep) /*+ 1*/;
+ int aNbSteps = int(aDistance/theSpatialStep);
bool isAddSecond = i==n1-1;
- AltitudePoints local_points = Interpolate( aHydraulicAxis, theProfiles[i], distances[i],
- theProfiles[i+1], distances[i+1], theDDZ, aNbSteps, isAddSecond, theLeft, theRight );
+ // 1. Calculate interpolated profiles
+ std::vector<AltitudePoints> local_points = Interpolate( aHydraulicAxis, theProfiles[i], distances[i],
+ theProfiles[i+1], distances[i+1], theDDZ, aNbSteps, isAddSecond );
+ int lps = local_points.size();
+
+ // 2. Put all points into the global container
+ for( size_t j=0; j<lps; j++ )
+ {
+ const AltitudePoints& lp = local_points[j];
+ if( i==0 && j==0 )
+ points.reserve( lp.size() * n );
+ for( size_t k=0, ks=lp.size(); k<ks; k++ )
+ points.push_back( lp[k] );
+ }
+ // 3. Get left/right banks' points
if( i==0 )
- points.reserve( local_points.size() * ( n-1 ) );
+ {
+ theLeft.reserve( lps * n );
+ theRight.reserve( lps * n );
+ }
+ for( size_t j=0; j<lps; j++ )
+ {
+ const AltitudePoints& lp = local_points[j];
+ theLeft.push_back( lp[0] );
+ theRight.push_back( lp[lp.size()-1] );
+ }
- for( size_t j=0, m=local_points.size(); j<m; j++ )
- points.push_back( local_points[j] );
+ // 4. Get main profiles points
+ theMainProfiles.push_back( local_points[0] );
+ if( isAddSecond )
+ theMainProfiles.push_back( local_points[lps-1] );
}
return points;
}
-
-void HYDROData_DTM::CreateBankShapes( TopoDS_Edge& theLeft, TopoDS_Edge& theRight ) const
-{
- theLeft = myLeft.createEdge3d();
- theRight = myRight.createEdge3d();
-}
HYDRODATA_EXPORT virtual void Update();
- HYDRODATA_EXPORT void CreateBankShapes( TopoDS_Edge& theLeft, TopoDS_Edge& theRight ) const;
-
public:
struct PointUZ
{
double myXcurv;
gp_Vec2d myProfileDir;
};
- class Bank
- {
- public:
- void reserve( int theNbPoints );
- void push_back( const gp_Pnt& thePnt, const gp_Dir& theTangent );
- void clear();
- TopoDS_Edge createEdge3d() const;
-
- public:
- std::vector<gp_Pnt> myPoints;
- std::vector<gp_Dir> myDirs;
- };
protected:
friend class HYDROData_Iterator;
static void CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve,
- AltitudePoints& thePoints,
- Bank* theLeftBank = 0,
- Bank* theRightBank = 0,
- double dz = 0 );
+ AltitudePoints& thePoints, double dz );
static void Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCurveB,
int theNbSteps, std::vector<CurveUZ>& theInterpolation,
bool isAddSecond );
- static AltitudePoints Interpolate( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
- const Handle_HYDROData_Profile& theProfileA,
- double theXCurvA,
- const Handle_HYDROData_Profile& theProfileB,
- double theXCurvB,
- double theDDZ, int theNbSteps, bool isAddSecond,
- Bank* theLeftBank = 0,
- Bank* theRightBank = 0 );
+ static std::vector<AltitudePoints> Interpolate
+ ( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
+ const Handle_HYDROData_Profile& theProfileA,
+ double theXCurvA,
+ const Handle_HYDROData_Profile& theProfileB,
+ double theXCurvB,
+ double theDDZ, int theNbSteps, bool isAddSecond );
static AltitudePoints Interpolate( const std::vector<Handle_HYDROData_Profile>& theProfiles,
double theDDZ, double theSpatialStep,
- Bank* theLeftBank = 0,
- Bank* theRightBank = 0 );
-
-private:
- Bank myLeft;
- Bank myRight;
+ AltitudePoints& theLeft,
+ AltitudePoints& theRight,
+ std::vector<AltitudePoints>& theMainProfiles );
};
#endif