Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:39

0001 // Created on: 2014-10-14
0002 // Created by: Anton POLETAEV
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _Prs3d_BndBox_H__
0017 #define _Prs3d_BndBox_H__
0018 
0019 #include <Bnd_OBB.hxx>
0020 #include <Graphic3d_ArrayOfSegments.hxx>
0021 #include <Graphic3d_ArrayOfTriangles.hxx>
0022 #include <Prs3d_Drawer.hxx>
0023 #include <Prs3d_Presentation.hxx>
0024 #include <Prs3d_Root.hxx>
0025 
0026 //! Tool for computing bounding box presentation.
0027 class Prs3d_BndBox : public Prs3d_Root
0028 {
0029 public:
0030 
0031   //! Computes presentation of a bounding box.
0032   //! @param thePresentation [in] the presentation.
0033   //! @param theBndBox [in] the bounding box.
0034   //! @param theDrawer [in] the drawer.
0035   Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation,
0036                                    const Bnd_Box& theBndBox,
0037                                    const Handle(Prs3d_Drawer)& theDrawer);
0038 
0039   //! Computes presentation of a bounding box.
0040   //! @param thePresentation [in] the presentation.
0041   //! @param theBndBox [in] the bounding box.
0042   //! @param theDrawer [in] the drawer.
0043   Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation,
0044                                    const Bnd_OBB& theBndBox,
0045                                    const Handle(Prs3d_Drawer)& theDrawer);
0046 
0047 public:
0048 
0049   //! Create primitive array with line segments for displaying a box.
0050   //! @param theBox [in] the box to add
0051   static Handle(Graphic3d_ArrayOfSegments) FillSegments (const Bnd_OBB& theBox)
0052   {
0053     if (theBox.IsVoid())
0054     {
0055       return Handle(Graphic3d_ArrayOfSegments)();
0056     }
0057 
0058     Handle(Graphic3d_ArrayOfSegments) aSegs = new Graphic3d_ArrayOfSegments (8, 12 * 2);
0059     FillSegments (aSegs, theBox);
0060     return aSegs;
0061   }
0062 
0063   //! Create primitive array with line segments for displaying a box.
0064   //! @param theBox [in] the box to add
0065   static Handle(Graphic3d_ArrayOfSegments) FillSegments (const Bnd_Box& theBox)
0066   {
0067     if (theBox.IsVoid())
0068     {
0069       return Handle(Graphic3d_ArrayOfSegments)();
0070     }
0071 
0072     Handle(Graphic3d_ArrayOfSegments) aSegs = new Graphic3d_ArrayOfSegments (8, 12 * 2);
0073     FillSegments (aSegs, theBox);
0074     return aSegs;
0075   }
0076 
0077   //! Create primitive array with line segments for displaying a box.
0078   //! @param theSegments [in] [out] primitive array to be filled;
0079   //!                               should be at least 8 nodes and 24 edges in size
0080   //! @param theBox [in] the box to add
0081   static void FillSegments (const Handle(Graphic3d_ArrayOfSegments)& theSegments, const Bnd_OBB& theBox)
0082   {
0083     if (!theBox.IsVoid())
0084     {
0085       gp_Pnt aXYZ[8];
0086       theBox.GetVertex (aXYZ);
0087       fillSegments (theSegments, aXYZ);
0088     }
0089   }
0090 
0091   //! Create primitive array with line segments for displaying a box.
0092   //! @param theSegments [in] [out] primitive array to be filled;
0093   //!                               should be at least 8 nodes and 24 edges in size
0094   //! @param theBox [in] the box to add
0095   static void FillSegments (const Handle(Graphic3d_ArrayOfSegments)& theSegments, const Bnd_Box& theBox)
0096   {
0097     if (!theBox.IsVoid())
0098     {
0099       const gp_Pnt aMin = theBox.CornerMin();
0100       const gp_Pnt aMax = theBox.CornerMax();
0101       const gp_Pnt aXYZ[8] =
0102       {
0103         gp_Pnt (aMin.X(), aMin.Y(), aMin.Z()),
0104         gp_Pnt (aMax.X(), aMin.Y(), aMin.Z()),
0105         gp_Pnt (aMin.X(), aMax.Y(), aMin.Z()),
0106         gp_Pnt (aMax.X(), aMax.Y(), aMin.Z()),
0107         gp_Pnt (aMin.X(), aMin.Y(), aMax.Z()),
0108         gp_Pnt (aMax.X(), aMin.Y(), aMax.Z()),
0109         gp_Pnt (aMin.X(), aMax.Y(), aMax.Z()),
0110         gp_Pnt (aMax.X(), aMax.Y(), aMax.Z()),
0111       };
0112       fillSegments (theSegments, aXYZ);
0113     }
0114   }
0115 
0116 public:
0117 
0118   //! Create primitive array with line segments for displaying a box.
0119   //! @param theSegments [in] [out] primitive array to be filled;
0120   //!                               should be at least 8 nodes and 24 edges in size
0121   //! @param theBox [in] the box to add
0122   static void fillSegments (const Handle(Graphic3d_ArrayOfSegments)& theSegments, const gp_Pnt* theBox)
0123   {
0124     const Standard_Integer aFrom = theSegments->VertexNumber();
0125     for (int aVertIter = 0; aVertIter < 8; ++aVertIter)
0126     {
0127       theSegments->AddVertex (theBox[aVertIter]);
0128     }
0129 
0130     theSegments->AddEdges (aFrom + 1, aFrom + 2);
0131     theSegments->AddEdges (aFrom + 3, aFrom + 4);
0132     theSegments->AddEdges (aFrom + 5, aFrom + 6);
0133     theSegments->AddEdges (aFrom + 7, aFrom + 8);
0134     //
0135     theSegments->AddEdges (aFrom + 1, aFrom + 3);
0136     theSegments->AddEdges (aFrom + 2, aFrom + 4);
0137     theSegments->AddEdges (aFrom + 5, aFrom + 7);
0138     theSegments->AddEdges (aFrom + 6, aFrom + 8);
0139     //
0140     theSegments->AddEdges (aFrom + 1, aFrom + 5);
0141     theSegments->AddEdges (aFrom + 2, aFrom + 6);
0142     theSegments->AddEdges (aFrom + 3, aFrom + 7);
0143     theSegments->AddEdges (aFrom + 4, aFrom + 8);
0144   }
0145 
0146 };
0147 
0148 #endif // _Prs3d_BndBox_H__