User Manual, Developers Guide and API Documentation

NearestNeighbour.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 
00029 #ifndef _NEARESTNEIGHBOUR_HPP
00030 #define _NEARESTNEIGHBOUR_HPP
00031 
00032 #include <cmath>
00033 #include <WNS/Interpolation.hpp>
00034 
00035 namespace wns
00036 {
00049     template<typename T,
00050          InterpolationDefs::SizeType N>
00051     class NearestNeighbour :
00052         public Interpolation<T, N>
00053     {
00057         typedef Interpolation<T, N> SuperType;
00058     public:
00062         typedef typename SuperType::SizeType SizeType;
00063 
00067         typedef typename SuperType::CoordType CoordType;
00068 
00073         typedef typename SuperType::DiscreteContainer DiscreteContainer;
00074 
00078         typedef NearestNeighbour<T, N-1> HyperplaneType;
00079 
00083         typedef const HyperplaneType& ConstReference;
00084 
00092         NearestNeighbour(const DiscreteContainer& discreteValues)
00093             : SuperType(discreteValues),
00094               hyperplanes(discreteValues.dimSize(0), HyperplaneType(discreteValues[0]))
00095         {
00096             for(SizeType i = 0; i < hyperplanes.size(); ++i) {
00097                 hyperplanes[i] = HyperplaneType(discreteValues[i]);
00098             }
00099         }
00100 
00107         virtual ConstReference operator[](const CoordType& coord) const
00108         {
00109             typedef typename DiscreteContainer::IndexType IndexType;
00110             return hyperplanes[(IndexType)std::floor(coord+0.5)];
00111         }
00112 
00113     private:
00114         typedef std::vector<HyperplaneType> HyperplaneContainer;
00115 
00116         HyperplaneContainer hyperplanes;
00117     };
00118 
00123     template<typename T>
00124     class NearestNeighbour<T, 1> :
00125         public Interpolation<T, 1>
00126     {
00127         typedef Interpolation<T, 1> SuperType;
00128     public:
00129         typedef typename SuperType::ValueType ValueType;
00130         typedef typename SuperType::CoordType CoordType;
00131         typedef typename SuperType::DiscreteContainer DiscreteContainer;
00132         typedef typename DiscreteContainer::IndexType IndexType;
00133 
00134         NearestNeighbour(const DiscreteContainer& discreteValues)
00135             : SuperType(discreteValues)
00136         {}
00137 
00138         virtual ValueType operator[](const CoordType& coord) const
00139         {
00140             return Interpolation<T,1>::discretes()[(IndexType)std::floor(coord+0.5)];
00141         }
00142 
00143     };
00144 }
00145 
00146 #endif // _NEARESTNEIGHBOUR_HPP
00147 

Generated on Fri May 25 03:31:48 2012 for openWNS by  doxygen 1.5.5