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 51205 : PointShape::PointShape()
48 51205 : :ComponentShape()
49 : {
50 51205 : DebugAssert(ok(), AipsError);
51 51205 : }
52 :
53 1 : PointShape::PointShape(const MDirection& direction)
54 1 : :ComponentShape(direction)
55 : {
56 1 : DebugAssert(ok(), AipsError);
57 1 : }
58 :
59 1 : PointShape::PointShape(const PointShape& other)
60 1 : :ComponentShape(other)
61 : {
62 1 : DebugAssert(ok(), AipsError);
63 1 : }
64 :
65 102411 : PointShape::~PointShape() {
66 51206 : DebugAssert(ok(), AipsError);
67 102411 : }
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 52004 : ComponentType::Shape PointShape::type() const {
76 52004 : DebugAssert(ok(), AipsError);
77 52004 : return ComponentType::POINT;
78 : }
79 :
80 0 : Double PointShape::sample(const MDirection& direction,
81 : const MVAngle& pixelLatSize,
82 : const MVAngle& pixelLongSize) const {
83 0 : DebugAssert(ok(), AipsError);
84 0 : const MDirection& compDir(refDirection());
85 0 : const MDirection::Ref& compDirFrame(compDir.getRef());
86 0 : const MDirection::MVType* compDirValue = &(compDir.getValue());
87 0 : Bool deleteValue = false;
88 : // Convert direction to the same frame as the reference direction
89 0 : if (ComponentShape::differentRefs(direction.getRef(), compDirFrame)) {
90 0 : compDirValue = new MDirection::MVType
91 0 : (MDirection::Convert(compDir, direction.getRef())().getValue());
92 0 : deleteValue = true;
93 : }
94 : //
95 0 : const Double latSize = abs(pixelLatSize.radian());
96 0 : const Double longSize = abs(pixelLongSize.radian());
97 0 : const Double nearSize = max(latSize, longSize);
98 : //
99 0 : const MDirection::MVType& dirValue = direction.getValue();
100 : //
101 0 : Double retVal = dirIsInPixel (longSize, latSize, nearSize, dirValue, compDirValue);
102 : //
103 0 : if (deleteValue) delete compDirValue;
104 0 : return retVal;
105 0 : }
106 :
107 :
108 0 : 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 0 : DebugAssert(ok(), AipsError);
115 0 : const uInt nSamples = directions.nelements();
116 0 : DebugAssert(scale.nelements() == nSamples, AipsError);
117 :
118 0 : const MDirection& compDir(refDirection());
119 0 : const MDirection::Ref& compDirFrame(compDir.getRef());
120 0 : const MDirection::MVType* compDirValue = &(compDir.getValue());
121 0 : Bool deleteValue = false;
122 : // Convert direction to the same frame as the reference direction
123 0 : if (refFrame != compDirFrame) {
124 0 : compDirValue = new MDirection::MVType
125 0 : (MDirection::Convert(compDir, refFrame)().getValue());
126 0 : deleteValue = true;
127 : }
128 : //
129 0 : const Double longSize = abs(pixelLongSize.radian());
130 0 : const Double latSize = abs(pixelLatSize.radian());
131 0 : const Double nearSize = max(latSize, longSize);
132 0 : scale = 0.0;
133 : //
134 0 : for (uInt i = 0; i < nSamples; i++) {
135 0 : const MDirection::MVType& dirValue = directions(i);
136 0 : scale(i) = dirIsInPixel (longSize, latSize, nearSize, dirValue, compDirValue);
137 : }
138 0 : if (deleteValue) delete compDirValue;
139 0 : }
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 25600 : void PointShape::visibility(Matrix<DComplex>& scale, const Matrix<Double>& uvw,
155 : const Vector<Double> & freq) const {
156 25600 : DebugAssert(ok(), AipsError);
157 25600 : scale.resize(uvw.ncolumn(), freq.nelements());
158 25600 : scale = DComplex(1.0, 0.0);
159 25600 : }
160 :
161 0 : Bool PointShape::isSymmetric() const {
162 0 : DebugAssert(ok(), AipsError);
163 0 : return true;
164 : }
165 :
166 1 : ComponentShape* PointShape::clone() const {
167 1 : DebugAssert(ok(), AipsError);
168 1 : ComponentShape* tmpPtr = new PointShape(*this);
169 1 : AlwaysAssert(tmpPtr != 0, AipsError);
170 1 : return tmpPtr;
171 : }
172 :
173 0 : uInt PointShape::nParameters() const {
174 0 : DebugAssert(ok(), AipsError);
175 0 : return 0;
176 : }
177 :
178 0 : void PointShape::setParameters(const Vector<Double>& newParms) {
179 0 : DebugAssert(newParms.nelements() == nParameters(), AipsError);
180 0 : DebugAssert(ok(), AipsError);
181 : // Suppress compiler warning about unused variable
182 0 : if (newParms.empty()) {};
183 0 : }
184 :
185 0 : Vector<Double> PointShape::parameters() const {
186 0 : DebugAssert(ok(), AipsError);
187 0 : return Vector<Double>(0);
188 : }
189 :
190 0 : void PointShape::setErrors(const Vector<Double>& newErrors) {
191 0 : DebugAssert(newErrors.nelements() == nParameters(), AipsError);
192 0 : DebugAssert(ok(), AipsError);
193 : // Suppress compiler warning about unused variable
194 0 : if (newErrors.empty()) {};
195 0 : }
196 :
197 0 : Vector<Double> PointShape::errors() const {
198 0 : DebugAssert(ok(), AipsError);
199 0 : 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 25600 : Bool PointShape::fromRecord(String& errorMessage,
214 : const RecordInterface& record) {
215 25600 : DebugAssert(ok(), AipsError);
216 25600 : return ComponentShape::fromRecord(errorMessage, record);
217 : }
218 :
219 800 : Bool PointShape::toRecord(String& errorMessage,
220 : RecordInterface& record) const {
221 800 : DebugAssert(ok(), AipsError);
222 800 : 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 257624 : Bool PointShape::ok() const {
231 257624 : return ComponentShape::ok();
232 : }
233 :
234 0 : const ComponentShape* PointShape::getPtr() const {
235 0 : return this;
236 : }
237 :
238 :
239 0 : Double PointShape::dirIsInPixel (Double longSize, Double latSize, Double nearSize,
240 : const MDirection::MVType& dirValue,
241 : const MDirection::MVType* compDirValue) const
242 : {
243 0 : Double retVal = 0.0;
244 : //
245 0 : const Double separation = abs(compDirValue->separation(dirValue));
246 0 : if (separation <= nearSize) {
247 0 : const Double pa = compDirValue->positionAngle(dirValue);
248 : //
249 0 : if (abs(separation*sin(pa)) <= longSize/2.0 &&
250 0 : abs(separation*cos(pa)) <= latSize/2.0) {
251 0 : retVal = 1.0;
252 : }
253 : }
254 0 : 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 :
|