1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkExtractHierarchicalBins.cxx
5
6 Copyright (c) Kitware, Inc.
7 All rights reserved.
8 See LICENSE file for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkExtractHierarchicalBins.h"
16
17 #include "vtkObjectFactory.h"
18 #include "vtkPointSet.h"
19 #include "vtkPoints.h"
20 #include "vtkDataArray.h"
21 #include "vtkHierarchicalBinningFilter.h"
22 #include "vtkGarbageCollector.h"
23
24 vtkStandardNewMacro(vtkExtractHierarchicalBins);
25 vtkCxxSetObjectMacro(vtkExtractHierarchicalBins,BinningFilter,vtkHierarchicalBinningFilter);
26
27 //----------------------------------------------------------------------------
28 // Helper classes to support efficient computing, and threaded execution.
29 namespace {
30
31 //----------------------------------------------------------------------------
32 // Mark points to be extracted
MaskPoints(vtkIdType numPts,vtkIdType * map,vtkIdType offset,vtkIdType numFill)33 static void MaskPoints(vtkIdType numPts, vtkIdType *map, vtkIdType offset,
34 vtkIdType numFill)
35 {
36 std::fill_n(map, offset, static_cast<vtkIdType>(-1));
37 std::fill_n(map+offset, numFill, static_cast<vtkIdType>(1));
38 std::fill_n(map+offset+numFill, numPts-(offset+numFill), static_cast<vtkIdType>(-1));
39 }
40
41 } //anonymous namespace
42
43 //================= Begin class proper =======================================
44 //----------------------------------------------------------------------------
vtkExtractHierarchicalBins()45 vtkExtractHierarchicalBins::vtkExtractHierarchicalBins()
46 {
47 this->Level = 0;
48 this->Bin = -1;
49 this->BinningFilter = nullptr;
50 }
51
52 //----------------------------------------------------------------------------
~vtkExtractHierarchicalBins()53 vtkExtractHierarchicalBins::~vtkExtractHierarchicalBins()
54 {
55 this->SetBinningFilter(nullptr);
56 }
57
ReportReferences(vtkGarbageCollector * collector)58 void vtkExtractHierarchicalBins::ReportReferences(vtkGarbageCollector* collector)
59 {
60 // Report references held by this object that may be in a loop.
61 this->Superclass::ReportReferences(collector);
62 vtkGarbageCollectorReport(collector, this->BinningFilter, "Binning Filter");
63 }
64
65 //----------------------------------------------------------------------------
66 // Traverse all the input points and extract points that are contained within
67 // and implicit function.
FilterPoints(vtkPointSet * input)68 int vtkExtractHierarchicalBins::FilterPoints(vtkPointSet *input)
69 {
70 // Check the input.
71 if ( !this->BinningFilter )
72 {
73 vtkErrorMacro(<<"vtkHierarchicalBinningFilter required\n");
74 return 0;
75 }
76
77 // Access the correct bin and determine how many points to extract.
78 vtkIdType offset;
79 vtkIdType numFill;
80
81 if ( this->Level >= 0 )
82 {
83 int level =
84 (this->Level < this->BinningFilter->GetNumberOfLevels() ? this->Level :
85 (this->BinningFilter->GetNumberOfLevels() - 1) );
86 offset = this->BinningFilter->GetLevelOffset(level, numFill);
87 }
88 else if ( this->Bin >= 0 )
89 {
90 int bin =
91 (this->Level < this->BinningFilter->GetNumberOfGlobalBins() ? this->Bin :
92 (this->BinningFilter->GetNumberOfGlobalBins() - 1) );
93 offset = this->BinningFilter->GetBinOffset(bin, numFill);
94 }
95 else //pass everything through
96 {
97 return 1;
98 }
99
100 vtkIdType numPts = input->GetNumberOfPoints();
101 MaskPoints(numPts, this->PointMap, offset, numFill);
102
103 return 1;
104 }
105
106 //----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)107 void vtkExtractHierarchicalBins::PrintSelf(ostream& os, vtkIndent indent)
108 {
109 this->Superclass::PrintSelf(os,indent);
110
111 os << indent << "Level: " << this->Level << "\n";
112 os << indent << "Bin: " << this->Bin << "\n";
113 os << indent << "Binning Filter: "
114 << static_cast<void *>(this->BinningFilter) << "\n";
115
116 }
117