casacore
Loading...
Searching...
No Matches
LCPolygon.h
Go to the documentation of this file.
1// # LCPolygon.h: Define a 2-dimensional region by a polygon
2// # Copyright (C) 1998,2000
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef LATTICES_LCPOLYGON_H
27#define LATTICES_LCPOLYGON_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/lattices/LRegions/LCRegionFixed.h>
32#include <casacore/casa/Arrays/Vector.h>
33#include <casacore/casa/Arrays/ArrayFwd.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary>
38// Define a 2-dimensional region by a polygon.
39// </summary>
40
41// <use visibility=export>
42
43// <reviewed reviewer="" date="" tests="">
44// </reviewed>
45
46// <prerequisite>
47// <li> <linkto class=LCRegion>LCRegion</linkto>
48// </prerequisite>
49
50// <synopsis>
51// The LCPolygon class is a specialization of class
52// <linkto class=LCRegion>LCRegion</linkto>.
53// It makes it possible to define a 2-dimensional region by means
54// an ordered collection of points with straight lines connecting
55// adjacent points. The last point can be equal to the first one.
56// If not, an extra point gets added to form the closing line.
57// <p>
58// The polygon can be as complex as one likes. E.g. it is possible to
59// have a rectangle with an inner rectangle to exclude interior points.
60// <p>
61// The points defining the polygon do not need to coincide with pixel points.
62// Points may be outside the lattice meaning that only part of the
63// polygon surface is actually used. However, at least some part of the
64// polygon surface has to intersect with the lattice.
65// <br>A lattice pixel is part of the polygon surface if the center of
66// the pixel is on or inside the polygon. Note that 0 is the beginning ond
67// 1 is the end of the first pixel. Thus 0.5 is its center.
68// </synopsis>
69
70// <example>
71// <srcblock>
72// // A simple (tilted) square.
73// Vector<Float> x(4), y(4);
74// x(0)=3; y(0)=3;
75// x(1)=6; y(1)=6;
76// x(2)=3; y(2)=9;
77// x(3)=0; y(3)=6;
78// LCPolygon region(x, y, IPosition(2,128,128));
79//
80// // A rectangle with an inner region to exclude interior points.
81// // Note that the last point is equal to the first point, thus
82// // the last line is given explicitly.
83// Vector<Float> x(11), y(11);
84// x(0)=3; y(0)=3;
85// x(1)=9; y(1)=3;
86// x(2)=9; y(2)=8;
87// x(3)=3; y(3)=8;
88// x(4)=3; y(4)=3;
89// x(5)=5; y(5)=5;
90// x(6)=8; y(6)=4;
91// x(7)=7; y(7)=7;
92// x(8)=5; y(8)=7;
93// x(9)=5; y(9)=5;
94// x(10)=3; y(10)=3;
95// LCPolygon region(x, y, IPosition(2,128,128));
96// </srcblock>
97// </example>
98
99// # <todo asof="1997/11/11">
100// # <li>
101// # </todo>
102
103class LCPolygon : public LCRegionFixed {
104 public:
106
107 // Construct from the given x and y values.
108 // The latticeShape must define a 2-dimensional lattice.
109 // <br>LCPolygon can be used for an N-dimensional lattice by making
110 // another lattice representing any 2 axes from the original lattice.
111 // <group>
114 // </group>
115
116 // Copy constructor (reference semantics).
117 LCPolygon(const LCPolygon& other);
118
119 virtual ~LCPolygon();
120
121 // Assignment (copy semantics).
123
124 // Make a copy of the derived object.
125 LCRegion* cloneRegion() const override;
126
127 // Get the X-values.
128 const Vector<Float>& x() const;
129
130 // Get the Y-values.
131 const Vector<Float>& y() const;
132
133 // Get the class name (to store in the record).
135
136 // Get the region type. Returns className()
137 String type() const override;
138
139 // Convert the (derived) object to a record.
140 TableRecord toRecord(const String& tableName) const override;
141
142 // Convert correct object from a record.
143 static LCPolygon* fromRecord(const TableRecord&, const String& tablename);
144
145 protected:
146 // Comparison
147 Bool equals(const LCRegion& other) const override;
148
149 // Construct another LCPolygon (for e.g. another lattice) by moving
150 // this one. It recalculates the bounding box.
151 // A positive translation value indicates "to right".
152 LCRegion* doTranslate(const Vector<Float>& translateVector,
153 const IPosition& newLatticeShape) const override;
154
155 private:
156 // Make the bounding box.
157 void defineBox();
158
159 // Define the mask to indicate which elements are inside the polygon.
161
162 // Fill the mask from the given points.
163 void fillMask(Bool* mask, Int nx, Int ny, Int blcx, Int blcy, const Float* ptrX,
164 const Float* ptrY, uInt nrline);
165
166 // Truncate a start value to a pixel point.
167 // A pixel point is taken if near the value, otherwise floor(value+1).
168 // The returned value is never < 0.
170
171 // Truncate an end value to a pixel point.
172 // A pixel point is taken if near the value, otherwise floor(value).
173 // The returned value is never > maxEnd.
175
176 // takes into account when one value is zero and the other is absolutely (as
177 // opposed to relatively) near zero.
178 static Bool _isNear(Float val1, Float val2);
179
182};
183
184inline const Vector<Float>& LCPolygon::x() const { return itsX; }
185inline const Vector<Float>& LCPolygon::y() const { return itsY; }
186
187} // namespace casacore
188
189#endif
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.
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 & operator=(const LCPolygon &other)
Assignment (copy semantics).
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.
LCRegion * doTranslate(const Vector< Float > &translateVector, const IPosition &newLatticeShape) const override
Construct another LCPolygon (for e.g.
static Bool _isNear(Float val1, Float val2)
takes into account when one value is zero and the other is absolutely (as opposed to relatively) near...
void defineMask()
Define the mask to indicate which elements are inside the polygon.
static String className()
Get the class name (to store in the record).
void defineBox()
Make the bounding box.
const Vector< Float > & x() const
Get the X-values.
Definition LCPolygon.h:184
Bool equals(const LCRegion &other) const override
Comparison.
TableRecord toRecord(const String &tableName) const override
Convert the (derived) object to a record.
LCRegion * cloneRegion() const override
Make a copy of the derived object.
const Vector< Float > & y() const
Get the Y-values.
Definition LCPolygon.h:185
Vector< Float > itsY
Definition LCPolygon.h:181
String type() const override
Get the region type.
static LCPolygon * fromRecord(const TableRecord &, const String &tablename)
Convert correct object from a record.
Vector< Float > itsX
Definition LCPolygon.h:180
LCPolygon(const LCPolygon &other)
Copy constructor (reference semantics).
const IPosition & latticeShape() const
Give the full lattice shape.
Definition LCRegion.h:211
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40