1 // Created on: 1992-08-19
2 // Created by: Modelistation
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Hatch_Hatcher_HeaderFile
18 #define _Hatch_Hatcher_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Real.hxx>
25 #include <Hatch_SequenceOfLine.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Hatch_LineForm.hxx>
28 #include <Standard_Integer.hxx>
29 class Standard_OutOfRange;
35 //! The Hatcher is an algorithm to compute cross
36 //! hatchings in a 2d plane. It is mainly dedicated to
39 //! Computing cross hatchings is a 3 steps process :
41 //! 1. The users stores in the Hatcher a set of 2d
42 //! lines to be trimmed. Methods in the "Lines"
45 //! 2. The user trims the lines with a boundary. The
46 //! inside of a boundary is on the left side. Methods
47 //! in the "Trimming" category.
49 //! 3. The user reads back the trimmed lines. Methods
50 //! in the "Results" category.
52 //! The result is a set of parameter intervals on the
53 //! line. The first parameter of an Interval may be
54 //! RealFirst() and the last may be RealLast().
56 //! A line can be a line parallel to the axis (X or Y
57 //! line or a 2D line.
59 //! The Hatcher has two modes :
61 //! * The "Oriented" mode, where the orientation of
62 //! the trimming curves is considered. The hatch are
63 //! kept on the left of the trimming curve. In this
64 //! mode infinite hatch can be computed.
66 //! * The "UnOriented" mode, where the hatch are
75 //! Returns a empty hatcher. <Tol> is the tolerance
76 //! for intersections.
77 Standard_EXPORT Hatch_Hatcher(const Standard_Real Tol, const Standard_Boolean Oriented = Standard_True);
79 void Tolerance (const Standard_Real Tol);
81 Standard_Real Tolerance() const;
83 //! Add a line <L> to be trimmed. <T> the type is
84 //! only kept from information. It is not used in the
86 Standard_EXPORT void AddLine (const gp_Lin2d& L, const Hatch_LineForm T = Hatch_ANYLINE);
88 //! Add an infinite line on direction <D> at distance
89 //! <Dist> from the origin to be trimmed. <Dist> may
92 //! If O is the origin of the 2D plane, and V the
93 //! vector perpendicular to D (in the direct direction).
95 //! A point P is on the line if :
97 //! The parameter of P on the line is
99 Standard_EXPORT void AddLine (const gp_Dir2d& D, const Standard_Real Dist);
101 //! Add an infinite line parallel to the Y-axis at
103 Standard_EXPORT void AddXLine (const Standard_Real X);
105 //! Add an infinite line parallel to the X-axis at
107 Standard_EXPORT void AddYLine (const Standard_Real Y);
109 //! Trims the lines at intersections with <L>.
110 Standard_EXPORT void Trim (const gp_Lin2d& L, const Standard_Integer Index = 0);
112 //! Trims the lines at intersections with <L> in the
113 //! parameter range <Start>, <End>
114 Standard_EXPORT void Trim (const gp_Lin2d& L, const Standard_Real Start, const Standard_Real End, const Standard_Integer Index = 0);
116 //! Trims the line at intersection with the oriented
118 Standard_EXPORT void Trim (const gp_Pnt2d& P1, const gp_Pnt2d& P2, const Standard_Integer Index = 0);
120 //! Returns the total number of intervals on all the
122 Standard_EXPORT Standard_Integer NbIntervals() const;
124 //! Returns the number of lines.
125 Standard_EXPORT Standard_Integer NbLines() const;
127 //! Returns the line of index <I>.
128 Standard_EXPORT const gp_Lin2d& Line (const Standard_Integer I) const;
130 //! Returns the type of the line of index <I>.
131 Standard_EXPORT Hatch_LineForm LineForm (const Standard_Integer I) const;
133 //! Returns True if the line of index <I> has a
134 //! constant X value.
135 Standard_Boolean IsXLine (const Standard_Integer I) const;
137 //! Returns True if the line of index <I> has a
138 //! constant Y value.
139 Standard_Boolean IsYLine (const Standard_Integer I) const;
141 //! Returns the X or Y coordinate of the line of index
142 //! <I> if it is a X or a Y line.
143 Standard_EXPORT Standard_Real Coordinate (const Standard_Integer I) const;
145 //! Returns the number of intervals on line of index <I>.
146 Standard_EXPORT Standard_Integer NbIntervals (const Standard_Integer I) const;
148 //! Returns the first parameter of interval <J> on
150 Standard_EXPORT Standard_Real Start (const Standard_Integer I, const Standard_Integer J) const;
152 //! Returns the first Index and Par2 of interval <J> on
154 Standard_EXPORT void StartIndex (const Standard_Integer I, const Standard_Integer J, Standard_Integer& Index, Standard_Real& Par2) const;
156 //! Returns the last parameter of interval <J> on
158 Standard_EXPORT Standard_Real End (const Standard_Integer I, const Standard_Integer J) const;
160 //! Returns the last Index and Par2 of interval <J> on
162 Standard_EXPORT void EndIndex (const Standard_Integer I, const Standard_Integer J, Standard_Integer& Index, Standard_Real& Par2) const;
177 Standard_Real myToler;
178 Hatch_SequenceOfLine myLines;
179 Standard_Boolean myOrient;
185 #include <Hatch_Hatcher.lxx>
191 #endif // _Hatch_Hatcher_HeaderFile