1 // This file is part of OpenMVG, an Open Multiple View Geometry C++ library. 2 3 // Copyright (c) 2015 Pierre MOULON. 4 5 // This Source Code Form is subject to the terms of the Mozilla Public 6 // License, v. 2.0. If a copy of the MPL was not distributed with this 7 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 9 #ifndef OPENMVG_SFM_SFM_DATA_FILTERS_FRUSTUM_HPP 10 #define OPENMVG_SFM_SFM_DATA_FILTERS_FRUSTUM_HPP 11 12 #include <string> 13 #include <utility> 14 #include <vector> 15 16 #include "openMVG/geometry/frustum.hpp" 17 #include "openMVG/types.hpp" 18 19 namespace openMVG { namespace sfm { struct SfM_Data; } } 20 21 22 namespace openMVG { 23 namespace sfm { 24 25 struct SfM_Data; 26 27 class Frustum_Filter 28 { 29 public: 30 using FrustumsT = Hash_Map<IndexT, geometry::Frustum>; 31 using NearFarPlanesT = Hash_Map<IndexT, std::pair<double, double>>; 32 33 // Constructor 34 Frustum_Filter 35 ( 36 const SfM_Data & sfm_data, 37 const double zNear = -1., 38 const double zFar = -1., 39 const NearFarPlanesT & z_near_z_far = NearFarPlanesT{} 40 ); 41 42 // Init a frustum for each valid views of the SfM scene 43 void initFrustum(const SfM_Data & sfm_data); 44 45 // Return intersecting View frustum pairs. An optional bounding volume 46 // defined as a vector of half-plane objects can also be provided to further 47 // limit the intersection area. 48 Pair_Set getFrustumIntersectionPairs( 49 const std::vector<geometry::halfPlane::HalfPlaneObject>& bounding_volume = {} 50 ) const; 51 52 // Export defined frustum in PLY file for viewing 53 bool export_Ply(const std::string & filename, bool colorize = false) const; 54 55 private: 56 57 /// Init near and far plane depth from SfM_Data structure or defined value 58 void init_z_near_z_far_depth 59 ( 60 const SfM_Data & sfm_data, 61 const double zNear = -1., 62 const double zFar = -1. 63 ); 64 65 //-- 66 // Data 67 //-- 68 bool _bTruncated; // Tell if we use truncated or infinite frustum 69 70 FrustumsT frustum_perView; // Frustum for the valid view (defined pose+intrinsic) 71 72 NearFarPlanesT z_near_z_far_perView; // Near & Far plane distance per view 73 }; 74 75 } // namespace sfm 76 } // namespace openMVG 77 78 #endif // OPENMVG_SFM_SFM_DATA_FILTERS_FRUSTUM_HPP 79