+TopTools_IndexedMapOfOrientedShape HYDROData_DTM::Create3DShape(const AltitudePoints& left,
+ const AltitudePoints& right,
+ const std::vector<AltitudePoints>& main_profiles)
+{
+ TopTools_IndexedMapOfOrientedShape ll;
+ //TopoDS_Wire LWire, RWire;
+ //PointsToWire(left, LWire);
+ //PointsToWire(right, RWire);
+ TopoDS_Edge LEdge, REdge;
+ PointsToEdge(left, LEdge);
+ PointsToEdge(right, REdge);
+ if (!LEdge.IsNull())
+ ll.Add(LEdge.Oriented(TopAbs_FORWARD));
+
+ for (int k = 0; k < main_profiles.size(); k++)
+ {
+ TopoDS_Wire W;
+ PointsToWire(main_profiles[k], W);
+ TopAbs_Orientation Ori = TopAbs_INTERNAL;
+ if (k == 0 || k == main_profiles.size() - 1)
+ Ori = TopAbs_FORWARD;
+ ll.Add(W.Oriented(Ori));
+ }
+
+ if (!REdge.IsNull())
+ ll.Add(REdge.Oriented(TopAbs_FORWARD));
+ //yes, add subshapes in this order (left + profiles + right)
+ //otherwise the projected wire will be non-manifold
+
+ return ll;
+}
+
+
+void HYDROData_DTM::Update()
+{
+ AltitudePoints points;
+ TopoDS_Shape Out3dPres;
+ TopoDS_Shape Out2dPres;
+ TopoDS_Shape OutLeftB;
+ TopoDS_Shape OutRightB;
+ TopoDS_Shape OutInlet;
+ TopoDS_Shape OutOutlet;
+
+ HYDROData_SequenceOfObjects objs = GetProfiles();
+ double ddz = GetDDZ();
+ double step = GetSpatialStep();
+ std::set<int> InvInd;
+ bool WireIntersections; //__TODO
+ CreateProfilesFromDTM( objs, ddz, step, points, Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, true, true, InvInd, -1, WireIntersections );
+ SetAltitudePoints( points );
+
+ SetShape( DataTag_LeftBankShape, OutLeftB);
+ SetShape( DataTag_RightBankShape, OutRightB);
+ SetShape( DataTag_InletShape, OutInlet);
+ SetShape( DataTag_OutletShape, OutOutlet );
+ SetShape( DataTag_3DShape, Out3dPres );
+ SetShape( DataTag_2DShape, Out2dPres );
+
+ HYDROData_Bathymetry::Update();
+}
+
+void HYDROData_DTM::GetPresentationShapes( TopoDS_Shape& Out3dPres,
+ TopoDS_Shape& Out2dPres,
+ TopoDS_Shape& OutLeftB,
+ TopoDS_Shape& OutRightB,
+ TopoDS_Shape& OutInlet,
+ TopoDS_Shape& OutOutlet )
+{
+ //without update!
+ OutLeftB = GetShape( DataTag_LeftBankShape);
+ OutRightB = GetShape( DataTag_RightBankShape);
+ OutInlet = GetShape( DataTag_InletShape);
+ OutOutlet = GetShape( DataTag_OutletShape );
+ Out3dPres = GetShape( DataTag_3DShape );
+ Out2dPres = GetShape( DataTag_2DShape );
+}
+void HYDROData_DTM::CreateProfilesFromDTM (const HYDROData_SequenceOfObjects& InpProfiles,
+ double ddz,
+ double step,
+ AltitudePoints& points,
+ TopoDS_Shape& Out3dPres,
+ TopoDS_Shape& Out2dPres,
+ TopoDS_Shape& OutLeftB,
+ TopoDS_Shape& OutRightB,
+ TopoDS_Shape& OutInlet,
+ TopoDS_Shape& OutOutlet,
+ bool Create3dPres,
+ bool Create2dPres,
+ std::set<int>& InvInd,
+ int thePntsLimit,
+ bool& WireIntersections)
+{
+ int aLower = InpProfiles.Lower(), anUpper = InpProfiles.Upper();
+ size_t n = anUpper - aLower + 1;
+
+ std::vector<Handle(HYDROData_Profile)> profiles;
+ profiles.reserve( n );
+ for( int i=aLower; i<=anUpper; i++ )
+ {
+ Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( InpProfiles.Value( i ) );
+ if( !aProfile.IsNull() )
+ profiles.push_back( aProfile );
+ }
+ const double EPS = 1E-3;
+ AltitudePoints left;
+ AltitudePoints right;
+ std::vector<AltitudePoints> main_profiles;
+
+ if( thePntsLimit > 0 )
+ {
+ int aNbPoints = EstimateNbPoints( profiles, ddz, step );
+ if( aNbPoints < 0 || aNbPoints > thePntsLimit )
+ return;
+ }
+
+ if( ddz>EPS && step>EPS )
+ CreateProfiles(profiles, ddz, step, left, right, points, main_profiles,
+ Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, Create3dPres, Create2dPres, InvInd, WireIntersections );
+}
+
+bool HYDROData_DTM::GetPlanarFaceFromBanks( const TopoDS_Edge& LB, const TopoDS_Edge& RB, TopoDS_Face& outF,
+ TopTools_SequenceOfShape* Boundr)
+{
+ BRep_Builder BB;
+ TopoDS_Face F;
+ Handle_Geom_Plane refpl = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1));
+
+ TopoDS_Vertex VFI, VLI, VFO, VLO;
+ TopoDS_Edge prLB;
+ TopoDS_Edge prRB;
+
+
+ BRepAdaptor_Curve LBAD(LB);
+ Handle_Geom_Curve LBPC = GeomProjLib::ProjectOnPlane(LBAD.Curve().Curve(), refpl, gp_Dir(0, 0, -1), 1 );
+ prLB = BRepLib_MakeEdge(LBPC).Edge();
+
+ BRepAdaptor_Curve RBAD(RB);
+ Handle_Geom_Curve RBPC = GeomProjLib::ProjectOnPlane(RBAD.Curve().Curve(), refpl, gp_Dir(0, 0, -1), 1 );
+ prRB = BRepLib_MakeEdge(RBPC).Edge();
+
+ TopExp::Vertices(prLB, VFI, VFO, 1);
+ TopExp::Vertices(prRB, VLI, VLO, 1);
+ TopoDS_Edge prIL = BRepLib_MakeEdge(VFI, VLI).Edge();
+ TopoDS_Edge prOL = BRepLib_MakeEdge(VFO, VLO).Edge();
+ TopoDS_Wire prW = BRepLib_MakeWire(prLB, prIL, prOL, prRB).Wire();
+ outF = BRepBuilderAPI_MakeFace(refpl->Pln(), prW, 1).Face();
+
+ if (Boundr)
+ {
+ Boundr->Append(prLB);
+ Boundr->Append(prIL);
+ Boundr->Append(prOL);
+ Boundr->Append(prRB);
+ }
+
+ ShapeAnalysis_Wire WA(prW, outF, Precision::Confusion());
+ bool res = WA.CheckSelfIntersection();
+ return !res;
+}
+
+void HYDROData_DTM::CreateProfiles(const std::vector<Handle(HYDROData_Profile)>& theProfiles,
+ double theDDZ,
+ double theSpatialStep,
+ AltitudePoints& theOutLeft,
+ AltitudePoints& theOutRight,
+ AltitudePoints& theOutPoints,
+ std::vector<AltitudePoints>& theOutMainProfiles,
+ TopoDS_Shape& Out3dPres,
+ TopoDS_Shape& Out2dPres,
+ TopoDS_Shape& OutLeftB,
+ TopoDS_Shape& OutRightB,
+ TopoDS_Shape& OutInlet,
+ TopoDS_Shape& OutOutlet,
+ bool Create3dPres,
+ bool Create2dPres,
+ std::set<int>& InvInd,
+ bool& ProjStat)
+{
+ if (theProfiles.empty())
+ return;
+ theOutPoints = Interpolate( theProfiles, theDDZ, theSpatialStep, theOutLeft, theOutRight, theOutMainProfiles, InvInd );
+ //note that if Create3dPres is false => Create2dPres flag is meaningless!
+ if( theOutPoints.empty() )
+ return;
+
+ if (Create3dPres)
+ {
+ TopTools_IndexedMapOfOrientedShape ll = Create3DShape( theOutLeft, theOutRight, theOutMainProfiles);
+
+ if (ll.IsEmpty())
+ return;
+ BRep_Builder BB;
+ TopoDS_Compound cmp;
+ BB.MakeCompound(cmp);
+ for (int i = 1; i <= ll.Extent(); i++)
+ BB.Add(cmp, ll(i));
+
+ Out3dPres = cmp;
+
+ //same order as in HYDROData_DTM::Update()
+ OutLeftB = ll(1);
+ OutRightB = ll(ll.Extent());
+ OutInlet = ll(2);
+ OutOutlet = ll(ll.Extent() - 1);
+
+ if (Create2dPres)
+ {
+ TopoDS_Face outF;
+ ProjStat = GetPlanarFaceFromBanks(TopoDS::Edge(OutLeftB), TopoDS::Edge(OutRightB), outF, NULL);
+ Out2dPres = outF;
+ };
+ }
+}
+
+
+
+
+void HYDROData_DTM::GetProperties( const Handle(HYDROData_Profile)& theProfile,