cell.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, AASS Research Center, Orebro University.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of AASS Research Center nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  */
00035 #ifndef CELL_HH
00036 #define CELL_HH
00037 
00038 #include <vector>
00039 #include <cstdio>
00040 #include <cmath>
00041 
00042 namespace lslgeneric
00043 {
00044 
00051 template<typename PointT>
00052 class Cell
00053 {
00054 
00055 protected:
00056     PointT center_;
00057     double xsize_, ysize_, zsize_;
00058 
00059 public:
00060     Cell() { }
00061     inline Cell(PointT &center, double &xsize, double &ysize, double &zsize)
00062     {
00063         center_ = center;
00064         xsize_ = xsize;
00065         ysize_ = ysize;
00066         zsize_ = zsize;
00067     }
00068     inline Cell(const Cell& other)
00069     {
00070         center_ = other.center_;
00071         xsize_ = other.xsize_;
00072         ysize_ = other.ysize_;
00073         zsize_ = other.zsize_;
00074     }
00075     virtual ~Cell() { }
00076 
00077     inline void setCenter(const PointT &cn)
00078     {
00079         center_ = cn;
00080     }
00081     inline void setDimensions(const double &xs, const double &ys, const double &zs)
00082     {
00083         xsize_ = xs;
00084         ysize_ = ys;
00085         zsize_ = zs;
00086     }
00087 
00088     inline PointT getCenter() const
00089     {
00090         return center_;
00091     }
00092     inline void getDimensions(double &xs, double &ys, double &zs) const
00093     {
00094         xs = xsize_;
00095         ys = ysize_;
00096         zs = zsize_;
00097     }
00098     inline bool isInside(const PointT pt) const
00099     {
00100         if(pt.x < center_.x-xsize_/2 || pt.x > center_.x+xsize_/2)
00101         {
00102             return false;
00103         }
00104         if(pt.y < center_.y-ysize_/2 || pt.y > center_.y+ysize_/2)
00105         {
00106             return false;
00107         }
00108         if(pt.z < center_.z-zsize_/2 || pt.z > center_.z+zsize_/2)
00109         {
00110             return false;
00111         }
00112         return true;
00113     }
00114 
00116     inline virtual Cell<PointT>* clone() const
00117     {
00118         Cell<PointT> *ret = new Cell<PointT>();
00119         return(ret);
00120     }
00122     virtual Cell<PointT>* copy() const
00123     {
00124         Cell<PointT> *ret = new Cell<PointT>();
00125         ret->setDimensions(xsize_,ysize_,zsize_);
00126         ret->setCenter(center_);
00127         return(ret);
00128     }
00129 
00130     virtual void addPoint(PointT &pt) { }
00131     virtual double getDiagonal() const
00132     {
00133         return std::sqrt(xsize_*xsize_+ysize_*ysize_+zsize_*zsize_);
00134     }
00135 };
00136 
00137 
00138 } //end namespace
00139 
00140 //#include<impl/cell.hpp>
00141 
00142 #endif


ndt_map
Author(s): Todor Stoyanov, Jari Saarinen, Henrik Andreasson
autogenerated on Mon Oct 6 2014 03:18:54