forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkExtractHierarchicalBins.cxx
116 lines (96 loc) · 3.76 KB
/
vtkExtractHierarchicalBins.cxx
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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkExtractHierarchicalBins.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See LICENSE file 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 "vtkExtractHierarchicalBins.h"
#include "vtkObjectFactory.h"
#include "vtkPointSet.h"
#include "vtkPoints.h"
#include "vtkDataArray.h"
#include "vtkHierarchicalBinningFilter.h"
#include "vtkGarbageCollector.h"
vtkStandardNewMacro(vtkExtractHierarchicalBins);
vtkCxxSetObjectMacro(vtkExtractHierarchicalBins,BinningFilter,vtkHierarchicalBinningFilter);
//----------------------------------------------------------------------------
// Helper classes to support efficient computing, and threaded execution.
namespace {
//----------------------------------------------------------------------------
// Mark points to be extracted
static void MaskPoints(vtkIdType numPts, vtkIdType *map, vtkIdType offset,
vtkIdType numFill)
{
std::fill_n(map, offset, static_cast<vtkIdType>(-1));
std::fill_n(map+offset, numFill, static_cast<vtkIdType>(1));
std::fill_n(map+offset+numFill, numPts-(offset+numFill), static_cast<vtkIdType>(-1));
}
} //anonymous namespace
//================= Begin class proper =======================================
//----------------------------------------------------------------------------
vtkExtractHierarchicalBins::vtkExtractHierarchicalBins()
{
this->Level = 0;
this->Bin = -1;
this->BinningFilter = nullptr;
}
//----------------------------------------------------------------------------
vtkExtractHierarchicalBins::~vtkExtractHierarchicalBins()
{
this->SetBinningFilter(nullptr);
}
void vtkExtractHierarchicalBins::ReportReferences(vtkGarbageCollector* collector)
{
// Report references held by this object that may be in a loop.
this->Superclass::ReportReferences(collector);
vtkGarbageCollectorReport(collector, this->BinningFilter, "Binning Filter");
}
//----------------------------------------------------------------------------
// Traverse all the input points and extract points that are contained within
// and implicit function.
int vtkExtractHierarchicalBins::FilterPoints(vtkPointSet *input)
{
// Check the input.
if ( !this->BinningFilter )
{
vtkErrorMacro(<<"vtkHierarchicalBinningFilter required\n");
return 0;
}
// Access the correct bin and determine how many points to extract.
vtkIdType offset;
vtkIdType numFill;
if ( this->Level >= 0 )
{
int level =
(this->Level < this->BinningFilter->GetNumberOfLevels() ? this->Level :
(this->BinningFilter->GetNumberOfLevels() - 1) );
offset = this->BinningFilter->GetLevelOffset(level, numFill);
}
else if ( this->Bin >= 0 )
{
int bin =
(this->Level < this->BinningFilter->GetNumberOfGlobalBins() ? this->Bin :
(this->BinningFilter->GetNumberOfGlobalBins() - 1) );
offset = this->BinningFilter->GetBinOffset(bin, numFill);
}
else //pass everything through
{
return 1;
}
vtkIdType numPts = input->GetNumberOfPoints();
MaskPoints(numPts, this->PointMap, offset, numFill);
return 1;
}
//----------------------------------------------------------------------------
void vtkExtractHierarchicalBins::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Level: " << this->Level << "\n";
os << indent << "Bin: " << this->Bin << "\n";
os << indent << "Binning Filter: "
<< static_cast<void *>(this->BinningFilter) << "\n";
}