core/vnl/vnl_na.h

Go to the documentation of this file.
00001 // This is core/vnl/vnl_na.h
00002 #ifndef vnl_na_h_
00003 #define vnl_na_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 
00008 
00009 #include <vcl_iosfwd.h>
00010 
00011 //:
00012 // \file
00013 // \brief NA (Not Available) is a particular double NaN to represent missing data.
00014 // For example, where a vnl_vector<double> represents a series of samples from an image,
00015 // NA could be used to represent places where the measurement was taken outside the image.
00016 //
00017 // NA is distinct for the two other standard meanings of NaN - Indeterminate and Error.
00018 // It is entirely up to each algorithm to treat NA values meaningfully. Unless
00019 // a function's interpretation of NA is explicitly documentated, you should assume that
00020 // it will be treated similarly to every other NaN.
00021 // The IEEE754 bit value used to represent NA in double-precision is 0x7ff00000000007a2, the
00022 // same as used by Octave and R. Initial values of NA are stored as signalling NaNs, but
00023 // many uses will covert this to the non-signalling variant 0x7ff80000000007a2. vnl_isna()
00024 // will accept either variant.
00025 //
00026 // You can read and write floating point values from a stream using standard operators
00027 // by using a conversion manipulator.
00028 // \verbatim
00029 // double x, y;
00030 // is >> x >> y;
00031 // os << x << ' ' << y;
00032 // \endverbatim
00033 
00034  
00035 //: qNaN to indicate value Not Available.
00036 // Don't assume that any VXL functions will do something sensible in the face of NA, unless
00037 // explicitly documented.
00038 double   vnl_na();
00039 
00040 
00041 //: True if parameter is specific NA qNaN.
00042 // Tests for bit pattern 0x7ff00000000007a2, as used by Octave and R
00043 bool vnl_na_isna(double);
00044 
00045 
00046 //: Read a floating point number or "NA" from a stream.
00047 // Should beahve exactly like a>>x, if the extraction operator was aware of the
00048 // character sequence \code NA.
00049 void vnl_na_double_extract(vcl_istream &is, double& x);
00050 
00051 
00052 //: Write a floating point number or "NA" to a stream.
00053 // Should beahve exactly like a<<x, if the insertion operator was aware of the
00054 // character sequence \code NA.
00055 void vnl_na_double_insert(vcl_ostream &is, double x);
00056 
00057 
00058 
00059 //: Wrapper around a double that handles streaming NA.
00060 struct vnl_na_stream_t
00061 {
00062   double& x_;
00063   vnl_na_stream_t(double& x): x_(x) {}
00064 };
00065 
00066 //: Wrapper around a double that handles streaming NA.
00067 struct vnl_na_stream_const_t
00068 {
00069   const double& x_;
00070   vnl_na_stream_const_t(const double& x): x_(x) {}
00071 };
00072 
00073 //: Wrap a double to handle streaming NA.
00074 inline vnl_na_stream_t vnl_na_stream(double& x)
00075 {
00076   return vnl_na_stream_t(x);
00077 }
00078 
00079 //: Wrap a double to handle streaming NA.
00080 inline vnl_na_stream_const_t vnl_na_stream(const double& x)
00081 {
00082   return vnl_na_stream_const_t(x);
00083 }
00084 
00085 //: Insert wrapped double into stream, whilst handling NA.
00086 inline vcl_ostream& operator <<(vcl_ostream &os, const vnl_na_stream_t& ns)
00087 {
00088   vnl_na_double_insert(os, ns.x_);
00089   return os;
00090 }
00091 
00092 //: Insert wrapped double into stream, whilst handling NA.
00093 inline vcl_ostream& operator <<(vcl_ostream &os, const vnl_na_stream_const_t& ns)
00094 {
00095   vnl_na_double_insert(os, ns.x_);
00096   return os;
00097 }
00098 
00099 //: Extract wrapped double from stream, whilst handling NA.
00100 inline vcl_istream& operator >>(vcl_istream &is, const vnl_na_stream_t& ns)
00101 {
00102   vnl_na_double_extract(is, ns.x_);
00103   return is;
00104 }
00105 
00106 
00107 #endif // vnl_na_h_

Generated on Mon Mar 8 05:06:45 2010 for core/vnl by  doxygen 1.5.1