// Created on: 2013-12-20 // Created by: Denis BOGOLEPOV // Copyright (c) 2013 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and / or modify it // under the terms of the GNU Lesser General Public version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #include namespace BVHTools { template struct CenterAxis { // Not implemented }; template struct CenterAxis { static T Center (const BVH_Box& theBox, const Standard_Integer theAxis) { if (theAxis == 0) { return (theBox.CornerMin().x() + theBox.CornerMax().x()) * static_cast (0.5); } else if (theAxis == 1) { return (theBox.CornerMin().y() + theBox.CornerMax().y()) * static_cast (0.5); } return static_cast (0.0); } }; template struct CenterAxis { static T Center (const BVH_Box& theBox, const Standard_Integer theAxis) { if (theAxis == 0) { return (theBox.CornerMin().x() + theBox.CornerMax().x()) * static_cast (0.5); } else if (theAxis == 1) { return (theBox.CornerMin().y() + theBox.CornerMax().y()) * static_cast (0.5); } else if (theAxis == 2) { return (theBox.CornerMin().z() + theBox.CornerMax().z()) * static_cast (0.5); } return static_cast (0.0); } }; template struct CenterAxis { static T Center (const BVH_Box& theBox, const Standard_Integer theAxis) { if (theAxis == 0) { return (theBox.CornerMin().x() + theBox.CornerMax().x()) * static_cast (0.5); } else if (theAxis == 1) { return (theBox.CornerMin().y() + theBox.CornerMax().y()) * static_cast (0.5); } else if (theAxis == 2) { return (theBox.CornerMin().z() + theBox.CornerMax().z()) * static_cast (0.5); } return static_cast (0.0); } }; } // ======================================================================= // function : Clear // purpose : // ======================================================================= template void BVH_Box::Clear() { myInitialized = Standard_False; } // ======================================================================= // function : Clear // purpose : // ======================================================================= template Standard_Boolean BVH_Box::IsValid() const { return myInitialized; } // ======================================================================= // function : Add // purpose : // ======================================================================= template void BVH_Box::Add (const BVH_VecNt& thePoint) { if (!myInitialized) { myMinPoint = thePoint; myMaxPoint = thePoint; myInitialized = Standard_True; } else { myMinPoint = myMinPoint.cwiseMin (thePoint); myMaxPoint = myMaxPoint.cwiseMax (thePoint); } } // ======================================================================= // function : Combine // purpose : // ======================================================================= template void BVH_Box::Combine (const BVH_Box& theBox) { if (!theBox.myInitialized) { return; } if (!myInitialized) { myMinPoint = theBox.myMinPoint; myMaxPoint = theBox.myMaxPoint; myInitialized = Standard_True; } else { myMinPoint = myMinPoint.cwiseMin (theBox.myMinPoint); myMaxPoint = myMaxPoint.cwiseMax (theBox.myMaxPoint); } } namespace BVHTools { template struct SurfaceCalculator { // Not implemented }; template struct SurfaceCalculator { static T Area (const typename BVH_Box::BVH_VecNt& theSize) { return theSize.x() * theSize.y(); } }; template struct SurfaceCalculator { static T Area (const typename BVH_Box::BVH_VecNt& theSize) { return ( theSize.x() * theSize.y() + theSize.x() * theSize.z() + theSize.z() * theSize.y() ) * static_cast (2.0); } }; template struct SurfaceCalculator { static T Area (const typename BVH_Box::BVH_VecNt& theSize) { return ( theSize.x() * theSize.y() + theSize.x() * theSize.z() + theSize.z() * theSize.y() ) * static_cast (2.0); } }; } // ======================================================================= // function : Area // purpose : // ======================================================================= template T BVH_Box::Area() const { return BVHTools::SurfaceCalculator::Area (myMaxPoint - myMinPoint); } // ======================================================================= // function : CornerMin // purpose : // ======================================================================= template const typename BVH_Box::BVH_VecNt& BVH_Box::CornerMin() const { return myMinPoint; } // ======================================================================= // function : CornerMax // purpose : // ======================================================================= template const typename BVH_Box::BVH_VecNt& BVH_Box::CornerMax() const { return myMaxPoint; } // ======================================================================= // function : CornerMin // purpose : // ======================================================================= template typename BVH_Box::BVH_VecNt& BVH_Box::CornerMin() { return myMinPoint; } // ======================================================================= // function : CornerMax // purpose : // ======================================================================= template typename BVH_Box::BVH_VecNt& BVH_Box::CornerMax() { return myMaxPoint; } // ======================================================================= // function : Size // purpose : // ======================================================================= template typename BVH_Box::BVH_VecNt BVH_Box::Size() const { return myMaxPoint - myMinPoint; } // ======================================================================= // function : Center // purpose : // ======================================================================= template typename BVH_Box::BVH_VecNt BVH_Box::Center() const { return (myMinPoint + myMaxPoint) * static_cast (0.5); }