0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / V3d / V3d_SpotLight.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14/***********************************************************************
15
16 FONCTION :
17 ----------
18 Classe V3d_SpotLight :
19
20 HISTORIQUE DES MODIFICATIONS :
21 --------------------------------
22 00-09-92 : GG ; Creation.
23 18-06-96 : FMN ; Ajout MyGraphicStructure1 pour sauvegarder snopick
24 30-03-98 : ZOV ; PRO6774 (reconstruction of the class hierarchy and suppressing useless methods)
25 02.15.100 : JR : Clutter
26
27************************************************************************/
28
29/*----------------------------------------------------------------------*/
30/*
31 * Includes
32 */
33
34#include <V3d.hxx>
35#include <V3d_SpotLight.ixx>
36#include <Graphic3d_Vector.hxx>
37#include <Graphic3d_Vertex.hxx>
38#include <Graphic3d_Structure.hxx>
39#include <Graphic3d_Group.hxx>
b8ddfc2f 40#include <Graphic3d_ArrayOfSegments.hxx>
7fd59977 41#include <Graphic3d_AspectMarker3d.hxx>
42#include <Graphic3d_AspectLine3d.hxx>
43#include <Graphic3d_AspectText3d.hxx>
44#include <Visual3d_Light.hxx>
45#include <Visual3d_ViewManager.hxx>
46#include <Visual3d_ContextPick.hxx>
47#include <Visual3d_PickDescriptor.hxx>
48#include <Visual3d_HSequenceOfPickPath.hxx>
49#include <Visual3d_PickPath.hxx>
50#include <gp_Dir.hxx>
51#include <gp_Ax1.hxx>
52#include <gp_Vec.hxx>
53#include <gp_Pnt.hxx>
54#include <gp_Trsf.hxx>
55#include <TCollection_AsciiString.hxx>
56
7fd59977 57V3d_SpotLight::V3d_SpotLight(const Handle(V3d_Viewer)& VM, const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const V3d_TypeOfOrientation Direction, const Quantity_NameOfColor Name, const Standard_Real A1, const Standard_Real A2, const Standard_Real CN, const Standard_Real AN):V3d_PositionLight(VM) {
58
6942f04a 59 V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1
c6541a0c 60 || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle");
7fd59977 61
62 Quantity_Color C(Name) ;
63 Graphic3d_Vector D = V3d::GetProjAxis(Direction) ;
64 Graphic3d_Vertex P(X,Y,Z) ;
65 Graphic3d_Vertex T;
66
67 MyType = V3d_SPOT ;
68 MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ;
81bba717 69 // The target is fixed, starting from the light position and the direction.
7fd59977 70 T.SetCoord(X + D.X(), Y + D.Y(), Z + D.Z());
71 MyTarget = T;
72}
73
74V3d_SpotLight::V3d_SpotLight(const Handle(V3d_Viewer)& VM, const Standard_Real Xt, const Standard_Real Yt, const Standard_Real Zt, const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp, const Quantity_NameOfColor Name, const Standard_Real A1, const Standard_Real A2, const Standard_Real CN, const Standard_Real AN):V3d_PositionLight(VM) {
75
6942f04a 76 V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1
c6541a0c 77 || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle");
7fd59977 78
79 Quantity_Color C(Name) ;
80 Graphic3d_Vertex T(Xt,Yt,Zt) ;
81 Graphic3d_Vertex P(Xp,Yp,Zp) ;
82 Graphic3d_Vector D(P,T);
83
84 MyType = V3d_SPOT ;
85 D.Normalize();
86 MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ;
87 MyTarget = T;
88 // La Structure graphique sera initialisee lors de l'affichage.
89}
90
91
92//-Methods, in order
93
94void V3d_SpotLight::SetPosition(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp) {
95 MyLight->SetPosition (Graphic3d_Vertex (Xp,Yp,Zp));
96}
97
98void V3d_SpotLight::SetDirection(const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) {
99
100 Graphic3d_Vector D ;
101 D.SetCoord(Vx,Vy,Vz) ; D.Normalize() ;
102 MyLight->SetDirection(D) ;
103}
104
105void V3d_SpotLight::SetDirection(const V3d_TypeOfOrientation Direction) {
106
107 Graphic3d_Vector D = V3d::GetProjAxis(Direction) ;
108 MyLight->SetDirection(D) ;
109}
110
111void V3d_SpotLight::SetAttenuation(const Standard_Real A1, const Standard_Real A2) {
112
6942f04a 113 V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 ,
7fd59977 114 "V3d_SpotLight::SetAttenuation, bad coefficients");
115
116 MyLight->SetAttenuation1(A1) ;
117 MyLight->SetAttenuation2(A2) ;
118}
119
120void V3d_SpotLight::SetConcentration(const Standard_Real C) {
121
122
6942f04a 123 V3d_BadValue_Raise_if( C < 0 || C > 1.,
7fd59977 124 "V3d_SpotLight::SetConcentration, bad coefficient");
125
126 MyLight->SetConcentration(C) ;
127}
128
129void V3d_SpotLight::SetAngle(const Standard_Real Angle) {
130
6942f04a 131 V3d_BadValue_Raise_if( Angle <= 0. || Angle >= M_PI,
7fd59977 132 "V3d_SpotLight::SetAngle, bad angle");
133 MyLight->SetAngle(Angle) ;
134
135}
136
137void V3d_SpotLight::Direction(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz)const {
138
139 Quantity_Color C ;
140 Graphic3d_Vector D ;
141 Graphic3d_Vertex P ;
142 Standard_Real CN,A1,A2,AN ;
143
144 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
145 D.Coord(Vx,Vy,Vz) ;
146}
147
148void V3d_SpotLight::Position(Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp)const {
149
150 Quantity_Color C ;
151 Graphic3d_Vector D ;
152 Graphic3d_Vertex P ;
153 Standard_Real CN,A1,A2,AN ;
154
155 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
156 P.Coord(Xp,Yp,Zp) ;
157}
158
159void V3d_SpotLight::Attenuation(Standard_Real& A1, Standard_Real& A2) const {
160 Quantity_Color C ;
161 Graphic3d_Vector D ;
162 Graphic3d_Vertex P ;
163 Standard_Real CN,AN ;
164
165 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
166}
167
b8ddfc2f 168Standard_Real V3d_SpotLight::Concentration()const
169{
7fd59977 170 Quantity_Color C ;
171 Graphic3d_Vector D ;
172 Graphic3d_Vertex P ;
173 Standard_Real AN,A1,A2,CN ;
174
175 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
176 return CN ;
177}
178
b8ddfc2f 179Standard_Real V3d_SpotLight::Angle()const
180{
7fd59977 181 Quantity_Color C ;
182 Graphic3d_Vector D ;
183 Graphic3d_Vertex P ;
184 Standard_Real CN,A1,A2,AN ;
185
186 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
187 return AN ;
188}
189
190void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& gsymbol,
b8ddfc2f 191 const Handle(V3d_View)& ) const
192{
193 Standard_Real X,Y,Z;
7fd59977 194 Standard_Real DX,DY,DZ;
7fd59977 195 this->Position(X,Y,Z);
196 this->Direction(DX,DY,DZ);
b8ddfc2f 197
198 V3d::ArrowOfRadius(gsymbol,X,Y,Z,-DX,-DY,-DZ,M_PI/8.,this->Radius()/15.);
7fd59977 199}
200
201void V3d_SpotLight::Display( const Handle(V3d_View)& aView,
b8ddfc2f 202 const V3d_TypeOfRepresentation TPres)
203{
7fd59977 204 Graphic3d_Vertex PText ;
205 Standard_Real X,Y,Z,Rayon;
206 Standard_Real X0,Y0,Z0,VX,VY,VZ;
207 Standard_Real X1,Y1,Z1;
208 Standard_Real DXRef,DYRef,DZRef,DXini,DYini,DZini;
209 Standard_Real R1,G1,B1;
210 V3d_TypeOfRepresentation Pres;
211 V3d_TypeOfUpdate UpdSov;
212
81bba717 213// Creation of a structure slight of markable elements (position of the
214// light, and the domain of lighting represented by a circle)
215// Creation of a structure snopick of non-markable elements (target, meridian and
216// parallel).//
7fd59977 217
b8ddfc2f 218 Pres = TPres;
219 Handle(V3d_Viewer) TheViewer = aView->Viewer();
220 UpdSov = TheViewer->UpdateMode();
221 TheViewer->SetUpdateMode(V3d_WAIT);
222 if (!MyGraphicStructure.IsNull()) {
223 MyGraphicStructure->Disconnect(MyGraphicStructure1);
224 MyGraphicStructure->Clear();
225 MyGraphicStructure1->Clear();
226 if (Pres == V3d_SAMELAST) Pres = MyTypeOfRepresentation;
227 }
228 else {
229 if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE;
230 Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->Viewer());
231 MyGraphicStructure = slight;
232 Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->Viewer());
233 MyGraphicStructure1 = snopick;
234 }
235
7fd59977 236 Handle(Graphic3d_Group) gradius;
237 Handle(Graphic3d_Group) gExtArrow;
238 Handle(Graphic3d_Group) gIntArrow;
239 if (Pres == V3d_COMPLETE) {
240 gradius = new Graphic3d_Group(MyGraphicStructure);
241 gExtArrow = new Graphic3d_Group(MyGraphicStructure);
242 gIntArrow = new Graphic3d_Group(MyGraphicStructure);
243 }
244 Handle(Graphic3d_Group) glight = new Graphic3d_Group(MyGraphicStructure);
245 Handle(Graphic3d_Group) gsphere;
246 if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) gsphere = new Graphic3d_Group(MyGraphicStructure);
247
248 Handle(Graphic3d_Group) gnopick = new Graphic3d_Group(MyGraphicStructure1);
249 MyGraphicStructure1->SetPick(Standard_False);
250
251 X0 = MyTarget.X();
252 Y0 = MyTarget.Y();
253 Z0 = MyTarget.Z();
254
81bba717 255//Display of the position of the light.
7fd59977 256
7fd59977 257 this->Color(Quantity_TOC_RGB,R1,G1,B1);
258 Quantity_Color Col1(R1,G1,B1,Quantity_TOC_RGB);
259 Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d();
260 Asp1->SetColor(Col1);
261 glight->SetPrimitivesAspect(Asp1);
262 this->Symbol(glight,aView);
263
81bba717 264// Display of the reference sphere (limited by circle).
7fd59977 265
266 if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) {
267
268 Rayon = this->Radius();
269 aView->Proj(VX,VY,VZ);
7fd59977 270 V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon);
271
81bba717 272// Display of the radius of the sphere (line + text)
7fd59977 273
274 if (Pres == V3d_COMPLETE) {
7fd59977 275 this->Position(X,Y,Z);
b8ddfc2f 276 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
277 aPrims->AddVertex(X0,Y0,Z0);
278 aPrims->AddVertex(X,Y,Z);
279 gnopick->AddPrimitiveArray(aPrims);
280 V3d::ArrowOfRadius(gExtArrow,X-.1*(X-X0),Y-.1*(Y-Y0),Z-.1*(Z-Z0),X-X0,Y-Y0,Z-Z0,M_PI/15.,Rayon/20.);
281 V3d::ArrowOfRadius(gIntArrow,X0,Y0,Z0,X0-X,Y0-Y,Z0-Z,M_PI/15.,Rayon/20.);
7fd59977 282 TCollection_AsciiString ValOfRadius(Rayon);
b8ddfc2f 283 PText.SetCoord( .5*(X0+X), .5*(Y0+Y), .5*(Z0+Z) );
7fd59977 284 gradius->Text(ValOfRadius.ToCString(),PText,0.01);
285 }
286
81bba717 287// Display of the meridian
7fd59977 288
289 Quantity_Color Col2(Quantity_NOC_GREEN);
b8ddfc2f 290 Handle(Graphic3d_AspectLine3d) Asp2 = new Graphic3d_AspectLine3d(Col2,Aspect_TOL_SOLID,1.);
7fd59977 291 gnopick->SetPrimitivesAspect(Asp2);
292
81bba717 293// Definition of the axis of the circle
7fd59977 294 aView->Up(DXRef,DYRef,DZRef);
295 this->Position(X,Y,Z);
296 DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0;
297 VX = DYRef*DZini - DZRef*DYini;
298 VY = DZRef*DXini - DXRef*DZini;
299 VZ = DXRef*DYini - DYRef*DXini;
300
301 V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon);
302
81bba717 303// Display of the parallel
7fd59977 304
81bba717 305// Definition of the axis of the circle
7fd59977 306 aView->Proj(VX,VY,VZ);
307 aView->Up(X1,Y1,Z1);
308 DXRef = VY * Z1 - VZ * Y1;
309 DYRef = VZ * X1 - VX * Z1;
310 DZRef = VX * Y1 - VY * X1;
311 this->Position(X,Y,Z);
312 DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0;
313 VX = DYRef*DZini - DZRef*DYini;
314 VY = DZRef*DXini - DXRef*DZini;
315 VZ = DXRef*DYini - DYRef*DXini;
316
317 V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon);
7fd59977 318 }
319
320 MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT);
321 MyTypeOfRepresentation = Pres;
322 MyGraphicStructure->Display();
323 TheViewer->SetUpdateMode(UpdSov);
324}