CVR-Lib last update 20 Sep 2009

cvrMatrixProcessingInterface.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007
00003  * ITCR, Pablo Alvarado
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 /**
00042  * \file   cvrMatrixProcessingInterface.h
00043  *         Simple interface from which all functors that process a matrix<T>
00044  *         to produce another matrix can be inherited.
00045  *
00046  * \author Pablo Alvarado
00047  * \date   23.09.2007
00048  *
00049  * revisions ..: $Id: cvrMatrixProcessingInterface.h,v 1.2 2007/10/07 03:17:16 alvarado Exp $
00050  */
00051 
00052 #ifndef _CVR_MATRIX_PROCESSING_INTERFACE_H_
00053 #define _CVR_MATRIX_PROCESSING_INTERFACE_H_
00054 
00055 #include "cvrMatrix.h"
00056 #include "cvrRGBAPixel.h"
00057 
00058 namespace cvr {
00059 
00060   /**
00061    * Class matrixProcessingInterface
00062    *
00063    * Very simple interface to allow virtualization of classes that
00064    * transform a matrix into another one, like convolution, correlation,
00065    * matrixTransform, etc.
00066    *
00067    * Note that it is required that the apply methods do not alter the internal
00068    * state of the class.
00069    *
00070    * \ingroup gInterfaces
00071    */
00072   template<typename T>
00073   class matrixProcessingInterface {
00074   public:
00075 
00076     /**
00077      * Virtual destructor
00078      */
00079     virtual ~matrixProcessingInterface() {};
00080 
00081     /**
00082      * On-place processing apply.
00083      *
00084      * The inherited methods should take the \a srcdest matrix, process it in
00085      * some way, and on the same matrix leave the result.  No restrictions are
00086      * imposed on whether the memory block of the resulting matrix will be the
00087      * same that the one in the original matrix.  As a matter of fact, it
00088      * usually won't be.
00089      *
00090      * If you need to ensure the memory constancy, and assuming the resulting
00091      * matrix will always have the same size than the original one, then you
00092      * can use the following code:
00093      * \code
00094      * matrixProcessingInterfaceInheritedClass<T> theFunctor;
00095      * matrix<T> tmp;
00096      * theFunctor.apply(srcdest,tmp);
00097      * srcdest.fill(tmp)
00098      * \endcode
00099      *
00100      * which of course will be slower as it requires to copy all the data of
00101      * the result in the original matrix.
00102      *
00103      * @param srcdest matrix<T> with the source data. The result
00104      *                will be left here too.
00105      * @return true if apply successful or false otherwise.
00106      */
00107     virtual bool apply(matrix<T>& srcdest) const = 0;
00108 
00109     /**
00110      * On-copy processing apply.
00111      *
00112      * The inherited methods take the \a src matrix and process it leaving the
00113      * result in the \a dest matrix.
00114      *
00115      * @param src matrix<T> with the source data.
00116      * @param dest matrix<T> where the result will be left.
00117      * @return true if apply successful or false otherwise.
00118      */
00119     virtual bool apply(const matrix<T>& src, matrix<T>& dest) const = 0;
00120   };
00121 }
00122 
00123 #endif
00124 

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8