00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef IMAGES_IMAGEREGRID_H
00030 #define IMAGES_IMAGEREGRID_H
00031
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/Arrays/Matrix.h>
00034 #include <casacore/casa/Arrays/Cube.h>
00035 #include <casacore/measures/Measures/MDirection.h>
00036 #include <casacore/measures/Measures/MFrequency.h>
00037 #include <casacore/scimath/Mathematics/Interpolate2D.h>
00038 #include <set>
00039
00040 namespace casacore {
00041
00042 template<class T> class MaskedLattice;
00043 template<class T> class ImageInterface;
00044 template<class T> class Lattice;
00045 template<class T> class LatticeIterator;
00046 template<class T> class Vector;
00047
00048 class CoordinateSystem;
00049 class DirectionCoordinate;
00050 class Coordinate;
00051 class ObsInfo;
00052 class IPosition;
00053 class Unit;
00054 class ProgressMeter;
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 template <class T> class ImageRegrid
00120 {
00121 public:
00122
00123
00124 ImageRegrid();
00125
00126
00127 ImageRegrid(const ImageRegrid &other);
00128
00129
00130 ~ImageRegrid();
00131
00132
00133 ImageRegrid<T>& operator=(const ImageRegrid& other);
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 void regrid(ImageInterface<T>& outImage,
00149 typename Interpolate2D::Method method,
00150 const IPosition& whichOutPixelAxes,
00151 const ImageInterface<T>& inImage,
00152 Bool replicate=False, uInt decimate=0,
00153 Bool showProgress=False, Bool forceRegrid=False,
00154 Bool verbose=False);
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 void get2DCoordinateGrid (Cube<Double>& grid, Matrix<Bool>& gridMask) const;
00169 void set2DCoordinateGrid (const Cube<Double>& grid, const Matrix<Bool>& gridMask, Bool notify=False);
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 Bool insert(ImageInterface<T>& outImage,
00181 const Vector<Double>& outPixelLocation,
00182 const ImageInterface<T>& inImage);
00183
00184
00185
00186 void showDebugInfo(Int level=0) {itsShowLevel = level;};
00187
00188
00189 void disableReferenceConversions(Bool disable=True) {itsDisableConversions = disable;};
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 static CoordinateSystem makeCoordinateSystem(
00208 LogIO& os,
00209 std::set<Coordinate::Type>& coordsToBeRegridded,
00210 const CoordinateSystem& cSysTo,
00211 const CoordinateSystem& cSysFrom,
00212 const IPosition& axes,
00213 const IPosition& inShape=IPosition(),
00214 Bool giveStokesWarning=True
00215 );
00216
00217 private:
00218
00219 Int itsShowLevel;
00220 Bool itsDisableConversions;
00221
00222 Cube<Double> its2DCoordinateGrid;
00223 Matrix<Bool> its2DCoordinateGridMask;
00224
00225 Cube<Double> itsUser2DCoordinateGrid;
00226 Matrix<Bool> itsUser2DCoordinateGridMask;
00227 Bool itsNotify;
00228
00229
00230
00231 void _checkAxes(IPosition& outPixelAxes,
00232 const IPosition& inShape,
00233 const IPosition& outShape,
00234 const Vector<Int>& pixelAxisMap,
00235 const CoordinateSystem& outCoords,
00236 Bool verbose);
00237
00238
00239 void findMaps (uInt nDim,
00240 Vector<Int>& pixelAxisMap1,
00241 Vector<Int>& pixelAxisMap2,
00242 const CoordinateSystem& inCoords,
00243 const CoordinateSystem& outCoords) const;
00244
00245
00246 Double findScaleFactor(const Unit& units,
00247 const CoordinateSystem& inCoords,
00248 const CoordinateSystem& outCoords,
00249 Int inCoordinate, Int outCoordinate,
00250 LogIO& os) const;
00251
00252
00253 void _regridOneCoordinate (LogIO& os, IPosition& outShape2,
00254 Vector<Bool>& doneOutPixelAxes,
00255 MaskedLattice<T>* &finalOutPtr,
00256 MaskedLattice<T>* &inPtr,
00257 MaskedLattice<T>* &outPtr,
00258 CoordinateSystem& outCoords,
00259 const CoordinateSystem& inCoords,
00260 Int outPixelAxis,
00261 const ImageInterface<T>& inImage,
00262 const IPosition& outShape,
00263 Bool replicate, uInt decimate,
00264 Bool outIsMasked, Bool showProgress,
00265 Bool forceRegrid,
00266 typename Interpolate2D::Method method,
00267 Bool verbose);
00268
00269
00270 void regridTwoAxisCoordinate (LogIO& os, MaskedLattice<T>& outLattice,
00271 const MaskedLattice<T>& inLattice,
00272 const Unit& imageUnit,
00273 const CoordinateSystem& inCoords,
00274 const CoordinateSystem& outCoords,
00275 Int inCoordinate, Int outCoordinate,
00276 const Vector<Int> inPixelAxes,
00277 const Vector<Int> outPixelAxes,
00278 const Vector<Int> pixelAxisMap1,
00279 const Vector<Int> pixelAxisMap2,
00280 typename Interpolate2D::Method method,
00281 Bool replicate, uInt decimate,
00282 Bool showProgress);
00283
00284
00285 void make2DCoordinateGrid (LogIO& os, Bool& allFail, Bool&missedIt,
00286 Double& minInX, Double& minInY,
00287 Double& maxInX, Double& maxInY,
00288 Cube<Double>& in2DPos,
00289 Matrix<Bool>& succeed,
00290 const CoordinateSystem& inCoords,
00291 const CoordinateSystem& outCoords,
00292 Int inCoordinate, Int outCoordinate,
00293 uInt xInAxis, uInt yInAxis,
00294 uInt xOutAxis, uInt yOutAxis,
00295 const IPosition& inPixelAxes,
00296 const IPosition& outPixelAxes,
00297 const IPosition& inShape,
00298 const IPosition& outPos,
00299 const IPosition& cursorShape,
00300 uInt decimate=0);
00301
00302
00303 void make2DCoordinateGrid (Cube<Double>& in2DPos,
00304 Double& minInX, Double& minInY,
00305 Double& maxInX, Double& maxInY,
00306 const Vector<Double>& pixelScale,
00307 uInt xInAxis, uInt yInAxis,
00308 uInt xOutAxis, uInt yOutAxis,
00309 uInt xInCorrAxis, uInt yInCorrAxis,
00310 uInt xOutCorrAxis, uInt yOutCorrAxis,
00311 const IPosition& outPos, const IPosition& cursorShape);
00312
00313
00314 void make1DCoordinateGrid (Block<Float>& xOut,
00315 Vector<Bool>& failed,
00316 Bool& allFailed,
00317 Bool& allGood,
00318 const Coordinate& inCoord,
00319 const Coordinate& outCoord,
00320 Int inAxisInCoordinate,
00321 Int outAxisInCoordinate,
00322 MFrequency::Convert& machine,
00323 Bool useMachine);
00324
00325
00326
00327 void make1DCoordinateGrid (Block<Float>& xOut, Float pixelScale) const;
00328
00329
00330 void regrid1D (MaskedLattice<T>& outLattice,
00331 const MaskedLattice<T>& inLattice,
00332 const Coordinate& inCoord,
00333 const Coordinate& outCoord,
00334 const Vector<Int>& inPixelAxes,
00335 const Vector<Int>& outPixelAxes,
00336 Int inAxisInCoordinate,
00337 Int outAxisInCoordinate,
00338 const Vector<Int> pixelAxisMap,
00339 typename Interpolate2D::Method method,
00340 MFrequency::Convert& machine,
00341 Bool replicate,
00342 Bool useMachine, Bool showProgress);
00343
00344
00345 void regrid2DMatrix(Lattice<T>& outCursor,
00346 LatticeIterator<Bool>*& outMaskIterPtr,
00347 const Interpolate2D& interp,
00348 ProgressMeter*& pProgress,
00349 Double& iPix,
00350 uInt nDim,
00351 uInt xInAxis, uInt yInAxis,
00352 uInt xOutAxis, uInt yOutAxis,
00353 Double scale,
00354 Bool inIsMasked, Bool outIsMasked,
00355 const IPosition& outPos,
00356 const IPosition& outCursorShape,
00357 const IPosition& inChunkShape,
00358 const IPosition& inChunkBlc,
00359 const IPosition& pixelAxisMap2,
00360 Array<T>& inDataChunk,
00361 Array<Bool>*& inMaskChunkPtr,
00362 const Cube<Double>& pix2DPos,
00363 const Matrix<Bool>& succeed);
00364
00365 void findXYExtent (Bool& missedIt, Bool& allFailed,
00366 Double& minInX, Double& minInY,
00367 Double& maxInX, Double& maxInY,
00368 Cube<Double>& in2DPos,
00369 const Matrix<Bool>& succeed,
00370 uInt xInAxis, uInt yInAxis,
00371 uInt xOutAxis, uInt yOutAxis,
00372 const IPosition& outPos,
00373 const IPosition& outCursorShape,
00374 const IPosition& inShape);
00375
00376 Bool minmax(Double &minX, Double &maxX, Double& minY, Double& maxY,
00377 const Array<Double> &xData,
00378 const Array<Double> &yData,
00379 const Array<Bool>& mask);
00380 };
00381
00382
00383 #ifdef AIPS_CXX11
00384 extern template class ImageRegrid<Float>;
00385 #endif
00386
00387 }
00388
00389 #ifndef CASACORE_NO_AUTO_TEMPLATES
00390 #include <casacore/images/Images/ImageRegrid.tcc>
00391 #endif //# CASACORE_NO_AUTO_TEMPLATES
00392 #endif
00393