Coord: Rename to Vector2
The class is not only used to represent coordinates but also lengths in XY. Vector2 is a more fitting/general name for this purpose.
This commit is contained in:
parent
3fc3a81286
commit
60db1c2eaf
41
src/zm_box.h
41
src/zm_box.h
|
@ -20,7 +20,7 @@
|
|||
#ifndef ZM_BOX_H
|
||||
#define ZM_BOX_H
|
||||
|
||||
#include "zm_coord.h"
|
||||
#include "zm_vector2.h"
|
||||
#include <cmath>
|
||||
|
||||
//
|
||||
|
@ -28,40 +28,39 @@
|
|||
// defined by two coordinates
|
||||
//
|
||||
class Box {
|
||||
private:
|
||||
Coord lo, hi;
|
||||
Coord size;
|
||||
private:
|
||||
Vector2 lo, hi;
|
||||
Vector2 size;
|
||||
|
||||
public:
|
||||
inline Box() : lo(0,0), hi(0,0), size(0,0) { }
|
||||
explicit inline Box(unsigned int p_size) : lo(0, 0), hi(p_size-1, p_size-1), size(Coord::Range(hi, lo)) { }
|
||||
inline Box( int p_x_size, int p_y_size ) : lo( 0, 0 ), hi ( p_x_size-1, p_y_size-1 ), size( Coord::Range( hi, lo ) ) { }
|
||||
inline Box( int lo_x, int lo_y, int hi_x, int hi_y ) : lo( lo_x, lo_y ), hi( hi_x, hi_y ), size( Coord::Range( hi, lo ) ) { }
|
||||
inline Box( const Coord &p_lo, const Coord &p_hi ) : lo( p_lo ), hi( p_hi ), size( Coord::Range( hi, lo ) ) { }
|
||||
public:
|
||||
inline Box() : lo(0, 0), hi(0, 0), size(0, 0) {}
|
||||
explicit inline Box(unsigned int p_size) : lo(0, 0), hi(p_size - 1, p_size - 1), size(Vector2::Range(hi, lo)) {}
|
||||
inline Box(int p_x_size, int p_y_size) : lo(0, 0), hi(p_x_size - 1, p_y_size - 1), size(Vector2::Range(hi, lo)) {}
|
||||
inline Box(int lo_x, int lo_y, int hi_x, int hi_y) : lo(lo_x, lo_y), hi(hi_x, hi_y), size(Vector2::Range(hi, lo)) {}
|
||||
inline Box(const Vector2 &p_lo, const Vector2 &p_hi) : lo(p_lo), hi(p_hi), size(Vector2::Range(hi, lo)) {}
|
||||
|
||||
inline const Coord &Lo() const { return lo; }
|
||||
inline const Vector2 &Lo() const { return lo; }
|
||||
inline int LoX() const { return lo.X(); }
|
||||
inline int LoX(int p_lo_x) { return lo.X(p_lo_x); }
|
||||
inline int LoY() const { return lo.Y(); }
|
||||
inline int LoY(int p_lo_y) { return lo.Y(p_lo_y); }
|
||||
inline const Coord &Hi() const { return hi; }
|
||||
inline const Vector2 &Hi() const { return hi; }
|
||||
inline int HiX() const { return hi.X(); }
|
||||
inline int HiX(int p_hi_x) { return hi.X(p_hi_x); }
|
||||
inline int HiY() const { return hi.Y(); }
|
||||
inline int HiY(int p_hi_y) { return hi.Y(p_hi_y); }
|
||||
inline const Coord &Size() const { return size; }
|
||||
inline const Vector2 &Size() const { return size; }
|
||||
inline int Width() const { return size.X(); }
|
||||
inline int Height() const { return size.Y(); }
|
||||
inline int Area() const { return size.X()*size.Y(); }
|
||||
inline int Area() const { return size.X() * size.Y(); }
|
||||
|
||||
inline const Coord Centre() const {
|
||||
int mid_x = int(std::round(lo.X()+(size.X()/2.0)));
|
||||
int mid_y = int(std::round(lo.Y()+(size.Y()/2.0)));
|
||||
return Coord( mid_x, mid_y );
|
||||
inline const Vector2 Centre() const {
|
||||
int mid_x = int(std::round(lo.X() + (size.X() / 2.0)));
|
||||
int mid_y = int(std::round(lo.Y() + (size.Y() / 2.0)));
|
||||
return Vector2(mid_x, mid_y);
|
||||
}
|
||||
inline bool Inside( const Coord &coord ) const
|
||||
{
|
||||
return( coord.X() >= lo.X() && coord.X() <= hi.X() && coord.Y() >= lo.Y() && coord.Y() <= hi.Y() );
|
||||
inline bool Inside(const Vector2 &coord) const {
|
||||
return (coord.X() >= lo.X() && coord.X() <= hi.X() && coord.Y() >= lo.Y() && coord.Y() <= hi.Y());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
//
|
||||
// ZoneMinder Coordinate Class Interface, $Date$, $Revision$
|
||||
// Copyright (C) 2001-2008 Philip Coombes
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
#ifndef ZM_COORD_H
|
||||
#define ZM_COORD_H
|
||||
|
||||
#include "zm_define.h"
|
||||
|
||||
//
|
||||
// Class used for storing an x,y pair, i.e. a coordinate
|
||||
//
|
||||
class Coord {
|
||||
private:
|
||||
int x, y;
|
||||
|
||||
public:
|
||||
inline Coord() : x(0), y(0) { }
|
||||
inline Coord( int p_x, int p_y ) : x(p_x), y(p_y) { }
|
||||
inline Coord( const Coord &p_coord ) : x(p_coord.x), y(p_coord.y) { }
|
||||
inline Coord &operator =( const Coord &coord ) {
|
||||
x = coord.x;
|
||||
y = coord.y;
|
||||
return *this;
|
||||
}
|
||||
inline int &X(int p_x) { x=p_x; return x; }
|
||||
inline const int &X() const { return x; }
|
||||
inline int &Y(int p_y) { y=p_y; return y; }
|
||||
inline const int &Y() const { return y; }
|
||||
|
||||
inline static Coord Range( const Coord &coord1, const Coord &coord2 ) {
|
||||
Coord result( (coord1.x-coord2.x)+1, (coord1.y-coord2.y)+1 );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline bool operator==( const Coord &coord ) const { return( x == coord.x && y == coord.y ); }
|
||||
inline bool operator!=( const Coord &coord ) const { return( x != coord.x || y != coord.y ); }
|
||||
inline bool operator>( const Coord &coord ) const { return( x > coord.x && y > coord.y ); }
|
||||
inline bool operator>=( const Coord &coord ) const { return( !(operator<(coord)) ); }
|
||||
inline bool operator<( const Coord &coord ) const { return( x < coord.x && y < coord.y ); }
|
||||
inline bool operator<=( const Coord &coord ) const { return( !(operator>(coord)) ); }
|
||||
inline Coord &operator+=( const Coord &coord ) { x += coord.x; y += coord.y; return( *this ); }
|
||||
inline Coord &operator-=( const Coord &coord ) { x -= coord.x; y -= coord.y; return( *this ); }
|
||||
|
||||
inline friend Coord operator+( const Coord &coord1, const Coord &coord2 ) { Coord result( coord1 ); result += coord2; return( result ); }
|
||||
inline friend Coord operator-( const Coord &coord1, const Coord &coord2 ) { Coord result( coord1 ); result -= coord2; return( result ); }
|
||||
};
|
||||
|
||||
#endif // ZM_COORD_H
|
|
@ -250,7 +250,7 @@ int Image::PopulateFrame(AVFrame *frame) {
|
|||
width, height, linesize, colours, size,
|
||||
av_get_pix_fmt_name(imagePixFormat)
|
||||
);
|
||||
AVBufferRef *ref = av_buffer_create(buffer, size,
|
||||
AVBufferRef *ref = av_buffer_create(buffer, size,
|
||||
dont_free, /* Free callback */
|
||||
nullptr, /* opaque */
|
||||
0 /* flags */
|
||||
|
@ -576,7 +576,7 @@ void Image::Initialise() {
|
|||
if ( res == FontLoadError::kFileNotFound ) {
|
||||
Panic("Invalid font location: %s", config.font_file_location);
|
||||
} else if ( res == FontLoadError::kInvalidFile ) {
|
||||
Panic("Invalid font file.");
|
||||
Panic("Invalid font file.");
|
||||
}
|
||||
initialised = true;
|
||||
}
|
||||
|
@ -781,7 +781,7 @@ void Image::Assign(const Image &image) {
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
if ( new_size > allocation || !buffer ) {
|
||||
if (new_size > allocation || !buffer) {
|
||||
// DumpImgBuffer(); This is also done in AllocImgBuffer
|
||||
AllocImgBuffer(new_size);
|
||||
}
|
||||
|
@ -1932,7 +1932,7 @@ void Image::Delta(const Image &image, Image* targetimage) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
const Coord Image::centreCoord( const char *text, int size=1 ) const {
|
||||
const Vector2 Image::centreCoord(const char *text, int size = 1) const {
|
||||
int index = 0;
|
||||
int line_no = 0;
|
||||
int text_len = strlen(text);
|
||||
|
@ -1957,7 +1957,7 @@ const Coord Image::centreCoord( const char *text, int size=1 ) const {
|
|||
uint16_t char_height = font_variant.GetCharHeight();
|
||||
int x = (width - (max_line_len * char_width )) / 2;
|
||||
int y = (height - (line_no * char_height) ) / 2;
|
||||
return Coord(x, y);
|
||||
return {x, y};
|
||||
}
|
||||
|
||||
/* RGB32 compatible: complete */
|
||||
|
@ -2007,7 +2007,7 @@ https://lemire.me/blog/2018/02/21/iterating-over-set-bits-quickly/
|
|||
*/
|
||||
void Image::Annotate(
|
||||
const std::string &text,
|
||||
const Coord &coord,
|
||||
const Vector2 &coord,
|
||||
const uint8 size,
|
||||
const Rgb fg_colour,
|
||||
const Rgb bg_colour) {
|
||||
|
@ -2127,7 +2127,7 @@ void Image::Annotate(
|
|||
}
|
||||
}
|
||||
|
||||
void Image::Timestamp( const char *label, const time_t when, const Coord &coord, const int size ) {
|
||||
void Image::Timestamp(const char *label, const time_t when, const Vector2 &coord, const int size) {
|
||||
char time_text[64];
|
||||
tm when_tm = {};
|
||||
strftime(time_text, sizeof(time_text), "%y/%m/%d %H:%M:%S", localtime_r(&when, &when_tm));
|
||||
|
@ -2386,8 +2386,8 @@ void Image::Outline( Rgb colour, const Polygon &polygon ) {
|
|||
|
||||
int n_coords = polygon.getNumCoords();
|
||||
for ( int j = 0, i = n_coords-1; j < n_coords; i = j++ ) {
|
||||
const Coord &p1 = polygon.getCoord( i );
|
||||
const Coord &p2 = polygon.getCoord( j );
|
||||
const Vector2 &p1 = polygon.getCoord(i);
|
||||
const Vector2 &p2 = polygon.getCoord(j);
|
||||
|
||||
int x1 = p1.X();
|
||||
int x2 = p2.X();
|
||||
|
@ -2470,8 +2470,8 @@ void Image::Fill(Rgb colour, int density, const Polygon &polygon) {
|
|||
int n_global_edges = 0;
|
||||
Edge global_edges[n_coords];
|
||||
for ( int j = 0, i = n_coords-1; j < n_coords; i = j++ ) {
|
||||
const Coord &p1 = polygon.getCoord(i);
|
||||
const Coord &p2 = polygon.getCoord(j);
|
||||
const Vector2 &p1 = polygon.getCoord(i);
|
||||
const Vector2 &p2 = polygon.getCoord(j);
|
||||
|
||||
int x1 = p1.X();
|
||||
int x2 = p2.X();
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
#ifndef ZM_IMAGE_H
|
||||
#define ZM_IMAGE_H
|
||||
|
||||
#include "zm_coord.h"
|
||||
#include "zm_ffmpeg.h"
|
||||
#include "zm_jpeg.h"
|
||||
#include "zm_logger.h"
|
||||
#include "zm_mem_utils.h"
|
||||
#include "zm_rgb.h"
|
||||
#include "zm_vector2.h"
|
||||
|
||||
#if HAVE_ZLIB_H
|
||||
#include <zlib.h>
|
||||
|
@ -280,16 +280,16 @@ class Image {
|
|||
//Image *Delta( const Image &image ) const;
|
||||
void Delta( const Image &image, Image* targetimage) const;
|
||||
|
||||
const Coord centreCoord(const char *text, const int size) const;
|
||||
const Vector2 centreCoord(const char *text, const int size) const;
|
||||
void MaskPrivacy( const unsigned char *p_bitmask, const Rgb pixel_colour=0x00222222 );
|
||||
void Annotate(const std::string &text,
|
||||
const Coord &coord,
|
||||
const Vector2 &coord,
|
||||
uint8 size = 1,
|
||||
Rgb fg_colour = kRGBWhite,
|
||||
Rgb bg_colour = kRGBBlack);
|
||||
Image *HighlightEdges( Rgb colour, unsigned int p_colours, unsigned int p_subpixelorder, const Box *limits=0 );
|
||||
//Image *HighlightEdges( Rgb colour, const Polygon &polygon );
|
||||
void Timestamp( const char *label, const time_t when, const Coord &coord, const int size );
|
||||
void Timestamp(const char *label, const time_t when, const Vector2 &coord, const int size);
|
||||
void Colourise(const unsigned int p_reqcolours, const unsigned int p_reqsubpixelorder);
|
||||
void DeColourise();
|
||||
|
||||
|
|
|
@ -327,7 +327,7 @@ Monitor::Monitor()
|
|||
record_audio(0),
|
||||
//event_prefix
|
||||
//label_format
|
||||
label_coord(Coord(0,0)),
|
||||
label_coord(Vector2(0,0)),
|
||||
label_size(0),
|
||||
image_buffer_count(0),
|
||||
max_image_buffer_count(0),
|
||||
|
@ -561,7 +561,7 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) {
|
|||
/* "EventPrefix, LabelFormat, LabelX, LabelY, LabelSize," */
|
||||
event_prefix = dbrow[col] ? dbrow[col] : ""; col++;
|
||||
label_format = dbrow[col] ? ReplaceAll(dbrow[col], "\\n", "\n") : ""; col++;
|
||||
label_coord = Coord(atoi(dbrow[col]), atoi(dbrow[col+1])); col += 2;
|
||||
label_coord = Vector2(atoi(dbrow[col]), atoi(dbrow[col + 1])); col += 2;
|
||||
label_size = atoi(dbrow[col]); col++;
|
||||
|
||||
/* "ImageBufferCount, `MaxImageBufferCount`, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, " */
|
||||
|
@ -2832,7 +2832,7 @@ unsigned int Monitor::DetectMotion(const Image &comp_image, Event::StringSet &zo
|
|||
} // end if CheckAlarms
|
||||
} // end foreach zone
|
||||
|
||||
Coord alarm_centre;
|
||||
Vector2 alarm_centre;
|
||||
int top_score = -1;
|
||||
|
||||
if (alarm) {
|
||||
|
|
|
@ -305,7 +305,7 @@ protected:
|
|||
|
||||
std::string event_prefix; // The prefix applied to event names as they are created
|
||||
std::string label_format; // The format of the timestamp on the images
|
||||
Coord label_coord; // The coordinates of the timestamp on the images
|
||||
Vector2 label_coord; // The coordinates of the timestamp on the images
|
||||
int label_size; // Size of the timestamp on the images
|
||||
int32_t image_buffer_count; // Size of circular image buffer, kept in /dev/shm
|
||||
int32_t max_image_buffer_count; // Max # of video packets to keep in packet queue
|
||||
|
|
|
@ -23,58 +23,59 @@
|
|||
|
||||
void Polygon::calcArea() {
|
||||
double float_area = 0.0L;
|
||||
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
|
||||
double trap_area = ((coords[i].X()-coords[j].X())*((coords[i].Y()+coords[j].Y())))/2.0L;
|
||||
for (int i = 0, j = n_coords - 1; i < n_coords; j = i++) {
|
||||
double trap_area = ((coords[i].X() - coords[j].X()) * ((coords[i].Y() + coords[j].Y()))) / 2.0L;
|
||||
float_area += trap_area;
|
||||
//printf( "%.2f (%.2f)\n", float_area, trap_area );
|
||||
}
|
||||
area = (int)round(fabs(float_area));
|
||||
area = (int) round(fabs(float_area));
|
||||
}
|
||||
|
||||
void Polygon::calcCentre() {
|
||||
if ( !area && n_coords )
|
||||
if (!area && n_coords)
|
||||
calcArea();
|
||||
double float_x = 0.0L, float_y = 0.0L;
|
||||
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
|
||||
float_x += ((coords[i].Y()-coords[j].Y())*((coords[i].X()*2)+(coords[i].X()*coords[j].X())+(coords[j].X()*2)));
|
||||
float_y += ((coords[j].X()-coords[i].X())*((coords[i].Y()*2)+(coords[i].Y()*coords[j].Y())+(coords[j].Y()*2)));
|
||||
for (int i = 0, j = n_coords - 1; i < n_coords; j = i++) {
|
||||
float_x += ((coords[i].Y() - coords[j].Y())
|
||||
* ((coords[i].X() * 2) + (coords[i].X() * coords[j].X()) + (coords[j].X() * 2)));
|
||||
float_y += ((coords[j].X() - coords[i].X())
|
||||
* ((coords[i].Y() * 2) + (coords[i].Y() * coords[j].Y()) + (coords[j].Y() * 2)));
|
||||
}
|
||||
float_x /= (6*area);
|
||||
float_y /= (6*area);
|
||||
centre = Coord( (int)round(float_x), (int)round(float_y) );
|
||||
float_x /= (6 * area);
|
||||
float_y /= (6 * area);
|
||||
centre = Vector2((int) round(float_x), (int) round(float_y));
|
||||
}
|
||||
|
||||
Polygon::Polygon(int p_n_coords, const Coord *p_coords) : n_coords(p_n_coords) {
|
||||
coords = new Coord[n_coords];
|
||||
Polygon::Polygon(int p_n_coords, const Vector2 *p_coords) : n_coords(p_n_coords) {
|
||||
coords = new Vector2[n_coords];
|
||||
|
||||
int min_x = -1;
|
||||
int max_x = -1;
|
||||
int min_y = -1;
|
||||
int max_y = -1;
|
||||
for ( int i = 0; i < n_coords; i++ ) {
|
||||
for (int i = 0; i < n_coords; i++) {
|
||||
coords[i] = p_coords[i];
|
||||
if ( min_x == -1 || coords[i].X() < min_x )
|
||||
if (min_x == -1 || coords[i].X() < min_x)
|
||||
min_x = coords[i].X();
|
||||
if ( max_x == -1 || coords[i].X() > max_x )
|
||||
if (max_x == -1 || coords[i].X() > max_x)
|
||||
max_x = coords[i].X();
|
||||
if ( min_y == -1 || coords[i].Y() < min_y )
|
||||
if (min_y == -1 || coords[i].Y() < min_y)
|
||||
min_y = coords[i].Y();
|
||||
if ( max_y == -1 || coords[i].Y() > max_y )
|
||||
if (max_y == -1 || coords[i].Y() > max_y)
|
||||
max_y = coords[i].Y();
|
||||
}
|
||||
extent = Box( min_x, min_y, max_x, max_y );
|
||||
extent = Box(min_x, min_y, max_x, max_y);
|
||||
calcArea();
|
||||
calcCentre();
|
||||
}
|
||||
|
||||
Polygon::Polygon(const Polygon &p_polygon) :
|
||||
n_coords(p_polygon.n_coords),
|
||||
extent(p_polygon.extent),
|
||||
area(p_polygon.area),
|
||||
centre(p_polygon.centre)
|
||||
{
|
||||
coords = new Coord[n_coords];
|
||||
for( int i = 0; i < n_coords; i++ ) {
|
||||
n_coords(p_polygon.n_coords),
|
||||
extent(p_polygon.extent),
|
||||
area(p_polygon.area),
|
||||
centre(p_polygon.centre) {
|
||||
coords = new Vector2[n_coords];
|
||||
for (int i = 0; i < n_coords; i++) {
|
||||
coords[i] = p_polygon.coords[i];
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +83,7 @@ Polygon::Polygon(const Polygon &p_polygon) :
|
|||
Polygon &Polygon::operator=(const Polygon &p_polygon) {
|
||||
n_coords = p_polygon.n_coords;
|
||||
|
||||
Coord *new_coords = new Coord[n_coords];
|
||||
Vector2 *new_coords = new Vector2[n_coords];
|
||||
for (int i = 0; i < n_coords; i++) {
|
||||
new_coords[i] = p_polygon.coords[i];
|
||||
}
|
||||
|
@ -95,7 +96,7 @@ Polygon &Polygon::operator=(const Polygon &p_polygon) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool Polygon::isInside( const Coord &coord ) const {
|
||||
bool Polygon::isInside(const Vector2 &coord) const {
|
||||
bool inside = false;
|
||||
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
|
||||
if ( (((coords[i].Y() <= coord.Y()) && (coord.Y() < coords[j].Y()) )
|
||||
|
|
|
@ -68,10 +68,10 @@ protected:
|
|||
|
||||
protected:
|
||||
int n_coords;
|
||||
Coord *coords;
|
||||
Vector2 *coords;
|
||||
Box extent;
|
||||
int area;
|
||||
Coord centre;
|
||||
Vector2 centre;
|
||||
|
||||
protected:
|
||||
void initialiseEdges();
|
||||
|
@ -81,7 +81,7 @@ protected:
|
|||
public:
|
||||
inline Polygon() : n_coords(0), coords(nullptr), area(0) {
|
||||
}
|
||||
Polygon(int p_n_coords, const Coord *p_coords);
|
||||
Polygon(int p_n_coords, const Vector2 *p_coords);
|
||||
Polygon(const Polygon &p_polygon);
|
||||
~Polygon() {
|
||||
delete[] coords;
|
||||
|
@ -90,7 +90,7 @@ public:
|
|||
Polygon &operator=( const Polygon &p_polygon );
|
||||
|
||||
inline int getNumCoords() const { return n_coords; }
|
||||
inline const Coord &getCoord( int index ) const {
|
||||
inline const Vector2 &getCoord( int index ) const {
|
||||
return coords[index];
|
||||
}
|
||||
|
||||
|
@ -107,10 +107,10 @@ public:
|
|||
inline int Height() const { return extent.Height(); }
|
||||
|
||||
inline int Area() const { return area; }
|
||||
inline const Coord &Centre() const {
|
||||
inline const Vector2 &Centre() const {
|
||||
return centre;
|
||||
}
|
||||
bool isInside( const Coord &coord ) const;
|
||||
bool isInside(const Vector2 &coord) const;
|
||||
};
|
||||
|
||||
#endif // ZM_POLY_H
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
//
|
||||
// ZoneMinder Coordinate Class Interface, $Date$, $Revision$
|
||||
// Copyright (C) 2001-2008 Philip Coombes
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
#ifndef ZM_VECTOR2_H
|
||||
#define ZM_VECTOR2_H
|
||||
|
||||
#include "zm_define.h"
|
||||
|
||||
//
|
||||
// Class used for storing an x,y pair, i.e. a coordinate/vector
|
||||
//
|
||||
class Vector2 {
|
||||
public:
|
||||
inline Vector2() : x(0), y(0) {}
|
||||
inline Vector2(int p_x, int p_y) : x(p_x), y(p_y) {}
|
||||
inline Vector2(const Vector2 &p_coord) : x(p_coord.x), y(p_coord.y) {}
|
||||
|
||||
inline Vector2 &operator=(const Vector2 &coord) {
|
||||
x = coord.x;
|
||||
y = coord.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int &X(int p_x) {
|
||||
x = p_x;
|
||||
return x;
|
||||
}
|
||||
inline const int &X() const { return x; }
|
||||
|
||||
inline int &Y(int p_y) {
|
||||
y = p_y;
|
||||
return y;
|
||||
}
|
||||
inline const int &Y() const { return y; }
|
||||
|
||||
inline static Vector2 Range(const Vector2 &coord1, const Vector2 &coord2) {
|
||||
Vector2 result((coord1.x - coord2.x) + 1, (coord1.y - coord2.y) + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline bool operator==(const Vector2 &coord) const { return (x == coord.x && y == coord.y); }
|
||||
inline bool operator!=(const Vector2 &coord) const { return (x != coord.x || y != coord.y); }
|
||||
|
||||
inline bool operator>(const Vector2 &coord) const { return (x > coord.x && y > coord.y); }
|
||||
inline bool operator>=(const Vector2 &coord) const { return (!(operator<(coord))); }
|
||||
inline bool operator<(const Vector2 &coord) const { return (x < coord.x && y < coord.y); }
|
||||
inline bool operator<=(const Vector2 &coord) const { return (!(operator>(coord))); }
|
||||
|
||||
inline Vector2 &operator+=(const Vector2 &coord) {
|
||||
x += coord.x;
|
||||
y += coord.y;
|
||||
return *this;
|
||||
}
|
||||
inline Vector2 &operator-=(const Vector2 &coord) {
|
||||
x -= coord.x;
|
||||
y -= coord.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline friend Vector2 operator+(const Vector2 &coord1, const Vector2 &coord2) {
|
||||
Vector2 result(coord1);
|
||||
result += coord2;
|
||||
return result;
|
||||
}
|
||||
inline friend Vector2 operator-(const Vector2 &coord1, const Vector2 &coord2) {
|
||||
Vector2 result(coord1);
|
||||
result -= coord2;
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
#endif // ZM_VECTOR2_H
|
|
@ -32,7 +32,7 @@ void Zone::Setup(
|
|||
int p_max_pixel_threshold,
|
||||
int p_min_alarm_pixels,
|
||||
int p_max_alarm_pixels,
|
||||
const Coord &p_filter_box,
|
||||
const Vector2 &p_filter_box,
|
||||
int p_min_filter_pixels,
|
||||
int p_max_filter_pixels,
|
||||
int p_min_blob_pixels,
|
||||
|
@ -684,11 +684,11 @@ bool Zone::CheckAlarms(const Image *delta_image) {
|
|||
|
||||
// Now outline the changed region
|
||||
if (stats.score_) {
|
||||
stats.alarm_box_ = Box(Coord(alarm_lo_x, alarm_lo_y), Coord(alarm_hi_x, alarm_hi_y));
|
||||
stats.alarm_box_ = Box(Vector2(alarm_lo_x, alarm_lo_y), Vector2(alarm_hi_x, alarm_hi_y));
|
||||
|
||||
//if ( monitor->followMotion() )
|
||||
if ( true ) {
|
||||
stats.alarm_centre_ = Coord(alarm_mid_x, alarm_mid_y);
|
||||
stats.alarm_centre_ = Vector2(alarm_mid_x, alarm_mid_y);
|
||||
} else {
|
||||
stats.alarm_centre_ = stats.alarm_box_.Centre();
|
||||
}
|
||||
|
@ -750,7 +750,7 @@ bool Zone::ParsePolygonString(const char *poly_string, Polygon &polygon) {
|
|||
char *str = (char *)poly_string;
|
||||
int n_coords = 0;
|
||||
int max_n_coords = strlen(str)/4;
|
||||
Coord *coords = new Coord[max_n_coords];
|
||||
Vector2 *coords = new Vector2[max_n_coords];
|
||||
while (*str != '\0') {
|
||||
char *cp = strchr(str, ',');
|
||||
if (!cp) {
|
||||
|
@ -760,7 +760,7 @@ bool Zone::ParsePolygonString(const char *poly_string, Polygon &polygon) {
|
|||
int x = atoi(str);
|
||||
int y = atoi(cp+1);
|
||||
Debug(3, "Got coordinate %d,%d from polygon string", x, y);
|
||||
coords[n_coords++] = Coord(x, y);
|
||||
coords[n_coords++] = Vector2(x, y);
|
||||
|
||||
char *ws = strchr(cp+2, ' ');
|
||||
if (ws)
|
||||
|
@ -899,7 +899,7 @@ std::vector<Zone> Zone::Load(Monitor *monitor) {
|
|||
zones.emplace_back(
|
||||
monitor, Id, Name, Type, polygon, AlarmRGB,
|
||||
CheckMethod, MinPixelThreshold, MaxPixelThreshold,
|
||||
MinAlarmPixels, MaxAlarmPixels, Coord(FilterX, FilterY),
|
||||
MinAlarmPixels, MaxAlarmPixels, Vector2(FilterX, FilterY),
|
||||
MinFilterPixels, MaxFilterPixels,
|
||||
MinBlobPixels, MaxBlobPixels, MinBlobs, MaxBlobs,
|
||||
OverloadFrames, ExtendAlarmFrames);
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
#define ZM_ZONE_H
|
||||
|
||||
#include "zm_box.h"
|
||||
#include "zm_coord.h"
|
||||
#include "zm_define.h"
|
||||
#include "zm_config.h"
|
||||
#include "zm_poly.h"
|
||||
#include "zm_rgb.h"
|
||||
#include "zm_zone_stats.h"
|
||||
#include "zm_vector2.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
@ -77,7 +77,7 @@ class Zone {
|
|||
int min_alarm_pixels;
|
||||
int max_alarm_pixels;
|
||||
|
||||
Coord filter_box;
|
||||
Vector2 filter_box;
|
||||
int min_filter_pixels;
|
||||
int max_filter_pixels;
|
||||
|
||||
|
@ -112,7 +112,7 @@ class Zone {
|
|||
int p_max_pixel_threshold,
|
||||
int p_min_alarm_pixels,
|
||||
int p_max_alarm_pixels,
|
||||
const Coord &p_filter_box,
|
||||
const Vector2 &p_filter_box,
|
||||
int p_min_filter_pixels,
|
||||
int p_max_filter_pixels,
|
||||
int p_min_blob_pixels,
|
||||
|
@ -137,7 +137,7 @@ class Zone {
|
|||
int p_max_pixel_threshold=0,
|
||||
int p_min_alarm_pixels=50,
|
||||
int p_max_alarm_pixels=75000,
|
||||
const Coord &p_filter_box=Coord( 3, 3 ),
|
||||
const Vector2 &p_filter_box = Vector2(3, 3),
|
||||
int p_min_filter_pixels=50,
|
||||
int p_max_filter_pixels=50000,
|
||||
int p_min_blob_pixels=10,
|
||||
|
@ -164,7 +164,7 @@ class Zone {
|
|||
blob_stats{},
|
||||
stats(p_id)
|
||||
{
|
||||
Setup(Zone::INACTIVE, p_polygon, kRGBBlack, (Zone::CheckMethod)0, 0, 0, 0, 0, Coord(0, 0), 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
Setup(Zone::INACTIVE, p_polygon, kRGBBlack, (Zone::CheckMethod)0, 0, 0, 0, 0, Vector2(0, 0), 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
Zone(Monitor *p_monitor, int p_id, const char *p_label, ZoneType p_type, const Polygon &p_polygon)
|
||||
:
|
||||
|
@ -174,7 +174,7 @@ class Zone {
|
|||
blob_stats{},
|
||||
stats(p_id)
|
||||
{
|
||||
Setup(p_type, p_polygon, kRGBBlack, (Zone::CheckMethod)0, 0, 0, 0, 0, Coord( 0, 0 ), 0, 0, 0, 0, 0, 0, 0, 0 );
|
||||
Setup(p_type, p_polygon, kRGBBlack, (Zone::CheckMethod)0, 0, 0, 0, 0, Vector2(0, 0), 0, 0, 0, 0, 0, 0, 0, 0 );
|
||||
}
|
||||
|
||||
Zone(const Zone &z);
|
||||
|
@ -195,7 +195,7 @@ class Zone {
|
|||
inline bool WasAlarmed() const { return was_alarmed; }
|
||||
inline void SetAlarm() { was_alarmed = alarmed; alarmed = true; }
|
||||
inline void ClearAlarm() { was_alarmed = alarmed; alarmed = false; }
|
||||
inline Coord GetAlarmCentre() const { return stats.alarm_centre_; }
|
||||
inline Vector2 GetAlarmCentre() const { return stats.alarm_centre_; }
|
||||
inline unsigned int Score() const { return stats.score_; }
|
||||
|
||||
inline void ResetStats() {
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#define ZM_ZONE_STATS_H
|
||||
|
||||
#include "zm_box.h"
|
||||
#include "zm_coord.h"
|
||||
#include "zm_logger.h"
|
||||
#include "zm_vector2.h"
|
||||
|
||||
class ZoneStats {
|
||||
public:
|
||||
|
@ -87,7 +87,7 @@ class ZoneStats {
|
|||
int min_blob_size_;
|
||||
int max_blob_size_;
|
||||
Box alarm_box_;
|
||||
Coord alarm_centre_;
|
||||
Vector2 alarm_centre_;
|
||||
unsigned int score_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue