/* * PointIterator.hpp * * Created on: Jan 3, 2017 * Author: i-bird */ #ifndef OPENFPM_NUMERICS_SRC_DRAW_POINTITERATOR_HPP_ #define OPENFPM_NUMERICS_SRC_DRAW_POINTITERATOR_HPP_ /*! \brief this class draw particles on subset of grid-like position * \verbatim Point B | (0.6,0.6) + + + + + | + + + + +---------------+ + | + + + + | + + + + | | + | + + + + | + + + + | | + | + + + + | + + + + | | + | + + + + | + + + + | | + | + + + + | + + + + | | + | + + + + | + + + + | | + | + + + + | + + + + +---------------+ + + + + + ^ + + + + (-1.0,-1.0) | | (Point A) \endverbatim * * * Suppose we have a grid 9x9 from (-1.0,-1.0 to 0.6,0.6) * * Defined a Box (-0.9,-0.9 to -0.1,0.5) * * This class will return the points * * (-0.8 -0.8) * (-0.6 -0.8) * (-0.4 -0.8) * ... * (-0.1,-0.8) Point A * ... * (-0.1,0.5) Point B * */ template class PointIterator: protected grid_dist_id_iterator_dec { //! Actual point Point ap; //! sub_domain Box sub_domain; //! domain Box domain; //! Spacing T sp[dim]; static grid_key_dx getStart(size_t (& gs)[dim], const Box & dom, Box & sub_dom, T (& sp)[dim]) { for (size_t i = 0 ; i < dim ; i++) sp[i] = (dom.getHigh(i) - dom.getLow(i)) / (gs[i] -1); grid_key_dx pkey; for (size_t i = 0 ; i < dim ; i++) pkey.set_d(i,std::ceil( (sub_dom.getLow(i) - dom.getLow(i)) / sp[i])); return pkey; } static grid_key_dx getStop(size_t (& gs)[dim], const Box & dom, Box & sub_dom, T (& sp)[dim]) { for (size_t i = 0 ; i < dim ; i++) sp[i] = (dom.getHigh(i) - dom.getLow(i)) / (gs[i] - 1); grid_key_dx pkey; for (size_t i = 0 ; i < dim ; i++) pkey.set_d(i,std::floor( (sub_dom.getHigh(i) - dom.getLow(i)) / sp[i])); return pkey; } void calculateAp() { if (grid_dist_id_iterator_dec::isNext() == false) return; grid_key_dx key = grid_dist_id_iterator_dec::get(); for (size_t i = 0 ; i < dim ; i++) ap.get(i) = key.get(i) * sp[i] + domain.getLow(i); } public: /*! \brief Draw Particles * * \param sp grid spacing * */ PointIterator( Decomposition & dec, size_t (& sz)[dim], const Box & domain, Box & sub_domain) :grid_dist_id_iterator_dec(dec, sz, getStart(sz,domain,sub_domain,sp), getStop(sz,domain,sub_domain,sp)),sub_domain(sub_domain),domain(domain) { calculateAp(); } /*! \Return the actual point * * */ Point & get() { return ap; } /*! \brief Next point * * \return itself * */ PointIterator & operator++() { grid_dist_id_iterator_dec::operator++(); calculateAp(); return *this; } bool isNext() { return grid_dist_id_iterator_dec::isNext(); } /*! \brief Return the real Margin of the box * * For example consider to have a domain (0.0,0.0) to (1.0,1.0) * 11 points in each direction (spacing 0.1). if we have a sub-domain * (0.15,0.15) to (0.55,0.55) getBoxMargins return the box (0.2,0.2) to * (0.5,0.5). the smallest box that enclose the points that the point * iterator is going to give * */ Box getBoxMargins() { Box box; grid_key_dx start = grid_dist_id_iterator_dec::getStart(); grid_key_dx stop = grid_dist_id_iterator_dec::getStop(); for (size_t i = 0 ; i < dim ; i++) { box.setLow(i, start.get(i)*sp[i] + domain.getLow(i)); box.setHigh(i, stop.get(i)*sp[i] + domain.getLow(i)); } return box; } }; #endif /* OPENFPM_NUMERICS_SRC_DRAW_POINTITERATOR_HPP_ */