1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkDataObjectTreeIterator.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /**
16  * @class   vtkDataObjectTreeIterator
17  * @brief   superclass for composite data iterators
18  *
19  * vtkDataObjectTreeIterator provides an interface for accessing datasets
20  * in a collection (vtkDataObjectTreeIterator).
21  */
22 
23 #ifndef vtkDataObjectTreeIterator_h
24 #define vtkDataObjectTreeIterator_h
25 
26 #include "vtkCommonDataModelModule.h" // For export macro
27 #include "vtkCompositeDataIterator.h"
28 #include "vtkSmartPointer.h" //to store data sets
29 
30 class vtkDataObjectTree;
31 class vtkDataObjectTreeInternals;
32 class vtkDataObjectTreeIndex;
33 class vtkDataObject;
34 class vtkInformation;
35 
36 class VTKCOMMONDATAMODEL_EXPORT vtkDataObjectTreeIterator : public vtkCompositeDataIterator
37 {
38 public:
39   static vtkDataObjectTreeIterator* New();
40   vtkTypeMacro(vtkDataObjectTreeIterator, vtkCompositeDataIterator);
41   void PrintSelf(ostream& os, vtkIndent indent) override;
42 
43   /**
44    * Move the iterator to the beginning of the collection.
45    */
46   void GoToFirstItem() override;
47 
48   /**
49    * Move the iterator to the next item in the collection.
50    */
51   void GoToNextItem() override;
52 
53   /**
54    * Test whether the iterator is finished with the traversal.
55    * Returns 1 for yes, and 0 for no.
56    * It is safe to call any of the GetCurrent...() methods only when
57    * IsDoneWithTraversal() returns 0.
58    */
59   int IsDoneWithTraversal() override;
60 
61   /**
62    * Returns the current item. Valid only when IsDoneWithTraversal() returns 0.
63    */
64   vtkDataObject* GetCurrentDataObject() override;
65 
66   /**
67    * Returns the meta-data associated with the current item.
68    * Note that, depending on iterator implementation, the returned information
69    * is not necessarily stored on the current object. So modifying the information
70    * is forbidden.
71    */
72   vtkInformation* GetCurrentMetaData() override;
73 
74   /**
75    * Returns if the a meta-data information object is present for the current
76    * item. Return 1 on success, 0 otherwise.
77    */
78   int HasCurrentMetaData() override;
79 
80   /**
81    * Flat index is an index obtained by traversing the tree in preorder.
82    * This can be used to uniquely identify nodes in the tree.
83    * Not valid if IsDoneWithTraversal() returns true.
84    */
85   unsigned int GetCurrentFlatIndex() override;
86 
87   ///@{
88   /**
89    * If VisitOnlyLeaves is true, the iterator will only visit nodes
90    * (sub-datasets) that are not composite. If it encounters a composite
91    * data set, it will automatically traverse that composite dataset until
92    * it finds non-composite datasets. With this options, it is possible to
93    * visit all non-composite datasets in tree of composite datasets
94    * (composite of composite of composite for example :-) ) If
95    * VisitOnlyLeaves is false, GetCurrentDataObject() may return
96    * vtkCompositeDataSet. By default, VisitOnlyLeaves is 1.
97    */
98   vtkSetMacro(VisitOnlyLeaves, vtkTypeBool);
99   vtkGetMacro(VisitOnlyLeaves, vtkTypeBool);
100   vtkBooleanMacro(VisitOnlyLeaves, vtkTypeBool);
101   ///@}
102 
103   ///@{
104   /**
105    * If TraverseSubTree is set to true, the iterator will visit the entire tree
106    * structure, otherwise it only visits the first level children. Set to 1 by
107    * default.
108    */
109   vtkSetMacro(TraverseSubTree, vtkTypeBool);
110   vtkGetMacro(TraverseSubTree, vtkTypeBool);
111   vtkBooleanMacro(TraverseSubTree, vtkTypeBool);
112   ///@}
113 
114 protected:
115   vtkDataObjectTreeIterator();
116   ~vtkDataObjectTreeIterator() override;
117 
118   // Use the macro to ensure MTime is updated:
119   vtkSetMacro(CurrentFlatIndex, unsigned int);
120 
121   // Takes the current location to the next dataset. This traverses the tree in
122   // preorder fashion.
123   // If the current location is a composite dataset, next is its 1st child dataset.
124   // If the current is not a composite dataset, then next is the next dataset.
125   // This method gives no guarantees whether the current dataset will be
126   // non-null or leaf.
127   void NextInternal();
128 
129   /**
130    * Returns the index for the current data object.
131    */
132   vtkDataObjectTreeIndex GetCurrentIndex();
133 
134   // Needs access to GetCurrentIndex().
135   friend class vtkDataObjectTree;
136   friend class vtkMultiDataSetInternal;
137 
138   unsigned int CurrentFlatIndex;
139 
140 private:
141   vtkDataObjectTreeIterator(const vtkDataObjectTreeIterator&) = delete;
142   void operator=(const vtkDataObjectTreeIterator&) = delete;
143 
144   class vtkInternals;
145   vtkInternals* Internals;
146   friend class vtkInternals;
147 
148   vtkTypeBool TraverseSubTree;
149   vtkTypeBool VisitOnlyLeaves;
150 
151   /**
152    * Helper method used by vtkInternals to get access to the internals of
153    * vtkDataObjectTree.
154    */
155   vtkDataObjectTreeInternals* GetInternals(vtkDataObjectTree*);
156 
157   // Cannot be called when this->IsDoneWithTraversal() return 1.
158   void UpdateLocation();
159 };
160 
161 #endif
162