Commit | Line | Data |
---|---|---|
7fd59977 | 1 | /*********************************************************************** |
2 | ||
3 | FONCTION : | |
4 | ---------- | |
5 | Classe V3d_PositionalLight : | |
6 | ||
7 | HISTORIQUE DES MODIFICATIONS : | |
8 | -------------------------------- | |
9 | 00-09-92 : GG ; Creation. | |
10 | 18-06-96 : FMN ; Ajout MyGraphicStructure1 pour sauvegarder snopick | |
11 | 24-12-97 : FMN ; Remplacement de math par MathGra | |
12 | 31-12-97 : CAL ; Suppression de MathGra | |
13 | 21-01-98 : CAL ; Window de Xw et WNT remplacee par Aspect_Window | |
14 | 23-02-98 : FMN ; Remplacement PI par Standard_PI | |
15 | 30-03-98 : ZOV ; PRO6774 (reconstruction of the class hierarchy and suppressing useless methods) | |
16 | ||
17 | ************************************************************************/ | |
18 | ||
19 | /*----------------------------------------------------------------------*/ | |
20 | /* | |
21 | * Includes | |
22 | */ | |
23 | ||
24 | #include <V3d.hxx> | |
25 | #include <V3d_PositionalLight.ixx> | |
26 | #include <Graphic3d_Vector.hxx> | |
27 | #include <Graphic3d_Vertex.hxx> | |
28 | #include <Graphic3d_Structure.hxx> | |
29 | #include <Graphic3d_Group.hxx> | |
30 | #include <Graphic3d_Array1OfVertex.hxx> | |
31 | #include <Graphic3d_AspectMarker3d.hxx> | |
32 | #include <Graphic3d_AspectLine3d.hxx> | |
33 | #include <Graphic3d_AspectText3d.hxx> | |
34 | #include <Visual3d_Light.hxx> | |
35 | #include <Visual3d_ViewManager.hxx> | |
36 | #include <Visual3d_ContextPick.hxx> | |
37 | #include <Visual3d_PickDescriptor.hxx> | |
38 | #include <Visual3d_HSequenceOfPickPath.hxx> | |
39 | #include <Visual3d_PickPath.hxx> | |
40 | #include <Viewer_BadValue.hxx> | |
41 | #include <gp_Dir.hxx> | |
42 | #include <gp_Ax1.hxx> | |
43 | #include <gp_Vec.hxx> | |
44 | #include <gp_Pnt.hxx> | |
45 | #include <gp_Trsf.hxx> | |
46 | #include <TColStd_Array2OfReal.hxx> | |
47 | #include <TCollection_AsciiString.hxx> | |
48 | #include <Aspect_Window.hxx> | |
49 | ||
50 | //-Declarations | |
51 | ||
52 | //-Constructors | |
53 | ||
54 | V3d_PositionalLight::V3d_PositionalLight(const Handle(V3d_Viewer)& VM, const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Quantity_NameOfColor Name, const Standard_Real A1, const Standard_Real A2):V3d_PositionLight(VM) { | |
55 | ||
56 | Quantity_Color C(Name) ; | |
57 | Graphic3d_Vertex P(X,Y,Z) ; | |
58 | Graphic3d_Vertex T(0.,0.,0.); | |
59 | ||
60 | Viewer_BadValue_Raise_if ( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1, | |
61 | "V3d_PositionalLight, bad coefficients"); | |
62 | ||
63 | MyType = V3d_POSITIONAL ; | |
64 | MyLight = new Visual3d_Light(C,P,A1,A2) ; | |
65 | MyTarget = T; | |
66 | ||
67 | } | |
68 | ||
69 | V3d_PositionalLight::V3d_PositionalLight(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):V3d_PositionLight(VM) { | |
70 | ||
71 | Quantity_Color C(Name) ; | |
72 | Graphic3d_Vertex T(Xt,Yt,Zt) ; | |
73 | Graphic3d_Vertex P(Xp,Yp,Zp) ; | |
74 | ||
75 | Viewer_BadValue_Raise_if ( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1, | |
76 | "V3d_PositionalLight, bad coefficients"); | |
77 | ||
78 | MyType = V3d_POSITIONAL ; | |
79 | MyLight = new Visual3d_Light(C,P,A1,A2) ; | |
80 | MyTarget = T; | |
81bba717 | 81 | // Graphic structure is initialized during the display. |
7fd59977 | 82 | |
83 | } | |
84 | ||
85 | //-Methods, in order | |
86 | ||
87 | void V3d_PositionalLight::SetPosition(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp) { | |
88 | MyLight->SetPosition (Graphic3d_Vertex (Xp,Yp,Zp)); | |
89 | } | |
90 | ||
91 | void V3d_PositionalLight::SetAttenuation(const Standard_Real A1, const Standard_Real A2) { | |
92 | ||
93 | ||
94 | Viewer_BadValue_Raise_if ( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1, | |
95 | "V3d_PositionalLight::SetAttenuation, bad coefficients"); | |
96 | ||
97 | MyLight->SetAttenuation1(A1) ; | |
98 | MyLight->SetAttenuation2(A2) ; | |
99 | } | |
100 | ||
101 | void V3d_PositionalLight::Position(Standard_Real& X, Standard_Real& Y, Standard_Real& Z)const { | |
102 | Quantity_Color C ; | |
103 | Graphic3d_Vertex P ; | |
104 | Standard_Real A1,A2 ; | |
105 | ||
106 | MyLight->Values(C,P,A1,A2) ; | |
107 | P.Coord(X,Y,Z) ; | |
108 | } | |
109 | ||
110 | void V3d_PositionalLight::Attenuation(Standard_Real& A1, Standard_Real& A2)const { | |
111 | Quantity_Color C ; | |
112 | Graphic3d_Vertex P ; | |
113 | ||
114 | MyLight->Values(C,P,A1,A2) ; | |
115 | } | |
116 | ||
117 | void V3d_PositionalLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, const Handle(V3d_View)& aView) const { | |
118 | ||
119 | Standard_Real Xi,Yi,Zi,Xf,Yf,Zf,Rayon,PXT,PYT,X,Y,Z,XT,YT,ZT; | |
120 | Standard_Real A,B,C,Dist,Beta,CosBeta,SinBeta,Coef,X1,Y1,Z1; | |
121 | Standard_Real VX,VY,VZ; | |
122 | Standard_Integer IXP,IYP,j; | |
123 | TColStd_Array2OfReal MatRot(0,2,0,2); | |
124 | ||
125 | aView->Proj(VX,VY,VZ); | |
126 | this->Position(Xi,Yi,Zi); | |
127 | Rayon = this->Radius(); | |
128 | aView->Project(Xi,Yi,Zi,PXT,PYT); | |
129 | aView->Convert(PXT,PYT,IXP,IYP); | |
81bba717 | 130 | // 3D Coordinate in the plane of projection of the source. |
7fd59977 | 131 | aView->Convert(IXP,IYP,XT,YT,ZT); |
132 | aView->Convert(PXT,PYT+Rayon,IXP,IYP); | |
133 | aView->Convert(IXP,IYP,X,Y,Z); | |
134 | X = X+Xi-XT; Y = Y+Yi-YT; Z = Z+Zi-ZT; | |
135 | Dist = Sqrt( Square(X-Xi) + Square(Y-Yi) + Square(Z-Zi) ); | |
81bba717 | 136 | // Axis of rotation. |
7fd59977 | 137 | A = (X-Xi)/Dist; |
138 | B = (Y-Yi)/Dist; | |
139 | C = (Z-Zi)/Dist; | |
140 | ||
81bba717 | 141 | // A sphere is drawn |
7fd59977 | 142 | V3d::CircleInPlane(gsymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); |
143 | for( j=1 ; j<=3 ; j++ ) { | |
c6541a0c | 144 | Beta = j * M_PI / 4.; |
7fd59977 | 145 | CosBeta = Cos(Beta); |
146 | SinBeta = Sin(Beta); | |
147 | Coef = 1. - CosBeta; | |
148 | MatRot(0,0) = A * A + (1. - A * A) * CosBeta; | |
149 | MatRot(0,1) = -C * SinBeta + Coef * A * B; | |
150 | MatRot(0,2) = B * SinBeta + Coef * A * C; | |
151 | MatRot(1,0) = C * SinBeta + Coef * A * B; | |
152 | MatRot(1,1) = B * B + (1. - B * B) * CosBeta; | |
153 | MatRot(1,2) = -A * SinBeta + Coef * B * C; | |
154 | MatRot(2,0) = -B * SinBeta + Coef * A * C; | |
155 | MatRot(2,1) = A * SinBeta + Coef * B * C; | |
156 | MatRot(2,2) = C * C + (1. - C * C) * CosBeta; | |
157 | Xf = Xi * MatRot(0,0) + Yi * MatRot(0,1) + Zi * MatRot(0,2); | |
158 | Yf = Xi * MatRot(1,0) + Yi * MatRot(1,1) + Zi * MatRot(1,2); | |
159 | Zf = Xi * MatRot(2,0) + Yi * MatRot(2,1) + Zi * MatRot(2,2); | |
81bba717 | 160 | // Rotation of the normal |
7fd59977 | 161 | X1 = VX * MatRot(0,0) + VY * MatRot(0,1) + VZ * MatRot(0,2); |
162 | Y1 = VX * MatRot(1,0) + VY * MatRot(1,1) + VZ * MatRot(1,2); | |
163 | Z1 = VX * MatRot(2,0) + VY * MatRot(2,1) + VZ * MatRot(2,2); | |
164 | VX = X1 + Xi - Xf ; VY = Y1 + Yi - Yf ; VZ = Z1 + Zi - Zf; | |
165 | V3d::CircleInPlane(gsymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); | |
166 | } | |
167 | } | |
168 | ||
169 | ||
170 | void V3d_PositionalLight::Display( const Handle(V3d_View)& aView, | |
171 | const V3d_TypeOfRepresentation TPres ) { | |
172 | ||
173 | Graphic3d_Array1OfVertex PRadius(0,1); | |
174 | Graphic3d_Vertex PText ; | |
175 | Standard_Real X,Y,Z,Rayon; | |
176 | Standard_Real X0,Y0,Z0,VX,VY,VZ; | |
177 | Standard_Real X1,Y1,Z1; | |
178 | Standard_Real DXRef,DYRef,DZRef,DXini,DYini,DZini; | |
179 | Standard_Real R1,G1,B1; | |
180 | V3d_TypeOfRepresentation Pres; | |
181 | V3d_TypeOfUpdate UpdSov; | |
182 | ||
81bba717 | 183 | // Creation of a structure slight of markable elements (position of the |
184 | // light, and the domain of lighting represented by a circle) | |
185 | // Creation of a structure snopick of non-markable elements (target, meridian and | |
186 | // parallel). | |
7fd59977 | 187 | |
188 | Pres = TPres; | |
189 | Handle(V3d_Viewer) TheViewer = aView->Viewer(); | |
190 | UpdSov = TheViewer->UpdateMode(); | |
191 | TheViewer->SetUpdateMode(V3d_WAIT); | |
192 | if (!MyGraphicStructure.IsNull()) { | |
193 | MyGraphicStructure->Disconnect(MyGraphicStructure1); | |
194 | MyGraphicStructure->Clear(); | |
195 | MyGraphicStructure1->Clear(); | |
196 | if (Pres == V3d_SAMELAST) Pres = MyTypeOfRepresentation; | |
197 | } | |
198 | else { | |
199 | if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE; | |
200 | Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->Viewer()); | |
201 | MyGraphicStructure = slight; | |
202 | Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->Viewer()); | |
203 | MyGraphicStructure1 = snopick; | |
204 | } | |
205 | ||
206 | Handle(Graphic3d_Group) gradius; | |
207 | Handle(Graphic3d_Group) gExtArrow; | |
208 | Handle(Graphic3d_Group) gIntArrow; | |
209 | if (Pres == V3d_COMPLETE) { | |
210 | gradius = new Graphic3d_Group(MyGraphicStructure); | |
211 | gExtArrow = new Graphic3d_Group(MyGraphicStructure); | |
212 | gIntArrow = new Graphic3d_Group(MyGraphicStructure); | |
213 | } | |
214 | Handle(Graphic3d_Group) glight = new Graphic3d_Group(MyGraphicStructure); | |
215 | Handle(Graphic3d_Group) gsphere; | |
216 | if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) gsphere = new Graphic3d_Group(MyGraphicStructure); | |
217 | ||
218 | Handle(Graphic3d_Group) gnopick = new Graphic3d_Group(MyGraphicStructure1); | |
219 | MyGraphicStructure1->SetPick(Standard_False); | |
220 | ||
221 | X0 = MyTarget.X(); | |
222 | Y0 = MyTarget.Y(); | |
223 | Z0 = MyTarget.Z(); | |
224 | ||
81bba717 | 225 | // Display of the position of the light. |
7fd59977 | 226 | |
227 | glight->SetPickId(1); | |
228 | this->Color(Quantity_TOC_RGB,R1,G1,B1); | |
229 | Quantity_Color Col1(R1,G1,B1,Quantity_TOC_RGB); | |
230 | Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d(); | |
231 | Asp1->SetColor(Col1); | |
232 | glight->SetPrimitivesAspect(Asp1); | |
233 | this->Symbol(glight,aView); | |
234 | ||
81bba717 | 235 | // Display of the markable sphere (limit at the cercle). |
7fd59977 | 236 | |
237 | if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { | |
238 | ||
239 | Rayon = this->Radius(); | |
240 | aView->Proj(VX,VY,VZ); | |
241 | gsphere->SetPickId(2); | |
242 | V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon); | |
243 | ||
81bba717 | 244 | // Display of the radius of the sphere (line + text) |
7fd59977 | 245 | |
246 | if (Pres == V3d_COMPLETE) { | |
247 | gradius->SetPickId(3); | |
248 | gExtArrow->SetPickId(4); | |
249 | gIntArrow->SetPickId(5); | |
250 | PRadius(0).SetCoord(X0,Y0,Z0); | |
251 | this->Position(X,Y,Z); | |
252 | PRadius(1).SetCoord(X,Y,Z); | |
253 | gnopick->Polyline(PRadius); | |
254 | V3d::ArrowOfRadius(gExtArrow,X-(X-X0)/10., | |
255 | Y-(Y-Y0)/10., | |
c6541a0c D |
256 | Z-(Z-Z0) / 10., X-X0, Y-Y0, Z-Z0, M_PI / 15., Rayon / 20.); |
257 | V3d::ArrowOfRadius(gIntArrow, X0, Y0, Z0, X0-X, Y0-Y, Z0-Z, M_PI / 15., Rayon / 20.); | |
7fd59977 | 258 | TCollection_AsciiString ValOfRadius(Rayon); |
259 | PText.SetCoord( (X0+X)/2., (Y0+Y)/2. , (Z0+Z)/2. ); | |
260 | gradius->Text(ValOfRadius.ToCString(),PText,0.01); | |
261 | } | |
262 | ||
81bba717 | 263 | // Display of the meridian |
7fd59977 | 264 | |
265 | Quantity_Color Col2(Quantity_NOC_GREEN); | |
266 | Handle(Graphic3d_AspectLine3d) Asp2 = new Graphic3d_AspectLine3d | |
267 | (Col2,Aspect_TOL_SOLID,1.); | |
268 | gnopick->SetPrimitivesAspect(Asp2); | |
269 | ||
81bba717 | 270 | // Definition of the axis of circle |
7fd59977 | 271 | aView->Up(DXRef,DYRef,DZRef); |
272 | this->Position(X,Y,Z); | |
273 | DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0; | |
274 | VX = DYRef*DZini - DZRef*DYini; | |
275 | VY = DZRef*DXini - DXRef*DZini; | |
276 | VZ = DXRef*DYini - DYRef*DXini; | |
277 | ||
278 | V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon); | |
279 | ||
81bba717 | 280 | // Display of the parallel |
7fd59977 | 281 | |
81bba717 | 282 | // Definition of the axis of circle |
7fd59977 | 283 | aView->Proj(VX,VY,VZ); |
284 | aView->Up(X1,Y1,Z1); | |
285 | DXRef = VY * Z1 - VZ * Y1; | |
286 | DYRef = VZ * X1 - VX * Z1; | |
287 | DZRef = VX * Y1 - VY * X1; | |
288 | this->Position(X,Y,Z); | |
289 | DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0; | |
290 | VX = DYRef*DZini - DZRef*DYini; | |
291 | VY = DZRef*DXini - DXRef*DZini; | |
292 | VZ = DXRef*DYini - DYRef*DXini; | |
293 | ||
294 | V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon); | |
295 | ||
296 | } | |
297 | ||
298 | MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT); | |
299 | MyTypeOfRepresentation = Pres; | |
300 | MyGraphicStructure->Display(); | |
301 | TheViewer->SetUpdateMode(UpdSov); | |
302 | } |