mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-05-15 05:28:47 +08:00
296 lines
10 KiB
C++
Executable File
296 lines
10 KiB
C++
Executable File
// Created on: 2007-11-25
|
|
// Created by: Alexander GRIGORIEV
|
|
// Copyright (c) 2007-2012 OPEN CASCADE SAS
|
|
//
|
|
// The content of this file is subject to the Open CASCADE Technology Public
|
|
// License Version 6.5 (the "License"). You may not use the content of this file
|
|
// except in compliance with the License. Please obtain a copy of the License
|
|
// at http://www.opencascade.org and read it completely before using this file.
|
|
//
|
|
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
|
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
|
//
|
|
// The Original Code and all software distributed under the License is
|
|
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
|
// Initial Developer hereby disclaims all such warranties, including without
|
|
// limitation, any warranties of merchantability, fitness for a particular
|
|
// purpose or non-infringement. Please see the License for the specific terms
|
|
// and conditions governing the rights and limitations under the License.
|
|
|
|
|
|
|
|
#include <Poly_CoherentTriangle.hxx>
|
|
#include <Standard_ProgramError.hxx>
|
|
|
|
//=======================================================================
|
|
//function : Poly_CoherentTriangle()
|
|
//purpose : Empty Constructor
|
|
//=======================================================================
|
|
|
|
Poly_CoherentTriangle::Poly_CoherentTriangle ()
|
|
: myNConnections (0)
|
|
{
|
|
myNodes[0] = -1;
|
|
myNodes[1] = -1;
|
|
myNodes[2] = -1;
|
|
myNodesOnConnected[0] = -1;
|
|
myNodesOnConnected[1] = -1;
|
|
myNodesOnConnected[2] = -1;
|
|
mypConnected[0] = 0L;
|
|
mypConnected[1] = 0L;
|
|
mypConnected[2] = 0L;
|
|
mypLink[0] = 0L;
|
|
mypLink[1] = 0L;
|
|
mypLink[2] = 0L;
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : Poly_CoherentTriangle()
|
|
//purpose : Constructor
|
|
//=======================================================================
|
|
|
|
Poly_CoherentTriangle::Poly_CoherentTriangle (const Standard_Integer iNode0,
|
|
const Standard_Integer iNode1,
|
|
const Standard_Integer iNode2)
|
|
: myNConnections (0)
|
|
{
|
|
myNodes[0] = iNode0;
|
|
myNodes[1] = iNode1;
|
|
myNodes[2] = iNode2;
|
|
myNodesOnConnected[0] = -1;
|
|
myNodesOnConnected[1] = -1;
|
|
myNodesOnConnected[2] = -1;
|
|
mypConnected[0] = 0L;
|
|
mypConnected[1] = 0L;
|
|
mypConnected[2] = 0L;
|
|
mypLink[0] = 0L;
|
|
mypLink[1] = 0L;
|
|
mypLink[2] = 0L;
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : SetConnection
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
Standard_Boolean Poly_CoherentTriangle::SetConnection
|
|
(const Standard_Integer iConn,
|
|
Poly_CoherentTriangle& theTr)
|
|
{
|
|
Standard_Boolean aResult(Standard_False);
|
|
static const Standard_Integer II[] = { 2, 0, 1, 2, 0 };
|
|
|
|
if (theTr.Node(0) == myNodes[II[iConn+2]]) {
|
|
if (theTr.Node(2) == myNodes[II[iConn]]) {
|
|
RemoveConnection(iConn);
|
|
myNodesOnConnected[iConn] = theTr.Node(1);
|
|
mypConnected[iConn] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(1);
|
|
theTr.myNodesOnConnected[1] = myNodes[iConn];
|
|
theTr.mypConnected[1] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
}
|
|
} else if (theTr.Node(1) == myNodes[II[iConn+2]]) {
|
|
if (theTr.Node(0) == myNodes[II[iConn]]) {
|
|
RemoveConnection(iConn);
|
|
myNodesOnConnected[iConn] = theTr.Node(2);
|
|
mypConnected[iConn] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(2);
|
|
theTr.myNodesOnConnected[2] = myNodes[iConn];
|
|
theTr.mypConnected[2] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
}
|
|
} else if (theTr.Node(2) == myNodes[II[iConn+2]]) {
|
|
if (theTr.Node(1) == myNodes[II[iConn]]) {
|
|
RemoveConnection(iConn);
|
|
myNodesOnConnected[iConn] = theTr.Node(0);
|
|
mypConnected[iConn] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(0);
|
|
theTr.myNodesOnConnected[0] = myNodes[iConn];
|
|
theTr.mypConnected[0] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
}
|
|
}
|
|
return aResult;
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : SetConnection
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
Standard_Boolean Poly_CoherentTriangle::SetConnection
|
|
(Poly_CoherentTriangle& theTr)
|
|
{
|
|
Standard_Boolean aResult(Standard_False);
|
|
if (myNodes[0] == theTr.Node(0)) {
|
|
if (myNodes[1] == theTr.Node(2) && mypConnected[2] != &theTr) {
|
|
RemoveConnection(2);
|
|
myNodesOnConnected[2] = theTr.Node(1);
|
|
mypConnected[2] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(1);
|
|
theTr.myNodesOnConnected[1] = myNodes[2];
|
|
theTr.mypConnected[1] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
} else if (myNodes[2] == theTr.Node(1) && mypConnected[1] != &theTr) {
|
|
RemoveConnection(1);
|
|
myNodesOnConnected[1] = theTr.Node(2);
|
|
mypConnected[1] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(2);
|
|
theTr.myNodesOnConnected[2] = myNodes[1];
|
|
theTr.mypConnected[2] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
}
|
|
} else if (myNodes[0] == theTr.Node(1)) {
|
|
if (myNodes[1] == theTr.Node(0) && mypConnected[2] != &theTr) {
|
|
RemoveConnection(2);
|
|
myNodesOnConnected[2] = theTr.Node(2);
|
|
mypConnected[2] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(2);
|
|
theTr.myNodesOnConnected[2] = myNodes[2];
|
|
theTr.mypConnected[2] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
} else if (myNodes[2] == theTr.Node(2) && mypConnected[1] != &theTr) {
|
|
RemoveConnection(1);
|
|
myNodesOnConnected[1] = theTr.Node(0);
|
|
mypConnected[1] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(0);
|
|
theTr.myNodesOnConnected[0] = myNodes[1];
|
|
theTr.mypConnected[0] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
}
|
|
} else if (myNodes[0] == theTr.Node(2)) {
|
|
if (myNodes[1] == theTr.Node(1) && mypConnected[2] != &theTr) {
|
|
RemoveConnection(2);
|
|
myNodesOnConnected[2] = theTr.Node(0);
|
|
mypConnected[2] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(0);
|
|
theTr.myNodesOnConnected[0] = myNodes[2];
|
|
theTr.mypConnected[0] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
} else if (myNodes[2] == theTr.Node(0) && mypConnected[1] != &theTr) {
|
|
RemoveConnection(1);
|
|
myNodesOnConnected[1] = theTr.Node(1);
|
|
mypConnected[1] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(1);
|
|
theTr.myNodesOnConnected[1] = myNodes[1];
|
|
theTr.mypConnected[1] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
}
|
|
} else if (mypConnected[0] != &theTr) {
|
|
if (myNodes[1] == theTr.Node(0) && myNodes[2] == theTr.Node(2)) {
|
|
RemoveConnection(0);
|
|
myNodesOnConnected[0] = theTr.Node(1);
|
|
mypConnected[0] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(1);
|
|
theTr.myNodesOnConnected[1] = myNodes[0];
|
|
theTr.mypConnected[1] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
} else if (myNodes[1] == theTr.Node(2) && myNodes[2] == theTr.Node(1)) {
|
|
RemoveConnection(0);
|
|
myNodesOnConnected[0] = theTr.Node(0);
|
|
mypConnected[0] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(0);
|
|
theTr.myNodesOnConnected[0] = myNodes[0];
|
|
theTr.mypConnected[0] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
} else if (myNodes[1] == theTr.Node(1) && myNodes[2] == theTr.Node(0)) {
|
|
RemoveConnection(0);
|
|
myNodesOnConnected[0] = theTr.Node(2);
|
|
mypConnected[0] = &theTr;
|
|
myNConnections++;
|
|
theTr.RemoveConnection(2);
|
|
theTr.myNodesOnConnected[2] = myNodes[0];
|
|
theTr.mypConnected[2] = this;
|
|
theTr.myNConnections++;
|
|
aResult = Standard_True;
|
|
}
|
|
}
|
|
return aResult;
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : RemoveConnection
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
void Poly_CoherentTriangle::RemoveConnection(const Standard_Integer iConn)
|
|
{
|
|
Poly_CoherentTriangle * pConnectedTri =
|
|
const_cast<Poly_CoherentTriangle *> (mypConnected[iConn]);
|
|
if (pConnectedTri) {
|
|
Standard_Integer iConn1(0);
|
|
if (pConnectedTri->mypConnected[0] != this) {
|
|
if (pConnectedTri->mypConnected[1] == this)
|
|
iConn1 = 1;
|
|
else if (pConnectedTri->mypConnected[2] == this)
|
|
iConn1 = 2;
|
|
else
|
|
Standard_ProgramError::Raise("Poly_CoherentTriangle::RemoveConnection: "
|
|
"wrong connection between triangles");
|
|
}
|
|
pConnectedTri->mypConnected[iConn1] = 0L;
|
|
pConnectedTri->myNodesOnConnected[iConn1] = -1;
|
|
pConnectedTri->myNConnections--;
|
|
mypConnected[iConn] = 0L;
|
|
myNodesOnConnected[iConn] = -1;
|
|
myNConnections--;
|
|
}
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : RemoveConnection
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
Standard_Boolean Poly_CoherentTriangle::RemoveConnection
|
|
(Poly_CoherentTriangle& theTri)
|
|
{
|
|
const Standard_Integer iConn = FindConnection(theTri);
|
|
if (iConn >= 0)
|
|
RemoveConnection(iConn);
|
|
return (iConn >= 0);
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : FindConnection
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
Standard_Integer Poly_CoherentTriangle::FindConnection
|
|
(const Poly_CoherentTriangle& theTri) const
|
|
{
|
|
Standard_Integer aResult;
|
|
if (mypConnected[0] == &theTri)
|
|
aResult = 0;
|
|
else if (mypConnected[1] == &theTri)
|
|
aResult = 1;
|
|
else if (mypConnected[2] == &theTri)
|
|
aResult = 2;
|
|
else
|
|
aResult = -1;
|
|
return aResult;
|
|
}
|