casa
$Rev:20696$
|
00001 //# AxesSpecifier.h: Specification of axes to keep or remove 00002 //# Copyright (C) 2000 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: AxesSpecifier.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00028 00029 #ifndef CASA_AXESSPECIFIER_H 00030 #define CASA_AXESSPECIFIER_H 00031 00032 00033 //# Includes 00034 #include <casa/aips.h> 00035 #include <casa/Arrays/IPosition.h> 00036 #include <casa/Arrays/AxesMapping.h> 00037 00038 namespace casa { //# NAMESPACE CASA - BEGIN 00039 00040 //# Forward Declarations 00041 00042 00043 // <summary> 00044 // Specification of axes to keep or remove 00045 // </summary> 00046 00047 // <use visibility=export> 00048 00049 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tAxesSpecifier.cc" demos=""> 00050 // </reviewed> 00051 00052 // <prerequisite> 00053 // <li> <linkto class="IPosition">IPosition</linkto> 00054 // </prerequisite> 00055 00056 // <synopsis> 00057 // AxesSpecifier makes it possible to specify which axes should 00058 // be used in a shape. Degenerate axes (i.e. axes with length 0) 00059 // can be thrown away which makes it possible to reduce the 00060 // dimensionality of an array. All degenerate axes can be thrown 00061 // away, but one can also specify which ones should be kept. 00062 // <p> 00063 // Another option of this class is to reorder the axes, thus to 00064 // make the axes of a lattice appear in a different order. 00065 // This can be useful when two images with diferent axes orders 00066 // have to be combined. 00067 // <p> 00068 // When an AxesSpecifier has to be used for a lattice, the lattice's 00069 // shape has to be applied to the AxesSpecifier. The result is 00070 // a <linkto class=AxesMapping>AxesMapping</linkto> object. 00071 // This object is (for example) used internally in the 00072 // <linkto class=SubLattice>SubLattice</linkto> class to know how 00073 // to map the axes form the original lattice to the sublattice. 00074 // <note role=caution> 00075 // Reordering axes is not supported (yet) by the other AIPS++ classes 00076 // like Lattices and Images. 00077 // </note> 00078 // </synopsis> 00079 00080 // <example> 00081 // This example tells that all degenerate axes have to be kept. 00082 // The axes are reordered to 1,0,2. Thus the first and second axes are 00083 // swapped. 00084 // <srcblock> 00085 // AxesSpecifier spec(True, IPosition(3,1,0,2)); 00086 // AxesMapping map = spec.apply (IPosition(3,4,1,5)); 00087 // AlwaysAssertExit (map.posToNew (IPosition(3,2,0,3)) == IPosition(3,0,2,3)); 00088 // AlwaysAssertExit (map.posToOld (IPosition(3,0,2,3)) == IPosition(3,2,0,3)); 00089 // 00090 // The following specification would have the same effect, because the 00091 // unspecified axes are kept in their natural order. 00092 // AxesSpecifier spec(True, IPosition(1,1)); 00093 // </srcblock> 00094 // 00095 // The same example as above, but now degenerated axes are removed. 00096 // Note that because the second axis is removed, the third axis now 00097 // get the second axis, thus gets swapped with the first axis. 00098 // <br>Also note the difference between the functions <src>posToOld</src> 00099 // and <src>shapeToOld</src>. 00100 // <srcblock> 00101 // AxesSpecifier spec(False, IPosition(1,1)); 00102 // AxesMapping map = spec.apply (IPosition(3,4,1,5)); 00103 // AlwaysAssertExit (map.posToNew (IPosition(3,2,0,3)) == IPosition(2,3,2)); 00104 // AlwaysAssertExit (map.posToOld (IPosition(3,3,2)) == IPosition(3,2,0,3); 00105 // AlwaysAssertExit (map.shapeToOld (IPosition(3,3,2)) == IPosition(3,2,1,3); 00106 // </srcblock> 00107 // </example> 00108 00109 //# <todo asof="yyyy/mm/dd"> 00110 //# </todo> 00111 00112 class AxesSpecifier 00113 { 00114 public: 00115 // The default constructor keeps all axes. 00116 AxesSpecifier(); 00117 00118 // Tell if no or all degenerate axes have to be removed. 00119 explicit AxesSpecifier (Bool keepDegenerate); 00120 00121 // Tell if no or all degenerate axes have to be removed. 00122 // <br>The argument <src>axisPath</src> makes it possible to specify in 00123 // which order the KEPT axes have to be used. Unspecified axes are 00124 // appended to the end. It gives a means to reorder the axes of a lattice. 00125 // <br>E.g. for a 4-dim lattice axisPath [2,0] means axis order [2,0,1,3]. 00126 explicit AxesSpecifier (Bool keepDegenerate, const IPosition& axisPath); 00127 00128 // Tell which (degenerate) axes have to be kept. 00129 // Non-degenerate axes will always be kept. 00130 explicit AxesSpecifier (const IPosition& keepAxes); 00131 00132 // The argument <src>keepAxes</src> tells which degenerate axes have 00133 // to be kept. Non-degenerate axes will always be kept. 00134 // <br>The argument <src>axisPath</src> makes it possible to specify in 00135 // which order the KEPT axes have to be used. Unspecified axes are 00136 // appended to the end. It gives a means to reorder the axes of a lattice. 00137 // <br>E.g. for a 4-dim lattice axisPath [2,0] means axis order [2,0,1,3]. 00138 AxesSpecifier (const IPosition& keepAxes, const IPosition& axisPath); 00139 00140 // Copy constructor (copy semantics). 00141 AxesSpecifier(const AxesSpecifier& other); 00142 00143 ~AxesSpecifier(); 00144 00145 // Assignment (copy semantics). 00146 // This and that do not have to have the same length. 00147 AxesSpecifier& operator= (const AxesSpecifier& other); 00148 00149 // Apply the specification to a shape. 00150 // It returns an <linkto class=AxesMapping>AxesMapping</linkto> 00151 // object which takes care of mapping old to new axes order. 00152 AxesMapping apply (const IPosition& shape) const; 00153 00154 // Are we keeping all degenerate axes ? 00155 Bool keep() const {return itsKeep;}; 00156 00157 private: 00158 IPosition itsAxes; 00159 IPosition itsPath; 00160 Bool itsKeep; 00161 }; 00162 00163 00164 00165 } //# NAMESPACE CASA - END 00166 00167 #endif