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