1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 /***********************************************************************
18 Classe V3d_SpotLight :
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
27 ************************************************************************/
29 /*----------------------------------------------------------------------*/
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>
40 #include <Graphic3d_ArrayOfSegments.hxx>
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>
54 #include <gp_Trsf.hxx>
55 #include <TCollection_AsciiString.hxx>
57 V3d_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) {
59 V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1
60 || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle");
62 Quantity_Color C(Name) ;
63 Graphic3d_Vector D = V3d::GetProjAxis(Direction) ;
64 Graphic3d_Vertex P(X,Y,Z) ;
68 MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ;
69 // The target is fixed, starting from the light position and the direction.
70 T.SetCoord(X + D.X(), Y + D.Y(), Z + D.Z());
74 V3d_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) {
76 V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1
77 || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle");
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);
86 MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ;
88 // La Structure graphique sera initialisee lors de l'affichage.
94 void V3d_SpotLight::SetPosition(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp) {
95 MyLight->SetPosition (Graphic3d_Vertex (Xp,Yp,Zp));
98 void V3d_SpotLight::SetDirection(const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) {
101 D.SetCoord(Vx,Vy,Vz) ; D.Normalize() ;
102 MyLight->SetDirection(D) ;
105 void V3d_SpotLight::SetDirection(const V3d_TypeOfOrientation Direction) {
107 Graphic3d_Vector D = V3d::GetProjAxis(Direction) ;
108 MyLight->SetDirection(D) ;
111 void V3d_SpotLight::SetAttenuation(const Standard_Real A1, const Standard_Real A2) {
113 V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 ,
114 "V3d_SpotLight::SetAttenuation, bad coefficients");
116 MyLight->SetAttenuation1(A1) ;
117 MyLight->SetAttenuation2(A2) ;
120 void V3d_SpotLight::SetConcentration(const Standard_Real C) {
123 V3d_BadValue_Raise_if( C < 0 || C > 1.,
124 "V3d_SpotLight::SetConcentration, bad coefficient");
126 MyLight->SetConcentration(C) ;
129 void V3d_SpotLight::SetAngle(const Standard_Real Angle) {
131 V3d_BadValue_Raise_if( Angle <= 0. || Angle >= M_PI,
132 "V3d_SpotLight::SetAngle, bad angle");
133 MyLight->SetAngle(Angle) ;
137 void V3d_SpotLight::Direction(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz)const {
142 Standard_Real CN,A1,A2,AN ;
144 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
148 void V3d_SpotLight::Position(Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp)const {
153 Standard_Real CN,A1,A2,AN ;
155 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
159 void V3d_SpotLight::Attenuation(Standard_Real& A1, Standard_Real& A2) const {
163 Standard_Real CN,AN ;
165 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
168 Standard_Real V3d_SpotLight::Concentration()const
173 Standard_Real AN,A1,A2,CN ;
175 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
179 Standard_Real V3d_SpotLight::Angle()const
184 Standard_Real CN,A1,A2,AN ;
186 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
190 void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& gsymbol,
191 const Handle(V3d_View)& ) const
194 Standard_Real DX,DY,DZ;
195 this->Position(X,Y,Z);
196 this->Direction(DX,DY,DZ);
198 V3d::ArrowOfRadius(gsymbol,X,Y,Z,-DX,-DY,-DZ,M_PI/8.,this->Radius()/15.);
201 void V3d_SpotLight::Display( const Handle(V3d_View)& aView,
202 const V3d_TypeOfRepresentation TPres)
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;
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
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;
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;
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);
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);
248 Handle(Graphic3d_Group) gnopick = new Graphic3d_Group(MyGraphicStructure1);
249 MyGraphicStructure1->SetPick(Standard_False);
255 //Display of the position of the light.
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);
264 // Display of the reference sphere (limited by circle).
266 if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) {
268 Rayon = this->Radius();
269 aView->Proj(VX,VY,VZ);
270 V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon);
272 // Display of the radius of the sphere (line + text)
274 if (Pres == V3d_COMPLETE) {
275 this->Position(X,Y,Z);
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.);
282 TCollection_AsciiString ValOfRadius(Rayon);
283 PText.SetCoord( .5*(X0+X), .5*(Y0+Y), .5*(Z0+Z) );
284 gradius->Text(ValOfRadius.ToCString(),PText,0.01);
287 // Display of the meridian
289 Quantity_Color Col2(Quantity_NOC_GREEN);
290 Handle(Graphic3d_AspectLine3d) Asp2 = new Graphic3d_AspectLine3d(Col2,Aspect_TOL_SOLID,1.);
291 gnopick->SetPrimitivesAspect(Asp2);
293 // Definition of the axis of the circle
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;
301 V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon);
303 // Display of the parallel
305 // Definition of the axis of the circle
306 aView->Proj(VX,VY,VZ);
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;
317 V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon);
320 MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT);
321 MyTypeOfRepresentation = Pres;
322 MyGraphicStructure->Display();
323 TheViewer->SetUpdateMode(UpdSov);