Define a 2-dimensional region by a polygon. More...
#include <LCPolygon.h>
Public Member Functions | |
LCPolygon () | |
LCPolygon (const Vector< Float > &x, const Vector< Float > &y, const IPosition &latticeShape) | |
Construct from the given x and y values. | |
LCPolygon (const Vector< Double > &x, const Vector< Double > &y, const IPosition &latticeShape) | |
LCPolygon (const LCPolygon &other) | |
Copy constructor (reference semantics). | |
virtual | ~LCPolygon () |
LCPolygon & | operator= (const LCPolygon &other) |
Assignment (copy semantics). | |
virtual Bool | operator== (const LCRegion &other) const |
Comparison. | |
virtual LCRegion * | cloneRegion () const |
Make a copy of the derived object. | |
const Vector< Float > & | x () const |
Get the X-values. | |
const Vector< Float > & | y () const |
Get the Y-values. | |
virtual String | type () const |
Get the region type. | |
virtual TableRecord | toRecord (const String &tableName) const |
Convert the (derived) object to a record. | |
Static Public Member Functions | |
static String | className () |
Get the class name (to store in the record). | |
static LCPolygon * | fromRecord (const TableRecord &, const String &tablename) |
Convert correct object from a record. | |
Protected Member Functions | |
virtual LCRegion * | doTranslate (const Vector< Float > &translateVector, const IPosition &newLatticeShape) const |
Construct another LCPolygon (for e.g. | |
Private Member Functions | |
void | defineBox () |
Make the bounding box. | |
void | defineMask () |
Define the mask to indicate which elements are inside the polygon. | |
void | fillMask (Bool *mask, Int nx, Int ny, Int blcx, Int blcy, const Float *ptrX, const Float *ptrY, uInt nrline) |
Fill the mask from the given points. | |
Int | truncateStart (Float v) |
Truncate a start value to a pixel point. | |
Int | truncateEnd (Float v, Int maxEnd) |
Truncate an end value to a pixel point. | |
Private Attributes | |
Vector< Float > | itsX |
Vector< Float > | itsY |
Define a 2-dimensional region by a polygon.
Public interface
The LCPolygon class is a specialization of class LCRegion . It makes it possible to define a 2-dimensional region by means an ordered collection of points with straight lines connecting adjacent points. The last point can be equal to the first one. If not, an extra point gets added to form the closing line.
The polygon can be as complex as one likes. E.g. it is possible to have a rectangle with an inner rectangle to exclude interior points.
The points defining the polygon do not need to coincide with pixel points. Points may be outside the lattice meaning that only part of the polygon surface is actually used. However, at least some part of the polygon surface has to intersect with the lattice.
A lattice pixel is part of the polygon surface if the center of the pixel is on or inside the polygon. Note that 0 is the beginning ond 1 is the end of the first pixel. Thus 0.5 is its center.
// A simple (tilted) square. Vector<Float> x(4), y(4); x(0)=3; y(0)=3; x(1)=6; y(1)=6; x(2)=3; y(2)=9; x(3)=0; y(3)=6; LCPolygon region(x, y, IPosition(2,128,128)); // A rectangle with an inner region to exclude interior points. // Note that the last point is equal to the first point, thus // the last line is given explicitly. Vector<Float> x(11), y(11); x(0)=3; y(0)=3; x(1)=9; y(1)=3; x(2)=9; y(2)=8; x(3)=3; y(3)=8; x(4)=3; y(4)=3; x(5)=5; y(5)=5; x(6)=8; y(6)=4; x(7)=7; y(7)=7; x(8)=5; y(8)=7; x(9)=5; y(9)=5; x(10)=3; y(10)=3; LCPolygon region(x, y, IPosition(2,128,128));
Definition at line 109 of file LCPolygon.h.
casacore::LCPolygon::LCPolygon | ( | ) |
casacore::LCPolygon::LCPolygon | ( | const Vector< Float > & | x, | |
const Vector< Float > & | y, | |||
const IPosition & | latticeShape | |||
) |
Construct from the given x and y values.
The latticeShape must define a 2-dimensional lattice.
LCPolygon can be used for an N-dimensional lattice by making another lattice representing any 2 axes from the original lattice.
casacore::LCPolygon::LCPolygon | ( | const Vector< Double > & | x, | |
const Vector< Double > & | y, | |||
const IPosition & | latticeShape | |||
) |
casacore::LCPolygon::LCPolygon | ( | const LCPolygon & | other | ) |
Copy constructor (reference semantics).
virtual casacore::LCPolygon::~LCPolygon | ( | ) | [virtual] |
static String casacore::LCPolygon::className | ( | ) | [static] |
Get the class name (to store in the record).
virtual LCRegion* casacore::LCPolygon::cloneRegion | ( | ) | const [virtual] |
Make a copy of the derived object.
Implements casacore::LCRegion.
void casacore::LCPolygon::defineBox | ( | ) | [private] |
Make the bounding box.
void casacore::LCPolygon::defineMask | ( | ) | [private] |
Define the mask to indicate which elements are inside the polygon.
virtual LCRegion* casacore::LCPolygon::doTranslate | ( | const Vector< Float > & | translateVector, | |
const IPosition & | newLatticeShape | |||
) | const [protected, virtual] |
Construct another LCPolygon (for e.g.
another lattice) by moving this one. It recalculates the bounding box. A positive translation value indicates "to right".
Implements casacore::LCRegion.
void casacore::LCPolygon::fillMask | ( | Bool * | mask, | |
Int | nx, | |||
Int | ny, | |||
Int | blcx, | |||
Int | blcy, | |||
const Float * | ptrX, | |||
const Float * | ptrY, | |||
uInt | nrline | |||
) | [private] |
Fill the mask from the given points.
static LCPolygon* casacore::LCPolygon::fromRecord | ( | const TableRecord & | , | |
const String & | tablename | |||
) | [static] |
Convert correct object from a record.
Reimplemented from casacore::LCRegion.
Assignment (copy semantics).
Reimplemented from casacore::LCRegionFixed.
Comparison.
Reimplemented from casacore::LCRegionFixed.
virtual TableRecord casacore::LCPolygon::toRecord | ( | const String & | tableName | ) | const [virtual] |
Convert the (derived) object to a record.
Implements casacore::LCRegion.
Truncate an end value to a pixel point.
A pixel point is taken if near the value, otherwise floor(value). The returned value is never > maxEnd.
Truncate a start value to a pixel point.
A pixel point is taken if near the value, otherwise floor(value+1). The returned value is never < 0.
virtual String casacore::LCPolygon::type | ( | ) | const [virtual] |
Vector<Float> casacore::LCPolygon::itsX [private] |
Definition at line 187 of file LCPolygon.h.
Referenced by x().
Vector<Float> casacore::LCPolygon::itsY [private] |
Definition at line 188 of file LCPolygon.h.
Referenced by y().