1 // Created on: 2007-11-25
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Poly_CoherentTriangle.hxx>
17 #include <Standard_ProgramError.hxx>
19 //=======================================================================
20 //function : Poly_CoherentTriangle()
21 //purpose : Empty Constructor
22 //=======================================================================
24 Poly_CoherentTriangle::Poly_CoherentTriangle ()
30 myNodesOnConnected[0] = -1;
31 myNodesOnConnected[1] = -1;
32 myNodesOnConnected[2] = -1;
41 //=======================================================================
42 //function : Poly_CoherentTriangle()
43 //purpose : Constructor
44 //=======================================================================
46 Poly_CoherentTriangle::Poly_CoherentTriangle (const Standard_Integer iNode0,
47 const Standard_Integer iNode1,
48 const Standard_Integer iNode2)
54 myNodesOnConnected[0] = -1;
55 myNodesOnConnected[1] = -1;
56 myNodesOnConnected[2] = -1;
65 //=======================================================================
66 //function : SetConnection
68 //=======================================================================
70 Standard_Boolean Poly_CoherentTriangle::SetConnection
71 (const Standard_Integer iConn,
72 Poly_CoherentTriangle& theTr)
74 Standard_Boolean aResult(Standard_False);
75 static const Standard_Integer II[] = { 2, 0, 1, 2, 0 };
77 if (theTr.Node(0) == myNodes[II[iConn+2]]) {
78 if (theTr.Node(2) == myNodes[II[iConn]]) {
79 RemoveConnection(iConn);
80 myNodesOnConnected[iConn] = theTr.Node(1);
81 mypConnected[iConn] = &theTr;
83 theTr.RemoveConnection(1);
84 theTr.myNodesOnConnected[1] = myNodes[iConn];
85 theTr.mypConnected[1] = this;
86 theTr.myNConnections++;
87 aResult = Standard_True;
89 } else if (theTr.Node(1) == myNodes[II[iConn+2]]) {
90 if (theTr.Node(0) == myNodes[II[iConn]]) {
91 RemoveConnection(iConn);
92 myNodesOnConnected[iConn] = theTr.Node(2);
93 mypConnected[iConn] = &theTr;
95 theTr.RemoveConnection(2);
96 theTr.myNodesOnConnected[2] = myNodes[iConn];
97 theTr.mypConnected[2] = this;
98 theTr.myNConnections++;
99 aResult = Standard_True;
101 } else if (theTr.Node(2) == myNodes[II[iConn+2]]) {
102 if (theTr.Node(1) == myNodes[II[iConn]]) {
103 RemoveConnection(iConn);
104 myNodesOnConnected[iConn] = theTr.Node(0);
105 mypConnected[iConn] = &theTr;
107 theTr.RemoveConnection(0);
108 theTr.myNodesOnConnected[0] = myNodes[iConn];
109 theTr.mypConnected[0] = this;
110 theTr.myNConnections++;
111 aResult = Standard_True;
117 //=======================================================================
118 //function : SetConnection
120 //=======================================================================
122 Standard_Boolean Poly_CoherentTriangle::SetConnection
123 (Poly_CoherentTriangle& theTr)
125 Standard_Boolean aResult(Standard_False);
126 if (myNodes[0] == theTr.Node(0)) {
127 if (myNodes[1] == theTr.Node(2) && mypConnected[2] != &theTr) {
129 myNodesOnConnected[2] = theTr.Node(1);
130 mypConnected[2] = &theTr;
132 theTr.RemoveConnection(1);
133 theTr.myNodesOnConnected[1] = myNodes[2];
134 theTr.mypConnected[1] = this;
135 theTr.myNConnections++;
136 aResult = Standard_True;
137 } else if (myNodes[2] == theTr.Node(1) && mypConnected[1] != &theTr) {
139 myNodesOnConnected[1] = theTr.Node(2);
140 mypConnected[1] = &theTr;
142 theTr.RemoveConnection(2);
143 theTr.myNodesOnConnected[2] = myNodes[1];
144 theTr.mypConnected[2] = this;
145 theTr.myNConnections++;
146 aResult = Standard_True;
148 } else if (myNodes[0] == theTr.Node(1)) {
149 if (myNodes[1] == theTr.Node(0) && mypConnected[2] != &theTr) {
151 myNodesOnConnected[2] = theTr.Node(2);
152 mypConnected[2] = &theTr;
154 theTr.RemoveConnection(2);
155 theTr.myNodesOnConnected[2] = myNodes[2];
156 theTr.mypConnected[2] = this;
157 theTr.myNConnections++;
158 aResult = Standard_True;
159 } else if (myNodes[2] == theTr.Node(2) && mypConnected[1] != &theTr) {
161 myNodesOnConnected[1] = theTr.Node(0);
162 mypConnected[1] = &theTr;
164 theTr.RemoveConnection(0);
165 theTr.myNodesOnConnected[0] = myNodes[1];
166 theTr.mypConnected[0] = this;
167 theTr.myNConnections++;
168 aResult = Standard_True;
170 } else if (myNodes[0] == theTr.Node(2)) {
171 if (myNodes[1] == theTr.Node(1) && mypConnected[2] != &theTr) {
173 myNodesOnConnected[2] = theTr.Node(0);
174 mypConnected[2] = &theTr;
176 theTr.RemoveConnection(0);
177 theTr.myNodesOnConnected[0] = myNodes[2];
178 theTr.mypConnected[0] = this;
179 theTr.myNConnections++;
180 aResult = Standard_True;
181 } else if (myNodes[2] == theTr.Node(0) && mypConnected[1] != &theTr) {
183 myNodesOnConnected[1] = theTr.Node(1);
184 mypConnected[1] = &theTr;
186 theTr.RemoveConnection(1);
187 theTr.myNodesOnConnected[1] = myNodes[1];
188 theTr.mypConnected[1] = this;
189 theTr.myNConnections++;
190 aResult = Standard_True;
192 } else if (mypConnected[0] != &theTr) {
193 if (myNodes[1] == theTr.Node(0) && myNodes[2] == theTr.Node(2)) {
195 myNodesOnConnected[0] = theTr.Node(1);
196 mypConnected[0] = &theTr;
198 theTr.RemoveConnection(1);
199 theTr.myNodesOnConnected[1] = myNodes[0];
200 theTr.mypConnected[1] = this;
201 theTr.myNConnections++;
202 aResult = Standard_True;
203 } else if (myNodes[1] == theTr.Node(2) && myNodes[2] == theTr.Node(1)) {
205 myNodesOnConnected[0] = theTr.Node(0);
206 mypConnected[0] = &theTr;
208 theTr.RemoveConnection(0);
209 theTr.myNodesOnConnected[0] = myNodes[0];
210 theTr.mypConnected[0] = this;
211 theTr.myNConnections++;
212 aResult = Standard_True;
213 } else if (myNodes[1] == theTr.Node(1) && myNodes[2] == theTr.Node(0)) {
215 myNodesOnConnected[0] = theTr.Node(2);
216 mypConnected[0] = &theTr;
218 theTr.RemoveConnection(2);
219 theTr.myNodesOnConnected[2] = myNodes[0];
220 theTr.mypConnected[2] = this;
221 theTr.myNConnections++;
222 aResult = Standard_True;
228 //=======================================================================
229 //function : RemoveConnection
231 //=======================================================================
233 void Poly_CoherentTriangle::RemoveConnection(const Standard_Integer iConn)
235 Poly_CoherentTriangle * pConnectedTri =
236 const_cast<Poly_CoherentTriangle *> (mypConnected[iConn]);
238 Standard_Integer iConn1(0);
239 if (pConnectedTri->mypConnected[0] != this) {
240 if (pConnectedTri->mypConnected[1] == this)
242 else if (pConnectedTri->mypConnected[2] == this)
245 throw Standard_ProgramError("Poly_CoherentTriangle::RemoveConnection: "
246 "wrong connection between triangles");
248 pConnectedTri->mypConnected[iConn1] = 0L;
249 pConnectedTri->myNodesOnConnected[iConn1] = -1;
250 pConnectedTri->myNConnections--;
251 mypConnected[iConn] = 0L;
252 myNodesOnConnected[iConn] = -1;
257 //=======================================================================
258 //function : RemoveConnection
260 //=======================================================================
262 Standard_Boolean Poly_CoherentTriangle::RemoveConnection
263 (Poly_CoherentTriangle& theTri)
265 const Standard_Integer iConn = FindConnection(theTri);
267 RemoveConnection(iConn);
271 //=======================================================================
272 //function : FindConnection
274 //=======================================================================
276 Standard_Integer Poly_CoherentTriangle::FindConnection
277 (const Poly_CoherentTriangle& theTri) const
279 Standard_Integer aResult;
280 if (mypConnected[0] == &theTri)
282 else if (mypConnected[1] == &theTri)
284 else if (mypConnected[2] == &theTri)