Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

A draft commit of the innermost library core.

  • Loading branch information...
commit 9053a9bb9d74e4cec549c24e9fa1b2e316b896c8 1 parent 37744b7
Matthew Hancher authored
View
56 Makefile.am
@@ -0,0 +1,56 @@
+# __BEGIN_LICENSE__
+#
+# Copyright (C) 2006 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration
+# (NASA). All Rights Reserved.
+#
+# This software is distributed under the NASA Open Source Agreement
+# (NOSA), version 1.3. The NOSA has been approved by the Open Source
+# Initiative. See the file COPYING at the top of the distribution
+# directory tree for the complete NOSA document.
+#
+# THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+# KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+# LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+# SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+# A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+# THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+# DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+#
+# __END_LICENSE__
+
+########################################################################
+# sources
+########################################################################
+
+SUBDIRS = src
+
+EXTRA_DIST = config/rules.mak config/relicense thirdparty
+
+########################################################################
+# special top-level rules
+########################################################################
+
+install-data-hook:
+ $(INSTALL) src/vw/config.h $(prefix)/include/vw/
+
+dist-hook:
+ rm -rf `find $(distdir) -name CVS`
+if DIST_LICENSE
+ cp $(DIST_LICENSE) $(distdir)/COPYING
+endif
+if DIST_LICENSE_SUMMARY
+ find $(distdir) -type f | config/relicense $(DIST_LICENSE_SUMMARY) -
+endif
+if DIST_CONFIG_OPTIONS_DEFAULT
+ cp $(DIST_CONFIG_OPTIONS_DEFAULT) $(distdir)/config/config.options.default
+endif
+
+doxygen:
+ cd src/vw; doxygen
+
+########################################################################
+# general
+########################################################################
+
+include $(top_srcdir)/config/rules.mak
View
32 src/Makefile.am
@@ -0,0 +1,32 @@
+# __BEGIN_LICENSE__
+#
+# Copyright (C) 2006 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration
+# (NASA). All Rights Reserved.
+#
+# This software is distributed under the NASA Open Source Agreement
+# (NOSA), version 1.3. The NOSA has been approved by the Open Source
+# Initiative. See the file COPYING at the top of the distribution
+# directory tree for the complete NOSA document.
+#
+# THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+# KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+# LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+# SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+# A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+# THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+# DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+#
+# __END_LICENSE__
+
+########################################################################
+# sources
+########################################################################
+
+SUBDIRS = vw
+
+########################################################################
+# general
+########################################################################
+
+include $(top_srcdir)/config/rules.mak
View
34 src/vw/Core.h
@@ -0,0 +1,34 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file Core.h
+///
+/// A convenience header that includes the header files in vw/Core.
+///
+#ifndef __VW_CORE_H__
+#define __VW_CORE_H__
+
+#include <vw/Core/Exception.h>
+#include <vw/Core/FundamentalTypes.h>
+#include <vw/Core/TypeDeduction.h>
+#include <vw/Core/Functors.h>
+
+#endif // __VW_CORE_H__
View
230 src/vw/Core/CompoundTypes.h
@@ -0,0 +1,230 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file CompoundTypes.h
+///
+/// Types and traits for compound (i.e. multi-channel) types.
+///
+#ifndef __VW_CORE_COMPOUND_TYPES_H__
+#define __VW_CORE_COMPOUND_TYPES_H__
+
+#include <boost/utility/result_of.hpp>
+
+#include <vw/Core/FundamentalTypes.h>
+
+namespace vw {
+
+ // Default compound type traits templates. Compound types are mainly used
+ // as pixel types, but the type traits machinery is defined here in more
+ // general terms to avoid undesirable dependencies.
+ template <class T> struct CompoundChannelType { typedef T type; };
+ template <class T> struct CompoundNumChannels { static const unsigned value = 1; };
+ template <class T, class ChannelT> struct CompoundChannelCast { typedef T type; };
+ template <class T> struct IsCompound
+ : public boost::mpl::not_< boost::is_same< typename CompoundChannelType<T>::type, T > >::type {};
+ template <class T1, class T2> struct CompoundIsCompatible
+ : public boost::is_same< typename CompoundChannelCast<T1, typename CompoundChannelType<T2>::type>::type, T2 >::type {};
+
+ // Default specializations of the compound type traits for const types.
+ template <class T> struct CompoundChannelType<const T> : public CompoundChannelType<T> {};
+ template <class T> struct CompoundNumChannels<const T> : public CompoundNumChannels<T> {};
+ template <class T, class ChannelT> struct CompoundChannelCast<const T, ChannelT> : public CompoundChannelCast<T, ChannelT> {};
+ template <class T> struct IsCompound<const T> : public IsCompound<T> {};
+ template <class T1, class T2> struct CompoundIsCompatible<T1, const T2> : public CompoundIsCompatible<T1,T2> {};
+
+
+ template <class FuncT>
+ class BinaryCompoundFunctor {
+ FuncT func;
+
+ // The general multi-channel case
+ template <bool CompoundB, int ChannelsN, class ResultT, class Arg1T, class Arg2T>
+ struct Helper {
+ static inline ResultT construct( FuncT const& func, Arg1T const& arg1, Arg2T const& arg2 ) {
+ ResultT result;
+ for( int i=0; i<ChannelsN; ++i ) result[i] = func(arg1[i],arg2[i]);
+ return result;
+ }
+ };
+
+ // Specialization for non-compound types
+ template <class ResultT, class Arg1T, class Arg2T>
+ struct Helper<false,1,ResultT,Arg1T,Arg2T> {
+ static inline ResultT construct( FuncT const& func, Arg1T const& arg1, Arg2T const& arg2 ) {
+ return func(arg1,arg2);
+ }
+ };
+
+ // Specialization for one-channel types
+ template <class ResultT, class Arg1T, class Arg2T>
+ struct Helper<true,1,ResultT,Arg1T,Arg2T> {
+ static inline ResultT construct( FuncT const& func, Arg1T const& arg1, Arg2T const& arg2 ) {
+ return ResultT( func(arg1[0],arg2[0]) );
+ }
+ };
+
+ // Specialization for two-channel types
+ template <class ResultT, class Arg1T, class Arg2T>
+ struct Helper<true,2,ResultT,Arg1T,Arg2T> {
+ static inline ResultT construct( FuncT const& func, Arg1T const& arg1, Arg2T const& arg2 ) {
+ return ResultT( func(arg1[0],arg2[0]), func(arg1[1],arg2[1]) );
+ }
+ };
+
+ // Specialization for three-channel types
+ template <class ResultT, class Arg1T, class Arg2T>
+ struct Helper<true,3,ResultT,Arg1T,Arg2T> {
+ static inline ResultT construct( FuncT const& func, Arg1T const& arg1, Arg2T const& arg2 ) {
+ return ResultT( func(arg1[0],arg2[0]), func(arg1[1],arg2[1]), func(arg1[2],arg2[2]) );
+ }
+ };
+
+ // Specialization for four-channel types
+ template <class ResultT, class Arg1T, class Arg2T>
+ struct Helper<true,4,ResultT,Arg1T,Arg2T> {
+ static inline ResultT construct( FuncT const& func, Arg1T const& arg1, Arg2T const& arg2 ) {
+ return ResultT( func(arg1[0],arg2[0]), func(arg1[1],arg2[1]), func(arg1[2],arg2[2]), func(arg1[3],arg2[3]) );
+ }
+ };
+
+ public:
+ BinaryCompoundFunctor() : func() {}
+ BinaryCompoundFunctor( FuncT const& func ) : func(func) {}
+
+ template <class ArgsT> struct result {};
+
+ template <class F, class Arg1T, class Arg2T>
+ struct result<F(Arg1T,Arg2T)> {
+ typedef typename CompoundChannelType<Arg1T>::type arg1_type;
+ typedef typename CompoundChannelType<Arg2T>::type arg2_type;
+ typedef typename boost::result_of<FuncT(arg1_type,arg2_type)>::type result_type;
+ typedef typename CompoundChannelCast<Arg1T,result_type>::type type;
+ };
+
+ template <class Arg1T, class Arg2T>
+ typename result<BinaryCompoundFunctor(Arg1T,Arg2T)>::type
+ inline operator()( Arg1T const& arg1, Arg2T const& arg2 ) {
+ typedef typename result<BinaryCompoundFunctor(Arg1T,Arg2T)>::type result_type;
+ return Helper<IsCompound<result_type>::value,CompoundNumChannels<result_type>::value,result_type,Arg1T,Arg2T>::construct(func,arg1,arg2);
+ }
+ };
+
+ template <class FuncT, class Arg1T, class Arg2T=void>
+ struct CompoundResult {
+ typedef typename boost::result_of<BinaryCompoundFunctor<FuncT>(Arg1T,Arg2T)>::type type;
+ };
+
+ template <class FuncT, class Arg1T, class Arg2T>
+ typename CompoundResult<FuncT,Arg1T,Arg2T>::type
+ inline compound_apply( FuncT const& func, Arg1T const& arg1, Arg2T const& arg2 ) {
+ return BinaryCompoundFunctor<FuncT>(func)(arg1,arg2);
+ }
+
+
+ template <class FuncT>
+ class UnaryCompoundFunctor {
+ FuncT func;
+
+ // The general multi-channel case
+ template <bool CompoundB, int ChannelsN, class ResultT, class ArgT>
+ struct Helper {
+ static inline ResultT construct( FuncT const& func, ArgT const& arg ) {
+ ResultT result;
+ for( int i=0; i<ChannelsN; ++i ) result[i] = func(arg[i]);
+ return result;
+ }
+ };
+
+ // Specialization for non-compound types
+ template <class ResultT, class ArgT>
+ struct Helper<false,1,ResultT,ArgT> {
+ static inline ResultT construct( FuncT const& func, ArgT const& arg ) {
+ return func(arg);
+ }
+ };
+
+ // Specialization for single-channel types
+ template <class ResultT, class ArgT>
+ struct Helper<true,1,ResultT,ArgT> {
+ static inline ResultT construct( FuncT const& func, ArgT const& arg ) {
+ return ResultT( func(arg[0]) );
+ }
+ };
+
+ // Specialization for two-channel types
+ template <class ResultT, class ArgT>
+ struct Helper<true,2,ResultT,ArgT> {
+ static inline ResultT construct( FuncT const& func, ArgT const& arg ) {
+ return ResultT( func(arg[0]), func(arg[1]) );
+ }
+ };
+
+ // Specialization for three-channel types
+ template <class ResultT, class ArgT>
+ struct Helper<true,3,ResultT,ArgT> {
+ static inline ResultT construct( FuncT const& func, ArgT const& arg ) {
+ return ResultT( func(arg[0]), func(arg[1]), func(arg[2]) );
+ }
+ };
+
+ // Specialization for four-channel types
+ template <class ResultT, class ArgT>
+ struct Helper<true,4,ResultT,ArgT> {
+ static inline ResultT construct( FuncT const& func, ArgT const& arg ) {
+ return ResultT( func(arg[0]), func(arg[1]), func(arg[2]), func(arg[3]) );
+ }
+ };
+
+ public:
+ UnaryCompoundFunctor() : func() {}
+ UnaryCompoundFunctor( FuncT const& func ) : func(func) {}
+
+ template <class ArgsT> struct result {};
+
+ template <class F, class ArgT>
+ struct result<F(ArgT)> {
+ typedef typename CompoundChannelType<ArgT>::type arg_type;
+ typedef typename boost::result_of<FuncT(arg_type)>::type result_type;
+ typedef typename CompoundChannelCast<ArgT,result_type>::type type;
+ };
+
+ template <class ArgT>
+ typename result<UnaryCompoundFunctor(ArgT)>::type
+ inline operator()( ArgT const& arg ) {
+ typedef typename result<UnaryCompoundFunctor(ArgT)>::type result_type;
+ return Helper<IsCompound<result_type>::value,CompoundNumChannels<result_type>::value,result_type,ArgT>::construct(func,arg);
+ }
+ };
+
+ template <class FuncT, class ArgT>
+ struct CompoundResult<FuncT,ArgT,void> {
+ typedef typename boost::result_of<UnaryCompoundFunctor<FuncT>(ArgT)>::type type;
+ };
+
+ template <class FuncT, class ArgT>
+ typename CompoundResult<FuncT,ArgT>::type
+ inline compound_apply( FuncT const& func, ArgT const& arg ) {
+ return UnaryCompoundFunctor<FuncT>(func)(arg);
+ }
+
+} // namespace vw
+
+#endif // __VW_CORE_COMPOUND_TYPES_H__
View
210 src/vw/Core/Exception.h
@@ -0,0 +1,210 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file Exception.h
+///
+/// Base exception classes and related macros.
+///
+/// The vw::Exception class serves as a base class for all VWB error
+/// types. It is designed to make it easy to throw exceptions with
+/// meaningful error messages. For example, the this invocation:
+///
+/// <TT>throw vw::Exception() << "Unable to open file \"" << filename << "\"!";</TT>
+///
+/// might generate a message like this:
+///
+/// <TT>terminate called after throwing an instance of 'vw::Exception'</TT>
+///
+/// <TT> what(): Unable to open file "somefile.foo"! </TT>
+///
+/// A variety of standard derived exception types are provided; in the
+/// above example, the exception should probably have been of type
+/// vw::IOErr. Also, two macros, VW_ASSERT(condition,exception) and
+/// VW_DEBUG_ASSERT(condition,exception), are provided, with the usual
+/// assertion semantics. The only difference is that the debug assertions
+/// will be disabled for increased performance in release builds when
+/// __VW_DEBUG_LEVEL__ is defined to zero (which happens by default when
+/// NDEBUG is defined).
+///
+/// Note that the base Exception class is not particularly lightweight.
+/// If you are throwing an exception that you intend to catch as part
+/// of the normal flow of your program, you should create your own
+/// (typically empty) class for this purpose. If you do that, however,
+/// you must be absolutely certain that you catch it everywhere it may
+/// be thrown. The user should only ever encounter exceptions derived
+/// from vw::Exception.
+///
+#ifndef __VW_CORE_EXCEPTION_H__
+#define __VW_CORE_EXCEPTION_H__
+
+#include <exception>
+#include <string>
+#include <sstream>
+#include <ostream>
+
+namespace vw {
+
+ /// The core exception class.
+ struct Exception : public std::exception {
+
+ /// The default constructor generates exceptions with empty error
+ /// message text. This is the cleanest approach if you intend to
+ /// use streaming (via operator <<) to generate your message.
+ Exception() throw() {}
+
+ /// Generates exceptions with the given error message text.
+ Exception( std::string const& s ) throw() { m_desc << s; }
+
+ virtual ~Exception() throw() {}
+
+ /// Copy Constructor
+ Exception( Exception const& e ) throw() {
+ m_desc << e.m_desc.str();
+ }
+
+ /// Assignment operator copies the error string.
+ Exception& operator=( Exception const& e ) throw() {
+ m_desc.str( e.m_desc.str() );
+ return *this;
+ }
+
+ /// Returns a the error message text for display to the user. The
+ /// returned pointer must be used immediately; other operations on
+ /// the exception may invalidate it. If you need the data for
+ /// later, you must save it to a local buffer of your own.
+ virtual const char* what() const throw() {
+ m_what_buf = m_desc.str();
+ return m_what_buf.c_str();
+ }
+
+ /// Returns the error message text as a std::string.
+ std::string desc() const { return m_desc.str(); }
+
+ protected:
+ // The error message text.
+ std::ostringstream m_desc;
+
+ // A buffer for storing the full exception description returned by
+ // the what() method, which must generate its return value from
+ // the current value of m_desc. The what() method provides no
+ // mechanism for freeing the returned string, and so we handle
+ // allocation of that memory here, internally to the exception.
+ mutable std::string m_what_buf;
+ };
+
+ // Use this macro to construct new exception types that do not add
+ // additional functionality. If you can think of a clean way to do
+ // this using templates instead of the preprocessor, please do. For
+ // now, we're stuck with this.
+ //
+ // Some functions need to return the *this pointer with the correct
+ // subclass type, and these are defined in the macro below rather
+ // than the base exception class above. These are:
+ //
+ // Exception::operator=():
+ // The assignment operator must return an instance of the subclass.
+ //
+ // Exception::operator<<():
+ // The streaming operator (<<) makes it possible to quickly
+ // generate error message text. This is currently implemented
+ // by simply forwarding invocations of this method to an
+ // internal ostringstream.
+ //
+ // Exception::set():
+ // Sets the error message text to the provided string, returning a
+ // reference to the exception for use with the streaming operator
+ // (<<) if desired.
+ //
+ // Exception::reset():
+ // Resets (i.e. clears) the error message text, returning a
+ // reference to the exception for use with the streaming operator
+ // (<<) if desired
+
+ /// Macro for quickly creating a hierarchy of exceptions, all of
+ /// which share the same functionality.
+ #define VW_DEFINE_EXCEPTION(name,base) \
+ struct name : public base { \
+ name() throw() : base() {} \
+ name(std::string const& s) throw() : base(s) {} \
+ name( name const& e ) throw() : base( e ) {} \
+ virtual ~name() throw() {} \
+ \
+ inline name& operator=( name const& e ) throw() { \
+ base::operator=( e ); \
+ return *this; \
+ } \
+ \
+ template <class T> \
+ name& operator<<( T const& t ) { m_desc << t; return *this; } \
+ \
+ name& set( std::string const& s ) { m_desc.str(s); return *this; } \
+ \
+ name& reset() { m_desc.str(""); return *this; } \
+ }
+
+ /// Invalid function argument exception
+ VW_DEFINE_EXCEPTION(ArgumentErr, Exception);
+
+ /// Incorrect program logic exception
+ VW_DEFINE_EXCEPTION(LogicErr, Exception);
+
+ /// Invalid program input exception
+ VW_DEFINE_EXCEPTION(InputErr, Exception);
+
+ /// IO failure exception
+ VW_DEFINE_EXCEPTION(IOErr, Exception);
+
+ /// Arithmetic failure exception
+ VW_DEFINE_EXCEPTION(MathErr, Exception);
+
+ /// Unexpected null pointer exception
+ VW_DEFINE_EXCEPTION(NullPtrErr, Exception);
+
+ /// Invalid type exception
+ VW_DEFINE_EXCEPTION(TypeErr, Exception);
+
+ /// Unimplemented functionality exception
+ VW_DEFINE_EXCEPTION(NoImplErr, Exception);
+
+} // namespace vw
+
+/// The VW_ASSERT macro throws the given exception if the given
+/// condition is not met. The VW_DEBUG_ASSERT macro does the
+/// same thing, but is disabled if __VW_DEBUG_LEVEL__ is zero.
+/// The default value for __VW_DEBUG_LEVEL__ is guessed based
+/// on whether or not NDEBUG is defined.
+#ifndef __VW_DEBUG_LEVEL__
+#ifdef NDEBUG
+#define __VW_DEBUG_LEVEL__ 0
+#else
+#define __VW_DEBUG_LEVEL__ 1
+#endif
+#endif
+
+#define VW_ASSERT(cond,excep) do { if(!(cond)) throw (excep); } while(0)
+#if __VW_DEBUG_LEVEL__ == 0
+#define VW_DEBUG_ASSERT(cond,excep) do {} while(0)
+#else
+// Duplicate the definition to avoid extra macro expansion in recusion
+#define VW_DEBUG_ASSERT(cond,excep) do { if(!(cond)) throw (excep); } while(0)
+#endif
+
+#endif // __VW_CORE_EXCEPTION_H__
View
464 src/vw/Core/Functors.h
@@ -0,0 +1,464 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file Functors.h
+///
+/// General-purpose functors and functor support code.
+///
+/// This file provides a few mix-in base classes that you can use when
+/// writing your own polymorphic functors. They instruct the return
+/// type deduction system about the return type of your functor in
+/// some of the common cases.
+///
+/// It also provides a collection of functors implementing the
+/// standard arithmetic operations and so forth, which also serve to
+/// demonstrate how to use the mix-ins.
+///
+#ifndef __VW_CORE_FUNCTORS_H__
+#define __VW_CORE_FUNCTORS_H__
+
+#include <vw/Core/TypeDeduction.h>
+
+namespace vw {
+
+ /// A mix-in specifying that a functor is an unary functor
+ /// whose return type is the same as its argument type.
+ struct UnaryReturnSameType {
+ /// \cond INTERNAL
+ template <class Args> struct result;
+ template <class ChannelT, class FuncT>
+ struct result<FuncT(ChannelT)> {
+ typedef ChannelT type;
+ };
+ /// \endcond
+ };
+
+ /// A mix-in specifying that a functor is a unary functor
+ /// whose return type is determined by the given traits
+ /// template class.
+ template <template<class> class ResultT>
+ struct UnaryReturnTemplateType {
+ /// \cond INTERNAL
+ template <class Args> struct result {};
+ template <class FuncT, class ArgT>
+ struct result<FuncT(ArgT)> {
+ typedef typename ResultT<ArgT>::type type;
+ };
+ /// \endcond
+ };
+
+ /// A mix-in specifying that a functor is a binary functor
+ /// whose return type is determined by the given traits
+ /// template class.
+ template <template<class,class> class ResultT>
+ struct BinaryReturnTemplateType {
+ /// \cond INTERNAL
+ template <class Args> struct result {};
+ template <class FuncT, class Arg1T, class Arg2T>
+ struct result<FuncT(Arg1T,Arg2T)> {
+ typedef typename ResultT<Arg1T,Arg2T>::type type;
+ };
+ /// \endcond
+ };
+
+ /// A mix-in specifying that a functor always returns a
+ /// particular type.
+ template <class T>
+ struct ReturnFixedType {
+ /// \cond INTERNAL
+ template <class Args>
+ struct result {
+ typedef T type;
+ };
+ /// \endcond
+ };
+
+ /// A mix-in specifying that a functor is an unary functor
+ /// whose return type is determined by the given binary
+ /// type function with the given first argument.
+ template <template<class,class> class ResultT, class ValT>
+ struct UnaryReturnBinaryTemplateBind1st {
+ /// \cond INTERNAL
+ template <class Args> struct result { typedef void type; };
+ template <class FuncT, class ArgT>
+ struct result<FuncT(ArgT)> {
+ typedef typename ResultT<ValT,ArgT>::type type;
+ };
+ /// \endcond
+ };
+
+ /// A mix-in specifying that a functor is an unary functor
+ /// whose return type is determined by the given binary
+ /// type function with the given second argument.
+ template <template<class,class> class ResultT, class ValT>
+ struct UnaryReturnBinaryTemplateBind2nd {
+ /// \cond INTERNAL
+ template <class Args> struct result { typedef void type; };
+ template <class FuncT, class ArgT>
+ struct result<FuncT(ArgT)> {
+ typedef typename ResultT<ArgT,ValT>::type type;
+ };
+ /// \endcond
+ };
+
+ template <template<class,class> class FuncT, class ValT>
+ struct BinaryBind1st {
+ template <class ArgT>
+ struct bound_type {
+ typedef typename FuncT<ValT,ArgT>::type type;
+ };
+ };
+
+
+ /// \cond INTERNAL
+
+ // ********************************************************************
+ // PixelType Arithmetic Operation Functors
+ //
+ // We could build these on top of Phoenix instead, but I think it
+ // makes sense to wait until Phoenix 2 stabilizes, or until the
+ // typeof keyword becomes standard, since the main problem these
+ // classes exist to solve is having known functor types). (I'm not
+ // actually sure that is correct, but whatever. 'Tis a problem for
+ // another day. Meanwhile, we can use these.)
+ //
+ // ********************************************************************
+
+ // Unary negation of an argument
+ class ArgNegationFunctor : public UnaryReturnSameType {
+ public:
+ template <class ArgT>
+ typename result<ArgNegationFunctor(ArgT)>::type
+ inline operator()( ArgT const& arg ) const { return -arg; }
+ };
+
+ // Binary sum of two arguments
+ class ArgArgSumFunctor : public BinaryReturnTemplateType<SumType> {
+ public:
+ template <class Arg1T, class Arg2T>
+ inline typename SumType<Arg1T,Arg2T>::type operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1+arg2; }
+ };
+
+ // Unary sum of an argument and a value
+ template <class ValT>
+ class ArgValSumFunctor : public UnaryReturnBinaryTemplateBind2nd<SumType,ValT> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValSumFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline typename SumType<ArgT,ValT>::type operator()( ArgT const& arg ) const { return arg+m_val; }
+ };
+
+ // Unary sum of a value and an argument
+ template <class ValT>
+ class ValArgSumFunctor : public UnaryReturnBinaryTemplateBind1st<SumType,ValT> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgSumFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline typename SumType<ValT,ArgT>::type operator()( ArgT const& arg ) const { return m_val+arg; }
+ };
+
+ // Binary difference of two arguments
+ struct ArgArgDifferenceFunctor : BinaryReturnTemplateType<DifferenceType> {
+ template <class Arg1T, class Arg2T>
+ inline typename DifferenceType<Arg1T,Arg2T>::type operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1-arg2; }
+ };
+
+ // Unary difference of an argument and a value
+ template <class ValT>
+ class ArgValDifferenceFunctor : public UnaryReturnBinaryTemplateBind2nd<DifferenceType,ValT> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValDifferenceFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline typename DifferenceType<ArgT,ValT>::type operator()( ArgT const& arg ) const { return arg-m_val; }
+ };
+
+ // Unary difference of a value and an argument
+ template <class ValT>
+ class ValArgDifferenceFunctor : public UnaryReturnBinaryTemplateBind1st<DifferenceType,ValT> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgDifferenceFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline typename DifferenceType<ValT,ArgT>::type operator()( ArgT const& arg ) const { return m_val-arg; }
+ };
+
+ // Binary product of two arguments
+ struct ArgArgProductFunctor : public BinaryReturnTemplateType<ProductType> {
+ template <class Arg1T, class Arg2T>
+ inline typename ProductType<Arg1T,Arg2T>::type operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1*arg2; }
+ };
+
+ // Unary product of an argument and a value
+ template <class ValT>
+ class ArgValProductFunctor : public UnaryReturnTemplateType<BinaryBind1st<ProductType,ValT>::template bound_type> {//UnaryReturnBinaryTemplateBind2nd<ProductType,ValT> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValProductFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline typename ProductType<ArgT,ValT>::type operator()( ArgT const& arg ) const { return arg*m_val; }
+ };
+
+ // Unary product of a value and an argument
+ template <class ValT>
+ class ValArgProductFunctor : public UnaryReturnBinaryTemplateBind1st<ProductType,ValT> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgProductFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline typename ProductType<ValT,ArgT>::type operator()( ArgT const& arg ) const { return m_val*arg; }
+ };
+
+ // Binary quotient of two arguments
+ struct ArgArgQuotientFunctor : BinaryReturnTemplateType<QuotientType> {
+ template <class Arg1T, class Arg2T>
+ inline typename QuotientType<Arg1T,Arg2T>::type operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1/arg2; }
+ };
+
+ // Unary quotient of an argument and a value
+ template <class ValT>
+ class ArgValQuotientFunctor : public UnaryReturnBinaryTemplateBind2nd<QuotientType,ValT> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValQuotientFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline typename QuotientType<ArgT,ValT>::type operator()( ArgT const& arg ) const { return arg/m_val; }
+ };
+
+ // Unary quotient of a value and an argument
+ template <class ValT>
+ class ValArgQuotientFunctor : public UnaryReturnBinaryTemplateBind1st<QuotientType,ValT> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgQuotientFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline typename QuotientType<ValT,ArgT>::type operator()( ArgT const& arg ) const { return m_val/arg; }
+ };
+
+ // Binary equality operator of two arguments
+ class ArgArgEqualityFunctor : ReturnFixedType<bool> {
+ public:
+ template <class Arg1T, class Arg2T>
+ inline bool operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1==arg2; }
+ };
+
+ // Unary equality operator of an argument and a value
+ template <class ValT>
+ class ArgValEqualityFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValEqualityFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return arg==m_val; }
+ };
+
+ // Unary equality operator of a value and an argument
+ template <class ValT>
+ class ValArgEqualityFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgEqualityFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return m_val==arg; }
+ };
+
+ // Binary inequality operator of two arguments
+ class ArgArgInequalityFunctor : ReturnFixedType<bool> {
+ public:
+ template <class Arg1T, class Arg2T>
+ inline bool operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1!=arg2; }
+ };
+
+ // Unary inequality operator of an argument and a value
+ template <class ValT>
+ class ArgValInequalityFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValInequalityFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return arg!=m_val; }
+ };
+
+ // Unary inequality operator of a value and an argument
+ template <class ValT>
+ class ValArgInequalityFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgInequalityFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return m_val!=arg; }
+ };
+
+ // Binary less-than operator of two arguments
+ class ArgArgLessThanFunctor : ReturnFixedType<bool> {
+ public:
+ template <class Arg1T, class Arg2T>
+ inline bool operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1<arg2; }
+ };
+
+ // Unary less-than operator of an argument and a value
+ template <class ValT>
+ class ArgValLessThanFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValLessThanFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return arg<m_val; }
+ };
+
+ // Unary less-than operator of a value and an argument
+ template <class ValT>
+ class ValArgLessThanFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgLessThanFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return m_val<arg; }
+ };
+
+ // Binary less-than-or-equal operator of two arguments
+ class ArgArgLessThanOrEqualFunctor : ReturnFixedType<bool> {
+ public:
+ template <class Arg1T, class Arg2T>
+ inline bool operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1<=arg2; }
+ };
+
+ // Unary less-than-or-equal operator of an argument and a value
+ template <class ValT>
+ class ArgValLessThanOrEqualFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValLessThanOrEqualFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return arg<=m_val; }
+ };
+
+ // Unary less-than-or-equal operator of a value and an argument
+ template <class ValT>
+ class ValArgLessThanOrEqualFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgLessThanOrEqualFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return m_val<=arg; }
+ };
+
+ // Binary greater-than operator of two arguments
+ class ArgArgGreaterThanFunctor : ReturnFixedType<bool> {
+ public:
+ template <class Arg1T, class Arg2T>
+ inline bool operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1>arg2; }
+ };
+
+ // Unary greater-than operator of an argument and a value
+ template <class ValT>
+ class ArgValGreaterThanFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValGreaterThanFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return arg>m_val; }
+ };
+
+ // Unary greater-than operator of a value and an argument
+ template <class ValT>
+ class ValArgGreaterThanFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgGreaterThanFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return m_val>arg; }
+ };
+
+ // Binary greater-than-or-equal operator of two arguments
+ class ArgArgGreaterThanOrEqualFunctor : ReturnFixedType<bool> {
+ public:
+ template <class Arg1T, class Arg2T>
+ inline bool operator()( Arg1T const& arg1, Arg2T const& arg2 ) const { return arg1>=arg2; }
+ };
+
+ // Unary greater-than-or-equal operator of an argument and a value
+ template <class ValT>
+ class ArgValGreaterThanOrEqualFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ArgValGreaterThanOrEqualFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return arg>=m_val; }
+ };
+
+ // Unary greater-than-or-equal operator of a value and an argument
+ template <class ValT>
+ class ValArgGreaterThanOrEqualFunctor : ReturnFixedType<bool> {
+ private:
+ const ValT m_val;
+ public:
+ ValArgGreaterThanOrEqualFunctor( ValT const& val ) : m_val(val) {}
+
+ template <class ArgT>
+ inline bool operator()( ArgT const& arg ) const { return m_val>=arg; }
+ };
+
+ /// \endcond INTERNAL
+
+} // namespace vw
+
+#endif // __VW_CORE_FUNCTORS_H__
View
114 src/vw/Core/FundamentalTypes.h
@@ -0,0 +1,114 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file FundamentalTypes.h
+///
+/// Types and traits for fundamental floating point and integral types.
+///
+#ifndef __VW_CORE_FUNDAMENTAL_TYPES_H__
+#define __VW_CORE_FUNDAMENTAL_TYPES_H__
+
+#include <complex>
+#include <boost/cstdint.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/mpl/not.hpp>
+
+namespace vw {
+
+ /// Basic signed integer types
+ typedef boost::int8_t int8;
+ typedef boost::int16_t int16;
+ typedef boost::int32_t int32;
+ typedef boost::int64_t int64;
+
+ /// Basic unsigned integer types
+ typedef boost::uint8_t uint8;
+ typedef boost::uint16_t uint16;
+ typedef boost::uint32_t uint32;
+ typedef boost::uint64_t uint64;
+
+ /// Basic floating-point types
+ typedef float float32;
+ typedef double float64;
+
+ /// Given a type, these traits classes identify whether or not the
+ /// type is a scalar (in the mathematical sense of the word.) This
+ /// includes the built-in arithmetic types as well as complex
+ /// numbers.
+ template <class T> struct IsScalar : public boost::is_arithmetic<T> {};
+ template <class T> struct IsScalar<std::complex<T> > : public boost::true_type {};
+ template <class T> struct IsScalar<const T> : public IsScalar<T> {};
+
+
+ /// Given a type, these traits classes help to determine a suitable
+ /// working type for accumulation operations or other intermediate
+ /// results that require computational headroom.
+ template <class T> struct AccumulatorType {};
+ template <> struct AccumulatorType<bool> { typedef int type; };
+ template <> struct AccumulatorType<vw::uint8> { typedef vw::uint32 type; };
+ template <> struct AccumulatorType<vw::int8> { typedef vw::int32 type; };
+ template <> struct AccumulatorType<vw::uint16> { typedef vw::uint32 type; };
+ template <> struct AccumulatorType<vw::int16> { typedef vw::int32 type; };
+ template <> struct AccumulatorType<vw::uint32> { typedef vw::uint64 type; };
+ template <> struct AccumulatorType<vw::int32> { typedef vw::int64 type; };
+ template <> struct AccumulatorType<vw::uint64> { typedef vw::uint64 type; };
+ template <> struct AccumulatorType<vw::int64> { typedef vw::int64 type; };
+ template <> struct AccumulatorType<vw::float32> { typedef vw::float64 type; };
+ template <> struct AccumulatorType<vw::float64> { typedef vw::float64 type; };
+ template <class T> struct AccumulatorType<std::complex<T> > {
+ typedef std::complex<typename AccumulatorType<T>::type> type;
+ };
+
+ /// This type computation class template computes a complex type
+ /// with the same storage type as the argument. (This is the
+ /// identity operation for complex types.)
+ template <class T> struct MakeComplex { typedef std::complex<T> type; };
+ template <class T> struct MakeComplex<std::complex<T> > { typedef std::complex<T> type; };
+
+ /// This type computation class template computes the real type
+ /// with the same storage type as the (possibly complex) argument.
+ /// (This is the identity operation for non-complex types.)
+ template <class T> struct MakeReal { typedef T type; };
+ template <class T> struct MakeReal<std::complex<T> > { typedef T type; };
+
+ /// This function is used to work around the fact that sending
+ /// a character type, the usual container for an 8-bit numeric
+ /// type, to a C++ output stream results in the character being
+ /// printed rather than the corresponding number.
+ template <class T> inline T _numeric( T v ) { return v; }
+ inline unsigned _numeric( uint8 v ) { return v; }
+ inline int _numeric( int8 v ) { return v; }
+
+ /// This traits class determines whether a dereferenceable or
+ /// indexable type, such as an iterator or image view, returns
+ /// elements whose address can be taken. For example, a
+ /// MemoryStridingPixelIterator is referenceable whereas a
+ /// ProceduralPixelIterator is not: the latter's pixel values are
+ /// determined on the fly via function evaluation and do not reside
+ /// anywhere in memory. This trait evaluates to false by default,
+ /// which is always safe, but certain algorithms can make
+ /// optimizations when it is true.
+ template <class T>
+ struct IsReferenceable : public boost::false_type {};
+
+} // namespace vw
+
+#endif // __VW_CORE_FUNDAMENTAL_TYPES_H__
View
42 src/vw/Core/Makefile.am
@@ -0,0 +1,42 @@
+# __BEGIN_LICENSE__
+#
+# Copyright (C) 2006 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration
+# (NASA). All Rights Reserved.
+#
+# This software is distributed under the NASA Open Source Agreement
+# (NOSA), version 1.3. The NOSA has been approved by the Open Source
+# Initiative. See the file COPYING at the top of the distribution
+# directory tree for the complete NOSA document.
+#
+# THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+# KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+# LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+# SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+# A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+# THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+# DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+#
+# __END_LICENSE__
+
+########################################################################
+# sources
+########################################################################
+
+if MAKE_MODULE_VW
+
+include_HEADERS = Exception.h FundamentalTypes.h TypeDeduction.h \
+ Functors.h CompoundTypes.h
+
+endif
+
+########################################################################
+# general
+########################################################################
+
+includedir = $(prefix)/include/vw/Core
+
+AM_CPPFLAGS = @MODULE_VW_CPPFLAGS@
+AM_LDFLAGS = @MODULE_VW_LDFLAGS@
+
+include $(top_srcdir)/config/rules.mak
View
346 src/vw/Core/TypeDeduction.h
@@ -0,0 +1,346 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file TypeDeduction.h
+///
+/// Defines standard type deduction behavior.
+///
+/// Known issues:
+///
+/// The default type deduction behavior for compound types does not
+/// use operation-specific specializations for the channel types.
+/// Thus, for instance, SumType<A<B>,A<C>> by default reduces to
+/// A<PromoteType<B,C>> rather than A<SumType<B,C>>. This does not
+/// currently impact any supported channel types.
+///
+#ifndef __VW_CORE_TYPE_DEDUCTION_H__
+#define __VW_CORE_TYPE_DEDUCTION_H__
+
+#include <boost/type_traits.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/not.hpp>
+
+#include <vw/Core/FundamentalTypes.h>
+#include <vw/Core/CompoundTypes.h>
+
+namespace vw {
+
+ /// \cond INTERNAL
+
+ // ********************************************************************
+ // Operator Return Type Deduction Routines
+ //
+ // The following type-deduction metaprograms can be used to deduce the
+ // return types of various operations on compound types. This exists
+ // and must be maintained until either C++ officially adopts the typeof
+ // keyword (and compilers actually support it) or the BOOST folks get
+ // their act together and agree on a single unified framework for this
+ // sort of thing. (In the latter case some code still needs to stay,
+ // but it should get reworked to fit within said framework.)
+ //
+ // At the moment nothing fancy is supported. For instance, compound
+ // type sums are only supported when the two arguments have the same
+ // type. However, everything is in place to make it easy to extend
+ // should the need arise.
+ // ********************************************************************
+
+ // Okay, I'll be the first to admit that this is a really brain-dead
+ // way to do this. Nevertheless, it works and will give us a standard
+ // against which to compare better methods later.
+#define __VW_STANDARD_ARITHMETIC_CONVERSIONS(Helper) \
+ /* Combinations that return long double */ \
+ template<> struct Helper<long double,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,double> { typedef long double type; }; \
+ template<> struct Helper<double,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,float> { typedef long double type; }; \
+ template<> struct Helper<float,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,unsigned long> { typedef long double type; }; \
+ template<> struct Helper<unsigned long,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,signed long> { typedef long double type; }; \
+ template<> struct Helper<signed long,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,unsigned int> { typedef long double type; }; \
+ template<> struct Helper<unsigned int,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,signed int> { typedef long double type; }; \
+ template<> struct Helper<signed int,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,unsigned short> { typedef long double type; }; \
+ template<> struct Helper<unsigned short,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,signed short> { typedef long double type; }; \
+ template<> struct Helper<signed short,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,unsigned char> { typedef long double type; }; \
+ template<> struct Helper<unsigned char,long double> { typedef long double type; }; \
+ template<> struct Helper<long double,signed char> { typedef long double type; }; \
+ template<> struct Helper<signed char,long double> { typedef long double type; }; \
+ /* Combinations that return double */ \
+ template<> struct Helper<double,double> { typedef double type; }; \
+ template<> struct Helper<double,float> { typedef double type; }; \
+ template<> struct Helper<float,double> { typedef double type; }; \
+ template<> struct Helper<double,unsigned long> { typedef double type; }; \
+ template<> struct Helper<unsigned long,double> { typedef double type; }; \
+ template<> struct Helper<double,signed long> { typedef double type; }; \
+ template<> struct Helper<signed long,double> { typedef double type; }; \
+ template<> struct Helper<double,unsigned int> { typedef double type; }; \
+ template<> struct Helper<unsigned int,double> { typedef double type; }; \
+ template<> struct Helper<double,signed int> { typedef double type; }; \
+ template<> struct Helper<signed int,double> { typedef double type; }; \
+ template<> struct Helper<double,unsigned short> { typedef double type; }; \
+ template<> struct Helper<unsigned short,double> { typedef double type; }; \
+ template<> struct Helper<double,signed short> { typedef double type; }; \
+ template<> struct Helper<signed short,double> { typedef double type; }; \
+ template<> struct Helper<double,unsigned char> { typedef double type; }; \
+ template<> struct Helper<unsigned char,double> { typedef double type; }; \
+ template<> struct Helper<double,signed char> { typedef double type; }; \
+ template<> struct Helper<signed char,double> { typedef double type; }; \
+ /* Combinations that return float */ \
+ template<> struct Helper<float,float> { typedef float type; }; \
+ template<> struct Helper<unsigned long,float> { typedef float type; }; \
+ template<> struct Helper<float,signed long> { typedef float type; }; \
+ template<> struct Helper<signed long,float> { typedef float type; }; \
+ template<> struct Helper<float,unsigned int> { typedef float type; }; \
+ template<> struct Helper<unsigned int,float> { typedef float type; }; \
+ template<> struct Helper<float,signed int> { typedef float type; }; \
+ template<> struct Helper<signed int,float> { typedef float type; }; \
+ template<> struct Helper<float,unsigned short> { typedef float type; }; \
+ template<> struct Helper<unsigned short,float> { typedef float type; }; \
+ template<> struct Helper<float,signed short> { typedef float type; }; \
+ template<> struct Helper<signed short,float> { typedef float type; }; \
+ template<> struct Helper<float,unsigned char> { typedef float type; }; \
+ template<> struct Helper<unsigned char,float> { typedef float type; }; \
+ template<> struct Helper<float,signed char> { typedef float type; }; \
+ template<> struct Helper<signed char,float> { typedef float type; }; \
+ /* Combinations that return unsigned long */ \
+ template<> struct Helper<unsigned long,unsigned long> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned long,signed long> { typedef unsigned long type; }; \
+ template<> struct Helper<signed long,unsigned long> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned long,unsigned int> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned int,unsigned long> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned long,signed int> { typedef unsigned long type; }; \
+ template<> struct Helper<signed int,unsigned long> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned long,unsigned short> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned short,unsigned long> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned long,signed short> { typedef unsigned long type; }; \
+ template<> struct Helper<signed short,unsigned long> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned long,unsigned char> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned char,unsigned long> { typedef unsigned long type; }; \
+ template<> struct Helper<unsigned long,signed char> { typedef unsigned long type; }; \
+ template<> struct Helper<signed char,unsigned long> { typedef unsigned long type; }; \
+ /* Combinations that return signed long */ \
+ template<> struct Helper<signed long,signed long> { typedef signed long type; }; \
+ template<> struct Helper<signed long,unsigned int> { typedef signed long type; }; \
+ template<> struct Helper<unsigned int,signed long> { typedef signed long type; }; \
+ template<> struct Helper<signed long,signed int> { typedef signed long type; }; \
+ template<> struct Helper<signed int,signed long> { typedef signed long type; }; \
+ template<> struct Helper<signed long,unsigned short> { typedef signed long type; }; \
+ template<> struct Helper<unsigned short,signed long> { typedef signed long type; }; \
+ template<> struct Helper<signed long,signed short> { typedef signed long type; }; \
+ template<> struct Helper<signed short,signed long> { typedef signed long type; }; \
+ template<> struct Helper<signed long,unsigned char> { typedef signed long type; }; \
+ template<> struct Helper<unsigned char,signed long> { typedef signed long type; }; \
+ template<> struct Helper<signed long,signed char> { typedef signed long type; }; \
+ template<> struct Helper<signed char,signed long> { typedef signed long type; }; \
+ /* Combinations that return unsigned int */ \
+ template<> struct Helper<unsigned int,unsigned int> { typedef unsigned int type; }; \
+ template<> struct Helper<unsigned int,signed int> { typedef unsigned int type; }; \
+ template<> struct Helper<signed int,unsigned int> { typedef unsigned int type; }; \
+ template<> struct Helper<unsigned int,unsigned short> { typedef unsigned int type; }; \
+ template<> struct Helper<unsigned short,unsigned int> { typedef unsigned int type; }; \
+ template<> struct Helper<unsigned int,signed short> { typedef unsigned int type; }; \
+ template<> struct Helper<signed short,unsigned int> { typedef unsigned int type; }; \
+ template<> struct Helper<unsigned int,unsigned char> { typedef unsigned int type; }; \
+ template<> struct Helper<unsigned char,unsigned int> { typedef unsigned int type; }; \
+ template<> struct Helper<unsigned int,signed char> { typedef unsigned int type; }; \
+ template<> struct Helper<signed char,unsigned int> { typedef unsigned int type; }; \
+ /* Combinations that return signed int */ \
+ template<> struct Helper<signed int,signed int> { typedef signed int type; }; \
+ template<> struct Helper<signed int,unsigned short> { typedef signed int type; }; \
+ template<> struct Helper<unsigned short,signed int> { typedef signed int type; }; \
+ template<> struct Helper<signed int,signed short> { typedef signed int type; }; \
+ template<> struct Helper<signed short,signed int> { typedef signed int type; }; \
+ template<> struct Helper<signed int,unsigned char> { typedef signed int type; }; \
+ template<> struct Helper<unsigned char,signed int> { typedef signed int type; }; \
+ template<> struct Helper<signed int,signed char> { typedef signed int type; }; \
+ template<> struct Helper<signed char,signed int> { typedef signed int type; }; \
+ /* Combinations that return unsigned short */ \
+ template<> struct Helper<unsigned short,unsigned short> { typedef unsigned short type; }; \
+ template<> struct Helper<unsigned short,signed short> { typedef unsigned short type; }; \
+ template<> struct Helper<signed short,unsigned short> { typedef unsigned short type; }; \
+ template<> struct Helper<unsigned short,unsigned char> { typedef unsigned short type; }; \
+ template<> struct Helper<unsigned char,unsigned short> { typedef unsigned short type; }; \
+ template<> struct Helper<unsigned short,signed char> { typedef unsigned short type; }; \
+ template<> struct Helper<signed char,unsigned short> { typedef unsigned short type; }; \
+ /* Combinations that return signed short */ \
+ template<> struct Helper<signed short,signed short> { typedef signed short type; }; \
+ template<> struct Helper<signed short,unsigned char> { typedef signed short type; }; \
+ template<> struct Helper<unsigned char,signed short> { typedef signed short type; }; \
+ template<> struct Helper<signed short,signed char> { typedef signed short type; }; \
+ template<> struct Helper<signed char,signed short> { typedef signed short type; }; \
+ /* Combinations that return unsigned char */ \
+ template<> struct Helper<unsigned char,unsigned char> { typedef unsigned char type; }; \
+ template<> struct Helper<unsigned char,signed char> { typedef unsigned char type; }; \
+ template<> struct Helper<signed char,unsigned char> { typedef unsigned char type; }; \
+ /* Combinations that return signed char */ \
+ template<> struct Helper<signed char,signed char> { typedef signed char type; }; \
+ /* Combinations with a user type return that type */ \
+ template<class T> struct Helper<long double,T> { typedef T type; }; \
+ template<class T> struct Helper<T,long double> { typedef T type; }; \
+ template<class T> struct Helper<double,T> { typedef T type; }; \
+ template<class T> struct Helper<T,double> { typedef T type; }; \
+ template<class T> struct Helper<float,T> { typedef T type; }; \
+ template<class T> struct Helper<T,float> { typedef T type; }; \
+ template<class T> struct Helper<unsigned long,T> { typedef T type; }; \
+ template<class T> struct Helper<T,unsigned long> { typedef T type; }; \
+ template<class T> struct Helper<signed long,T> { typedef T type; }; \
+ template<class T> struct Helper<T,signed long> { typedef T type; }; \
+ template<class T> struct Helper<unsigned int,T> { typedef T type; }; \
+ template<class T> struct Helper<T,unsigned int> { typedef T type; }; \
+ template<class T> struct Helper<signed int,T> { typedef T type; }; \
+ template<class T> struct Helper<T,signed int> { typedef T type; }; \
+ template<class T> struct Helper<unsigned short,T> { typedef T type; }; \
+ template<class T> struct Helper<T,unsigned short> { typedef T type; }; \
+ template<class T> struct Helper<signed short,T> { typedef T type; }; \
+ template<class T> struct Helper<T,signed short> { typedef T type; }; \
+ template<class T> struct Helper<unsigned char,T> { typedef T type; }; \
+ template<class T> struct Helper<T,unsigned char> { typedef T type; }; \
+ template<class T> struct Helper<signed char,T> { typedef T type; }; \
+ template<class T> struct Helper<T,signed char> { typedef T type; };
+
+ template <class T>
+ struct TypeDeductionError;
+
+ template <class Arg1T, class Arg2T>
+ struct TypeDeductionHelper {
+ typedef TypeDeductionError<TypeDeductionHelper> type;
+ };
+
+ template <class ArgT>
+ struct TypeDeductionHelper<ArgT, ArgT> {
+ typedef ArgT type;
+ };
+
+ __VW_STANDARD_ARITHMETIC_CONVERSIONS(TypeDeductionHelper)
+
+
+ // ********************************************************************
+ // Now we set up the default promotion behavior for general types.
+ // This includes promotions of compound types (e.g. pixel types)
+ // when used in operations with fundamental types. Thus for example
+ // multiplying PixelRGB<int> by float should return PixelRGB<float>.
+ // We address this by recursing on the template parameter. Users
+ // can explicitly specialize PromoteTypeSpecialization<> to support
+ // custom behaviors when both arguments are custom types.
+ // ********************************************************************
+
+ // First we forward-declare the specialization class.
+ template <class Arg1T, class Arg2T> class PromoteTypeSpecialization;
+
+ // This helper class forwards the default case to TypeDeductionHelper.
+ template <class Arg1T, class Arg2T, bool Arg1IsCompound, bool Arg2IsCompound>
+ struct PromoteTypeSpecializationHelper : public TypeDeductionHelper<Arg1T,Arg2T> {};
+
+ // Recursive behavior when Arg1T is a compound type.
+ template <class Arg1T, class Arg2T>
+ struct PromoteTypeSpecializationHelper<Arg1T,Arg2T,true,false> {
+ typedef typename CompoundChannelCast<Arg1T,typename PromoteTypeSpecialization<typename CompoundChannelType<Arg1T>::type, Arg2T>::type>::type type;
+ };
+
+ // Recursive behavior when Arg2T is a compound type.
+ template <class Arg1T, class Arg2T>
+ struct PromoteTypeSpecializationHelper<Arg1T,Arg2T,false,true> {
+ typedef typename CompoundChannelCast<Arg2T,typename PromoteTypeSpecialization<Arg1T, typename CompoundChannelType<Arg2T>::type>::type>::type type;
+ };
+
+ // Recursive behavior when both Arg1T and Arg2T are compound types.
+ template <class Arg1T, class Arg2T>
+ class PromoteTypeSpecializationHelper<Arg1T,Arg2T,true,true> {
+ typedef typename boost::is_same<Arg1T,typename CompoundChannelCast<Arg2T,typename CompoundChannelType<Arg1T>::type>::type>::type if_same_type;
+ typedef typename CompoundChannelCast<Arg1T,typename PromoteTypeSpecialization<typename CompoundChannelType<Arg1T>::type,typename CompoundChannelType<Arg2T>::type>::type>::type is_same_type;
+ typedef typename TypeDeductionHelper<Arg1T,Arg2T>::type not_same_type;
+ public:
+ typedef typename boost::mpl::if_<if_same_type,is_same_type,not_same_type>::type type;
+ };
+
+ // Dispatch to the appropriate helper based on which if any
+ // argument is a compound type.
+ template <class Arg1T, class Arg2T>
+ class PromoteTypeSpecialization
+ : public PromoteTypeSpecializationHelper<Arg1T, Arg2T, IsCompound<Arg1T>::value, IsCompound<Arg2T>::value>
+ {};
+
+
+ // ********************************************************************
+ // Finally, we provide forwarding classes for the different operations
+ // that the user can specifically specialize in special cases if
+ // needed. The classes the user *uses*, such as SumType, simply
+ // strip off any CV-qualification and forward to the appropriate
+ // specialization type. If the user needs to override the type
+ // deduction behavior, they should generally do so by overriding one
+ // of the ...Specialization classes, so that they don't have to worry
+ // about CV-qualification themselves.
+ // ********************************************************************
+
+ template <class Arg1T, class Arg2T>
+ struct SumTypeSpecialization : public PromoteTypeSpecialization<Arg1T,Arg2T> {};
+
+ template <class Arg1T, class Arg2T>
+ struct DifferenceTypeSpecialization : public PromoteTypeSpecialization<Arg1T,Arg2T> {};
+
+ template <class Arg1T, class Arg2T>
+ struct ProductTypeSpecialization : public PromoteTypeSpecialization<Arg1T,Arg2T> {};
+
+ template <class Arg1T, class Arg2T>
+ struct QuotientTypeSpecialization : public PromoteTypeSpecialization<Arg1T,Arg2T> {};
+
+
+ template <class Arg1T, class Arg2T>
+ struct PromoteType {
+ typedef typename PromoteTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
+ typename boost::remove_cv<Arg2T>::type>::type type;
+ };
+
+ template <class Arg1T, class Arg2T>
+ struct SumType {
+ typedef typename SumTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
+ typename boost::remove_cv<Arg2T>::type>::type type;
+ };
+
+ template <class Arg1T, class Arg2T>
+ struct DifferenceType {
+ typedef typename DifferenceTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
+ typename boost::remove_cv<Arg2T>::type>::type type;
+ };
+
+ template <class Arg1T, class Arg2T>
+ struct ProductType {
+ typedef typename ProductTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
+ typename boost::remove_cv<Arg2T>::type>::type type;
+ };
+
+ template <class Arg1T, class Arg2T>
+ struct QuotientType {
+ typedef typename QuotientTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
+ typename boost::remove_cv<Arg2T>::type>::type type;
+ };
+
+ /// \endcond
+
+} // namespace vw
+
+#endif // __VW_TYPE_DEDUCTION_H__
View
39 src/vw/Doxygen.h
@@ -0,0 +1,39 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+// THIS HEADER FILE EXISTS FOR DOXYGEN ONLY! IT DOES NOT GET
+// INSTALLED ALONG WITH THE PACKAGE! DO NOT PUT ANYTHING
+// HERE THAT SERVES ANY PURPOSE OTHER THAN HELPING OUT DOXYGEN!
+
+/**
+\mainpage Vision Workbench Core Module
+
+\section Introduction
+
+This is the automatically-generated reference documentation for the
+core module of the Vision Workbench, a C++ image processing library.
+
+If in doubt, start with \ref vw::ImageView.
+
+*/
+
+/// This is the core Vision Workbench namespace.
+namespace vw {}
View
29 src/vw/FileIO.h
@@ -0,0 +1,29 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file FileIO.h
+///
+/// A convenience header that includes the header files in vw/FileIO.
+///
+#ifndef __VW_FILEIO_H__
+#define __VW_FILEIO_H__
+
+#endif // __VW_FILEIO_H__
View
41 src/vw/FileIO/Makefile.am
@@ -0,0 +1,41 @@
+# __BEGIN_LICENSE__
+#
+# Copyright (C) 2006 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration
+# (NASA). All Rights Reserved.
+#
+# This software is distributed under the NASA Open Source Agreement
+# (NOSA), version 1.3. The NOSA has been approved by the Open Source
+# Initiative. See the file COPYING at the top of the distribution
+# directory tree for the complete NOSA document.
+#
+# THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+# KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+# LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+# SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+# A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+# THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+# DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+#
+# __END_LICENSE__
+
+########################################################################
+# sources
+########################################################################
+
+if MAKE_MODULE_VW
+
+#include_HEADERS =
+
+endif
+
+########################################################################
+# general
+########################################################################
+
+includedir = $(prefix)/include/vw/FileIO
+
+AM_CPPFLAGS = @MODULE_VW_CPPFLAGS@
+AM_LDFLAGS = @MODULE_VW_LDFLAGS@
+
+include $(top_srcdir)/config/rules.mak
View
37 src/vw/Image.h
@@ -0,0 +1,37 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file Image.h
+///
+/// A convenience header that includes the header files in vw/Image.
+///
+#ifndef __VW__IMAGE_H__
+#define __VW__IMAGE_H__
+
+#include <vw/Image/PixelIterator.h>
+#include <vw/Image/ImageViewBase.h>
+#include <vw/Image/PixelAccessors.h>
+#include <vw/Image/ImageView.h>
+#include <vw/Image/ImageViewRef.h>
+#include <vw/Image/PixelTypeInfo.h>
+#include <vw/Image/PixelTypes.h>
+
+#endif // __VW__IMAGE_H__
View
247 src/vw/Image/ImageView.h
@@ -0,0 +1,247 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file ImageView.h
+///
+/// Defines the core in-memory image view type.
+
+#ifndef __VW_IMAGE__IMAGE_VIEW_H__
+#define __VW_IMAGE__IMAGE_VIEW_H__
+
+#include <vw/config.h>
+
+#include <string.h> // For memset()
+
+#include <boost/smart_ptr.hpp>
+#include <boost/type_traits.hpp>
+
+#include <vw/Core/Exception.h>
+
+#include <vw/Image/ImageViewBase.h>
+#include <vw/Image/PixelAccessors.h>
+
+// support for conversion to and from vil_image_view
+#ifdef VW_HAVE_PKG_VXL
+#include <vil/vil_image_view.txx>
+#include <vil/vil_copy.h>
+#endif
+
+namespace vw {
+
+ /// The standard image container for in-memory image data.
+ ///
+ /// This class represents an image stored in memory or, more
+ /// precisely, a view onto such an image. That is, the ImageView
+ /// object itself does not contain the image data itself but rather
+ /// a pointer to it. More than one ImageView object can point to
+ /// the same data, and they can even choose to interpret that data
+ /// differently. In particular, copying an ImageView object is a
+ /// shallow, lightweight operation. The underlying image data is
+ /// reference counted, so the user does not usually need to be
+ /// concerned with memory allocation and deallocation.
+ ///
+ /// A more complete name for this class might be something like
+ /// MemoryImageView, or StandardImageView, but it is so ubiquitous
+ /// that we decided to keep the name short.
+ ///
+ template <class PixelT>
+ class ImageView : public ImageViewBase<ImageView<PixelT> >
+ {
+ boost::shared_array<PixelT> m_data;
+ unsigned m_cols, m_rows, m_planes;
+ PixelT *m_origin;
+ ptrdiff_t m_cstride, m_rstride, m_pstride;
+ public:
+
+ /// The pixel type of the image.
+ typedef PixelT pixel_type;
+
+ /// The data type of the image, considered as a container.
+ typedef PixelT value_type;
+
+ /// The image's %pixel_accessor type.
+ typedef MemoryStridingPixelAccessor<PixelT> pixel_accessor;
+
+ /// Constructs an empty image with zero size.
+ ImageView() : m_cols(0), m_rows(0), m_planes(0), m_origin(0), m_cstride(0), m_rstride(0), m_pstride(0) {
+ }
+
+ /// Copy-constructs a view pointing to the same data as the given ImageView.
+ ImageView( ImageView const& other ) : m_data(other.m_data), m_cols(other.m_cols), m_rows(other.m_rows), m_planes(other.m_planes),
+ m_origin(other.m_origin), m_cstride(other.m_cstride), m_rstride(other.m_rstride), m_pstride(other.m_pstride) {}
+
+ /// Resets to an empty image with zero size.
+ void reset() {
+ m_data.reset();
+ m_cols = m_rows = m_planes = 0;
+ m_origin = 0;
+ m_cstride = m_rstride = m_pstride = 0;
+ }
+
+ /// Constructs an empty image with the given dimensions.
+ ImageView( unsigned cols, unsigned rows, unsigned planes=1 ) : m_cols(0), m_rows(0), m_planes(0), m_origin(0), m_cstride(0), m_rstride(0), m_pstride(0) {
+ set_size( cols, rows, planes );
+ }
+
+ /// Constructs an image view and rasterizes the given view into it.
+ template <class ViewT>
+ ImageView( ViewT const& view ) : m_cols(0), m_rows(0), m_planes(0), m_origin(0), m_cstride(0), m_rstride(0), m_pstride(0) {
+ set_size( view.cols(), view.rows(), view.planes() );
+ view.rasterize( *this );
+ }
+
+ /// Rasterizes the given view into the image, adjusting the size if needed.
+ template <class SrcT>
+ ImageView& operator=( ImageViewBase<SrcT> const& view ) {
+ set_size( view.impl().cols(), view.impl().rows(), view.impl().planes() );
+ view.impl().rasterize( *this );
+ return *this;
+ }
+
+ /// Rasterizes the given view into the image.
+ template <class SrcT>
+ ImageView const& operator=( ImageViewBase<SrcT> const& view ) const {
+ view.impl().rasterize( *this );
+ return *this;
+ }
+
+ value_type *data() {
+ return &(operator()(0,0));
+ }
+
+ const value_type *data() const {
+ return &(operator()(0,0));
+ }
+
+ /// Returns the number of columns in the image.
+ inline unsigned cols() const { return m_cols; }
+
+ /// Returns the number of rows in the image.
+ inline unsigned rows() const { return m_rows; }
+
+ /// Returns the number of planes in the image.
+ inline unsigned planes() const { return m_planes; }
+
+ /// Returns a pixel_accessor pointing to the top-left corner of the first plane.
+ inline pixel_accessor origin() const {
+ return pixel_accessor( m_origin, m_cstride, m_rstride, m_pstride );
+ }
+
+ /// Returns the pixel at the given position in the first plane.
+ inline pixel_type& operator()( int col, int row ) const {
+ return *(m_origin + col*m_cstride + row*m_rstride);
+ }
+
+ /// Returns the pixel at the given position in the given plane.
+ inline pixel_type& operator()( int col, int row, int plane ) const {
+ return *(m_origin + col*m_cstride + row*m_rstride + plane*m_pstride);
+ }
+
+ /// Adjusts the size of the image to match the dimensions of another image.
+ template <class ImageT>
+ void set_size( ImageViewBase<ImageT> &img ) {
+ this->set_size(img.impl().cols(), img.impl().rows(), img.impl().planes());
+ }
+
+ /// Adjusts the size of the image, allocating a new buffer if the size has changed.
+ void set_size( unsigned cols, unsigned rows, unsigned planes = 1 ) {
+ if( cols==m_cols && rows==m_rows && planes==m_planes ) return;
+
+ unsigned size = cols*rows*planes;
+ if( size==0 ) {
+ m_data.reset();
+ }
+ else {
+ boost::shared_array<PixelT> data( new PixelT[size] );
+ m_data = data;
+ }
+
+ m_cols = cols;
+ m_rows = rows;
+ m_planes = planes;
+ m_origin = m_data.get();
+ m_cstride = 1;
+ m_rstride = cols;
+ m_pstride = rows*cols;
+
+ // Fundamental types might not be initialized. Really this is
+ // true of all POD types, but there's no good way to detect
+ // those. We can only hope that the user will never use a
+ // custom POD pixel type.
+ //
+ // Note that this is a copy of the fill algorithm that resides
+ // in ImageAlgorithms.h, however including ImageAlgorithms.h
+ // directly causes an include file cycle.
+ if( boost::is_fundamental<pixel_type>::value ) {
+ memset( m_data.get(), 0, m_rows*m_cols*m_planes*sizeof(PixelT) );
+ }
+ }
+
+#ifdef VW_HAVE_PKG_VXL
+ /// Constructs an image from the given VIL image.
+ ImageView( vil_image_view<typename CompoundChannelType<PixelT>::type> const& src ) :
+ m_cols(0), m_rows(0), m_planes(0), m_origin(0), m_cstride(0), m_rstride(0), m_pstride(0) {
+ operator=( src );
+ }
+
+ /// Copies the given VIL image into this image.
+ ImageView& operator=( vil_image_view<typename CompoundChannelType<PixelT>::type> const& src ) {
+ unsigned channels = CompoundNumChannels<PixelT>::value;
+ if( channels != 1 && src.nplanes() != channels ) throw ArgumentErr() << "incompatible number of planes (need " << channels << ", got " << src.nplanes() << ")";
+ set_size( src.ni(), src.nj(), (channels==1)?(src.nplanes()):(1) );
+ vil_image_view<typename CompoundChannelType<PixelT>::type> wrapper = vil_view();
+ vil_copy_reformat( src, wrapper );
+ return *this;
+ }
+
+ /// Returns a VIL image view of this view's image data.
+ vil_image_view<typename CompoundChannelType<PixelT>::type> vil_view() const {
+ unsigned channels = CompoundNumChannels<PixelT>::value;
+ VW_ASSERT( m_planes==1 || channels== 1, ArgumentErr() <<
+ "VIL does not support having both interleaved planes (i.e channels) and non-interleaved planes" );
+ return vil_image_view<typename CompoundChannelType<PixelT>::type>( reinterpret_cast<typename CompoundChannelType<PixelT>::type*>( m_origin ),
+ m_cols, m_rows, channels*m_planes, m_cstride*channels, m_rstride*channels,
+ (channels==1)?(m_pstride):(1) );
+ }
+#endif // VW_HAVE_PKG_VXL
+
+ /// \cond INTERNAL
+ typedef ImageView prerasterize_type;
+ inline prerasterize_type prerasterize() const { return *this; }
+ template <class DestT> inline void rasterize( DestT const& dest ) const { vw::rasterize( prerasterize(), dest ); }
+ /// \endcond
+ };
+
+ // Image view traits
+ /// \cond INTERNAL
+ template <class ImageT>
+ struct IsReferenceable<ImageView<ImageT> > : public boost::true_type {};
+
+ template <class PixelT>
+ struct IsResizable<ImageView<PixelT> > : public boost::true_type {};
+
+ template <class PixelT>
+ struct IsMultiplyAccessible<ImageView<PixelT> > : public boost::true_type {};
+ /// \endcond
+
+} // namespace vw
+
+#endif /* __VW_IMAGE__IMAGE_VIEW_H__ */
View
171 src/vw/Image/ImageViewBase.h
@@ -0,0 +1,171 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file ImageViewBase.h
+///
+/// Image view base class and default rasterization code.
+///
+/// This file provides the core image view functionality. You should not
+/// need to care about this file unless you are writing your own view.
+/// First there is a templatized base class for image views, \ref vw::ImageViewBase.
+/// Then there are the default templates for several image view traits
+/// classes. Finally, there is the default rasterization function,
+/// \ref vw::rasterize, which iterates over source and destination views
+/// copying pixels from one into the other.
+///
+#ifndef __VW_IMAGE__IMAGE_VIEW_BASE_H__
+#define __VW_IMAGE__IMAGE_VIEW_BASE_H__
+
+#include <boost/type_traits.hpp>
+#include <boost/utility/enable_if.hpp>
+
+#include <vw/core/Exception.h>
+#include <vw/Core/FundamentalTypes.h>
+#include <vw/Core/CompoundTypes.h>
+
+#include <vw/Image/PixelIterator.h>
+
+namespace vw {
+
+ // *******************************************************************
+ // The core image view CRTP base class
+ // *******************************************************************
+
+ /// A CRTP image view base class.
+ // Consider a function that takes a single argument, which should be
+ // an arbitrary image view. You may not want to define it like this:
+ // template<class ImageViewT> void foo(ImageViewT& v) {...}
+ // because that will accept any type, not just an image view type.
+ // Instead, to resolve ambiguities, you can define it like this:
+ // template<class T> void foo(ImageViewBase<T>& v) {...}
+ // which affords you better compile-time type checking and greater
+ // function overload flexibility.
+ template <class ImplT>
+ struct ImageViewBase {
+
+ /// \cond INTERNAL
+ // Methods to access the derived type
+ inline ImplT& impl() { return static_cast<ImplT&>(*this); }
+ inline ImplT const& impl() const { return static_cast<ImplT const&>(*this); }
+ /// \endcond
+
+ /// An STL-compatible iterator type.
+ typedef PixelIterator<ImplT> iterator;
+
+ /// Returns an iterator pointing to the first pixel in the image.
+ iterator begin() const { return iterator(impl(),0,0,0); }
+
+ /// Returns an iterator pointing one past the last pixel in the image.
+ iterator end() const { return iterator(impl(), 0, 0, impl().planes()); }
+
+ /// Returns the number of channels in the image's pixel type.
+ inline int channels() const { return CompoundNumChannels<typename ImplT::pixel_type>::value; }
+
+ /// \cond INTERNAL
+ protected:
+ // These are defined here to prevent the user from accidentally
+ // copy constructing an ImageViewBase.
+ ImageViewBase() {}
+ ImageViewBase(ImageViewBase const&) {}
+ ImageViewBase& operator=(ImageViewBase const&) { return *this; }
+ /// \endcond
+ };
+
+
+ // *******************************************************************
+ // Default image traits templates
+ //
+ // We do not define the default IsReferenceable template here
+ // because it has already been defined in FundamentalTypes.h.
+ // *******************************************************************
+
+ /// Indicates whether a view can be resized via <B>set_size()</B>.
+ template <class ImplT>
+ struct IsResizable : public boost::false_type {};
+
+ /// Indicates whether a view type can be accessed at floating-point positions.
+ template <class ImplT>
+ struct IsFloatingPointIndexable : public boost::false_type {};
+
+ /// Indicates whether or not a type is an image view type.
+ template <class ImageT>
+ struct IsImageView : public boost::is_base_of<ImageViewBase<ImageT>,ImageT>::type {};
+
+ /// Indicates whether or not a view can be accessed multiple times
+ /// just as efficiently as a locally-cached version.
+ template <class ImplT>
+ struct IsMultiplyAccessible : public boost::false_type {};
+
+
+ // *******************************************************************
+ // The master rasterization function
+ // *******************************************************************
+
+ /// This function is called by image views that do not have special
+ /// optimized rasterization methods. The user can also call it
+ /// explicitly when pixel-by-pixel rasterization is preferred to
+ /// the default optimized rasterization behavior. This can be
+ /// useful in some cases, such as when the views are heavily
+ /// subsampled.
+ template <class SrcT, class DestT>
+ void rasterize( SrcT const& src, DestT const& dest ) {
+ typedef typename DestT::pixel_type DestPixelT;
+ typedef typename SrcT::pixel_accessor SrcAccT;
+ typedef typename DestT::pixel_accessor DestAccT;
+ unsigned cols=src.cols(), rows=src.rows(), planes=src.planes();
+ VW_ASSERT( dest.cols()==cols && dest.rows()==rows && dest.planes()==planes,
+ ArgumentErr() << "rasterize: Source and destination images must have same dimensions." );
+ SrcAccT splane = src.origin();
+ DestAccT dplane = dest.origin();
+ for( unsigned plane=planes; plane; --plane ) {
+ SrcAccT srow = splane;
+ DestAccT drow = dplane;
+ for( unsigned row=rows; row; --row ) {
+ SrcAccT scol = srow;
+ DestAccT dcol = drow;
+ for( unsigned col=cols; col; --col ) {
+ *dcol = DestPixelT(*scol);
+ scol.next_col();
+ dcol.next_col();
+ }
+ srow.next_row();
+ drow.next_row();
+ }
+ splane.next_plane();
+ dplane.next_plane();
+ }
+ }
+
+ /// A specialization for resizable destination views.
+ ///
+ /// This function resizes the destination view prior to
+ /// rasterization.
+ /// \see vw::rasterize
+ template <class SrcT, class DestT>
+ typename boost::enable_if<IsResizable<DestT>, void>::type
+ inline rasterize( SrcT const& src, DestT& dest ) {
+ dest.set_size( src.cols(), src.rows(), src.planes() );
+ rasterize( src, const_cast<DestT const&>(dest) );
+ }
+
+} // namespace vw
+
+#endif // __VW_IMAGE__IMAGE_VIEW_BASE_H__
View
215 src/vw/Image/ImageViewRef.h
@@ -0,0 +1,215 @@
+// __BEGIN_LICENSE__
+//
+// Copyright (C) 2006 United States Government as represented by the
+// Administrator of the National Aeronautics and Space Administration
+// (NASA). All Rights Reserved.
+//
+// This software is distributed under the NASA Open Source Agreement
+// (NOSA), version 1.3. The NOSA has been approved by the Open Source
+// Initiative. See the file COPYING at the top of the distribution
+// directory tree for the complete NOSA document.
+//
+// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+// __END_LICENSE__
+
+/// \file ImageViewRef.h
+///
+/// A generic image view reference class.
+///
+/// Most Vision Workbench image processing functions simply return
+/// image view objects that lazily represent the processed data.
+/// Under some circumstances it is helpful to be able to hold onto
+/// such a processed view without rasterizing it. Ordinarily this
+/// requires knowing the full type of the view. When this is not
+/// acceptable, the \ref vw::ImageViewRef class allows you to hold
+/// a virtualized reference to an arbitrary image view with a given
+/// pixel type.
+///
+#ifndef __VW_IMAGE__IMAGE_VIEW_REF_H__
+#define __VW_IMAGE__IMAGE_VIEW_REF_H__
+
+#include <boost/type_traits.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
+
+#include <vw/Image/ImageView.h>
+
+namespace vw {
+
+ /// \cond INTERNAL
+ template <class PixelT>
+ class ImageViewRefAccessorBase {
+ public:
+ virtual ~ImageViewRefAccessorBase() {}
+ virtual ImageViewRefAccessorBase* copy() const = 0;
+ virtual void next_col() = 0;
+ virtual void prev_col() = 0;
+ virtual void next_row() = 0;
+ virtual void prev_row() = 0;
+ virtual void next_plane() = 0;
+ virtual void prev_plane() = 0;
+ virtual void advance( ptrdiff_t di, ptrdiff_t dj, ptrdiff_t dp=0 ) = 0;
+ virtual typename boost::add_const<PixelT>::type operator*() const = 0;
+ };
+
+ template <class IterT>
+ class ImageViewRefAccessorImpl : public ImageViewRefAccessorBase<typename boost::add_const<typename IterT::pixel_type>::type> {
+ private:
+ IterT m_iter;
+ public:
+ typedef typename boost::add_const<typename IterT::pixel_type>::type pixel_type;
+
+ ImageViewRefAccessorImpl( IterT const& iter ) : m_iter(iter) {}
+ virtual ~ImageViewRefAccessorImpl() {}
+
+ virtual ImageViewRefAccessorBase<pixel_type>* copy() const { return new ImageViewRefAccessorImpl(m_iter); }
+
+ virtual void next_col() { m_iter.next_col(); }
+ virtual void prev_col() { m_iter.prev_col(); }
+ virtual void next_row() { m_iter.next_row(); }
+ virtual void prev_row() { m_iter.prev_row(); }
+ virtual void next_plane() { m_iter.next_plane(); }
+ virtual void prev_plane() { m_iter.prev_plane(); }
+ virtual void advance( ptrdiff_t di, ptrdiff_t dj, ptrdiff_t dp=0 ) { m_iter.advance(di,dj,dp); }
+ virtual typename boost::add_const<pixel_type>::type operator*() const { return *m_iter; }
+ };
+ /// \endcond
+
+ /// A special virtualized accessor adaptor.
+ ///
+ /// This accessor adaptor is used by the \ref vw::ImageViewRef class.
+ template <class PixelT>
+ class ImageViewRefAccessor {
+ private:
+ boost::scoped_ptr< ImageViewRefAccessorBase<PixelT> > m_iter;
+ public:
+ typedef PixelT pixel_type;
+
+ template <class IterT> ImageViewRefAccessor( IterT const& iter ) : m_iter( new ImageViewRefAccessorImpl<IterT>(iter) ) {}
+ ~ImageViewRefAccessor() {}
+
+ ImageViewRefAccessor( ImageViewRefAccessor const& other ) : m_iter( other.m_iter->copy() ) {}
+ ImageViewRefAccessor& operator=( ImageViewRefAccessor const& other ) { m_iter = other.m_iter->copy(); }
+
+ inline ImageViewRefAccessor& next_col() { m_iter->next_col(); return *this; }
+ inline ImageViewRefAccessor& prev_col() { m_iter->prev_col(); return *this; }
+ inline ImageViewRefAccessor& next_row() { m_iter->next_row(); return *this; }
+ inline ImageViewRefAccessor& prev_row() { m_iter->prev_row(); return *this; }
+ inline ImageViewRefAccessor& next_plane() { m_iter->next_plane(); return *this; }
+ inline ImageViewRefAccessor& prev_plane() { m_iter->prev_plane(); return *this; }
+ inline ImageViewRefAccessor& advance( ptrdiff_t di, ptrdiff_t dj, ptrdiff_t dp=0 ) { m_iter->advance(di,dj,dp=0); return *this; }
+ inline typename boost::add_const<pixel_type>::type operator*() const { return *(*m_iter); }
+ };
+
+
+ /// \cond INTERNAL
+ // Base class definition
+ template <class PixelT>
+ class ImageViewRefBase {
+ public:
+ typedef typename boost::add_const<PixelT>::type pixel_type;
+ typedef ImageViewRefAccessor<typename boost::add_const<PixelT>::type > pixel_accessor;
+
+ virtual ~ImageViewRefBase() {}
+
+ virtual unsigned cols() const = 0;
+ virtual unsigned rows() const = 0;
+ virtual unsigned planes() const = 0;
+ virtual pixel_type operator()( int i, int j ) const = 0;
+ virtual pixel_type operator()( int i, int j, int p ) const = 0;
+ virtual pixel_accessor origin() const = 0;
+
+ virtual void rasterize( ImageView<typename boost::remove_cv<pixel_type>::type> const& dest ) const = 0;
+ };
+
+ // ImageViewRef class implementation
+ template <class ViewT>
+ class ImageViewRefImpl : public ImageViewRefBase<typename boost::add_const<typename ViewT::pixel_type>::type> {
+ private:
+ ViewT m_view;
+ public:
+ typedef typename boost::add_const<typename ViewT::pixel_type>::type pixel_type;
+ typedef ImageViewRefAccessor<typename boost::add_const<typename ViewT::pixel_type>::type > pixel_accessor;
+
+ ImageViewRefImpl( ImageViewBase<ViewT> const& view ) : m_view(view.impl()) {}
+ virtual ~ImageViewRefImpl() {}
+
+ virtual unsigned cols() const { return m_view.cols(); }
+ virtual unsigned rows() const { return m_view.rows(); }
+ virtual unsigned planes() const { return m_view.planes(); }
+ virtual pixel_type operator()( int i, int j ) const { return m_view(i,j); }
+ virtual pixel_type operator()( int i, int j, int p ) const { return m_view(i,j,p); }
+ virtual pixel_accessor origin() const { return m_view.origin(); }
+
+ virtual void rasterize( ImageView<typename boost::remove_cv<pixel_type>::type> const& dest ) const { m_view.rasterize( dest ); }
+ };
+ /// \endcond
+
+
+ /// A virtualized image view reference object.
+ ///
+ /// This class behaves as a reference to an arbitrary image view
+ /// with the given pixel type. The purpose of this class is to
+ /// hide the full type of a view behind a veil of abstraction,
+ /// making things like run-time polymorphic behavior possible.
+ /// The inevitable cost of this flexibility is one virtual
+ /// function call per method invocation. In many cases there
+ /// are additional costs associated with not being able to
+ /// perform template-based optimizations at compile time.
+ ///
+ /// Like any C++ reference, you bind an ImageViewRef to a view
+ /// using a constructor and future operations act on the bound
+ /// object instead of the reference object itself.
+ ///
+ /// The current implementation of ImageViewRef is read-only.
+ template <class PixelT>
+ class ImageViewRef : public ImageViewBase<ImageViewRef<PixelT> > {
+ private:
+ boost::shared_ptr< ImageViewRefBase<typename boost::add_const<PixelT>::type > > m_view;
+ public:
+ typedef typename boost::add_const<PixelT>::type pixel_type;
+ typedef ImageViewRefAccessor<typename boost::add_const<PixelT>::type > pixel_accessor;
+
+ template <class ViewT> ImageViewRef( ImageViewBase<ViewT> const& view ) : m_view( new ImageViewRefImpl<ViewT>(view) ) {}
+ ~ImageViewRef() {}
+
+ inline unsigned cols() const { return m_view->cols(); }
+ inline unsigned rows() const { return m_view->rows(); }
+ inline unsigned planes() const { return m_view->planes(); }
+ inline pixel_type operator()( int i, int j ) const { return m_view->operator()(i,j); }
+ inline pixel_type operator()( int i, int j, int p ) const { return m_view->operator()(i,j,p); }
+ inline pixel_accessor origin() const { return m_view->origin(); }
+
+ /// \cond INTERNAL
+ typedef ImageView<PixelT> prerasterize_type;
+
+ inline prerasterize_type prerasterize() const {
+ ImageView<PixelT> buf( cols(), rows(), planes() );
+ m_view->rasterize( buf );
+ return buf;
+ }
+