1 // Created on: 1999-04-26
2 // Created by: Andrey BETENEV
3 // Copyright (c) 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 _ShapeFix_ComposeShell_HeaderFile
18 #define _ShapeFix_ComposeShell_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <TopLoc_Location.hxx>
24 #include <TopoDS_Face.hxx>
25 #include <TopAbs_Orientation.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Standard_Real.hxx>
29 #include <Standard_Boolean.hxx>
30 #include <ShapeFix_Root.hxx>
31 #include <ShapeExtend_Status.hxx>
32 #include <ShapeFix_SequenceOfWireSegment.hxx>
33 #include <TColStd_SequenceOfInteger.hxx>
34 #include <TColStd_SequenceOfReal.hxx>
35 #include <TopTools_SequenceOfShape.hxx>
36 class ShapeExtend_CompositeSurface;
37 class ShapeAnalysis_TransferParameters;
38 class TopLoc_Location;
41 class ShapeExtend_WireData;
43 class ShapeFix_WireSegment;
47 class ShapeFix_ComposeShell;
48 DEFINE_STANDARD_HANDLE(ShapeFix_ComposeShell, ShapeFix_Root)
50 //! This class is intended to create a shell from the composite
51 //! surface (grid of surfaces) and set of wires.
52 //! It may be either division of the supporting surface of the
53 //! face, or creating a shape corresponding to face on composite
54 //! surface which is missing in CAS.CADE but exists in some other
57 //! It splits (if necessary) original face to several ones by
58 //! splitting lines which are joint lines on a supplied grid of
59 //! surfaces (U- and V- isolines of the composite surface).
60 //! There are two modes of work, which differ in the way of
61 //! handling faces on periodic surfaces:
63 //! - if ClosedMode is False (default), when splitting itself is
64 //! done as if surface were not periodic. The periodicity of the
65 //! underlying surface is taken into account by duplicating splitting
66 //! lines in the periodic direction, as necessary to split all
67 //! the wires (whole parametrical range of a face)
68 //! In this mode, some regularization procedures are performed
69 //! (indexation of splitted segments by patch numbers), and it is
70 //! expected to be more reliable and robust in case of bad shapes
72 //! - if ClosedMode is True, when everything on a periodic surfaces
73 //! is considered as modulo period. This allows to deal with wires
74 //! which are closed in 3d but not in 2d, with wires which may be
75 //! shifted on several periods in 2d etc. However, this mode is
76 //! less reliable since some regularizations do not work for it.
78 //! The work is made basing on pcurves of the edges. These pcurves
79 //! should already exist (for example, in the case of division of
80 //! existing face), then they are taken as is. The existing pcurves
81 //! should be assigned to one surface (face) for all edges,
82 //! this surface (face) will be used only for accessing pcurves,
83 //! and it may have any geometry.
85 //! All the modifications are recorded in the context tool
86 //! (ShapeBuild_ReShape).
87 class ShapeFix_ComposeShell : public ShapeFix_Root
93 //! Creates empty tool.
94 Standard_EXPORT ShapeFix_ComposeShell();
96 //! Initializes with composite surface, face and precision.
97 //! Here face defines both set of wires and way of getting
98 //! pcurves. Precision is used (together with tolerance of edges)
99 //! for handling subtle cases, such as tangential intersections.
100 Standard_EXPORT void Init (const Handle(ShapeExtend_CompositeSurface)& Grid, const TopLoc_Location& L, const TopoDS_Face& Face, const Standard_Real Prec);
102 //! Returns (modifiable) flag for special 'closed'
103 //! mode which forces ComposeShell to consider
104 //! all pcurves on closed surface as modulo period.
105 //! This can reduce reliability, but allows to deal
106 //! with wires closed in 3d but open in 2d (missing seam)
108 Standard_EXPORT Standard_Boolean& ClosedMode();
110 //! Performs the work on already loaded data.
111 Standard_EXPORT virtual Standard_Boolean Perform();
113 //! Splits edges in the original shape by grid.
114 //! This is a part of Perform() which does not produce any
115 //! resulting shape; the only result is filled context
116 //! where splittings are recorded.
118 //! NOTE: If edge is splitted, it is replaced by wire, and
119 //! order of edges in the wire corresponds to FORWARD orientation
121 Standard_EXPORT void SplitEdges();
123 //! Returns resulting shell or face (or Null shape if not done)
124 Standard_EXPORT const TopoDS_Shape& Result() const;
126 //! Queries status of last call to Perform()
127 //! OK : nothing done (some kind of error)
128 //! DONE1: splitting is done, at least one new face created
129 //! DONE2: splitting is done, several new faces obtained
130 //! FAIL1: misoriented wire encountered (handled)
131 //! FAIL2: recoverable parity error
132 //! FAIL3: edge with no pcurve on supporting face
133 //! FAIL4: unrecoverable algorithm error (parity check)
134 Standard_EXPORT Standard_Boolean Status (const ShapeExtend_Status status) const;
136 //! Creates new faces from the set of (closed) wires. Each wire
137 //! is put on corresponding patch in the composite surface,
138 //! and all pcurves on the initial (pseudo)face are reassigned to
139 //! that surface. If several wires are one inside another, single
141 Standard_EXPORT void DispatchWires (TopTools_SequenceOfShape& faces, ShapeFix_SequenceOfWireSegment& wires) const;
143 //! Sets tool for transfer parameters from 3d to 2d and vice versa.
144 Standard_EXPORT void SetTransferParamTool (const Handle(ShapeAnalysis_TransferParameters)& TransferParam);
146 //! Gets tool for transfer parameters from 3d to 2d and vice versa.
147 Standard_EXPORT Handle(ShapeAnalysis_TransferParameters) GetTransferParamTool() const;
152 DEFINE_STANDARD_RTTIEXT(ShapeFix_ComposeShell,ShapeFix_Root)
157 //! Fill sequence of wire segments by wires from myFace
158 //! (pre-loaded). It performs reorder so that edges in segments
159 //! are well-ordered. The context is applied to all wires
160 //! before using them.
161 Standard_EXPORT void LoadWires (ShapeFix_SequenceOfWireSegment& seqw) const;
163 //! Analyze tangencies and compute orientation code for wire segment
164 //! between two intersections: tells if segment is on left or right side
165 //! of cutting line, or tangent to it (by several points recomputed to 3d,
166 //! distance is compared with tolerance of corresponding edge).
167 Standard_EXPORT Standard_Integer ComputeCode (const Handle(ShapeExtend_WireData)& wire, const gp_Lin2d& line, const Standard_Integer begInd, const Standard_Integer endInd, const Standard_Real begPar, const Standard_Real endPar, const Standard_Boolean IsInternal = Standard_False);
169 //! Splits edges in the wire by given indices of edges and
170 //! parameters on them. Returns resulting wire and vertices
171 //! corresponding to splitting parameters. If two consequtive
172 //! splitting points are too near one to another (with tolerance
173 //! of edge), edge is divided in single point. In the same way,
174 //! splitting which is too near to end of edge, is not applied
175 //! (end vertex is returned instead).
177 //! NOTE: If edge is splitted, it is replaced by wire, and
178 //! order of edges in the wire corresponds to FORWARD orientation
180 Standard_EXPORT ShapeFix_WireSegment SplitWire (ShapeFix_WireSegment& wire, TColStd_SequenceOfInteger& indexes, const TColStd_SequenceOfReal& values, TopTools_SequenceOfShape& vertices, const TColStd_SequenceOfInteger& segcodes, const Standard_Boolean cutbyu, const Standard_Integer cutindex);
182 //! Split edges in the wire by cutting line.
183 //! Wires with FORWARD or REVERSED orientation are considered
186 //! All modifications (splitting) are recorded in context,
187 //! except splitting of wires marked as EXTERNAL
188 //! (they are supposed to be former cutting lines).
190 //! Method fills sequences of parameters of intersection points
191 //! of cutting line with all edges, their types, and corresponding
192 //! vertices (including ones created during splitting edges).
193 Standard_EXPORT Standard_Boolean SplitByLine (ShapeFix_WireSegment& wire, const gp_Lin2d& line, const Standard_Boolean cutbyu, const Standard_Integer cutindex, TColStd_SequenceOfReal& SplitLinePar, TColStd_SequenceOfInteger& SplitLineCode, TopTools_SequenceOfShape& SplitLineVertex);
195 //! Split edges in the sequence of wires by cutting line.
196 //! Wires with FORWARD or REVERSED orientation are considered
199 //! Parts of cutting line which get inside the face (defined by
200 //! parity check of intersections with all wires) are added
201 //! into that sequence (with orientation EXTERNAL). Each part
202 //! is represented by one-edge wire segment with no 3d curve.
203 //! They share common vertices with all wires they intersect.
205 //! All modifications (splitting) are recorded in context,
206 //! except splitting of wires marked as EXTERNAL
207 //! (they are supposed to be former cutting lines).
208 Standard_EXPORT void SplitByLine (ShapeFix_SequenceOfWireSegment& seqw, const gp_Lin2d& line, const Standard_Boolean cutbyu, const Standard_Integer cutindex);
210 //! Split initial set of (closed) wires by grid of lines corresponding
211 //! to joints between patches on the composite surface.
212 //! Parts of joint lines which get inside the face are also added
213 //! into the sequence as wires with orientation EXTERNAL.
214 //! They share common vertices with all wires they intersect.
215 //! All modifications (splitting) are recorded in context,
216 //! except splitting of joint edge itself and wires marked as
217 //! EXTERNAL (they supposed to be another joint edges).
218 Standard_EXPORT void SplitByGrid (ShapeFix_SequenceOfWireSegment& seqw);
220 //! Break wires into open wire segments by common vertices
221 //! (splitting points), so that each segment is either closed and
222 //! not touching others, or touches others at ends (have common
224 //! After that, each wire segment lies on its own patch of grid.
225 Standard_EXPORT void BreakWires (ShapeFix_SequenceOfWireSegment& seqw);
227 //! Collect set of wire segments (already splitted) into closed
228 //! wires. This is done by traversing all the segments in allowed
229 //! directions, starting only from the REVERSED and FORWARD and
230 //! taking EXTERNAL as necessary in fork points. Forks are detected
231 //! by common vertices. In fork point, most left way is seleccted
232 //! among all possible ways.
233 Standard_EXPORT void CollectWires (ShapeFix_SequenceOfWireSegment& wires, ShapeFix_SequenceOfWireSegment& seqw);
235 //! Creates new faces on one path of grid. It dispatches given loops
236 //! (wires) into one or several faces depending on their mutual
238 Standard_EXPORT void MakeFacesOnPatch (TopTools_SequenceOfShape& faces, const Handle(Geom_Surface)& surf, TopTools_SequenceOfShape& loops) const;
240 TopAbs_Orientation myOrient;
241 TopoDS_Shape myResult;
242 Standard_Integer myStatus;
248 Handle(ShapeExtend_CompositeSurface) myGrid;
249 TopLoc_Location myLoc;
251 Standard_Real myUResolution;
252 Standard_Real myVResolution;
253 Handle(ShapeAnalysis_TransferParameters) myTransferParamTool;
254 Standard_Boolean myInvertEdgeStatus;
255 Standard_Boolean myClosedMode;
256 Standard_Boolean myUClosed;
257 Standard_Boolean myVClosed;
258 Standard_Real myUPeriod;
259 Standard_Real myVPeriod;
270 #endif // _ShapeFix_ComposeShell_HeaderFile