![]() |
|
|||
File indexing completed on 2025-09-15 09:06:14
0001 //------------------------------- -*- C++ -*- -------------------------------// 0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details 0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0004 //---------------------------------------------------------------------------// 0005 //! \file orange/surf/detail/QuadricPlaneConverter.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <algorithm> 0010 0011 #include "corecel/Assert.hh" 0012 #include "corecel/math/SoftEqual.hh" 0013 0014 #include "../Plane.hh" 0015 #include "../SimpleQuadric.hh" 0016 0017 namespace celeritas 0018 { 0019 namespace detail 0020 { 0021 //-------------------------------------------------------------------------// 0022 /*! 0023 * Convert a simple quadric to a plane. 0024 */ 0025 class QuadricPlaneConverter 0026 { 0027 public: 0028 // Construct with tolerance 0029 inline QuadricPlaneConverter(real_type tol); 0030 0031 // Convert to a plane 0032 Plane operator()(SimpleQuadric const& sq) const; 0033 0034 private: 0035 SoftZero<> soft_zero_; 0036 }; 0037 0038 //---------------------------------------------------------------------------// 0039 // INLINE DEFINITIONS 0040 //---------------------------------------------------------------------------// 0041 /*! 0042 * Construct with tolerance. 0043 */ 0044 QuadricPlaneConverter::QuadricPlaneConverter(real_type tol) : soft_zero_{tol} 0045 { 0046 } 0047 0048 //---------------------------------------------------------------------------// 0049 /*! 0050 * Convert to a plane. 0051 * 0052 * Simple quadric is calculated as 0053 * dx + ey + fz + g = 0, but plane is 0054 * ax + bx + cz - d = 0 0055 * so we need to reverse the sign of the scalar component. We also need to 0056 * normalize with the same factor. 0057 */ 0058 Plane QuadricPlaneConverter::operator()(SimpleQuadric const& sq) const 0059 { 0060 CELER_EXPECT( 0061 std::all_of(sq.second().begin(), sq.second().end(), soft_zero_)); 0062 CELER_EXPECT( 0063 !std::all_of(sq.first().begin(), sq.first().end(), soft_zero_)); 0064 // Second-order coefficients are zero: return a plane 0065 auto n = make_array(sq.first()); 0066 0067 real_type norm_factor = 1 / celeritas::norm(n); 0068 n *= norm_factor; 0069 0070 real_type d = -sq.zeroth() * norm_factor; 0071 0072 return Plane{n, d}; 0073 } 0074 0075 //---------------------------------------------------------------------------// 0076 } // namespace detail 0077 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |