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 David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Implementation of inline methods defined in ExactLpSeparableMetric.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 //------------------------------------------------------------------------------
40 template <typename TM>
42 typename DGtal::SeparableMetricAdapter<TM>::Abscissa
43 DGtal::SeparableMetricAdapter<TM>::binarySearchHidden(const Point &u,
45 const typename Point::UnsignedComponent dim,
47 const Point &upper) const
50 if ( (upper[dim] - lower[dim]) <= NumberTraits<Abscissa>::ONE)
53 Value du = myMetric->operator()(u, upper);
54 Value dv = myMetric->operator()(v, upper);
62 mid[dim] = (lower[dim] + upper[dim])/2;
64 Value duUpdated = myMetric->operator()(u, mid);
65 Value dvUpdated = myMetric->operator()(v, mid);
68 if ( duUpdated < dvUpdated)
69 return binarySearchHidden(u,v,dim,mid,upper);
71 return binarySearchHidden(u,v,dim,lower,mid);
74 //------------------------------------------------------------------------------
75 template <typename TM>
78 DGtal::SeparableMetricAdapter<TM>::hiddenBy(const Point &u,
81 const Point &startingPoint,
82 const Point &endPoint,
83 const typename Point::UnsignedComponent dim) const
85 //Abscissa of voronoi edges
87 Value dv,dw,du,ddv,ddw;
89 //checking distances to lower bound
90 du = myMetric->operator()(u, startingPoint);
91 dv = myMetric->operator()(v, startingPoint);
92 dw = myMetric->operator()(w, startingPoint);
94 //Precondition of binarySearchHidden is true
97 uv = binarySearchHidden(u,v,dim,startingPoint,endPoint);
100 vw = binarySearchHidden(v,w,dim,startingPoint,endPoint); //precondition
108 //check if uv + 1 is stricly in W
109 //first, optimisation
110 if (uv == endPoint[dim]) return true;
113 Point p = startingPoint;
115 ddv = myMetric->operator()(v, p);
116 ddw = myMetric->operator()(w, p);
132 //------------------------------------------------------------------------------
133 template <typename TM>
136 DGtal::SeparableMetricAdapter<TM>::selfDisplay ( std::ostream & out ) const
138 out << "[SeparableMetricAdapter] metric="<<myMetric;
140 //------------------------------------------------------------------------------
141 template <typename TM>
144 DGtal::operator<< ( std::ostream & out,
145 const SeparableMetricAdapter<TM> & object )
147 object.selfDisplay( out );