Salome HOME
Merge branch 'BR_v14_rc' into BR_quadtree
[modules/hydro.git] / src / HYDROData / HYDROData_QuadtreeNode.hxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  HYDROData HYDROData_QuadtreeNode : Quadtree with Nodes set (from SMESH module)
24 //  inherits global class HYDROData_Quadtree
25 //  File      : HYDROData_QuadtreeNode.hxx
26 //  Created   : Tue Jan 16 16:00:00 2007
27 //  Author    : Nicolas Geimer & Aurelien Motteux  (OCC)
28 //  Module    : HYDROData
29 //
30 #ifndef _HYDROData_QUADTREENODE_HXX_
31 #define _HYDROData_QUADTREENODE_HXX_
32
33 #include <Standard.hxx>
34 #include <Standard_Macro.hxx>
35
36 #include "HYDROData_Quadtree.hxx"
37 #include <gp_Pnt.hxx>
38
39 #include <list>
40 #include <set>
41 #include <vector>
42 #include <map>
43
44 //forward declaration
45 class HYDROData_QuadtreeNode;
46 class gp_XY;
47 class gp_XYZ;
48
49 typedef std::list<gp_XYZ*> Nodes_3D;
50
51 class Standard_EXPORT HYDROData_QuadtreeNode: public HYDROData_Quadtree
52 {
53
54 public:
55
56   //! public constructor: when theNodes is non null, compute the quadtree
57   HYDROData_QuadtreeNode(Nodes_3D* theNodes,
58                          const int maxLevel = 8,
59                          const int maxNbNodes = 5,
60                          const double minBoxSize = 0.);
61
62   //! destructor
63   virtual ~HYDROData_QuadtreeNode();
64
65   //! tu use when no nodes where given to the public constructor
66   virtual void setNodesAndCompute(Nodes_3D* theNodes);
67
68   //! Tells us if Node is inside the current box with the precision "precision"
69   virtual const bool isInside(const gp_XY& p, const double precision = 0.);
70
71   //! Return in Result a list of Nodes potentials to be near Node
72   void NodesAround(const gp_XY& Node,
73                    std::list<const gp_XYZ*>* Result,
74                    const double precision = 0.);
75
76   //! Return in dist2Nodes nodes mapped to their square distance from Node
77   bool NodesAround(const gp_XY& node,
78                    std::map<double, const gp_XYZ*>& dist2Nodes,
79                    double precision);
80
81   //! Update data according to node movement
82   void UpdateByMoveNode(const gp_XYZ* node, const gp_Pnt& toPnt);
83
84   //! Return nb nodes in a tree
85   int NbNodes() const
86   {
87     if (myNodes)
88       return myNodes->size();
89     else
90       return 0;
91   }
92
93   //! tells us if the tree as already bin computed
94   bool isEmpty() const { return myChildren == 0; }
95
96   inline double getPrecision() {return myPrecision; }
97   inline double setPrecision(double precision)  {myPrecision = precision; }
98
99 protected:
100
101   struct Limit: public HYDROData_TreeLimit
102   {
103     int myMaxNbNodes;
104     Limit(int maxLevel, double minSize, int maxNbNodes) :
105         HYDROData_TreeLimit(maxLevel, minSize), myMaxNbNodes(maxNbNodes) {}
106   };
107
108   int getMaxNbNodes() const;
109
110   HYDROData_QuadtreeNode();
111
112   //! Compute the bounding box of the whole set of nodes myNodes
113   virtual Bnd_B2d* buildRootBox();
114
115   //! Shares the father's data with each of his child
116   virtual void buildChildrenData();
117
118   //! Construct an empty HYDROData_QuadtreeNode used by HYDROData_Quadtree::buildChildren()
119   virtual HYDROData_Quadtree* newChild() const;
120
121   //! The set of nodes inside the box of the Quadtree (Empty if Quadtree is not a leaf)
122   Nodes_3D* myNodes;
123
124   //! distance to look for nearest nodes
125   double myPrecision;
126 };
127
128 #endif