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 5 // 6 // This file is part of Open CASCADE Technology software library. 7 // 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. 13 // 14 // Alternatively, this file may be used under the terms of Open CASCADE 15 // commercial license or contractual agreement. 16 17 #ifndef _Hatch_Hatcher_HeaderFile 18 #define _Hatch_Hatcher_HeaderFile 19 20 #include <Standard.hxx> 21 #include <Standard_DefineAlloc.hxx> 22 #include <Standard_Handle.hxx> 23 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 gp_Lin2d; 30 class gp_Dir2d; 31 class gp_Pnt2d; 32 33 34 //! The Hatcher is an algorithm to compute cross 35 //! hatchings in a 2d plane. It is mainly dedicated to 36 //! display purpose. 37 //! 38 //! Computing cross hatchings is a 3 steps process : 39 //! 40 //! 1. The users stores in the Hatcher a set of 2d 41 //! lines to be trimmed. Methods in the "Lines" 42 //! category. 43 //! 44 //! 2. The user trims the lines with a boundary. The 45 //! inside of a boundary is on the left side. Methods 46 //! in the "Trimming" category. 47 //! 48 //! 3. The user reads back the trimmed lines. Methods 49 //! in the "Results" category. 50 //! 51 //! The result is a set of parameter intervals on the 52 //! line. The first parameter of an Interval may be 53 //! RealFirst() and the last may be RealLast(). 54 //! 55 //! A line can be a line parallel to the axis (X or Y 56 //! line or a 2D line. 57 //! 58 //! The Hatcher has two modes : 59 //! 60 //! * The "Oriented" mode, where the orientation of 61 //! the trimming curves is considered. The hatch are 62 //! kept on the left of the trimming curve. In this 63 //! mode infinite hatch can be computed. 64 //! 65 //! * The "UnOriented" mode, where the hatch are 66 //! always finite. 67 class Hatch_Hatcher 68 { 69 public: 70 71 DEFINE_STANDARD_ALLOC 72 73 74 //! Returns a empty hatcher. <Tol> is the tolerance 75 //! for intersections. 76 Standard_EXPORT Hatch_Hatcher(const Standard_Real Tol, const Standard_Boolean Oriented = Standard_True); 77 78 void Tolerance (const Standard_Real Tol); 79 80 Standard_Real Tolerance() const; 81 82 //! Add a line <L> to be trimmed. <T> the type is 83 //! only kept from information. It is not used in the 84 //! computation. 85 Standard_EXPORT void AddLine (const gp_Lin2d& L, const Hatch_LineForm T = Hatch_ANYLINE); 86 87 //! Add an infinite line on direction <D> at distance 88 //! <Dist> from the origin to be trimmed. <Dist> may 89 //! be negative. 90 //! 91 //! If O is the origin of the 2D plane, and V the 92 //! vector perpendicular to D (in the direct direction). 93 //! 94 //! A point P is on the line if : 95 //! OP dot V = Dist 96 //! The parameter of P on the line is 97 //! OP dot D 98 Standard_EXPORT void AddLine (const gp_Dir2d& D, const Standard_Real Dist); 99 100 //! Add an infinite line parallel to the Y-axis at 101 //! abciss <X>. 102 Standard_EXPORT void AddXLine (const Standard_Real X); 103 104 //! Add an infinite line parallel to the X-axis at 105 //! ordinate <Y>. 106 Standard_EXPORT void AddYLine (const Standard_Real Y); 107 108 //! Trims the lines at intersections with <L>. 109 Standard_EXPORT void Trim (const gp_Lin2d& L, const Standard_Integer Index = 0); 110 111 //! Trims the lines at intersections with <L> in the 112 //! parameter range <Start>, <End> 113 Standard_EXPORT void Trim (const gp_Lin2d& L, const Standard_Real Start, const Standard_Real End, const Standard_Integer Index = 0); 114 115 //! Trims the line at intersection with the oriented 116 //! segment P1,P2. 117 Standard_EXPORT void Trim (const gp_Pnt2d& P1, const gp_Pnt2d& P2, const Standard_Integer Index = 0); 118 119 //! Returns the total number of intervals on all the 120 //! lines. 121 Standard_EXPORT Standard_Integer NbIntervals() const; 122 123 //! Returns the number of lines. 124 Standard_EXPORT Standard_Integer NbLines() const; 125 126 //! Returns the line of index <I>. 127 Standard_EXPORT const gp_Lin2d& Line (const Standard_Integer I) const; 128 129 //! Returns the type of the line of index <I>. 130 Standard_EXPORT Hatch_LineForm LineForm (const Standard_Integer I) const; 131 132 //! Returns True if the line of index <I> has a 133 //! constant X value. 134 Standard_Boolean IsXLine (const Standard_Integer I) const; 135 136 //! Returns True if the line of index <I> has a 137 //! constant Y value. 138 Standard_Boolean IsYLine (const Standard_Integer I) const; 139 140 //! Returns the X or Y coordinate of the line of index 141 //! <I> if it is a X or a Y line. 142 Standard_EXPORT Standard_Real Coordinate (const Standard_Integer I) const; 143 144 //! Returns the number of intervals on line of index <I>. 145 Standard_EXPORT Standard_Integer NbIntervals (const Standard_Integer I) const; 146 147 //! Returns the first parameter of interval <J> on 148 //! line <I>. 149 Standard_EXPORT Standard_Real Start (const Standard_Integer I, const Standard_Integer J) const; 150 151 //! Returns the first Index and Par2 of interval <J> on 152 //! line <I>. 153 Standard_EXPORT void StartIndex (const Standard_Integer I, const Standard_Integer J, Standard_Integer& Index, Standard_Real& Par2) const; 154 155 //! Returns the last parameter of interval <J> on 156 //! line <I>. 157 Standard_EXPORT Standard_Real End (const Standard_Integer I, const Standard_Integer J) const; 158 159 //! Returns the last Index and Par2 of interval <J> on 160 //! line <I>. 161 Standard_EXPORT void EndIndex (const Standard_Integer I, const Standard_Integer J, Standard_Integer& Index, Standard_Real& Par2) const; 162 163 164 165 166 protected: 167 168 169 170 171 172 private: 173 174 175 176 Standard_Real myToler; 177 Hatch_SequenceOfLine myLines; 178 Standard_Boolean myOrient; 179 180 181 }; 182 183 184 #include <Hatch_Hatcher.lxx> 185 186 187 188 189 190 #endif // _Hatch_Hatcher_HeaderFile 191