Line data Source code
1 : //# PointShape.cc:
2 : //# Copyright (C) 1998,1999,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 : //# $Id: PointShape.cc 21130 2011-10-18 07:39:05Z gervandiepen $
27 :
28 : #include <components/ComponentModels/PointShape.h>
29 : #include <components/ComponentModels/Flux.h>
30 : #include <casacore/casa/Arrays/Vector.h>
31 : #include <casacore/casa/Containers/RecordFieldId.h>
32 : #include <casacore/casa/Containers/RecordInterface.h>
33 : #include <casacore/casa/Exceptions/Error.h>
34 : #include <casacore/casa/BasicSL/Complex.h>
35 : #include <casacore/casa/BasicMath/Math.h>
36 : #include <casacore/measures/Measures/MCDirection.h>
37 : #include <casacore/measures/Measures/MeasConvert.h>
38 : #include <casacore/casa/Quanta/MVAngle.h>
39 : #include <casacore/casa/Quanta/QMath.h>
40 : #include <casacore/casa/Quanta/Quantum.h>
41 : #include <casacore/casa/Utilities/Assert.h>
42 : #include <casacore/casa/BasicSL/String.h>
43 :
44 : using namespace casacore;
45 : namespace casa { //# NAMESPACE CASA - BEGIN
46 :
47 65121 : PointShape::PointShape()
48 65121 : :ComponentShape()
49 : {
50 65121 : DebugAssert(ok(), AipsError);
51 65121 : }
52 :
53 2492 : PointShape::PointShape(const MDirection& direction)
54 2492 : :ComponentShape(direction)
55 : {
56 2492 : DebugAssert(ok(), AipsError);
57 2492 : }
58 :
59 6899 : PointShape::PointShape(const PointShape& other)
60 6899 : :ComponentShape(other)
61 : {
62 6899 : DebugAssert(ok(), AipsError);
63 6899 : }
64 :
65 146530 : PointShape::~PointShape() {
66 74511 : DebugAssert(ok(), AipsError);
67 146530 : }
68 :
69 0 : PointShape& PointShape::operator=(const PointShape& other) {
70 0 : ComponentShape::operator=(other);
71 0 : DebugAssert(ok(), AipsError);
72 0 : return *this;
73 : }
74 :
75 65002 : ComponentType::Shape PointShape::type() const {
76 65002 : DebugAssert(ok(), AipsError);
77 65002 : return ComponentType::POINT;
78 : }
79 :
80 2491 : Double PointShape::sample(const MDirection& direction,
81 : const MVAngle& pixelLatSize,
82 : const MVAngle& pixelLongSize) const {
83 2491 : DebugAssert(ok(), AipsError);
84 2491 : const MDirection& compDir(refDirection());
85 2491 : const MDirection::Ref& compDirFrame(compDir.getRef());
86 2491 : const MDirection::MVType* compDirValue = &(compDir.getValue());
87 2491 : Bool deleteValue = false;
88 : // Convert direction to the same frame as the reference direction
89 2491 : if (ComponentShape::differentRefs(direction.getRef(), compDirFrame)) {
90 2410 : compDirValue = new MDirection::MVType
91 2410 : (MDirection::Convert(compDir, direction.getRef())().getValue());
92 2410 : deleteValue = true;
93 : }
94 : //
95 2491 : const Double latSize = abs(pixelLatSize.radian());
96 2491 : const Double longSize = abs(pixelLongSize.radian());
97 2491 : const Double nearSize = max(latSize, longSize);
98 : //
99 2491 : const MDirection::MVType& dirValue = direction.getValue();
100 : //
101 2491 : Double retVal = dirIsInPixel (longSize, latSize, nearSize, dirValue, compDirValue);
102 : //
103 2491 : if (deleteValue) delete compDirValue;
104 2491 : return retVal;
105 2491 : }
106 :
107 :
108 1 : void PointShape::sample(Vector<Double>& scale,
109 : const Vector<MDirection::MVType>& directions,
110 : const MDirection::Ref& refFrame,
111 : const MVAngle& pixelLatSize,
112 : const MVAngle& pixelLongSize) const
113 : {
114 1 : DebugAssert(ok(), AipsError);
115 1 : const uInt nSamples = directions.nelements();
116 1 : DebugAssert(scale.nelements() == nSamples, AipsError);
117 :
118 1 : const MDirection& compDir(refDirection());
119 1 : const MDirection::Ref& compDirFrame(compDir.getRef());
120 1 : const MDirection::MVType* compDirValue = &(compDir.getValue());
121 1 : Bool deleteValue = false;
122 : // Convert direction to the same frame as the reference direction
123 1 : if (refFrame != compDirFrame) {
124 1 : compDirValue = new MDirection::MVType
125 1 : (MDirection::Convert(compDir, refFrame)().getValue());
126 1 : deleteValue = true;
127 : }
128 : //
129 1 : const Double longSize = abs(pixelLongSize.radian());
130 1 : const Double latSize = abs(pixelLatSize.radian());
131 1 : const Double nearSize = max(latSize, longSize);
132 1 : scale = 0.0;
133 : //
134 2 : for (uInt i = 0; i < nSamples; i++) {
135 1 : const MDirection::MVType& dirValue = directions(i);
136 1 : scale(i) = dirIsInPixel (longSize, latSize, nearSize, dirValue, compDirValue);
137 : }
138 1 : if (deleteValue) delete compDirValue;
139 1 : }
140 :
141 0 : DComplex PointShape::visibility(const Vector<Double>&,
142 : const Double&) const {
143 0 : DebugAssert(ok(), AipsError);
144 0 : return DComplex(1.0, 0.0);
145 : }
146 :
147 0 : void PointShape::visibility(Vector<DComplex>& scale,
148 : const Matrix<Double>&,
149 : const Double&) const {
150 0 : DebugAssert(ok(), AipsError);
151 0 : scale = DComplex(1.0, 0.0);
152 0 : }
153 :
154 32032 : void PointShape::visibility(Matrix<DComplex>& scale, const Matrix<Double>& uvw,
155 : const Vector<Double> & freq) const {
156 32032 : DebugAssert(ok(), AipsError);
157 32032 : scale.resize(uvw.ncolumn(), freq.nelements());
158 32032 : scale = DComplex(1.0, 0.0);
159 32032 : }
160 :
161 0 : Bool PointShape::isSymmetric() const {
162 0 : DebugAssert(ok(), AipsError);
163 0 : return true;
164 : }
165 :
166 6899 : ComponentShape* PointShape::clone() const {
167 6899 : DebugAssert(ok(), AipsError);
168 6899 : ComponentShape* tmpPtr = new PointShape(*this);
169 6899 : AlwaysAssert(tmpPtr != 0, AipsError);
170 6899 : return tmpPtr;
171 : }
172 :
173 8 : uInt PointShape::nParameters() const {
174 8 : DebugAssert(ok(), AipsError);
175 8 : return 0;
176 : }
177 :
178 4 : void PointShape::setParameters(const Vector<Double>& newParms) {
179 4 : DebugAssert(newParms.nelements() == nParameters(), AipsError);
180 4 : DebugAssert(ok(), AipsError);
181 : // Suppress compiler warning about unused variable
182 4 : if (newParms.empty()) {};
183 4 : }
184 :
185 3 : Vector<Double> PointShape::parameters() const {
186 3 : DebugAssert(ok(), AipsError);
187 3 : return Vector<Double>(0);
188 : }
189 :
190 4 : void PointShape::setErrors(const Vector<Double>& newErrors) {
191 4 : DebugAssert(newErrors.nelements() == nParameters(), AipsError);
192 4 : DebugAssert(ok(), AipsError);
193 : // Suppress compiler warning about unused variable
194 4 : if (newErrors.empty()) {};
195 4 : }
196 :
197 3 : Vector<Double> PointShape::errors() const {
198 3 : DebugAssert(ok(), AipsError);
199 3 : return Vector<Double>(0);
200 : }
201 :
202 0 : Vector<Double> PointShape::optParameters() const {
203 0 : DebugAssert(ok(), AipsError);
204 0 : return Vector<Double>(0);
205 : }
206 :
207 0 : void PointShape::setOptParameters(const Vector<Double>& newOptParms) {
208 0 : DebugAssert(ok(), AipsError);
209 : // squash compiler warning, maybe just get rid of DebugAssert statements
210 0 : if (newOptParms.empty()) {};
211 0 : }
212 :
213 32034 : Bool PointShape::fromRecord(String& errorMessage,
214 : const RecordInterface& record) {
215 32034 : DebugAssert(ok(), AipsError);
216 32034 : return ComponentShape::fromRecord(errorMessage, record);
217 : }
218 :
219 1002 : Bool PointShape::toRecord(String& errorMessage,
220 : RecordInterface& record) const {
221 1002 : DebugAssert(ok(), AipsError);
222 1002 : return ComponentShape::toRecord(errorMessage, record);
223 : }
224 :
225 0 : Bool PointShape::convertUnit(String&, const RecordInterface&) {
226 0 : DebugAssert(ok(), AipsError);
227 0 : return true;
228 : }
229 :
230 358033 : Bool PointShape::ok() const {
231 358033 : return ComponentShape::ok();
232 : }
233 :
234 1 : const ComponentShape* PointShape::getPtr() const {
235 1 : return this;
236 : }
237 :
238 :
239 2492 : Double PointShape::dirIsInPixel (Double longSize, Double latSize, Double nearSize,
240 : const MDirection::MVType& dirValue,
241 : const MDirection::MVType* compDirValue) const
242 : {
243 2492 : Double retVal = 0.0;
244 : //
245 2492 : const Double separation = abs(compDirValue->separation(dirValue));
246 2492 : if (separation <= nearSize) {
247 2492 : const Double pa = compDirValue->positionAngle(dirValue);
248 : //
249 4984 : if (abs(separation*sin(pa)) <= longSize/2.0 &&
250 2492 : abs(separation*cos(pa)) <= latSize/2.0) {
251 2492 : retVal = 1.0;
252 : }
253 : }
254 2492 : return retVal;
255 : }
256 :
257 0 : String PointShape::sizeToString() const {
258 0 : return "Point";
259 : }
260 :
261 :
262 :
263 : // Local Variables:
264 : // compile-command: "gmake PointShape"
265 : // End:
266 :
267 : } //# NAMESPACE CASA - END
268 :
|