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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkArrayExtents.cxx
-------------------------------------------------------------------------
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.
-------------------------------------------------------------------------
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.
=========================================================================*/
#include "vtkArrayCoordinates.h"
#include "vtkArrayExtents.h"
#include <functional>
#include <numeric>
vtkArrayExtents::vtkArrayExtents()
{
}
vtkArrayExtents::vtkArrayExtents(const CoordinateT i) :
Storage(1)
{
this->Storage[0] = vtkArrayRange(0, i);
}
vtkArrayExtents::vtkArrayExtents(const vtkArrayRange& i) :
Storage(1)
{
this->Storage[0] = i;
}
vtkArrayExtents::vtkArrayExtents(const CoordinateT i, const CoordinateT j) :
Storage(2)
{
this->Storage[0] = vtkArrayRange(0, i);
this->Storage[1] = vtkArrayRange(0, j);
}
vtkArrayExtents::vtkArrayExtents(const vtkArrayRange& i, const vtkArrayRange& j) :
Storage(2)
{
this->Storage[0] = i;
this->Storage[1] = j;
}
vtkArrayExtents::vtkArrayExtents(const CoordinateT i, const CoordinateT j, const CoordinateT k) :
Storage(3)
{
this->Storage[0] = vtkArrayRange(0, i);
this->Storage[1] = vtkArrayRange(0, j);
this->Storage[2] = vtkArrayRange(0, k);
}
vtkArrayExtents::vtkArrayExtents(const vtkArrayRange& i, const vtkArrayRange& j, const vtkArrayRange& k) :
Storage(3)
{
this->Storage[0] = i;
this->Storage[1] = j;
this->Storage[2] = k;
}
const vtkArrayExtents vtkArrayExtents::Uniform(DimensionT n, CoordinateT m)
{
vtkArrayExtents result;
// IA64 HP-UX doesn't seem to have the vector<T> vector1(n, value)
// overload nor the assign(n, value) method, so we use the single
// argument constructor and initialize the values manually.
// result.Storage = std::vector<vtkIdType>(n, m);
result.Storage = std::vector<vtkArrayRange>(n);
for(DimensionT i = 0; i < n; i++)
{
result.Storage[i] = vtkArrayRange(0, m);
}
return result;
}
void vtkArrayExtents::Append(const vtkArrayRange& extent)
{
this->Storage.push_back(extent);
}
vtkArrayExtents::DimensionT vtkArrayExtents::GetDimensions() const
{
return this->Storage.size();
}
vtkTypeUInt64 vtkArrayExtents::GetSize() const
{
if(this->Storage.empty())
return 0;
vtkTypeUInt64 size = 1;
for(size_t i = 0; i != this->Storage.size(); ++i)
size *= this->Storage[i].GetSize();
return size;
}
void vtkArrayExtents::SetDimensions(DimensionT dimensions)
{
this->Storage.assign(dimensions, vtkArrayRange());
}
vtkArrayRange& vtkArrayExtents::operator[](DimensionT i)
{
return this->Storage[i];
}
const vtkArrayRange& vtkArrayExtents::operator[](DimensionT i) const
{
return this->Storage[i];
}
vtkArrayRange vtkArrayExtents::GetExtent(DimensionT i) const
{
return this->Storage[i];
}
void vtkArrayExtents::SetExtent(DimensionT i, const vtkArrayRange& extent)
{
this->Storage[i] = extent;
}
bool vtkArrayExtents::operator==(const vtkArrayExtents& rhs) const
{
return this->Storage == rhs.Storage;
}
bool vtkArrayExtents::operator!=(const vtkArrayExtents& rhs) const
{
return !(*this == rhs);
}
bool vtkArrayExtents::ZeroBased() const
{
for(DimensionT i = 0; i != this->GetDimensions(); ++i)
{
if(this->Storage[i].GetBegin() != 0)
return false;
}
return true;
}
bool vtkArrayExtents::SameShape(const vtkArrayExtents& rhs) const
{
if(this->GetDimensions() != rhs.GetDimensions())
return false;
for(DimensionT i = 0; i != this->GetDimensions(); ++i)
{
if(this->Storage[i].GetSize() != rhs.Storage[i].GetSize())
return false;
}
return true;
}
void vtkArrayExtents::GetLeftToRightCoordinatesN(SizeT n, vtkArrayCoordinates& coordinates) const
{
coordinates.SetDimensions(this->GetDimensions());
vtkIdType divisor = 1;
for(vtkIdType i = 0; i < this->GetDimensions(); ++i)
{
coordinates[i] = ((n / divisor) % this->Storage[i].GetSize()) + this->Storage[i].GetBegin();
divisor *= this->Storage[i].GetSize();
}
}
void vtkArrayExtents::GetRightToLeftCoordinatesN(SizeT n, vtkArrayCoordinates& coordinates) const
{
coordinates.SetDimensions(this->GetDimensions());
vtkIdType divisor = 1;
for(vtkIdType i = this->GetDimensions() - 1; i >= 0; --i)
{
coordinates[i] = ((n / divisor) % this->Storage[i].GetSize()) + this->Storage[i].GetBegin();
divisor *= this->Storage[i].GetSize();
}
}
bool vtkArrayExtents::Contains(const vtkArrayExtents& other) const
{
if(this->GetDimensions() != other.GetDimensions())
return false;
for(DimensionT i = 0; i != this->GetDimensions(); ++i)
{
if(!this->Storage[i].Contains(other[i]))
return false;
}
return true;
}
bool vtkArrayExtents::Contains(const vtkArrayCoordinates& coordinates) const
{
if(coordinates.GetDimensions() != this->GetDimensions())
return false;
for(DimensionT i = 0; i != this->GetDimensions(); ++i)
{
if(!this->Storage[i].Contains(coordinates[i]))
return false;
}
return true;
}
ostream& operator<<(ostream& stream, const vtkArrayExtents& rhs)
{
for(size_t i = 0; i != rhs.Storage.size(); ++i)
{
if(i)
stream << "x";
stream << "[" << rhs.Storage[i].GetBegin() << "," << rhs.Storage[i].GetEnd() << ")";
}
return stream;
}
|