DGtal  1.5.beta
DigitalPlanePredicate.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/03
23  *
24  * Implementation of inline methods defined in DigitalPlanePredicate.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 TSpace>
43 inline
44 DGtal::DigitalPlanePredicate<TSpace>::
45 DigitalPlanePredicate (Vector const& aNormal, Integer const& aMu, Integer const& aNu)
46  : myNormal(aNormal), myMu(aMu), myNu(aNu)
47 {}
48 
49 //-----------------------------------------------------------------------------
50 template <typename TSpace>
51 inline
52 DGtal::DigitalPlanePredicate<TSpace>::
53 DigitalPlanePredicate (const DGtal::DigitalPlanePredicate<TSpace> & other)
54  : myNormal(other.normal()), myMu(other.mu()), myNu(other.nu())
55 {}
56 
57 //-----------------------------------------------------------------------------
58 template <typename TSpace>
59 inline
60 DGtal::DigitalPlanePredicate<TSpace>::
61 DigitalPlanePredicate (DGtal::DigitalPlanePredicate<TSpace> && other)
62  : myNormal(other.normal()), myMu(other.mu()), myNu(other.nu())
63 {}
64 
65 //-----------------------------------------------------------------------------
66 template <typename TSpace>
67 inline
68 DGtal::DigitalPlanePredicate<TSpace>&
69 DGtal::DigitalPlanePredicate<TSpace>::operator= (const DGtal::DigitalPlanePredicate<TSpace> & other)
70 {
71  if (this != &other)
72  {
73  myNormal = other.normal();
74  myMu = other.mu();
75  myNu = other.nu();
76  }
77 
78  return *this;
79 }
80 
81 //-----------------------------------------------------------------------------
82 template <typename TSpace>
83 inline
84 DGtal::DigitalPlanePredicate<TSpace>&
85 DGtal::DigitalPlanePredicate<TSpace>::operator= (DGtal::DigitalPlanePredicate<TSpace> && other)
86 {
87  myNormal = other.normal();
88  myMu = other.mu();
89  myNu = other.nu();
90 
91  return *this;
92 }
93 
94 ///////////////////////////////////////////////////////////////////////////////
95 //-------------------- plane services -----------------------------
96 
97 //-----------------------------------------------------------------------------
98 template <typename TSpace>
99 inline
100 typename DGtal::DigitalPlanePredicate<TSpace>::Vector const&
101 DGtal::DigitalPlanePredicate<TSpace>::normal () const
102 {
103  return myNormal;
104 }
105 
106 //-----------------------------------------------------------------------------
107 template <typename TSpace>
108 inline
109 typename DGtal::DigitalPlanePredicate<TSpace>::Integer
110 DGtal::DigitalPlanePredicate<TSpace>::mu () const
111 {
112  return myMu;
113 }
114 
115 //-----------------------------------------------------------------------------
116 template <typename TSpace>
117 inline
118 typename DGtal::DigitalPlanePredicate<TSpace>::Integer
119 DGtal::DigitalPlanePredicate<TSpace>::nu () const
120 {
121  return myNu;
122 }
123 
124 ///////////////////////////////////////////////////////////////////////////////
125 //-------------------- model of concepts::CPointPredicate -----------------------------
126 
127 //-----------------------------------------------------------------------------
128 template <typename TSpace>
129 inline
130 bool DGtal::DigitalPlanePredicate<TSpace>::
131 operator() (Point const& aPoint) const
132 {
133  Integer height = aPoint.dot(myNormal);
134  return (height >= mu() && height < mu() + nu());
135 }
136 
137 ///////////////////////////////////////////////////////////////////////////////
138 // Interface - public :
139 
140 /**
141  * Writes/Displays the object on an output stream.
142  * @param out the output stream where the object is written.
143  */
144 template <typename TSpace>
145 inline
146 void
147 DGtal::DigitalPlanePredicate<TSpace>::selfDisplay ( std::ostream & out ) const
148 {
149  out << "[DigitalPlanePredicate ";
150  out << mu() << " <= ";
151  out << "(" << myNormal[0];
152  for (Dimension i = 1; i < TSpace::dimension; ++i) {
153  out << ", " << myNormal[i];
154  }
155  out << ").X";
156  out << " < " << (mu() + nu());
157  out << " ]";
158 }
159 
160 /**
161  * Checks the validity/consistency of the object.
162  * @return 'true' if the object is valid, 'false' otherwise.
163  */
164 template <typename TSpace>
165 inline
166 bool
167 DGtal::DigitalPlanePredicate<TSpace>::isValid() const
168 {
169  return normal().norm1() > NumberTraits<Integer>::ZERO;
170 }
171 
172 
173 
174 ///////////////////////////////////////////////////////////////////////////////
175 // Implementation of inline functions //
176 
177 template <typename TSpace>
178 inline
179 std::ostream&
180 DGtal::operator<< ( std::ostream & out,
181  const DigitalPlanePredicate<TSpace> & object )
182 {
183  object.selfDisplay( out );
184  return out;
185 }
186 
187 // //
188 ///////////////////////////////////////////////////////////////////////////////
189 
190