Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

exotkUtils_View.cxx

Go to the documentation of this file.
00001 
00002 //   exotkUtils_View.cxx
00004 //    Copyright (C) 2001  Stephane Routelous
00005 //
00006 //    This file is part of exoTK.
00007 //
00008 //    exoTK is free software; you can redistribute it and/or modify
00009 //    it under the terms of the GNU General Public License as published by
00010 //    the Free Software Foundation; either version 2 of the License, or
00011 //    (at your option) any later version.
00012 //
00013 //    exoTK is distributed in the hope that it will be useful,
00014 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //    GNU General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU General Public License
00019 //    along with exoTK; if not, write to the Free Software
00020 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Function name        : exotkUtils_View::Convert2dPntTo3dPnt
00053 //==================================================================================
00054 // Written by       : Stephane Routelous - 2001-11-08 19:02:49
00055 // Description      : 
00056 // Return type          : Standard_Boolean 
00057 //==================================================================================
00058 // Argument         : const Handle_V3d_View& aView
00059 // Argument         : const Standard_Integer aX2d
00060 // Argument         : const Standard_Integer aY2d
00061 // Argument         : gp_Pnt& a3dPoint
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         // get the eye and the target points
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         // create the direction
00075         gp_Vec theEyeVector(theEyePoint, theAtPoint);
00076         gp_Dir theEyeDir(theEyeVector);
00077         
00078         // make a plane perpendicular to this direction
00079         gp_Pln thePlaneOfTheView = gp_Pln(theAtPoint, theEyeDir);
00080         
00081         // convert the 2d point into 3d
00082         Standard_Real theX, theY, theZ;
00083         aView->Convert(aX2d, aY2d, theX, theY, theZ);
00084         gp_Pnt theConvertedPoint(theX, theY, theZ);
00085         
00086         // project the converted point to the plane
00087         gp_Pnt2d theConvertedPointOnPlane = ProjLib::Project(thePlaneOfTheView, theConvertedPoint);
00088         
00089         // get the 3d point of this 2d point
00090         gp_Pnt theResultPoint = ElSLib::Value(theConvertedPointOnPlane.X(),     theConvertedPointOnPlane.Y(), thePlaneOfTheView);
00091         a3dPoint = theResultPoint;
00092         return Standard_True;
00093 }
00094 
00095 //==================================================================================
00096 // Function name        : exotkUtils_View::GetBounds
00097 //==================================================================================
00098 // Written by       : Stephane Routelous - 2001-11-08 19:02:51
00099 // Description      : 
00100 // Return type          : Standard_Boolean 
00101 //==================================================================================
00102 // Argument         : const Handle_V3d_View& aView
00103 // Argument         : gp_Pnt& aTopLeft
00104 // Argument         : gp_Pnt& aBottomRight
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 // Function name        : exotkUtils_View::GetBounds
00126 //==================================================================================
00127 // Written by       : Stephane Routelous - 2001-11-08 19:02:53
00128 // Description      : 
00129 // Return type          : Standard_Boolean 
00130 //==================================================================================
00131 // Argument         : const Handle_V3d_View& aView
00132 // Argument         : gp_Pnt2d& aTopLeft
00133 // Argument         : gp_Pnt2d& aBottomRight
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 }

Generated on Wed Jan 23 12:16:45 2002 for exotk by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001