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