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 myTriangles.Resize (1, nbNodes, Standard_False);
87 if (myAdjacents.Size() != aNbAdjs)
89 myAdjacents.Resize (1, aNbAdjs, Standard_False);
96 // We first build an array of the list of edges connected to the nodes
97 // create an array to store the edges starting from the vertices
99 // the last node is not used because edges are stored at the lower node index
100 polyedge** edges = new polyedge*[nbNodes];
101 for (i = 0; i < nbNodes; i++) edges[i] = 0;
104 // loop on the triangles
105 Standard_Integer j,k,n[3],n1,n2;
106 const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
108 for (i = 1; i <= nbTriangles; i++) {
111 triangles(i).Get(n[0],n[1],n[2]);
113 // Update the myTriangles array
114 myTriangles(n[0]) = i;
115 myTriangles(n[1]) = i;
116 myTriangles(n[2]) = i;
118 // update the edge lists
119 for (j = 0; j < 3; j++) {
120 k = (j+1) % 3; // the following node of the edge
130 // edge from n1 to n2 with n1 < n2
131 // insert in the list of n1
133 polyedge* ced = edges[n1];
135 // the edge already exists
143 // create the edge if not found
145 ced->next = edges[n1];
149 ced->nn[0] = n[3-j-k]; // the third node
154 // just mark the adjacency if found
156 ced->nn[1] = n[3-j-k]; // the third node
162 // now complete the myAdjacents array
164 Standard_Integer index = 1;
165 for (i = 1; i <= nbTriangles; i++) {
168 triangles(i).Get(n[0],n[1],n[2]);
171 for (j = 0; j < 3; j++) {
172 k = (j+1) % 3; // the following node of the edge
182 // edge from n1 to n2 with n1 < n2
183 // find in the list of n1
185 polyedge* ced = edges[n1];
186 while (ced->nd != n2)
189 // Find the adjacent triangle
190 Standard_Integer l = 0;
191 if (ced->nt[0] == i) l = 1;
193 myAdjacents(index) = ced->nt[l];
194 myAdjacents(index+3) = ced->nn[l];
200 // destroy the edges array
201 for (i = 0; i < nbNodes; i++) {
202 polyedge* ced = edges[i];
204 polyedge* tmp = ced->next;
212 //=======================================================================
213 //function : Initialize
215 //=======================================================================
217 void Poly_Connect::Initialize(const Standard_Integer N)
220 myfirst = Triangle(N);
222 mysense = Standard_True;
223 mymore = (myfirst != 0);
226 Standard_Integer i, no[3];
227 const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
228 triangles(myfirst).Get(no[0], no[1], no[2]);
229 for (i = 0; i < 3; i++)
230 if (no[i] == mynode) break;
231 myothernode = no[(i+2)%3];
235 //=======================================================================
238 //=======================================================================
240 void Poly_Connect::Next()
242 Standard_Integer i, j;
243 Standard_Integer n[3];
244 Standard_Integer t[3];
245 const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
246 Triangles(mytr, t[0], t[1], t[2]);
248 for (i = 0; i < 3; i++) {
250 triangles(t[i]).Get(n[0], n[1], n[2]);
251 for (j = 0; j < 3; j++) {
252 if ((n[j] == mynode) && (n[(j+1)%3] == myothernode)) {
254 myothernode = n[(j+2)%3];
255 mymore = (mytr != myfirst);
261 // sinon, depart vers la gauche.
262 triangles(myfirst).Get(n[0], n[1], n[2]);
263 for (i = 0; i < 3; i++)
264 if (n[i] == mynode) break;
265 myothernode = n[(i+1)%3];
266 mysense = Standard_False;
268 Triangles(mytr, t[0], t[1], t[2]);
271 for (i = 0; i < 3; i++) {
273 triangles(t[i]).Get(n[0], n[1], n[2]);
274 for (j = 0; j < 3; j++) {
275 if ((n[j] == mynode) && (n[(j+2)%3] == myothernode)) {
277 myothernode = n[(j+1)%3];
278 mymore = Standard_True;
285 mymore = Standard_False;