Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkHierarchicalDataSetInternal.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkHierarchicalDataSetInternal.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00016 #ifndef __vtkHierarchicalDataSetInternal_h
00017 #define __vtkHierarchicalDataSetInternal_h
00018 
00019 #include <vtkstd/vector>
00020 #include <vtkstd/algorithm>
00021 
00022 #include "vtkDataObject.h"
00023 #include "vtkSmartPointer.h"
00024 
00025 class vtkHDSNode;
00026 
00027 struct vtkHierarchicalDataSetInternal
00028 {
00029   typedef vtkstd::vector<vtkHDSNode*> LevelDataSetsType;
00030   typedef LevelDataSetsType::iterator LevelDataSetsIterator;
00031   typedef vtkstd::vector<LevelDataSetsType> DataSetsType;
00032   typedef DataSetsType::iterator DataSetsIterator;
00033 
00034   DataSetsType DataSets;
00035 };
00036 
00037 struct vtkHDSNodeRef
00038 {
00039   vtkHDSNodeRef(int level, int index) : Level(level), Index(index) {}
00040 
00041   vtkstd_bool operator==(const vtkHDSNodeRef& rhs)
00042     {
00043       return (this->Level == rhs.Level) && (this->Index == rhs.Index);
00044     }
00045   vtkstd_bool operator!=(const vtkHDSNodeRef& rhs)
00046     {
00047       return (this->Level != rhs.Level) || (this->Index != rhs.Index);
00048     }
00049   
00050   int Level;
00051   int Index;
00052 };
00053 
00054 class vtkHDSNode
00055 {
00056 public:
00057 
00058   vtkHDSNode() : DataSet(0) {}
00059   vtkSmartPointer<vtkDataObject> DataSet;
00060 
00061   void AddParent(const vtkHDSNodeRef& parent);
00062   void AddChild (const vtkHDSNodeRef& child );
00063 
00064   void RemoveParent(const vtkHDSNodeRef& parent);
00065   void RemoveChild (const vtkHDSNodeRef& child );
00066 
00067   void DisconnectFromParent(const vtkHDSNodeRef& self,
00068                             const vtkHDSNodeRef& parent,
00069                             vtkHierarchicalDataSetInternal::DataSetsType& ds);
00070   void DisconnectFromChild (const vtkHDSNodeRef& self,
00071                             const vtkHDSNodeRef& child,
00072                             vtkHierarchicalDataSetInternal::DataSetsType& ds);
00073   void ConnectToParent(const vtkHDSNodeRef& self,
00074                        const vtkHDSNodeRef& parent,
00075                        vtkHierarchicalDataSetInternal::DataSetsType& ds);
00076   void ConnectToChild (const vtkHDSNodeRef& self,
00077                        const vtkHDSNodeRef& child,
00078                        vtkHierarchicalDataSetInternal::DataSetsType& ds);
00079 
00080   void DisconnectAll(const vtkHDSNodeRef& self,
00081                      vtkHierarchicalDataSetInternal::DataSetsType& ds);
00082 
00083 protected:
00084   vtkstd::vector<vtkHDSNodeRef> Parents;
00085   vtkstd::vector<vtkHDSNodeRef> Children;
00086 };
00087 
00088 inline void vtkHDSNode::AddParent(const vtkHDSNodeRef& parent)
00089 {
00090   this->Parents.push_back(parent);
00091 }
00092 
00093 inline void vtkHDSNode::AddChild(const vtkHDSNodeRef& child)
00094 {
00095   this->Children.push_back(child);
00096 }
00097 
00098 inline void vtkHDSNode::RemoveParent(const vtkHDSNodeRef& parent)
00099 {
00100   vtkstd::vector<vtkHDSNodeRef>::iterator it = 
00101     vtkstd::find(this->Parents.begin(), this->Parents.end(), parent);
00102   if (it != this->Parents.end())
00103     {
00104     this->Parents.erase(it);
00105     }
00106 }
00107 
00108 inline void vtkHDSNode::RemoveChild (const vtkHDSNodeRef& child)
00109 {
00110   vtkstd::vector<vtkHDSNodeRef>::iterator it = 
00111     vtkstd::find(this->Children.begin(), this->Children.end(), child);
00112   if (it != this->Children.end())
00113     {
00114     this->Children.erase(it);
00115     }
00116 }
00117 
00118 inline void vtkHDSNode::ConnectToParent(
00119   const vtkHDSNodeRef& self,
00120   const vtkHDSNodeRef& parent,
00121   vtkHierarchicalDataSetInternal::DataSetsType& ds)
00122 {
00123   this->AddParent(parent);
00124   ds[parent.Level][parent.Index]->AddChild(self);
00125 }
00126 
00127 inline void vtkHDSNode::ConnectToChild(
00128   const vtkHDSNodeRef& self,
00129   const vtkHDSNodeRef& child,
00130   vtkHierarchicalDataSetInternal::DataSetsType& ds)
00131 {
00132   this->AddChild(child);
00133   ds[child.Level][child.Index]->AddParent(self);
00134 }
00135 
00136 inline void vtkHDSNode::DisconnectFromParent(
00137   const vtkHDSNodeRef& self,
00138   const vtkHDSNodeRef& parent, 
00139   vtkHierarchicalDataSetInternal::DataSetsType& ds)
00140 {
00141   this->RemoveParent(parent);
00142   ds[parent.Level][parent.Index]->RemoveChild(self);
00143 }
00144 
00145 inline void vtkHDSNode::DisconnectFromChild(
00146   const vtkHDSNodeRef& self,
00147   const vtkHDSNodeRef& child, 
00148   vtkHierarchicalDataSetInternal::DataSetsType& ds)
00149 {
00150   this->RemoveChild(child);
00151   ds[child.Level][child.Index]->RemoveParent(self);
00152 }
00153 
00154 inline void vtkHDSNode::DisconnectAll(
00155   const vtkHDSNodeRef& self, vtkHierarchicalDataSetInternal::DataSetsType& ds)
00156 {
00157   vtkstd::vector<vtkHDSNodeRef>::iterator it;
00158 
00159   for(it=this->Parents.begin(); it!=this->Parents.end(); ++it)
00160     {
00161     this->DisconnectFromParent(self, *it, ds);
00162     }
00163 
00164   for(it=this->Children.begin(); it!=this->Children.end(); ++it)
00165     {
00166     this->DisconnectFromChild(self, *it, ds);
00167     }
00168 
00169 }
00170 
00171 #endif