0027067: Avoid use of virtual methods for implementation of destructors in legacy...
[occt.git] / src / TopOpeBRepTool / TopOpeBRepTool_SolidClassifier.cxx
CommitLineData
b311480e 1// Created on: 1996-08-27
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
7fd59977 18#include <BRepClass3d_SolidClassifier.hxx>
42cf5bc1 19#include <gp_Pnt.hxx>
20#include <TopoDS_Shell.hxx>
21#include <TopoDS_Solid.hxx>
22#include <TopOpeBRepTool_SolidClassifier.hxx>
7fd59977 23
24//=======================================================================
25//function : TopOpeBRepTool_SolidClassifier
26//purpose :
27//=======================================================================
28TopOpeBRepTool_SolidClassifier::TopOpeBRepTool_SolidClassifier()
29{
30 Clear();
31}
32
33//modified by NIZNHY-PKV Mon Dec 16 10:39:00 2002 f
34//=======================================================================
e6f550da 35//function : ~TopOpeBRepTool_SolidClassifier
36//purpose :
7fd59977 37//=======================================================================
e6f550da 38TopOpeBRepTool_SolidClassifier::~TopOpeBRepTool_SolidClassifier()
7fd59977 39{
40 Standard_Integer i, aNb;
41
42 aNb=myShapeClassifierMap.Extent();
43 for (i=1; i<=aNb; ++i) {
44 Standard_Address anAddr=myShapeClassifierMap(i);
45 BRepClass3d_SolidClassifier* pClsf=
46 (BRepClass3d_SolidClassifier*) anAddr;
47 delete pClsf;
48 }
49 myShapeClassifierMap.Clear();
50}
51
52//=======================================================================
53//function : LoadSolid
54//purpose :
55//=======================================================================
56void TopOpeBRepTool_SolidClassifier::LoadSolid(const TopoDS_Solid& SOL)
57{
58 Standard_Boolean found = myShapeClassifierMap.Contains(SOL);
59
60 if ( !found ) {
61 myPClassifier = new BRepClass3d_SolidClassifier(SOL);
62 myShapeClassifierMap.Add(SOL, (Standard_Address)myPClassifier);
63 }
64 else {
65 myPClassifier =
66 (BRepClass3d_SolidClassifier*)myShapeClassifierMap.ChangeFromKey(SOL);
67 }
68}
69
70//=======================================================================
71//function : LoadShell
72//purpose :
73//=======================================================================
74void TopOpeBRepTool_SolidClassifier::LoadShell(const TopoDS_Shell& SHE)
75{
76 Standard_Boolean found = myShapeClassifierMap.Contains(SHE);
77 if ( !found ) {
78 myBuilder.MakeSolid(mySolid);
79 myBuilder.Add(mySolid, SHE);
80
81 myPClassifier = new BRepClass3d_SolidClassifier(mySolid);
82 myShapeClassifierMap.Add(SHE, (Standard_Address)myPClassifier);
83 }
84 else {
85 myPClassifier =
86 (BRepClass3d_SolidClassifier*)myShapeClassifierMap.ChangeFromKey(SHE);
87 }
88}
89//modified by NIZNHY-PKV Mon Dec 16 10:53:41 2002 t
90
91//=======================================================================
92//function : Clear
93//purpose :
94//=======================================================================
95void TopOpeBRepTool_SolidClassifier::Clear()
96{
97 myPClassifier = NULL;
98 //modified by NIZNHY-PKV Mon Dec 16 10:46:04 2002 f
99 //myClassifierMap.Clear();
100 myShapeClassifierMap.Clear();
101 //modified by NIZNHY-PKV Mon Dec 16 10:46:06 2002 t
102 myState = TopAbs_UNKNOWN;
103 myShell.Nullify();
104 mySolid.Nullify();
105}
106
107//=======================================================================
108//function : Classify
109//purpose :
110//=======================================================================
111TopAbs_State TopOpeBRepTool_SolidClassifier::Classify (const TopoDS_Solid& SOL,
112 const gp_Pnt& P,
113 const Standard_Real Tol)
114{
115 myPClassifier = NULL;
116 myState = TopAbs_UNKNOWN;
117 LoadSolid(SOL);
118 if (myPClassifier == NULL) return myState;
119 myPClassifier->Perform(P,Tol);
120 myState = myPClassifier->State();
121 const TopoDS_Shape& fres = myPClassifier->Face();
122 if (fres.IsNull()) {
123 // NYI : en cas d'elimination des faces EXTERNAL et INTERNAL par le
124 // classifier BRepClass3d_SolidClassifier, traiter quand meme ces faces
125 // pour generer l'etat ON/Solid quand le point est IN/face INTERNAL ou EXTERNAL
126 return myState;
127 }
128 TopAbs_Orientation ofres = fres.Orientation();
129 if ( ofres == TopAbs_EXTERNAL ) {
130 if ( myState == TopAbs_IN ) myState = TopAbs_OUT;
131 else if ( myState == TopAbs_OUT ) myState = TopAbs_OUT;
132 else if ( myState == TopAbs_ON ) myState = TopAbs_ON;
133 else if ( myState == TopAbs_UNKNOWN ) myState = TopAbs_OUT;
134 }
135 else if ( ofres == TopAbs_INTERNAL ) {
136 if ( myState == TopAbs_IN ) myState = TopAbs_IN;
137 else if ( myState == TopAbs_OUT) myState = TopAbs_IN;
138 else if ( myState == TopAbs_ON ) myState = TopAbs_ON;
139 else if ( myState == TopAbs_UNKNOWN ) myState = TopAbs_IN;
140 }
141 return myState;
142}
143
144//=======================================================================
145//function : Classify
146//purpose :
147//=======================================================================
148TopAbs_State TopOpeBRepTool_SolidClassifier::Classify(const TopoDS_Shell& SHE,
149 const gp_Pnt& P,
150 const Standard_Real Tol)
151{
152 myPClassifier = NULL;
153 myState = TopAbs_UNKNOWN;
154 LoadShell(SHE);
155 if (myPClassifier == NULL) return myState;
156 myPClassifier->Perform(P,Tol);
157 myState = myPClassifier->State();
158 return myState;
159}
160
161//=======================================================================
162//function : State
163//purpose :
164//=======================================================================
165TopAbs_State TopOpeBRepTool_SolidClassifier::State() const
166{
167 return myState;
168}
169//modified by NIZNHY-PKV Mon Dec 16 10:55:47 2002 f
170/*
171//=======================================================================
172//function : LoadSolid
173//purpose :
174//=======================================================================
175
176void TopOpeBRepTool_SolidClassifier::LoadSolid(const TopoDS_Solid& SOL)
177{
178 Standard_Boolean found = myClassifierMap.Contains(SOL);
179 if ( !found ) {
180 myPClassifier = new BRepClass3d_SolidClassifier(SOL);
181 myClassifierMap.Add(SOL,*myPClassifier);
182 }
183 else {
184 myPClassifier = &myClassifierMap.ChangeFromKey(SOL);
185 }
0797d9d3 186#ifdef OCCT_DEBUG
7fd59977 187 Standard_Integer i =
188#endif
189 myClassifierMap.FindIndex(SOL); // DEB
190}
191
192//=======================================================================
193//function : LoadShell
194//purpose :
195//=======================================================================
196void TopOpeBRepTool_SolidClassifier::LoadShell(const TopoDS_Shell& SHE)
197{
198 Standard_Boolean found = myClassifierMap.Contains(SHE);
199 if ( !found ) {
200 myBuilder.MakeSolid(mySolid);
201 myBuilder.Add(mySolid,SHE);
202 TopoDS_Shell* pshe = (TopoDS_Shell*)&SHE; (*pshe).Free(Standard_True);
203 myPClassifier = new BRepClass3d_SolidClassifier(mySolid);
204 myClassifierMap.Add(SHE,*myPClassifier);
205 }
206 else {
207 myPClassifier = &myClassifierMap.ChangeFromKey(SHE);
208 }
0797d9d3 209#ifdef OCCT_DEBUG
7fd59977 210 Standard_Integer i =
211#endif
212 myClassifierMap.FindIndex(SHE); // DEB
213}
214*/
215//modified by NIZNHY-PKV Mon Dec 16 10:55:56 2002 t