0024157: Parallelization of assembly part of BO
[occt.git] / src / IntImpParGen / IntImpParGen.cxx
CommitLineData
b311480e 1// Created on: 1992-06-10
2// Created by: Laurent BUCHARD
3// Copyright (c) 1992-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 <IntImpParGen.ixx>
25#include <IntRes2d_Domain.hxx>
26#include <IntRes2d_Position.hxx>
27#include <IntRes2d_Transition.hxx>
28#include <gp_Vec2d.hxx>
29#include <gp_Pnt2d.hxx>
30
31
32
33
34#include <IntImpParGen_Tool.hxx>
35#include <gp.hxx>
36
37
38#define TOLERANCE_ANGULAIRE 0.00000001
39#define DERIVEE_PREMIERE_NULLE 0.000000000001
40//----------------------------------------------------------------------
41Standard_Real IntImpParGen::NormalizeOnDomain(Standard_Real& Param,
42 const IntRes2d_Domain& TheDomain) {
43 Standard_Real modParam = Param;
44 if(TheDomain.IsClosed()) {
45 Standard_Real Periode,t;
46 TheDomain.EquivalentParameters(t,Periode);
47 Periode-=t;
48 while( modParam<TheDomain.FirstParameter()
49 && modParam+Periode < TheDomain.LastParameter()) {
50 modParam+=Periode;
51 }
52 while( modParam>TheDomain.LastParameter()
53 && modParam-Periode > TheDomain.FirstParameter()) {
54 modParam-=Periode;
55 }
56 }
57 return(modParam);
58}
59//----------------------------------------------------------------------
60void IntImpParGen::DeterminePosition(IntRes2d_Position& Pos1,
61 const IntRes2d_Domain& TheDomain,
62 const gp_Pnt2d& Pnt1,
63 const Standard_Real Param1) {
64
65 Pos1=IntRes2d_Middle;
66
67 if(TheDomain.HasFirstPoint()) {
68 if(Pnt1.Distance(TheDomain.FirstPoint())
69 <= TheDomain.FirstTolerance()) {
70 Pos1=IntRes2d_Head;
71 }
72 }
73
74 if(TheDomain.HasLastPoint()) {
75 if(Pnt1.Distance(TheDomain.LastPoint())
76 <= TheDomain.LastTolerance()) {
77 if(Pos1==IntRes2d_Head) {
78 if(Abs(Param1-TheDomain.LastParameter())
79 < Abs(Param1-TheDomain.FirstParameter()))
80 Pos1=IntRes2d_End;
81 }
82 else {
83 Pos1=IntRes2d_End;
84 }
85 }
86 }
87}
88//----------------------------------------------------------------------
89void IntImpParGen::DetermineTransition(const IntRes2d_Position Pos1,
90 gp_Vec2d& Tan1,
91 const gp_Vec2d& Norm1,
92 IntRes2d_Transition& T1,
93 const IntRes2d_Position Pos2,
94 gp_Vec2d& Tan2,
95 const gp_Vec2d& Norm2,
96 IntRes2d_Transition& T2,
97 const Standard_Real ) {
98
99 Standard_Boolean courbure1=Standard_True;
100 Standard_Boolean courbure2=Standard_True;
101 Standard_Boolean decide=Standard_True;
102
103 T1.SetPosition(Pos1);
104 T2.SetPosition(Pos2);
105
106
107 if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
108 Tan1=Norm1;
109 courbure1=Standard_False;
110 if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) { // transition undecided
111 decide=Standard_False;
112 }
113 }
114
115 if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
116 Tan2=Norm2;
117 courbure2=Standard_False;
118 if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) { // transition undecided
119 decide=Standard_False;
120 }
121 }
122
123 if (!decide) {
124 T1.SetValue(Pos1);
125 T2.SetValue(Pos2);
126 }
127 else {
128 Standard_Real sgn=Tan1.Crossed(Tan2);
129 Standard_Real norm=Tan1.Magnitude()*Tan2.Magnitude();
130
131 if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) { // Transition TOUCH #########
132 Standard_Boolean opos=(Tan1.Dot(Tan2))<0;
133 if (!(courbure1||courbure2)) {
134 T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
135 T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
136 }
137 else {
138 gp_Vec2d Norm;
139 Tan1.Normalized();
140 Norm.SetCoord(-Tan1.Y(),Tan1.X());
141 Standard_Real Val1,Val2;
142 if (!courbure1) {
143 Val1=0.0;
144 }
145 else {
146 Val1=Norm.Dot(Norm1);
147 }
148 if (!courbure2) {
149 Val2=0.0;
150 }
151 else {
152 Val2=Norm.Dot(Norm2);
153 }
154
155 if (Abs(Val1-Val2) <= TOLERANCE_ANGULAIRE) {
156 T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
157 T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
158 }
159 else if (Val2 > Val1) {
160 T2.SetValue(Standard_True,Pos2,IntRes2d_Inside,opos);
161 if (opos) {
162 T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
163 }
164 else {
165 T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
166 }
167 }
168 else { // Val1 > Val2
169 T2.SetValue(Standard_True,Pos2,IntRes2d_Outside,opos);
170 if (opos) {
171 T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
172 }
173 else {
174 T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
175 }
176 }
177 }
178 }
179 else if (sgn<0) {
180 T1.SetValue(Standard_False,Pos1,IntRes2d_In);
181 T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
182 }
183 else { // sgn>0
184 T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
185 T2.SetValue(Standard_False,Pos2,IntRes2d_In);
186 }
187 }
188}
189
190//----------------------------------------------------------------------
191Standard_Boolean IntImpParGen::DetermineTransition(const IntRes2d_Position Pos1,
192 gp_Vec2d& Tan1,
193 IntRes2d_Transition& T1,
194 const IntRes2d_Position Pos2,
195 gp_Vec2d& Tan2,
196 IntRes2d_Transition& T2,
197 const Standard_Real ) {
198
199 T1.SetPosition(Pos1);
200 T2.SetPosition(Pos2);
201
202 Standard_Real Tan1Magnitude = Tan1.Magnitude();
203 if (Tan1Magnitude<=DERIVEE_PREMIERE_NULLE) {
204 return(Standard_False);
205 }
206
207 Standard_Real Tan2Magnitude = Tan2.Magnitude();
208 if (Tan2Magnitude<=DERIVEE_PREMIERE_NULLE) {
209 return(Standard_False);
210 }
211
212 Standard_Real sgn=Tan1.Crossed(Tan2);
213 Standard_Real norm=Tan1Magnitude*Tan2Magnitude;
214
215 if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) { // Transition TOUCH #########
216 return(Standard_False);
217 }
218 else if (sgn<0) {
219 T1.SetValue(Standard_False,Pos1,IntRes2d_In);
220 T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
221 }
222 else { // sgn>0
223 T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
224 T2.SetValue(Standard_False,Pos2,IntRes2d_In);
225 }
226 return(Standard_True);
227}
228
229
230
231
232
233
234
235
236