DGtal 1.4.0
Loading...
Searching...
No Matches
DigitalSurfacePredicate.ih
1/**
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.
6 *
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.
11 *
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/>.
14 *
15 **/
16
17/**
18 * @file
19 * @author Jocelyn Meyron (\c jocelyn.meyron@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21 *
22 * @date 2020/12/07
23 *
24 * Implementation of inline methods defined in DigitalSurfacePredicate.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32//////////////////////////////////////////////////////////////////////////////
33
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
37
38///////////////////////////////////////////////////////////////////////////////
39// ----------------------- Standard services ------------------------------
40
41//-----------------------------------------------------------------------------
42template <typename TSurface>
43inline
44DGtal::DigitalSurfacePredicate<TSurface>::
45DigitalSurfacePredicate ()
46{}
47
48//-----------------------------------------------------------------------------
49template <typename TSurface>
50inline
51DGtal::DigitalSurfacePredicate<TSurface>::
52DigitalSurfacePredicate (ConstAlias<Surface> aSurface)
53 : mySurface(aSurface)
54{
55 buildPointSet();
56}
57
58//-----------------------------------------------------------------------------
59template <typename TSurface>
60inline
61DGtal::DigitalSurfacePredicate<TSurface>::
62DigitalSurfacePredicate (const DigitalSurfacePredicate<TSurface>& other)
63 : mySurface(other.mySurface)
64{
65 buildPointSet();
66}
67
68//-----------------------------------------------------------------------------
69template <typename TSurface>
70inline
71DGtal::DigitalSurfacePredicate<TSurface>&
72DGtal::DigitalSurfacePredicate<TSurface>::operator= (const DigitalSurfacePredicate<TSurface>& other)
73{
74 if (this != &other)
75 {
76 mySurface = other.mySurface;
77 buildPointSet();
78 }
79
80 return *this;
81}
82
83//-----------------------------------------------------------------------------
84template <typename TSurface>
85inline
86DGtal::DigitalSurfacePredicate<TSurface>::
87~DigitalSurfacePredicate ()
88{}
89
90//-------------------- model of concepts::CPointPredicate -----------------------------
91
92//-----------------------------------------------------------------------------
93template <typename TSurface>
94inline
95bool DGtal::DigitalSurfacePredicate<TSurface>::
96operator() (Point const& aPoint) const
97{
98 return myPointSet.count(aPoint) > 0;
99}
100
101// ------------------------- Internals ------------------------------------
102
103//-----------------------------------------------------------------------------
104template <typename TSurface>
105inline
106typename DGtal::DigitalSurfacePredicate<TSurface>::KSpace const&
107DGtal::DigitalSurfacePredicate<TSurface>::space () const
108{
109 return mySurface->container().space();
110}
111
112//-----------------------------------------------------------------------------
113template <typename TSurface>
114inline
115void
116DGtal::DigitalSurfacePredicate<TSurface>::buildPointSet ()
117{
118 myPointSet.clear();
119
120 // Extract all the pointels of the digital surface
121 KSpace const& K = space();
122 for (const auto& f: *mySurface) {
123 typename KSpace::Cells faces = K.uFaces(K.unsigns(f));
124
125 for (const auto& c: faces) {
126 if (K.uDim(c) == 0) {
127 myPointSet.insert(K.uCoords(c));
128 }
129 }
130 }
131}
132
133///////////////////////////////////////////////////////////////////////////////
134// Interface - public :
135
136/**
137 * Writes/Displays the object on an output stream.
138 * @param out the output stream where the object is written.
139 */
140template <typename TSurface>
141inline
142void
143DGtal::DigitalSurfacePredicate<TSurface>::selfDisplay ( std::ostream & out ) const
144{
145 out << "[DigitalSurfacePredicate]";
146}
147
148/**
149 * Checks the validity/consistency of the object.
150 * @return 'true' if the object is valid, 'false' otherwise.
151 */
152template <typename TSurface>
153inline
154bool
155DGtal::DigitalSurfacePredicate<TSurface>::isValid() const
156{
157 return true;
158}
159
160
161
162///////////////////////////////////////////////////////////////////////////////
163// Implementation of inline functions //
164
165template <typename TSurface>
166inline
167std::ostream&
168DGtal::operator<< ( std::ostream & out,
169 const DigitalSurfacePredicate<TSurface> & object )
170{
171 object.selfDisplay( out );
172 return out;
173}
174
175// //
176///////////////////////////////////////////////////////////////////////////////
177
178