0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / AdvApprox / AdvApprox_PrefAndRec.cxx
CommitLineData
b311480e 1// Created on: 1996-11-14
2// Created by: Philippe MANGIN
3// Copyright (c) 1996-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#include <AdvApprox_PrefAndRec.ixx>
24
25#include <Precision.hxx>
26#include <Standard_DomainError.hxx>
27
28
29AdvApprox_PrefAndRec::AdvApprox_PrefAndRec(const TColStd_Array1OfReal& RecCut,
30 const TColStd_Array1OfReal& PrefCut,
31 const Standard_Real Weight):
32 myRecCutting(1, RecCut.Length()),
33 myPrefCutting(1, PrefCut.Length()),
34 myWeight(Weight)
35{
36 myRecCutting = RecCut;
37 myPrefCutting = PrefCut;
38 if (myWeight <= 1) { Standard_DomainError::Raise("PrefAndRec : Weight is too small");}
39}
40
41Standard_Boolean AdvApprox_PrefAndRec::Value(const Standard_Real a,
42 const Standard_Real b,
43 Standard_Real& cuttingvalue) const
44{
45// longueur minimum d'un intervalle parametrique : 10*PConfusion()
46 Standard_Real lgmin = 10 * Precision::PConfusion();
47 Standard_Integer i;
48 Standard_Real cut, mil=(a+b)/2, dist;
49
50 cut = mil;
51
52// Recheche d'une decoupe preferentiel
53 dist = Abs( (a*myWeight+b)/(1+myWeight) - mil ) ;
54 for ( i=1; i<=myPrefCutting.Length(); i++) {
55 if ( dist > Abs(mil-myPrefCutting.Value(i))) {
56 cut = myPrefCutting.Value(i);
57 dist = Abs(mil-cut);
58 }
59 }
60
61// Recheche d'une decoupe recommende
62 dist = Abs((a-b)/2);
63 for ( i=1; i<=myRecCutting.Length(); i++) {
64 if ((dist-lgmin) > Abs(mil-myRecCutting.Value(i))) {
65 cut = myRecCutting.Value(i);
66 dist = Abs(mil-cut);
67 }
68 }
69
70// Resultat
71 cuttingvalue = cut;
72 return (Abs(cut-a)>=lgmin && Abs(b-cut)>=lgmin);
73}