Beatmup
Beatmup::IntegerContour2D Class Reference

A sequence of integer-valued 2D points. More...

#include <contours.h>

Classes

class  BadSeedPoint
 

Public Member Functions

 IntegerContour2D ()
 
void addPoint (int x, int y)
 Adds a new point to the end of the contour. More...
 
void clear ()
 Removes contour content. More...
 
int getPointCount () const
 
float getLength () const
 
IntPoint getPoint (int index) const
 

Static Public Member Functions

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. More...
 

Private Attributes

std::vector< IntPointpoints
 
float totalLength
 
float lastFragmentLength
 

Detailed Description

A sequence of integer-valued 2D points.

Definition at line 33 of file contours.h.

Constructor & Destructor Documentation

◆ IntegerContour2D()

IntegerContour2D::IntegerContour2D ( )

Definition at line 132 of file contours.cpp.

132  :
133  totalLength(0.0f), lastFragmentLength(0.0f)
134 {}

Member Function Documentation

◆ addPoint()

void IntegerContour2D::addPoint ( int  x,
int  y 
)

Adds a new point to the end of the contour.

Some points may be skipped to optimize the storage.

Parameters
xnew point X coordinate
ynew point Y coordinate

Definition at line 137 of file contours.cpp.

137  {
138  // check for update
139  if (points.size() > 2) {
140  IntPoint& p1 = points.back();
141  IntPoint p2 = points[points.size() - 2];
142  if (
143  (std::max(abs(x - p1.x), abs(y - p1.y)) <= 1 && std::max(abs(x - p2.x), abs(y - p2.y)) <= 1) ||
144  (x != p1.x && (p1.y - y) * (p2.x - p1.x) == (p2.y - p1.y) * (p1.x - x)) ||
145  (y != p1.y && (p1.x - x) * (p2.y - p1.y) == (p2.x - p1.x) * (p1.y - y))
146  ) {
147  // update the last point in this case, not to add a new one
148  p1.x = x;
149  p1.y = y;
151  lastFragmentLength = std::sqrt((float)(p1 - p2).hypot2());
153  return;
154  }
155  if (x == p1.x && y == p1.y)
156  return; //p1 == (x,y)
157  }
158 
159  // adding the new point
160  IntPoint p(x, y);
161  points.push_back(p);
162  lastFragmentLength = 0;
163 }
std::vector< IntPoint > points
Definition: contours.h:35
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:728
jobject jlong jint jint y
jobject jlong jint x
Beatmup::IntPoint p((int) x,(int) y)

◆ clear()

void IntegerContour2D::clear ( )

Removes contour content.

Definition at line 171 of file contours.cpp.

171  {
172  points.clear();
174 }

◆ getPointCount()

int Beatmup::IntegerContour2D::getPointCount ( ) const
inline
Returns
number of points in the contour.

Definition at line 59 of file contours.h.

59 { return (int)points.size(); };

◆ getLength()

float Beatmup::IntegerContour2D::getLength ( ) const
inline

Definition at line 62 of file contours.h.

62 { return totalLength; };

◆ getPoint()

IntPoint Beatmup::IntegerContour2D::getPoint ( int  index) const
inline
Returns
a point by its index

Definition at line 68 of file contours.h.

68 { return points[index % points.size()]; };
jlong jint index

◆ computeBoundary()

void IntegerContour2D::computeBoundary ( std::vector< IntegerContour2D * > &  boundary,
AbstractBitmap bitmap,
std::vector< IntPoint > &  border,
BinaryMaskWriter testedPixels,
float  level = 0.5f 
)
static

Discovers an area boundary in a bitmap following a level curve, starting from a given set of points.

Parameters
boundaryvector to put connected components of the detected boundary to
bitmapthe bitmap to discover
borderthe starting points
testedPixelsa writer of a binary mask bitmap marking pixels that are already processed
levelthe level of the curve
Returns
a vector of all the contours limiting the area

Definition at line 166 of file contours.cpp.

166  {
167  BitmapProcessing::read<Kernels::ComputeBounds>(bitmap, boundary, border, testedPixels, level);
168 }
Beatmup::InternalBitmap * bitmap

Member Data Documentation

◆ points

std::vector<IntPoint> Beatmup::IntegerContour2D::points
private

Definition at line 35 of file contours.h.

◆ totalLength

float Beatmup::IntegerContour2D::totalLength
private

Definition at line 37 of file contours.h.

◆ lastFragmentLength

float Beatmup::IntegerContour2D::lastFragmentLength
private

Definition at line 38 of file contours.h.


The documentation for this class was generated from the following files: