#include "HYDROData_Projection.h"
#include "HYDROData_ShapesGroup.h"
#include "HYDROData_ShapesTool.h"
+#include "HYDROData_Pipes.h"
#include <BRepOffsetAPI_MakePipeShell.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <BRepCheck_Analyzer.hxx>
+#include <BRepTools.hxx>
#include <TopExp.hxx>
if(aProfileWire.IsNull())
return;
- BRepOffsetAPI_MakePipeShell aMkSweep(aPathWire);
- aMkSweep.Add(aProfileWire,Standard_True, Standard_True);
- aMkSweep.SetTransitionMode(BRepBuilderAPI_RightCorner);
- //aMkSweep.SetMode(Standard_True);
- aMkSweep.Build();
- if(aMkSweep.IsDone()) {
- const TopoDS_Shape& aChannel = aMkSweep.Shape();
- BRepCheck_Analyzer aCheck(aChannel);
- if(aCheck.IsValid())
- {
- //BRepTools::Write(aChannel, "ChanV.brep");
- SetShape3D( aMkSweep.Shape());
- } else {
-#ifdef DEB_CHANNEL
- cout <<"NOT VALID" <<endl;
- BRepTools::Write(aChannel, "ChanNV.brep");
-#endif
- }
- }
-
- TopoDS_Shape a3dShape = GetShape3D();
- if ( a3dShape.IsNull() )
- return;
-
- // build 2d shape -- temporary solution!!
- TopoDS_Face aProj = HYDROData_Projection::MakeProjection( a3dShape );
- SetTopShape( aProj );
- if ( aProj.IsNull() )
- return;
-
- // Create the channel groups
- TopoDS_Shape aFirstShape = aMkSweep.FirstShape();
- TopoDS_Shape aLastShape = aMkSweep.LastShape();
- if ( aFirstShape.IsNull() || aFirstShape.ShapeType() != TopAbs_WIRE ||
- aLastShape.IsNull() || aLastShape.ShapeType() != TopAbs_WIRE )
- return;
-
- TopoDS_Wire anInletWire = TopoDS::Wire( aFirstShape );
- TopoDS_Wire anOutletWire = TopoDS::Wire( aLastShape );
-
- TopoDS_Vertex anInletFirstVert, anInletLastVert;
- TopExp::Vertices( anInletWire, anInletFirstVert, anInletLastVert );
-
- const TopTools_ListOfShape& aGeneratedLeftEdges = aMkSweep.Generated( anInletFirstVert );
- const TopTools_ListOfShape& aGeneratedRightEdges = aMkSweep.Generated( anInletLastVert );
-
- TopTools_SequenceOfShape aProjEdges;
- HYDROData_ShapesTool::ExploreShapeToShapes( aProj, TopAbs_EDGE, aProjEdges );
-
- TopTools_SequenceOfShape aProjLeftEdges;
- findEdges( aProjEdges, aGeneratedLeftEdges, aProjLeftEdges );
-
- TopTools_SequenceOfShape aProjRightEdges;
- findEdges( aProjEdges, aGeneratedRightEdges, aProjRightEdges );
+ //BRepTools::Write( aPathWire, "guideline.brep" );
+ //BRepTools::Write( aProfileWire, "profile.brep" );
- TopTools_SequenceOfShape aProjInletEdges;
- findEdges( aProjEdges, anInletWire, aProjInletEdges );
+ HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
+ aChannelConstructor.Create3dPresentation();
+ aChannelConstructor.Create2dPresentation();
+ SetShape3D( aChannelConstructor.Get3dPresentation() );
+ SetTopShape( aChannelConstructor.Get2dPresentation() );
- TopTools_SequenceOfShape aProjOutletEdges;
- findEdges( aProjEdges, anOutletWire, aProjOutletEdges );
+ /*TODO: groups via new API
QString aLeftGroupName = GetName() + "_Left_Bank";
Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
anOutGroup->SetName( anOutGroupName );
anOutGroup->SetShapes( aProjOutletEdges );
+ */
}
QColor HYDROData_Channel::DefaultFillingColor()
--- /dev/null
+// File: HYDROData_Pipes.cxx
+// Created: 25.12.13 16:39:40
+// Author: jgv@ROLEX
+// Copyright: Open CASCADE 2013
+
+#include <HYDROData_Pipes.h>
+#include <TopExp.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Iterator.hxx>
+#include <gp_Pln.hxx>
+#include <BRepOffsetAPI_NormalProjection.hxx>
+#include <BRepLib_MakeVertex.hxx>
+#include <BRepLib_MakeEdge.hxx>
+#include <BRepLib_MakeFace.hxx>
+#include <BRepLib_MakeWire.hxx>
+#include <BRepExtrema_ExtCC.hxx>
+#include <BRepBuilderAPI_Transform.hxx>
+#include <BRepOffsetAPI_MakePipeShell.hxx>
+#include <BRep_Tool.hxx>
+#include <Geom_Curve.hxx>
+
+HYDROData_Canal3dAnd2d::HYDROData_Canal3dAnd2d(const TopoDS_Wire& Profile,
+ const TopoDS_Wire& Guideline)
+ : myProfile(Profile), myGuideline(Guideline)
+{
+ TopExp::Vertices(myProfile, myLeftVertex, myRightVertex);
+
+ ProjectWireOntoXOY(myGuideline, myProjectedGuideline);
+ Make2dProfile();
+ SetMiddlePoint2d();
+ SetMiddlePoint3d();
+}
+
+Standard_Boolean HYDROData_Canal3dAnd2d::ProjectWireOntoXOY(const TopoDS_Wire& aWire,
+ TopoDS_Wire& ProjectedWire)
+{
+ gp_Pln XOY; //default plane
+ TopoDS_Face theXOYface = BRepLib_MakeFace(XOY);
+
+ BRepOffsetAPI_NormalProjection OrtProj(theXOYface);
+ OrtProj.Add(aWire);
+ //OrtProj.SetParams(...); ???
+ OrtProj.Build();
+ TopTools_ListOfShape Wires;
+ OrtProj.BuildWire(Wires);
+
+ if (Wires.Extent() != 1)
+ return Standard_False;
+
+ ProjectedWire = TopoDS::Wire(Wires.First());
+ return Standard_True;
+}
+
+TopoDS_Vertex HYDROData_Canal3dAnd2d::ProjectVertexOntoXOY(const TopoDS_Vertex& aVertex)
+{
+ gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+ gp_Pnt aProjPoint(aPoint.X(), aPoint.Y(), 0.);
+ TopoDS_Vertex aProjVertex = BRepLib_MakeVertex(aProjPoint);
+ return aProjVertex;
+}
+
+void HYDROData_Canal3dAnd2d::Make2dProfile()
+{
+ TopoDS_Vertex ProjectedLeftVertex = ProjectVertexOntoXOY(myLeftVertex);
+ TopoDS_Vertex ProjectedRightVertex = ProjectVertexOntoXOY(myRightVertex);
+ TopoDS_Edge anEdge = BRepLib_MakeEdge(ProjectedLeftVertex, ProjectedRightVertex);
+ myProjectedProfile = BRepLib_MakeWire(anEdge);
+}
+
+void HYDROData_Canal3dAnd2d::SetMiddlePoint2d()
+{
+ TopoDS_Vertex V1, V2;
+ TopExp::Vertices(myProjectedProfile, V1, V2);
+ gp_Pnt Pnt1 = BRep_Tool::Pnt(V1);
+ gp_Pnt Pnt2 = BRep_Tool::Pnt(V2);
+ myMiddlePoint2d.SetXYZ(0.5*(Pnt1.XYZ() + Pnt2.XYZ()));
+}
+
+void HYDROData_Canal3dAnd2d::SetMiddlePoint3d()
+{
+ gp_Lin MidLin(myMiddlePoint2d, gp::DZ());
+ TopoDS_Edge MidEdge = BRepLib_MakeEdge(MidLin);
+ TopoDS_Iterator itw(myProfile);
+ for (; itw.More(); itw.Next())
+ {
+ const TopoDS_Edge& anEdge = TopoDS::Edge(itw.Value());
+ BRepExtrema_ExtCC ExtremaEE(MidEdge, anEdge);
+ if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0)
+ {
+ for (Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++)
+ {
+ if (ExtremaEE.SquareDistance(i) <= Precision::Confusion())
+ {
+ myMiddlePoint3d = ExtremaEE.PointOnE1(i);
+ break;
+ }
+ }
+ }
+ }
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::SetTransformedProfile(const TopoDS_Wire& aProfile,
+ const TopoDS_Wire& aGuideline,
+ const gp_Pnt& aMiddlePoint)
+{
+ TopoDS_Wire aTransformedProfile;
+
+ TopoDS_Iterator itw(myProjectedGuideline);
+ TopoDS_Edge FirstEdge = TopoDS::Edge(itw.Value());
+ Standard_Real fpar, lpar;
+ Handle(Geom_Curve) FirstCurve = BRep_Tool::Curve(FirstEdge, fpar, lpar);
+ gp_Pnt StartPnt;
+ gp_Vec StartVec;
+ FirstCurve->D1(fpar, StartPnt, StartVec);
+
+ TopoDS_Vertex FirstOnGuide, LastOnGuide;
+ TopExp::Vertices(aGuideline, FirstOnGuide, LastOnGuide);
+ gp_Pnt StartPointOnGuide = BRep_Tool::Pnt(FirstOnGuide);
+
+ gp_Trsf Translation, Rotation;
+ Translation.SetTranslation(aMiddlePoint, StartPointOnGuide);
+ aTransformedProfile =
+ TopoDS::Wire(BRepBuilderAPI_Transform(aProfile, Translation, Standard_True)); //copy
+
+ gp_Vec Vertical(0.,0.,1.);
+ TopoDS_Vertex LeftVertex, RightVertex;
+ TopExp::Vertices(aTransformedProfile, LeftVertex, RightVertex);
+ gp_Pnt LeftPoint = BRep_Tool::Pnt(LeftVertex);
+ gp_Pnt RightPoint = BRep_Tool::Pnt(RightVertex);
+ gp_Vec LeftToRight(LeftPoint, RightPoint);
+ gp_Vec NormalToProfile = Vertical ^ LeftToRight;
+
+ gp_Vec AxisOfRotation = NormalToProfile ^ StartVec;
+ if (AxisOfRotation.Magnitude() <= gp::Resolution())
+ {
+ if (Vertical * LeftToRight < 0.)
+ {
+ gp_Ax1 theVertical(StartPointOnGuide, gp::DZ());
+ Rotation.SetRotation(theVertical, M_PI);
+ }
+ }
+ else
+ {
+ gp_Ax1 theAxis(StartPointOnGuide, AxisOfRotation);
+ Standard_Real theAngle = NormalToProfile.AngleWithRef(StartVec, AxisOfRotation);
+ Rotation.SetRotation(theAxis, theAngle);
+ }
+
+ aTransformedProfile =
+ TopoDS::Wire(BRepBuilderAPI_Transform(aTransformedProfile, Rotation, Standard_True)); //copy
+
+ return aTransformedProfile;
+}
+
+Standard_Boolean HYDROData_Canal3dAnd2d::Create3dPresentation()
+{
+ myTransformedProfile3d = SetTransformedProfile(myProfile, myGuideline, myMiddlePoint3d);
+
+ mySweep3d = new BRepOffsetAPI_MakePipeShell(myGuideline);
+ mySweep3d->SetMode(gp::DZ()); //optional
+ mySweep3d->Add(myTransformedProfile3d);
+ //mySweep3d->SetTransitionMode(BRepBuilderAPI_RightCorner); //optional
+ mySweep3d->Build();
+ if (!mySweep3d->IsDone())
+ return Standard_False;
+
+ myPipe3d = mySweep3d->Shape();
+ return Standard_True;
+}
+
+Standard_Boolean HYDROData_Canal3dAnd2d::Create2dPresentation()
+{
+ myTransformedProfile2d = SetTransformedProfile(myProjectedProfile, myProjectedGuideline, myMiddlePoint2d);
+
+ mySweep2d = new BRepOffsetAPI_MakePipeShell(myProjectedGuideline);
+ mySweep2d->SetMode(gp::DZ()); //optional
+ mySweep2d->Add(myTransformedProfile2d);
+ //mySweep2d->SetTransitionMode(BRepBuilderAPI_RightCorner); //optional
+ mySweep2d->Build();
+ if (!mySweep2d->IsDone())
+ return Standard_False;
+
+ myPipe2d = mySweep2d->Shape();
+ myInlet = TopoDS::Wire(mySweep2d->FirstShape());
+ myOutlet = TopoDS::Wire(mySweep2d->LastShape());
+ TopoDS_Vertex V1, V2, V3, V4;
+ TopExp::Vertices(myTransformedProfile2d, V1, V2);
+ TopExp::Vertices(myInlet, V3, V4);
+ gp_Pnt P1 = BRep_Tool::Pnt(V1);
+ gp_Pnt P3 = BRep_Tool::Pnt(V3);
+ if (P1.IsEqual(P3, Precision::Confusion()))
+ { myLeftVertex2d = V3; myRightVertex2d = V4; }
+ else
+ { myLeftVertex2d = V4; myRightVertex2d = V3; }
+
+ return Standard_True;
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetBank(const TopoDS_Vertex& aFreeVertex)
+{
+ TopoDS_Wire aBank;
+
+ TopTools_ListOfShape GeneratedShapes;
+ GeneratedShapes = mySweep2d->Generated(aFreeVertex);
+ BRepLib_MakeWire MW;
+ MW.Add(GeneratedShapes);
+ aBank = MW.Wire();
+
+ return aBank;
+}
+
+TopoDS_Shape HYDROData_Canal3dAnd2d::Get3dPresentation()
+{
+ return myPipe3d;
+}
+
+TopoDS_Shape HYDROData_Canal3dAnd2d::Get2dPresentation()
+{
+ return myPipe2d;
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetInlet()
+{
+ return myInlet;
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetOutlet()
+{
+ return myOutlet;
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetLeftBank()
+{
+ return GetBank(myLeftVertex2d);
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetRightBank()
+{
+ return GetBank(myRightVertex2d);
+}
--- /dev/null
+
+#ifndef HYDROData_Pipes_HeaderFile
+#define HYDROData_Pipes_HeaderFile
+
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Wire.hxx>
+#include <gp_Pnt.hxx>
+
+class BRepOffsetAPI_MakePipeShell;
+
+class HYDROData_Canal3dAnd2d
+{
+public:
+ HYDROData_Canal3dAnd2d( const TopoDS_Wire& Profile,
+ const TopoDS_Wire& Guideline );
+
+ Standard_Boolean Create3dPresentation();
+
+ Standard_Boolean Create2dPresentation();
+
+ Standard_Boolean ProjectWireOntoXOY(const TopoDS_Wire& aWire,
+ TopoDS_Wire& ProjectedWire);
+
+ void Make2dProfile();
+
+ TopoDS_Vertex ProjectVertexOntoXOY(const TopoDS_Vertex& aVertex);
+
+ void SetMiddlePoint2d();
+
+ void SetMiddlePoint3d();
+
+ TopoDS_Wire SetTransformedProfile(const TopoDS_Wire& aProfile,
+ const TopoDS_Wire& aGuideline,
+ const gp_Pnt& aMiddlePoint);
+
+ TopoDS_Wire GetBank(const TopoDS_Vertex& aFreeVertex);
+
+ //Queries
+ TopoDS_Shape Get3dPresentation();
+ TopoDS_Shape Get2dPresentation();
+ TopoDS_Wire GetLeftBank();
+ TopoDS_Wire GetRightBank();
+ TopoDS_Wire GetInlet();
+ TopoDS_Wire GetOutlet();
+
+private:
+
+ TopoDS_Wire myProfile;
+ TopoDS_Wire myGuideline;
+ TopoDS_Vertex myLeftVertex;
+ TopoDS_Vertex myRightVertex;
+ TopoDS_Vertex myLeftVertex2d;
+ TopoDS_Vertex myRightVertex2d;
+ gp_Pnt myMiddlePoint2d;
+ gp_Pnt myMiddlePoint3d;
+
+ TopoDS_Wire myProjectedProfile;
+ TopoDS_Wire myProjectedGuideline;
+ TopoDS_Wire myTransformedProfile3d;
+ TopoDS_Wire myTransformedProfile2d;
+ BRepOffsetAPI_MakePipeShell* mySweep3d;
+ BRepOffsetAPI_MakePipeShell* mySweep2d;
+
+ TopoDS_Shape myPipe3d;
+ TopoDS_Shape myPipe2d;
+ TopoDS_Wire myInlet;
+ TopoDS_Wire myOutlet;
+ //TopoDS_Shape myLeftBank;
+ //TopoDS_Shape myRightBank;
+};
+
+#endif