// commercial license or contractual agreement.
/***********************************************************************
-
FONCTION :
----------
Classe V3d_SpotLight :
-
HISTORIQUE DES MODIFICATIONS :
--------------------------------
00-09-92 : GG ; Creation.
18-06-96 : FMN ; Ajout MyGraphicStructure1 pour sauvegarder snopick
30-03-98 : ZOV ; PRO6774 (reconstruction of the class hierarchy and suppressing useless methods)
02.15.100 : JR : Clutter
-
************************************************************************/
-
/*----------------------------------------------------------------------*/
/*
* Includes
*/
-#include <V3d.hxx>
-#include <V3d_SpotLight.ixx>
-#include <Graphic3d_Vector.hxx>
-#include <Graphic3d_Vertex.hxx>
-#include <Graphic3d_Structure.hxx>
-#include <Graphic3d_Group.hxx>
-#include <Graphic3d_ArrayOfSegments.hxx>
-#include <Graphic3d_AspectMarker3d.hxx>
-#include <Graphic3d_AspectLine3d.hxx>
-#include <Graphic3d_AspectText3d.hxx>
-#include <Visual3d_Light.hxx>
-#include <Visual3d_ViewManager.hxx>
-#include <Visual3d_ContextPick.hxx>
-#include <Visual3d_PickDescriptor.hxx>
-#include <Visual3d_HSequenceOfPickPath.hxx>
-#include <Visual3d_PickPath.hxx>
-#include <gp_Dir.hxx>
#include <gp_Ax1.hxx>
-#include <gp_Vec.hxx>
+#include <gp_Dir.hxx>
#include <gp_Pnt.hxx>
#include <gp_Trsf.hxx>
+#include <gp_Vec.hxx>
+#include <Graphic3d_ArrayOfSegments.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_AspectText3d.hxx>
+#include <Graphic3d_Group.hxx>
+#include <Graphic3d_Structure.hxx>
+#include <Graphic3d_Vector.hxx>
+#include <Graphic3d_Vertex.hxx>
+#include <Standard_Type.hxx>
#include <TCollection_AsciiString.hxx>
-
-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) {
-
- V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1
- || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle");
-
- Quantity_Color C(Name) ;
- Graphic3d_Vector D = V3d::GetProjAxis(Direction) ;
- Graphic3d_Vertex P(X,Y,Z) ;
- Graphic3d_Vertex T;
-
- MyType = V3d_SPOT ;
- MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ;
- // The target is fixed, starting from the light position and the direction.
- T.SetCoord(X + D.X(), Y + D.Y(), Z + D.Z());
- MyTarget = T;
-}
-
-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) {
-
- V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1
- || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle");
-
- Quantity_Color C(Name) ;
- Graphic3d_Vertex T(Xt,Yt,Zt) ;
- Graphic3d_Vertex P(Xp,Yp,Zp) ;
- Graphic3d_Vector D(P,T);
-
- MyType = V3d_SPOT ;
- D.Normalize();
- MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ;
- MyTarget = T;
- // La Structure graphique sera initialisee lors de l'affichage.
+#include <V3d.hxx>
+#include <V3d_BadValue.hxx>
+#include <V3d_SpotLight.hxx>
+#include <V3d_View.hxx>
+#include <V3d_Viewer.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(V3d_SpotLight,V3d_PositionLight)
+
+// =======================================================================
+// function : V3d_SpotLight
+// purpose :
+// =======================================================================
+V3d_SpotLight::V3d_SpotLight (const Handle(V3d_Viewer)& theViewer,
+ const Standard_Real theX,
+ const Standard_Real theY,
+ const Standard_Real theZ,
+ const V3d_TypeOfOrientation theDirection,
+ const Quantity_Color& theColor,
+ const Standard_Real theConstAttenuation,
+ const Standard_Real theLinearAttenuation,
+ const Standard_Real theConcentration,
+ const Standard_Real theAngle)
+: V3d_PositionLight (theViewer)
+{
+ Graphic3d_Vector aDir = V3d::GetProjAxis (theDirection);
+ SetType (V3d_SPOT);
+ SetColor (theColor);
+ SetTarget (theX + aDir.X(), theY + aDir.Y(), theZ + aDir.Z());
+ SetPosition (theX, theY, theZ);
+ SetDirection (aDir.X(), aDir.Y(), aDir.Z());
+ SetAttenuation (theConstAttenuation, theLinearAttenuation);
+ SetConcentration (theConcentration);
+ SetAngle (theAngle);
}
-
-//-Methods, in order
-
-void V3d_SpotLight::SetPosition(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp) {
- MyLight->SetPosition (Graphic3d_Vertex (Xp,Yp,Zp));
+// =======================================================================
+// function : V3d_SpotLight
+// purpose :
+// =======================================================================
+V3d_SpotLight::V3d_SpotLight (const Handle(V3d_Viewer)& theViewer,
+ const Standard_Real theXt,
+ const Standard_Real theYt,
+ const Standard_Real theZt,
+ const Standard_Real theXp,
+ const Standard_Real theYp,
+ const Standard_Real theZp,
+ const Quantity_Color& theColor,
+ const Standard_Real theConstAttenuation,
+ const Standard_Real theLinearAttenuation,
+ const Standard_Real theConcentration,
+ const Standard_Real theAngle)
+: V3d_PositionLight (theViewer)
+{
+ SetType (V3d_SPOT);
+ SetColor (theColor);
+ SetTarget (theXt, theYt, theZt);
+ SetPosition (theXp, theYp, theZp);
+ SetDirection (theXt - theXp, theYt - theYp, theZt - theZp);
+ SetAttenuation (theConstAttenuation, theLinearAttenuation);
+ SetConcentration (theConcentration);
+ SetAngle (theAngle);
}
-void V3d_SpotLight::SetDirection(const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) {
-
- Graphic3d_Vector D ;
- D.SetCoord(Vx,Vy,Vz) ; D.Normalize() ;
- MyLight->SetDirection(D) ;
+// =======================================================================
+// function : SetPosition
+// purpose :
+// =======================================================================
+void V3d_SpotLight::SetPosition (const Standard_Real theXp,
+ const Standard_Real theYp,
+ const Standard_Real theZp)
+{
+ myLight.Position.x() = theXp;
+ myLight.Position.y() = theYp;
+ myLight.Position.z() = theZp;
}
-void V3d_SpotLight::SetDirection(const V3d_TypeOfOrientation Direction) {
-
- Graphic3d_Vector D = V3d::GetProjAxis(Direction) ;
- MyLight->SetDirection(D) ;
+// =======================================================================
+// function : SetDirection
+// purpose :
+// =======================================================================
+void V3d_SpotLight::SetDirection (const Standard_Real theVx,
+ const Standard_Real theVy,
+ const Standard_Real theVz)
+{
+ myLight.Direction.x() = static_cast<Standard_ShortReal> (theVx);
+ myLight.Direction.y() = static_cast<Standard_ShortReal> (theVy);
+ myLight.Direction.z() = static_cast<Standard_ShortReal> (theVz);
}
-void V3d_SpotLight::SetAttenuation(const Standard_Real A1, const Standard_Real A2) {
-
- V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 ,
- "V3d_SpotLight::SetAttenuation, bad coefficients");
-
- MyLight->SetAttenuation1(A1) ;
- MyLight->SetAttenuation2(A2) ;
+// =======================================================================
+// function : SetDirection
+// purpose :
+// =======================================================================
+void V3d_SpotLight::SetDirection (const V3d_TypeOfOrientation theDirection)
+{
+ Graphic3d_Vector aDir = V3d::GetProjAxis (theDirection);
+ SetDirection (aDir.X(), aDir.Y(), aDir.Z());
}
-void V3d_SpotLight::SetConcentration(const Standard_Real C) {
-
-
- V3d_BadValue_Raise_if( C < 0 || C > 1.,
- "V3d_SpotLight::SetConcentration, bad coefficient");
-
- MyLight->SetConcentration(C) ;
+// =======================================================================
+// function : SetAttenuation
+// purpose :
+// =======================================================================
+void V3d_SpotLight::SetAttenuation (const Standard_Real theConstAttenuation,
+ const Standard_Real theLinearAttenuation)
+{
+ V3d_BadValue_Raise_if (theConstAttenuation < 0. ||
+ theConstAttenuation > 1. ||
+ theLinearAttenuation < 0. ||
+ theLinearAttenuation > 1 ,
+ "V3d_SpotLight::SetAttenuation, "
+ "bad coefficients");
+
+ myLight.ChangeConstAttenuation() = static_cast<Standard_ShortReal> (theConstAttenuation);
+ myLight.ChangeLinearAttenuation() = static_cast<Standard_ShortReal> (theLinearAttenuation);
}
-void V3d_SpotLight::SetAngle(const Standard_Real Angle) {
-
- V3d_BadValue_Raise_if( Angle <= 0. || Angle >= M_PI,
- "V3d_SpotLight::SetAngle, bad angle");
- MyLight->SetAngle(Angle) ;
+// =======================================================================
+// function : SetConcentration
+// purpose :
+// =======================================================================
+void V3d_SpotLight::SetConcentration (const Standard_Real theConcentration)
+{
+ V3d_BadValue_Raise_if (theConcentration < 0. ||
+ theConcentration > 1.,
+ "V3d_SpotLight::SetConcentration, "
+ "bad coefficient");
+ myLight.ChangeConcentration() = static_cast<Standard_ShortReal> (theConcentration);
}
-void V3d_SpotLight::Direction(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz)const {
-
- Quantity_Color C ;
- Graphic3d_Vector D ;
- Graphic3d_Vertex P ;
- Standard_Real CN,A1,A2,AN ;
+// =======================================================================
+// function : SetAngle
+// purpose :
+// =======================================================================
+void V3d_SpotLight::SetAngle (const Standard_Real theAngle)
+{
+ V3d_BadValue_Raise_if (theAngle <= 0. ||
+ theAngle >= M_PI,
+ "V3d_SpotLight::SetAngle, "
+ "bad angle");
- MyLight->Values(C,P,D,CN,A1,A2,AN) ;
- D.Coord(Vx,Vy,Vz) ;
+ myLight.ChangeAngle() = static_cast<Standard_ShortReal> (theAngle);
}
-void V3d_SpotLight::Position(Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp)const {
-
- Quantity_Color C ;
- Graphic3d_Vector D ;
- Graphic3d_Vertex P ;
- Standard_Real CN,A1,A2,AN ;
+// =======================================================================
+// function : Direction
+// purpose :
+// =======================================================================
+void V3d_SpotLight::Direction (Standard_Real& theVx,
+ Standard_Real& theVy,
+ Standard_Real& theVz) const
+{
+ theVx = myLight.Direction.x();
+ theVy = myLight.Direction.y();
+ theVz = myLight.Direction.z();
+}
- MyLight->Values(C,P,D,CN,A1,A2,AN) ;
- P.Coord(Xp,Yp,Zp) ;
+// =======================================================================
+// function : Direction
+// purpose :
+// =======================================================================
+void V3d_SpotLight::Position (Standard_Real& theXp,
+ Standard_Real& theYp,
+ Standard_Real& theZp) const
+{
+ theXp = myLight.Position.x();
+ theYp = myLight.Position.y();
+ theZp = myLight.Position.z();
}
-void V3d_SpotLight::Attenuation(Standard_Real& A1, Standard_Real& A2) const {
- Quantity_Color C ;
- Graphic3d_Vector D ;
- Graphic3d_Vertex P ;
- Standard_Real CN,AN ;
-
- MyLight->Values(C,P,D,CN,A1,A2,AN) ;
+// =======================================================================
+// function : Attenuation
+// purpose :
+// =======================================================================
+void V3d_SpotLight::Attenuation (Standard_Real& theConstAttenuation,
+ Standard_Real& theLinearAttenuation) const
+{
+ theConstAttenuation = myLight.ConstAttenuation();
+ theLinearAttenuation = myLight.LinearAttenuation();
}
-Standard_Real V3d_SpotLight::Concentration()const
+// =======================================================================
+// function : Concentration
+// purpose :
+// =======================================================================
+Standard_Real V3d_SpotLight::Concentration ()const
{
- Quantity_Color C ;
- Graphic3d_Vector D ;
- Graphic3d_Vertex P ;
- Standard_Real AN,A1,A2,CN ;
-
- MyLight->Values(C,P,D,CN,A1,A2,AN) ;
- return CN ;
+ return myLight.Concentration();
}
+// =======================================================================
+// function : Concentration
+// purpose :
+// =======================================================================
Standard_Real V3d_SpotLight::Angle()const
{
- Quantity_Color C ;
- Graphic3d_Vector D ;
- Graphic3d_Vertex P ;
- Standard_Real CN,A1,A2,AN ;
-
- MyLight->Values(C,P,D,CN,A1,A2,AN) ;
- return AN ;
+ return myLight.Angle();
}
-void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& gsymbol,
+// =======================================================================
+// function : Symbol
+// purpose :
+// =======================================================================
+void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& theSymbol,
const Handle(V3d_View)& ) const
{
Standard_Real X,Y,Z;
this->Position(X,Y,Z);
this->Direction(DX,DY,DZ);
- V3d::ArrowOfRadius(gsymbol,X,Y,Z,-DX,-DY,-DZ,M_PI/8.,this->Radius()/15.);
+ V3d::ArrowOfRadius(theSymbol,X,Y,Z,-DX,-DY,-DZ,M_PI/8.,this->Radius()/15.);
}
-
-void V3d_SpotLight::Display( const Handle(V3d_View)& aView,
- const V3d_TypeOfRepresentation TPres)
+
+// =======================================================================
+// function : Display
+// purpose :
+// =======================================================================
+void V3d_SpotLight::Display (const Handle(V3d_View)& theView,
+ const V3d_TypeOfRepresentation theTPres)
{
Graphic3d_Vertex PText ;
Standard_Real X,Y,Z,Rayon;
Standard_Real X0,Y0,Z0,VX,VY,VZ;
Standard_Real X1,Y1,Z1;
Standard_Real DXRef,DYRef,DZRef,DXini,DYini,DZini;
- Standard_Real R1,G1,B1;
V3d_TypeOfRepresentation Pres;
- V3d_TypeOfUpdate UpdSov;
// Creation of a structure slight of markable elements (position of the
// light, and the domain of lighting represented by a circle)
// Creation of a structure snopick of non-markable elements (target, meridian and
// parallel).//
- Pres = TPres;
- Handle(V3d_Viewer) TheViewer = aView->Viewer();
- UpdSov = TheViewer->UpdateMode();
- TheViewer->SetUpdateMode(V3d_WAIT);
- if (!MyGraphicStructure.IsNull()) {
- MyGraphicStructure->Disconnect(MyGraphicStructure1);
- MyGraphicStructure->Clear();
- MyGraphicStructure1->Clear();
- if (Pres == V3d_SAMELAST) Pres = MyTypeOfRepresentation;
+ Pres = theTPres;
+ Handle(V3d_Viewer) TheViewer = theView->Viewer();
+ if (!myGraphicStructure.IsNull()) {
+ myGraphicStructure->Disconnect(myGraphicStructure1);
+ myGraphicStructure->Clear();
+ myGraphicStructure1->Clear();
+ if (Pres == V3d_SAMELAST) Pres = myTypeOfRepresentation;
}
else {
if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE;
- Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->Viewer());
- MyGraphicStructure = slight;
- Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->Viewer());
- MyGraphicStructure1 = snopick;
+ Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->StructureManager());
+ myGraphicStructure = slight;
+ Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->StructureManager());
+ myGraphicStructure1 = snopick;
}
- Handle(Graphic3d_Group) gradius;
- Handle(Graphic3d_Group) gExtArrow;
- Handle(Graphic3d_Group) gIntArrow;
- if (Pres == V3d_COMPLETE) {
- gradius = new Graphic3d_Group(MyGraphicStructure);
- gExtArrow = new Graphic3d_Group(MyGraphicStructure);
- gIntArrow = new Graphic3d_Group(MyGraphicStructure);
+ Handle(Graphic3d_Group) gradius, gExtArrow, gIntArrow;
+ if (Pres == V3d_COMPLETE)
+ {
+ gradius = myGraphicStructure->NewGroup();
+ gExtArrow = myGraphicStructure->NewGroup();
+ gIntArrow = myGraphicStructure->NewGroup();
}
- Handle(Graphic3d_Group) glight = new Graphic3d_Group(MyGraphicStructure);
+ Handle(Graphic3d_Group) glight = myGraphicStructure->NewGroup();
Handle(Graphic3d_Group) gsphere;
- if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) gsphere = new Graphic3d_Group(MyGraphicStructure);
+ if (Pres == V3d_COMPLETE
+ || Pres == V3d_PARTIAL)
+ {
+ gsphere = myGraphicStructure->NewGroup();
+ }
- Handle(Graphic3d_Group) gnopick = new Graphic3d_Group(MyGraphicStructure1);
- MyGraphicStructure1->SetPick(Standard_False);
+ Handle(Graphic3d_Group) gnopick = myGraphicStructure1->NewGroup();
- X0 = MyTarget.X();
- Y0 = MyTarget.Y();
- Z0 = MyTarget.Z();
+ X0 = myTarget.X();
+ Y0 = myTarget.Y();
+ Z0 = myTarget.Z();
//Display of the position of the light.
- this->Color(Quantity_TOC_RGB,R1,G1,B1);
- Quantity_Color Col1(R1,G1,B1,Quantity_TOC_RGB);
+ const Quantity_Color Col1 = this->Color();
Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d();
Asp1->SetColor(Col1);
glight->SetPrimitivesAspect(Asp1);
- this->Symbol(glight,aView);
+ this->Symbol(glight,theView);
// Display of the reference sphere (limited by circle).
if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) {
Rayon = this->Radius();
- aView->Proj(VX,VY,VZ);
+ theView->Proj(VX,VY,VZ);
V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon);
// Display of the radius of the sphere (line + text)
gnopick->SetPrimitivesAspect(Asp2);
// Definition of the axis of the circle
- aView->Up(DXRef,DYRef,DZRef);
+ theView->Up(DXRef,DYRef,DZRef);
this->Position(X,Y,Z);
DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0;
VX = DYRef*DZini - DZRef*DYini;
// Display of the parallel
// Definition of the axis of the circle
- aView->Proj(VX,VY,VZ);
- aView->Up(X1,Y1,Z1);
+ theView->Proj(VX,VY,VZ);
+ theView->Up(X1,Y1,Z1);
DXRef = VY * Z1 - VZ * Y1;
DYRef = VZ * X1 - VX * Z1;
DZRef = VX * Y1 - VY * X1;
V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon);
}
- MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT);
- MyTypeOfRepresentation = Pres;
- MyGraphicStructure->Display();
- TheViewer->SetUpdateMode(UpdSov);
+ myGraphicStructure->Connect(myGraphicStructure1,Graphic3d_TOC_DESCENDANT);
+ myTypeOfRepresentation = Pres;
+ myGraphicStructure->Display();
}