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