summaryrefslogtreecommitdiff
path: root/src/Visual3d/Visual3d_ViewMapping.cxx
blob: a3f8b5b753b8cb95a9a3c7ef74d7047bed0c221d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// File		Visual3d_ViewMapping.cxx
// Created	Fevrier 1992
// Author	NW,JPB,CAL
// Modified	
//    22-12-98  : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
//    23-07-07  : NKV ; Define custom PROJECTION matrix for OpenGl context

//-Copyright	MatraDatavision 1991,1992

//-Version	

//-Design	Declaration of variables specific to mapping of views

//-Warning	Mapping of a view is defined by :
//		- reference point of projection
//		- type of projection
//		- distance for the Back Plane
//		- distance for the Front Plane
//		- distance for the Projection Plane

//-References	

//-Language	C++ 2.0

//-Declarations

// for the class
#include <Visual3d_ViewMapping.ixx>
#include <Precision.hxx>

// Perspective
#include <OSD_Environment.hxx>
static OSD_Environment env_walkthrow; 

static Standard_Boolean Visual3dWalkthrow()
{
  static Standard_Integer isWalkthrow( -1 );
  if ( isWalkthrow < 0 ) {
    isWalkthrow = 1;
    OSD_Environment WalkThrow("CSF_WALKTHROUGH");
    if ( WalkThrow.Value().IsEmpty() )
      isWalkthrow = 0;
  }                       
  return ( isWalkthrow != 0 );
}


//-Aliases

//-Global data definitions

//	-- le point reference de projection
//	MyReferencePoint		:	Vertex;

//	-- le type de projection
//	MyProjectionType		:	TypeOfProjection;

//	-- la distance pour le Back Plane
//	MyBackPlaneDistance		:	Standard_Real;

//	-- la distance pour le Front Plane
//	MyFrontPlaneDistance		:	Standard_Real;

//	-- la distance pour le Projection Plane
//	MyViewPlaneDistance		:	Standard_Real;

//	-- les limites de la partie visible du plan
//	-- MyWindowLimits[0] = u du coin inferieur gauche.
//	-- MyWindowLimits[1] = v du coin inferieur gauche.
//	-- MyWindowLimits[2] = u du coin superieur droit.
//	-- MyWindowLimits[3] = v du coin superieur droit.
//	MyWindowLimits			:	Standard_Real[4];

//-Constructors

//-Destructors

//-Methods, in order

Visual3d_ViewMapping::Visual3d_ViewMapping ():
MyReferencePoint (0.5, 0.5, 2.0),
MyProjectionType (Visual3d_TOP_PARALLEL) {
     	if ( Visual3dWalkthrow() )
	{
	    MyBackPlaneDistance  = -1.0;
	    MyFrontPlaneDistance = 1.0;
	    MyViewPlaneDistance  = 0.0;
	}
	else
	{
	    MyBackPlaneDistance  = 0.0;
	    MyFrontPlaneDistance = 1.0;
	    MyViewPlaneDistance  = 1.0;
	}

	MyWindowLimits[0]	= 0.0;
	MyWindowLimits[1]	= 0.0;
	MyWindowLimits[2]	= 1.0;
	MyWindowLimits[3]	= 1.0;

}

Visual3d_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):
MyReferencePoint (PRP),
MyProjectionType (AType),
MyBackPlaneDistance (BPD),
MyFrontPlaneDistance (FPD),
MyViewPlaneDistance (VPD) {

	if ( (WUmin >= WUmax) || (WVmin >= WVmax) )
		Visual3d_ViewMappingDefinitionError::Raise
			("Invalid window; WUmin > WUmax or WVmin > WVmax");

	if (BPD > FPD)
		Visual3d_ViewMappingDefinitionError::Raise
			("The back plane is in front of the front plane");

/*
	A TESTER AVEC LE VRP ?
		Visual3d_ViewMappingDefinitionError::Raise
	("The projection reference point is between the front and back planes");

	if (PRP.Z () == VPD)
		Visual3d_ViewMappingDefinitionError::Raise
("The projection reference point cannot be positioned on the view plane");
*/

	MyWindowLimits[0]	= WUmin;
	MyWindowLimits[1]	= WVmin;
	MyWindowLimits[2]	= WUmax;
	MyWindowLimits[3]	= WVmax;

}

void Visual3d_ViewMapping::SetProjection (const Visual3d_TypeOfProjection AType) {

	MyProjectionType	= AType;

}

Visual3d_TypeOfProjection Visual3d_ViewMapping::Projection () const {

	return (MyProjectionType);

}

void Visual3d_ViewMapping::SetProjectionReferencePoint (const Graphic3d_Vertex& PRP) {

/*
Standard_Real VPD, BPD, FPD;

	VPD	= MyViewPlaneDistance;
	BPD	= MyBackPlaneDistance;
	FPD	= MyFrontPlaneDistance;

	A TESTER AVEC LE VRP ?
		Visual3d_ViewMappingDefinitionError::Raise
	("The projection reference point is between the front and back planes");

	if (PRP.Z () == VPD)
		Visual3d_ViewMappingDefinitionError::Raise
("The projection reference point cannot be positioned on the view plane");
*/

	MyReferencePoint	= PRP;

}

Graphic3d_Vertex Visual3d_ViewMapping::ProjectionReferencePoint () const {

	return (MyReferencePoint);

}

void Visual3d_ViewMapping::SetViewPlaneDistance (const Standard_Real VPD) {

/*
Standard_Real PRPZ, BPD, FPD;

	PRPZ	= MyReferencePoint.Z ();
	BPD	= MyBackPlaneDistance;
	FPD	= MyFrontPlaneDistance;

	A TESTER AVEC LE VRP ?
		Visual3d_ViewMappingDefinitionError::Raise
	("The projection reference point is between the front and back planes");

	if (PRPZ == VPD)
		Visual3d_ViewMappingDefinitionError::Raise
("The projection reference point cannot be positioned on the view plane");
*/

	MyViewPlaneDistance	= VPD;

}

Standard_Real Visual3d_ViewMapping::ViewPlaneDistance () const {

	return (MyViewPlaneDistance);

}

void Visual3d_ViewMapping::SetBackPlaneDistance (const Standard_Real BPD) {

/*
Standard_Real VPD, PRPZ, FPD;

	PRPZ	= MyReferencePoint.Z ();
	VPD	= MyViewPlaneDistance;
	FPD	= MyFrontPlaneDistance;

	if (BPD > FPD)
		Visual3d_ViewMappingDefinitionError::Raise
			("The back plane is in front of the front plane");

	A TESTER AVEC LE VRP ?
		Visual3d_ViewMappingDefinitionError::Raise
	("The projection reference point is between the front and back planes");
*/

	MyBackPlaneDistance	= BPD;
}

Standard_Real Visual3d_ViewMapping::BackPlaneDistance () const {

	return (MyBackPlaneDistance);
}

void Visual3d_ViewMapping::SetFrontPlaneDistance (const Standard_Real FPD) {

/*
Standard_Real VPD, BPD, PRPZ;

	PRPZ	= MyReferencePoint.Z ();
	VPD	= MyViewPlaneDistance;
	BPD	= MyBackPlaneDistance;

	if (BPD > FPD)
		Visual3d_ViewMappingDefinitionError::Raise
			("The back plane is in front of the front plane");

	A TESTER AVEC LE VRP ?
		Visual3d_ViewMappingDefinitionError::Raise
	("The projection reference point is between the front and back planes");
*/

	MyFrontPlaneDistance	= FPD;

}

Standard_Real Visual3d_ViewMapping::FrontPlaneDistance () const {

	return (MyFrontPlaneDistance);

}

void Visual3d_ViewMapping::SetWindowLimit (const Standard_Real Umin, const Standard_Real Vmin, const Standard_Real Umax, const Standard_Real Vmax) {

	if ( (Umin >= Umax) || (Vmin >= Vmax) )
		Visual3d_ViewMappingDefinitionError::Raise
			("Invalid window; WUmin > WUmax or WVmin > WVmax");

	if( (Umax - Umin) < Precision::Confusion() || (Vmax - Vmin) < Precision::Confusion())
		Visual3d_ViewMappingDefinitionError::Raise
			("Window is too small");

	MyWindowLimits[0]	= Umin;
	MyWindowLimits[1]	= Vmin;
	MyWindowLimits[2]	= Umax;
	MyWindowLimits[3]	= Vmax;

}

void Visual3d_ViewMapping::WindowLimit (Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const {

	Umin	= MyWindowLimits[0];
	Vmin	= MyWindowLimits[1];
	Umax	= MyWindowLimits[2];
	Vmax	= MyWindowLimits[3];

}

void Visual3d_ViewMapping::SetCustomProjectionMatrix(const Handle(TColStd_HArray2OfReal)& Mat)
{
  MyProjectionMatrix = Mat;
}

Standard_Boolean Visual3d_ViewMapping::IsCustomMatrix() const
{
  return !MyProjectionMatrix.IsNull() 
      && MyProjectionMatrix->LowerRow() == 0
      && MyProjectionMatrix->LowerCol() == 0
      && MyProjectionMatrix->UpperRow() == 3
      && MyProjectionMatrix->UpperCol() == 3;
}


void Visual3d_ViewMapping::Assign (const Visual3d_ViewMapping& Other) {

Standard_Real X, Y, Z;

	(Other.ProjectionReferencePoint ()).Coord (X, Y, Z);
	MyReferencePoint.SetCoord (X, Y, Z);

	MyProjectionType	= Other.Projection ();

	MyBackPlaneDistance	= Other.BackPlaneDistance ();

	MyFrontPlaneDistance	= Other.FrontPlaneDistance ();

	MyViewPlaneDistance	= Other.ViewPlaneDistance ();

	Other.WindowLimit (MyWindowLimits[0], MyWindowLimits[1],
			    MyWindowLimits[2], MyWindowLimits[3]);

        if ( Other.IsCustomMatrix() ) {
          MyProjectionMatrix = new TColStd_HArray2OfReal( 0, 3, 0, 3 );
	  for (Standard_Integer i = 0; i < 4; i++)
	    for (Standard_Integer j = 0; j < 4; j++)
	      MyProjectionMatrix->SetValue( i, j, Other.MyProjectionMatrix->Value(i, j) );
	}
        else
	  MyProjectionMatrix.Nullify();
}