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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPointSet.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.
=========================================================================*/
#include "vtkPointSet.h"
#include "vtkCell.h"
#include "vtkCellLocator.h"
#include "vtkClosestPointStrategy.h"
#include "vtkGarbageCollector.h"
#include "vtkGenericCell.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPointLocator.h"
#include "vtkPointSetCellIterator.h"
#include "vtkStaticCellLocator.h"
#include "vtkStaticPointLocator.h"
#include "vtkSmartPointer.h"
#define VTK_CREATE(type, name) vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
vtkCxxSetObjectMacro(vtkPointSet, Points, vtkPoints);
vtkCxxSetObjectMacro(vtkPointSet, PointLocator, vtkAbstractPointLocator);
vtkCxxSetObjectMacro(vtkPointSet, CellLocator, vtkAbstractCellLocator);
//----------------------------------------------------------------------------
vtkPointSet::vtkPointSet()
{
this->Editable = false;
this->Points = nullptr;
this->PointLocator = nullptr;
this->CellLocator = nullptr;
}
//----------------------------------------------------------------------------
vtkPointSet::~vtkPointSet()
{
this->Cleanup();
if (this->PointLocator != nullptr)
{
cout << "DELETING LOCATOR: PointSet: " << this << " locator: " << this->PointLocator << "\n";
}
this->SetPointLocator(nullptr);
this->SetCellLocator(nullptr);
}
//----------------------------------------------------------------------------
// Copy the geometric structure of an input point set object.
void vtkPointSet::CopyStructure(vtkDataSet* ds)
{
vtkPointSet* ps = static_cast<vtkPointSet*>(ds);
if (this->Points != ps->Points)
{
if (this->PointLocator)
{
this->PointLocator->Initialize();
}
this->SetPoints(ps->Points);
if (this->CellLocator)
{
this->CellLocator->Initialize();
}
}
}
//----------------------------------------------------------------------------
void vtkPointSet::Cleanup()
{
if (this->Points)
{
this->Points->UnRegister(this);
this->Points = nullptr;
}
}
//----------------------------------------------------------------------------
void vtkPointSet::Initialize()
{
vtkDataSet::Initialize();
this->Cleanup();
if (this->PointLocator)
{
this->PointLocator->Initialize();
}
if (this->CellLocator)
{
this->CellLocator->Initialize();
}
}
//----------------------------------------------------------------------------
void vtkPointSet::ComputeBounds()
{
if (this->Points)
{
// only depends on tyhis->Points so only check this->Points mtime
// The generic mtime check includes Field/Cell/PointData also
// which has no impact on the bounds
if (this->Points->GetMTime() >= this->ComputeTime)
{
const double* bounds = this->Points->GetBounds();
for (int i = 0; i < 6; i++)
{
this->Bounds[i] = bounds[i];
}
this->ComputeTime.Modified();
}
}
}
//----------------------------------------------------------------------------
vtkMTimeType vtkPointSet::GetMTime()
{
vtkMTimeType dsTime = vtkDataSet::GetMTime();
if (this->Points)
{
if (this->Points->GetMTime() > dsTime)
{
dsTime = this->Points->GetMTime();
}
}
// don't get locator's mtime because its an internal object that cannot be
// modified directly from outside. Causes problems due to FindCell()
// SetPoints() method.
return dsTime;
}
//----------------------------------------------------------------------------
void vtkPointSet::BuildPointLocator()
{
if (!this->Points)
{
return;
}
if (!this->PointLocator)
{
if (this->Editable || !this->Points->GetData()->HasStandardMemoryLayout())
{
this->PointLocator = vtkPointLocator::New();
}
else
{
this->PointLocator = vtkStaticPointLocator::New();
}
this->PointLocator->SetDataSet(this);
}
else if (this->Points->GetMTime() > this->PointLocator->GetMTime())
{
cout << "Building supplied point locator\n";
this->PointLocator->SetDataSet(this);
}
this->PointLocator->BuildLocator();
}
//----------------------------------------------------------------------------
// Build the cell locator (if needed)
void vtkPointSet::BuildCellLocator()
{
if (!this->Points)
{
return;
}
if (!this->CellLocator)
{
if (this->Editable || !this->Points->GetData()->HasStandardMemoryLayout())
{
this->CellLocator = vtkCellLocator::New();
}
else
{
this->CellLocator = vtkStaticCellLocator::New();
}
this->CellLocator->Register(this);
this->CellLocator->Delete();
this->CellLocator->SetDataSet(this);
}
else if (this->Points->GetMTime() > this->CellLocator->GetMTime())
{
this->CellLocator->SetDataSet(this);
}
this->CellLocator->BuildLocator();
}
//----------------------------------------------------------------------------
vtkIdType vtkPointSet::FindPoint(double x[3])
{
if (!this->Points)
{
return -1;
}
if (!this->PointLocator)
{
this->BuildPointLocator();
}
return this->PointLocator->FindClosestPoint(x);
}
//----------------------------------------------------------------------------
// This FindCell() method is based on using a locator (either point or
// cell). In this application, point locators are typically faster to build
// and operate on than cell locator, yet do not always produce the correct
// result. The basic idea is that we find one or more close points to the
// query point, and we assume that one of the cells attached to one of the
// close points contains the query point. However this approach is not 100%
// reliable, in which case a slower cell locator must be used. The algorithm
// below (based on a point locator) uses progressively more complex (and
// expensive) approaches to identify close points near the query point (and
// connected cells). If a point locator approach proves unreliable, then a
// cell locator strategy should be used. Use subclasses of
// vtkFindCellStrategy to control the strategies.
vtkIdType vtkPointSet::FindCell(double x[3], vtkCell* cell, vtkGenericCell* gencell,
vtkIdType cellId, double tol2, int& subId, double pcoords[3], double* weights)
{
VTK_CREATE(vtkClosestPointStrategy, strategy);
strategy->Initialize(this);
return strategy->FindCell(x, cell, gencell, cellId, tol2, subId, pcoords, weights);
}
//----------------------------------------------------------------------------
vtkIdType vtkPointSet::FindCell(double x[3], vtkCell* cell, vtkIdType cellId, double tol2,
int& subId, double pcoords[3], double* weights)
{
return this->FindCell(x, cell, nullptr, cellId, tol2, subId, pcoords, weights);
}
//----------------------------------------------------------------------------
vtkCellIterator* vtkPointSet::NewCellIterator()
{
vtkPointSetCellIterator* iter = vtkPointSetCellIterator::New();
iter->SetPointSet(this);
return iter;
}
//----------------------------------------------------------------------------
void vtkPointSet::Squeeze()
{
if (this->Points)
{
this->Points->Squeeze();
}
vtkDataSet::Squeeze();
}
//----------------------------------------------------------------------------
void vtkPointSet::ReportReferences(vtkGarbageCollector* collector)
{
this->Superclass::ReportReferences(collector);
vtkGarbageCollectorReport(collector, this->PointLocator, "PointLocator");
vtkGarbageCollectorReport(collector, this->CellLocator, "CellLocator");
}
//----------------------------------------------------------------------------
unsigned long vtkPointSet::GetActualMemorySize()
{
unsigned long size = this->vtkDataSet::GetActualMemorySize();
if (this->Points)
{
size += this->Points->GetActualMemorySize();
}
return size;
}
//----------------------------------------------------------------------------
void vtkPointSet::ShallowCopy(vtkDataObject* dataObject)
{
vtkPointSet* pointSet = vtkPointSet::SafeDownCast(dataObject);
if (pointSet != nullptr)
{
this->SetEditable(pointSet->GetEditable());
this->SetPoints(pointSet->GetPoints());
}
// Do superclass
this->vtkDataSet::ShallowCopy(dataObject);
}
//----------------------------------------------------------------------------
void vtkPointSet::DeepCopy(vtkDataObject* dataObject)
{
vtkPointSet* pointSet = vtkPointSet::SafeDownCast(dataObject);
if (pointSet != nullptr)
{
this->SetEditable(pointSet->GetEditable());
vtkPoints* newPoints;
vtkPoints* pointsToCopy = pointSet->GetPoints();
if (pointsToCopy)
{
newPoints = pointsToCopy->NewInstance();
newPoints->SetDataType(pointsToCopy->GetDataType());
newPoints->DeepCopy(pointsToCopy);
}
else
{
newPoints = vtkPoints::New();
}
this->SetPoints(newPoints);
newPoints->Delete();
}
// Do superclass
this->vtkDataSet::DeepCopy(dataObject);
}
//----------------------------------------------------------------------------
vtkPointSet* vtkPointSet::GetData(vtkInformation* info)
{
return info ? vtkPointSet::SafeDownCast(info->Get(DATA_OBJECT())) : nullptr;
}
//----------------------------------------------------------------------------
vtkPointSet* vtkPointSet::GetData(vtkInformationVector* v, int i)
{
return vtkPointSet::GetData(v->GetInformationObject(i));
}
//----------------------------------------------------------------------------
void vtkPointSet::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Editable: " << (this->Editable ? "true\n" : "false\n");
os << indent << "Number Of Points: " << this->GetNumberOfPoints() << "\n";
os << indent << "Point Coordinates: " << this->Points << "\n";
os << indent << "PointLocator: " << this->PointLocator << "\n";
os << indent << "CellLocator: " << this->CellLocator << "\n";
}
//----------------------------------------------------------------------------
void vtkPointSet::Register(vtkObjectBase* o)
{
this->RegisterInternal(o, 1);
}
//----------------------------------------------------------------------------
void vtkPointSet::UnRegister(vtkObjectBase* o)
{
this->UnRegisterInternal(o, 1);
}
|