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: 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: 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 10069 : PointShape::PointShape()
48 10069 : :ComponentShape()
49 : {
50 10069 : DebugAssert(ok(), AipsError);
51 10069 : }
52 :
53 2521 : PointShape::PointShape(const MDirection& direction)
54 2521 : :ComponentShape(direction)
55 : {
56 2521 : DebugAssert(ok(), AipsError);
57 2521 : }
58 :
59 11457 : PointShape::PointShape(const PointShape& other)
60 11457 : :ComponentShape(other)
61 : {
62 11457 : DebugAssert(ok(), AipsError);
63 11457 : }
64 :
65 45573 : PointShape::~PointShape() {
66 24047 : DebugAssert(ok(), AipsError);
67 45573 : }
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 10998 : ComponentType::Shape PointShape::type() const {
76 10998 : DebugAssert(ok(), AipsError);
77 10998 : 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 4982 : return retVal;
105 : }
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 2 : 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 1994155 : DComplex PointShape::visibility(const Vector<Double>&,
142 : const Double&) const {
143 1994155 : DebugAssert(ok(), AipsError);
144 1994155 : 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 4739 : void PointShape::visibility(Matrix<DComplex>& scale, const Matrix<Double>& uvw,
155 : const Vector<Double> & freq) const {
156 4739 : DebugAssert(ok(), AipsError);
157 4739 : scale.resize(uvw.ncolumn(), freq.nelements());
158 4739 : scale = DComplex(1.0, 0.0);
159 4739 : }
160 :
161 0 : Bool PointShape::isSymmetric() const {
162 0 : DebugAssert(ok(), AipsError);
163 0 : return true;
164 : }
165 :
166 11457 : ComponentShape* PointShape::clone() const {
167 11457 : DebugAssert(ok(), AipsError);
168 11457 : ComponentShape* tmpPtr = new PointShape(*this);
169 11457 : AlwaysAssert(tmpPtr != 0, AipsError);
170 11457 : return tmpPtr;
171 : }
172 :
173 400 : uInt PointShape::nParameters() const {
174 400 : DebugAssert(ok(), AipsError);
175 400 : return 0;
176 : }
177 :
178 62 : void PointShape::setParameters(const Vector<Double>& newParms) {
179 62 : DebugAssert(newParms.nelements() == nParameters(), AipsError);
180 62 : DebugAssert(ok(), AipsError);
181 : // Suppress compiler warning about unused variable
182 62 : if (newParms.empty()) {};
183 62 : }
184 :
185 93 : Vector<Double> PointShape::parameters() const {
186 93 : DebugAssert(ok(), AipsError);
187 93 : return Vector<Double>(0);
188 : }
189 :
190 62 : void PointShape::setErrors(const Vector<Double>& newErrors) {
191 62 : DebugAssert(newErrors.nelements() == nParameters(), AipsError);
192 62 : DebugAssert(ok(), AipsError);
193 : // Suppress compiler warning about unused variable
194 62 : if (newErrors.empty()) {};
195 62 : }
196 :
197 93 : Vector<Double> PointShape::errors() const {
198 93 : DebugAssert(ok(), AipsError);
199 93 : 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 4767 : Bool PointShape::fromRecord(String& errorMessage,
214 : const RecordInterface& record) {
215 4767 : DebugAssert(ok(), AipsError);
216 4767 : return ComponentShape::fromRecord(errorMessage, record);
217 : }
218 :
219 4770 : Bool PointShape::toRecord(String& errorMessage,
220 : RecordInterface& record) const {
221 4770 : DebugAssert(ok(), AipsError);
222 4770 : 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 2101199 : Bool PointShape::ok() const {
231 2101199 : return ComponentShape::ok();
232 : }
233 :
234 5 : const ComponentShape* PointShape::getPtr() const {
235 5 : 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 :
|