summaryrefslogtreecommitdiff
path: root/src/StdPrs/StdPrs_WFDeflectionSurface.cxx
blob: c32f36ce7959ebfe55d9eb6731bfbefbb4abca61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// File:	StdPrs_WFDeflectionSurface.cxx
// Created:	Mon Jul 24 17:25:12 1995
// Author:	Modelistation
//		<model@metrox>


#include <StdPrs_WFDeflectionSurface.ixx>
#include <Graphic3d_Group.hxx>
#include <GeomAbs_IsoType.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <Bnd_Box.hxx>
#include <BndLib_AddSurface.hxx>
#include <Precision.hxx>
#include <gp_Pnt.hxx>
#include <Adaptor3d_IsoCurve.hxx>
#include <StdPrs_DeflectionCurve.hxx>

static void FindLimits(const Handle(Adaptor3d_HSurface)& surf ,
		       const Standard_Real    aLimit,
		       Standard_Real&         UFirst,
		       Standard_Real&         ULast,
		       Standard_Real&         VFirst,
		       Standard_Real&         VLast)
{
  UFirst = surf->FirstUParameter();
  ULast = surf->LastUParameter();
  VFirst = surf->FirstVParameter();
  VLast = surf->LastVParameter();
  
  Standard_Boolean UfirstInf = Precision::IsNegativeInfinite(UFirst);
  Standard_Boolean UlastInf  = Precision::IsPositiveInfinite(ULast);
  Standard_Boolean VfirstInf = Precision::IsNegativeInfinite(VFirst);
  Standard_Boolean VlastInf  = Precision::IsPositiveInfinite(VLast);
  
  if (UfirstInf || UlastInf) {
    gp_Pnt P1,P2;
    Standard_Real v;
    if (VfirstInf && VlastInf) 
      v = 0;
    else if (VfirstInf)
      v = VLast;
    else if (VlastInf)
      v = VFirst;
    else
      v = (VFirst + VLast) / 2;
    
    Standard_Real delta = aLimit * 2;

    if (UfirstInf && UlastInf) {
      do {
	delta /= 2;
	UFirst = - delta;
	ULast  =   delta;
	surf->D0(UFirst,v,P1);
	surf->D0(ULast,v,P2);
      } while (P1.Distance(P2) > aLimit);
    }
    else if (UfirstInf) {
      surf->D0(ULast,v,P2);
      do {
	delta /= 2;
	UFirst = ULast - delta;
	surf->D0(UFirst,v,P1);
      } while (P1.Distance(P2) > aLimit);
    }
    else if (UlastInf) {
      surf->D0(UFirst,v,P1);
      do {
	delta /= 2;
	ULast = UFirst + delta;
	surf->D0(ULast,v,P2);
      } while (P1.Distance(P2) > aLimit);
    }
  }

  if (VfirstInf || VlastInf) {
    gp_Pnt P1,P2;
    Standard_Real u = (UFirst + ULast) /2 ;

    Standard_Real delta = aLimit * 2;

    if (VfirstInf && VlastInf) {
      do {
	delta /= 2;
	VFirst = - delta;
	VLast  =   delta;
	surf->D0(u,VFirst,P1);
	surf->D0(u,VLast,P2);
      } while (P1.Distance(P2) > aLimit);
    }
    else if (VfirstInf) {
      surf->D0(u,VLast,P2);
      do {
	delta /= 2;
	VFirst = VLast - delta;
	surf->D0(u,VFirst,P1);
      } while (P1.Distance(P2) > aLimit);
    }
    else if (VlastInf) {
      surf->D0(u,VFirst,P1);
      do {
	delta /= 2;
	VLast = VFirst + delta;
	surf->D0(u,VLast,P2);
      } while (P1.Distance(P2) > aLimit);
    }
  }



}


//=======================================================================
//function : Add
//purpose  : 
//=======================================================================

void StdPrs_WFDeflectionSurface::Add (
			      const Handle (Prs3d_Presentation)& aPresentation,
			      const Handle(Adaptor3d_HSurface)&    aSurface,
			      const Handle (Prs3d_Drawer)&       aDrawer)
{
    Standard_Real  U1, U2, V1, V2;
    Standard_Real MaxP = aDrawer->MaximalParameterValue();
    FindLimits(aSurface, MaxP, U1, U2, V1, V2);
    
    Standard_Boolean UClosed = aSurface->IsUClosed();
    Standard_Boolean VClosed = aSurface->IsVClosed();
      
    Standard_Real TheDeflection;
    Aspect_TypeOfDeflection TOD = aDrawer->TypeOfDeflection();    
    if (TOD == Aspect_TOD_RELATIVE) {
// On calcule la fleche en fonction des min max globaux de la piece:
       Bnd_Box Total;
       BndLib_AddSurface::Add(aSurface->Surface(),U1, U2, V1, V2, 0.,Total);
       Standard_Real m = aDrawer->MaximalChordialDeviation()/
	 aDrawer->DeviationCoefficient();
       Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
       Total.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
       if ( ! (Total.IsOpenXmin() || Total.IsOpenXmax() ))
	  m = Min ( m , Abs (aXmax-aXmin));
       if ( ! (Total.IsOpenYmin() || Total.IsOpenYmax() ))
	  m = Min ( m , Abs (aYmax-aYmin));
       if ( ! (Total.IsOpenZmin() || Total.IsOpenZmax() ))
	  m = Min ( m , Abs (aZmax-aZmin));

       TheDeflection = m * aDrawer->DeviationCoefficient();
    }
    else
      TheDeflection = aDrawer->MaximalChordialDeviation();  

    Adaptor3d_IsoCurve anIso;
    anIso.Load(aSurface);

    // Trace des frontieres.
    // *********************
    //
    if ( !(UClosed && VClosed) ) {
	
      (Prs3d_Root::CurrentGroup(aPresentation))->SetPrimitivesAspect
	(aDrawer->FreeBoundaryAspect()->Aspect());
      if ( !UClosed ) 
	{ 
	  anIso.Load(GeomAbs_IsoU,U1,V1,V2);
	  StdPrs_DeflectionCurve::Add(aPresentation,anIso,TheDeflection, MaxP);
	  anIso.Load(GeomAbs_IsoU,U2,V1,V2);
	  StdPrs_DeflectionCurve::Add(aPresentation,anIso,TheDeflection, MaxP);
	}
      if ( !VClosed )
	{
	  anIso.Load(GeomAbs_IsoV,V1,U1,U2);
	  StdPrs_DeflectionCurve::Add(aPresentation,anIso,TheDeflection, MaxP);
	  anIso.Load(GeomAbs_IsoV,V2,U1,U2);
	  StdPrs_DeflectionCurve::Add(aPresentation,anIso,TheDeflection, MaxP);
	}
    }
    //
    // Trace des isoparametriques.
    // ***************************
    //
    Standard_Integer fin = aDrawer->UIsoAspect()->Number();
    if ( fin != 0) {
      
      (Prs3d_Root::CurrentGroup(aPresentation))->SetPrimitivesAspect
	(aDrawer->UIsoAspect()->Aspect());
      
      Standard_Real du= UClosed ? (U2-U1)/fin : (U2-U1)/(1+fin);
      for (Standard_Integer i=1; i<=fin;i++){
	anIso.Load(GeomAbs_IsoU,U1+du*i,V1,V2);
	StdPrs_DeflectionCurve::Add(aPresentation,anIso,TheDeflection, MaxP);
      }
    }
    fin = aDrawer->VIsoAspect()->Number();
    if ( fin != 0) {
      
      (Prs3d_Root::CurrentGroup(aPresentation))->SetPrimitivesAspect
	(aDrawer->VIsoAspect()->Aspect());
      
      Standard_Real dv= VClosed ?(V2-V1)/fin : (V2-V1)/(1+fin);
      for (Standard_Integer i=1; i<=fin;i++){
	anIso.Load(GeomAbs_IsoV,V1+dv*i,U1,U2);
	StdPrs_DeflectionCurve::Add(aPresentation,anIso,TheDeflection, MaxP);
      }
    }
  }