2 ///////////////////////////////////////////////////////////////////////////////
4 // Description: header file for quadtree management (Cquadtree class) //
5 // This file is part of the SISCone project. //
6 // For more details, see http://projects.hepforge.org/siscone //
8 // Copyright (c) 2006 Gavin Salam and Gregory Soyez //
10 // This program is free software; you can redistribute it and/or modify //
11 // it under the terms of the GNU General Public License as published by //
12 // the Free Software Foundation; either version 2 of the License, or //
13 // (at your option) any later version. //
15 // This program is distributed in the hope that it will be useful, //
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
18 // GNU General Public License for more details. //
20 // You should have received a copy of the GNU General Public License //
21 // along with this program; if not, write to the Free Software //
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
24 // $Revision:: 123 $//
25 // $Date:: 2007-03-01 02:52:16 +0100 (Thu, 01 Mar 2007) $//
26 ///////////////////////////////////////////////////////////////////////////////
28 #ifndef __QUADTREE_H__
29 #define __QUADTREE_H__
38 * \brief Implementation of a 2D quadtree.
40 * This class implements the traditional two-dimensional quadtree.
41 * The elements at each node are of 'Cmomentum' type.
48 /// ctor with initialisation (see init for details)
49 Cquadtree(double _x, double _y, double _half_size_x, double _half_size_y);
51 /// default destructor
52 /// at destruction, everything is destroyed except
53 /// physical values at the leaves
58 * By initializing the tree, we mean setting the cell parameters
59 * and preparing the object to act as a seed for a new tree.
60 * \param _x x-position of the center
61 * \param _y y-position of the center
62 * \param _half_size_x x-size of the cell
63 * \param _half_size_y y-size of the cell
64 * \return 0 on success, 1 on error. Note that if the cell or its
65 * parent is already filled, we return an error.
67 int init(double _x, double _y, double _half_size_x, double _half_size_y);
70 * adding a particle to the tree.
71 * This method adds one vector to the quadtree structure which
72 * is updated consequently.
73 * \param v_add vector to add
74 * \return 0 on success 1 on error
76 int add(Cmomentum *v_add);
79 * circle intersection.
80 * computes the intersection with a circle of given centre and radius.
81 * The output takes the form of a quadtree with all squares included
83 * \param cx circle centre x coordinate
84 * \param cy circle centre y coordinate
85 * \param cR2 circle radius SQUARED
86 * \return the checksum for that intersection
88 Creference circle_intersect(double cx, double cy, double cR2);
91 * output a data file for drawing the grid.
92 * This can be used to output a data file containing all the
93 * grid subdivisions. The file contents is as follows:
94 * first and second columns give center of the cell, the third
96 * \param flux opened stream to write to
97 * \return 0 on success, 1 on error
102 * output a data file for drawing the tree leaves.
103 * This can be used to output a data file containing all the
104 * tree leaves. The file contents is as follows:
105 * first and second columns give center of the cell, the third
107 * \param flux opened stream to write to
108 * \return 0 on success, 1 on error
110 int save_leaves(FILE *flux);
112 double centre_x; ///< x-position of the centre of the cell
113 double centre_y; ///< y-position of the centre of the cell
114 double half_size_x; ///< HALF size of the cell
115 double half_size_y; ///< HALF size of the cell
117 Cmomentum *v; ///< physical contents
119 Cquadtree* children[2][2]; ///< sub-cells ( 0,1->left-right; 0,1->bottom,top)
120 bool has_child; ///< true if not a leaf