synaps/topology/Octree.h

Go to the documentation of this file.
00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS library          *
00003 *   Author(s): L. Deschamps                                          *
00004 *              G. Gatellier  , GALAAD, INRIA                         *
00005 **********************************************************************/
00007 #ifndef synaps_mesh_octree_H
00008 #define synaps_mesh_octree_H
00009 
00010 /*********************************************************************/
00011 
00012 #include <synaps/init.h>
00013 
00014 #include <iostream>
00015 #include <vector>
00016 
00017 /*********************************************************************/
00018 
00019 __BEGIN_NAMESPACE_SYNAPS
00020 
00022 
00032 namespace OCTREE
00033 {
00034   
00037   enum FACE_TYPE{B,F,W,E,S,N};
00038 
00039   //The order of the node_types should not be changed:
00040   // B_SW, F_SW, B_SE, F_SE, B_NW, F_NW, B_NE, F_NE
00041   enum NODE_TYPE{B_SW, F_SW, B_SE, F_SE, B_NW, F_NW, B_NE, F_NE};
00042   //  {F_NE, F_NW, F_SW, F_SE, B_NE, B_NW, B_SW, B_SE};
00043   enum EDGE_TYPE{B_E, B_W, B_S, B_N, F_E, F_W, F_S, F_N, S_E, N_E, S_W, N_W};
00044   
00046   template <class Cell>
00047   class Node
00048   {
00049     //the node of the octree, see octree at the end of this file 
00050     //each node corresponding to a box when breaking planes
00051   public:
00052   
00053     // Each node points on a cell. 
00054     Cell cell;
00055     
00056     // The type of the node. 
00057     // Makes some, its geographic situation in the subdivision into 8.
00058     NODE_TYPE type;
00059   
00060     // The father.
00061     Node* parent;
00062 
00063     //front side
00064     Node* F_NEchild; 
00065     Node* F_NWchild;
00066     Node* F_SEchild;
00067     Node* F_SWchild; 
00068 
00069     //back side          
00070     Node* B_NEchild;
00071     Node* B_NWchild; 
00072     Node* B_SEchild; 
00073     Node* B_SWchild; 
00074 
00075     // Depth of the node (that of the father is has 0)
00076     int depth;
00077 
00078     // The index of the node in the tree.
00079     int index;
00080 
00081   private :
00082  
00083     Node(Node& node);
00084 
00085   public:
00086 
00087     // Constructors
00088     Node(NODE_TYPE nodeType, Node<Cell>* theParent, Cell &theCell);
00089 
00090     Node();     
00091   
00092     // Modifieurs
00093     void  SetCell(Cell &c) { cell = c; }
00094 
00095     void  SetParent(Node* n){parent = n;}
00096          
00097     void  SetF_NEchild( Node<Cell>* n){F_NEchild = n;}
00098     void  SetF_NWchild( Node<Cell>* n){F_NWchild = n;}
00099     void  SetF_SEchild( Node<Cell>* n){F_SEchild = n;}
00100     void  SetF_SWchild( Node<Cell>* n){F_SWchild = n;} 
00101          
00102     void  SetB_NEchild( Node<Cell>* n){B_NEchild = n;} 
00103     void  SetB_NWchild( Node<Cell>* n){B_NWchild = n;} 
00104     void  SetB_SEchild( Node<Cell>* n){B_SEchild = n;} 
00105     void  SetB_SWchild( Node<Cell>* n){B_SWchild = n;} 
00106          
00107         
00108     // Accessors
00109     Cell&          GetCell() {return cell;}
00110 
00111     Node<Cell>*    GetF_NEchild(){return(F_NEchild);}
00112     Node<Cell>*    GetF_NWchild(){return(F_NWchild);}
00113     Node<Cell>*    GetF_SEchild(){return(F_SEchild);}
00114     Node<Cell>*    GetF_SWchild(){return(F_SWchild);}
00115          
00116     Node<Cell>*    GetB_NEchild(){return(B_NEchild);} 
00117     Node<Cell>*    GetB_NWchild(){return(B_NWchild);} 
00118     Node<Cell>*    GetB_SEchild(){return(B_SEchild);} 
00119     Node<Cell>*    GetB_SWchild(){return(B_SWchild);} 
00120  
00121     // Is the node a leaf?
00122     bool isLeaf();
00123 
00124 
00132     void getAllFaceNeighbors(std::vector< Node<Cell> * > &nbrs); 
00133   
00136     void getAllNeighbors(std::vector< Node<Cell> * > &nbrs);
00137     
00139     void getAllEdgeNeighbors(std::vector< Node<Cell> * > &nbrs);
00140 
00141     /**************************************** 
00142      *             DUE SECTION              * 
00143      ****************************************/
00144   
00145     //---------------DUE SOUTH---------------------
00146 
00147     void getAllSouthNeighbors(std::vector< Node<Cell>*>& nbrs);
00148     Node<Cell>* getSouthNeighborNode();
00150     void getNorthBoundary(std::vector< Node<Cell>*>& nbrs);
00151 
00152     //---------------DUE NORTH---------------------
00153 
00155     void getAllNorthNeighbors(std::vector< Node<Cell>*>& nbrs);
00156     Node<Cell>* getNorthNeighborNode();
00158     void getSouthBoundary(std::vector< Node<Cell>*>& nbrs);
00159 
00160     //---------------DUE WEST---------------------
00161 
00163     void getAllWestNeighbors(std::vector< Node<Cell>*>& nbrs);
00164     Node<Cell>* getWestNeighborNode();
00165     void getEastBoundary(std::vector< Node<Cell>*>& nbrs);
00166 
00167     //--------DUE EAST--------------------
00168 
00170     void getWestBoundary(std::vector< Node<Cell>*>& nbrs);
00171     void getAllEastNeighbors(std::vector< Node<Cell>*>& nbrs);
00172     Node<Cell>* getEastNeighborNode(); 
00173 
00174     //---------------DUE FRONT--------------------- 
00175 
00177     void getAllFrontNeighbors(std::vector< Node<Cell>*>& nbrs); 
00178     Node<Cell>* getFrontNeighborNode(); 
00179     void getBackBoundary(std::vector< Node<Cell>*>& nbrs); 
00180 
00181     //---------------DUE BACK--------------------- 
00182 
00184     void getAllBackNeighbors(std::vector< Node<Cell>*>& nbrs); 
00185     Node<Cell>* getBackNeighborNode(); 
00186     void getFrontBoundary(std::vector< Node<Cell>*>& nbrs); 
00187 
00188     /************************************************ 
00189      *             CORNER-LINE PARTS                * 
00190      ************************************************/ 
00192     void getNWLine(std::vector< Node<Cell>*>& line); 
00193     void getNELine(std::vector< Node<Cell>*>& line); 
00194     void getSWLine(std::vector< Node<Cell>*>& line); 
00195     void getSELine(std::vector< Node<Cell>*>& line); 
00196     void getF_NLine(std::vector< Node<Cell>*>& line); 
00197     void getF_SLine(std::vector< Node<Cell>*>& line); 
00198     void getF_ELine(std::vector< Node<Cell>*>& line); 
00199     void getF_WLine(std::vector< Node<Cell>*>& line); 
00200     void getB_NLine(std::vector< Node<Cell>*>& line); 
00201     void getB_SLine(std::vector< Node<Cell>*>& line); 
00202     void getB_ELine(std::vector< Node<Cell>*>& line); 
00203     void getB_WLine(std::vector< Node<Cell>*>& line); 
00204          
00206     void getNWNeighbors(std::vector< Node<Cell>*>& nbrs); 
00207     void getNENeighbors(std::vector< Node<Cell>*>& nbrs); 
00208     void getSWNeighbors(std::vector< Node<Cell>*>& nbrs); 
00209     void getSENeighbors(std::vector< Node<Cell>*>& nbrs); 
00210     void getF_NNeighbors(std::vector< Node<Cell>*>& nbrs); 
00211     void getF_SNeighbors(std::vector< Node<Cell>*>& nbrs); 
00212     void getF_ENeighbors(std::vector< Node<Cell>*>& nbrs); 
00213     void getF_WNeighbors(std::vector< Node<Cell>*>& nbrs); 
00214     void getB_NNeighbors(std::vector< Node<Cell>*>& nbrs); 
00215     void getB_SNeighbors(std::vector< Node<Cell>*>& nbrs); 
00216     void getB_ENeighbors(std::vector< Node<Cell>*>& nbrs); 
00217     void getB_WNeighbors(std::vector< Node<Cell>*>& nbrs); 
00218     /************************************************ 
00219      *             TRUE CORNER PARTS                * 
00220      ************************************************/ 
00222     Node<Cell>* getF_NWCorner(); 
00223     Node<Cell>* getF_NECorner(); 
00224     Node<Cell>* getF_SWCorner(); 
00225     Node<Cell>* getF_SECorner(); 
00226     
00227     Node<Cell>* getB_NWCorner(); 
00228     Node<Cell>* getB_NECorner(); 
00229     Node<Cell>* getB_SWCorner(); 
00230     Node<Cell>* getB_SECorner(); 
00231  
00233     Node<Cell>* F_NENeighbor();
00234     Node<Cell>* F_NWNeighbor(); 
00235     Node<Cell>* F_SWNeighbor(); 
00236     Node<Cell>* F_SENeighbor(); 
00237  
00238     Node<Cell>* B_NENeighbor();
00239     Node<Cell>* B_NWNeighbor(); 
00240     Node<Cell>* B_SWNeighbor(); 
00241     Node<Cell>* B_SENeighbor(); 
00242 
00243     bool isSmallerThanNeighbors( std::vector< Node<Cell> * > &nbrs );
00244 
00245   };
00246   
00247 
00251   template <class Cell>
00252   class Octree
00253   {
00254   public:
00255  
00256     // The root node.
00257     Node<Cell>* root;
00258     
00259     // Constructor with initialization.
00260     Octree<Cell>()
00261       {
00262         root = new Node<Cell>();
00263         root->SetParent(NULL);
00264       } 
00265      
00266     // Accessor.
00267     Node<Cell>* GetRoot(){ return(root); }
00268 
00269   };
00270 
00271   template <class Cell>
00272   std::ostream& operator<<( std::ostream& os, const Octree<Cell>& octree)
00273   {return os;}
00274 
00275 /*****************************************************************************/
00276 #include "Octree.C"
00277 /*****************************************************************************/
00278 }
00279 
00280 __END_NAMESPACE_SYNAPS
00281 
00282 #endif // synaps_mesh_octree_H

SYNAPS DOCUMENTATION
logo