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/>.
18 * @file ContourHelper.ih
19 * @author Bertrand Kerautret (\c kerautre@loria.fr )
20 * LORIA (CNRS, UMR 7503), University of Nancy, France
24 * Implementation of inline methods defined in ContourHelper.h
26 * This file is part of the DGtal library.
29 ///////////////////////////////////////////////////////////////////////////////
30 // IMPLEMENTATION of inline methods.
31 ///////////////////////////////////////////////////////////////////////////////
33 //////////////////////////////////////////////////////////////////////////////
35 #include "DGtal/geometry/curves/FreemanChain.h"
36 //////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
41 // Implementation of inline methods //
45 template <typename TPoint>
47 DGtal::PointVector<TPoint::dimension, double>
48 DGtal::ContourHelper::getBarycenter(const std::vector<TPoint> & aSet)
50 DGtal::PointVector<TPoint::dimension, double> ptMean;
51 for(unsigned int i =0; i<aSet.size(); i++)
53 for(typename TPoint::Dimension j=0; j < TPoint::dimension; j++)
55 ptMean[j] += static_cast<double>(aSet.at(i)[j]);
58 for(unsigned int j=0; j < TPoint::dimension; j++)
60 ptMean[j] /= aSet.size();
70 template <typename TIterator, typename TOutputIterator>
73 DGtal::ContourHelper::pixels2pixels8C(const TIterator &itb, const TIterator &ite,
78 auto size = std::distance(itb, ite);
83 short code = FreemanChain<int>::freemanCode4C((*(it+1))[0]-(*it)[0],(*(it+1))[1]-(*it)[1]);
84 short codeNext = FreemanChain<int>::freemanCode4C((*(it+2))[0]-(*(it+1))[0],(*(it+2))[1]-(*(it+1))[1]);
85 if((code != 8 && codeNext != 8) && (((4+(int)codeNext-(int)code)%4)==1 || ((4+(int)codeNext-(int)code)%4)==3))
99 template <typename TPoint>
102 DGtal::ContourHelper::isCounterClockWise(const std::vector<TPoint> & aCurve)
105 TPoint p0 = *(aCurve.begin());
106 typename std::vector<TPoint>::const_iterator itContour = aCurve.begin();
110 for( ; itContour!=aCurve.end(); itContour++)
112 TPoint pSuiv = *itContour;
113 typename TPoint::Coordinate v1x = p[0] - p0[0];
114 typename TPoint::Coordinate v1y = p[1] - p0[1];
115 typename TPoint::Coordinate v2x = pSuiv[0] - p[0];
116 typename TPoint::Coordinate v2y = pSuiv[1] - p[1];
117 sum+=(v1x*v2y)-(v2x*v1y);
127 ///////////////////////////////////////////////////////////////////////////////
128 // Implementation of inline functions and external operators //
131 * Overloads 'operator<<' for displaying objects of class 'ContourHelper'.
132 * @param out the output stream where the object is written.
133 * @param object the object of class 'ContourHelper' to write.
134 * @return the output stream after the writing.
138 DGtal::operator<< ( std::ostream & out,
139 const ContourHelper & object )
141 object.selfDisplay ( out );
146 ///////////////////////////////////////////////////////////////////////////////