Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkBSPTree.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 
00011 #ifndef __mitkBSPTree_h
00012 #define __mitkBSPTree_h
00013 
00018 template <class BSPTreeNode> 
00019 class mitkBSPTree
00020 {
00021 public:
00022     float plane[4];
00023     BSPTreeNode *node;
00024     mitkBSPTree *front;
00025     mitkBSPTree *back;  
00026 
00027     mitkBSPTree() : node(NULL), front(NULL), back(NULL) {}
00028     ~mitkBSPTree() { delete node; node=NULL; delete front; front=NULL; delete back; back=NULL; }
00029 };
00030 
00031 template <class BSPTreeNode, class NodeProc>
00032 inline void mitkBSPTreeTravelFrontToBack(mitkBSPTree<BSPTreeNode> *tree, float eyepos[3])
00033 {
00034     if (tree->node)
00035     {
00036         NodeProc(tree->node);
00037     }
00038     else
00039     {
00040         float const *p = tree->plane;
00041         if (p[0]*eyepos[0]+p[1]*eyepos[1]+p[2]*eyepos[2]+p[3] <= 0)
00042         {
00043             if (tree->back) mitkBSPTreeTravelFrontToBack(tree->back, eyepos);
00044             if (tree->front) mitkBSPTreeTravelFrontToBack(tree->front, eyepos);
00045         }
00046         else
00047         {
00048             if (tree->front) mitkBSPTreeTravelFrontToBack(tree->front, eyepos);
00049             if (tree->back) mitkBSPTreeTravelFrontToBack(tree->back, eyepos);
00050         }
00051     }
00052 }
00053 
00054 template <class BSPTreeNode, class NodeProc>
00055 inline void mitkBSPTreeTravelBackToFront(mitkBSPTree<BSPTreeNode> *tree, float eyepos[3])
00056 {
00057     if (tree->node)
00058     {
00059         NodeProc(tree->node);
00060     }
00061     else
00062     {
00063         float const *p = tree->plane;
00064         if (p[0]*eyepos[0]+p[1]*eyepos[1]+p[2]*eyepos[2]+p[3] <= 0)
00065         {
00066             if (tree->back) mitkBSPTreeTravelBackToFront(tree->back, eyepos);
00067             if (tree->front) mitkBSPTreeTravelBackToFront(tree->front, eyepos);
00068         }
00069         else
00070         {
00071             if (tree->front) mitkBSPTreeTravelBackToFront(tree->front, eyepos);
00072             if (tree->back) mitkBSPTreeTravelBackToFront(tree->back, eyepos);
00073         }
00074     }
00075 }
00076 
00077 #endif
00078 

Generated on Tue Feb 25 15:00:36 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3