summaryrefslogtreecommitdiff
path: root/src/Visual3d/Visual3d_ViewOrientation.cxx
blob: 24c4b72c79396f65169efe57489720058bc33c07 (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

// File		Visual3d_ViewOrientation.cxx
// Created	Fevrier 1992
// Author	NW,JPB,CAL

//-Copyright	MatraDatavision 1991,1992

//-Version	

//-Design	Declaration of variables specific to the orientation of views

//-Warning	The view orientation is defined by :
//		- the point of origin of the reference mark 
//		- the normal vector to the visualisation plane
//		- the vertical vector of the viewer

//-References	

//-Language	C++ 2.0

//-Declarations

// for the class
#include <Visual3d_ViewOrientation.ixx>

//-Aliases

//-Global data definitions

//	-- le point origine du repere
//	MyViewReferencePoint	:	Vertex;

//	-- le vecteur normal au plan de visualisation
//	MyViewPlaneNormal	:	Vector;

//	-- le vecteur vertical de l'observateur
//	MyViewUpVector		:	Vector;

//-Constructors

//-Destructors

//-Methods, in order

Visual3d_ViewOrientation::Visual3d_ViewOrientation ():
MyViewReferencePoint (0.0, 0.0, 0.0),
MyViewPlaneNormal (0.0, 0.0, 1.0),
MyViewUpVector (0.0, 1.0, 0.0),
MyScaleX(1.0),
MyScaleY(1.0),
MyScaleZ(1.0) {
}

Visual3d_ViewOrientation::Visual3d_ViewOrientation (const Graphic3d_Vertex& VRP, const Graphic3d_Vector& VPN, const Graphic3d_Vector& VUP):
MyViewReferencePoint (VRP),
MyViewPlaneNormal (VPN),
MyViewUpVector (VUP),
MyScaleX(1.0),
MyScaleY(1.0),
MyScaleZ(1.0) {

	if (Graphic3d_Vector::NormeOf (VPN) == 0.0)
		Visual3d_ViewOrientationDefinitionError::Raise
			("Bad value for ViewPlaneNormal");

	if (Graphic3d_Vector::NormeOf (VUP) == 0.0)
		Visual3d_ViewOrientationDefinitionError::Raise
			("Bad value for ViewUpVector");

	if (Graphic3d_Vector::IsParallel (VPN, VUP))
		Visual3d_ViewOrientationDefinitionError::Raise
			("ViewPlaneNormal and ViewUpVector are parallel");

}

Visual3d_ViewOrientation::Visual3d_ViewOrientation (const Graphic3d_Vertex& VRP, const Graphic3d_Vector& VPN, const Standard_Real Twist) {

	if (Graphic3d_Vector::NormeOf (VPN) == 0.0)
		Visual3d_ViewOrientationDefinitionError::Raise
			("Bad value for ViewPlaneNormal");

	cout << "\nVisual3d_ViewOrientation : Not Yet Implemented\n\n" << flush;

	MyViewReferencePoint	= VRP;
	MyViewPlaneNormal	= VPN;

}

Visual3d_ViewOrientation::Visual3d_ViewOrientation (const Graphic3d_Vertex& VRP, const Standard_Real Azim, const Standard_Real Inc, const Standard_Real Twist) {

	cout << "\nVisual3d_ViewOrientation : Not Yet Implemented\n\n" << flush;

	MyViewReferencePoint	= VRP;

}

void Visual3d_ViewOrientation::SetViewReferencePoint (const Graphic3d_Vertex& VRP) {

	MyViewReferencePoint	= VRP;

}

Graphic3d_Vertex Visual3d_ViewOrientation::ViewReferencePoint () const {

	return (MyViewReferencePoint);

}

void Visual3d_ViewOrientation::SetViewReferencePlane (const Graphic3d_Vector& VPN) {

	if (Graphic3d_Vector::NormeOf (VPN) == 0.0)
		Visual3d_ViewOrientationDefinitionError::Raise
			("Bad value for ViewPlaneNormal");

	MyViewPlaneNormal	= VPN;

}

Graphic3d_Vector Visual3d_ViewOrientation::ViewReferencePlane () const {

	return (MyViewPlaneNormal);

}

void Visual3d_ViewOrientation::SetViewReferenceUp (const Graphic3d_Vector& VUP) {

	if (Graphic3d_Vector::NormeOf (VUP) == 0.0)
		Visual3d_ViewOrientationDefinitionError::Raise
			("Bad value for ViewUpVector");

	MyViewUpVector		= VUP;

}

void Visual3d_ViewOrientation::SetAxialScale (const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz) {
  if ( Sx <= 0. || Sy <= 0. || Sz <= 0. )
    Visual3d_ViewOrientationDefinitionError::Raise
      ("Bad value for ViewUpVector");
	MyScaleX = Sx;
	MyScaleY = Sy;
	MyScaleZ = Sz;
}

Graphic3d_Vector Visual3d_ViewOrientation::ViewReferenceUp () const {

	return (MyViewUpVector);

}

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

Standard_Real X, Y, Z;

	(Other.ViewReferencePoint ()).Coord (X, Y, Z);
	MyViewReferencePoint.SetCoord (X, Y, Z);

	(Other.ViewReferencePlane ()).Coord (X, Y, Z);
	MyViewPlaneNormal.SetCoord (X, Y, Z);

	(Other.ViewReferenceUp ()).Coord (X, Y, Z);
	MyViewUpVector.SetCoord (X, Y, Z);

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

Standard_Real Visual3d_ViewOrientation::Twist () const {

cout << "\nVisual3d_ViewOrientation::Twist : Not Yet Implemented\n\n" << flush;

#ifdef OK
Standard_Real Xrp, Yrp, Zrp;
Standard_Real Xpn, Ypn, Zpn;
Standard_Real Xup, Yup, Zup;
Standard_Real a1, b1, c1, a2, b2, c2;
Standard_Real pvx, pvy, pvz;
Standard_Real an1, an2;
Standard_Real pvn, sca, angle;

	MyViewReferencePoint.Coord (Xrp, Yrp, Zrp) ;	
	MyViewPlaneNormal.Coord (Xpn, Ypn, Zpn) ;	
	MyViewUpVector.Coord (Xup, Yup, Zup) ;	

	Xrp -= Xpn ; Yrp -= Ypn ; Zrp -= Zpn ;
	Xup -= Xpn ; Yup -= Ypn ; Zup -= Zpn ;
				/* Compute Plane Normal EYE, AT, UP */
	a1 = Yrp*Zup - Yup*Zrp ;
	b1 = Zrp*Xup - Zup*Xrp ;
	c1 = Xrp*Yup - Xup*Yrp ;
				/* Compute Plane Normal EYE, AT, YAXIS */
	a2 = -Zrp ;
	b2 = 0. ;
	c2 = Xrp ;
				/* Compute Cross Vector from 2 last Normals */
	pvx = b1*c2 - c1*b2 ;
	pvy = c1*a2 - a1*c2 ;
	pvz = a1*b2 - b1*a2 ;
				/* Normalize vectors */
	an1 = a1*a1 + b1*b1 + c1*c1 ;
	an2 = a2*a2 + b2*b2 + c2*c2 ;
	pvn = pvx*pvx + pvy*pvy + pvz*pvz ;
				/* Compute Angle */
	if (angle > 1.) angle = 1. ;
	else if ( angle < -1. ) angle = -1. ;
	angle = asin (angle)/Standard_PI180 ;
	sca = a1*a2 + b1*b2 + c1*c2 ;
	if (sca < 0.) angle = 180. - angle ;
	if ( (angle > 0.) && (angle < 180.) ) {
        sca = - (pvx*Xrp + pvy*Yrp + pvz*Zrp) ;
        if (sca > 0.) angle = 360. - angle ;
	}

	return (angle*Standard_PI/180.0);
#else
	return (Standard_PI/180.0);
#endif

}

void Visual3d_ViewOrientation::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz)const  {
  Sx = MyScaleX;
  Sy = MyScaleY;
  Sz = MyScaleZ;
}


void Visual3d_ViewOrientation::SetCustomModelViewMatrix(const Handle(TColStd_HArray2OfReal)& Mat)
{
  MyModelViewMatrix = Mat;
}

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