2
* voxelise.h - Compute 3D binning (voxelisation) of point clouds
3
* Copyright (C) 2013, D Haley
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "../filter.h"
21
#include "../../common/translation.h"
23
//!Filter that does voxelisation for various primitives (copied from CompositionFilter)
24
class VoxeliseFilter : public Filter
27
const static size_t INDEX_LENGTH = 3;
29
//Enabled ions for numerator/denom
30
std::vector<char> enabledIons[2];
32
//!Stepping mode - fixed width or fixed number of bins
35
//!number of bins (if using fixed bins)
36
unsigned long long nBins[INDEX_LENGTH];
37
//!Width of each bin (if using fixed wdith)
39
//!boundcube for the input data points
42
//!density-based or count-based
43
unsigned int normaliseType;
44
bool numeratorAll, denominatorAll;
45
//This is filter's enabled ranges
46
RangeStreamData *rsdIncoming;
50
//!Filter mode to apply to data before output
51
unsigned int filterMode;
53
//!How do we treat boundaries when applying filters
54
unsigned int filterBoundaryMode;
57
unsigned int filterBins;
59
//!Gaussian filter standard deviation
62
//!3D Point Representation size
67
//!Default output representation mode
68
unsigned int representation;
71
~VoxeliseFilter() { if(rsdIncoming) delete rsdIncoming;}
72
//!Duplicate filter contents, excluding cache.
73
Filter *cloneUncached() const;
77
//!Get approx number of bytes for caching output
78
size_t numBytesForCache(size_t nObjects) const;
80
unsigned int getType() const { return FILTER_TYPE_VOXELS;};
82
virtual void initFilter(const std::vector<const FilterStreamData *> &dataIn,
83
std::vector<const FilterStreamData *> &dataOut);
85
unsigned int refresh(const std::vector<const FilterStreamData *> &dataIn,
86
std::vector<const FilterStreamData *> &getOut,
87
ProgressData &progress, bool (*callback)(bool));
89
virtual std::string typeString() const { return std::string(TRANS("Voxelisation"));};
91
//!Get the human-readable options for the normalisation, based upon enum
92
static std::string getNormaliseTypeString(int type);
93
//!Get the human-readable options for filtering, based upon enum
94
static std::string getFilterTypeString(int type);
95
//!Get the human-readable options for the visual representation (enum)
96
static std::string getRepresentTypeString(int type);
97
//!Get the human-readable options for boundary behaviour during filtering, based upon enum
98
static std::string getFilterBoundTypeString(int type);
100
//!Get the properties of the filter, in key-value form. First vector is for each output.
101
void getProperties(FilterPropGroup &propertyList) const;
103
//!Set the properties for the nth filter. Returns true if prop set OK
104
bool setProperty(unsigned int key,
105
const std::string &value, bool &needUpdate);
106
//!Get the human readable error string associated with a particular error code during refresh(...)
107
std::string getErrString(unsigned int code) const;
109
//!Dump state to output stream, using specified format
110
bool writeState(std::ostream &f,unsigned int format,
111
unsigned int depth=0) const;
112
//!Read the state of the filter from XML file. If this
113
//fails, filter will be in an undefined state.
114
bool readState(xmlNodePtr &node, const std::string &packDir);
116
//!Get the stream types that will be dropped during ::refresh
117
unsigned int getRefreshBlockMask() const;
119
//!Get the stream types that will be generated during ::refresh
120
unsigned int getRefreshEmitMask() const;
122
//!Get the stream types that will be possibly ued during ::refresh
123
unsigned int getRefreshUseMask() const;
124
//!Set internal property value using a selection binding
125
void setPropFromBinding(const SelectionBinding &b) ;
128
//!calculate the widths of the bins in 3D
129
void calculateWidthsFromNumBins(Point3D &widths, unsigned long long *nb) const{
131
bc.getBounds(low, high);
132
for (unsigned int i = 0; i < 3; i++) {
133
widths[i] = (high[i] - low[i])/(float)nb[i];
136
//!set the number of the bins in 3D
137
void calculateNumBinsFromWidths(Point3D &widths, unsigned long long *nb) const{
139
bc.getBounds(low, high);
140
for (unsigned int i = 0; i < 3; i++) {
141
if (low[i] == high[i]) nb[i] = 1;
142
else nb[i] = (unsigned long long)((high[i] - low[i])/(float)widths[i]) + 1;