1 // File: Poly_Connect.cxx
2 // Created: Mon Mar 6 16:30:09 1995
3 // Author: Laurent PAINNOT
7 #include <Poly_Connect.ixx>
8 #include <Poly_Triangle.hxx>
10 #include <Standard.hxx>
13 //=======================================================================
14 //function : Poly_Connect
16 //=======================================================================
17 // this structure records one of the edges starting from a node
19 //typedef struct polyedge {
21 polyedge* next; // the next edge in the list
22 Standard_Integer nd; // the second node of the edge
23 Standard_Integer nt[2]; // the two adjacent triangles
24 Standard_Integer nn[2]; // the two adjacent nodes
25 void* operator new(size_t aSize)
26 {return (void*)(Standard::Allocate(aSize));}
27 // void operator delete(void* aNode, size_t aSize) {
28 void operator delete(void* aNode) {
29 Standard_Address anAdress = (Standard_Address)aNode;
30 Standard::Free(anAdress);
34 Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& T) :
36 myTriangles(1,T->NbNodes()),
37 myAdjacents(1,6*T->NbTriangles())
41 Standard_Integer nbNodes = myTriangulation->NbNodes();
42 Standard_Integer nbTriangles = myTriangulation->NbTriangles();
44 // We first build an array of the list of edges connected to the nodes
48 // create an array to store the edges starting from the vertices
51 // the last node is not used because edges are stored at the lower node index
52 polyedge** edges = new polyedge*[nbNodes];
53 for (i = 0; i < nbNodes; i++) edges[i] = 0;
56 // loop on the triangles
57 Standard_Integer j,k,n[3],n1,n2;
58 const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
60 for (i = 1; i <= nbTriangles; i++) {
63 triangles(i).Get(n[0],n[1],n[2]);
65 // Update the myTriangles array
66 myTriangles(n[0]) = i;
67 myTriangles(n[1]) = i;
68 myTriangles(n[2]) = i;
70 // update the edge lists
71 for (j = 0; j < 3; j++) {
72 k = (j+1) % 3; // the following node of the edge
82 // edge from n1 to n2 with n1 < n2
83 // insert in the list of n1
85 polyedge* ced = edges[n1];
87 // the edge already exists
95 // create the edge if not found
97 ced->next = edges[n1];
101 ced->nn[0] = n[3-j-k]; // the third node
106 // just mark the adjacency if found
108 ced->nn[1] = n[3-j-k]; // the third node
114 // now complete the myAdjacents array
116 Standard_Integer index = 1;
117 for (i = 1; i <= nbTriangles; i++) {
120 triangles(i).Get(n[0],n[1],n[2]);
123 for (j = 0; j < 3; j++) {
124 k = (j+1) % 3; // the following node of the edge
134 // edge from n1 to n2 with n1 < n2
135 // find in the list of n1
137 polyedge* ced = edges[n1];
138 while (ced->nd != n2)
141 // Find the adjacent triangle
142 Standard_Integer l = 0;
143 if (ced->nt[0] == i) l = 1;
145 myAdjacents(index) = ced->nt[l];
146 myAdjacents(index+3) = ced->nn[l];
152 // destroy the edges array
153 for (i = 0; i < nbNodes; i++) {
154 polyedge* ced = edges[i];
156 polyedge* tmp = ced->next;
164 //=======================================================================
165 //function : Triangles
167 //=======================================================================
169 void Poly_Connect::Triangles(const Standard_Integer T,
170 Standard_Integer& t1,
171 Standard_Integer& t2,
172 Standard_Integer& t3) const
174 Standard_Integer index = 6*(T-1);
175 t1 = myAdjacents(index+1);
176 t2 = myAdjacents(index+2);
177 t3 = myAdjacents(index+3);
180 //=======================================================================
183 //=======================================================================
185 void Poly_Connect::Nodes(const Standard_Integer T,
186 Standard_Integer& n1,
187 Standard_Integer& n2,
188 Standard_Integer& n3) const
190 Standard_Integer index = 6*(T-1);
191 n1 = myAdjacents(index+4);
192 n2 = myAdjacents(index+5);
193 n3 = myAdjacents(index+6);
197 //=======================================================================
198 //function : Initialize
200 //=======================================================================
202 void Poly_Connect::Initialize(const Standard_Integer N)
205 myfirst = Triangle(N);
207 mysense = Standard_True;
208 mymore = (myfirst != 0);
211 Standard_Integer i, no[3];
212 const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
213 triangles(myfirst).Get(no[0], no[1], no[2]);
214 for (i = 0; i < 3; i++)
215 if (no[i] == mynode) break;
216 myothernode = no[(i+2)%3];
220 //=======================================================================
223 //=======================================================================
225 void Poly_Connect::Next()
227 Standard_Integer i, j;
228 static Standard_Integer n[3];
229 static Standard_Integer t[3];
230 const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
231 Triangles(mytr, t[0], t[1], t[2]);
233 for (i = 0; i < 3; i++) {
235 triangles(t[i]).Get(n[0], n[1], n[2]);
236 for (j = 0; j < 3; j++) {
237 if ((n[j] == mynode) && (n[(j+1)%3] == myothernode)) {
239 myothernode = n[(j+2)%3];
240 mymore = (mytr != myfirst);
246 // sinon, depart vers la gauche.
247 triangles(myfirst).Get(n[0], n[1], n[2]);
248 for (i = 0; i < 3; i++)
249 if (n[i] == mynode) break;
250 myothernode = n[(i+1)%3];
251 mysense = Standard_False;
253 Triangles(mytr, t[0], t[1], t[2]);
256 for (i = 0; i < 3; i++) {
258 triangles(t[i]).Get(n[0], n[1], n[2]);
259 for (j = 0; j < 3; j++) {
260 if ((n[j] == mynode) && (n[(j+2)%3] == myothernode)) {
262 myothernode = n[(j+1)%3];
263 mymore = Standard_True;
270 mymore = Standard_False;
274 //=======================================================================
277 //=======================================================================
279 Standard_Integer Poly_Connect::Value() const