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_IMAGEPROXY_H
00030 #define IMAGES_IMAGEPROXY_H
00031
00032
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/images/Images/MaskSpecifier.h>
00035 #include <casacore/lattices/Lattices/LatticeBase.h>
00036 #include <casacore/lattices/Lattices/TiledShape.h>
00037 #include <casacore/casa/Utilities/CountedPtr.h>
00038 #include <casacore/casa/Containers/ValueHolder.h>
00039 #include <casacore/casa/Containers/Record.h>
00040
00041 namespace casacore {
00042
00043
00044 class ImageInfo;
00045 template<typename T> class ImageInterface;
00046 class LatticeExprNode;
00047 class CoordinateSystem;
00048 class ImageAttrHandler;
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 class ImageProxy
00077 {
00078 public:
00079
00080 ImageProxy();
00081
00082
00083
00084
00085 ImageProxy (const Vector<String>& names, Int axis);
00086
00087
00088
00089 ImageProxy (const String& name, const String& mask,
00090 const vector<ImageProxy>& images);
00091
00092
00093
00094
00095
00096
00097 ImageProxy (const vector<ImageProxy>& images, Int axis,
00098 Int dummy1=0, Int dummy2=0);
00099
00100
00101
00102
00103
00104
00105 ImageProxy (const ValueHolder& values,
00106 const ValueHolder& mask,
00107 const Record& coordinates,
00108 const String& imageName = String(),
00109 Bool overwrite = True,
00110 Bool asHDF5 = False,
00111 const String& maskName = String(),
00112 const IPosition& tileShape = IPosition());
00113
00114
00115
00116
00117
00118
00119 ImageProxy (const IPosition& shape,
00120 const ValueHolder& value,
00121 const Record& coordinates,
00122 const String& imageName = String(),
00123 Bool overwrite = True,
00124 Bool asHDF5 = False,
00125 const String& maskName = String(),
00126 const IPosition& tileShape = IPosition(),
00127 Int dummy=0);
00128
00129
00130 ImageProxy (const CountedPtr<LatticeBase>&);
00131
00132
00133 ImageProxy (const ImageProxy&);
00134
00135
00136 ImageProxy& operator= (const ImageProxy&);
00137
00138 ~ImageProxy();
00139
00140
00141
00142 static LatticeBase* openImage (const String& name,
00143 const String& mask = String(),
00144 const vector<ImageProxy>& images = vector<ImageProxy>());
00145
00146
00147
00148
00149
00150
00151 static LatticeBase* openImageOrExpr (const String& str,
00152 const MaskSpecifier&,
00153 const Block<LatticeExprNode>& nodes);
00154
00155
00156 void close();
00157
00158
00159 LatticeExprNode makeNode() const;
00160
00161
00162 Bool isPersistent() const;
00163
00164
00165 String name (Bool stripPath=False) const;
00166
00167
00168 IPosition shape() const;
00169
00170
00171 uInt ndim() const;
00172
00173
00174 uInt size() const;
00175
00176
00177 String dataType() const;
00178
00179 DataType type() const;
00180
00181
00182 String imageType() const;
00183
00184
00185 ValueHolder getData (const IPosition& blc,
00186 const IPosition& trc,
00187 const IPosition& inc);
00188
00189
00190 ValueHolder getMask (const IPosition& blc,
00191 const IPosition& trc,
00192 const IPosition& inc);
00193
00194
00195 void putData (const ValueHolder&,
00196 const IPosition& blc,
00197 const IPosition& inc);
00198
00199
00200
00201
00202 void putMask (const ValueHolder& value,
00203 const IPosition& blc,
00204 const IPosition& inc);
00205
00206
00207 Bool hasLock (Bool writeLock = False);
00208
00209
00210
00211
00212 void lock (Bool writeLock=False, Int nattempts=0);
00213
00214
00215 void unlock();
00216
00217
00218 Vector<String> attrGroupNames() const;
00219
00220
00221 void createAttrGroup (const String& groupName);
00222
00223
00224 Vector<String> attrNames (const String& groupName) const;
00225
00226
00227 uInt attrNrows (const String& groupName) const;
00228
00229
00230 ValueHolder getAttr (const String& groupName,
00231 const String& attrName,
00232 uInt rownr) const;
00233
00234
00235 Record getAttrRow (const String& groupName,
00236 uInt rownr) const;
00237
00238
00239 Vector<String> getAttrUnit(const String& groupName,
00240 const String& attrName) const;
00241
00242
00243 Vector<String> getAttrMeas(const String& groupName,
00244 const String& attrName) const;
00245
00246
00247
00248 void putAttr (const String& groupName, const String& attrName, uInt rownr,
00249 const ValueHolder& value,
00250 const Vector<String>& units,
00251 const Vector<String>& measInfo);
00252
00253
00254
00255 ImageProxy subImage (const IPosition& blc,
00256 const IPosition& trc,
00257 const IPosition& inc,
00258 Bool dropDegenerate=True);
00259
00260 ImageProxy subImage2 (const IPosition& blc,
00261 const IPosition& trc,
00262 const IPosition& inc,
00263 Bool dropDegenerate,
00264 Bool preserveAxesOrder);
00265
00266
00267 String unit() const;
00268
00269
00270 Record coordSys() const;
00271
00272 const CoordinateSystem& coordSysObject() const;
00273
00274
00275
00276
00277 Vector<Double> toWorld (const Vector<Double>& pixel,
00278 Bool reverseAxes);
00279
00280
00281
00282
00283 Vector<Double> toPixel (const Vector<Double>& world,
00284 Bool reverseAxes);
00285
00286
00287 Record imageInfo() const;
00288
00289 const ImageInfo& imageInfoObject() const;
00290
00291
00292 Record miscInfo() const;
00293
00294
00295 Vector<String> history() const;
00296
00297
00298
00299
00300 void toFits (const String& fitsfile, Bool overwrite=True,
00301 Bool velocity=True, Bool optical=True, Int bitpix=-32,
00302 Double minpix=1, Double maxpix=-1) const;
00303
00304
00305
00306 void saveAs (const String& fileName, Bool overwrite=True,
00307 Bool hdf5=False,
00308 Bool copyMask=True, const String& newMaskName=String(),
00309 const IPosition& newTileShape=IPosition()) const;
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 Record statistics (const Vector<Int>& axes,
00320 const String& mask,
00321 const ValueHolder& minMaxValues,
00322 Bool exclude = False,
00323 Bool robust = False) const;
00324
00325
00326
00327
00328
00329
00330 ImageProxy regrid (const Vector<Int>& axes = Vector<Int>(),
00331 const String& outfile = String(),
00332 Bool overwriteOutFile = True,
00333 const IPosition& outShape = IPosition(),
00334 const Record& coordSys = Record(),
00335 const String& method = "linear",
00336 Int decimate = 10,
00337 Bool replicate = False,
00338 Bool doRefChange = True,
00339 Bool forceRegrid = False);
00340
00341
00342
00343 static IPosition adjustBlc (const IPosition& blc, const IPosition& shp);
00344 static IPosition adjustTrc (const IPosition& trc, const IPosition& shp);
00345 static IPosition adjustInc (const IPosition& inc, const IPosition& shp);
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 LatticeBase* getLattice() const
00381 { return itsLattice.operator->(); }
00382
00383 private:
00384
00385 explicit ImageProxy (LatticeBase*);
00386
00387
00388 void checkNull() const;
00389
00390
00391 template<typename T>
00392 void makeImage (const Array<T>& array, const Array<Bool>& mask,
00393 const IPosition& shape, const Record& coordinates,
00394 const String& fileName, Bool asHDF5,
00395 const String& maskName,
00396 const IPosition& tileShape);
00397
00398
00399
00400 void concatImages (const std::vector<ImageProxy>& images, Int axis);
00401 void concatImagesFloat (const std::vector<ImageProxy>& images, Int axis);
00402 void concatImagesDouble (const std::vector<ImageProxy>& images, Int axis);
00403 void concatImagesComplex (const std::vector<ImageProxy>& images, Int axis);
00404 void concatImagesDComplex (const std::vector<ImageProxy>& images, Int axis);
00405
00406
00407
00408 void setup();
00409
00410
00411
00412 void setup (LatticeBase* lattice);
00413
00414
00415 void centreRefPix (CoordinateSystem& cSys,
00416 const IPosition& shape) const;
00417
00418
00419 template<typename T>
00420 void doPutMask (ImageInterface<T>& image,
00421 const ValueHolder& value,
00422 const IPosition& blc,
00423 const IPosition& inc);
00424
00425
00426
00427
00428 template <typename T>
00429 void saveImage (const String& fileName,
00430 Bool hdf5, Bool copyMask,
00431 const String& newMaskName,
00432 const IPosition& newTileShape,
00433 const ImageInterface<T>& image) const;
00434
00435
00436 TiledShape makeTiledShape (const IPosition& newTileShape,
00437 const IPosition& shape,
00438 const IPosition& oldTileShape=IPosition()) const;
00439
00440
00441 template<typename T>
00442 Record makeStatistics (const ImageInterface<T>& image,
00443 const Vector<Int>& axes,
00444 const String& mask,
00445 const ValueHolder& minMaxValues,
00446 Bool exclude,
00447 Bool robust) const;
00448
00449
00450 template<typename T>
00451 ImageProxy doRegrid (const ImageInterface<T>& image,
00452 const Vector<Int>& axes,
00453 const String& outfile,
00454 const IPosition& shape,
00455 const Record& coordSys,
00456 const String& method,
00457 Int decimate,
00458 Bool replicate,
00459 Bool doRefChange,
00460 Bool force);
00461
00462
00463
00464 CoordinateSystem makeCoordinateSystem (const Record& coordinates,
00465 const IPosition& shape) const;
00466
00467
00468
00469
00470 CountedPtr<LatticeBase> itsLattice;
00471 ImageInterface<Float>* itsImageFloat;
00472 ImageInterface<Double>* itsImageDouble;
00473 ImageInterface<Complex>* itsImageComplex;
00474 ImageInterface<DComplex>* itsImageDComplex;
00475 const CoordinateSystem* itsCoordSys;
00476 ImageAttrHandler* itsAttrHandler;
00477 };
00478
00479 }
00480
00481 #endif