Salome HOME
Merge from BR_phase16 branch (09/12/09)
[modules/smesh.git] / src / SMESH / SMESH_OctreeNode.hxx
1 //  Copyright (C) 2007-2008  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.
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 //  SMESH SMESH_OctreeNode : Octree with Nodes set
23 //  inherites global class SMESH_Octree
24 //
25 //  File      : SMESH_OctreeNode.hxx
26 //  Created   : Tue Jan 16 16:00:00 2007
27 //  Author    : Nicolas Geimer & AurĂ©lien Motteux  (OCC)
28 //  Module    : SMESH
29
30 #ifndef _SMESH_OCTREENODE_HXX_
31 #define _SMESH_OCTREENODE_HXX_
32
33 #include "SMESH_Octree.hxx"
34
35 #include <list>
36 #include <set>
37 #include <map>
38
39 #include "SMDS_ElemIterator.hxx"
40
41 //forward declaration
42 class SMDS_MeshNode;
43 class SMESH_OctreeNode;
44
45 typedef SMDS_Iterator<SMESH_OctreeNode*>            SMESH_OctreeNodeIterator;
46 typedef boost::shared_ptr<SMESH_OctreeNodeIterator> SMESH_OctreeNodeIteratorPtr;
47
48 class SMESH_OctreeNode : public SMESH_Octree {
49
50 public:
51
52   // Constructor
53   SMESH_OctreeNode (const std::set<const SMDS_MeshNode*>& theNodes, const int maxLevel = -1,
54                     const int maxNbNodes = 5, const double minBoxSize = 0.);
55
56 //=============================
57 /*!
58  * \brief Empty destructor
59  */
60 //=============================
61   virtual ~SMESH_OctreeNode () {};
62
63   // Tells us if Node is inside the current box with the precision "precision"
64   virtual const bool isInside(const SMDS_MeshNode * Node, const double precision = 0.);
65
66   // Return in Result a list of Nodes potentials to be near Node
67   void               NodesAround(const SMDS_MeshNode * Node,
68                                  std::list<const SMDS_MeshNode*>* Result,
69                                  const double precision = 0.);
70
71   // Return in dist2Nodes nodes mapped to their square distance from Node
72   bool               NodesAround(const SMDS_MeshNode *                   Node,
73                                  std::map<double, const SMDS_MeshNode*>& dist2Nodes,
74                                  double                                  precision);
75
76   // Return in theGroupsOfNodes a list of group of nodes close to each other within theTolerance
77   // Search for all the nodes in nodes
78   void               FindCoincidentNodes ( std::set<const SMDS_MeshNode*>* nodes,
79                                            const double                theTolerance,
80                                            std::list< std::list< const SMDS_MeshNode*> >* theGroupsOfNodes);
81
82   // Static method that return in theGroupsOfNodes a list of group of nodes close to each other within
83   // theTolerance search for all the nodes in nodes
84   static void        FindCoincidentNodes ( std::set<const SMDS_MeshNode*>& nodes,
85                                            std::list< std::list< const SMDS_MeshNode*> >* theGroupsOfNodes,
86                                            const double theTolerance = 0.00001,
87                                            const int maxLevel = -1,
88                                            const int maxNbNodes = 5);
89   /*!
90    * \brief Update data according to node movement
91    */
92   void                        UpdateByMoveNode( const SMDS_MeshNode* node, const gp_Pnt& toPnt );
93   /*!
94    * \brief Return iterator over children
95    */
96   SMESH_OctreeNodeIteratorPtr GetChildrenIterator();
97   /*!
98    * \brief Return nodes iterator
99    */
100   SMDS_NodeIteratorPtr        GetNodeIterator();
101   /*!
102    * \brief Return nb nodes in a tree
103    */
104   int                         NbNodes() const { return myNodes.size(); }
105
106 protected:
107
108   SMESH_OctreeNode (int maxNbNodes );
109
110   // Compute the bounding box of the whole set of nodes myNodes
111   virtual Bnd_B3d*      buildRootBox();
112
113   // Shares the father's data with each of his child
114   virtual void          buildChildrenData();
115
116   // Construct an empty SMESH_OctreeNode used by SMESH_Octree::buildChildren()
117   virtual SMESH_Octree* allocateOctreeChild() const;
118
119   // Return in result a list of nodes closed to Node and remove it from SetOfNodes
120   void                  FindCoincidentNodes( const SMDS_MeshNode * Node,
121                                              std::set<const SMDS_MeshNode*>* SetOfNodes,
122                                              std::list<const SMDS_MeshNode*>* Result,
123                                              const double precision);
124
125   // The max number of nodes a leaf box can contain
126   int                              myMaxNbNodes;
127
128   // The set of nodes inside the box of the Octree (Empty if Octree is not a leaf)
129   std::set<const SMDS_MeshNode*>   myNodes;
130
131 };
132
133 #endif