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 #include <Poly_Connect.hxx>
19 #include <Poly_Triangle.hxx>
20 #include <Poly_Triangulation.hxx>
22 // this structure records one of the edges starting from a node
25 polyedge* next; // the next edge in the list
26 Standard_Integer nd; // the second node of the edge
27 Standard_Integer nt[2]; // the two adjacent triangles
28 Standard_Integer nn[2]; // the two adjacent nodes
32 //=======================================================================
33 //function : Poly_Connect
35 //=======================================================================
36 Poly_Connect::Poly_Connect()
47 //=======================================================================
48 //function : Poly_Connect
50 //=======================================================================
51 Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& theTriangulation)
52 : myTriangulation (theTriangulation),
53 myTriangles (1, theTriangulation->NbNodes()),
54 myAdjacents (1, 6 * theTriangulation->NbTriangles()),
62 Load (theTriangulation);
65 //=======================================================================
68 //=======================================================================
69 void Poly_Connect::Load (const Handle(Poly_Triangulation)& theTriangulation)
71 myTriangulation = theTriangulation;
79 const Standard_Integer nbNodes = myTriangulation->NbNodes();
80 const Standard_Integer nbTriangles = myTriangulation->NbTriangles();
82 const Standard_Integer aNbAdjs = 6 * nbTriangles;
83 if (myTriangles.Size() != nbNodes)
85 TColStd_Array1OfInteger aTriArray (1, nbNodes);
86 myTriangles.Move (std::move (aTriArray));
88 if (myAdjacents.Size() != aNbAdjs)
90 TColStd_Array1OfInteger anAdjArray (1, aNbAdjs);
91 myAdjacents.Move (std::move (anAdjArray));
98 // We first build an array of the list of edges connected to the nodes
99 // create an array to store the edges starting from the vertices
101 // the last node is not used because edges are stored at the lower node index
102 polyedge** edges = new polyedge*[nbNodes];
103 for (i = 0; i < nbNodes; i++) edges[i] = 0;
106 // loop on the triangles
107 Standard_Integer j,k,n[3],n1,n2;
108 const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
110 for (i = 1; i <= nbTriangles; i++) {
113 triangles(i).Get(n[0],n[1],n[2]);
115 // Update the myTriangles array
116 myTriangles(n[0]) = i;
117 myTriangles(n[1]) = i;
118 myTriangles(n[2]) = i;
120 // update the edge lists
121 for (j = 0; j < 3; j++) {
122 k = (j+1) % 3; // the following node of the edge
132 // edge from n1 to n2 with n1 < n2
133 // insert in the list of n1
135 polyedge* ced = edges[n1];
137 // the edge already exists
145 // create the edge if not found
147 ced->next = edges[n1];
151 ced->nn[0] = n[3-j-k]; // the third node
156 // just mark the adjacency if found
158 ced->nn[1] = n[3-j-k]; // the third node
164 // now complete the myAdjacents array
166 Standard_Integer index = 1;
167 for (i = 1; i <= nbTriangles; i++) {
170 triangles(i).Get(n[0],n[1],n[2]);
173 for (j = 0; j < 3; j++) {
174 k = (j+1) % 3; // the following node of the edge
184 // edge from n1 to n2 with n1 < n2
185 // find in the list of n1
187 polyedge* ced = edges[n1];
188 while (ced->nd != n2)
191 // Find the adjacent triangle
192 Standard_Integer l = 0;
193 if (ced->nt[0] == i) l = 1;
195 myAdjacents(index) = ced->nt[l];
196 myAdjacents(index+3) = ced->nn[l];
202 // destroy the edges array
203 for (i = 0; i < nbNodes; i++) {
204 polyedge* ced = edges[i];
206 polyedge* tmp = ced->next;
214 //=======================================================================
215 //function : Initialize
217 //=======================================================================
219 void Poly_Connect::Initialize(const Standard_Integer N)
222 myfirst = Triangle(N);
224 mysense = Standard_True;
225 mymore = (myfirst != 0);
228 Standard_Integer i, no[3];
229 const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
230 triangles(myfirst).Get(no[0], no[1], no[2]);
231 for (i = 0; i < 3; i++)
232 if (no[i] == mynode) break;
233 myothernode = no[(i+2)%3];
237 //=======================================================================
240 //=======================================================================
242 void Poly_Connect::Next()
244 Standard_Integer i, j;
245 Standard_Integer n[3];
246 Standard_Integer t[3];
247 const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
248 Triangles(mytr, t[0], t[1], t[2]);
250 for (i = 0; i < 3; i++) {
252 triangles(t[i]).Get(n[0], n[1], n[2]);
253 for (j = 0; j < 3; j++) {
254 if ((n[j] == mynode) && (n[(j+1)%3] == myothernode)) {
256 myothernode = n[(j+2)%3];
257 mymore = (mytr != myfirst);
263 // sinon, depart vers la gauche.
264 triangles(myfirst).Get(n[0], n[1], n[2]);
265 for (i = 0; i < 3; i++)
266 if (n[i] == mynode) break;
267 myothernode = n[(i+1)%3];
268 mysense = Standard_False;
270 Triangles(mytr, t[0], t[1], t[2]);
273 for (i = 0; i < 3; i++) {
275 triangles(t[i]).Get(n[0], n[1], n[2]);
276 for (j = 0; j < 3; j++) {
277 if ((n[j] == mynode) && (n[(j+2)%3] == myothernode)) {
279 myothernode = n[(j+1)%3];
280 mymore = Standard_True;
287 mymore = Standard_False;