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
38// <summary>
39// Define a 2-dimensional region by a polygon.
40// </summary>
41
42// <use visibility=export>
43
44// <reviewed reviewer="" date="" tests="">
45// </reviewed>
46
47// <prerequisite>
48// <li> <linkto class=LCRegion>LCRegion</linkto>
49// </prerequisite>
50
51// <synopsis>
52// The LCPolygon class is a specialization of class
53// <linkto class=LCRegion>LCRegion</linkto>.
54// It makes it possible to define a 2-dimensional region by means
55// an ordered collection of points with straight lines connecting
56// adjacent points. The last point can be equal to the first one.
57// If not, an extra point gets added to form the closing line.
58// <p>
59// The polygon can be as complex as one likes. E.g. it is possible to
60// have a rectangle with an inner rectangle to exclude interior points.
61// <p>
62// The points defining the polygon do not need to coincide with pixel points.
63// Points may be outside the lattice meaning that only part of the
64// polygon surface is actually used. However, at least some part of the
65// polygon surface has to intersect with the lattice.
66// <br>A lattice pixel is part of the polygon surface if the center of
67// the pixel is on or inside the polygon. Note that 0 is the beginning ond
68// 1 is the end of the first pixel. Thus 0.5 is its center.
69// </synopsis>
70
71// <example>
72// <srcblock>
73// // A simple (tilted) square.
74// Vector<Float> x(4), y(4);
75// x(0)=3; y(0)=3;
76// x(1)=6; y(1)=6;
77// x(2)=3; y(2)=9;
78// x(3)=0; y(3)=6;
79// LCPolygon region(x, y, IPosition(2,128,128));
80//
81// // A rectangle with an inner region to exclude interior points.
82// // Note that the last point is equal to the first point, thus
83// // the last line is given explicitly.
84// Vector<Float> x(11), y(11);
85// x(0)=3; y(0)=3;
86// x(1)=9; y(1)=3;
87// x(2)=9; y(2)=8;
88// x(3)=3; y(3)=8;
89// x(4)=3; y(4)=3;
90// x(5)=5; y(5)=5;
91// x(6)=8; y(6)=4;
92// x(7)=7; y(7)=7;
93// x(8)=5; y(8)=7;
94// x(9)=5; y(9)=5;
95// x(10)=3; y(10)=3;
96// LCPolygon region(x, y, IPosition(2,128,128));
97// </srcblock>
98// </example>
99
100//# <todo asof="1997/11/11">
101//# <li>
102//# </todo>
103
104
106{
107public:
109
110 // Construct from the given x and y values.
111 // The latticeShape must define a 2-dimensional lattice.
112 // <br>LCPolygon can be used for an N-dimensional lattice by making
113 // another lattice representing any 2 axes from the original lattice.
114 // <group>
116 const IPosition& latticeShape);
118 const IPosition& latticeShape);
119 // </group>
120
121 // Copy constructor (reference semantics).
122 LCPolygon (const LCPolygon& other);
123
124 virtual ~LCPolygon();
125
126 // Assignment (copy semantics).
128
129 // Comparison
130 virtual Bool operator== (const LCRegion& other) const;
131
132 // Make a copy of the derived object.
133 virtual LCRegion* cloneRegion() const;
134
135 // Get the X-values.
136 const Vector<Float>& x() const;
137
138 // Get the Y-values.
139 const Vector<Float>& y() const;
140
141 // Get the class name (to store in the record).
143
144 // Get the region type. Returns className()
145 virtual String type() const;
146
147 // Convert the (derived) object to a record.
148 virtual TableRecord toRecord (const String& tableName) const;
149
150 // Convert correct object from a record.
152 const String& tablename);
153
154protected:
155 // Construct another LCPolygon (for e.g. another lattice) by moving
156 // this one. It recalculates the bounding box.
157 // A positive translation value indicates "to right".
158 virtual LCRegion* doTranslate (const Vector<Float>& translateVector,
159 const IPosition& newLatticeShape) const;
160
161private:
162 // Make the bounding box.
163 void defineBox();
164
165 // Define the mask to indicate which elements are inside the polygon.
167
168 // Fill the mask from the given points.
169 void fillMask (Bool* mask, Int nx, Int ny, Int blcx, Int blcy,
170 const Float* ptrX, const Float* ptrY, uInt nrline);
171
172 // Truncate a start value to a pixel point.
173 // A pixel point is taken if near the value, otherwise floor(value+1).
174 // The returned value is never < 0.
176
177 // Truncate an end value to a pixel point.
178 // A pixel point is taken if near the value, otherwise floor(value).
179 // The returned value is never > maxEnd.
181
182 // takes into account when one value is zero and the other is absolutely (as
183 // opposed to relatively) near zero.
184 static Bool _isNear(Float val1, Float val2);
185
188};
189
190
191inline const Vector<Float>& LCPolygon::x() const
192{
193 return itsX;
194}
195inline const Vector<Float>& LCPolygon::y() const
196{
197 return itsY;
198}
199
200
201
202} //# NAMESPACE CASACORE - END
203
204#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).
virtual String type() const
Get the region type.
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.
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.
virtual Bool operator==(const LCRegion &other) const
Comparison.
virtual TableRecord toRecord(const String &tableName) const
Convert the (derived) object to a record.
const Vector< Float > & x() const
Get the X-values.
Definition LCPolygon.h:191
const Vector< Float > & y() const
Get the Y-values.
Definition LCPolygon.h:195
virtual LCRegion * cloneRegion() const
Make a copy of the derived object.
virtual LCRegion * doTranslate(const Vector< Float > &translateVector, const IPosition &newLatticeShape) const
Construct another LCPolygon (for e.g.
Vector< Float > itsY
Definition LCPolygon.h:187
static LCPolygon * fromRecord(const TableRecord &, const String &tablename)
Convert correct object from a record.
Vector< Float > itsX
Definition LCPolygon.h:186
LCPolygon(const LCPolygon &other)
Copy constructor (reference semantics).
const IPosition & latticeShape() const
Give the full lattice shape.
Definition LCRegion.h:229
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
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