~ubuntu-branches/ubuntu/saucy/3depict/saucy

« back to all changes in this revision

Viewing changes to src/backend/filters/voxelise.h

  • Committer: Package Import Robot
  • Author(s): D Haley
  • Date: 2013-05-17 00:52:39 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130517005239-7bl4mnhkvrhc2ba6
Tags: 0.0.13-1
Upload to unstable 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      voxelise.h - Compute 3D binning (voxelisation) of point clouds
 
3
 *      Copyright (C) 2013, D Haley 
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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/>.
 
17
*/
 
18
#ifndef VOXELISE_H
 
19
#define VOXELISE_H
 
20
#include "../filter.h"
 
21
#include "../../common/translation.h"
 
22
 
 
23
//!Filter that does voxelisation for various primitives (copied from CompositionFilter)
 
24
class VoxeliseFilter : public Filter
 
25
{
 
26
private:
 
27
        const static size_t INDEX_LENGTH = 3;
 
28
 
 
29
        //Enabled ions for numerator/denom
 
30
        std::vector<char> enabledIons[2];
 
31
 
 
32
        //!Stepping mode - fixed width or fixed number of bins
 
33
        bool fixedWidth;
 
34
        
 
35
        //!number of bins (if using fixed bins)
 
36
        unsigned long long nBins[INDEX_LENGTH];
 
37
        //!Width of each bin (if using fixed wdith)
 
38
        Point3D binWidth;
 
39
        //!boundcube for the input data points
 
40
        BoundCube bc;
 
41
        
 
42
        //!density-based or count-based 
 
43
        unsigned int normaliseType;
 
44
        bool numeratorAll, denominatorAll;
 
45
        //This is filter's enabled ranges
 
46
        RangeStreamData *rsdIncoming;
 
47
        
 
48
        float r,g,b,a;
 
49
 
 
50
        //!Filter mode to apply to data before output
 
51
        unsigned int filterMode;
 
52
 
 
53
        //!How do we treat boundaries when applying filters
 
54
        unsigned int filterBoundaryMode;
 
55
 
 
56
        //!Filter size
 
57
        unsigned int filterBins;
 
58
 
 
59
        //!Gaussian filter standard deviation
 
60
        float gaussDev;
 
61
 
 
62
        //!3D Point Representation size
 
63
        float splatSize;
 
64
 
 
65
        //!Isosurface level
 
66
        float isoLevel;
 
67
        //!Default output representation mode
 
68
        unsigned int representation;
 
69
public:
 
70
        VoxeliseFilter();
 
71
        ~VoxeliseFilter() { if(rsdIncoming) delete rsdIncoming;}
 
72
        //!Duplicate filter contents, excluding cache.
 
73
        Filter *cloneUncached() const;
 
74
 
 
75
 
 
76
        
 
77
        //!Get approx number of bytes for caching output
 
78
        size_t numBytesForCache(size_t nObjects) const;
 
79
 
 
80
        unsigned int getType() const { return FILTER_TYPE_VOXELS;};
 
81
        
 
82
        virtual void initFilter(const std::vector<const FilterStreamData *> &dataIn,
 
83
                                        std::vector<const FilterStreamData *> &dataOut);
 
84
        //!update filter
 
85
        unsigned int refresh(const std::vector<const FilterStreamData *> &dataIn,
 
86
                                                 std::vector<const FilterStreamData *> &getOut, 
 
87
                                                 ProgressData &progress, bool (*callback)(bool));
 
88
        
 
89
        virtual std::string typeString() const { return std::string(TRANS("Voxelisation"));};
 
90
 
 
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);
 
99
        
 
100
        //!Get the properties of the filter, in key-value form. First vector is for each output.
 
101
        void getProperties(FilterPropGroup &propertyList) const;
 
102
        
 
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;
 
108
        
 
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);
 
115
 
 
116
        //!Get the stream types that will be dropped during ::refresh   
 
117
        unsigned int getRefreshBlockMask() const;
 
118
 
 
119
        //!Get the stream types that will be generated during ::refresh 
 
120
        unsigned int getRefreshEmitMask() const;        
 
121
 
 
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) ;
 
126
        
 
127
        
 
128
        //!calculate the widths of the bins in 3D
 
129
        void calculateWidthsFromNumBins(Point3D &widths, unsigned long long *nb) const{
 
130
                Point3D low, high;
 
131
                bc.getBounds(low, high);
 
132
                for (unsigned int i = 0; i < 3; i++) {
 
133
                        widths[i] = (high[i] - low[i])/(float)nb[i];
 
134
                }
 
135
        }
 
136
        //!set the number of the bins in 3D
 
137
        void calculateNumBinsFromWidths(Point3D &widths, unsigned long long *nb) const{
 
138
                Point3D low, high;
 
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;
 
143
                }
 
144
        }
 
145
 
 
146
#ifdef DEBUG
 
147
        bool runUnitTests();
 
148
#endif
 
149
 
 
150
};
 
151
 
 
152
#endif
 
153