0024157: Parallelization of assembly part of BO
[occt.git] / src / Select3D / Select3D_SensitiveBox.cxx
CommitLineData
b311480e 1// Created on: 1995-04-13
2// Created by: Robert COUBLANC
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23
24#include <Select3D_SensitiveBox.ixx>
25#include <gp_Pnt2d.hxx>
26#include <gp_Pnt.hxx>
27#include <Bnd_Box.hxx>
28#include <ElCLib.hxx>
29
30
31
32//==================================================
33// Function: Constructor
34// Purpose :
35//==================================================
36
37Select3D_SensitiveBox::Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
ac04d101 38 const Bnd_Box& BBox):
7fd59977 39Select3D_SensitiveEntity(OwnerId),
40mybox3d(BBox){}
41
7fd59977 42//==================================================
43// Function: Constructor
44// Purpose :
45//==================================================
46
47Select3D_SensitiveBox::
48Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
ac04d101
SA
49 const Standard_Real XMin,
50 const Standard_Real YMin,
51 const Standard_Real ZMin,
52 const Standard_Real XMax,
53 const Standard_Real YMax,
54 const Standard_Real ZMax):
7fd59977 55Select3D_SensitiveEntity(OwnerId)
56{
57 mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax);
58}
59
7fd59977 60//==================================================
61// Function: Project
62// Purpose :
63//==================================================
ac04d101 64
7fd59977 65void Select3D_SensitiveBox::
4952a30a 66Project(const Handle(Select3D_Projector)& aProj)
7fd59977 67{
ac04d101
SA
68 if(HasLocation())
69 {
7fd59977 70 Bnd_Box B = mybox3d.Transformed(Location().Transformation());
71 ProjectBox(aProj,B);
72 }
73 else
74 ProjectBox(aProj,mybox3d);
75}
76
77//==================================================
ac04d101 78// Function: Areas
7fd59977 79// Purpose :
80//==================================================
ac04d101 81
7fd59977 82void Select3D_SensitiveBox::
83Areas(SelectBasics_ListOfBox2d& aSeq)
84{ aSeq.Append(mybox2d);}
85
7fd59977 86//=======================================================================
87//function : GetConnected
88//purpose :
89//=======================================================================
90
91Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected(const TopLoc_Location& aLoc)
92{
93 Handle(Select3D_SensitiveBox) NiouEnt = new Select3D_SensitiveBox(myOwnerId,mybox3d);
94
95 if(HasLocation()) NiouEnt->SetLocation(Location());
96 NiouEnt->UpdateLocation(aLoc);
97 return NiouEnt;
98}
99
7fd59977 100//==================================================
ac04d101 101// Function: Matches
7fd59977 102// Purpose :
103//==================================================
4269bd1b 104
105Standard_Boolean Select3D_SensitiveBox::Matches (const SelectBasics_PickArgs& thePickArgs,
106 Standard_Real& theMatchDMin,
107 Standard_Real& theMatchDepth)
7fd59977 108{
4269bd1b 109 // check that sensitive box passes by depth
110 Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
111 if (thePickArgs.IsClipped (aDepth))
112 {
113 return Standard_False;
114 }
115
116 theMatchDMin = 0.0;
117 theMatchDepth = aDepth;
7fd59977 118 return Standard_True;
7fd59977 119}
120
121//==================================================
ac04d101 122// Function: Matches
7fd59977 123// Purpose :
124//==================================================
125
126Standard_Boolean Select3D_SensitiveBox::
127Matches (const Standard_Real XMin,
ac04d101
SA
128 const Standard_Real YMin,
129 const Standard_Real XMax,
130 const Standard_Real YMax,
131 const Standard_Real aTol)
7fd59977 132{
133 Bnd_Box2d BoundBox;
134 BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
135 return(!BoundBox.IsOut(mybox2d));
136}
137
7fd59977 138//=======================================================================
139//function : Matches
140//purpose :
141//=======================================================================
142
143Standard_Boolean Select3D_SensitiveBox::
35e08fe8 144Matches (const TColgp_Array1OfPnt2d& /*aPoly*/,
ac04d101 145 const Bnd_Box2d& aBox,
35e08fe8 146 const Standard_Real /*aTol*/)
ac04d101 147{
7fd59977 148 return(!aBox.IsOut(mybox2d));
149}
150
7fd59977 151//=======================================================================
152//function : Dump
153//purpose :
154//=======================================================================
155
156void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
157{
158 S<<"\tSensitiveBox 3D :\n";
159 if(HasLocation())
160 S<<"\t\tExisting Location"<<endl;
161
162 Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
163 mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
164
165 S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]";
166 S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl;
167
ac04d101
SA
168 if(FullDump)
169 {
7fd59977 170// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
ac04d101
SA
171 Select3D_SensitiveEntity::DumpBox(S,mybox2d);
172 }
7fd59977 173}
174
175
176//=======================================================================
177//function : ProjectBox
178//purpose :
179//=======================================================================
180
4952a30a 181void Select3D_SensitiveBox::ProjectBox(const Handle(Select3D_Projector)& aPrj,
ac04d101 182 const Bnd_Box& aBox)
7fd59977 183{
184 mybox2d.SetVoid();
185 gp_Pnt2d curp2d;
186 Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
187 aBox.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
4952a30a 188
189 aPrj->Project(gp_Pnt(XMin,YMin,ZMin),curp2d);
7fd59977 190 mybox2d.Update(curp2d.X(),curp2d.Y());
4952a30a 191 aPrj->Project(gp_Pnt(XMax,YMin,ZMin),curp2d);
7fd59977 192 mybox2d.Update(curp2d.X(),curp2d.Y());
4952a30a 193 aPrj->Project(gp_Pnt(XMax,YMax,ZMin),curp2d);
7fd59977 194 mybox2d.Update(curp2d.X(),curp2d.Y());
4952a30a 195 aPrj->Project(gp_Pnt(XMin,YMax,ZMin),curp2d);
7fd59977 196 mybox2d.Update(curp2d.X(),curp2d.Y());
4952a30a 197 aPrj->Project(gp_Pnt(XMin,YMin,ZMax),curp2d);
7fd59977 198 mybox2d.Update(curp2d.X(),curp2d.Y());
4952a30a 199 aPrj->Project(gp_Pnt(XMax,YMin,ZMax),curp2d);
7fd59977 200 mybox2d.Update(curp2d.X(),curp2d.Y());
4952a30a 201 aPrj->Project(gp_Pnt(XMax,YMax,ZMax),curp2d);
7fd59977 202 mybox2d.Update(curp2d.X(),curp2d.Y());
4952a30a 203 aPrj->Project(gp_Pnt(XMin,YMax,ZMax),curp2d);
7fd59977 204 mybox2d.Update(curp2d.X(),curp2d.Y());
205}
206
207//=======================================================================
208//function : ComputeDepth
209//purpose :
210//=======================================================================
211
212Standard_Real Select3D_SensitiveBox::ComputeDepth(const gp_Lin& EyeLine) const
213{
214 Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
215 mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
216 gp_Pnt PMid((XMin+XMax)/2.,(YMin+YMax)/2.,(ZMin+ZMax)/2.);
217 return ElCLib::Parameter(EyeLine,PMid);
218}