1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 /***********************************************************************
22 Classe V3d_SpotLight :
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 00-09-92 : GG ; Creation.
27 18-06-96 : FMN ; Ajout MyGraphicStructure1 pour sauvegarder snopick
28 30-03-98 : ZOV ; PRO6774 (reconstruction of the class hierarchy and suppressing useless methods)
29 02.15.100 : JR : Clutter
31 ************************************************************************/
33 /*----------------------------------------------------------------------*/
39 #include <V3d_SpotLight.ixx>
40 #include <Graphic3d_Vector.hxx>
41 #include <Graphic3d_Vertex.hxx>
42 #include <Graphic3d_Structure.hxx>
43 #include <Graphic3d_Group.hxx>
44 #include <Graphic3d_ArrayOfSegments.hxx>
45 #include <Graphic3d_AspectMarker3d.hxx>
46 #include <Graphic3d_AspectLine3d.hxx>
47 #include <Graphic3d_AspectText3d.hxx>
48 #include <Visual3d_Light.hxx>
49 #include <Visual3d_ViewManager.hxx>
50 #include <Visual3d_ContextPick.hxx>
51 #include <Visual3d_PickDescriptor.hxx>
52 #include <Visual3d_HSequenceOfPickPath.hxx>
53 #include <Visual3d_PickPath.hxx>
58 #include <gp_Trsf.hxx>
59 #include <TCollection_AsciiString.hxx>
61 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) {
63 V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1
64 || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle");
66 Quantity_Color C(Name) ;
67 Graphic3d_Vector D = V3d::GetProjAxis(Direction) ;
68 Graphic3d_Vertex P(X,Y,Z) ;
72 MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ;
73 // The target is fixed, starting from the light position and the direction.
74 T.SetCoord(X + D.X(), Y + D.Y(), Z + D.Z());
78 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) {
80 V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1
81 || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle");
83 Quantity_Color C(Name) ;
84 Graphic3d_Vertex T(Xt,Yt,Zt) ;
85 Graphic3d_Vertex P(Xp,Yp,Zp) ;
86 Graphic3d_Vector D(P,T);
90 MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ;
92 // La Structure graphique sera initialisee lors de l'affichage.
98 void V3d_SpotLight::SetPosition(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp) {
99 MyLight->SetPosition (Graphic3d_Vertex (Xp,Yp,Zp));
102 void V3d_SpotLight::SetDirection(const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) {
105 D.SetCoord(Vx,Vy,Vz) ; D.Normalize() ;
106 MyLight->SetDirection(D) ;
109 void V3d_SpotLight::SetDirection(const V3d_TypeOfOrientation Direction) {
111 Graphic3d_Vector D = V3d::GetProjAxis(Direction) ;
112 MyLight->SetDirection(D) ;
115 void V3d_SpotLight::SetAttenuation(const Standard_Real A1, const Standard_Real A2) {
117 V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 ,
118 "V3d_SpotLight::SetAttenuation, bad coefficients");
120 MyLight->SetAttenuation1(A1) ;
121 MyLight->SetAttenuation2(A2) ;
124 void V3d_SpotLight::SetConcentration(const Standard_Real C) {
127 V3d_BadValue_Raise_if( C < 0 || C > 1.,
128 "V3d_SpotLight::SetConcentration, bad coefficient");
130 MyLight->SetConcentration(C) ;
133 void V3d_SpotLight::SetAngle(const Standard_Real Angle) {
135 V3d_BadValue_Raise_if( Angle <= 0. || Angle >= M_PI,
136 "V3d_SpotLight::SetAngle, bad angle");
137 MyLight->SetAngle(Angle) ;
141 void V3d_SpotLight::Direction(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz)const {
146 Standard_Real CN,A1,A2,AN ;
148 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
152 void V3d_SpotLight::Position(Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp)const {
157 Standard_Real CN,A1,A2,AN ;
159 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
163 void V3d_SpotLight::Attenuation(Standard_Real& A1, Standard_Real& A2) const {
167 Standard_Real CN,AN ;
169 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
172 Standard_Real V3d_SpotLight::Concentration()const
177 Standard_Real AN,A1,A2,CN ;
179 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
183 Standard_Real V3d_SpotLight::Angle()const
188 Standard_Real CN,A1,A2,AN ;
190 MyLight->Values(C,P,D,CN,A1,A2,AN) ;
194 void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& gsymbol,
195 const Handle(V3d_View)& ) const
198 Standard_Real DX,DY,DZ;
199 this->Position(X,Y,Z);
200 this->Direction(DX,DY,DZ);
202 V3d::ArrowOfRadius(gsymbol,X,Y,Z,-DX,-DY,-DZ,M_PI/8.,this->Radius()/15.);
205 void V3d_SpotLight::Display( const Handle(V3d_View)& aView,
206 const V3d_TypeOfRepresentation TPres)
208 Graphic3d_Vertex PText ;
209 Standard_Real X,Y,Z,Rayon;
210 Standard_Real X0,Y0,Z0,VX,VY,VZ;
211 Standard_Real X1,Y1,Z1;
212 Standard_Real DXRef,DYRef,DZRef,DXini,DYini,DZini;
213 Standard_Real R1,G1,B1;
214 V3d_TypeOfRepresentation Pres;
215 V3d_TypeOfUpdate UpdSov;
217 // Creation of a structure slight of markable elements (position of the
218 // light, and the domain of lighting represented by a circle)
219 // Creation of a structure snopick of non-markable elements (target, meridian and
223 Handle(V3d_Viewer) TheViewer = aView->Viewer();
224 UpdSov = TheViewer->UpdateMode();
225 TheViewer->SetUpdateMode(V3d_WAIT);
226 if (!MyGraphicStructure.IsNull()) {
227 MyGraphicStructure->Disconnect(MyGraphicStructure1);
228 MyGraphicStructure->Clear();
229 MyGraphicStructure1->Clear();
230 if (Pres == V3d_SAMELAST) Pres = MyTypeOfRepresentation;
233 if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE;
234 Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->Viewer());
235 MyGraphicStructure = slight;
236 Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->Viewer());
237 MyGraphicStructure1 = snopick;
240 Handle(Graphic3d_Group) gradius;
241 Handle(Graphic3d_Group) gExtArrow;
242 Handle(Graphic3d_Group) gIntArrow;
243 if (Pres == V3d_COMPLETE) {
244 gradius = new Graphic3d_Group(MyGraphicStructure);
245 gExtArrow = new Graphic3d_Group(MyGraphicStructure);
246 gIntArrow = new Graphic3d_Group(MyGraphicStructure);
248 Handle(Graphic3d_Group) glight = new Graphic3d_Group(MyGraphicStructure);
249 Handle(Graphic3d_Group) gsphere;
250 if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) gsphere = new Graphic3d_Group(MyGraphicStructure);
252 Handle(Graphic3d_Group) gnopick = new Graphic3d_Group(MyGraphicStructure1);
253 MyGraphicStructure1->SetPick(Standard_False);
259 //Display of the position of the light.
261 this->Color(Quantity_TOC_RGB,R1,G1,B1);
262 Quantity_Color Col1(R1,G1,B1,Quantity_TOC_RGB);
263 Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d();
264 Asp1->SetColor(Col1);
265 glight->SetPrimitivesAspect(Asp1);
266 this->Symbol(glight,aView);
268 // Display of the reference sphere (limited by circle).
270 if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) {
272 Rayon = this->Radius();
273 aView->Proj(VX,VY,VZ);
274 V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon);
276 // Display of the radius of the sphere (line + text)
278 if (Pres == V3d_COMPLETE) {
279 this->Position(X,Y,Z);
280 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
281 aPrims->AddVertex(X0,Y0,Z0);
282 aPrims->AddVertex(X,Y,Z);
283 gnopick->AddPrimitiveArray(aPrims);
284 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.);
285 V3d::ArrowOfRadius(gIntArrow,X0,Y0,Z0,X0-X,Y0-Y,Z0-Z,M_PI/15.,Rayon/20.);
286 TCollection_AsciiString ValOfRadius(Rayon);
287 PText.SetCoord( .5*(X0+X), .5*(Y0+Y), .5*(Z0+Z) );
288 gradius->Text(ValOfRadius.ToCString(),PText,0.01);
291 // Display of the meridian
293 Quantity_Color Col2(Quantity_NOC_GREEN);
294 Handle(Graphic3d_AspectLine3d) Asp2 = new Graphic3d_AspectLine3d(Col2,Aspect_TOL_SOLID,1.);
295 gnopick->SetPrimitivesAspect(Asp2);
297 // Definition of the axis of the circle
298 aView->Up(DXRef,DYRef,DZRef);
299 this->Position(X,Y,Z);
300 DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0;
301 VX = DYRef*DZini - DZRef*DYini;
302 VY = DZRef*DXini - DXRef*DZini;
303 VZ = DXRef*DYini - DYRef*DXini;
305 V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon);
307 // Display of the parallel
309 // Definition of the axis of the circle
310 aView->Proj(VX,VY,VZ);
312 DXRef = VY * Z1 - VZ * Y1;
313 DYRef = VZ * X1 - VX * Z1;
314 DZRef = VX * Y1 - VY * X1;
315 this->Position(X,Y,Z);
316 DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0;
317 VX = DYRef*DZini - DZRef*DYini;
318 VY = DZRef*DXini - DXRef*DZini;
319 VZ = DXRef*DYini - DYRef*DXini;
321 V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon);
324 MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT);
325 MyTypeOfRepresentation = Pres;
326 MyGraphicStructure->Display();
327 TheViewer->SetUpdateMode(UpdSov);