1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef HYDRODATA_TOPOCURVE_H
20 #define HYDRODATA_TOPOCURVE_H
23 #include <Geom_BSplineCurve.hxx>
24 #include <HYDROData.h>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Vertex.hxx>
30 #include <Adaptor3d_Curve.hxx>
34 //! Get the parameter of the projected point on the curve, and return the distance of the original point
35 double ProjectPointToCurve(const gp_XYZ& thePoint,
36 const Adaptor3d_Curve& theCurve,
37 double& theParameter);
39 //! The type represents a 1 manifold connected topo curve
40 //! with forward orientation.
41 class HYDROData_TopoCurve
44 //! The default computer.
45 HYDROData_TopoCurve() {}
47 //! Constructs the curve from the edge.
48 HYDROData_TopoCurve(const TopoDS_Edge& theEdge) {myEdges.push_back(theEdge);}
50 //! Initializes the curve by the wire.
51 //! Returns 'false' if the wire is not 1 manifold or
52 //! is disconnected or is empty.
53 HYDRODATA_EXPORT bool Initialize(const TopoDS_Wire& theWire);
55 //! Converts the curve to the wire.
56 HYDRODATA_EXPORT TopoDS_Wire Wire() const;
58 //! Returns 'true' if the curve has no edges.
59 bool IsEmpty() const {return myEdges.empty();}
61 //! Returns 'true' whether the curve is closed.
64 return TopExp::LastVertex(myEdges.back(), Standard_True).
65 IsSame(TopExp::FirstVertex(myEdges.front(), Standard_True)) ==
69 //! Returns the curve edges.
70 const std::list<TopoDS_Edge>& Edges() const {return myEdges;}
72 //! Returns the curve edges.
73 std::list<TopoDS_Edge>& Edges() {return myEdges;}
75 //! Cuts the curve in the given parameter of the given edge and
76 //! fills the cut part.
77 //! Returns 'true' if:
78 //! - the curve is open and was split into two parts or
79 //! - the curve is closed and was cut into an open curve.
80 HYDRODATA_EXPORT bool Cut(
81 const std::list<TopoDS_Edge>::iterator& theEdgePosition,
82 const double theParameter,
83 HYDROData_TopoCurve& theCurve);
85 //! Cuts the curve in the given parameter of the given edge and
86 //! fills the cut parts.
87 HYDRODATA_EXPORT void Cut(
88 const std::list<TopoDS_Edge>::const_iterator& theEdgePosition,
89 const double theParameter,
90 HYDROData_TopoCurve& theCurve1,
91 HYDROData_TopoCurve& theCurve2) const;
93 //! Cuts the curve at the parameters.
94 //! Each parameter vector list corresponds to the curve edge and
95 //! is ordered in the ascending order.
96 HYDRODATA_EXPORT bool Cut(
97 const std::deque<std::list<double> >& theParameters,
98 std::deque<HYDROData_TopoCurve>& theCurves) const;
100 //! Projects the point to the nearest point of the curve.
101 //! Fills the iterator of the edge and
102 //! the parameter on the edge for the projection.
103 //! Returns the square distance from the point to the projection.
104 HYDRODATA_EXPORT double Project(
105 const gp_XYZ& thePoint,
106 std::list<TopoDS_Edge>::const_iterator& theEdgeIterator,
107 double& theParameter) const;
109 //! Adds the intersection parameters of the curve with the wire to the vector.
110 HYDRODATA_EXPORT int Intersect(
111 const TopoDS_Wire& theWire,
112 std::deque<std::list<double> >& theParameters) const;
114 //! Replaces the first vertex by the last one.
115 HYDRODATA_EXPORT void CloseCurve();
117 //! Topologically extends the curve by the parameter at the position:
118 //! 0 - start, 1 - end.
119 HYDRODATA_EXPORT void Merge(
120 const int thePosition, HYDROData_TopoCurve& theCurve);
122 //! Topologically merges the curve to the curves.
123 HYDRODATA_EXPORT void Merge(
124 const double theTolerance, std::deque<HYDROData_TopoCurve>& theCurves);
126 //! Topologically merges the wire curve to the curves.
127 //! Returns 'false' if the wire is not a curve.
129 const double theTolerance,
130 const TopoDS_Wire& theWire,
131 std::deque<HYDROData_TopoCurve>& theCurves)
133 HYDROData_TopoCurve aCurve;
134 const bool aResult = aCurve.Initialize(theWire);
137 aCurve.Merge(theTolerance, theCurves);
142 //! Topologically connects the curve to the first open one of the curves.
143 //! If the gap between the curve and the first open curve is more than the
144 //! tolerance then the gap is smoothly filled by a curve.
145 //! It is assumed that only one of the parameter curves may be open.
146 //! If the curve is closed then it is added to the curves.
147 HYDRODATA_EXPORT bool Connect(
148 const Standard_Real theTolerance,
149 std::deque<HYDROData_TopoCurve>& theCurves);
151 //! Works by the same way as the above method.
153 const Standard_Real theTolerance,
154 const TopoDS_Wire& theWire,
155 std::deque<HYDROData_TopoCurve>& theCurves)
157 HYDROData_TopoCurve aCurve;
158 if (aCurve.Initialize(theWire))
160 return aCurve.Connect(theTolerance, theCurves);
166 //! Creates a B-spline piecewise curve corresponding to the curve
167 //! and using the deflection.
168 //! Returns the piece count.
169 //! Returns 0 in the case of any error.
170 HYDRODATA_EXPORT int BSplinePiecewiseCurve(
171 const double theDeflection, HYDROData_TopoCurve& theCurve) const;
173 //! Calculates the values of the curve in its knots.
174 //! Returns 'false' if a curve edge has a non-identity location or a non-forward
175 //! orientation or has no a B-spline representation.
176 HYDRODATA_EXPORT bool ValuesInKnots(std::list<gp_XYZ>& theValues) const;
179 //! Transfers the edges of the parameter to this curve end.
180 void append(HYDROData_TopoCurve& theCurve)
181 {myEdges.splice(myEdges.end(), theCurve.myEdges);}
183 //! Transfers the edges of the parameter to this curve start.
184 void prepend(HYDROData_TopoCurve& theCurve)
185 {myEdges.splice(myEdges.begin(), theCurve.myEdges);}
187 std::list<TopoDS_Edge> myEdges; //!< The ordered curve edges.