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/>.
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
24 * Implementation of inline methods defined in PlaneProbingRNeighborhood.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
41 // ------------------------------------------------------------------------
42 template < typename TPredicate >
44 DGtal::PlaneProbingRNeighborhood<TPredicate>::
45 PlaneProbingRNeighborhood(Predicate const& aPredicate, Point const& aQ, Triangle const& aM)
46 : DGtal::PlaneProbingNeighborhood<TPredicate>(aPredicate, aQ, aM)
49 // ------------------------------------------------------------------------
50 template < typename TPredicate >
52 DGtal::PlaneProbingRNeighborhood<TPredicate>::
53 ~PlaneProbingRNeighborhood()
56 ///////////////////////////////////////////////////////////////////////////////
57 // ----------------------- Plane Probing services ------------------------------
59 // ------------------------------------------------------------------------
60 template < typename TPredicate >
62 typename DGtal::PlaneProbingRNeighborhood<TPredicate>::HexagonState
63 DGtal::PlaneProbingRNeighborhood<TPredicate>::hexagonState ()
65 this->myCandidates.clear();
67 std::array< bool, 6 > state = { false, false, false, false, false, false };
68 for (int i = 0; i < 6; ++i)
70 PointOnProbingRay r = this->myNeighborhood[i].getBase();
72 if (this->isNeighbor(r))
74 state[i] = this->myPredicate(this->absolutePoint(r));
78 PointOnProbingRay pt = closestPointOnRayLogWithPredicate(r.getBase());
80 assert(pt == closestPointOnRayLinearWithPredicate(r.getBase()));
81 assert(this->myPredicate(this->absolutePoint(pt)));
83 this->myCandidates.push_back(pt);
88 return this->classify(state);
91 // ------------------------------------------------------------------------
92 template < typename TPredicate >
93 template < typename TPointAdapter >
96 DGtal::PlaneProbingRNeighborhood<TPredicate>::closestPointOnRayLogWithPredicate (TPointAdapter const& aRay) const
98 assert(this->myPredicate(this->absolutePoint(aRay)));
101 TPointAdapter Xk = aRay, Xl = aRay.next(1);
102 while (this->myPredicate(this->absolutePoint(Xk)) &&
103 this->isSmallest(this->relativePoint(Xk), this->relativePoint(Xl))) {
104 Integer d = Xl.position() - Xk.position();
108 Xk = Xk.previous(Integer((Xl.position() - Xk.position()) / 2));
111 Integer d = Xl.position() - Xk.position();
113 assert(this->myPredicate(this->absolutePoint(Xk)));
115 TPointAdapter Xalpha = Xk.next(Integer(d / 4)),
116 Xbeta = Xk.next(Integer(d / 2)),
117 Xgamma = Xk.next(Integer(3*d/4));
119 assert(Xk.position() < Xalpha.position() && Xalpha.position() < Xbeta.position() &&
120 Xbeta.position() < Xgamma.position() && Xgamma.position() < Xl.position());
122 if (this->myPredicate(this->absolutePoint(Xbeta)) &&
123 this->isSmallest(this->relativePoint(Xbeta), this->relativePoint(Xgamma))) {
125 } else if (! this->myPredicate(this->absolutePoint(Xalpha)) ||
126 this->isSmallest(this->relativePoint(Xbeta), this->relativePoint(Xalpha))) {
133 d = Xl.position() - Xk.position();
136 return closestPointOnRayLinearWithPredicate(Xk);
139 // ------------------------------------------------------------------------
140 template < typename TPredicate >
141 template < typename TPointAdapter >
144 DGtal::PlaneProbingRNeighborhood<TPredicate>::closestPointOnRayLinearWithPredicate (TPointAdapter const& aRay) const
146 assert(this->myPredicate(this->absolutePoint(aRay)));
148 TPointAdapter previousX = aRay, currentX = previousX.next(1);
149 while (this->myPredicate(this->absolutePoint(currentX)) &&
150 this->isSmallest(this->relativePoint(previousX), this->relativePoint(currentX))) {
151 previousX = currentX;
152 currentX = previousX.next(1);
155 assert(this->myPredicate(this->absolutePoint(previousX)));
160 ///////////////////////////////////////////////////////////////////////////////
161 // Interface - public :
164 * Writes/Displays the object on an output stream.
165 * @param out the output stream where the object is written.
167 template <typename TPredicate>
170 DGtal::PlaneProbingRNeighborhood<TPredicate>::selfDisplay ( std::ostream & out ) const
172 out << "[PlaneProbingRNeighborhood]";
176 * Checks the validity/consistency of the object.
177 * @return 'true' if the object is valid, 'false' otherwise.
179 template <typename TPredicate>
182 DGtal::PlaneProbingRNeighborhood<TPredicate>::isValid() const
189 ///////////////////////////////////////////////////////////////////////////////
190 // Implementation of inline functions //
192 template <typename TPredicate>
195 DGtal::operator<< ( std::ostream & out,
196 const PlaneProbingRNeighborhood<TPredicate> & object )
198 object.selfDisplay( out );
203 ///////////////////////////////////////////////////////////////////////////////