0024552: Convertation of the generic classes to the non-generic (BndLib).
[occt.git] / src / Visual3d / Visual3d_ViewMapping.cxx
CommitLineData
b311480e 1// Created by: NW,JPB,CAL
2// Copyright (c) 1991-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// Modified
7fd59977 17// 22-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
18// 23-07-07 : NKV ; Define custom PROJECTION matrix for OpenGl context
19
7fd59977 20
21//-Version
22
81bba717 23//-Design Declaration of variables specific to mapping of views
7fd59977 24
81bba717 25//-Warning Mapping of a view is defined by :
26// - reference point of projection
27// - type of projection
28// - distance for the Back Plane
29// - distance for the Front Plane
30// - distance for the Projection Plane
7fd59977 31
32//-References
33
34//-Language C++ 2.0
35
36//-Declarations
37
38// for the class
39#include <Visual3d_ViewMapping.ixx>
40#include <Precision.hxx>
41
42// Perspective
43#include <OSD_Environment.hxx>
7fd59977 44static OSD_Environment env_walkthrow;
45
46static Standard_Boolean Visual3dWalkthrow()
47{
48 static Standard_Integer isWalkthrow( -1 );
49 if ( isWalkthrow < 0 ) {
50 isWalkthrow = 1;
51 OSD_Environment WalkThrow("CSF_WALKTHROUGH");
52 if ( WalkThrow.Value().IsEmpty() )
53 isWalkthrow = 0;
54 }
55 return ( isWalkthrow != 0 );
56}
57
58
59//-Aliases
60
61//-Global data definitions
62
63// -- le point reference de projection
64// MyReferencePoint : Vertex;
65
66// -- le type de projection
67// MyProjectionType : TypeOfProjection;
68
69// -- la distance pour le Back Plane
70// MyBackPlaneDistance : Standard_Real;
71
72// -- la distance pour le Front Plane
73// MyFrontPlaneDistance : Standard_Real;
74
75// -- la distance pour le Projection Plane
76// MyViewPlaneDistance : Standard_Real;
77
78// -- les limites de la partie visible du plan
79// -- MyWindowLimits[0] = u du coin inferieur gauche.
80// -- MyWindowLimits[1] = v du coin inferieur gauche.
81// -- MyWindowLimits[2] = u du coin superieur droit.
82// -- MyWindowLimits[3] = v du coin superieur droit.
83// MyWindowLimits : Standard_Real[4];
84
85//-Constructors
86
87//-Destructors
88
89//-Methods, in order
90
91Visual3d_ViewMapping::Visual3d_ViewMapping ():
92MyReferencePoint (0.5, 0.5, 2.0),
93MyProjectionType (Visual3d_TOP_PARALLEL) {
94 if ( Visual3dWalkthrow() )
95 {
96 MyBackPlaneDistance = -1.0;
97 MyFrontPlaneDistance = 1.0;
98 MyViewPlaneDistance = 0.0;
99 }
100 else
101 {
102 MyBackPlaneDistance = 0.0;
103 MyFrontPlaneDistance = 1.0;
104 MyViewPlaneDistance = 1.0;
105 }
106
107 MyWindowLimits[0] = 0.0;
108 MyWindowLimits[1] = 0.0;
109 MyWindowLimits[2] = 1.0;
110 MyWindowLimits[3] = 1.0;
111
112}
113
114Visual3d_ViewMapping::Visual3d_ViewMapping (const Visual3d_TypeOfProjection AType, const Graphic3d_Vertex& PRP, const Standard_Real BPD, const Standard_Real FPD, const Standard_Real VPD, const Standard_Real WUmin, const Standard_Real WVmin, const Standard_Real WUmax, const Standard_Real WVmax):
115MyReferencePoint (PRP),
116MyProjectionType (AType),
117MyBackPlaneDistance (BPD),
118MyFrontPlaneDistance (FPD),
119MyViewPlaneDistance (VPD) {
120
121 if ( (WUmin >= WUmax) || (WVmin >= WVmax) )
122 Visual3d_ViewMappingDefinitionError::Raise
123 ("Invalid window; WUmin > WUmax or WVmin > WVmax");
124
125 if (BPD > FPD)
126 Visual3d_ViewMappingDefinitionError::Raise
127 ("The back plane is in front of the front plane");
128
129/*
130 A TESTER AVEC LE VRP ?
131 Visual3d_ViewMappingDefinitionError::Raise
132 ("The projection reference point is between the front and back planes");
133
134 if (PRP.Z () == VPD)
135 Visual3d_ViewMappingDefinitionError::Raise
136("The projection reference point cannot be positioned on the view plane");
137*/
138
139 MyWindowLimits[0] = WUmin;
140 MyWindowLimits[1] = WVmin;
141 MyWindowLimits[2] = WUmax;
142 MyWindowLimits[3] = WVmax;
143
144}
145
146void Visual3d_ViewMapping::SetProjection (const Visual3d_TypeOfProjection AType) {
147
148 MyProjectionType = AType;
149
150}
151
152Visual3d_TypeOfProjection Visual3d_ViewMapping::Projection () const {
153
154 return (MyProjectionType);
155
156}
157
158void Visual3d_ViewMapping::SetProjectionReferencePoint (const Graphic3d_Vertex& PRP) {
159
160/*
161Standard_Real VPD, BPD, FPD;
162
163 VPD = MyViewPlaneDistance;
164 BPD = MyBackPlaneDistance;
165 FPD = MyFrontPlaneDistance;
166
167 A TESTER AVEC LE VRP ?
168 Visual3d_ViewMappingDefinitionError::Raise
169 ("The projection reference point is between the front and back planes");
170
171 if (PRP.Z () == VPD)
172 Visual3d_ViewMappingDefinitionError::Raise
173("The projection reference point cannot be positioned on the view plane");
174*/
175
176 MyReferencePoint = PRP;
177
178}
179
180Graphic3d_Vertex Visual3d_ViewMapping::ProjectionReferencePoint () const {
181
182 return (MyReferencePoint);
183
184}
185
186void Visual3d_ViewMapping::SetViewPlaneDistance (const Standard_Real VPD) {
187
188/*
189Standard_Real PRPZ, BPD, FPD;
190
191 PRPZ = MyReferencePoint.Z ();
192 BPD = MyBackPlaneDistance;
193 FPD = MyFrontPlaneDistance;
194
195 A TESTER AVEC LE VRP ?
196 Visual3d_ViewMappingDefinitionError::Raise
197 ("The projection reference point is between the front and back planes");
198
199 if (PRPZ == VPD)
200 Visual3d_ViewMappingDefinitionError::Raise
201("The projection reference point cannot be positioned on the view plane");
202*/
203
204 MyViewPlaneDistance = VPD;
205
206}
207
208Standard_Real Visual3d_ViewMapping::ViewPlaneDistance () const {
209
210 return (MyViewPlaneDistance);
211
212}
213
214void Visual3d_ViewMapping::SetBackPlaneDistance (const Standard_Real BPD) {
215
216/*
217Standard_Real VPD, PRPZ, FPD;
218
219 PRPZ = MyReferencePoint.Z ();
220 VPD = MyViewPlaneDistance;
221 FPD = MyFrontPlaneDistance;
222
223 if (BPD > FPD)
224 Visual3d_ViewMappingDefinitionError::Raise
225 ("The back plane is in front of the front plane");
226
227 A TESTER AVEC LE VRP ?
228 Visual3d_ViewMappingDefinitionError::Raise
229 ("The projection reference point is between the front and back planes");
230*/
231
232 MyBackPlaneDistance = BPD;
233}
234
235Standard_Real Visual3d_ViewMapping::BackPlaneDistance () const {
236
237 return (MyBackPlaneDistance);
238}
239
240void Visual3d_ViewMapping::SetFrontPlaneDistance (const Standard_Real FPD) {
241
242/*
243Standard_Real VPD, BPD, PRPZ;
244
245 PRPZ = MyReferencePoint.Z ();
246 VPD = MyViewPlaneDistance;
247 BPD = MyBackPlaneDistance;
248
249 if (BPD > FPD)
250 Visual3d_ViewMappingDefinitionError::Raise
251 ("The back plane is in front of the front plane");
252
253 A TESTER AVEC LE VRP ?
254 Visual3d_ViewMappingDefinitionError::Raise
255 ("The projection reference point is between the front and back planes");
256*/
257
258 MyFrontPlaneDistance = FPD;
259
260}
261
262Standard_Real Visual3d_ViewMapping::FrontPlaneDistance () const {
263
264 return (MyFrontPlaneDistance);
265
266}
267
268void Visual3d_ViewMapping::SetWindowLimit (const Standard_Real Umin, const Standard_Real Vmin, const Standard_Real Umax, const Standard_Real Vmax) {
269
270 if ( (Umin >= Umax) || (Vmin >= Vmax) )
271 Visual3d_ViewMappingDefinitionError::Raise
272 ("Invalid window; WUmin > WUmax or WVmin > WVmax");
273
274 if( (Umax - Umin) < Precision::Confusion() || (Vmax - Vmin) < Precision::Confusion())
275 Visual3d_ViewMappingDefinitionError::Raise
276 ("Window is too small");
277
278 MyWindowLimits[0] = Umin;
279 MyWindowLimits[1] = Vmin;
280 MyWindowLimits[2] = Umax;
281 MyWindowLimits[3] = Vmax;
282
283}
284
285void Visual3d_ViewMapping::WindowLimit (Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const {
286
287 Umin = MyWindowLimits[0];
288 Vmin = MyWindowLimits[1];
289 Umax = MyWindowLimits[2];
290 Vmax = MyWindowLimits[3];
291
292}
293
294void Visual3d_ViewMapping::SetCustomProjectionMatrix(const Handle(TColStd_HArray2OfReal)& Mat)
295{
296 MyProjectionMatrix = Mat;
297}
298
299Standard_Boolean Visual3d_ViewMapping::IsCustomMatrix() const
300{
301 return !MyProjectionMatrix.IsNull()
302 && MyProjectionMatrix->LowerRow() == 0
303 && MyProjectionMatrix->LowerCol() == 0
304 && MyProjectionMatrix->UpperRow() == 3
305 && MyProjectionMatrix->UpperCol() == 3;
306}
307
308
309void Visual3d_ViewMapping::Assign (const Visual3d_ViewMapping& Other) {
310
311Standard_Real X, Y, Z;
312
313 (Other.ProjectionReferencePoint ()).Coord (X, Y, Z);
314 MyReferencePoint.SetCoord (X, Y, Z);
315
316 MyProjectionType = Other.Projection ();
317
318 MyBackPlaneDistance = Other.BackPlaneDistance ();
319
320 MyFrontPlaneDistance = Other.FrontPlaneDistance ();
321
322 MyViewPlaneDistance = Other.ViewPlaneDistance ();
323
324 Other.WindowLimit (MyWindowLimits[0], MyWindowLimits[1],
325 MyWindowLimits[2], MyWindowLimits[3]);
326
327 if ( Other.IsCustomMatrix() ) {
328 MyProjectionMatrix = new TColStd_HArray2OfReal( 0, 3, 0, 3 );
329 for (Standard_Integer i = 0; i < 4; i++)
330 for (Standard_Integer j = 0; j < 4; j++)
331 MyProjectionMatrix->SetValue( i, j, Other.MyProjectionMatrix->Value(i, j) );
332 }
333 else
334 MyProjectionMatrix.Nullify();
335}