casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Viff.h
Go to the documentation of this file.
00001 //# Viff.h: Convert between Khoros Viff format and AIPS++ Arrays
00002 //# Copyright (C) 1993,1994,1995,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 //# $Id$
00027 
00028 #ifndef NRAO_VIFF_H
00029 #define NRAO_VIFF_H
00030 
00031 // .LIB(aips)
00032 
00033 // This class encapsulates the Khoros "Viff" format. It will normally be
00034 // used to interconvert AIPS++ in-memory arrayss and Viff disk files. The
00035 // primary limitation of the Viff format is that it can only deal with up-to
00036 // 3-dimensional arrays. If an array of greater than 3-dimensions is put into
00037 // a Viff structure an error is returned (first, however an attempt is made
00038 // to remove degenerate (length==1) axes).
00039 
00040 // All Viff types are handled, and conversions will occur automatically.
00041 // The conversions use the normal C++ assignments, e.g. converting from floats
00042 // to bytes is not apt to be very meaningful (maybe we should put in automatic
00043 // scalings?).
00044 
00045 // TBF - At the moment the user array types are only floats, although any underlying
00046 // Viff format is supported, except for the complex types.
00047 
00048 #include <casa/aips.h>
00049 
00050 // These should be forward declared; how do you do that with templates?
00051 #include <casa/Arrays/Array.h>
00052 #include <casa/Arrays/Cube.h>
00053 #include <casa/BasicSL/Complex.h>
00054 
00055 struct xvimage; // From Khoros
00056 class String;
00057 
00058 class Viff {
00059 public:
00060     enum {BYTE, SHORT, INTEGER, FLOAT, DOUBLE, COMPLEX, DCOMPLEX};
00061     Viff();
00062 
00063     ~Viff();
00064 
00065     // Put Array (or any class derived from it, Vector, Matrix, Cube...)
00066     // into this Viff structure. Non-degenerate arrays of dimension >=4
00067     // will cause a "False" to be returned, since Viff images are restricted
00068     // to 3 dimensions. When the Viff type and the Array types differ,
00069     // a conversion will be done. Complex types are turned into real and
00070     // integer by taking the real component.
00071     Bool put(const Array<float> &array);
00072     Bool put(const Array<Complex> &array);
00073 
00074     // Get the Array out of this Viff structre. If the Viff structure isn't 
00075     // initialized it will return a 0-sized array and set the flag to False.
00076     // This will convert from the internal Viff type to the desired Array<T>
00077     // type. Complex types are turned into real
00078     // and integer types by taking the real component.
00079     Bool get(Array<float> &array);
00080     Bool get(Array<Complex> &array);
00081 
00082     // Read the Viff file specified by name; return false if it fails
00083     // (file does not exist, no permissions, etc).
00084     Bool read(String name);
00085 
00086     // Write the current Viff structure to a file; create a 0-sized Viff
00087     // image if this object has not been previously filled (by read or by
00088     // put). Return True if this succeeds, False otherwise. Note that this
00089     // will overwrite an existing file.
00090     Bool write(String name);
00091 
00092     // Viff can be thought of as always containing a "3D" data structure, and
00093     // a vector is when only one of the dimentions is non-unity. nx(), ny() and
00094     // nx() return 0 if the Viff object isn't defined.
00095     uInt nx() const;
00096     uInt ny() const;
00097     uInt nz() const;
00098 
00099     // We can assign an N dimensional location to each (x,y) position in
00100     // the Viff object (yes, this is strange - ask the authors of Viff), 
00101     // i.e. we can assign nx()*ny() N-dimensional locations. Fundamentally
00102     // this is done by giving a Cube<float> of values where the first two
00103     // indices in the Cube correspond to the (x,y) in the Viff structure, and
00104     // the Z-depth of the cube corresponds to the dimensionality of the
00105     // positions we want to assign.
00106     // Because a Cube can be constructed from a Vector, to create a file which
00107     // contains a y vs x vector plot, you merely have to do something like:
00108     // viff.put(y); viff.putLocations(x);
00109     Bool putLocations(const Cube<float> &);
00110 
00111 private:
00112     // These members are the arguments to create image;
00113     void setDefaults();
00114     unsigned long col_size, row_size, num_data_bands; // shape parameters
00115     unsigned long data_storage_type;                  // Defaults to float
00116     unsigned long num_of_images;                      // always 1
00117     char *comment;
00118     unsigned long map_row_size, map_col_size,         // Maps aren't used
00119               map_scheme, map_storage_type;
00120     unsigned long location_type, location_dim;
00121 
00122     xvimage *kimage;
00123 };
00124 
00125 #endif