2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file NeighborhoodConfigurations.ih
20 * @author Pablo Hernandez-Cerdan. Institute of Fundamental Sciences.
21 * Massey University. Palmerston North, New Zealand
25 * Implementation of header NeighborhoodConfigurations.h
27 * This file is part of the DGtal library.
31 #include "DGtal/kernel/SpaceND.h"
32 #include "DGtal/kernel/domains/HyperRectDomain.h"
36 /*---------------------------------------------------------------------*/
38 DGtal::CountedPtr< boost::dynamic_bitset<> >
39 loadTable(const std::string &input_filename, unsigned int known_size)
41 using ConfigMap = boost::dynamic_bitset<> ;
42 CountedPtr<ConfigMap> table(new ConfigMap(known_size));
44 std::ifstream text_file(input_filename);
47 } catch(std::exception &e) {
48 throw std::runtime_error("loadTable error in: " + input_filename + " with exception: " + e.what());
54 template<unsigned int N>
56 DGtal::CountedPtr< boost::dynamic_bitset<> >
57 loadTable(const std::string &input_filename)
59 if (N == 3) // Default
60 return loadTable(input_filename, 67108864);
62 return loadTable(input_filename, 256);
63 throw std::domain_error("loadTable<N> error, template parameter N = "
64 + std::to_string(N) + " is invalid (use N = 2 or N = 3)");
68 /*---------------------------------------------------------------------*/
70 template<typename TPoint>
73 std::unordered_map<TPoint, NeighborhoodConfiguration > >
74 mapZeroPointNeighborhoodToConfigurationMask()
76 using Map = std::unordered_map<TPoint, NeighborhoodConfiguration> ;
77 NeighborhoodConfiguration mask = 1 ;
78 CountedPtr<Map> mapPtr(new Map);
80 auto p1 = TPoint::diagonal(-1);
81 auto p2 = TPoint::diagonal(1);
82 auto center = TPoint::diagonal(0);
83 // HyperRect Domain with lexicograpicOrder ensures same order.
84 using Space = SpaceND< TPoint::dimension , DGtal::int32_t>;
85 using Domain = HyperRectDomain< Space >;
87 for (typename Domain::ConstIterator it = domain.begin(), itE = domain.end() ;
90 if (*it == center ) continue;
98 } // namespace functions