/usr/include/casacore/images/Images/PagedImage.h is in casacore-dev 2.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | //# PagedImage.h: read, store and manipulate astronomical images
//# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2003
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
//# $Id$
#ifndef IMAGES_PAGEDIMAGE_H
#define IMAGES_PAGEDIMAGE_H
//# Includes
#include <casacore/casa/aips.h>
#include <casacore/images/Images/ImageInterface.h>
#include <casacore/images/Images/ImageAttrHandlerCasa.h>
#include <casacore/lattices/Lattices/PagedArray.h>
#include <casacore/tables/Tables/Table.h>
#include <casacore/casa/Utilities/DataType.h>
#include <casacore/tables/Tables/TableRecord.h>
//# Forward Declarations
#include <casacore/casa/iosfwd.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
// <summary>
// Read, store, and manipulate astronomical images.
// </summary>
// <use visibility=export>
// <reviewed reviewer="" date="" tests="tPagedmage.cc" demos="dPagedImage.cc">
// </reviewed>
// <prerequisite>
// <li> <linkto class=CoordinateSystem>CoordinateSystem</linkto>
// <li> <linkto class=ImageInterface>ImageInterface</linkto>
// <li> <linkto class=Lattice>Lattice</linkto>
// <li> <linkto class=LatticeIterator>LatticeIterator</linkto>
// <li> <linkto class=LatticeNavigator>LatticeNavigator</linkto>
// <li> <linkto class=ImageRegion>ImageRegion</linkto>
// </prerequisite>
// <etymology>
// The PagedImage name comes from its role as the Image class with paging
// from persistent memory. Users are thus invited to treat the
// PagedImage instances like Casacore Lattices
// </etymology>
// <synopsis>
// All Casacore Images are Lattices. They may be treated like any other Lattice;
// getSlice(...), putSlice(...), LatticeIterator for iterating, etc.
// ArrayImages contain a map, a mask for that map, and coordinate
// information. This provides a Lattice interface for images and their
// respective coordinates. Additional functionality is defined by the
// ImageInterface class.
//
// You can use the global function <src>imagePixelType</src> to determine
// what the pixel type of an image is before you open the image if your
// code can work with Images of many possible types, or for error checking.
//
// </synopsis>
// <example>
// This example shows how to create a mask for an image, fill it, and
// make it known to the image.
// <srcblock>
// // Open the image (as readonly for the moment).
// PagedImage<Float> myimage ("image.name");
// // Create a mask for the image.
// // The mask will be stored in a subtable of the image.
// LCPagedMask mask (RegionHandler::makeMask (myimage, "mask.name"));
// // Fill the mask with whatever values (e.g. all True).
// mask.set (True);
// // Make the mask known to the image (with name mask1).
// myimage.defineRegion ("mask1", mask, RegionHandler::Masks);
// // Make the mask the default mask for this image.
// myimage.setDefaultMask ("mask1");
// </srcblock>
// It is possible to create as many masks as one likes. They can all
// be defined as masks for the image (with different names, of course).
// However, only one of them can be the default mask (the mask used
// by default when the image is opened). When another mask has to be
// used, one can do two things:
// <ul>
// <li> Use setDefaultMask to make the other mask the default mask.
// This is advisable when the change should be more or less permanent.
// <li> Open the PagedImage without using a default mask. Thereafter
// a <linkto class=SubImage>SubImage</linkto> object can be created
// from the PagedImage and the mask. This is advisable when it the
// mask has to be used only one time.
// </ul>
// </example>
// <motivation>
// The size of astronomical data can be very large. The ability to fit an
// entire image into random access memory cannot be guaranteed. Paging from
// disk pieces of the image appeared to be the way to deal with this problem.
// </motivation>
//
// <note>
// When you make a new PagedImage, and you are transferring
// information from some other PagedImage, be aware that you
// must copy, manually, things like miscInfo, imageInfo, units,
// logSink (history) to the new file.
// </note>
// <todo asof="1996/09/04">
// <li> The CoordinateSystem::store() function returns a TableRecord. That
// TableRecord should be stored in the same row as our image. This will
// allow ImageStack members to have their own coordinate frames.
// </todo>
template <class T> class PagedImage: public ImageInterface<T>
{
public:
// Construct a new Image from shape and coordinate information.
// Data will be stored in the argument table.
PagedImage (const TiledShape& mapShape,
const CoordinateSystem& coordinateInfo,
Table& table,
uInt rowNumber = 0);
// Construct a new Image from shape and coordinate information. Table
// will be stored in the named file.
PagedImage (const TiledShape& mapShape,
const CoordinateSystem& coordinateInfo,
const String& nameOfNewFile,
uInt rowNumber = 0);
// Construct a new Image from shape and coordinate information. Table
// will be stored in the named file.
// The lock options may be specified
// <group>
PagedImage (const TiledShape& mapShape,
const CoordinateSystem& coordinateInfo,
const String& nameOfNewFile,
TableLock::LockOption,
uInt rowNumber = 0);
PagedImage (const TiledShape& mapShape,
const CoordinateSystem& coordinateInfo,
const String& nameOfNewFile,
const TableLock& lockOptions,
uInt rowNumber = 0);
// </group>
// Reconstruct an image from a pre-existing file.
// By default the default pixelmask (if available) is used.
explicit PagedImage (Table& table, MaskSpecifier = MaskSpecifier(),
uInt rowNumber = 0);
// Reconstruct an image from a pre-existing file.
// By default the default pixelmask (if available) is used.
explicit PagedImage (const String& filename, MaskSpecifier = MaskSpecifier(),
uInt rowNumber = 0);
// Reconstruct an image from a pre-existing file with Locking.
// By default the default pixelmask (if available) is used.
// <group>
PagedImage (const String& filename, TableLock::LockOption,
MaskSpecifier = MaskSpecifier(), uInt rowNumber = 0);
PagedImage (const String& filename, const TableLock& lockOptions,
MaskSpecifier = MaskSpecifier(), uInt rowNumber = 0);
// </group>
// Copy constructor (reference semantics).
PagedImage (const PagedImage<T>& other);
~PagedImage();
// Assignment operator (reference semantics).
PagedImage<T>& operator= (const PagedImage<T>& other);
// Make a copy of the object (reference semantics).
virtual ImageInterface<T>* cloneII() const;
// Return the name of this derived class.
static String className()
{ return "PagedImage"; }
// Get the image type (returns name of this derived class).
virtual String imageType() const;
// A PagedImage is always persistent.
virtual Bool isPersistent() const;
// A PagedImage is always paged to disk.
virtual Bool isPaged() const;
// Is the PagedImage writable?
virtual Bool isWritable() const;
// Does the image object use a pixelmask?
virtual Bool hasPixelMask() const;
// Get access to the pixelmask used.
// An exception is thrown if the image does not use a pixelmask.
// <group>
virtual const Lattice<Bool>& pixelMask() const;
virtual Lattice<Bool>& pixelMask();
// </group>
// Get a pointer the default pixelmask object used with this image.
// It returns 0 if no default pixelmask is used.
virtual const LatticeRegion* getRegionPtr() const;
// Set the default pixelmask to the mask with the given name
// (which has to exist in the "masks" group).
// If the image table is writable, the setting is persistent by writing
// the name as a keyword.
// If the given regionName is the empty string,
// the default pixelmask is unset.
virtual void setDefaultMask (const String& maskName);
// Use the mask as specified.
// If a mask was already in use, it is replaced by the new one.
virtual void useMask (MaskSpecifier = MaskSpecifier());
// Function to change the name of the Table file on disk.
// PagedImage is given a file name at construction time. You may change
// that name here.
void rename (const String& newName);
// Return the current Table name. By default this includes the full path.
// the path preceding the file name can be stripped off on request.
virtual String name (Bool stripPath=False) const;
// Return the current TableColumn row number.
uInt rowNumber() const;
// Return the shape of the image.
virtual IPosition shape() const;
// Change the shape of the image (N.B. the data is thrown away).
virtual void resize (const TiledShape& newShape);
// Function which extracts an array from the map.
virtual Bool doGetSlice (Array<T>& buffer, const Slicer& theSlice);
// Function to replace the values in the map with soureBuffer.
virtual void doPutSlice (const Array<T>& sourceBuffer,
const IPosition& where,
const IPosition& stride);
// Replace every element, x, of the lattice with the result of f(x).
// you must pass in the address of the function -- so the function
// must be declared and defined in the scope of your program.
// Both versions of apply require a function that accepts a single
// argument of type T (the Lattice template actual type) and returns
// a result of the same type. The first apply expects a function with
// an argument passed by value; the second expects the argument to
// be passed by const reference. The first form ought to run faster
// for the built-in types, which may be an issue for large Lattices
// stored in memory, where disk access is not an issue.
// <group>
virtual void apply (T (*function)(T));
virtual void apply (T (*function)(const T& ));
virtual void apply (const Functional<T,T>& function);
// </group>
// Add a lattice to this image.
PagedImage<T>& operator+= (const Lattice<T>& other);
// Function which sets the units associated with the image
// pixels (i.e. the "brightness" unit). <src>setUnits()</src> returns
// False if it cannot set the unit for some reason (e.g. the underlying
// file is not writable).
virtual Bool setUnits (const Unit& newUnits);
// Return the table holding the data.
Table& table()
{ return map_p.table(); }
// Flushes the new coordinate system to disk if the table is writable.
virtual Bool setCoordinateInfo (const CoordinateSystem& coords);
// Check for symmetry in data members.
virtual Bool ok() const;
// These are the true implementations of the paran operator.
// <note> Not for public use </note>
// <group>
virtual T getAt (const IPosition& where) const;
virtual void putAt (const T& value, const IPosition& where);
// </group>
// Replace the miscinfo in the PagedImage.
// It can fail if, e.g., the underlying table is not writable.
virtual Bool setMiscInfo (const RecordInterface& newInfo);
// The ImageInfo object contains some miscellaneous information about the
// image, which unlike that stored in MiscInfo, has a standard list of
// things, such as the restoring beam.
// Note that setImageInfo REPLACES the information with the new information.
// It can fail if, e.g., the underlying table is not writable.
virtual Bool setImageInfo(const ImageInfo& info);
// Get access to the attribute handler.
// If a handler keyword does not exist yet, it is created if
// <src>createHandler</src> is set.
// Otherwise the handler is empty and no groups can be created for it.
virtual ImageAttrHandler& attrHandler (Bool createHandler=False);
// Remove a region/mask belonging to the image from the given group
// (which can be Any).
// If a mask removed is the default mask, the image gets unmasked.
// <br>Optionally an exception is thrown if the region does not exist.
virtual void removeRegion (const String& name,
RegionHandler::GroupType = RegionHandler::Any,
Bool throwIfUnknown = True);
// This is the implementation of the letter for the envelope Iterator
// class. <note> Not for public use </note>.
virtual LatticeIterInterface<T>* makeIter
(const LatticeNavigator& navigator,
Bool useRef) const;
// Returns the maximum recommended number of pixels for a cursor. This is
// the number of pixels in a tile.
virtual uInt advisedMaxPixels() const;
// Help the user pick a cursor for most efficient access.
virtual IPosition doNiceCursorShape (uInt maxPixels) const;
// Maximum size - not necessarily all used. In pixels.
virtual uInt maximumCacheSize() const;
// Set the maximum (allowed) cache size as indicated.
virtual void setMaximumCacheSize (uInt howManyPixels);
// Set the cache size as to "fit" the indicated path.
virtual void setCacheSizeFromPath (const IPosition& sliceShape,
const IPosition& windowStart,
const IPosition& windowLength,
const IPosition& axisPath);
// Set the actual cache size for this Array to be be big enough for the
// indicated number of tiles. This cache is not shared with PagedArrays
// in other rows and is always clipped to be less than the maximum value
// set using the setMaximumCacheSize member function.
// tiles. Tiles are cached using a first in first out algorithm.
virtual void setCacheSizeInTiles (uInt howManyTiles);
// Clears and frees up the caches, but the maximum allowed cache size is
// unchanged from when setCacheSize was called
virtual void clearCache();
// Report on cache success.
virtual void showCacheStatistics (ostream& os) const;
// Handle the (un)locking.
// Unlocking also unlocks the logtable and a possible mask table.
// Locking only locks the image itself.
// <group>
virtual Bool lock (FileLocker::LockType, uInt nattempts);
virtual void unlock();
virtual Bool hasLock (FileLocker::LockType) const;
// </group>
// Resynchronize the PagedImage object with the table contents.
// The logtable and possible mask table are also synchronized if
// they do not have a readlock.
// <br>This function is only useful if no read-locking is used, ie.
// if the table lock option is UserNoReadLocking or AutoNoReadLocking.
// In that cases the table system does not acquire a read-lock, thus
// does not synchronize itself automatically.
virtual void resync();
// Flush the data.
virtual void flush();
// Close the Image and associated files temporarily.
// It'll be reopened automatically when needed or when
// <src>reopen</src> is called explicitly.
virtual void tempClose();
// If needed, reopen a temporarily closed Image.
virtual void reopen();
private:
// Function to return the internal Table object to the RegionHandler.
static Table& getTable (void* imagePtr, Bool writable);
// This must be called in every constructor and place where the image
// is attached to a new image.
void attach_logtable();
void open_logtable();
void restoreUnits (const TableRecord& rec);
void restoreMiscInfo (const TableRecord& rec);
void restoreImageInfo (const TableRecord& rec);
void restoreAll (const TableRecord& rec);
void check_conformance (const Lattice<T>& other);
void reopenRW();
void setTableType();
void applyMaskSpecifier (const MaskSpecifier&);
void applyMask (const String& maskName);
void makePagedImage (const TiledShape& mapShape,
const CoordinateSystem& coordinateInfo,
const String& nameOfNewFile,
const TableLock& lockOptions,
uInt rowNumber);
void makePagedImage (const String& filename, const TableLock& lockOptions,
const MaskSpecifier&, uInt rowNumber);
const Table& table() const
{ return const_cast<PagedImage<T>*>(this)->table(); }
PagedArray<T> map_p;
LatticeRegion* regionPtr_p;
ImageAttrHandlerCasa itsAttrHandler;
//# Make members of parent class known.
public:
using ImageInterface<T>::logSink;
using ImageInterface<T>::logger;
using ImageInterface<T>::imageInfo;
using ImageInterface<T>::coordinates;
using ImageInterface<T>::getDefaultMask;
using ImageInterface<T>::hasRegion;
using ImageInterface<T>::getImageRegionPtr;
protected:
using ImageInterface<T>::setCoordsMember;
using ImageInterface<T>::setMiscInfoMember;
using ImageInterface<T>::setLogMember;
using ImageInterface<T>::setUnitMember;
using ImageInterface<T>::setImageInfoMember;
};
//# A nasty - the column name is hard-coded into this function, needs to
//# be centralized somewhere.
// Determine the pixel type in the PagedImage contained in
// <src>fileName</src>. If the file doesn't appear to be a Table or cannot
// be opened, TpOther is returned.
// <group name="pixeltype")
DataType imagePixelType(const String& fileName);
// </group>
//# Declare extern templates for often used types.
#ifdef AIPS_CXX11
extern template class PagedImage<Float>;
extern template class PagedImage<Complex>;
#endif
} //# NAMESPACE CASACORE - END
#ifndef CASACORE_NO_AUTO_TEMPLATES
#include <casacore/images/Images/PagedImage.tcc>
#endif //# CASACORE_NO_AUTO_TEMPLATES
#endif
|