File indexing completed on 2024-04-28 03:40:50

0001 /*************************************************************************************
0002  *  Copyright (C) 2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>      *
0003  *                                                                                   *
0004  *  This program is free software; you can redistribute it and/or                    *
0005  *  modify it under the terms of the GNU General Public License                      *
0006  *  as published by the Free Software Foundation; either version 2                   *
0007  *  of the License, or (at your option) any later version.                           *
0008  *                                                                                   *
0009  *  This program is distributed in the hope that it will be useful,                  *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0012  *  GNU General Public License for more details.                                     *
0013  *                                                                                   *
0014  *  You should have received a copy of the GNU General Public License                *
0015  *  along with this program; if not, write to the Free Software                      *
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0017  *************************************************************************************/
0018 
0019 
0020 #ifndef QUADTREE_H
0021 #define QUADTREE_H
0022 
0023 #include <QRectF>
0024 
0025 class Square : public QRectF
0026 {
0027 public:
0028     Square(const QPointF &c = QPointF(0,0), double hEdge = 1);
0029     Square(double x, double y, double hEdge = 1);
0030 
0031     void setCeter(const QPointF &c);
0032     void setCenter(double x, double y);
0033 
0034     double halfEdge() const;
0035     void setHalfEdge(double he);
0036 };
0037 
0038 
0039 struct QNode
0040 {
0041     Square cubo;
0042     QNode* nodos[8];
0043 };
0044 
0045 
0046 /*
0047  node index
0048 
0049  -----
0050  |2|4|
0051  -----
0052  |1|3|
0053  -----
0054 */
0055 
0056 
0057 
0058 class Quadtree
0059 {
0060 private:
0061     QNode* root;
0062 
0063     //create children with correct vertex values
0064     void inicializar_nodos(QNode* padre);
0065 
0066     void borrar_rec(QNode* nodo);
0067     void crear_rec(QNode* nodo, unsigned int nivel_actual, unsigned int nivel_max);
0068 
0069 public:
0070     explicit Quadtree(double largo_mundo);
0071     explicit Quadtree(const Square &cubo);
0072     ~Quadtree();
0073 
0074     QNode* get_raiz();
0075     void crearNivel(unsigned int nivel);
0076     void bajarNivel(QNode* nodo);
0077     void borrarHijos(QNode* padre);
0078 
0079 };
0080 
0081 
0082 #endif
0083