Beatmup
contours.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "../geometry.h"
21 #include "../bitmap/abstract_bitmap.h"
22 #include "../bitmap/bitmap_access.h"
23 #include "../bitmap/mask_bitmap_access.h"
24 #include "../exception.h"
25 #include <vector>
26 #include <mutex>
27 
28 namespace Beatmup {
29 
30  /**
31  A sequence of integer-valued 2D points
32  */
34  private:
35  std::vector<IntPoint> points;
36  float
39  public:
41 
42  /**
43  Adds a new point to the end of the contour. Some points may be skipped to optimize the storage.
44  \param x new point X coordinate
45  \param y new point Y coordinate
46  */
47  void addPoint(int x, int y);
48 
49 
50  /**
51  Removes contour content
52  */
53  void clear();
54 
55 
56  /**
57  \return number of points in the contour.
58  */
59  int getPointCount() const { return (int)points.size(); };
60 
61 
62  float getLength() const { return totalLength; };
63 
64 
65  /**
66  \return a point by its index
67  */
68  inline IntPoint getPoint(int index) const { return points[index % points.size()]; };
69 
70  /**
71  Discovers an area boundary in a bitmap following a level curve, starting from a given set of points
72  \param boundary vector to put connected components of the detected boundary to
73  \param bitmap the bitmap to discover
74  \param border the starting points
75  \param testedPixels a writer of a binary mask bitmap marking pixels that are already processed
76  \param level the level of the curve
77  \returns a vector of all the contours limiting the area
78  */
79  static void computeBoundary(
80  std::vector<IntegerContour2D*>& boundary,
82  std::vector<IntPoint>& border,
83  BinaryMaskWriter& testedPixels,
84  float level = 0.5f
85  );
86 
87 
88  class BadSeedPoint : public Exception {
89  public:
90  BadSeedPoint() : Exception("Bad seeds: no border points found")
91  {}
92 
93  BadSeedPoint(int x, int y, bool lefttop, bool righttop, bool leftbottom, bool rightbottom):
94  Exception("Bad seed (%d,%d), pattern:\n %d%d\n %d%d\n", x, y, lefttop, righttop, leftbottom, rightbottom)
95  {}
96  };
97  };
98 }
A very basic class for any image.
Base class for all exceptions.
Definition: exception.h:37
BadSeedPoint(int x, int y, bool lefttop, bool righttop, bool leftbottom, bool rightbottom)
Definition: contours.h:93
A sequence of integer-valued 2D points.
Definition: contours.h:33
static void computeBoundary(std::vector< IntegerContour2D * > &boundary, AbstractBitmap &bitmap, std::vector< IntPoint > &border, BinaryMaskWriter &testedPixels, float level=0.5f)
Discovers an area boundary in a bitmap following a level curve, starting from a given set of points.
Definition: contours.cpp:166
float getLength() const
Definition: contours.h:62
IntPoint getPoint(int index) const
Definition: contours.h:68
void clear()
Removes contour content.
Definition: contours.cpp:171
std::vector< IntPoint > points
Definition: contours.h:35
int getPointCount() const
Definition: contours.h:59
void addPoint(int x, int y)
Adds a new point to the end of the contour.
Definition: contours.cpp:137
A generic to write mask bitmap data lookup tables for masks values.
jlong jint index
jobject jlong jint jint y
jobject jlong jint x
Beatmup::InternalBitmap * bitmap