vtkGeoTreeNode.h 5.25 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkGeoTreeNode.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/

22 23 24 25 26 27 28 29 30 31 32 33 34 35
/**
 * @class   vtkGeoTreeNode
 * @brief   Stores data for a patch of the globe.
 *
 *
 * A self-referential data structure for storing geometry or imagery for
 * the geospatial views. The data is organized in a quadtree. Each node
 * contains a pointer to its parent and owns references to its four
 * child nodes. The ID of each node is unique in its level, and encodes
 * the path from the root node in its bits.
 *
 * @sa
 * vtkGeoView vtkGeoView2D vtkGeoTerrain vtkGeoAlignedImageRepresentation
*/
36

37 38
#ifndef vtkGeoTreeNode_h
#define vtkGeoTreeNode_h
Ken Martin's avatar
Ken Martin committed
39

40
#include "vtkGeovisCoreModule.h" // For export macro
Ken Martin's avatar
Ken Martin committed
41
#include "vtkObject.h"
Ken Martin's avatar
Ken Martin committed
42
#include "vtkSmartPointer.h" // for SP
Ken Martin's avatar
Ken Martin committed
43 44 45

class vtkPolyData;

46
class VTKGEOVISCORE_EXPORT vtkGeoTreeNode : public vtkObject
Ken Martin's avatar
Ken Martin committed
47 48 49
{
public:
  static vtkGeoTreeNode *New();
50
  vtkTypeMacro(vtkGeoTreeNode, vtkObject);
51
  void PrintSelf(ostream& os, vtkIndent indent) override;
52

53 54 55 56 57 58
  //@{
  /**
   * The id uniquely specified this node.
   * For this implementation I am going to store the branch path
   * in the bits.
   */
Ken Martin's avatar
Ken Martin committed
59 60
  vtkSetMacro(Id,unsigned long);
  vtkGetMacro(Id,unsigned long);
61
  //@}
62

63 64 65 66
  //@{
  /**
   * Knowing the level simplifies encoding the branch trace in the Id.
   */
Ken Martin's avatar
Ken Martin committed
67 68
  vtkSetMacro(Level, int);
  vtkGetMacro(Level, int);
69
  //@}
70

71 72 73 74
  //@{
  /**
   * Longitude and latitude range of the terrain model.
   */
Ken Martin's avatar
Ken Martin committed
75 76 77 78
  vtkSetVector2Macro(LongitudeRange,double);
  vtkGetVector2Macro(LongitudeRange,double);
  vtkSetVector2Macro(LatitudeRange,double);
  vtkGetVector2Macro(LatitudeRange,double);
79
  //@}
80

81 82 83 84
  /**
   * Get a child of this node. If one is set, then they all should
   * set.  No not mix subclasses.
   */
Ken Martin's avatar
Ken Martin committed
85 86
  void SetChild(vtkGeoTreeNode* node, int idx);

87 88 89 90 91
  /**
   * When we merge children to a lower resolution parent, we need
   * this reference.  It is not referenced counted to avoid reference loops.
   * A child should never exist when the parent is destructed anyway.
   */
92 93 94
  void SetParent(vtkGeoTreeNode* node)
    { this->Parent = node; }

95 96 97 98
  /**
   * Manage links to older and newer tree nodes.
   * These are used to periodically delete unused patches.
   */
99 100 101 102 103 104 105 106 107
  void SetOlder(vtkGeoTreeNode* node)
    { this->Older = node; }
  vtkGeoTreeNode* GetOlder()
    { return this->Older; }
  void SetNewer(vtkGeoTreeNode* node)
    { this->Newer = node; }
  vtkGeoTreeNode* GetNewer()
    { return this->Newer; }

108 109 110 111
  /**
   * Returns whether this node has valid data associated
   * with it, or if it is an "empty" node.
   */
112 113 114
  virtual bool HasData()
    { return false; }

115 116 117 118 119
  /**
   * Deletes the data associated with the node to make this
   * an "empty" node. This is performed when the node has
   * been unused for a certain amount of time.
   */
120 121
  virtual void DeleteData()
    { }
Ken Martin's avatar
Ken Martin committed
122

123 124 125
  /**
   * Get this nodes child index in node's parent.
   */
Ken Martin's avatar
Ken Martin committed
126 127
  int GetWhichChildAreYou();

128 129 130 131 132
  /**
   * This method returns true if this node descends from the
   * elder node.  The decision is made from the node ids, so the nodes do
   * not have to be in the same tree!
   */
Ken Martin's avatar
Ken Martin committed
133 134
  bool IsDescendantOf(vtkGeoTreeNode* elder);

135 136 137 138 139
  /**
   * Create children of the same type as parent.
   * Id, level and Latitude-Longitude ranges are set.
   * Returns VTK_ERROR if level gets too deep to create children.
   */
Ken Martin's avatar
Ken Martin committed
140 141
  int CreateChildren();

142 143 144 145 146
  /**
   * Get the child as a vtkGeoTreeNode.
   * Subclasses also implement GetChild() which returns the child
   * as the appropriate subclass type.
   */
147 148 149
  vtkGeoTreeNode* GetChildTreeNode(int idx)
    { return this->Children[idx]; }

150 151 152 153 154
  /**
   * Get the parent as a vtkGeoTreeNode.
   * Subclasses also implement GetParent() which returns the parent
   * as the appropriate subclass type.
   */
155 156 157
  vtkGeoTreeNode* GetParentTreeNode()
    { return this->Parent; }

158
  enum NodeStatus
159
  {
160 161
    NONE,
    PROCESSING
162
  };
163 164 165 166

  NodeStatus GetStatus();
  void SetStatus(NodeStatus status);

167 168 169 170 171
  //@{
  /**
   * Shallow and Deep copy. Deep copy performs a shallow copy
   * of the Child nodes.
   */
172
  virtual void ShallowCopy(vtkGeoTreeNode *src);
173
  virtual void DeepCopy(vtkGeoTreeNode *src);
174
  //@}
175

Ken Martin's avatar
Ken Martin committed
176 177
protected:
  vtkGeoTreeNode();
178
  ~vtkGeoTreeNode() override;
Ken Martin's avatar
Ken Martin committed
179 180 181 182 183 184 185 186

  int Level;
  unsigned long Id;

  double LongitudeRange[2];
  double LatitudeRange[2];

  vtkSmartPointer<vtkGeoTreeNode> Children[4];
187
  vtkGeoTreeNode * Parent;
188
  NodeStatus Status;
189 190
  vtkGeoTreeNode* Older;
  vtkGeoTreeNode* Newer;
Ken Martin's avatar
Ken Martin committed
191 192

private:
193 194
  vtkGeoTreeNode(const vtkGeoTreeNode&) = delete;
  void operator=(const vtkGeoTreeNode&) = delete;
Ken Martin's avatar
Ken Martin committed
195 196 197
};

#endif