Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // | |
3 | // The content of this file is subject to the Open CASCADE Technology Public | |
4 | // License Version 6.5 (the "License"). You may not use the content of this file | |
5 | // except in compliance with the License. Please obtain a copy of the License | |
6 | // at http://www.opencascade.org and read it completely before using this file. | |
7 | // | |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
10 | // | |
11 | // The Original Code and all software distributed under the License is | |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
13 | // Initial Developer hereby disclaims all such warranties, including without | |
14 | // limitation, any warranties of merchantability, fitness for a particular | |
15 | // purpose or non-infringement. Please see the License for the specific terms | |
16 | // and conditions governing the rights and limitations under the License. | |
17 | ||
7fd59977 | 18 | /*********************************************************************** |
19 | ||
20 | FONCTION : | |
21 | ---------- | |
22 | Classe V3d_View : | |
23 | ||
24 | HISTORIQUE DES MODIFICATIONS : | |
25 | -------------------------------- | |
26 | 00-09-92 : GG ; Creation. | |
27 | 02-10-96 : FMN ; Suppression appel Redraw sans MustBeResized() | |
28 | 05-06-97 : FMN ; Correction FitAll() | |
29 | 30-06-97 : GG ; Correction + Optimisation de Panning(...) | |
30 | On fait la translation + le zoom en une seule | |
31 | operation au lieu de 2 precedemment qui etait buggee. | |
32 | 09-07-97 : FMN ; Correction FitAll() sur le Ratio | |
33 | 16-07-97 : FMN ; Correction FitAll() sur le calcul de la Box | |
34 | 22-07-97 : FMN ; Ajout mode RetainMode pour le Transient | |
35 | 15-12-97 : FMN ; Ajout texture mapping | |
36 | 17-12-97 : FMN ; CTS19129 Correction FitAll() multiple | |
37 | 18-12-97 : FMN ; Ajout mode Ajout | |
38 | 24-12-97 : FMN ; Remplacement de math par MathGra | |
39 | 24-12-97 : CQO ; BUC50037 Xw_Window -> Aspect_Window | |
40 | 31-12-97 : CAL ; Remplacement de MathGra par Array2OfReal | |
41 | 07-01-98 : CAL ; Ajout de la methode DoMapping. | |
42 | 07-01-98 : CAL ; Retrait de tous les "this->" inutiles | |
43 | 21-01-98 : CAL ; Remplacement des Window->Position () par Window->Size () | |
44 | 27-01-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM) | |
45 | 12-02-98 : GG ; Reactivation du Redraw dans MustBeResized() | |
46 | 23-02-98 : FMN ; Remplacement PI par Standard_PI | |
47 | 25-02-98 : FMN ; PERF.27: Optimisation of view creation from existing view | |
48 | 11-03-98 : STT ; S3558 | |
49 | 19-03-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real) | |
50 | ne marche pas. | |
51 | 08-04-98 : STT ; suppr. S3558 | |
52 | 10-04-98 : CAL ; Ajout des methodes RefToPix et PixToRef | |
53 | 13-06-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real) | |
54 | ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int). | |
55 | 16-08-98 : CAL ; S3892. Ajout grilles 3d. | |
56 | 09-09-98 : CAL ; S3892. Generalisation de TrsPoint. | |
57 | 24-09-98 : CAL ; Ajout d'un parametre a V3d_View::SetPlotter. | |
58 | 06-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie. | |
59 | 16-10-98 : CAL ; Retrait d'un TIMER si CSF_GraphicTimer est definie. | |
60 | 06-11-98 : CAL ; PRO ?????. Probleme dans ZFitAll si un point dans la vue. | |
61 | 13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guinde) | |
62 | 29-OCT-98 : DCB : Adding ScreenCopy () method. | |
63 | 22-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH | |
64 | 10-11-99 : GG ; PRO19603 Add Redraw( area ) method | |
65 | IMP130100 : GG | |
66 | -> Don't increase too much the ZSize. | |
67 | -> Initialize correctly the Z clipping and D cueing | |
68 | planes. | |
69 | IMP100701 : SZV ; Add ToPixMap() method | |
70 | ||
71 | REMARQUES : | |
72 | ----------- | |
73 | About FitAll() multiple. This probleme is caused by missing | |
74 | precision of transformation matrices. If it is supposed that | |
75 | projection is made in the plane (U,V), there is a difference | |
76 | after several Zoom - compared to the exact value (cf ZoomX). | |
77 | Don't forget that the matrices work in float and not in double. | |
78 | To solve the problem (for lack of a better solution) I make 2 passes. | |
79 | ||
80 | ************************************************************************/ | |
81 | ||
b8ddfc2f | 82 | //GER61351 //GG_15/12/99 Add SetBackgroundColor() and BackgroundColor() methods |
7fd59977 | 83 | |
84 | ||
85 | #define IMP240100 //GG | |
86 | // -> Remove PixToRef() method ,use | |
87 | // instead the equivalent Convert() method. | |
88 | // -> Rename RefToPix() to Convert() method. | |
89 | // -> Remove the grid computation in Convert() | |
90 | // method. Use instead the NEW ConvertToGrid() methods. | |
91 | // Reason is the Convert() method is call by | |
92 | // StdSelect_ViewSelector3d_Pick() from | |
93 | // AIS_InteractiveContext() and it's not possible | |
94 | // to select an object vertex when the grid is active! | |
95 | // -> Remove grid echo marker definition | |
96 | // (reported in the viewer) | |
97 | // -> Add SetProjModel() methods. | |
98 | ||
7fd59977 | 99 | #define G004 //VKH 15-11-99 |
100 | // -> Add Dump() methods | |
101 | // -> GG 07/03/00 Use the new MMSize() | |
102 | // method from Aspect_Window class. | |
103 | ||
104 | #define IMP210200 //GG Add Transparency() method | |
105 | ||
106 | #define IMP250200 //GG With SetDepth() method, when the requested | |
107 | // depth is < 0., | |
108 | // move the view ref point and the eye,instead | |
109 | // only the eye. | |
110 | ||
111 | #define IMP020300 //GG Don't use ZFitAll in during Rotation | |
112 | // for perf improvment | |
113 | ||
114 | #define IMP210600 //GG Avoid to have infinite loop when call Rotation() method | |
115 | // without call before StartRotation(). | |
116 | // This problem occurs when CTRL MB3 is maintain press betwwen 2 views. | |
117 | ||
118 | #define IMP250900 //GG Enable rotation around screen Z axis when | |
119 | // rotation begin far the center of the screen. | |
120 | // Thanks to Patrick REGINSTER (SAMTECH) | |
121 | // GG 21/12/00 Due to a regression on the previous specifications | |
122 | // this new functionnality is right now deactivated | |
123 | // by default (see StartRotation(...,zRotationThreshold) | |
124 | // method. | |
125 | ||
126 | #define BUC60952 //GG Enable to rotate around the view axis | |
127 | // and the required view point | |
128 | ||
129 | #define RIC120302 //GG Add a NEW SetWindow method which enable | |
130 | // to connect a graphic widget and context to OGL. | |
131 | ||
132 | #define IMP260302 //GG To avoid conflicting in Window destructor | |
133 | // nullify this handle in Remove method | |
134 | ||
135 | #define OCC280 //SAV fix for FitAll problem in the perspective view. | |
136 | ||
137 | #define OCC1188 //SAV Added methods to set background image | |
138 | ||
139 | /*----------------------------------------------------------------------*/ | |
140 | /* | |
141 | * Includes | |
142 | */ | |
143 | ||
144 | #include <Standard_TypeMismatch.hxx> | |
145 | #include <Visual3d_ViewManager.hxx> | |
146 | #include <Visual3d_Light.hxx> | |
7fd59977 | 147 | #include <Graphic3d_Structure.hxx> |
148 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> | |
149 | #include <Graphic3d_MapOfStructure.hxx> | |
150 | #include <Graphic3d_TextureEnv.hxx> | |
692613e5 | 151 | #include <Image_AlienPixMap.hxx> |
7fd59977 | 152 | #include <V3d.hxx> |
153 | #include <V3d_View.ixx> | |
6942f04a | 154 | #include <V3d_BadValue.hxx> |
7fd59977 | 155 | #include <Standard_ShortReal.hxx> |
156 | #include <gp_Dir.hxx> | |
157 | #include <TColStd_Array2OfReal.hxx> | |
158 | #include <Visual3d_TransientManager.hxx> | |
159 | #include <Precision.hxx> | |
160 | ||
161 | // S3892 | |
162 | #include <Graphic3d_AspectMarker3d.hxx> | |
1981cb22 | 163 | #include <Graphic3d_GraphicDriver.hxx> |
7fd59977 | 164 | |
165 | // S3603 | |
166 | #include <Aspect_GenericColorMap.hxx> | |
167 | #include <Aspect_TypeMap.hxx> | |
168 | #include <Aspect_WidthMap.hxx> | |
169 | #include <Aspect_MarkMap.hxx> | |
170 | #include <Aspect_FontMap.hxx> | |
7fd59977 | 171 | #include <TColStd_HSequenceOfInteger.hxx> |
7fd59977 | 172 | |
de75ed09 | 173 | #define V3d_FLAG_COMPUTATION 0x00000004 |
7fd59977 | 174 | |
175 | // Perspective | |
176 | #include <OSD_Environment.hxx> | |
177 | ||
178 | /*----------------------------------------------------------------------*/ | |
179 | /* | |
180 | * Constant | |
181 | */ | |
182 | ||
183 | #define Zmargin 1. | |
c6541a0c | 184 | #define DEUXPI (2. * M_PI) |
7fd59977 | 185 | |
7fd59977 | 186 | /*----------------------------------------------------------------------*/ |
187 | /* | |
188 | * Local data definitions | |
189 | */ | |
190 | ||
191 | ||
192 | static Standard_Real MyXwindowCenter ; | |
193 | static Standard_Real MyYwindowCenter ; | |
194 | static Standard_Real MyWindowWidth ; | |
195 | static Standard_Real MyWindowHeight ; | |
196 | ||
197 | #define LOPTIM | |
198 | #ifndef LOPTIM | |
199 | static Graphic3d_Vector MyXscreenAxis ; | |
200 | static Graphic3d_Vector MyYscreenAxis ; | |
201 | static Graphic3d_Vector MyZscreenAxis ; | |
202 | static Graphic3d_Vector MyViewReferencePlane ; | |
203 | static Graphic3d_Vector MyViewReferenceUp ; | |
204 | static Graphic3d_Vector MyViewAxis ; | |
205 | static Graphic3d_Vertex MyViewReferencePoint ; | |
206 | static Graphic3d_Vertex MyGravityReferencePoint ; | |
207 | static Graphic3d_Vertex MyProjReferencePoint ; | |
208 | #else | |
209 | static Graphic3d_Vector& _MyXscreenAxis() { | |
210 | static Graphic3d_Vector MyXscreenAxis; | |
211 | return MyXscreenAxis; | |
212 | } | |
213 | #define MyXscreenAxis _MyXscreenAxis() | |
214 | ||
215 | static Graphic3d_Vector& _MyYscreenAxis() { | |
216 | static Graphic3d_Vector MyYscreenAxis; | |
217 | return MyYscreenAxis; | |
218 | } | |
219 | #define MyYscreenAxis _MyYscreenAxis() | |
220 | ||
221 | static Graphic3d_Vector& _MyZscreenAxis() { | |
222 | static Graphic3d_Vector MyZscreenAxis; | |
223 | return MyZscreenAxis; | |
224 | } | |
225 | #define MyZscreenAxis _MyZscreenAxis() | |
226 | ||
227 | static Graphic3d_Vector& _MyViewReferencePlane() { | |
228 | static Graphic3d_Vector MyViewReferencePlane; | |
229 | return MyViewReferencePlane; | |
230 | } | |
231 | #define MyViewReferencePlane _MyViewReferencePlane() | |
232 | ||
233 | static Graphic3d_Vector& _MyViewReferenceUp() { | |
234 | static Graphic3d_Vector MyViewReferenceUp; | |
235 | return MyViewReferenceUp; | |
236 | } | |
237 | #define MyViewReferenceUp _MyViewReferenceUp() | |
238 | ||
239 | static Graphic3d_Vector& _MyViewAxis() { | |
240 | static Graphic3d_Vector MyViewAxis; | |
241 | return MyViewAxis; | |
242 | } | |
243 | #define MyViewAxis _MyViewAxis() | |
244 | ||
245 | static Graphic3d_Vertex& _MyViewReferencePoint() { | |
246 | static Graphic3d_Vertex MyViewReferencePoint; | |
247 | return MyViewReferencePoint; | |
248 | } | |
249 | #define MyViewReferencePoint _MyViewReferencePoint() | |
250 | ||
251 | static Graphic3d_Vertex& _MyGravityReferencePoint() { | |
252 | static Graphic3d_Vertex MyGravityReferencePoint; | |
253 | return MyGravityReferencePoint; | |
254 | } | |
255 | #define MyGravityReferencePoint _MyGravityReferencePoint() | |
256 | ||
257 | static Graphic3d_Vertex& _MyProjReferencePoint() { | |
258 | static Graphic3d_Vertex MyProjReferencePoint; | |
259 | return MyProjReferencePoint; | |
260 | } | |
261 | #define MyProjReferencePoint _MyProjReferencePoint() | |
262 | #endif // LOPTIM | |
263 | ||
264 | /*----------------------------------------------------------------------*/ | |
265 | //-Constructors | |
266 | ||
267 | V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) : | |
268 | MyType ( Type ), | |
269 | MyViewer(VM.operator->()), | |
270 | MyActiveLights(), | |
7fd59977 | 271 | MyViewContext (), |
272 | myActiveLightsIterator(), | |
7fd59977 | 273 | SwitchSetFront(Standard_False), |
2f6cb3ac | 274 | MyProjModel(V3d_TPM_SCREEN), |
275 | MyTrsf (1, 4, 1, 4) // S3892 | |
7fd59977 | 276 | { |
7fd59977 | 277 | myImmediateUpdate = Standard_False; |
278 | MyView = new Visual3d_View(MyViewer->Viewer()); | |
279 | ||
280 | // { Begin to retrieve the definition from ViewContext. | |
281 | // Step MyViewContext = MyView->Context() ; | |
282 | // to permit MyView->SetContext to compare | |
283 | // the old and the new context. | |
284 | // No problem for MyViewMapping, MyViewOrientation | |
285 | // as MyView->SetViewMapping and MyView->SetViewOrientation | |
286 | // don't try to optimize the modifications introduced to | |
287 | // viewmapping and vieworientation. | |
288 | ||
289 | // Aliasing | |
290 | if ((MyView->Context ()).AliasingIsOn ()) | |
291 | MyViewContext.SetAliasingOn (); | |
292 | else | |
293 | MyViewContext.SetAliasingOff (); | |
294 | ||
295 | // DepthCueing | |
296 | MyViewContext.SetDepthCueingBackPlane | |
297 | ((MyView->Context ()).DepthCueingBackPlane ()); | |
298 | MyViewContext.SetDepthCueingFrontPlane | |
299 | ((MyView->Context ()).DepthCueingFrontPlane ()); | |
300 | ||
301 | if ((MyView->Context ()).DepthCueingIsOn ()) | |
302 | MyViewContext.SetDepthCueingOn (); | |
303 | else | |
304 | MyViewContext.SetDepthCueingOff (); | |
305 | ||
306 | // ZClipping | |
307 | MyViewContext.SetZClippingBackPlane | |
308 | ((MyView->Context ()).ZClippingBackPlane ()); | |
309 | MyViewContext.SetZClippingFrontPlane | |
310 | ((MyView->Context ()).ZClippingFrontPlane ()); | |
311 | ||
312 | if ((MyView->Context ()).FrontZClippingIsOn ()) | |
313 | MyViewContext.SetFrontZClippingOn (); | |
314 | else | |
315 | MyViewContext.SetFrontZClippingOff (); | |
316 | ||
317 | if ((MyView->Context ()).BackZClippingIsOn ()) | |
318 | MyViewContext.SetBackZClippingOn (); | |
319 | else | |
320 | MyViewContext.SetBackZClippingOff (); | |
321 | ||
322 | // Visualisation and Shading Model | |
323 | MyViewContext.SetModel ((MyView->Context ()).Model ()); | |
324 | MyViewContext.SetVisualization ((MyView->Context ()).Visualization ()); | |
325 | ||
326 | // Texture Mapping | |
327 | MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ()); | |
328 | MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ()); | |
329 | // } End of retrieval of the definition of ViewContext. | |
330 | ||
331 | MyViewMapping = MyView->ViewMapping() ; | |
332 | MyViewOrientation = MyView->ViewOrientation() ; | |
333 | MyBackground = VM->GetBackgroundColor() ; | |
334 | MyGradientBackground = VM->GetGradientBackground() ; | |
335 | ||
336 | SetAxis(0.,0.,0.,1.,1.,1.) ; | |
337 | SetVisualization(VM->DefaultVisualization()) ; | |
338 | SetShadingModel(VM->DefaultShadingModel()) ; | |
339 | SetSurfaceDetail(VM->DefaultSurfaceDetail()) ; | |
340 | SetTwist(0.) ; | |
341 | SetAt(0.,0.,0.) ; | |
342 | SetProj(VM->DefaultViewProj()) ; | |
343 | SetSize(VM->DefaultViewSize()) ; | |
344 | Standard_Real zsize = VM->DefaultViewSize(); | |
345 | SetZSize(2.*zsize+zsize*Zmargin) ; | |
346 | SetZClippingDepth(0.); | |
347 | SetZClippingWidth(zsize); | |
348 | SetZCueingDepth(0.); | |
349 | SetZCueingWidth(zsize); | |
350 | SetDepth(VM->DefaultViewSize()/2.) ; | |
351 | SetCenter(0.,0.) ; | |
352 | SetViewMappingDefault(); | |
353 | VM->AddView(this) ; | |
354 | Init(); | |
355 | myImmediateUpdate = Standard_True; | |
356 | ||
357 | // S3892 | |
358 | #ifndef IMP240100 | |
7fd59977 | 359 | #endif //IMP240100 |
360 | ||
7fd59977 | 361 | #ifdef IMP210200 |
362 | MyTransparencyFlag = Standard_False; | |
363 | #endif | |
7fd59977 | 364 | } |
365 | ||
366 | /*----------------------------------------------------------------------*/ | |
367 | ||
368 | V3d_View::V3d_View(const Handle(V3d_Viewer)& VM,const Handle(V3d_View)& V, const V3d_TypeOfView Type ) : | |
369 | MyType ( Type ), | |
370 | MyViewer(VM.operator->()), | |
371 | MyActiveLights(), | |
7fd59977 | 372 | MyViewContext (), |
373 | myActiveLightsIterator(), | |
7fd59977 | 374 | SwitchSetFront(Standard_False), |
375 | MyTrsf (1, 4, 1, 4), // S3892 | |
376 | MyProjModel(V3d_TPM_SCREEN) | |
7fd59977 | 377 | { |
7fd59977 | 378 | Handle(Visual3d_View) FromView = V->View() ; |
379 | ||
380 | myImmediateUpdate = Standard_False; | |
381 | MyView = new Visual3d_View(MyViewer->Viewer()); | |
382 | ||
383 | for (V->InitActiveLights();V->MoreActiveLights();V->NextActiveLights()){ | |
384 | MyActiveLights.Append(V->ActiveLight());} | |
7fd59977 | 385 | |
386 | MyViewContext = FromView->Context() ; | |
387 | ||
388 | MyViewMapping = FromView->ViewMapping() ; | |
389 | MyViewOrientation = FromView->ViewOrientation() ; | |
390 | MyBackground = FromView->Background() ; | |
391 | MyGradientBackground = FromView->GradientBackground(); | |
392 | ||
393 | MyView->SetContext(MyViewContext) ; | |
394 | ||
395 | SetAxis(0.,0.,0.,1.,1.,1.) ; | |
396 | VM->AddView(this) ; | |
397 | Init(); | |
398 | myImmediateUpdate = Standard_True; | |
7fd59977 | 399 | } |
400 | ||
401 | /*----------------------------------------------------------------------*/ | |
402 | ||
403 | //-Methods, in order | |
404 | ||
405 | void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow, | |
406 | const Handle(V3d_View)& aPreviousView, | |
407 | const Standard_Integer x1, | |
408 | const Standard_Integer y1, | |
409 | const Standard_Integer x2, | |
410 | const Standard_Integer y2) | |
411 | { | |
7fd59977 | 412 | if( !MyView->IsDefined() ) { |
413 | Standard_Real a,b,c,d; | |
414 | aPreviousView->Convert(x1,y1,a,b); | |
415 | aPreviousView->Convert(x2,y2,c,d); | |
416 | MyView->SetWindow(TheWindow) ; | |
417 | FitAll(TheWindow,a,b,c,d); | |
418 | MyView->SetContext(MyViewContext) ; | |
419 | MyView->SetViewOrientation(MyViewOrientation) ; | |
420 | MyView->SetBackground(MyBackground) ; | |
421 | MyViewer->SetViewOn(this) ; | |
422 | MyWindow = TheWindow; | |
423 | MyView->Redraw() ; | |
424 | SetViewMappingDefault(); | |
425 | } | |
7fd59977 | 426 | } |
427 | ||
428 | /*----------------------------------------------------------------------*/ | |
429 | ||
430 | void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow) | |
431 | { | |
7fd59977 | 432 | Standard_MultiplyDefined_Raise_if( MyView->IsDefined(), |
433 | "V3d_View::SetWindow, window of view already defined"); | |
434 | ||
435 | MyView->SetWindow(TheWindow) ; | |
cdc2203b M |
436 | // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before |
437 | // calling Redraw(). Otherwise it is impossible to call certain methods of | |
438 | // V3d_View like Convert() inside the context of Redraw(), | |
439 | // particularly in class NIS_View. | |
440 | MyWindow = TheWindow; | |
7fd59977 | 441 | // SetWindow carries out SetRatio and modifies |
442 | // ViewMapping and ViewMappingDefault of MyView. | |
443 | MyViewMapping = MyView->ViewMapping() ; | |
444 | MyView->SetContext(MyViewContext) ; | |
445 | MyView->SetViewMapping(MyViewMapping) ; | |
446 | MyView->SetViewOrientation(MyViewOrientation) ; | |
447 | MyView->SetBackground(MyBackground) ; | |
448 | MyViewer->SetViewOn(this) ; | |
7fd59977 | 449 | MyView->Redraw() ; |
7fd59977 | 450 | } |
451 | ||
452 | // RIC120302 | |
453 | /*----------------------------------------------------------------------*/ | |
454 | ||
455 | void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow, | |
456 | const Aspect_RenderingContext aContext, | |
457 | const Aspect_GraphicCallbackProc& aDisplayCB, | |
458 | const Standard_Address aClientData) | |
459 | { | |
7fd59977 | 460 | Standard_MultiplyDefined_Raise_if( MyView->IsDefined(), |
461 | "V3d_View::SetWindow, " | |
462 | "window of view already defined"); | |
cdc2203b M |
463 | // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before |
464 | // calling Redraw(). Otherwise it is impossible to call certain methods of | |
465 | // V3d_View like Convert() inside the context of Redraw(), | |
466 | // particularly in class NIS_View. | |
467 | MyWindow = aWindow; | |
7fd59977 | 468 | MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ; |
469 | MyViewMapping = MyView->ViewMapping() ; | |
470 | MyView->SetContext(MyViewContext) ; | |
471 | MyView->SetViewMapping(MyViewMapping) ; | |
472 | MyView->SetViewOrientation(MyViewOrientation) ; | |
473 | MyView->SetBackground(MyBackground) ; | |
474 | MyViewer->SetViewOn(this) ; | |
475 | MyView->Redraw() ; | |
7fd59977 | 476 | } |
477 | // RIC120302 | |
478 | ||
479 | /*----------------------------------------------------------------------*/ | |
480 | ||
5e27df78 | 481 | void V3d_View::Remove() const |
482 | { | |
483 | MyViewer->DelView (this); | |
484 | MyView->Remove(); | |
485 | Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow); | |
486 | aWin.Nullify(); | |
7fd59977 | 487 | } |
488 | ||
489 | /*----------------------------------------------------------------------*/ | |
490 | ||
b8ddfc2f | 491 | void V3d_View::Update() const |
492 | { | |
7fd59977 | 493 | if( MyView->IsDefined() ) MyView->Update() ; |
494 | } | |
495 | ||
496 | /*----------------------------------------------------------------------*/ | |
497 | ||
b8ddfc2f | 498 | void V3d_View::Redraw() const |
499 | { | |
7fd59977 | 500 | if( MyView->IsDefined() ) MyView->Redraw() ; |
501 | } | |
b8ddfc2f | 502 | |
7fd59977 | 503 | /*----------------------------------------------------------------------*/ |
504 | ||
505 | void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc, | |
506 | const Standard_Integer width,const Standard_Integer height) const | |
507 | { | |
508 | if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ; | |
509 | } | |
510 | ||
511 | /*----------------------------------------------------------------------*/ | |
512 | ||
b8ddfc2f | 513 | Standard_Boolean V3d_View::IsEmpty() const |
514 | { | |
7fd59977 | 515 | Standard_Boolean TheStatus = Standard_True ; |
516 | if( MyView->IsDefined() ) { | |
517 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; | |
518 | if( Nstruct > 0 ) TheStatus = Standard_False ; | |
519 | } | |
520 | return (TheStatus) ; | |
7fd59977 | 521 | } |
522 | ||
523 | /*----------------------------------------------------------------------*/ | |
524 | ||
b8ddfc2f | 525 | void V3d_View::UpdateLights() const |
526 | { | |
7fd59977 | 527 | MyView->SetContext(MyViewContext); |
528 | Update(); | |
529 | } | |
530 | ||
531 | /*----------------------------------------------------------------------*/ | |
532 | ||
b8ddfc2f | 533 | void V3d_View::DoMapping() |
534 | { | |
7fd59977 | 535 | if( MyView->IsDefined() ) { |
536 | (MyView->Window())->DoMapping() ; | |
537 | } | |
538 | } | |
539 | ||
540 | /*----------------------------------------------------------------------*/ | |
541 | ||
b8ddfc2f | 542 | void V3d_View::MustBeResized() |
543 | { | |
7fd59977 | 544 | if ( !MyLayerMgr.IsNull() ) |
545 | MyLayerMgr->Resized(); | |
546 | ||
547 | if( MyView->IsDefined() ) { | |
548 | MyView->Resized() ; | |
549 | MyViewMapping = MyView->ViewMapping(); | |
550 | MyView->Redraw(); | |
551 | } | |
7fd59977 | 552 | } |
553 | ||
554 | /*----------------------------------------------------------------------*/ | |
555 | ||
556 | void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) | |
557 | { | |
558 | Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 ); | |
559 | Standard_Real V2 = Max( Min( v2, 1.0 ), 0.0 ); | |
560 | Standard_Real V3 = Max( Min( v3, 1.0 ), 0.0 ); | |
561 | ||
562 | Quantity_Color C( V1, V2, V3, Type ); | |
7fd59977 | 563 | SetBackgroundColor( C ); |
7fd59977 | 564 | } |
565 | ||
7fd59977 | 566 | /*----------------------------------------------------------------------*/ |
567 | ||
568 | void V3d_View::SetBackgroundColor(const Quantity_Color &Color) | |
569 | { | |
570 | MyBackground.SetColor( Color ); | |
571 | if ( MyView->IsDefined() ) | |
572 | MyView->SetBackground( MyBackground ); | |
573 | //szv: Why? | |
574 | if ( !MyLayerMgr.IsNull() ) | |
575 | MyLayerMgr->Resized(); | |
576 | } | |
7fd59977 | 577 | |
578 | /*----------------------------------------------------------------------*/ | |
579 | ||
580 | void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name) | |
581 | { | |
582 | Quantity_Color C( Name ); | |
7fd59977 | 583 | SetBackgroundColor( C ); |
7fd59977 | 584 | } |
585 | ||
586 | /*----------------------------------------------------------------------*/ | |
587 | ||
588 | void V3d_View::SetBgGradientColors( const Quantity_Color& Color1, | |
589 | const Quantity_Color& Color2, | |
590 | const Aspect_GradientFillMethod FillStyle, | |
591 | const Standard_Boolean status) | |
592 | { | |
7fd59977 | 593 | MyGradientBackground.SetColors(Color1, Color2, FillStyle); |
594 | if ( MyView->IsDefined() ) | |
595 | MyView->SetGradientBackground( MyGradientBackground, status ); | |
7fd59977 | 596 | } |
597 | ||
598 | /*----------------------------------------------------------------------*/ | |
599 | ||
600 | void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1, | |
601 | const Quantity_NameOfColor Color2, | |
602 | const Aspect_GradientFillMethod FillStyle, | |
603 | const Standard_Boolean status ) | |
604 | { | |
605 | Quantity_Color C1( Color1 ); | |
606 | Quantity_Color C2( Color2 ); | |
607 | MyGradientBackground.SetColors( C1, C2, FillStyle ); | |
608 | if ( MyView->IsDefined() ) | |
609 | MyView->SetGradientBackground( MyGradientBackground, status ); | |
610 | } | |
611 | ||
612 | /*----------------------------------------------------------------------*/ | |
613 | ||
614 | void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle, | |
f8b2ed36 | 615 | const Standard_Boolean update) |
7fd59977 | 616 | { |
f8b2ed36 | 617 | Quantity_Color Color1, Color2; |
618 | MyGradientBackground.Colors( Color1, Color2 ); | |
619 | MyGradientBackground.SetColors( Color1, Color2, FillStyle ); | |
7fd59977 | 620 | if( MyView->IsDefined() ) |
f8b2ed36 | 621 | MyView->SetBgGradientStyle( FillStyle, update ) ; |
7fd59977 | 622 | } |
623 | ||
624 | /*----------------------------------------------------------------------*/ | |
625 | ||
626 | void V3d_View::SetBackgroundImage( const Standard_CString FileName, | |
627 | const Aspect_FillMethod FillStyle, | |
628 | const Standard_Boolean update ) | |
629 | { | |
630 | #ifdef OCC1188 | |
631 | if( MyView->IsDefined() ) | |
632 | MyView->SetBackgroundImage( FileName, FillStyle, update ) ; | |
633 | #endif | |
634 | } | |
635 | ||
636 | /*----------------------------------------------------------------------*/ | |
637 | ||
638 | void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle, | |
639 | const Standard_Boolean update ) | |
640 | { | |
641 | #ifdef OCC1188 | |
642 | if( MyView->IsDefined() ) | |
643 | MyView->SetBgImageStyle( FillStyle, update ) ; | |
644 | #endif | |
645 | } | |
646 | ||
647 | /*----------------------------------------------------------------------*/ | |
648 | ||
b8ddfc2f | 649 | void V3d_View::SetAxis(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) |
650 | { | |
7fd59977 | 651 | Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ; |
652 | ||
653 | D = Sqrt( Vx*Vx + Vy*Vy + Vz*Vz ) ; | |
6942f04a | 654 | V3d_BadValue_Raise_if ( D <= 0. , "V3d_View::SetAxis, bad axis"); |
7fd59977 | 655 | Nx /= D ; Ny /= D ; Nz /= D ; |
656 | MyDefaultViewPoint.SetCoord(X,Y,Z) ; | |
657 | MyDefaultViewAxis.SetCoord(Nx,Ny,Nz) ; | |
658 | MyDefaultViewAxis.Normalize() ; | |
7fd59977 | 659 | } |
660 | ||
661 | /*----------------------------------------------------------------------*/ | |
662 | ||
b8ddfc2f | 663 | void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model) |
664 | { | |
7fd59977 | 665 | MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ; |
666 | MyView->SetContext(MyViewContext) ; | |
7fd59977 | 667 | } |
668 | ||
669 | /*----------------------------------------------------------------------*/ | |
670 | ||
b8ddfc2f | 671 | void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model) |
672 | { | |
7fd59977 | 673 | MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ; |
674 | MyView->SetContext(MyViewContext) ; | |
7fd59977 | 675 | } |
676 | ||
677 | /*----------------------------------------------------------------------*/ | |
678 | ||
b8ddfc2f | 679 | void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) |
680 | { | |
7fd59977 | 681 | MyViewContext.SetTextureEnv(ATexture) ; |
682 | MyView->SetContext(MyViewContext) ; | |
7fd59977 | 683 | } |
684 | ||
685 | /*----------------------------------------------------------------------*/ | |
686 | ||
b8ddfc2f | 687 | void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode) |
688 | { | |
7fd59977 | 689 | MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode); |
690 | MyView->SetContext(MyViewContext) ; | |
7fd59977 | 691 | } |
692 | ||
693 | /*----------------------------------------------------------------------*/ | |
694 | ||
b8ddfc2f | 695 | void V3d_View::SetFront() |
696 | { | |
7fd59977 | 697 | gp_Ax3 a = MyViewer->PrivilegedPlane(); |
698 | Standard_Real xo,yo,zo,vx,vy,vz,xu,yu,zu; | |
699 | ||
700 | a.Direction().Coord(vx,vy,vz); | |
701 | a.YDirection().Coord(xu,yu,zu); | |
702 | a.Location().Coord(xo,yo,zo); | |
703 | ||
704 | if(SwitchSetFront) | |
705 | MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(-vx,-vy,-vz)); | |
706 | else | |
707 | MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(vx,vy,vz)); | |
708 | ||
709 | SwitchSetFront = !SwitchSetFront; | |
710 | ||
711 | MyViewOrientation.SetViewReferenceUp(Graphic3d_Vector(xu,yu,zu)); | |
712 | MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(xo,yo,zo)); | |
713 | ||
714 | MyView->SetViewOrientation(MyViewOrientation) ; | |
715 | ||
716 | ImmediateUpdate(); | |
7fd59977 | 717 | } |
718 | ||
719 | /*----------------------------------------------------------------------*/ | |
720 | ||
b8ddfc2f | 721 | void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start) |
722 | { | |
7fd59977 | 723 | Standard_Real Ax = ax ; |
724 | Standard_Real Ay = ay ; | |
725 | Standard_Real Az = az ; | |
726 | Graphic3d_Vector Vpn,Vup ; | |
727 | TColStd_Array2OfReal Matrix(0,3,0,3) ; | |
728 | TColStd_Array2OfReal Rmatrix(0,3,0,3) ; | |
729 | ||
730 | if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ; | |
731 | else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ; | |
732 | if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ; | |
733 | else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ; | |
734 | if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ; | |
735 | else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ; | |
736 | ||
737 | if( Start ) { | |
738 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
739 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
740 | MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ; | |
741 | if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
742 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis)) | |
6942f04a | 743 | V3d_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up"); |
7fd59977 | 744 | } |
745 | ||
746 | InitMatrix(Matrix) ; | |
747 | ||
748 | if( Ax != 0. ) RotAxis(MyViewReferencePoint,MyYscreenAxis,-Ax,Matrix); | |
749 | if( Ay != 0. ) { | |
750 | RotAxis(MyViewReferencePoint,MyXscreenAxis,Ay,Rmatrix) ; | |
751 | Multiply(Matrix, Rmatrix, Matrix); | |
752 | } | |
753 | if( Az != 0. ) { | |
754 | RotAxis(MyViewReferencePoint,MyZscreenAxis,Az,Rmatrix) ; | |
755 | Multiply(Matrix, Rmatrix, Matrix); | |
756 | } | |
757 | Vpn = TrsPoint(MyViewReferencePlane,Matrix) ; | |
758 | MyViewOrientation.SetViewReferencePlane(Vpn) ; | |
759 | Vup = TrsPoint(MyViewReferenceUp,Matrix) ; | |
760 | MyViewOrientation.SetViewReferenceUp(Vup) ; | |
761 | MyView->SetViewOrientation(MyViewOrientation) ; | |
762 | #ifdef IMP020300 | |
763 | SetZSize(0.) ; | |
764 | #endif | |
765 | ImmediateUpdate(); | |
7fd59977 | 766 | } |
767 | ||
768 | /*----------------------------------------------------------------------*/ | |
769 | ||
770 | void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, | |
771 | const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start) | |
772 | { | |
7fd59977 | 773 | Standard_Real Ax = ax ; |
774 | Standard_Real Ay = ay ; | |
775 | Standard_Real Az = az ; | |
776 | Graphic3d_Vector Vpn,Vup ; | |
777 | Graphic3d_Vertex Vrp ; | |
778 | TColStd_Array2OfReal Matrix(0,3,0,3) ; | |
779 | TColStd_Array2OfReal Rmatrix(0,3,0,3) ; | |
780 | ||
781 | if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ; | |
782 | else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ; | |
783 | if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ; | |
784 | else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ; | |
785 | if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ; | |
786 | else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ; | |
787 | ||
788 | if( Start ) { | |
789 | MyGravityReferencePoint.SetCoord(X,Y,Z) ; | |
790 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
791 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
792 | MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ; | |
793 | if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
794 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis)) | |
6942f04a | 795 | V3d_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up"); |
7fd59977 | 796 | } |
797 | ||
798 | InitMatrix(Matrix) ; | |
799 | ||
800 | if( Ax != 0. ) RotAxis(MyGravityReferencePoint,MyYscreenAxis,-Ax,Matrix); | |
801 | if( Ay != 0. ) { | |
802 | RotAxis(MyGravityReferencePoint,MyXscreenAxis,Ay,Rmatrix) ; | |
803 | Multiply(Matrix, Rmatrix, Matrix); | |
804 | } | |
805 | if( Az != 0. ) { | |
806 | RotAxis(MyGravityReferencePoint,MyZscreenAxis,Az,Rmatrix) ; | |
807 | Multiply(Matrix, Rmatrix, Matrix); | |
808 | } | |
809 | Vrp = TrsPoint(MyViewReferencePoint,Matrix) ; | |
810 | MyViewOrientation.SetViewReferencePoint(Vrp) ; | |
811 | Vpn = TrsPoint(MyViewReferencePlane,Matrix) ; | |
812 | MyViewOrientation.SetViewReferencePlane(Vpn) ; | |
813 | Vup = TrsPoint(MyViewReferenceUp,Matrix) ; | |
814 | MyViewOrientation.SetViewReferenceUp(Vup) ; | |
815 | MyView->SetViewOrientation(MyViewOrientation) ; | |
816 | #ifdef IMP020300 | |
817 | SetZSize(0.) ; | |
818 | #endif | |
819 | ImmediateUpdate(); | |
7fd59977 | 820 | } |
821 | ||
822 | /*----------------------------------------------------------------------*/ | |
823 | ||
b8ddfc2f | 824 | void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) |
825 | { | |
7fd59977 | 826 | switch (Axe) { |
827 | case V3d_X : | |
828 | Rotate(angle,0.,0.,Start); | |
829 | break ; | |
830 | case V3d_Y : | |
831 | Rotate(0.,angle,0.,Start); | |
832 | break ; | |
833 | case V3d_Z : | |
834 | Rotate(0.,0.,angle,Start); | |
835 | break ; | |
836 | } | |
7fd59977 | 837 | } |
838 | ||
839 | /*----------------------------------------------------------------------*/ | |
840 | ||
841 | void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, | |
842 | const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start) | |
843 | { | |
7fd59977 | 844 | Standard_Real Angle = angle ; |
845 | Graphic3d_Vector Vpn,Vup ; | |
846 | Graphic3d_Vertex Vrp ; | |
847 | TColStd_Array2OfReal Matrix(0,3,0,3) ; | |
848 | ||
849 | if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; | |
850 | else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; | |
851 | ||
852 | if( Start ) { | |
853 | MyGravityReferencePoint.SetCoord(X,Y,Z) ; | |
854 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
855 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
856 | MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ; | |
857 | switch (Axe) { | |
858 | case V3d_X : | |
859 | MyViewAxis.SetCoord(1.,0.,0.) ; | |
860 | break ; | |
861 | case V3d_Y : | |
862 | MyViewAxis.SetCoord(0.,1.,0.) ; | |
863 | break ; | |
864 | case V3d_Z : | |
865 | MyViewAxis.SetCoord(0.,0.,1.) ; | |
866 | break ; | |
867 | } | |
868 | } | |
869 | ||
870 | RotAxis(MyGravityReferencePoint,MyViewAxis,Angle,Matrix) ; | |
871 | Vrp = TrsPoint(MyViewReferencePoint,Matrix) ; | |
872 | MyViewOrientation.SetViewReferencePoint(Vrp) ; | |
873 | Vpn = TrsPoint(MyViewReferencePlane,Matrix) ; | |
874 | MyViewOrientation.SetViewReferencePlane(Vpn) ; | |
875 | Vup = TrsPoint(MyViewReferenceUp,Matrix) ; | |
876 | MyViewOrientation.SetViewReferenceUp(Vup) ; | |
877 | MyView->SetViewOrientation(MyViewOrientation) ; | |
878 | #ifdef IMP020300 | |
879 | SetZSize(0.) ; | |
880 | #endif | |
881 | ImmediateUpdate(); | |
7fd59977 | 882 | } |
883 | ||
884 | /*----------------------------------------------------------------------*/ | |
885 | ||
b8ddfc2f | 886 | void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start) |
887 | { | |
7fd59977 | 888 | Standard_Real Angle = angle ; |
889 | Graphic3d_Vector Vpn,Vup ; | |
890 | TColStd_Array2OfReal Matrix(0,3,0,3) ; | |
891 | ||
892 | if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; | |
893 | else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; | |
894 | ||
895 | if( Start ) { | |
896 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
897 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
898 | MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ; | |
899 | } | |
900 | ||
901 | RotAxis(MyDefaultViewPoint,MyDefaultViewAxis,Angle,Matrix) ; | |
902 | #ifdef BUC60952 | |
903 | Graphic3d_Vertex Vrp ; | |
904 | Vrp = TrsPoint(MyViewReferencePoint,Matrix) ; | |
905 | MyViewOrientation.SetViewReferencePoint(Vrp) ; | |
906 | #endif | |
907 | Vpn = TrsPoint(MyViewReferencePlane,Matrix) ; | |
908 | MyViewOrientation.SetViewReferencePlane(Vpn) ; | |
909 | Vup = TrsPoint(MyViewReferenceUp,Matrix) ; | |
910 | MyViewOrientation.SetViewReferenceUp(Vup) ; | |
911 | MyView->SetViewOrientation(MyViewOrientation) ; | |
912 | #ifdef IMP020300 | |
913 | SetZSize(0.) ; | |
914 | #endif | |
915 | ImmediateUpdate(); | |
7fd59977 | 916 | } |
917 | ||
918 | /*----------------------------------------------------------------------*/ | |
919 | ||
920 | void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start) | |
921 | { | |
7fd59977 | 922 | Standard_Real Ax = ax ; |
923 | Standard_Real Ay = ay ; | |
924 | Standard_Real Az = az ; | |
925 | Graphic3d_Vertex Vrp,Eye ; | |
926 | Graphic3d_Vector Vpn,Vup ; | |
927 | Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ; | |
928 | TColStd_Array2OfReal Matrix(0,3,0,3) ; | |
929 | TColStd_Array2OfReal Rmatrix(0,3,0,3) ; | |
930 | ||
931 | if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ; | |
932 | else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ; | |
933 | if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ; | |
934 | else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ; | |
935 | if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ; | |
936 | else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ; | |
937 | ||
938 | if( Start ) { | |
939 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint(); | |
940 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
941 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
942 | MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ; | |
943 | if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
944 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis)) | |
6942f04a | 945 | V3d_BadValue::Raise ("V3d_View::Turn, alignment of Eye,At,Up"); |
7fd59977 | 946 | } |
947 | ||
948 | InitMatrix(Matrix) ; | |
949 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
950 | MyViewReferencePoint.Coord(Xat,Yat,Zat) ; | |
951 | MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ; | |
952 | Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ; | |
953 | Eye.SetCoord(Xeye,Yeye,Zeye) ; | |
954 | if( Ax != 0. ) RotAxis(Eye,MyYscreenAxis,-Ax,Matrix) ; | |
955 | if( Ay != 0. ) { | |
956 | RotAxis(Eye,MyXscreenAxis,Ay,Rmatrix) ; | |
957 | Multiply(Matrix, Rmatrix, Matrix); | |
958 | } | |
959 | if( Az != 0. ) { | |
960 | RotAxis(Eye,MyZscreenAxis,Az,Rmatrix) ; | |
961 | Multiply(Matrix, Rmatrix, Matrix); | |
962 | } | |
963 | Vrp = TrsPoint(MyViewReferencePoint,Matrix) ; | |
964 | MyViewOrientation.SetViewReferencePoint(Vrp) ; | |
965 | Vpn = TrsPoint(MyViewReferencePlane,Matrix) ; | |
966 | MyViewOrientation.SetViewReferenceUp(Vpn) ; | |
967 | Vup = TrsPoint(MyViewReferenceUp,Matrix) ; | |
968 | MyViewOrientation.SetViewReferenceUp(Vup) ; | |
969 | MyView->SetViewOrientation(MyViewOrientation) ; | |
970 | #ifdef IMP020300 | |
971 | SetZSize(0.) ; | |
972 | #else | |
973 | // Check ZClipping planes | |
974 | Standard_Real Zmax ; | |
975 | Vrp.Coord(Xat,Yat,Zat) ; | |
976 | Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat) ; | |
977 | if( Zmax > MyViewMapping.FrontPlaneDistance() && | |
978 | MyProjModel == V3d_TPM_SCREEN ) { | |
979 | SetZSize(2.*Zmax+Zmax*Zmargin) ; | |
980 | } | |
981 | #endif | |
982 | ImmediateUpdate(); | |
7fd59977 | 983 | } |
984 | ||
985 | /*----------------------------------------------------------------------*/ | |
986 | ||
987 | void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) | |
988 | { | |
7fd59977 | 989 | switch (Axe) { |
990 | case V3d_X : | |
991 | Turn(angle,0.,0.,Start); | |
992 | break ; | |
993 | case V3d_Y : | |
994 | Turn(0.,angle,0.,Start); | |
995 | break ; | |
996 | case V3d_Z : | |
997 | Turn(0.,0.,angle,Start); | |
998 | break ; | |
999 | } | |
1000 | } | |
1001 | ||
b8ddfc2f | 1002 | void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start) |
1003 | { | |
7fd59977 | 1004 | Standard_Real Angle = angle ; |
1005 | Graphic3d_Vertex Vrp,Eye ; | |
1006 | Graphic3d_Vector Vpn,Vup ; | |
1007 | Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ; | |
1008 | TColStd_Array2OfReal Matrix(0,3,0,3) ; | |
1009 | ||
1010 | if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; | |
1011 | else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; | |
1012 | ||
1013 | if( Start ) { | |
1014 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint(); | |
1015 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
1016 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
1017 | MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ; | |
1018 | } | |
1019 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
1020 | MyViewReferencePoint.Coord(Xat,Yat,Zat) ; | |
1021 | MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ; | |
1022 | Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ; | |
1023 | Eye.SetCoord(Xeye,Yeye,Zeye) ; | |
1024 | RotAxis(Eye,MyDefaultViewAxis,Angle,Matrix) ; | |
1025 | Vrp = TrsPoint(MyViewReferencePoint,Matrix) ; | |
1026 | MyViewOrientation.SetViewReferencePoint(Vrp) ; | |
1027 | Vpn = TrsPoint(MyViewReferencePlane,Matrix) ; | |
1028 | MyViewOrientation.SetViewReferencePlane(Vpn) ; | |
1029 | Vup = TrsPoint(MyViewReferenceUp,Matrix) ; | |
1030 | MyViewOrientation.SetViewReferenceUp(Vup) ; | |
1031 | MyView->SetViewOrientation(MyViewOrientation) ; | |
1032 | #ifdef IMP020300 | |
1033 | SetZSize(0.) ; | |
1034 | #else | |
1035 | // Check ZClipping planes | |
1036 | Standard_Real Zmax ; | |
1037 | Vrp.Coord(Xat,Yat,Zat) ; | |
1038 | Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat ) ; | |
1039 | if( Zmax > MyViewMapping.FrontPlaneDistance() && | |
1040 | MyProjModel == V3d_TPM_SCREEN ) { | |
1041 | SetZSize(2.*Zmax+Zmax*Zmargin) ; | |
1042 | } | |
1043 | #endif | |
1044 | ImmediateUpdate(); | |
7fd59977 | 1045 | } |
1046 | ||
b8ddfc2f | 1047 | void V3d_View::SetTwist(const Standard_Real angle) |
1048 | { | |
7fd59977 | 1049 | Standard_Real Angle = angle ; |
1050 | TColStd_Array2OfReal Matrix(0,3,0,3) ; | |
1051 | Standard_Boolean TheStatus ; | |
1052 | ||
1053 | if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; | |
1054 | else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; | |
1055 | ||
1056 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
1057 | MyViewReferenceUp.SetCoord(0.,0.,1.) ; | |
1058 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1059 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1060 | if( !TheStatus ) { | |
1061 | MyViewReferenceUp.SetCoord(0.,1.,0.) ; | |
1062 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1063 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1064 | } | |
1065 | if( !TheStatus ) { | |
1066 | MyViewReferenceUp.SetCoord(1.,0.,0.) ; | |
1067 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1068 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1069 | } | |
1070 | ||
6942f04a | 1071 | V3d_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,"); |
7fd59977 | 1072 | |
1073 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
1074 | RotAxis(MyViewReferencePoint,MyZscreenAxis,Angle,Matrix) ; | |
1075 | MyViewReferenceUp = TrsPoint(MyYscreenAxis,Matrix) ; | |
1076 | MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ; | |
1077 | MyView->SetViewOrientation(MyViewOrientation) ; | |
1078 | ImmediateUpdate(); | |
7fd59977 | 1079 | } |
1080 | ||
1081 | #ifdef IMP240100 | |
1082 | void V3d_View::SetProjModel( const V3d_TypeOfProjectionModel aModel ) | |
1083 | { | |
7fd59977 | 1084 | MyProjModel = aModel; |
7fd59977 | 1085 | } |
1086 | ||
b8ddfc2f | 1087 | V3d_TypeOfProjectionModel V3d_View::ProjModel() const |
1088 | { | |
7fd59977 | 1089 | return MyProjModel; |
7fd59977 | 1090 | } |
1091 | #endif | |
1092 | ||
b8ddfc2f | 1093 | void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) |
1094 | { | |
7fd59977 | 1095 | Standard_Real Angle,Xat,Yat,Zat,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn ; |
1096 | Angle = Twist() ; | |
1097 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ; | |
1098 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
1099 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
1100 | MyViewReferencePoint.Coord(Xat,Yat,Zat) ; | |
1101 | MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ; | |
1102 | Xpn = X - Xat ; Ypn = Y - Yat ; Zpn = Z - Zat ; | |
1103 | Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ; | |
6942f04a | 1104 | V3d_BadValue_Raise_if( Zrp <= 0. , "V3d_View::SetEye:: Eye,At are Confused"); |
7fd59977 | 1105 | |
1106 | Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ; | |
1107 | MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ; | |
1108 | MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ; | |
1109 | MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ; | |
1110 | MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint); | |
1111 | ||
1112 | Standard_Boolean update = myImmediateUpdate; | |
1113 | myImmediateUpdate = Standard_False; | |
1114 | if( MyProjModel == V3d_TPM_WALKTHROUGH ) { | |
1115 | //FMN desactivation temp SetTwist(Angle) ; | |
1116 | // Set infos. | |
1117 | MyView->SetViewOrientation(MyViewOrientation) ; | |
1118 | MyView->SetViewMapping(MyViewMapping) ; | |
1119 | } else { | |
1120 | SetTwist(Angle) ; | |
1121 | } | |
1122 | #ifdef IMP020300 | |
1123 | SetZSize(0.) ; | |
1124 | #else | |
1125 | // Check ZClipping planes | |
1126 | Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ; | |
1127 | if( Zmax > MyViewMapping.FrontPlaneDistance() && | |
1128 | MyProjModel == V3d_TPM_SCREEN ) { | |
1129 | SetZSize(2.*Zmax+Zmax*Zmargin) ; | |
1130 | } else { | |
1131 | if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ; | |
1132 | MyView->SetViewMapping(MyViewMapping); | |
1133 | } | |
1134 | #endif | |
1135 | myImmediateUpdate = update; | |
1136 | ImmediateUpdate(); | |
7fd59977 | 1137 | } |
1138 | ||
b8ddfc2f | 1139 | void V3d_View::SetDepth(const Standard_Real Depth) |
1140 | { | |
7fd59977 | 1141 | Standard_Real Xrp,Yrp,Zrp ; |
1142 | #ifdef IMP250200 | |
6942f04a | 1143 | V3d_BadValue_Raise_if( Depth == 0. ,"V3d_View::SetDepth, bad depth"); |
7fd59977 | 1144 | #else |
6942f04a | 1145 | V3d_BadValue_Raise_if( Depth <= 0. ,"V3d_View::SetDepth, bad depth"); |
7fd59977 | 1146 | #endif |
1147 | ||
7fd59977 | 1148 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; |
1149 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
1150 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ; | |
1151 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
1152 | #ifdef IMP250200 | |
1153 | if( Depth > 0. ) | |
1154 | #endif | |
1155 | { | |
1156 | Zrp = Depth; | |
1157 | MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ; | |
1158 | MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint); | |
1159 | } | |
1160 | ||
1161 | // Check ZClipping planes | |
1162 | Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ; | |
1163 | MyViewReferencePoint.Coord(Xat,Yat,Zat) ; | |
1164 | MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ; | |
1165 | #ifdef IMP250200 | |
1166 | if( Depth < 0. ) { // Move the view ref point instead of the eye. | |
1167 | Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ; | |
1168 | Zrp = Abs(Depth) ; | |
1169 | Xat = Xeye - Xpn*Zrp ; Yat = Yeye - Ypn*Zrp ; Zat = Zeye - Zpn*Zrp; | |
1170 | MyViewReferencePoint.SetCoord(Xat,Yat,Zat) ; | |
1171 | MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ; | |
1172 | MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ; | |
1173 | MyView->SetViewOrientation(MyViewOrientation); | |
1174 | } | |
1175 | #endif | |
1176 | #ifdef IMP020300 | |
1177 | MyView->SetViewMapping(MyViewMapping) ; | |
1178 | SetZSize(0.) ; | |
1179 | #else | |
1180 | Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ; | |
1181 | Standard_Real Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ); | |
1182 | ||
1183 | if( Zmax > MyViewMapping.FrontPlaneDistance() && | |
1184 | MyProjModel == V3d_TPM_SCREEN ) { | |
1185 | SetZSize(2.*Zmax+Zmax*Zmargin) ; | |
1186 | } else { | |
1187 | if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ; | |
1188 | #ifdef IMP250200 | |
1189 | if( Depth > 0. ) | |
1190 | #endif | |
1191 | MyView->SetViewMapping(MyViewMapping) ; | |
1192 | } | |
1193 | #endif | |
1194 | ||
1195 | ImmediateUpdate(); | |
7fd59977 | 1196 | } |
1197 | ||
1198 | ||
1199 | void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz ) | |
1200 | { | |
7fd59977 | 1201 | Standard_Real Angle ; |
1202 | ||
6942f04a | 1203 | V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0., |
7fd59977 | 1204 | "V3d_View::SetProj, null projection vector"); |
1205 | ||
1206 | Angle = Twist() ; | |
1207 | MyViewReferencePlane.SetCoord(Vx,Vy,Vz) ; | |
1208 | MyViewReferencePlane.Normalize() ; | |
1209 | MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ; | |
1210 | Standard_Boolean update = myImmediateUpdate; | |
1211 | myImmediateUpdate = Standard_False; | |
1212 | if( MyProjModel == V3d_TPM_SCREEN ) SetTwist(Angle) ; | |
1213 | #ifdef IMP020300 | |
1214 | SetZSize(0.) ; | |
1215 | #endif | |
1216 | myImmediateUpdate = update; | |
1217 | ImmediateUpdate(); | |
7fd59977 | 1218 | } |
1219 | ||
b8ddfc2f | 1220 | void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation ) |
1221 | { | |
7fd59977 | 1222 | MyViewReferencePlane = V3d::GetProjAxis(Orientation) ; |
1223 | MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ; | |
1224 | // MSV 14.03.2007: reset ViewReferencePoint to debug LH3D14955 | |
b8ddfc2f | 1225 | MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex (0.0f, 0.0f, 0.0f)); |
7fd59977 | 1226 | Standard_Real Xpn=0; |
1227 | Standard_Real Ypn=0; | |
1228 | Standard_Real Zpn=0; | |
1229 | ||
1230 | switch (Orientation) { | |
1231 | case V3d_Zpos : | |
1232 | Ypn = 1. ; | |
1233 | break ; | |
1234 | case V3d_Zneg : | |
1235 | Ypn = -1. ; | |
1236 | break ; | |
1237 | default: | |
1238 | Zpn = 1.; | |
1239 | } | |
1240 | SetUp(Xpn,Ypn,Zpn); | |
1241 | #ifdef IMP020300 | |
1242 | SetZSize(0.) ; | |
1243 | #endif | |
1244 | ImmediateUpdate(); | |
7fd59977 | 1245 | } |
1246 | ||
b8ddfc2f | 1247 | void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) |
1248 | { | |
7fd59977 | 1249 | Standard_Real Angle,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ; |
1250 | Standard_Real Xeye,Yeye,Zeye ; | |
1251 | ||
1252 | Angle = Twist() ; | |
1253 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ; | |
1254 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
1255 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
1256 | MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ; | |
1257 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
1258 | MyViewReferencePoint.Coord(Xat,Yat,Zat) ; | |
1259 | Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ; | |
1260 | Xpn = Xeye - X ; Ypn = Yeye - Y ; Zpn = Zeye - Z ; | |
1261 | Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ; | |
6942f04a | 1262 | V3d_BadValue_Raise_if( Zrp <= 0., |
7fd59977 | 1263 | "V3d_View::SetAt, Eye,At are Confused"); |
1264 | ||
1265 | Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ; | |
1266 | MyViewReferencePoint.SetCoord(X,Y,Z) ; | |
1267 | MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ; | |
1268 | MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ; | |
1269 | MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ; | |
1270 | MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ; | |
1271 | MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint); | |
1272 | Standard_Boolean update = myImmediateUpdate; | |
1273 | myImmediateUpdate = Standard_False; | |
1274 | if( MyProjModel == V3d_TPM_WALKTHROUGH ) { | |
1275 | //FMN desactivation temp SetTwist(Angle) ; | |
1276 | // Set infos. | |
1277 | MyView->SetViewOrientation(MyViewOrientation) ; | |
1278 | MyView->SetViewMapping(MyViewMapping) ; | |
1279 | } else { | |
1280 | SetTwist(Angle) ; | |
1281 | } | |
1282 | #ifdef IMP020300 | |
1283 | MyView->SetViewMapping(MyViewMapping); | |
1284 | SetZSize(0.) ; | |
1285 | #else | |
1286 | ImmediateUpdate(); | |
1287 | // Check ZClipping planes | |
1288 | Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ; | |
1289 | if( Zmax > MyViewMapping.FrontPlaneDistance() && | |
1290 | MyProjModel == V3d_TPM_SCREEN ) { | |
1291 | SetZSize(2.*Zmax+Zmax*Zmargin) ; | |
1292 | } else { | |
1293 | if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ; | |
1294 | MyView->SetViewMapping(MyViewMapping); | |
1295 | } | |
1296 | #endif | |
1297 | myImmediateUpdate = update; | |
1298 | ImmediateUpdate(); | |
7fd59977 | 1299 | } |
1300 | ||
b8ddfc2f | 1301 | void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz) |
1302 | { | |
7fd59977 | 1303 | Standard_Boolean TheStatus ; |
6942f04a | 1304 | V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. , |
7fd59977 | 1305 | "V3d_View::SetUp, nullUp vector"); |
1306 | ||
1307 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
1308 | MyViewReferenceUp.SetCoord(Vx,Vy,Vz) ; | |
1309 | MyViewReferenceUp.Normalize() ; | |
1310 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1311 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1312 | if( !TheStatus ) { | |
1313 | MyViewReferenceUp.SetCoord(0.,0.,1.) ; | |
1314 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1315 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1316 | } | |
1317 | if( !TheStatus ) { | |
1318 | MyViewReferenceUp.SetCoord(0.,1.,0.) ; | |
1319 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1320 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1321 | } | |
1322 | if( !TheStatus ) { | |
1323 | MyViewReferenceUp.SetCoord(1.,0.,0.) ; | |
1324 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1325 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1326 | } | |
6942f04a | 1327 | V3d_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up"); |
7fd59977 | 1328 | |
1329 | MyViewReferenceUp = MyYscreenAxis ; | |
1330 | MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ; | |
1331 | MyView->SetViewOrientation(MyViewOrientation) ; | |
1332 | ImmediateUpdate(); | |
7fd59977 | 1333 | } |
1334 | ||
b8ddfc2f | 1335 | void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) |
1336 | { | |
7fd59977 | 1337 | Standard_Boolean TheStatus ; |
1338 | ||
1339 | MyViewReferenceUp = V3d::GetProjAxis(Orientation) ; | |
1340 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; | |
1341 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1342 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1343 | if( !TheStatus ) { | |
1344 | MyViewReferenceUp.SetCoord(0.,0.,1.) ; | |
1345 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1346 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1347 | } | |
1348 | if( !TheStatus ) { | |
1349 | MyViewReferenceUp.SetCoord(0.,1.,0.) ; | |
1350 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1351 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1352 | } | |
1353 | if( !TheStatus ) { | |
1354 | MyViewReferenceUp.SetCoord(1.,0.,0.) ; | |
1355 | TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp, | |
1356 | MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ; | |
1357 | } | |
6942f04a | 1358 | V3d_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up"); |
7fd59977 | 1359 | |
1360 | MyViewReferenceUp = MyYscreenAxis ; | |
1361 | MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ; | |
1362 | MyView->SetViewOrientation(MyViewOrientation) ; | |
1363 | ImmediateUpdate(); | |
7fd59977 | 1364 | } |
1365 | ||
1366 | void V3d_View::SetViewOrientation(const Visual3d_ViewOrientation& VO) | |
1367 | { | |
1368 | MyViewOrientation = VO; | |
1369 | MyView->SetViewOrientation(MyViewOrientation) ; | |
1370 | ImmediateUpdate(); | |
1371 | } | |
1372 | ||
b8ddfc2f | 1373 | void V3d_View::SetViewOrientationDefault() |
1374 | { | |
7fd59977 | 1375 | MyView->SetViewOrientation(MyViewOrientation) ; |
1376 | MyView->SetViewOrientationDefault() ; | |
1377 | ImmediateUpdate(); | |
1378 | } | |
1379 | ||
b8ddfc2f | 1380 | void V3d_View::ResetViewOrientation() |
1381 | { | |
7fd59977 | 1382 | MyView->ViewOrientationReset() ; |
1383 | MyViewOrientation = MyView->ViewOrientation() ; | |
1384 | ImmediateUpdate(); | |
1385 | } | |
1386 | ||
b8ddfc2f | 1387 | void V3d_View::Reset( const Standard_Boolean update ) |
1388 | { | |
7fd59977 | 1389 | MyView->ViewOrientationReset() ; |
1390 | MyViewOrientation = MyView->ViewOrientation() ; | |
1391 | MyView->ViewMappingReset(); | |
1392 | MyViewMapping = MyView->ViewMapping() ; | |
1393 | ||
1394 | ZFitAll (Zmargin); | |
1395 | SwitchSetFront = Standard_False; | |
1396 | #ifdef IMP020300 | |
1397 | if( !myImmediateUpdate && update ) Update(); | |
1398 | #else | |
1399 | ImmediateUpdate(); | |
1400 | #endif | |
7fd59977 | 1401 | } |
1402 | ||
1403 | void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start) | |
1404 | { | |
7fd59977 | 1405 | Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp,Dxv,Dyv ; |
6942f04a | 1406 | V3d_BadValue_Raise_if( aZoomFactor <= 0.,"V3d_View::Panning, bad zoom factor"); |
7fd59977 | 1407 | |
1408 | if( Start ) { | |
1409 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ; | |
1410 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1411 | MyXwindowCenter = (Umin + Umax)/2. ; | |
1412 | MyYwindowCenter = (Vmin + Vmax)/2. ; | |
1413 | MyWindowWidth = Abs(Umax - Umin) ; | |
1414 | MyWindowHeight = Abs(Vmax - Vmin) ; | |
6942f04a | 1415 | V3d_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. , |
7fd59977 | 1416 | "V3d_View::Panning, Window Size is NULL"); |
1417 | } | |
1418 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
1419 | Xrp = MyXwindowCenter - Dx ; | |
1420 | Yrp = MyYwindowCenter - Dy ; | |
1421 | Dxv = MyWindowWidth/aZoomFactor ; Dyv = MyWindowHeight/aZoomFactor ; | |
1422 | Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ; | |
1423 | Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ; | |
1424 | MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1425 | if( MyType != V3d_PERSPECTIVE ) { | |
1426 | MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ; | |
1427 | MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ; | |
1428 | } | |
1429 | MyView->SetViewMapping(MyViewMapping) ; | |
1430 | ImmediateUpdate(); | |
7fd59977 | 1431 | } |
b8ddfc2f | 1432 | |
1433 | void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y) | |
1434 | { | |
7fd59977 | 1435 | Standard_Real x,y; |
1436 | Convert(X,Y,x,y); | |
1437 | SetCenter(x,y); | |
1438 | } | |
1439 | ||
b8ddfc2f | 1440 | void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc) |
1441 | { | |
7fd59977 | 1442 | Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp ; |
1443 | ||
1444 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ; | |
1445 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
1446 | MyXwindowCenter = Xrp = Xc ; MyYwindowCenter = Yrp = Yc ; | |
1447 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1448 | MyWindowWidth = Abs(Umax - Umin) ; MyWindowHeight = Abs(Vmax - Vmin) ; | |
6942f04a | 1449 | V3d_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. , |
7fd59977 | 1450 | "V3d_View::SetCenter, Window Size is NULL"); |
1451 | ||
1452 | Umin = Xc - MyWindowWidth/2. ; Vmin = Yc - MyWindowHeight/2. ; | |
1453 | Umax = Xc + MyWindowWidth/2. ; Vmax = Yc + MyWindowHeight/2. ; | |
1454 | MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1455 | if( MyType != V3d_PERSPECTIVE ) { | |
1456 | MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ; | |
1457 | MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ; | |
1458 | } | |
1459 | MyView->SetViewMapping(MyViewMapping) ; | |
1460 | ImmediateUpdate(); | |
7fd59977 | 1461 | } |
1462 | ||
1463 | void V3d_View::SetSize(const Standard_Real Size) | |
1464 | { | |
7fd59977 | 1465 | Standard_Real Umin,Vmin,Umax,Vmax,Rap ; |
1466 | ||
6942f04a | 1467 | V3d_BadValue_Raise_if( Size <= 0., |
7fd59977 | 1468 | "V3d_View::SetSize, Window Size is NULL"); |
1469 | ||
1470 | ||
1471 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1472 | MyWindowWidth = Abs(Umax - Umin) ; | |
1473 | MyWindowHeight = Abs(Vmax - Vmin) ; | |
1474 | MyXwindowCenter = (Umin + Umax)/2. ; | |
1475 | MyYwindowCenter = (Vmin + Vmax)/2. ; | |
1476 | Rap = MyWindowWidth/MyWindowHeight ; | |
1477 | if( MyWindowWidth >= MyWindowHeight ) { | |
1478 | MyWindowWidth = Size ; MyWindowHeight = Size/Rap ; | |
1479 | } else { | |
1480 | MyWindowHeight = Size ; MyWindowWidth = Size*Rap ; | |
1481 | } | |
1482 | Umin = MyXwindowCenter - MyWindowWidth/2. ; | |
1483 | Vmin = MyYwindowCenter - MyWindowHeight/2. ; | |
1484 | Umax = MyXwindowCenter + MyWindowWidth/2. ; | |
1485 | Vmax = MyYwindowCenter + MyWindowHeight/2. ; | |
1486 | MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1487 | MyView->SetViewMapping(MyViewMapping) ; | |
1488 | ImmediateUpdate(); | |
7fd59977 | 1489 | } |
1490 | ||
1491 | void V3d_View::SetZSize(const Standard_Real Size) | |
1492 | { | |
7fd59977 | 1493 | Standard_Real Zmax = Size/2.; |
1494 | ||
1495 | #ifdef IMP020300 | |
1496 | if( Size <= 0. ) { | |
1497 | Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye; | |
1498 | MyViewReferencePoint.Coord(Xat,Yat,Zat) ; | |
1499 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
1500 | MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ; | |
1501 | Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat; | |
1502 | Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ); | |
1503 | if( Zmax <= MyViewMapping.FrontPlaneDistance() ) return; | |
1504 | } | |
1505 | #else | |
6942f04a | 1506 | V3d_BadValue_Raise_if( Size <= 0., |
7fd59977 | 1507 | "V3d_View::SetZSize, Window ZSize is NULL"); |
1508 | #endif | |
1509 | ||
1510 | Standard_Real Front = MyViewContext.ZClippingFrontPlane() ; | |
1511 | Standard_Real Back = MyViewContext.ZClippingBackPlane() ; | |
7fd59977 | 1512 | |
1513 | MyViewMapping.SetFrontPlaneDistance(Zmax) ; | |
1514 | MyViewMapping.SetBackPlaneDistance(-Zmax) ; | |
1515 | ||
1516 | // OCC18942 | |
1517 | if( MyProjModel != V3d_TPM_WALKTHROUGH ) { | |
1518 | MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : Zmax) ; | |
1519 | } | |
1520 | ||
1521 | MyView->SetViewMapping(MyViewMapping) ; | |
1522 | if( MyViewContext.FrontZClippingIsOn() || | |
b8ddfc2f | 1523 | MyViewContext.BackZClippingIsOn() ) |
1524 | { | |
1525 | MyViewContext.SetZClippingFrontPlane(Front) ; | |
1526 | MyViewContext.SetZClippingBackPlane(Back) ; | |
1527 | MyView->SetContext(MyViewContext) ; | |
1528 | } | |
7fd59977 | 1529 | } |
1530 | ||
1531 | void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start) | |
1532 | { | |
7fd59977 | 1533 | Standard_Real Umin,Vmin,Umax,Vmax,Dxv,Dyv ; |
6942f04a | 1534 | V3d_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient"); |
7fd59977 | 1535 | |
1536 | if( Start ) { | |
1537 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1538 | MyXwindowCenter = (Umin + Umax)/2. ; | |
1539 | MyYwindowCenter = (Vmin + Vmax)/2. ; | |
1540 | MyWindowWidth = Abs(Umax - Umin) ; | |
1541 | MyWindowHeight = Abs(Vmax - Vmin) ; | |
1542 | } | |
1543 | ||
1544 | // ensure that zoom will not be too small or too big | |
1545 | Standard_Real coef = Coef; | |
1546 | if ( MyWindowWidth < coef * Precision::Confusion() ) | |
1547 | coef = MyWindowWidth / Precision::Confusion(); | |
1548 | else if ( MyWindowWidth > coef * 1e12 ) | |
1549 | coef = MyWindowWidth / 1e12; | |
1550 | if ( MyWindowHeight < coef * Precision::Confusion() ) | |
1551 | coef = MyWindowHeight / Precision::Confusion(); | |
1552 | else if ( MyWindowHeight > coef * 1e12 ) | |
1553 | coef = MyWindowHeight / 1e12; | |
1554 | ||
1555 | Dxv = MyWindowWidth/coef; | |
1556 | Dyv = MyWindowHeight/coef; | |
1557 | Umin = MyXwindowCenter - Dxv/2. ; Umax = MyXwindowCenter + Dxv/2. ; | |
1558 | Vmin = MyYwindowCenter - Dyv/2. ; Vmax = MyYwindowCenter + Dyv/2. ; | |
1559 | MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1560 | MyView->SetViewMapping(MyViewMapping) ; | |
1561 | ImmediateUpdate(); | |
1562 | } | |
1563 | ||
b8ddfc2f | 1564 | void V3d_View::SetScale( const Standard_Real Coef ) |
1565 | { | |
7fd59977 | 1566 | Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Dxv,Dyv ; |
1567 | Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ; | |
1568 | ||
6942f04a | 1569 | V3d_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient"); |
7fd59977 | 1570 | |
1571 | VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1572 | Dxv = Abs(Umax - Umin) ; Dyv = Abs(Vmax - Vmin) ; | |
1573 | Dxv /= Coef ; Dyv /= Coef ; | |
1574 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1575 | Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ; | |
1576 | Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ; | |
1577 | Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ; | |
1578 | MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ; | |
1579 | MyView->SetViewMapping(MyViewMapping) ; | |
1580 | ImmediateUpdate(); | |
7fd59977 | 1581 | } |
1582 | ||
b8ddfc2f | 1583 | void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz ) |
1584 | { | |
7fd59977 | 1585 | Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ; |
1586 | Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ; | |
6942f04a | 1587 | V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient"); |
7fd59977 | 1588 | |
1589 | MyViewOrientation.SetAxialScale( Sx, Sy, Sz ); | |
1590 | Aspect_TypeOfUpdate updateMode = MyView->ViewManager()->UpdateMode(); | |
1591 | MyView->ViewManager()->SetUpdateMode(Aspect_TOU_ASAP); | |
1592 | MyView->SetViewOrientation(MyViewOrientation); | |
1593 | MyView->ViewManager()->SetUpdateMode(updateMode); | |
1594 | ||
1595 | MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ; | |
1596 | ||
1597 | Standard_Real LIM = ShortRealLast() -1.; | |
1598 | if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM | |
1599 | || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) { | |
1600 | return; | |
1601 | } | |
1602 | ||
1603 | MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ; | |
1604 | MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ; | |
1605 | Umax = Max(Umin,Umax) ; Vmax = Max(Vmin,Vmax) ; | |
1606 | MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; | |
1607 | Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ; | |
1608 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1609 | MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ; | |
1610 | Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ; | |
1611 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1612 | MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ; | |
1613 | Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ; | |
1614 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1615 | MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ; | |
1616 | Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ; | |
1617 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1618 | MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ; | |
1619 | Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ; | |
1620 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1621 | MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ; | |
1622 | Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ; | |
1623 | Umax = Max(Umax,Vmax) ; | |
1624 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1625 | Wmax = Max(Abs(Wmin),Abs(Wmax)) ; | |
1626 | Wmax = Max(Abs(Umax),Abs(Wmax)) ; | |
1627 | ||
1628 | if( Wmax > 0. ) { | |
1629 | SetZSize(2.*Wmax + Wmax) ; | |
1630 | } | |
7fd59977 | 1631 | } |
1632 | ||
1633 | void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean FitZ, | |
1634 | const Standard_Boolean update) | |
1635 | { | |
35617823 K |
1636 | Standard_Real Umin, Umax, Vmin, Vmax, Xrp, Yrp, Zrp, U, V, W, U1, V1, W1; |
1637 | Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax; | |
1638 | Standard_Real DxvOld, DyvOld, DxvNew, DyvNew; | |
1639 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures(); | |
7fd59977 | 1640 | |
35617823 K |
1641 | if ((Nstruct <= 0) || (Coef < 0.0) || (Coef > 1.0)) |
1642 | { | |
7fd59977 | 1643 | #ifndef IMP020300 |
1644 | ImmediateUpdate(); | |
1645 | #endif | |
35617823 | 1646 | return; |
7fd59977 | 1647 | } |
7fd59977 | 1648 | |
35617823 K |
1649 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint(); |
1650 | MyProjReferencePoint.Coord (Xrp, Yrp, Zrp); | |
1651 | if (MyView->IsDefined()) | |
1652 | { | |
1653 | Standard_Integer Xpixel, Ypixel; | |
1654 | MyWindow->Size (Xpixel, Ypixel); | |
1655 | DxvOld = Xpixel; | |
1656 | DyvOld = Ypixel; | |
7fd59977 | 1657 | } |
35617823 K |
1658 | else |
1659 | { | |
1660 | MyViewMapping.WindowLimit (Umin, Vmin, Umax, Vmax); | |
1661 | DxvOld = Abs (Umax - Umin); | |
1662 | DyvOld = Abs (Vmax - Vmin); | |
7fd59977 | 1663 | } |
35617823 K |
1664 | if ((DxvOld == 0.0) || (DyvOld == 0.0)) |
1665 | { | |
1666 | return; | |
7fd59977 | 1667 | } |
1668 | ||
35617823 K |
1669 | Standard_Real aWinRatio = DxvOld / DyvOld; |
1670 | ||
1671 | // retrieve min / max values for current displayed objects | |
1672 | MyView->MinMaxValues (Xmin, Ymin, Zmin, | |
1673 | Xmax, Ymax, Zmax); | |
1674 | ||
1675 | Standard_Real LIM = ShortRealLast() - 1.0; | |
1676 | if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM | |
1677 | || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM) | |
1678 | { | |
7fd59977 | 1679 | #ifndef IMP020300 |
35617823 | 1680 | ImmediateUpdate(); |
7fd59977 | 1681 | #endif |
35617823 K |
1682 | return; |
1683 | } | |
7fd59977 | 1684 | |
35617823 K |
1685 | // eliminate fluctuations between sequential FitAll() calls |
1686 | MyViewMapping.SetWindowLimit (-1.0 * aWinRatio, -1.0, 1.0 * aWinRatio, 1.0); | |
1687 | if (MyType != V3d_PERSPECTIVE) | |
1688 | { | |
1689 | MyProjReferencePoint.SetCoord (0.0, 0.0, Zrp); | |
1690 | MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint); | |
1691 | } | |
1692 | MyView->SetViewMapping (MyViewMapping); | |
1693 | ||
1694 | // iterate 2 times to find optimal view plane size | |
1695 | // (use view plane values computed on previous iteration) | |
1696 | for (Standard_Integer aIteration = 2; aIteration > 0; --aIteration) | |
1697 | { | |
1698 | MyView->Projects (Xmin, Ymin, Zmin, U, V, W); | |
1699 | MyView->Projects (Xmax, Ymax, Zmax, U1, V1, W1); | |
1700 | Umin = Min (U, U1); Umax = Max (U, U1); | |
1701 | Vmin = Min (V, V1); Vmax = Max (V, V1); | |
1702 | ||
1703 | MyView->Projects (Xmin, Ymin, Zmax, U, V, W); | |
1704 | Umin = Min (U, Umin); Umax = Max (U, Umax); | |
1705 | Vmin = Min (V, Vmin); Vmax = Max (V, Vmax); | |
1706 | ||
1707 | MyView->Projects (Xmax, Ymin, Zmax, U, V, W); | |
1708 | Umin = Min (U, Umin); Umax = Max (U, Umax); | |
1709 | Vmin = Min (V, Vmin); Vmax = Max (V, Vmax); | |
1710 | ||
1711 | MyView->Projects (Xmax, Ymin, Zmin, U, V, W); | |
1712 | Umin = Min (U, Umin); Umax = Max (U, Umax); | |
1713 | Vmin = Min (V, Vmin); Vmax = Max (V, Vmax); | |
1714 | ||
1715 | MyView->Projects (Xmax, Ymax, Zmin, U, V, W); | |
1716 | Umin = Min (U, Umin); Umax = Max (U, Umax); | |
1717 | Vmin = Min (V, Vmin); Vmax = Max (V, Vmax); | |
7fd59977 | 1718 | |
35617823 K |
1719 | MyView->Projects (Xmin, Ymax, Zmax, U, V, W); |
1720 | Umin = Min (U, Umin); Umax = Max (U, Umax); | |
1721 | Vmin = Min (V, Vmin); Vmax = Max (V, Vmax); | |
7fd59977 | 1722 | |
35617823 K |
1723 | MyView->Projects (Xmin, Ymax, Zmin, U, V, W); |
1724 | Umin = Min (U, Umin); Umax = Max (U, Umax); | |
1725 | Vmin = Min (V, Vmin); Vmax = Max (V, Vmax); | |
1726 | ||
1727 | DxvNew = Abs (Umax - Umin); | |
1728 | DyvNew = Abs (Vmax - Vmin); | |
1729 | ||
1730 | if (DyvNew < 10.0 * Precision::Confusion()) | |
1731 | { | |
1732 | if (DxvNew < 10.0 * Precision::Confusion()) | |
1733 | { | |
1734 | // whole scene projected to point | |
1735 | DxvNew = Max (Abs (Zmax - Zmin), (Max (Abs (Xmax - Xmin), Abs (Ymax - Ymin)))); | |
1736 | if (DxvNew < 10.0 * Precision::Confusion()) | |
1737 | { | |
1738 | // this is really just one (!) point and zooming has no any effect | |
1739 | // just center the view | |
1740 | DyvNew = DyvOld; | |
1741 | DxvNew = DxvOld; | |
7fd59977 | 1742 | } |
35617823 K |
1743 | else |
1744 | { | |
1745 | // we look along some line | |
1746 | // fit view like that to see whole scene on rotation | |
1747 | DxvNew += Coef * DxvNew; | |
1748 | DyvNew = DxvNew / aWinRatio; | |
1749 | } | |
1750 | } | |
1751 | else | |
1752 | { | |
1753 | // whole scene projected to horizontal line | |
1754 | DxvNew += Coef * DxvNew; | |
1755 | DyvNew = DxvNew / aWinRatio; | |
7fd59977 | 1756 | } |
35617823 K |
1757 | } |
1758 | else | |
1759 | { | |
1760 | // general case (or DxvNew == 0.0 - vertical line) | |
1761 | // safe original ratio | |
1762 | Standard_Real aFitRatio = DxvNew / DyvNew; | |
1763 | if (aFitRatio >= aWinRatio) | |
1764 | { | |
1765 | DxvNew += Coef * DxvNew; | |
1766 | DyvNew = DxvNew / aWinRatio; | |
1767 | } | |
1768 | else | |
1769 | { | |
1770 | DyvNew += Coef * DyvNew; | |
1771 | DxvNew = DyvNew * aWinRatio; | |
1772 | } | |
1773 | } | |
7fd59977 | 1774 | |
35617823 K |
1775 | // new scene center |
1776 | Xrp = 0.5 * (Umin + Umax); | |
1777 | Yrp = 0.5 * (Vmin + Vmax); | |
7fd59977 | 1778 | |
35617823 K |
1779 | // new window limits |
1780 | Umin = Xrp - 0.5 * DxvNew; | |
1781 | Umax = Xrp + 0.5 * DxvNew; | |
1782 | Vmin = Yrp - 0.5 * DyvNew; | |
1783 | Vmax = Yrp + 0.5 * DyvNew; | |
1784 | MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax); | |
1785 | ||
1786 | if (MyType != V3d_PERSPECTIVE) | |
1787 | { | |
1788 | // center the view | |
1789 | MyProjReferencePoint.SetCoord (Xrp, Yrp, Zrp); | |
1790 | MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint); | |
1791 | } | |
1792 | MyView->SetViewMapping (MyViewMapping); | |
1793 | } | |
1794 | ||
1795 | if (FitZ) | |
1796 | { | |
1797 | ZFitAll (Zmargin); | |
7fd59977 | 1798 | #ifdef IMP020300 |
35617823 K |
1799 | } |
1800 | else | |
1801 | { | |
1802 | ImmediateUpdate(); | |
7fd59977 | 1803 | #endif |
35617823 | 1804 | } |
7fd59977 | 1805 | #ifdef IMP020300 |
35617823 K |
1806 | if (!myImmediateUpdate && update) |
1807 | { | |
1808 | Update(); | |
1809 | } | |
7fd59977 | 1810 | #endif |
1811 | } | |
1812 | ||
b8ddfc2f | 1813 | void V3d_View::ZFitAll(const Standard_Real Coef) |
1814 | { | |
7fd59977 | 1815 | Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ; |
1816 | Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ; | |
1817 | // CAL 6/11/98 | |
1818 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; | |
1819 | ||
1820 | if( MyType == V3d_PERSPECTIVE ) { | |
1821 | ImmediateUpdate(); | |
1822 | return ; | |
1823 | } | |
1824 | ||
1825 | if( (Nstruct <= 0) || (Coef < 0.) ) { | |
1826 | ImmediateUpdate(); | |
1827 | return ; | |
1828 | } | |
1829 | ||
1830 | MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ; | |
1831 | ||
1832 | Standard_Real LIM = ShortRealLast() -1.; | |
1833 | if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM | |
1834 | || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) { | |
1835 | ImmediateUpdate(); | |
1836 | return ; | |
1837 | } | |
1838 | ||
7fd59977 | 1839 | // CAL 6/11/98 |
1840 | // Case when view contains only a point | |
1841 | if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) { | |
1842 | ImmediateUpdate(); | |
1843 | return ; | |
1844 | } | |
1845 | MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ; | |
1846 | MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ; | |
1847 | MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; | |
1848 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1849 | MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ; | |
1850 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1851 | MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ; | |
1852 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1853 | MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ; | |
1854 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1855 | MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ; | |
1856 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1857 | MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ; | |
1858 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1859 | Wmax = Max(Abs(Wmin),Abs(Wmax)) ; | |
1860 | if( Wmax > 0. ) { | |
1861 | SetZSize(2.*Wmax + Coef * Wmax) ; | |
1862 | } | |
1863 | ImmediateUpdate(); | |
1864 | } | |
1865 | ||
1866 | void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect, | |
1867 | const Quantity_Coefficient Margin) | |
1868 | { | |
1869 | Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ; | |
1870 | Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ; | |
1871 | Standard_Real Xrp,Yrp,Zrp,Dx,Dy,Dz,Size; | |
1872 | ||
1873 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; | |
1874 | ||
1875 | if( (Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) { | |
1876 | ImmediateUpdate(); | |
1877 | return ; | |
1878 | } | |
1879 | ||
1880 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ; | |
1881 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
1882 | ||
1883 | MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ; | |
1884 | ||
1885 | Standard_Real LIM = ShortRealLast() -1.; | |
1886 | if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM | |
1887 | || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) { | |
1888 | ImmediateUpdate(); | |
1889 | return ; | |
1890 | } | |
1891 | ||
7fd59977 | 1892 | if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) { |
1893 | ImmediateUpdate(); | |
1894 | return ; | |
1895 | } | |
1896 | MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ; | |
1897 | MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ; | |
1898 | Umin = Min(U,U1) ; Umax = Max(U,U1) ; | |
1899 | Vmin = Min(V,V1) ; Vmax = Max(V,V1) ; | |
1900 | Wmin = Min(W,W1) ; Wmax = Max(W,W1) ; | |
1901 | MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; | |
1902 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1903 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1904 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1905 | MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ; | |
1906 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1907 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1908 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1909 | MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ; | |
1910 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1911 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1912 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1913 | MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ; | |
1914 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1915 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1916 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1917 | MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ; | |
1918 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1919 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1920 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1921 | MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ; | |
1922 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
1923 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
1924 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
1925 | ||
1926 | // Adjust Z size | |
1927 | Wmax = Max(Abs(Wmin),Abs(Wmax)) ; | |
1928 | Dz = 2.*Wmax + Margin * Wmax; | |
1929 | ||
1930 | // Compute depth value | |
1931 | Dx = Abs(Umax - Umin) ; Dy = Abs(Vmax - Vmin) ; // Dz = Abs(Wmax - Wmin); | |
1932 | Dx += Margin * Dx; Dy += Margin * Dy; | |
1933 | Size = Sqrt(Dx*Dx + Dy*Dy + Dz*Dz); | |
1934 | if( Size > 0. ) { | |
1935 | SetZSize(Size) ; | |
1936 | SetDepth( Aspect * Size / 2.); | |
1937 | } | |
1938 | ||
1939 | ImmediateUpdate(); | |
1940 | } | |
1941 | ||
b8ddfc2f | 1942 | void V3d_View::FitAll(const Standard_Real Xmin, const Standard_Real Ymin, const Standard_Real Xmax, const Standard_Real Ymax) |
1943 | { | |
7fd59977 | 1944 | FitAll(MyWindow,Xmin,Ymin,Xmax,Ymax); |
1945 | #ifndef IMP020300 | |
1946 | ImmediateUpdate(); | |
1947 | #endif | |
1948 | } | |
1949 | ||
b8ddfc2f | 1950 | void V3d_View::WindowFitAll(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) |
1951 | { | |
7fd59977 | 1952 | WindowFit(Xmin,Ymin,Xmax,Ymax); |
7fd59977 | 1953 | } |
b8ddfc2f | 1954 | |
1955 | void V3d_View::WindowFit(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) | |
1956 | { | |
7fd59977 | 1957 | Standard_Real x1,y1,x2,y2; |
1958 | Convert(Xmin,Ymin,x1,y1); | |
1959 | Convert(Xmax,Ymax,x2,y2); | |
1960 | FitAll(x1,y1,x2,y2); | |
1961 | } | |
1962 | ||
1963 | void V3d_View::SetViewMapping(const Visual3d_ViewMapping& VM) | |
1964 | { | |
1965 | MyViewMapping = VM; | |
1966 | // ajust view type according to mapping projection | |
1967 | // NOTE: Might be dangerous, potentially conflicts with the C++ view class | |
1968 | // (orthographic or perspective)! Use with care! | |
1969 | if ( VM.Projection() == Visual3d_TOP_PERSPECTIVE ) | |
1970 | MyType = V3d_PERSPECTIVE; | |
1971 | else MyType = V3d_ORTHOGRAPHIC; | |
1972 | ||
1973 | MyView->SetViewMapping(MyViewMapping) ; | |
1974 | ImmediateUpdate(); | |
1975 | } | |
1976 | ||
b8ddfc2f | 1977 | void V3d_View::SetViewMappingDefault() |
1978 | { | |
7fd59977 | 1979 | MyView->SetViewMapping(MyViewMapping) ; |
1980 | MyView->SetViewMappingDefault(); | |
1981 | ImmediateUpdate(); | |
1982 | } | |
1983 | ||
b8ddfc2f | 1984 | void V3d_View::ResetViewMapping() |
1985 | { | |
7fd59977 | 1986 | MyView->ViewMappingReset(); |
1987 | MyViewMapping = MyView->ViewMapping() ; | |
1988 | #ifdef IMP020300 | |
1989 | ZFitAll (Zmargin); | |
1990 | Update(); | |
1991 | #else | |
1992 | ImmediateUpdate(); | |
1993 | #endif | |
1994 | } | |
1995 | ||
b8ddfc2f | 1996 | Standard_Real V3d_View::Convert(const Standard_Integer Vp) const |
1997 | { | |
7fd59977 | 1998 | Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Vv ; |
1999 | Standard_Integer Dxw,Dyw ; | |
2000 | ||
2001 | V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window"); | |
2002 | ||
2003 | MyWindow->Size(Dxw,Dyw); | |
2004 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2005 | Dxv = Umax - Umin ; | |
2006 | Vv = Dxv*(Standard_Real)Vp/(Standard_Real)Dxw ; | |
2007 | ||
2008 | return Vv ; | |
2009 | } | |
2010 | ||
b8ddfc2f | 2011 | void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xv, Standard_Real& Yv) const |
2012 | { | |
7fd59977 | 2013 | Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Dyv ; |
2014 | Standard_Integer Dxw,Dyw ; | |
2015 | ||
2016 | V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window"); | |
2017 | ||
2018 | MyWindow->Size(Dxw,Dyw); | |
2019 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2020 | Dxv = Umax - Umin ; Dyv = Vmax - Vmin ; | |
2021 | Xv = Umin + Dxv*(Standard_Real)Xp/(Standard_Real)Dxw ; | |
2022 | Yv = Vmin + Dyv*(Standard_Real)(Dyw-Yp)/(Standard_Real)Dyw ; | |
2023 | } | |
2024 | ||
2025 | Standard_Integer V3d_View::Convert(const Standard_Real Vv) const | |
2026 | { | |
2027 | V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window"); | |
2028 | ||
2029 | Standard_Integer Dxw, Dyw; | |
2030 | MyWindow->Size(Dxw,Dyw); | |
2031 | ||
2032 | Standard_Real Umin,Umax,Vmin,Vmax; | |
2033 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2034 | Standard_Real Dxv = Umax - Umin; | |
2035 | return RealToInt ( Dxw * Vv / Dxv ); | |
2036 | } | |
2037 | ||
2038 | void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const | |
2039 | { | |
2040 | V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window"); | |
2041 | ||
2042 | Standard_Integer Dxw, Dyw; | |
2043 | MyWindow->Size(Dxw,Dyw); | |
2044 | ||
2045 | Standard_Real Umin,Umax,Vmin,Vmax; | |
2046 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2047 | Standard_Real Dxv = Umax - Umin; | |
2048 | Standard_Real Dyv = Vmax - Vmin; | |
2049 | ||
2050 | // CAL 15/12/93 warning: double assigned to int | |
2051 | Xp = RealToInt (Dxw*(Xv - Umin)/Dxv); | |
2052 | // CAL 15/12/93 warning: double assigned to int | |
2053 | Yp = Dyw - RealToInt (Dyw*(Yv - Vmin)/Dyv); | |
2054 | } | |
2055 | ||
b8ddfc2f | 2056 | void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const |
2057 | { | |
7fd59977 | 2058 | Graphic3d_Vertex Vrp ; |
2059 | Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ; | |
2060 | Vrp.Coord(X,Y,Z) ; | |
2061 | #ifndef IMP240100 | |
2062 | if( MyViewer->Grid()->IsActive() ) { | |
2063 | Graphic3d_Vertex NewVrp = Compute(Vrp) ; | |
2064 | NewVrp.Coord(X,Y,Z) ; | |
2065 | } | |
2066 | #endif | |
2067 | } | |
2068 | ||
2069 | void V3d_View::ConvertWithProj(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z, Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const | |
2070 | { | |
2071 | Graphic3d_Vertex Vrp ; | |
2072 | Graphic3d_Vector Proj ; | |
2073 | (MyViewer->Viewer())->ConvertCoordWithProj(MyWindow,Xp,Yp, Vrp, Proj) ; | |
2074 | Vrp.Coord(X,Y,Z) ; | |
2075 | Proj.Coord(Dx,Dy,Dz) ; | |
2076 | #ifndef IMP240100 | |
2077 | if( MyViewer->Grid()->IsActive() ) { | |
2078 | Graphic3d_Vertex NewVrp = Compute(Vrp) ; | |
2079 | NewVrp.Coord(X,Y,Z) ; | |
2080 | } | |
2081 | #endif | |
2082 | } | |
2083 | ||
2084 | #ifdef IMP240100 | |
b8ddfc2f | 2085 | void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const |
2086 | { | |
7fd59977 | 2087 | Graphic3d_Vertex Vrp ; |
2088 | Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ; | |
2089 | if( MyViewer->Grid()->IsActive() ) { | |
2090 | Graphic3d_Vertex NewVrp = Compute(Vrp) ; | |
2091 | NewVrp.Coord(Xg,Yg,Zg) ; | |
2092 | } else | |
2093 | Vrp.Coord(Xg,Yg,Zg) ; | |
2094 | } | |
2095 | ||
b8ddfc2f | 2096 | void V3d_View::ConvertToGrid(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const |
2097 | { | |
7fd59977 | 2098 | if( MyViewer->Grid()->IsActive() ) { |
2099 | Graphic3d_Vertex Vrp(X,Y,Z) ; | |
2100 | Graphic3d_Vertex NewVrp = Compute(Vrp) ; | |
2101 | NewVrp.Coord(Xg,Yg,Zg) ; | |
2102 | } else { | |
2103 | Xg = X; Yg = Y; Zg = Z; | |
2104 | } | |
2105 | } | |
2106 | #endif | |
2107 | ||
2108 | #ifndef IMP240100 | |
b8ddfc2f | 2109 | void V3d_View::PixToRef(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const |
2110 | { | |
7fd59977 | 2111 | Graphic3d_Vertex Vrp ; |
2112 | Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ; | |
2113 | Vrp.Coord(X,Y,Z) ; | |
2114 | if( MyViewer->Grid()->IsActive() ) { | |
2115 | Graphic3d_Vertex NewVrp = Compute(Vrp) ; | |
2116 | NewVrp.Coord(X,Y,Z) ; | |
2117 | } | |
2118 | } | |
2119 | #endif | |
2120 | ||
2121 | #ifdef IMP240100 | |
b8ddfc2f | 2122 | void V3d_View::Convert(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const |
7fd59977 | 2123 | #else |
b8ddfc2f | 2124 | void V3d_View::RefToPix(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const |
7fd59977 | 2125 | #endif |
b8ddfc2f | 2126 | { |
7fd59977 | 2127 | Graphic3d_Vertex Vrp(X,Y,Z) ; |
2128 | (MyViewer->Viewer())->ConvertCoord(MyWindow,Vrp,Xp,Yp) ; | |
2129 | } | |
2130 | ||
2131 | void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const | |
2132 | { | |
2133 | if ( MyType != V3d_PERSPECTIVE ) | |
2134 | { | |
2135 | // use old implementation | |
2136 | Standard_Real Zp; | |
2137 | MyView->Projects( X, Y, Z, Xp, Yp, Zp ); | |
2138 | } | |
2139 | else | |
2140 | { | |
2141 | // NKV - Using raster projection | |
2142 | Standard_Integer Xpx, Ypx; | |
2143 | Convert(X, Y, Z, Xpx, Ypx); | |
2144 | Convert(Xpx, Ypx, Xp, Yp); | |
2145 | } | |
2146 | } | |
2147 | ||
b8ddfc2f | 2148 | void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3) const |
2149 | { | |
7fd59977 | 2150 | Quantity_Color C = BackgroundColor() ; |
7fd59977 | 2151 | C.Values(V1,V2,V3,Type) ; |
2152 | } | |
2153 | ||
b8ddfc2f | 2154 | Quantity_Color V3d_View::BackgroundColor() const |
2155 | { | |
7fd59977 | 2156 | return MyBackground.Color() ; |
2157 | } | |
7fd59977 | 2158 | |
b8ddfc2f | 2159 | void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const |
2160 | { | |
7fd59977 | 2161 | MyGradientBackground.Colors(Color1, Color2); |
2162 | } | |
2163 | ||
b8ddfc2f | 2164 | Aspect_GradientBackground V3d_View::GradientBackground() const |
2165 | { | |
7fd59977 | 2166 | return MyGradientBackground; |
2167 | } | |
2168 | ||
b8ddfc2f | 2169 | Standard_Real V3d_View::Scale() const |
2170 | { | |
7fd59977 | 2171 | Standard_Real Umin,Vmin,Umax,Vmax,Dxv ; |
2172 | Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ; | |
2173 | Standard_Real S = 0. ; | |
2174 | ||
2175 | VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2176 | Dxv = Umax - Umin ; | |
2177 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2178 | if( Umax > Umin && Vmax > Vmin ) S = Dxv/(Umax - Umin) ; | |
2179 | return S ; | |
2180 | } | |
2181 | ||
b8ddfc2f | 2182 | void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const |
2183 | { | |
7fd59977 | 2184 | MyViewOrientation.AxialScale( Sx, Sy, Sz ); |
2185 | } | |
2186 | ||
b8ddfc2f | 2187 | void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const |
2188 | { | |
7fd59977 | 2189 | Standard_Real Umin,Vmin,Umax,Vmax ; |
2190 | ||
2191 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2192 | Xc = (Umin + Umax)/2. ; | |
2193 | Yc = (Vmin + Vmax)/2. ; | |
2194 | } | |
2195 | ||
b8ddfc2f | 2196 | void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const |
2197 | { | |
7fd59977 | 2198 | Standard_Real Umin,Vmin,Umax,Vmax ; |
2199 | ||
2200 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2201 | Width = Umax - Umin ; | |
2202 | Height = Vmax - Vmin ; | |
2203 | } | |
2204 | ||
b8ddfc2f | 2205 | Standard_Real V3d_View::ZSize() const |
2206 | { | |
7fd59977 | 2207 | Standard_Real Wmin,Wmax,Depth ; |
2208 | ||
2209 | Wmax = MyViewMapping.FrontPlaneDistance() ; | |
2210 | Wmin = MyViewMapping.BackPlaneDistance() ; | |
2211 | Depth = 2. * Max(Wmin,Wmax) ; | |
2212 | return (Depth) ; | |
2213 | } | |
2214 | ||
b8ddfc2f | 2215 | Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const |
2216 | { | |
7fd59977 | 2217 | Standard_Real Wmin,Wmax,U,V,W ; |
2218 | Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ; | |
2219 | // CAL 6/11/98 | |
2220 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; | |
2221 | ||
2222 | if( Nstruct ) { | |
2223 | MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ; | |
2224 | MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ; | |
2225 | MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ; | |
2226 | MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; | |
2227 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2228 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2229 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2230 | MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ; | |
2231 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2232 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2233 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2234 | MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ; | |
2235 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2236 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2237 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2238 | MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ; | |
2239 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2240 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2241 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2242 | MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ; | |
2243 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2244 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2245 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2246 | MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ; | |
2247 | Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; | |
2248 | Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; | |
2249 | Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; | |
2250 | } | |
2251 | return Nstruct ; | |
2252 | } | |
2253 | ||
b8ddfc2f | 2254 | Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Standard_Real& Zmin, Standard_Real& Xmax, Standard_Real& Ymax, Standard_Real& Zmax) const |
2255 | { | |
7fd59977 | 2256 | // CAL 6/11/98 |
2257 | // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ; | |
2258 | Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; | |
2259 | ||
2260 | if( Nstruct ) { | |
2261 | MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ; | |
2262 | } | |
2263 | return Nstruct ; | |
2264 | } | |
2265 | ||
b8ddfc2f | 2266 | Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const |
2267 | { | |
7fd59977 | 2268 | Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ; |
2269 | Standard_Real Umin,Vmin,Umax,Vmax ; | |
2270 | Standard_Integer Nstruct,Npoint ; | |
2271 | Graphic3d_MapOfStructure MySetOfStructures; | |
2272 | ||
2273 | MyView->DisplayedStructures (MySetOfStructures); | |
2274 | Nstruct = MySetOfStructures.Extent() ; | |
2275 | ||
2276 | Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ; | |
2277 | ||
2278 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2279 | Npoint = 0 ; X = Y = Z = 0. ; | |
2280 | for( ; MyIterator.More(); MyIterator.Next()) { | |
2281 | if (!(MyIterator.Key())->IsEmpty()) { | |
2282 | (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin, | |
2283 | Xmax,Ymax,Zmax) ; | |
2284 | ||
2285 | Standard_Real LIM = ShortRealLast() -1.; | |
2286 | if (! (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM | |
2287 | || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM )) { | |
2288 | ||
2289 | MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ; | |
2290 | if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) { | |
2291 | Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmin ; | |
2292 | } | |
2293 | MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ; | |
2294 | if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) { | |
2295 | Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmin ; | |
2296 | } | |
2297 | MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ; | |
2298 | if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) { | |
2299 | Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmin ; | |
2300 | } | |
2301 | MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ; | |
2302 | if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) { | |
2303 | Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmin ; | |
2304 | } | |
2305 | MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; | |
2306 | if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) { | |
2307 | Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmax ; | |
2308 | } | |
2309 | MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ; | |
2310 | if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) { | |
2311 | Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmax ; | |
2312 | } | |
2313 | MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ; | |
2314 | if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) { | |
2315 | Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmax ; | |
2316 | } | |
2317 | MyView->Projects(Xmax,Ymax,Zmax,U,V,W) ; | |
2318 | if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) { | |
2319 | Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmax ; | |
2320 | } | |
2321 | } | |
2322 | } | |
2323 | } | |
2324 | if( Npoint > 0 ) { | |
2325 | X /= Npoint ; Y /= Npoint ; Z /= Npoint ; | |
2326 | } | |
2327 | ||
2328 | return Nstruct ; | |
2329 | } | |
2330 | ||
b8ddfc2f | 2331 | void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const |
2332 | { | |
7fd59977 | 2333 | Graphic3d_Vertex Prp ; |
2334 | Graphic3d_Vector Vpn ; | |
2335 | Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ; | |
2336 | ||
2337 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; | |
2338 | MyViewReferencePoint.Coord(Xat,Yat,Zat) ; | |
2339 | Prp = MyViewMapping.ProjectionReferencePoint() ; | |
2340 | Prp.Coord(Xrp,Yrp,Zrp) ; | |
2341 | Vpn = MyViewOrientation.ViewReferencePlane() ; | |
2342 | Vpn.Coord(Xpn,Ypn,Zpn) ; | |
2343 | X = Zrp*Xpn + Xat; Y = Zrp*Ypn + Yat; Z = Zrp*Zpn + Zat; | |
2344 | } | |
2345 | ||
b8ddfc2f | 2346 | void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const |
2347 | { | |
7fd59977 | 2348 | Graphic3d_Vertex PRP,VRPoint; |
2349 | Graphic3d_Vector VRPlane; | |
2350 | Standard_Real FPD,Xprp,Yprp,Zprp; | |
2351 | Standard_Real Xvrp,Yvrp,Zvrp,DXvrp,DYvrp,DZvrp; | |
2352 | ||
2353 | if ( MyType == V3d_PERSPECTIVE ) { | |
2354 | PRP = MyViewMapping.ProjectionReferencePoint() ; | |
2355 | FPD = MyViewMapping.FrontPlaneDistance(); | |
2356 | PRP.Coord(Xprp,Yprp,Zprp); | |
2357 | VRPoint = MyViewOrientation.ViewReferencePoint(); | |
2358 | VRPoint.Coord(Xvrp,Yvrp,Zvrp); | |
2359 | VRPlane = MyViewOrientation.ViewReferencePlane(); | |
2360 | VRPlane.Coord(DXvrp,DYvrp,DZvrp); | |
2361 | X = (FPD + Zprp) * DXvrp + Xvrp; | |
2362 | Y = (FPD + Zprp) * DYvrp + Yvrp; | |
2363 | Z = (FPD + Zprp) * DZvrp + Zvrp; | |
2364 | } | |
2365 | else Eye(X,Y,Z); | |
2366 | } | |
2367 | ||
b8ddfc2f | 2368 | void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix, const Standard_Integer Ypix, Standard_Real& XP, Standard_Real& YP, Standard_Real& ZP, Standard_Real& VX, Standard_Real& VY, Standard_Real& VZ) const |
2369 | { | |
7fd59977 | 2370 | Standard_Real Xo,Yo,Zo; |
2371 | ||
2372 | Convert(Xpix,Ypix,XP,YP,ZP); | |
2373 | if ( MyType == V3d_PERSPECTIVE ) { | |
2374 | FocalReferencePoint(Xo,Yo,Zo); | |
2375 | VX = Xo - XP; | |
2376 | VY = Yo - YP; | |
2377 | VZ = Zo - ZP; | |
2378 | } | |
2379 | else { | |
2380 | Proj(VX,VY,VZ); | |
2381 | } | |
2382 | } | |
2383 | ||
b8ddfc2f | 2384 | Standard_Real V3d_View::Depth() const |
2385 | { | |
7fd59977 | 2386 | Graphic3d_Vertex Prp ; |
2387 | Standard_Real Xrp,Yrp,Zrp ; | |
2388 | ||
2389 | Prp = MyViewMapping.ProjectionReferencePoint() ; | |
2390 | Prp.Coord(Xrp,Yrp,Zrp) ; | |
2391 | return Zrp ; | |
2392 | } | |
2393 | ||
b8ddfc2f | 2394 | void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const |
2395 | { | |
7fd59977 | 2396 | Graphic3d_Vector Vpn ; |
2397 | ||
2398 | Vpn = MyViewOrientation.ViewReferencePlane() ; | |
2399 | Vpn.Coord(Dx,Dy,Dz) ; | |
2400 | } | |
2401 | ||
b8ddfc2f | 2402 | void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const |
2403 | { | |
7fd59977 | 2404 | Graphic3d_Vertex Vrp ; |
2405 | ||
2406 | Vrp = MyViewOrientation.ViewReferencePoint() ; | |
2407 | Vrp.Coord(X,Y,Z) ; | |
2408 | } | |
2409 | ||
b8ddfc2f | 2410 | void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const |
2411 | { | |
7fd59977 | 2412 | Graphic3d_Vector Vup ; |
2413 | ||
2414 | Vup = MyViewOrientation.ViewReferenceUp() ; | |
2415 | Vup.Coord(Vx,Vy,Vz) ; | |
2416 | } | |
2417 | ||
b8ddfc2f | 2418 | Standard_Real V3d_View::Twist() const |
2419 | { | |
7fd59977 | 2420 | Standard_Real Xup,Yup,Zup,Xpn,Ypn,Zpn,X0,Y0,Z0 ; |
2421 | Standard_Real pvx,pvy,pvz,pvn,sca,angle ; | |
2422 | Graphic3d_Vector Vpn,Vup,Xaxis,Yaxis,Zaxis ; | |
2423 | Standard_Boolean TheStatus ; | |
2424 | ||
2425 | Vpn = MyViewOrientation.ViewReferencePlane() ; | |
2426 | Vpn.Coord(Xpn,Ypn,Zpn) ; | |
2427 | Vup.SetCoord(0.,0.,1.) ; | |
2428 | TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ; | |
2429 | if( !TheStatus ) { | |
2430 | Vup.SetCoord(0.,1.,0.) ; | |
2431 | TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ; | |
2432 | } | |
2433 | if( !TheStatus ) { | |
2434 | Vup.SetCoord(1.,0.,0.) ; | |
2435 | TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ; | |
2436 | } | |
2437 | Yaxis.Coord(X0,Y0,Z0) ; | |
2438 | Vup = MyViewOrientation.ViewReferenceUp() ; | |
2439 | Vup.Coord(Xup,Yup,Zup) ; | |
2440 | /* Compute Cross Vector From Up & Origin */ | |
2441 | pvx = Y0*Zup - Z0*Yup ; | |
2442 | pvy = Z0*Xup - X0*Zup ; | |
2443 | pvz = X0*Yup - Y0*Xup ; | |
2444 | pvn = pvx*pvx + pvy*pvy + pvz*pvz ; | |
2445 | sca = X0*Xup + Y0*Yup + Z0*Zup ; | |
2446 | /* Compute Angle */ | |
2447 | angle = Sqrt(pvn) ; | |
2448 | if( angle > 1. ) angle = 1. ; | |
2449 | else if( angle < -1. ) angle = -1. ; | |
2450 | angle = asin(angle) ; | |
c6541a0c D |
2451 | if( sca < 0. ) angle = M_PI - angle ; |
2452 | if( angle > 0. && angle < M_PI ) { | |
7fd59977 | 2453 | sca = pvx*Xpn + pvy*Ypn + pvz*Zpn ; |
2454 | if( sca < 0. ) angle = DEUXPI - angle ; | |
2455 | } | |
2456 | return angle ; | |
2457 | } | |
2458 | ||
b8ddfc2f | 2459 | V3d_TypeOfShadingModel V3d_View::ShadingModel() const |
2460 | { | |
7fd59977 | 2461 | V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ; |
2462 | return SM ; | |
2463 | } | |
2464 | ||
b8ddfc2f | 2465 | V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail() const |
2466 | { | |
7fd59977 | 2467 | V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ; |
2468 | return SM ; | |
2469 | } | |
2470 | ||
b8ddfc2f | 2471 | Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const |
2472 | { | |
7fd59977 | 2473 | Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ; |
2474 | return SM ; | |
2475 | } | |
2476 | ||
b8ddfc2f | 2477 | V3d_TypeOfVisualization V3d_View::Visualization() const |
2478 | { | |
7fd59977 | 2479 | V3d_TypeOfVisualization V = |
2480 | (V3d_TypeOfVisualization)MyViewContext.Visualization() ; | |
2481 | return V ; | |
2482 | } | |
2483 | ||
b8ddfc2f | 2484 | Standard_Boolean V3d_View::Antialiasing() const |
2485 | { | |
7fd59977 | 2486 | Standard_Boolean A = MyViewContext.AliasingIsOn() ; |
2487 | return A ; | |
2488 | } | |
2489 | ||
b8ddfc2f | 2490 | Handle(V3d_Viewer) V3d_View::Viewer() const |
2491 | { | |
7fd59977 | 2492 | return MyViewer ; |
2493 | } | |
2494 | ||
b8ddfc2f | 2495 | Standard_Boolean V3d_View::IfWindow() const |
2496 | { | |
7fd59977 | 2497 | Standard_Boolean TheStatus = MyView->IsDefined() ; |
2498 | return TheStatus ; | |
2499 | } | |
2500 | ||
b8ddfc2f | 2501 | Handle(Aspect_Window) V3d_View::Window() const |
2502 | { | |
7fd59977 | 2503 | return MyWindow; |
2504 | } | |
2505 | ||
b8ddfc2f | 2506 | V3d_TypeOfView V3d_View::Type() const |
2507 | { | |
7fd59977 | 2508 | return (MyType) ; |
2509 | } | |
2510 | ||
b8ddfc2f | 2511 | void V3d_View::SetFocale( const Standard_Real focale ) |
2512 | { | |
7fd59977 | 2513 | Standard_TypeMismatch_Raise_if (MyType != V3d_PERSPECTIVE, |
2514 | "the view is not a perspective view"); | |
2515 | Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ; | |
2516 | Graphic3d_Vertex Prp ; | |
2517 | Prp = MyViewMapping.ProjectionReferencePoint() ; | |
2518 | Prp.Coord(Xrp,Yrp,Zrp) ; | |
2519 | if( MyProjModel == V3d_TPM_WALKTHROUGH ) { | |
2520 | ViewPlane = Zrp - focale ; | |
2521 | } else { | |
2522 | FrontPlane = MyViewMapping.FrontPlaneDistance() ; | |
2523 | ViewPlane = FrontPlane + Zrp - focale ; | |
2524 | } | |
2525 | MyViewMapping.SetViewPlaneDistance(ViewPlane) ; | |
2526 | MyView->SetViewMapping(MyViewMapping) ; | |
2527 | ||
2528 | ImmediateUpdate(); | |
2529 | } | |
2530 | ||
b8ddfc2f | 2531 | Standard_Real V3d_View::Focale( ) const |
2532 | { | |
7fd59977 | 2533 | Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ; |
2534 | Standard_Real focale = 0.0 ; | |
2535 | Graphic3d_Vertex Prp ; | |
2536 | ||
2537 | if( MyType == V3d_PERSPECTIVE ) { | |
2538 | Prp = MyViewMapping.ProjectionReferencePoint() ; | |
2539 | Prp.Coord(Xrp,Yrp,Zrp) ; | |
2540 | ViewPlane = MyViewMapping.ViewPlaneDistance() ; | |
2541 | if( MyProjModel == V3d_TPM_WALKTHROUGH ) { | |
2542 | focale = Zrp - ViewPlane ; | |
2543 | } else { | |
2544 | FrontPlane = MyViewMapping.FrontPlaneDistance() ; | |
2545 | focale = FrontPlane + Zrp - ViewPlane ; | |
2546 | } | |
2547 | } | |
2548 | return (focale) ; | |
2549 | } | |
2550 | ||
2551 | void V3d_View::SetViewingVolume(const Standard_Real Left, const Standard_Real Right, | |
2552 | const Standard_Real Bottom, const Standard_Real Top, | |
2553 | const Standard_Real ZNear, const Standard_Real ZFar) | |
2554 | { | |
2555 | Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp; | |
2556 | ||
6942f04a | 2557 | V3d_BadValue_Raise_if ( ZNear <= 0. || ZFar <= 0. || ZNear >= ZFar, "V3d_View::SetVolume, bad distances"); |
7fd59977 | 2558 | |
2559 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ; | |
2560 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
2561 | Zrp = ZNear; | |
2562 | ||
2563 | Standard_Real size = (ZFar - ZNear) / 2.; | |
2564 | ||
2565 | MyViewMapping.SetFrontPlaneDistance(size); | |
2566 | MyViewMapping.SetBackPlaneDistance(-size); | |
2567 | ||
2568 | // keep view plane at front plane distance | |
2569 | MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : size); | |
2570 | ||
2571 | // set window limits | |
2572 | Umin = Left; Umax = Right; | |
2573 | Vmin = Bottom; Vmax = Top; | |
2574 | MyViewMapping.SetWindowLimit(Left, Bottom, Right, Top); | |
2575 | ||
2576 | // Update window center | |
2577 | if ( MyType == V3d_PERSPECTIVE ) { | |
2578 | Xrp = Yrp = 0.0; | |
2579 | } | |
2580 | else { | |
2581 | Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ; | |
2582 | } | |
2583 | MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ; | |
2584 | MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint); | |
2585 | ||
2586 | MyView->SetViewMapping(MyViewMapping) ; | |
2587 | // SetZSize(0.); | |
2588 | ImmediateUpdate(); | |
2589 | } | |
2590 | ||
2591 | Handle(Visual3d_View) V3d_View::View() const | |
2592 | { | |
2593 | return MyView ; | |
2594 | } | |
2595 | ||
2596 | Visual3d_ViewMapping V3d_View::ViewMapping() const | |
2597 | { | |
2598 | return MyViewMapping; | |
2599 | } | |
2600 | ||
2601 | Visual3d_ViewOrientation V3d_View::ViewOrientation() const | |
2602 | { | |
2603 | return MyViewOrientation; | |
2604 | } | |
2605 | ||
b8ddfc2f | 2606 | Standard_Boolean V3d_View::ScreenAxis( const Graphic3d_Vector &Vpn, const Graphic3d_Vector &Vup, Graphic3d_Vector &Xaxe, Graphic3d_Vector &Yaxe, Graphic3d_Vector &Zaxe) |
2607 | { | |
7fd59977 | 2608 | Standard_Real Xpn,Ypn,Zpn,Xup,Yup,Zup ; |
2609 | Standard_Real dx1,dy1,dz1,dx2,dy2,dz2,xx,yy,zz ; | |
2610 | ||
2611 | Vpn.Coord(Xpn,Ypn,Zpn) ; | |
2612 | Vup.Coord(Xup,Yup,Zup) ; | |
2613 | xx = Yup*Zpn - Zup*Ypn ; | |
2614 | yy = Zup*Xpn - Xup*Zpn ; | |
2615 | zz = Xup*Ypn - Yup*Xpn ; | |
2616 | Xaxe.SetCoord(xx,yy,zz) ; | |
2617 | if( Xaxe.LengthZero() ) return Standard_False; | |
2618 | Xaxe.Normalize() ; Xaxe.Coord(dx1,dy1,dz1) ; | |
2619 | xx = Ypn*dz1 - Zpn*dy1 ; | |
2620 | yy = Zpn*dx1 - Xpn*dz1 ; | |
2621 | zz = Xpn*dy1 - Ypn*dx1 ; | |
2622 | Yaxe.SetCoord(xx,yy,zz) ; | |
2623 | if( Yaxe.LengthZero() ) return Standard_False; | |
2624 | Yaxe.Normalize() ; Yaxe.Coord(dx2,dy2,dz2) ; | |
2625 | xx = dy1*dz2 - dz1*dy2 ; | |
2626 | yy = dz1*dx2 - dx1*dz2 ; | |
2627 | zz = dx1*dy2 - dy1*dx2 ; | |
2628 | Zaxe.SetCoord(xx,yy,zz) ; | |
2629 | if( Zaxe.LengthZero() ) return Standard_False; | |
2630 | Zaxe.Normalize() ; | |
2631 | return Standard_True ; | |
2632 | } | |
2633 | ||
b8ddfc2f | 2634 | void V3d_View::InitMatrix( TColStd_Array2OfReal& Matrix ) |
2635 | { | |
7fd59977 | 2636 | Standard_Integer LR = Matrix.LowerRow() ; |
2637 | Standard_Integer UR = Matrix.UpperRow() ; | |
2638 | Standard_Integer LC = Matrix.LowerCol() ; | |
2639 | Standard_Integer UC = Matrix.UpperCol() ; | |
2640 | Standard_Integer I,J ; | |
2641 | ||
2642 | for( I=LR ; I<=UR ; I++ ) { | |
2643 | for( J=LC ; J<=UC ; J++ ) Matrix(I,J) = 0. ; | |
2644 | } | |
2645 | for( I=LR,J=LC ; I<=UR ; I++,J++ ) Matrix(I,J) = 1. ; | |
2646 | } | |
2647 | ||
b8ddfc2f | 2648 | Standard_Boolean V3d_View::Multiply (const TColStd_Array2OfReal& Left, const TColStd_Array2OfReal& Right, TColStd_Array2OfReal& Matrix) |
2649 | { | |
7fd59977 | 2650 | Standard_Integer llr = Left.LowerRow (); |
2651 | Standard_Integer llc = Left.LowerCol (); | |
2652 | Standard_Integer luc = Left.UpperCol (); | |
2653 | ||
2654 | Standard_Integer rlr = Right.LowerRow (); | |
2655 | Standard_Integer rur = Right.UpperRow (); | |
2656 | Standard_Integer rlc = Right.LowerCol (); | |
2657 | ||
2658 | Standard_Integer mlr = Matrix.LowerRow (); | |
2659 | Standard_Integer mur = Matrix.UpperRow (); | |
2660 | Standard_Integer mlc = Matrix.LowerCol (); | |
2661 | Standard_Integer muc = Matrix.UpperCol (); | |
2662 | ||
2663 | TColStd_Array2OfReal Result (mlr, mur, mlc, muc); | |
2664 | ||
2665 | InitMatrix (Result); | |
2666 | ||
2667 | // Left et Right incompatibles | |
2668 | if (luc - llc + 1 != rur - rlr + 1) | |
2669 | return Standard_False; | |
2670 | ||
2671 | Standard_Integer i, j, k; | |
2672 | ||
2673 | Standard_Real Som; | |
2674 | Standard_Integer I1 = llr; | |
2675 | ||
2676 | for (i=mlr; i<=mur; i++) { | |
2677 | Standard_Integer J2 = rlc; | |
2678 | for (j=mlc; j<=muc; j++) { | |
2679 | Som = 0.0; | |
2680 | Standard_Integer J1 = llc; | |
2681 | Standard_Integer I2 = rlr; | |
2682 | for (k=llc; k<=luc; k++) { | |
2683 | Som = Som + Left (I1, J1) * Right (I2, J2); | |
2684 | J1++; | |
2685 | I2++; | |
2686 | } | |
2687 | Result (i, j) = Som; | |
2688 | J2++; | |
2689 | } | |
2690 | I1++; | |
2691 | } | |
2692 | ||
2693 | for (i=mlr; i<=mur; i++) | |
2694 | for (j=mlc; j<=muc; j++) | |
2695 | Matrix (i, j) = Result (i, j); | |
2696 | ||
2697 | return Standard_True; | |
2698 | } | |
2699 | ||
2700 | /*----------------------------------------------------------------------*/ | |
2701 | ||
b8ddfc2f | 2702 | void V3d_View::RotAxis( const Graphic3d_Vertex &Vrp, const Graphic3d_Vector &Axe, const Standard_Real angle, TColStd_Array2OfReal& Matrix ) |
2703 | { | |
7fd59977 | 2704 | Standard_Real Xrp,Yrp,Zrp,Xaxe,Yaxe,Zaxe ; |
2705 | Standard_Real sina,cosa,cos1m,terms1,terms2,terms3 ; | |
2706 | Standard_Real termc12,termc13,termc23,vcal ; | |
2707 | TColStd_Array2OfReal Tmatrix(0,3,0,3) ; | |
2708 | TColStd_Array2OfReal Rmatrix(0,3,0,3) ; | |
2709 | ||
2710 | InitMatrix(Matrix) ; | |
2711 | InitMatrix(Tmatrix) ; | |
2712 | ||
2713 | Vrp.Coord(Xrp,Yrp,Zrp) ; | |
2714 | Axe.Coord(Xaxe,Yaxe,Zaxe) ; | |
2715 | /* translation of x,y,z */ | |
2716 | Tmatrix(0,3) = Xrp ; Tmatrix(1,3) = Yrp ; Tmatrix(2,3) = Zrp ; | |
2717 | /* rotation around an axis */ | |
2718 | cosa = cos(angle); sina = sin(angle); cos1m = 1. - cosa ; | |
2719 | termc12 = Xaxe * Yaxe * cos1m ; | |
2720 | termc13 = Xaxe * Zaxe * cos1m ; | |
2721 | termc23 = Yaxe * Zaxe * cos1m ; | |
2722 | terms1 = Xaxe * sina ; | |
2723 | terms2 = Yaxe * sina ; | |
2724 | terms3 = Zaxe * sina ; | |
2725 | ||
2726 | vcal = Xaxe * Xaxe ; | |
2727 | Rmatrix(0,0) = vcal + ( 1. - vcal ) * cosa ; | |
2728 | Rmatrix(1,0) = termc12 + terms3 ; | |
2729 | Rmatrix(2,0) = termc13 - terms2 ; | |
2730 | Rmatrix(3,0) = 0. ; | |
2731 | Rmatrix(0,1) = termc12 - terms3 ; | |
2732 | vcal = Yaxe * Yaxe ; | |
2733 | Rmatrix(1,1) = vcal + ( 1. - vcal ) * cosa ; | |
2734 | Rmatrix(2,1) = termc23 + terms1 ; | |
2735 | Rmatrix(3,1) = 0. ; | |
2736 | Rmatrix(0,2) = termc13 + terms2 ; | |
2737 | Rmatrix(1,2) = termc23 - terms1 ; | |
2738 | vcal = Zaxe * Zaxe ; | |
2739 | Rmatrix(2,2) = vcal + ( 1. - vcal ) * cosa ; | |
2740 | Rmatrix(3,2) = 0. ; | |
2741 | Rmatrix(0,3) = 0. ; | |
2742 | Rmatrix(1,3) = 0. ; | |
2743 | Rmatrix(2,3) = 0. ; | |
2744 | Rmatrix(3,3) = 1. ; | |
2745 | /* produced by two matrices */ | |
2746 | Multiply(Tmatrix, Rmatrix, Matrix); | |
2747 | /* translation invert */ | |
2748 | Tmatrix(0,3) = -Xrp; | |
2749 | Tmatrix(1,3) = -Yrp; | |
2750 | Tmatrix(2,3) = -Zrp; | |
2751 | /* product final */ | |
2752 | Multiply(Matrix, Tmatrix, Matrix); | |
2753 | } | |
2754 | ||
2755 | /*----------------------------------------------------------------------*/ | |
2756 | ||
b8ddfc2f | 2757 | Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Array2OfReal &Matrix ) |
2758 | { | |
7fd59977 | 2759 | Graphic3d_Vertex PP ; |
2760 | Standard_Real X,Y,Z,XX,YY,ZZ ; | |
2761 | ||
2762 | // CAL. S3892 | |
2763 | Standard_Integer lr, ur, lc, uc; | |
2764 | lr = Matrix.LowerRow (); | |
2765 | ur = Matrix.UpperRow (); | |
2766 | lc = Matrix.LowerCol (); | |
2767 | uc = Matrix.UpperCol (); | |
2768 | if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) { | |
2769 | P.Coord(X,Y,Z) ; | |
2770 | PP.SetCoord(X,Y,Z) ; | |
2771 | return PP ; | |
2772 | } | |
2773 | P.Coord(X,Y,Z) ; | |
2774 | XX = (Matrix(lr,lc+3) + X*Matrix(lr,lc) + Y*Matrix(lr,lc+1)+ | |
2775 | Z*Matrix(lr,lc+2))/Matrix(lr+3,lc+3) ; | |
2776 | ||
2777 | YY = (Matrix(lr+1,lc+3) + X*Matrix(lr+1,lc) + Y*Matrix(lr+1,lc+1) + | |
2778 | Z*Matrix(lr+1,lc+2))/Matrix(lr+3,lc+3) ; | |
2779 | ||
2780 | ZZ = (Matrix(lr+2,lc+3) + X*Matrix(lr+2,lc) + Y*Matrix(lr+2,lc+1) + | |
2781 | Z*Matrix(lr+2,lc+2))/Matrix(lr+3,lc+3) ; | |
2782 | PP.SetCoord(XX,YY,ZZ) ; | |
2783 | return PP ; | |
2784 | } | |
2785 | ||
b8ddfc2f | 2786 | Graphic3d_Vector V3d_View::TrsPoint( const Graphic3d_Vector& V, const TColStd_Array2OfReal& Matrix ) |
2787 | { | |
7fd59977 | 2788 | Graphic3d_Vector VV ; |
2789 | Standard_Real X,Y,Z,XX,YY,ZZ ; | |
2790 | ||
2791 | // CAL. S3892 | |
2792 | Standard_Integer lr, ur, lc, uc; | |
2793 | lr = Matrix.LowerRow (); | |
2794 | ur = Matrix.UpperRow (); | |
2795 | lc = Matrix.LowerCol (); | |
2796 | uc = Matrix.UpperCol (); | |
2797 | if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) { | |
2798 | V.Coord(X,Y,Z) ; | |
2799 | VV.SetCoord(X,Y,Z) ; | |
2800 | return VV ; | |
2801 | } | |
2802 | V.Coord(X,Y,Z) ; | |
2803 | XX = X*Matrix(lr,lc)+Y*Matrix(lr,lc+1)+Z*Matrix(lr,lc+2) ; | |
2804 | YY = X*Matrix(lr+1,lc)+Y*Matrix(lr+1,lc+1)+Z*Matrix(lr+1,lc+2) ; | |
2805 | ZZ = X*Matrix(lr+2,lc)+Y*Matrix(lr+2,lc+1)+Z*Matrix(lr+2,lc+2) ; | |
2806 | VV.SetCoord(XX,YY,ZZ) ; VV.Normalize() ; | |
2807 | return VV ; | |
2808 | } | |
2809 | ||
b8ddfc2f | 2810 | void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor) |
2811 | { | |
7fd59977 | 2812 | Panning(Convert(Dx),Convert(Dy),aZoomFactor,Standard_True); |
7fd59977 | 2813 | } |
2814 | ||
2815 | void V3d_View::Zoom (const Standard_Integer X1, | |
2816 | const Standard_Integer Y1, | |
2817 | const Standard_Integer X2, | |
2818 | const Standard_Integer Y2) | |
2819 | { | |
2820 | ||
2821 | Standard_Real dx = Standard_Real (X2-X1); | |
2822 | Standard_Real dy = Standard_Real (Y2-Y1); | |
2823 | if ( dx != 0. || dy != 0. ) { | |
2824 | Standard_Real dzoom = Sqrt(dx*dx + dy*dy) / 100. + 1; | |
2825 | dzoom = (dx > 0) ? dzoom : 1./dzoom; | |
2826 | SetZoom(dzoom, Standard_True); | |
2827 | } | |
2828 | } | |
2829 | ||
2830 | void V3d_View::Zoom (const Standard_Integer X1, | |
2831 | const Standard_Integer Y1) | |
2832 | { | |
2833 | Standard_Real x,y; | |
2834 | Center(x,y); | |
2835 | Standard_Integer ix,iy; | |
2836 | Convert(x,y,ix,iy); | |
2837 | Zoom(ix,iy,X1,Y1); | |
2838 | } | |
2839 | ||
2840 | // Defines the point (pixel) of zooming (for the method ZoomAtPoint()). | |
2841 | void V3d_View::StartZoomAtPoint(const Standard_Integer xpix, const Standard_Integer ypix) | |
2842 | { | |
2843 | MyZoomAtPointX = xpix; | |
2844 | MyZoomAtPointY = ypix; | |
2845 | } | |
2846 | ||
2847 | // Zooms the model at a pixel defined by the method StartZoomAtPoint(). | |
2848 | void V3d_View::ZoomAtPoint(const Standard_Integer mouseStartX, | |
2849 | const Standard_Integer mouseStartY, | |
2850 | const Standard_Integer mouseEndX, | |
2851 | const Standard_Integer mouseEndY) | |
2852 | { | |
2853 | Standard_Boolean update; | |
2854 | V3d_Coordinate X0, Y0, XS, YS; | |
2855 | ||
2856 | // Forbid any update. | |
2857 | update = SetImmediateUpdate(Standard_False); | |
2858 | ||
2859 | // Get center point | |
2860 | Center(X0, Y0); | |
2861 | ||
2862 | // Pan the point to the center of window. | |
2863 | Convert(MyZoomAtPointX, MyZoomAtPointY, XS, YS); | |
2864 | Panning(X0-XS, Y0-YS); | |
2865 | ||
2866 | // Zoom | |
2867 | Standard_Real d = Standard_Real ((mouseEndX + mouseEndY) - (mouseStartX + mouseStartY)); | |
2868 | ||
2869 | Standard_Real dzoom = fabs(d) / 100.0 + 1.0; | |
2870 | dzoom = (d > 0) ? dzoom : 1.0 / dzoom; | |
6942f04a | 2871 | V3d_BadValue_Raise_if( dzoom <= 0.,"V3d_View::ZoomAtPoint, bad coefficient"); |
7fd59977 | 2872 | |
2873 | Standard_Real Umin,Vmin,Umax,Vmax; | |
2874 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax); | |
2875 | ||
2876 | MyXwindowCenter = (Umin + Umax) / 2.0; | |
2877 | MyYwindowCenter = (Vmin + Vmax) / 2.0; | |
2878 | MyWindowWidth = Abs(Umax - Umin); | |
2879 | MyWindowHeight = Abs(Vmax - Vmin); | |
2880 | ||
2881 | // Ensure that zoom will not be too small or too big. | |
2882 | Standard_Real coef = dzoom; | |
2883 | if (MyWindowWidth < coef * Precision::Confusion()) | |
2884 | coef = MyWindowWidth / Precision::Confusion(); | |
2885 | else if (MyWindowWidth > coef * 1e12) | |
2886 | coef = MyWindowWidth / 1e12; | |
2887 | if (MyWindowHeight < coef * Precision::Confusion()) | |
2888 | coef = MyWindowHeight / Precision::Confusion(); | |
2889 | else if (MyWindowHeight > coef * 1e12) | |
2890 | coef = MyWindowHeight / 1e12; | |
2891 | ||
2892 | Standard_Real Dxv = MyWindowWidth / coef; | |
2893 | Standard_Real Dyv = MyWindowHeight / coef; | |
2894 | ||
2895 | Umin = MyXwindowCenter - Dxv/2.0; Umax = MyXwindowCenter + Dxv/2.0; | |
2896 | Vmin = MyYwindowCenter - Dyv/2.0; Vmax = MyYwindowCenter + Dyv/2.0; | |
2897 | ||
2898 | // Pan the point backwards. | |
2899 | Dxv = (XS - X0) / coef; | |
2900 | Dyv = (YS - Y0) / coef; | |
2901 | ||
2902 | MyXwindowCenter = (Umin + Umax) / 2.0; | |
2903 | MyYwindowCenter = (Vmin + Vmax) / 2.0; | |
2904 | MyWindowWidth = Abs(Umax - Umin); | |
2905 | MyWindowHeight = Abs(Vmax - Vmin); | |
2906 | ||
2907 | Standard_Real Xrp,Yrp,Zrp; | |
2908 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint(); | |
2909 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp); | |
2910 | ||
2911 | Xrp = MyXwindowCenter - Dxv; | |
2912 | Yrp = MyYwindowCenter - Dyv; | |
2913 | ||
2914 | Umin = Xrp - MyWindowWidth / 2.0; Umax = Xrp + MyWindowWidth / 2.0; | |
2915 | Vmin = Yrp - MyWindowHeight / 2.0; Vmax = Yrp + MyWindowHeight / 2.0; | |
2916 | ||
2917 | // Set new reference plane coordintes of the window. | |
2918 | MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax); | |
2919 | if (MyType != V3d_PERSPECTIVE) | |
2920 | { | |
2921 | MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp); | |
2922 | MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint); | |
2923 | } | |
2924 | MyView->SetViewMapping(MyViewMapping); | |
2925 | ||
2926 | // Update the view. | |
2927 | SetImmediateUpdate(update); | |
2928 | ImmediateUpdate(); | |
2929 | } | |
2930 | ||
2931 | void V3d_View::AxialScale (const Standard_Integer Dx, | |
2932 | const Standard_Integer Dy, | |
2933 | const V3d_TypeOfAxe Axis) | |
2934 | { | |
2935 | if( Dx != 0. || Dy != 0. ) { | |
2936 | Standard_Real Sx, Sy, Sz; | |
2937 | AxialScale( Sx, Sy, Sz ); | |
2938 | Standard_Real dscale = Sqrt(Dx*Dx + Dy*Dy) / 100. + 1; | |
2939 | dscale = (Dx > 0) ? dscale : 1./dscale; | |
2940 | if( Axis == V3d_X ) Sx = dscale; | |
2941 | if( Axis == V3d_Y ) Sy = dscale; | |
2942 | if( Axis == V3d_Z ) Sz = dscale; | |
2943 | SetAxialScale( Sx, Sy, Sz ); | |
2944 | } | |
2945 | } | |
2946 | ||
2947 | void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow, | |
2948 | const Standard_Real Xmin, | |
2949 | const Standard_Real Ymin, | |
2950 | const Standard_Real Xmax, | |
2951 | const Standard_Real Ymax) | |
2952 | { | |
2953 | ||
2954 | Standard_Real Umin,Umax,Vmin,Vmax,Xrp,Yrp,Zrp ; | |
2955 | Standard_Real DxvOld,DyvOld,DxvNew,DyvNew,RapOld,RapNew ; | |
2956 | Standard_Integer Xpixel,Ypixel; | |
2957 | //Standard_Integer Xleft,Yup,Xright,Ylow ; | |
2958 | ||
6942f04a | 2959 | V3d_BadValue_Raise_if( (Xmin == Xmax) || (Ymin == Ymax) , |
7fd59977 | 2960 | "V3d_View::FitAll, Window Size is NULL"); |
2961 | ||
2962 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ; | |
2963 | MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ; | |
2964 | aWindow->Size(Xpixel,Ypixel); | |
2965 | DxvOld = Xpixel; DyvOld = Ypixel; | |
2966 | ||
2967 | if( (DxvOld == 0.) || (DyvOld == 0.) ) return ; | |
2968 | RapOld = DxvOld/DyvOld ; | |
2969 | DxvNew = Abs(Xmax - Xmin) ; DyvNew = Abs(Ymax - Ymin) ; | |
2970 | RapNew = DxvNew/DyvNew ; | |
2971 | if( RapNew >= RapOld ) { | |
2972 | DyvNew = DxvNew/RapOld ; | |
2973 | } else { | |
2974 | DxvNew = DyvNew*RapOld ; | |
2975 | } | |
2976 | Xrp = (Xmin + Xmax)/2. ; Yrp = (Ymin + Ymax)/2. ; | |
2977 | Umin = Xrp - DxvNew/2. ; Vmin = Yrp - DyvNew/2. ; | |
2978 | Umax = Xrp + DxvNew/2. ; Vmax = Yrp + DyvNew/2. ; | |
2979 | MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ; | |
2980 | if( MyType != V3d_PERSPECTIVE ) { | |
2981 | MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ; | |
2982 | MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint); | |
2983 | } | |
2984 | MyView->SetViewMapping(MyViewMapping) ; | |
2985 | #ifdef IMP020300 | |
2986 | Update(); | |
2987 | #else | |
2988 | ImmediateUpdate(); | |
2989 | #endif | |
2990 | } | |
2991 | ||
2992 | #ifdef IMP250900 | |
2993 | static Standard_Boolean zRotation = Standard_False; | |
2994 | #endif | |
2995 | void V3d_View::StartRotation(const Standard_Integer X, | |
2996 | const Standard_Integer Y, | |
2997 | const Quantity_Ratio zRotationThreshold) | |
2998 | { | |
2999 | ||
3000 | sx = X; sy = Y; | |
3001 | Standard_Real x,y; | |
3002 | Size(x,y); | |
3003 | rx = Standard_Real(Convert(x)); | |
3004 | ry = Standard_Real(Convert(y)); | |
3005 | Gravity(gx,gy,gz); | |
3006 | Rotate(0.,0.,0.,gx,gy,gz,Standard_True); | |
3007 | #ifdef IMP250900 | |
3008 | zRotation = Standard_False; | |
3009 | if( zRotationThreshold > 0. ) { | |
3010 | Standard_Real dx = Abs(sx - rx/2.); | |
3011 | Standard_Real dy = Abs(sy - ry/2.); | |
3012 | // if( dx > rx/3. || dy > ry/3. ) zRotation = Standard_True; | |
3013 | Standard_Real dd = zRotationThreshold * (rx + ry)/2.; | |
3014 | if( dx > dd || dy > dd ) zRotation = Standard_True; | |
3015 | } | |
3016 | #endif | |
3017 | ||
3018 | } | |
3019 | ||
3020 | void V3d_View::Rotation(const Standard_Integer X, | |
3021 | const Standard_Integer Y) | |
3022 | { | |
3023 | ||
3024 | #ifdef IMP210600 | |
3025 | if( rx == 0. || ry == 0. ) { | |
3026 | StartRotation(X,Y); | |
3027 | return; | |
3028 | } | |
3029 | #endif | |
3030 | #ifdef IMP250900 | |
3031 | Standard_Real dx=0.,dy=0.,dz=0.; | |
3032 | if( zRotation ) { | |
3033 | dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) - | |
3034 | atan2(sx-rx/2.,ry/2.-sy); | |
3035 | } else { | |
c6541a0c D |
3036 | dx = (Standard_Real(X) - sx) * M_PI / rx; |
3037 | dy = (sy - Standard_Real(Y)) * M_PI / ry; | |
7fd59977 | 3038 | } |
3039 | Rotate(dx, dy, dz, gx, gy, gz, Standard_False); | |
3040 | #else | |
c6541a0c D |
3041 | Standard_Real dx = (Standard_Real(X - sx)) * M_PI; |
3042 | Standard_Real dy = (Standard_Real(sy - Y)) * M_PI; | |
7fd59977 | 3043 | Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False); |
3044 | #endif | |
3045 | #ifdef IMP020300 | |
3046 | if( !myImmediateUpdate ) Update(); | |
3047 | #else | |
3048 | myImmediateUpdate = Standard_False; | |
3049 | Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False); | |
3050 | ZFitAll (Zmargin); //Don't do that, perf improvment | |
3051 | myImmediateUpdate = Standard_True; | |
3052 | ImmediateUpdate(); | |
3053 | #endif | |
3054 | } | |
3055 | ||
7fd59977 | 3056 | void V3d_View :: SetComputedMode ( const Standard_Boolean aMode ) |
3057 | { | |
7fd59977 | 3058 | if( aMode ) { |
3059 | if( myComputedMode ) { | |
3060 | MyView -> SetComputedMode ( Standard_True ); | |
3061 | Update (); | |
3062 | } | |
3063 | } else { | |
3064 | MyView -> SetComputedMode ( Standard_False ); | |
3065 | Update (); | |
3066 | } | |
b8ddfc2f | 3067 | } |
7fd59977 | 3068 | |
3069 | Standard_Boolean V3d_View :: ComputedMode () const | |
3070 | { | |
7fd59977 | 3071 | return MyView -> ComputedMode (); |
b8ddfc2f | 3072 | } |
7fd59977 | 3073 | |
b8ddfc2f | 3074 | void V3d_View :: SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel) |
7fd59977 | 3075 | { |
7fd59977 | 3076 | MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) ); |
3077 | Redraw(); | |
b8ddfc2f | 3078 | } |
7fd59977 | 3079 | |
b8ddfc2f | 3080 | V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const |
3081 | { | |
7fd59977 | 3082 | return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ()); |
b8ddfc2f | 3083 | } |
7fd59977 | 3084 | |
b8ddfc2f | 3085 | Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const |
3086 | { | |
7fd59977 | 3087 | return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode); |
3088 | } | |
3089 | ||
b8ddfc2f | 3090 | void V3d_View::TransientManagerClearDraw() const |
3091 | { | |
7fd59977 | 3092 | Visual3d_TransientManager::ClearDraw(MyView); |
3093 | } | |
3094 | ||
b8ddfc2f | 3095 | Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const |
3096 | { | |
7fd59977 | 3097 | return Visual3d_TransientManager::BeginAddDraw(MyView); |
3098 | } | |
3099 | ||
b8ddfc2f | 3100 | void V3d_View::Init() |
3101 | { | |
7fd59977 | 3102 | myComputedMode = MyViewer->ComputedMode(); |
7fd59977 | 3103 | if( !myComputedMode || !MyViewer->DefaultComputedMode() ) { |
3104 | SetComputedMode(Standard_False); | |
3105 | } | |
7fd59977 | 3106 | |
3107 | #ifdef IMP240100 | |
3108 | OSD_Environment env_walkthrow("CSF_WALKTHROUGH"); | |
3109 | env_walkthrow.SetName( "CSF_WALKTHROUGH" ); | |
3110 | if ( env_walkthrow.Value () != "" ) MyProjModel = V3d_TPM_WALKTHROUGH; | |
3111 | else MyProjModel = V3d_TPM_SCREEN; | |
3112 | #endif | |
7fd59977 | 3113 | } |
3114 | ||
b8ddfc2f | 3115 | void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter) |
3116 | { | |
7fd59977 | 3117 | MyPlotter = aPlotter; |
3118 | } | |
3119 | ||
3120 | void V3d_View::Plot() | |
3121 | { | |
6942f04a | 3122 | V3d_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter"); |
7fd59977 | 3123 | MyView->Plot(MyPlotter); |
3124 | } | |
3125 | ||
7fd59977 | 3126 | #include <Aspect.hxx> |
3127 | #include <Visual3d_Layer.hxx> | |
3128 | ||
3129 | //////////////////////////////////////////////////////////////// | |
692613e5 | 3130 | Standard_Boolean V3d_View::Dump (const Standard_CString theFile, |
3131 | const Graphic3d_BufferType& theBufferType) | |
7fd59977 | 3132 | { |
3133 | Standard_Integer aWinWidth, aWinHeight; | |
3134 | MyWindow->Size (aWinWidth, aWinHeight); | |
692613e5 | 3135 | Image_AlienPixMap anImage; |
3136 | return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile); | |
7fd59977 | 3137 | } |
3138 | ||
7fd59977 | 3139 | //////////////////////////////////////////////////////////////// |
692613e5 | 3140 | Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage, |
3141 | const Standard_Integer theWidth, | |
3142 | const Standard_Integer theHeight, | |
3143 | const Graphic3d_BufferType& theBufferType, | |
3144 | const Standard_Boolean theIsForceCentred) | |
7fd59977 | 3145 | { |
7fd59977 | 3146 | Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView(); |
1981cb22 | 3147 | |
3148 | // always prefer hardware accelerated offscreen buffer | |
7fd59977 | 3149 | Graphic3d_PtrFrameBuffer aFBOPtr = NULL; |
3150 | Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO; | |
85e096c3 | 3151 | Standard_Integer aFBOVPSizeX (theWidth), aFBOVPSizeY (theHeight), aFBOSizeXMax (0), aFBOSizeYMax (0); |
7fd59977 | 3152 | Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0); |
3153 | if (aPrevFBOPtr != NULL) | |
3154 | { | |
3155 | MyView->FBOGetDimensions (aPrevFBOPtr, | |
3156 | aPrevFBOVPSizeX, aPrevFBOVPSizeY, | |
3157 | aPrevFBOSizeXMax, aPrevFBOSizeYMax); | |
85e096c3 | 3158 | if (aFBOVPSizeX <= aPrevFBOSizeXMax && aFBOVPSizeY <= aPrevFBOSizeYMax) |
7fd59977 | 3159 | { |
85e096c3 | 3160 | MyView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY); |
7fd59977 | 3161 | aFBOPtr = aPrevFBOPtr; |
3162 | } | |
3163 | } | |
3164 | ||
3165 | if (aFBOPtr == NULL) | |
3166 | { | |
3167 | // Try to create hardware accelerated buffer | |
85e096c3 | 3168 | aFBOPtr = MyView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY); |
3169 | if (aFBOPtr != NULL) | |
3170 | { | |
3171 | MyView->FBOGetDimensions (aFBOPtr, | |
3172 | aFBOVPSizeX, aFBOVPSizeY, | |
3173 | aFBOSizeXMax, aFBOSizeYMax); | |
3174 | // reduce viewport in case of hardware limits | |
3175 | if (aFBOVPSizeX > aFBOSizeXMax) aFBOVPSizeX = aFBOSizeXMax; | |
3176 | if (aFBOVPSizeY > aFBOSizeYMax) aFBOVPSizeY = aFBOSizeYMax; | |
3177 | MyView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY); | |
3178 | } | |
7fd59977 | 3179 | } |
3180 | cView->ptrFBO = aFBOPtr; | |
3181 | ||
3182 | // If hardware accelerated buffer - try to use onscreen buffer | |
3183 | // Results may be bad! | |
3184 | if (aFBOPtr == NULL) | |
3185 | { | |
3186 | // retrieve window sizes | |
3187 | Standard_Integer aWinWidth, aWinHeight; | |
3188 | MyWindow->Size (aWinWidth, aWinHeight); | |
3189 | ||
3190 | // technically we can reduce existing viewport... | |
3191 | // but currently allow only dumping the window itself | |
85e096c3 | 3192 | if (aFBOVPSizeX != aWinWidth || aFBOVPSizeY != aWinHeight) |
7fd59977 | 3193 | { |
692613e5 | 3194 | return Standard_False; |
7fd59977 | 3195 | } |
3196 | } | |
3197 | ||
3198 | //szv: save mapping | |
3199 | Visual3d_ViewMapping prevMapping = MyView->ViewMapping(); | |
3200 | Standard_Real Umin, Vmin, Umax, Vmax; | |
3201 | ||
3202 | if (theIsForceCentred) | |
3203 | { | |
3204 | //szv: get mapping frame | |
3205 | Standard_Real PUmin, PVmin, PUmax, PVmax; | |
3206 | prevMapping.WindowLimit (PUmin, PVmin, PUmax, PVmax); | |
3207 | ||
3208 | //szv: calculate expansion | |
3209 | Umin = PUmin; Vmin = PVmin; Umax = PUmax; Vmax = PVmax; | |
3210 | Standard_Real oldWidth = (PUmax - PUmin), oldHeight = (PVmax - PVmin); | |
85e096c3 | 3211 | Standard_Real newWidth = (oldHeight * aFBOVPSizeX) / aFBOVPSizeY; |
7fd59977 | 3212 | if (newWidth < oldWidth) |
3213 | { | |
85e096c3 | 3214 | Standard_Real newHeight = (oldWidth * aFBOVPSizeY) / aFBOVPSizeX; |
7fd59977 | 3215 | // Expand height |
3216 | Standard_Real delta = 0.5 * (newHeight - oldHeight); | |
3217 | Vmin = PVmin - delta; | |
3218 | Vmax = PVmax + delta; | |
3219 | } | |
3220 | else | |
3221 | { | |
3222 | // Expand width | |
3223 | Standard_Real delta = 0.5 * (newWidth - oldWidth); | |
3224 | Umin = PUmin - delta; | |
3225 | Umax = PUmax + delta; | |
3226 | } | |
3227 | ||
3228 | //szv: apply expanded mapping | |
3229 | MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax); | |
3230 | MyView->SetViewMapping (MyViewMapping); | |
3231 | } | |
3232 | ||
3233 | //workround for rendering list of Over and Under Layers | |
3234 | if (!MyLayerMgr.IsNull()) | |
3235 | { | |
3236 | MyLayerMgr->Compute(); | |
3237 | } | |
1981cb22 | 3238 | |
3239 | // render immediate structures into back buffer rather than front | |
3240 | Handle(Graphic3d_GraphicDriver) aDriver = Handle(Graphic3d_GraphicDriver)::DownCast (MyView->GraphicDriver()); | |
3241 | const Standard_Boolean aPrevImmediateMode = aDriver.IsNull() ? Standard_True : aDriver->SetImmediateModeDrawToFront (*cView, Standard_False); | |
3242 | ||
7fd59977 | 3243 | Redraw(); |
3244 | ||
1981cb22 | 3245 | if (!aDriver.IsNull()) |
3246 | { | |
3247 | aDriver->SetImmediateModeDrawToFront (*cView, aPrevImmediateMode); | |
3248 | } | |
3249 | ||
7fd59977 | 3250 | //szv: restore mapping |
3251 | MyViewMapping = prevMapping; | |
3252 | MyView->SetViewMapping (prevMapping); | |
3253 | ||
692613e5 | 3254 | Standard_Boolean isSuccess = Standard_True; |
3255 | ||
7fd59977 | 3256 | // allocate image buffer for dumping |
692613e5 | 3257 | if (theImage.IsEmpty() |
3258 | || (Standard_Size )aFBOVPSizeX != theImage.SizeX() | |
3259 | || (Standard_Size )aFBOVPSizeY != theImage.SizeY()) | |
7fd59977 | 3260 | { |
692613e5 | 3261 | bool isBigEndian = Image_PixMap::IsBigEndianHost(); |
3262 | Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN; | |
3263 | switch (theBufferType) | |
3264 | { | |
3265 | case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break; | |
3266 | case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break; | |
3267 | case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break; | |
3268 | } | |
3269 | ||
3270 | isSuccess = isSuccess && theImage.InitZero (aFormat, aFBOVPSizeX, aFBOVPSizeY); | |
7fd59977 | 3271 | } |
692613e5 | 3272 | isSuccess = isSuccess && MyView->BufferDump (theImage, theBufferType); |
7fd59977 | 3273 | |
3274 | // FBO now useless, free resources | |
3275 | if (aFBOPtr != aPrevFBOPtr) | |
3276 | { | |
3277 | MyView->FBORelease (aFBOPtr); | |
3278 | } | |
3279 | else if (aPrevFBOPtr != NULL) | |
3280 | { | |
3281 | MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY); | |
3282 | } | |
3283 | cView->ptrFBO = aPrevFBOPtr; | |
692613e5 | 3284 | return isSuccess; |
7fd59977 | 3285 | } |
6942f04a | 3286 | |
3287 | void V3d_View::ImmediateUpdate() const | |
3288 | { | |
3289 | if (myImmediateUpdate) Update(); | |
3290 | } | |
3291 | ||
3292 | Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmediateUpdate) | |
3293 | { | |
3294 | Standard_Boolean aPreviousMode = myImmediateUpdate; | |
3295 | myImmediateUpdate = theImmediateUpdate; | |
3296 | return aPreviousMode; | |
3297 | } |