Salome HOME
quick optimization patch (bytearray for images)
[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 #include <gp_XYZ.hxx>
39
40 #include <list>
41 #include <set>
42 #include <vector>
43 #include <map>
44
45 //forward declaration
46 class HYDROData_QuadtreeNode;
47 class gp_XY;
48
49 class Standard_EXPORT gpi_XYZ: public gp_XYZ
50 {
51 public:
52   gpi_XYZ();
53
54   gpi_XYZ(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, int i): gp_XYZ(X, Y, Z), myIndex(i) {}
55
56   int getIndex() const {return myIndex; }
57 protected:
58   int myIndex;
59 };
60
61 typedef std::list<gpi_XYZ*> Nodes_3D;
62
63 class Standard_EXPORT HYDROData_QuadtreeNode: public HYDROData_Quadtree
64 {
65
66 public:
67
68   //! public constructor: when theNodes is non null, compute the quadtree
69   HYDROData_QuadtreeNode(Nodes_3D* theNodes,
70                          const int maxLevel = 8,
71                          const int maxNbNodes = 5,
72                          const double minBoxSize = 0.);
73
74   //! destructor
75   virtual ~HYDROData_QuadtreeNode();
76
77   //! tu use when no nodes where given to the public constructor
78   virtual void setNodesAndCompute(Nodes_3D* theNodes);
79
80   //! Tells us if Node is inside the current box with the precision "precision"
81   virtual const bool isInside(const gp_XY& p, const double precision = 0.);
82
83   //! Return in Result a list of Nodes potentials to be near Node
84   void NodesAround(const gp_XY& Node,
85                    std::list<const gpi_XYZ*>* Result,
86                    const double precision = 0.);
87
88   //! Return in dist2Nodes nodes mapped to their square distance from Node
89   bool NodesAround(const gp_XY& node,
90                    std::map<double, const gpi_XYZ*>& dist2Nodes,
91                    double precision);
92
93   //! Update data according to node movement
94   void UpdateByMoveNode(const gpi_XYZ* node, const gp_Pnt& toPnt);
95
96   //! Return nb nodes in a tree
97   int NbNodes() const
98   {
99     if (myNodes)
100       return myNodes->size();
101     else
102       return 0;
103   }
104
105   //! tells us if the tree as already bin computed
106   bool isEmpty() const { return myChildren == 0; }
107
108   inline double getPrecision() {return myPrecision; }
109   inline void setPrecision(double precision)  {myPrecision = precision; }
110
111 protected:
112
113   struct Limit: public HYDROData_TreeLimit
114   {
115     int myMaxNbNodes;
116     Limit(int maxLevel, double minSize, int maxNbNodes) :
117         HYDROData_TreeLimit(maxLevel, minSize), myMaxNbNodes(maxNbNodes) {}
118   };
119
120   int getMaxNbNodes() const;
121
122   HYDROData_QuadtreeNode();
123
124   //! Compute the bounding box of the whole set of nodes myNodes
125   virtual Bnd_B2d* buildRootBox();
126
127   //! Shares the father's data with each of his child
128   virtual void buildChildrenData();
129
130   //! Construct an empty HYDROData_QuadtreeNode used by HYDROData_Quadtree::buildChildren()
131   virtual HYDROData_Quadtree* newChild() const;
132
133   //! The set of nodes inside the box of the Quadtree (Empty if Quadtree is not a leaf)
134   Nodes_3D* myNodes;
135
136   //! distance to look for nearest nodes
137   double myPrecision;
138 };
139
140 #endif