GJK_nD
 All Classes Files Functions Typedefs Friends Pages
BoundariesExtractor.hpp
1 /*
2  * Copyright (c) 2012 Laurent Provot <provot.research@gmail.com>,
3  * Yan Gerard <yan.gerard@free.fr> and Fabien Feschet <research@feschet.fr>
4  * All rights reserved.
5  *
6  * This is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef UTILS_BOUNDARIES_EXTRACTOR_HPP
21 #define UTILS_BOUNDARIES_EXTRACTOR_HPP
22 
23 #include <vector>
24 #include <utility>
25 #include "Array2D.hpp"
26 #include "png++/png.hpp"
27 
28 namespace Utils {
29 
68 {
69 public:
71  typedef std::pair<size_t, size_t> Coordinates;
73  typedef std::vector<Coordinates> Curve;
75  typedef png::image<png::gray_pixel> Image;
76 
77 public:
82  BoundariesExtractor(const Image * image = 0) : myImage(image) {}
84 
88  void setImage(const Image * image) { myImage = image; }
89 
95  std::vector<Curve> extractBoundaries();
96 
101  std::vector<Curve> extractBoundaries(const Image & image)
102  {
103  std::vector<Curve> result;
104  const Image * myImageBak = myImage;
105  setImage(&image);
106  result = extractBoundaries();
107  myImage = myImageBak;
108  return result;
109  }
110 
111 private:
112  enum Direction {Horizontal, Vertical};
113 
114  void color4ConnectedComponent(Coordinates coords, png::gray_pixel label,
115  const Image & inputImage,
116  Image & outputImage);
117 
118  Image color4ConnectedComponents(const Image & inputImage);
119 
120  void trackNextEgde(Direction direction, size_t i, size_t j, int color,
121  Curve & result);
122 
123 private:
125  BoundariesExtractor & operator=(const BoundariesExtractor &);
126 
127 private:
128  const Image * myImage;
129 
130  Utils::Array2D<int> verticalEdge;
131  Utils::Array2D<int> horizontalEdge;
132 };
133 
134 } // namespace Utils
135 
136 #endif // UTILS_BOUNDARIES_EXTRACTOR_HPP