DGtal  1.5.beta
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 //-----------------------------------------------------------------------------
42 template <typename TSurface>
43 inline
44 DGtal::DigitalSurfacePredicate<TSurface>::
45 DigitalSurfacePredicate ()
46 {}
47 
48 //-----------------------------------------------------------------------------
49 template <typename TSurface>
50 inline
51 DGtal::DigitalSurfacePredicate<TSurface>::
52 DigitalSurfacePredicate (ConstAlias<Surface> aSurface)
53  : mySurface(aSurface)
54 {
55  buildPointSet();
56 }
57 
58 //-----------------------------------------------------------------------------
59 template <typename TSurface>
60 inline
61 DGtal::DigitalSurfacePredicate<TSurface>::
62 DigitalSurfacePredicate (const DigitalSurfacePredicate<TSurface>& other)
63  : mySurface(other.mySurface)
64 {
65  buildPointSet();
66 }
67 
68 //-----------------------------------------------------------------------------
69 template <typename TSurface>
70 inline
71 DGtal::DigitalSurfacePredicate<TSurface>&
72 DGtal::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 //-----------------------------------------------------------------------------
84 template <typename TSurface>
85 inline
86 DGtal::DigitalSurfacePredicate<TSurface>::
87 ~DigitalSurfacePredicate ()
88 {}
89 
90 //-------------------- model of concepts::CPointPredicate -----------------------------
91 
92 //-----------------------------------------------------------------------------
93 template <typename TSurface>
94 inline
95 bool DGtal::DigitalSurfacePredicate<TSurface>::
96 operator() (Point const& aPoint) const
97 {
98  return myPointSet.count(aPoint) > 0;
99 }
100 
101 // ------------------------- Internals ------------------------------------
102 
103 //-----------------------------------------------------------------------------
104 template <typename TSurface>
105 inline
106 typename DGtal::DigitalSurfacePredicate<TSurface>::KSpace const&
107 DGtal::DigitalSurfacePredicate<TSurface>::space () const
108 {
109  return mySurface->container().space();
110 }
111 
112 //-----------------------------------------------------------------------------
113 template <typename TSurface>
114 inline
115 void
116 DGtal::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  */
140 template <typename TSurface>
141 inline
142 void
143 DGtal::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  */
152 template <typename TSurface>
153 inline
154 bool
155 DGtal::DigitalSurfacePredicate<TSurface>::isValid() const
156 {
157  return true;
158 }
159 
160 
161 
162 ///////////////////////////////////////////////////////////////////////////////
163 // Implementation of inline functions //
164 
165 template <typename TSurface>
166 inline
167 std::ostream&
168 DGtal::operator<< ( std::ostream & out,
169  const DigitalSurfacePredicate<TSurface> & object )
170 {
171  object.selfDisplay( out );
172  return out;
173 }
174 
175 // //
176 ///////////////////////////////////////////////////////////////////////////////
177 
178