00001 //# PixelCurve1D.h: Arbitrary 1-dim curve in a lattice plane 00002 //# Copyright (C) 2003 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 receied 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 LATTICES_PIXELCURVE1D_H 00029 #define LATTICES_PIXELCURVE1D_H 00030 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/scimath/Functionals/Function1D.h> 00035 #include <casacore/casa/Arrays/Vector.h> 00036 00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00038 00039 //# Forward Declarations 00040 00041 00042 // <summary> 00043 // Arbitrary 1-dim curve in a lattice plane. 00044 // </summary> 00045 00046 // <use visibility=export> 00047 00048 // <reviewed reviewer="" date="" tests="tPixelCurve1D.cc"> 00049 // </reviewed> 00050 00051 // <prerequisite> 00052 //# Classes you should understand before using this one. 00053 // <li> <linkto class=Function1D>Function1D</linkto> 00054 // <li> <linkto class=CurvedLattice2D>CurvedLattice2D</linkto> 00055 // </prerequisite> 00056 00057 // <synopsis> 00058 // PixelCurve1D represents a 1-dim curve in a lattice plane to be 00059 // used by CurvedLattice2D. 00060 // The curve can be any function supported in the 00061 // <linkto module=Functionals>Functionals</linkto> module. 00062 // <br>A special constructor exists to define a straight line. 00063 // <br>Another special constructor exists for a polyline. 00064 // 00065 // The domain for which the curve is valid is given by the interval 00066 // [x1,x2]. The granularity of the domain is given by the number of 00067 // points. The number of points also define the length of the new axis 00068 // in the CurvedLattice2D object. 00069 // </synopsis> 00070 00071 // <example> 00072 // <srcblock> 00073 // // Use function y=cos(2*pi*x) on the interval [0,2] with 5 points. 00074 // Sinusoid1D<float> fn; 00075 // PixelCurve1D pcurve2(fn, 0., 2., 5); 00076 // AlwaysAssertExit (pcurve2.npoints() == 5); 00077 // pcurve2.getPixelCoord (x, y, 0, 4); 00078 // cout << x << y << endl; 00079 // </srcblock> 00080 // The result of x is [0, 0.5, 1, 1.5, 2]. 00081 // The result of y is [1, -1, 1, -1, 1] 00082 // </example> 00083 00084 // <motivation> 00085 // The viewer must be able to show a crosscut through an image using 00086 // an arbitrary curve. 00087 // </motivation> 00088 00089 // <todo asof=2003/10/23> 00090 // <li> Maybe it is better to make itsNpoints part of CurvedLattice 00091 // <li> If itsNpoint is still part of this class, it is possible to 00092 // precompute all possible Y values in the constructors. This may 00093 // speed things up for the polyline case. 00094 // </todo> 00095 00096 class PixelCurve1D 00097 { 00098 public: 00099 // Define a straight line from (x1,y1) to (x2,y2). 00100 // The default number of points is the length of the line. 00101 explicit PixelCurve1D (double x1=0, double y1=0, double x2=1, double y2=1, 00102 uInt npoints=0); 00103 00104 // Define a curve with an arbitrary function from x1 to x2. 00105 // The default number of points is the length of the curve. 00106 // The length of the curve is determined numerically by integration 00107 // of sqrt(1+sqr(df/dx)). 00108 PixelCurve1D (const Function1D<float,float>&, 00109 float x1, float x2, uInt npoints=0); 00110 00111 // Define a curve from a polyline with the given points. 00112 // Both vectors have to be equally long and at least 2 long. 00113 // The argument <src>npoints</src> defines the number of points 00114 // (with regular steps) in which the curve is divided. 00115 // The default is the length of the polyline. 00116 PixelCurve1D (const Vector<Int>& x, const Vector<Int>& y, 00117 uInt npoints=0); 00118 PixelCurve1D (const Vector<float>& x, const Vector<float>& y, 00119 uInt npoints=0); 00120 PixelCurve1D (const Vector<double>& x, const Vector<double>& y, 00121 uInt npoints=0); 00122 00123 PixelCurve1D (const PixelCurve1D& that); 00124 00125 ~PixelCurve1D(); 00126 00127 PixelCurve1D& operator= (const PixelCurve1D& that); 00128 00129 uInt npoints() const 00130 { return itsNpoints; } 00131 00132 // Get the pixel coordinates in the original lattice for point start 00133 // till end with given step. 00134 void getPixelCoord (Vector<float>& x, Vector<float>& y, 00135 uInt start, uInt end, uInt incr=1) const; 00136 00137 private: 00138 // Initialize the object. 00139 void init (const Vector<double>& x, const Vector<double>& y, uInt npoints); 00140 00141 uInt itsNpoints; 00142 Vector<double> itsX; 00143 Vector<double> itsY; 00144 }; 00145 00146 00147 00148 } //# NAMESPACE CASACORE - END 00149 00150 #endif