1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/*=============================================================================
Program: Visualization Toolkit
Module: vtkGeoTreeNode.cxx
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.
-------------------------------------------------------------------------*/
#include "vtkObjectFactory.h"
#include "vtkGeoTreeNode.h"
vtkStandardNewMacro(vtkGeoTreeNode);
//----------------------------------------------------------------------------
vtkGeoTreeNode::vtkGeoTreeNode()
{
this->Level = 0;
this->Parent = 0;
this->Older = 0;
this->Newer = 0;
this->Id = 0; // make valgrind happy
this->LatitudeRange[0] = this->LatitudeRange[1] = 0.;
this->LongitudeRange[0] = this->LongitudeRange[1] = 0.;
this->Status = NONE;
}
//-----------------------------------------------------------------------------
vtkGeoTreeNode::~vtkGeoTreeNode()
{
this->SetParent(0);
}
//-----------------------------------------------------------------------------
void vtkGeoTreeNode::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Level: " << this->Level << "\n";
os << indent << "Parent: " << this->Parent << "\n";
os << indent << "Older: " << this->Older << "\n";
os << indent << "Newer: " << this->Newer << "\n";
os << indent << "Id: " << this->Id << "\n";
os << indent << "LatitudeRange: [" << this->LatitudeRange[0] << "," << this->LatitudeRange[1] << "]\n";
os << indent << "LongitudeRange: [" << this->LongitudeRange[0] << "," << this->LongitudeRange[1] << "]\n";
os << indent << "Children:";
for ( int i = 0; i < 4; ++ i )
{
os << " " << this->Children[i];
}
os << "\n";
}
//-----------------------------------------------------------------------------
void vtkGeoTreeNode::SetChild(vtkGeoTreeNode* node, int idx)
{
if (idx < 0 || idx > 3)
{
vtkErrorMacro("Index out of range.");
return;
}
this->Children[idx] = node;
}
//-----------------------------------------------------------------------------
int vtkGeoTreeNode::GetWhichChildAreYou()
{
if (this->Level == 0)
{
vtkErrorMacro("Node does not have a parent.");
return 0;
}
unsigned long id = this->Id;
id = id >> (this->Level*2-1);
id = id & 3;
return id;
}
//-----------------------------------------------------------------------------
bool vtkGeoTreeNode::IsDescendantOf(vtkGeoTreeNode* elder)
{
if (elder == 0)
{
return false;
}
if (this->Level <= elder->GetLevel())
{
return false;
}
// All descendants will have the same first N bits in their Id.
int N = ((elder->GetLevel() * 2) + 1);
unsigned long mask = (1 << N) - 1;
if ((this->Id & mask) == elder->GetId())
{
return true;
}
return false;
}
//-----------------------------------------------------------------------------
int vtkGeoTreeNode::CreateChildren()
{
// Create the four children.
if (this->Children[0])
{ // This node is already has children.
return VTK_OK;
}
int childLevel = this->GetLevel()+1;
// Where the child index get coded in the node id.
unsigned long idBit0 = 0;
unsigned long idBit1 = 0;
if (childLevel <= 15)
{
idBit0 = 1 << (2*childLevel - 1);
idBit1 = 1 << (2*childLevel);
}
else
{
// if (childLevel > ((sizeof(unsigned long)*8) - 1) / 2)
// this particular message gets printed too much and clutters the console...
static bool msg_printed = false;
if (!msg_printed)
{
vtkWarningMacro("Level too high to be encoded in node id. (this warning only emitted once)");
msg_printed = true;
}
}
unsigned long id = this->GetId();
double longitudeRange[2];
double latitudeRange[2];
vtkGeoTreeNode* child;
// Child 0
this->GetLongitudeRange(longitudeRange);
this->GetLatitudeRange(latitudeRange);
double longitudeMid = 0.5 * (longitudeRange[0]+longitudeRange[1]);
double latitudeMid = 0.5 * (latitudeRange[0]+latitudeRange[1]);
// Child type is the same as parent.
child = this->NewInstance();
child->SetLevel(childLevel);
child->SetId(id);
longitudeRange[1] = longitudeMid;
child->SetLongitudeRange(longitudeRange);
latitudeRange[1] = latitudeMid;
child->SetLatitudeRange(latitudeRange);
this->SetChild(child, 0);
child->SetParent(this);
child->Delete();
// Child 1
this->GetLongitudeRange(longitudeRange);
this->GetLatitudeRange(latitudeRange);
// Child type is the same as parent.
child = this->NewInstance();
child->SetLevel(childLevel);
child->SetId(id | idBit0);
longitudeRange[0] = longitudeMid;
child->SetLongitudeRange(longitudeRange);
latitudeRange[1] = latitudeMid;
child->SetLatitudeRange(latitudeRange);
this->SetChild(child, 1);
child->SetParent(this);
child->Delete();
// Child 2
this->GetLongitudeRange(longitudeRange);
this->GetLatitudeRange(latitudeRange);
// Child type is the same as parent.
child = this->NewInstance();
child->SetLevel(childLevel);
child->SetId(id | idBit1);
longitudeRange[1] = longitudeMid;
child->SetLongitudeRange(longitudeRange);
latitudeRange[0] = latitudeMid;
child->SetLatitudeRange(latitudeRange);
this->SetChild(child, 2);
child->SetParent(this);
child->Delete();
// Child 3
this->GetLongitudeRange(longitudeRange);
this->GetLatitudeRange(latitudeRange);
// Child type is the same as parent.
child = this->NewInstance();
child->SetLevel(childLevel);
child->SetId(id | idBit1 | idBit0);
longitudeRange[0] = longitudeMid;
child->SetLongitudeRange(longitudeRange);
latitudeRange[0] = latitudeMid;
child->SetLatitudeRange(latitudeRange);
this->SetChild(child, 3);
child->SetParent(this);
child->Delete();
//cerr << "creating child with range "
// << child->GetLongitudeRange()[0] << ","
// << child->GetLongitudeRange()[1] << ","
// << child->GetLatitudeRange()[0] << ","
// << child->GetLatitudeRange()[1] << endl;
return VTK_OK;
}
vtkGeoTreeNode::NodeStatus vtkGeoTreeNode::GetStatus()
{
return this->Status;
}
void vtkGeoTreeNode::SetStatus(NodeStatus status)
{
this->Status = status;
}
void vtkGeoTreeNode::ShallowCopy(vtkGeoTreeNode *src)
{
this->Level = src->Level;
this->Id = src->Id;
this->LongitudeRange[0] = src->LongitudeRange[0];
this->LongitudeRange[1] = src->LongitudeRange[1];
this->LatitudeRange[0] = src->LatitudeRange[0];
this->LatitudeRange[1] = src->LatitudeRange[1];
this->Children[0] = src->Children[0];
this->Children[1] = src->Children[1];
this->Children[2] = src->Children[2];
this->Children[3] = src->Children[3];
this->Status = src->Status;
this->Parent = src->Parent;
}
void vtkGeoTreeNode::DeepCopy(vtkGeoTreeNode *src)
{
this->Level = src->Level;
this->Id = src->Id;
this->LongitudeRange[0] = src->LongitudeRange[0];
this->LongitudeRange[1] = src->LongitudeRange[1];
this->LatitudeRange[0] = src->LatitudeRange[0];
this->LatitudeRange[1] = src->LatitudeRange[1];
this->Children[0] = src->Children[0];
this->Children[1] = src->Children[1];
this->Children[2] = src->Children[2];
this->Children[3] = src->Children[3];
this->Status = src->Status;
this->Parent = src->Parent;
}
|