00001
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00029 #include <exotkUtils_View.hxx>
00030
00031 #ifndef _V3d_View_HeaderFile
00032 #include <V3d_View.hxx>
00033 #endif
00034 #ifndef _gp_Pnt_HeaderFile
00035 #include <gp_Pnt.hxx>
00036 #endif
00037 #ifndef _ElSLib_HeaderFile
00038 #include <ElSLib.hxx>
00039 #endif
00040 #ifndef _gp_Pln_HeaderFile
00041 #include <gp_Pln.hxx>
00042 #endif
00043 #ifndef _ProjLib_HeaderFile
00044 #include <ProjLib.hxx>
00045 #endif
00046 #ifndef _Aspect_Window_HeaderFile
00047 #include <Aspect_Window.hxx>
00048 #endif
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 Standard_Boolean exotkUtils_View::Convert2dPntTo3dPnt(const Handle_V3d_View& aView, const Standard_Integer aX2d, const Standard_Integer aY2d, gp_Pnt& a3dPoint)
00063 {
00064 if (aView.IsNull())
00065 return Standard_False;
00066
00067
00068 V3d_Coordinate theXEye, theYEye, theZEye, theXAt, theYAt, theZAt;
00069 aView->Eye(theXEye, theYEye, theZEye);
00070 aView->At(theXAt, theYAt, theZAt);
00071 gp_Pnt theEyePoint(theXEye, theYEye, theZEye);
00072 gp_Pnt theAtPoint(theXAt, theYAt, theZAt);
00073
00074
00075 gp_Vec theEyeVector(theEyePoint, theAtPoint);
00076 gp_Dir theEyeDir(theEyeVector);
00077
00078
00079 gp_Pln thePlaneOfTheView = gp_Pln(theAtPoint, theEyeDir);
00080
00081
00082 Standard_Real theX, theY, theZ;
00083 aView->Convert(aX2d, aY2d, theX, theY, theZ);
00084 gp_Pnt theConvertedPoint(theX, theY, theZ);
00085
00086
00087 gp_Pnt2d theConvertedPointOnPlane = ProjLib::Project(thePlaneOfTheView, theConvertedPoint);
00088
00089
00090 gp_Pnt theResultPoint = ElSLib::Value(theConvertedPointOnPlane.X(), theConvertedPointOnPlane.Y(), thePlaneOfTheView);
00091 a3dPoint = theResultPoint;
00092 return Standard_True;
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 Standard_Boolean exotkUtils_View::GetBounds(const Handle_V3d_View& aView, gp_Pnt& aTopLeft, gp_Pnt& aBottomRight)
00106 {
00107 if (aView.IsNull())
00108 return Standard_False;
00109
00110 gp_Pnt2d theTopLeft2d, theBottomRight2d;
00111 if (!GetBounds(aView,theTopLeft2d, theBottomRight2d))
00112 return Standard_False;
00113
00114
00115 if (!Convert2dPntTo3dPnt(aView,(Standard_Integer)theTopLeft2d.X(), (Standard_Integer)theTopLeft2d.Y(), aTopLeft))
00116 return Standard_False;
00117
00118 if (!Convert2dPntTo3dPnt(aView,(Standard_Integer)theBottomRight2d.X(), (Standard_Integer)theBottomRight2d.Y(), aBottomRight))
00119 return Standard_False;
00120
00121 return Standard_True;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 Standard_Boolean exotkUtils_View::GetBounds(const Handle_V3d_View& aView, gp_Pnt2d& aTopLeft, gp_Pnt2d& aBottomRight)
00135 {
00136 if (aView.IsNull())
00137 return Standard_False;
00138
00139 Standard_Integer Xmin, Ymin, Xmax, Ymax;
00140 aView->Window()->Position(Xmin, Ymin, Xmax, Ymax);
00141 aTopLeft.SetCoord((Standard_Real)Xmin, (Standard_Real)Ymax);
00142 aBottomRight.SetCoord((Standard_Real)Xmax, (Standard_Real)Ymin);
00143 return Standard_True;
00144 }