1 // Created on: 2005-02-14
2 // Created by: Alexey MORENOV
3 // Copyright (c) 2005-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 <ShapeAnalysis_BoxBndTree.hxx>
17 #include <Standard_NoSuchObject.hxx>
18 #include <ShapeAnalysis_Edge.hxx>
19 #include <TopoDS_Vertex.hxx>
20 #include <TopoDS_Edge.hxx>
21 #include <TopoDS_Wire.hxx>
23 #include <ShapeAnalysis.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <BRep_Tool.hxx>
27 #include <Precision.hxx>
29 //=======================================================================
32 //=======================================================================
34 Standard_Boolean ShapeAnalysis_BoxBndTreeSelector::
35 Reject (const Bnd_Box& theBnd) const
37 Standard_Boolean fch = myFBox.IsOut(theBnd);
38 Standard_Boolean lch = myLBox.IsOut(theBnd);
39 if (fch == Standard_False || lch == Standard_False) return Standard_False;
43 //=======================================================================
46 //=======================================================================
48 Standard_Boolean ShapeAnalysis_BoxBndTreeSelector::
49 Accept (const Standard_Integer& theObj)
51 if (theObj < 1 || theObj > mySeq->Length())
52 throw Standard_NoSuchObject("ShapeAnalysis_BoxBndTreeSelector::Accept : no such object for current index");
53 Standard_Boolean IsAccept = Standard_False;
54 if (myList.Contains(theObj))
55 return Standard_False;
62 TopoDS_Wire W = TopoDS::Wire (mySeq->Value (theObj));
64 ShapeAnalysis::FindBounds (W,V1,V2);
66 if (myLVertex.IsSame(V1)){
67 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
68 IsAccept = Standard_True;
69 myArrIndices(Last) = theObj;
72 if (myLVertex.IsSame(V2)){
73 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
74 IsAccept = Standard_True;
75 myArrIndices(Last) = theObj;
78 if (myFVertex.IsSame(V2)){
79 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3);
80 IsAccept = Standard_True;
81 myArrIndices(First) = theObj;
84 if (myFVertex.IsSame(V1)){
85 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4);
86 IsAccept = Standard_True;
87 myArrIndices(First) = theObj;
89 else myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
98 if(myArrIndices(Last))
99 myStop = Standard_True;
100 return Standard_True;
102 else myStop = Standard_False;
106 gp_Pnt p1 = BRep_Tool::Pnt(V1);
107 gp_Pnt p2 = BRep_Tool::Pnt(V2);
109 Standard_Real tailhead, tailtail, headhead, headtail;
110 tailhead = p1.Distance(myLPnt);
111 tailtail = p2.Distance(myLPnt);
112 headhead = p1.Distance(myFPnt);
113 headtail = p2.Distance(myFPnt);
114 Standard_Real dm1 = tailhead, dm2 = headtail;
115 Standard_Integer res1 = 0, res2 = 0;
116 if (tailhead > tailtail) {res1 = 1; dm1 = tailtail;}
117 if (headtail > headhead) {res2 = 1; dm2 = headhead;}
118 Standard_Integer result = res1;
120 min3d = Min (dm1, dm2);
122 return Standard_False;
124 Standard_Integer minInd = (dm1 > dm2 ? First : Last );
125 Standard_Integer maxInd = (dm1 > dm2 ? Last : First);
126 myArrIndices(minInd) = theObj;
127 if((min3d - myMin3d) > RealSmall())
128 myArrIndices(maxInd) = 0;
133 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
134 return Standard_False;
137 Standard_Integer anObj = (myArrIndices(Last) ? myArrIndices(Last) : myArrIndices(First));
140 if (min3d == 0 && minInd == Last)
141 myStop = Standard_True;
151 case 0: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); break;
152 case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break;
153 case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break;
154 case 3: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break;
157 return Standard_True;
161 return Standard_False;