1 // Created on: 1995-03-06
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1995-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 _Poly_Connect_HeaderFile
18 #define _Poly_Connect_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <TColStd_Array1OfInteger.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Boolean.hxx>
27 class Poly_Triangulation;
29 //! Provides an algorithm to explore, inside a triangulation, the
30 //! adjacency data for a node or a triangle.
31 //! Adjacency data for a node consists of triangles which
33 //! Adjacency data for a triangle consists of:
34 //! - the 3 adjacent triangles which share an edge of the triangle,
35 //! - and the 3 nodes which are the other nodes of these adjacent triangles.
37 //! Inside a triangulation, a triangle T
38 //! has nodes n1, n2 and n3.
39 //! It has adjacent triangles AT1, AT2 and AT3 where:
40 //! - AT1 shares the nodes n2 and n3,
41 //! - AT2 shares the nodes n3 and n1,
42 //! - AT3 shares the nodes n1 and n2.
43 //! It has adjacent nodes an1, an2 and an3 where:
44 //! - an1 is the third node of AT1,
45 //! - an2 is the third node of AT2,
46 //! - an3 is the third node of AT3.
47 //! So triangle AT1 is composed of nodes n2, n3 and an1.
48 //! There are two ways of using this algorithm.
49 //! - From a given node you can look for one triangle that
50 //! passes through the node, then look for the triangles
51 //! adjacent to this triangle, then the adjacent nodes. You
52 //! can thus explore the triangulation step by step (functions
53 //! Triangle, Triangles and Nodes).
54 //! - From a given node you can look for all the triangles
55 //! that pass through the node (iteration method, using the
56 //! functions Initialize, More, Next and Value).
57 //! A Connect object can be seen as a tool which analyzes a
58 //! triangulation and translates it into a series of triangles. By
59 //! doing this, it provides an interface with other tools and
60 //! applications working on basic triangles, and which do not
61 //! work directly with a Poly_Triangulation.
68 //! Constructs an uninitialized algorithm.
69 Standard_EXPORT Poly_Connect();
71 //! Constructs an algorithm to explore the adjacency data of
72 //! nodes or triangles for the triangulation T.
73 Standard_EXPORT Poly_Connect (const Handle(Poly_Triangulation)& theTriangulation);
75 //! Initialize the algorithm to explore the adjacency data of
76 //! nodes or triangles for the triangulation theTriangulation.
77 Standard_EXPORT void Load (const Handle(Poly_Triangulation)& theTriangulation);
79 //! Returns the triangulation analyzed by this tool.
80 const Handle(Poly_Triangulation)& Triangulation() const { return myTriangulation; }
82 //! Returns the index of a triangle containing the node at
83 //! index N in the nodes table specific to the triangulation analyzed by this tool
84 Standard_Integer Triangle (const Standard_Integer N) const { return myTriangles (N); }
86 //! Returns in t1, t2 and t3, the indices of the 3 triangles
87 //! adjacent to the triangle at index T in the triangles table
88 //! specific to the triangulation analyzed by this tool.
90 //! Null indices are returned when there are fewer than 3
91 //! adjacent triangles.
92 void Triangles (const Standard_Integer T, Standard_Integer& t1, Standard_Integer& t2, Standard_Integer& t3) const
94 Standard_Integer index = 6*(T-1);
95 t1 = myAdjacents(index+1);
96 t2 = myAdjacents(index+2);
97 t3 = myAdjacents(index+3);
100 //! Returns, in n1, n2 and n3, the indices of the 3 nodes
101 //! adjacent to the triangle referenced at index T in the
102 //! triangles table specific to the triangulation analyzed by this tool.
104 //! Null indices are returned when there are fewer than 3 adjacent nodes.
105 void Nodes (const Standard_Integer T, Standard_Integer& n1, Standard_Integer& n2, Standard_Integer& n3) const
107 Standard_Integer index = 6*(T-1);
108 n1 = myAdjacents(index+4);
109 n2 = myAdjacents(index+5);
110 n3 = myAdjacents(index+6);
115 //! Initializes an iterator to search for all the triangles
116 //! containing the node referenced at index N in the nodes
117 //! table, for the triangulation analyzed by this tool.
118 //! The iterator is managed by the following functions:
119 //! - More, which checks if there are still elements in the iterator
120 //! - Next, which positions the iterator on the next element
121 //! - Value, which returns the current element.
122 //! The use of such an iterator provides direct access to the
123 //! triangles around a particular node, i.e. it avoids iterating on
124 //! all the component triangles of a triangulation.
126 //! Poly_Connect C(Tr);
128 //! (C.Initialize(n1);C.More();C.Next())
132 Standard_EXPORT void Initialize (const Standard_Integer N);
134 //! Returns true if there is another element in the iterator
135 //! defined with the function Initialize (i.e. if there is another
136 //! triangle containing the given node).
137 Standard_Boolean More() const { return mymore; }
139 //! Advances the iterator defined with the function Initialize to
140 //! access the next triangle.
141 //! Note: There is no action if the iterator is empty (i.e. if the
142 //! function More returns false).-
143 Standard_EXPORT void Next();
145 //! Returns the index of the current triangle to which the
146 //! iterator, defined with the function Initialize, points. This is
147 //! an index in the triangles table specific to the triangulation
148 //! analyzed by this tool
149 Standard_Integer Value() const { return mytr; }
153 Handle(Poly_Triangulation) myTriangulation;
154 TColStd_Array1OfInteger myTriangles;
155 TColStd_Array1OfInteger myAdjacents;
156 Standard_Integer mytr;
157 Standard_Integer myfirst;
158 Standard_Integer mynode;
159 Standard_Integer myothernode;
160 Standard_Boolean mysense;
161 Standard_Boolean mymore;
165 #endif // _Poly_Connect_HeaderFile