MINT2
HyperVolume.cpp
Go to the documentation of this file.
1 #include "Mint/HyperVolume.h"
2 
6 HyperVolume::HyperVolume(int dimension) :
7  _dimension ( dimension )
8 {
9 }
10 
13 HyperVolume::HyperVolume(const HyperPoint& lowCorner, const HyperPoint& highCorner) :
14  _dimension ( lowCorner.size() )
15 {
16  _hyperCuboids.push_back(HyperCuboid(lowCorner, highCorner));
17 }
18 
19 
22  _dimension ( cuboid.getDimension() )
23 {
24 
25  _hyperCuboids.push_back(cuboid);
26 
27 }
28 
30 HyperVolume::HyperVolume(const HyperCuboid& cuboid1, const HyperCuboid& cuboid2) :
31  _dimension ( cuboid1.getDimension() )
32 {
33  push_back(cuboid1);
34  push_back(cuboid2);
35 }
36 
39 bool HyperVolume::inVolume(const HyperPoint& coords) const{
40 
41  for(unsigned int i = 0; i < _hyperCuboids.size(); i++){
42  if(_hyperCuboids.at(i).inVolume(coords)==1) return 1;
43  }
44  return 0;
45 
46 }
47 
51 bool HyperVolume::inVolume(const HyperPointSet& coords) const{
52 
53  int ncoords = coords.size();
54  for (int i = 0; i < ncoords; i++){
55  if ( inVolume(coords.at(i)) == false ) return false;
56  }
57  return true;
58 }
59 
64 
65  if (getDimension() != other.getDimension()) {
66  ERROR_LOG << "You are trying to add HyperVolumes of different dimensions.";
67  return *this;
68  }
70  for(int i = 0; i < size(); i++){
71  volume.addHyperCuboid(getHyperCuboid(i));
72  }
73  for(int i = 0; i < other.size(); i++){
74  volume.addHyperCuboid(other.getHyperCuboid(i));
75  }
76  return volume;
77 }
78 
82 
84  _dimension = other._dimension;
85 
86  return *this;
87 }
88 
91 void HyperVolume::addHyperCuboid(const HyperPoint& lowCorner,const HyperPoint& highCorner){
92 
93  addHyperCuboid( HyperCuboid(lowCorner, highCorner) );
94 }
95 
98 void HyperVolume::addHyperCuboid(const HyperCuboid& hyperCuboid){
99  if (hyperCuboid.getDimension() == _dimension) _hyperCuboids.push_back(hyperCuboid);
100  else ERROR_LOG << "The HyperCuboid you are adding to this HyperVolume has the wrong dimension";
101 }
102 
105 void HyperVolume::push_back(const HyperCuboid& hyperCuboid){
106  addHyperCuboid(hyperCuboid);
107 }
108 
109 
110 
115 
116  HyperPoint binCenter(_dimension);
117  double sumW = 0.0;
118 
119  for(unsigned int i = 0; i < _hyperCuboids.size(); i++){
120  HyperPoint ithBinCenter = _hyperCuboids.at(i).getCenter();
121  double weight = _hyperCuboids.at(i).volume();
122 
123  binCenter = binCenter + ithBinCenter*weight;
124  sumW += weight;
125  }
126 
127  binCenter = binCenter/sumW;
128 
129  return binCenter;
130 
131 }
132 
136 double HyperVolume::volume() const{
137 
138  double volume = 0.0;
139  for(unsigned int i = 0; i < _hyperCuboids.size(); i++){
140  volume += _hyperCuboids.at(i).volume();
141  }
142  return volume;
143 
144 }
145 
148 double HyperVolume::getMin(int dimension) const{
149 
150  if (dimension < _dimension) {
151  double min = _hyperCuboids.at(0).getLowCorner().at(dimension);
152  for(unsigned int i = 1; i < _hyperCuboids.size(); i++){
153  double temp = _hyperCuboids.at(i).getLowCorner().at(dimension);
154  if (min > temp) min = temp;
155  }
156  return min;
157  }
158 
159  ERROR_LOG << "You are requesting a dimensionality that does not exist in this HyperVolume";
160  return -1.0;
161 
162 }
163 
166 double HyperVolume::getMax(int dimension) const{
167 
168  if (dimension < _dimension) {
169  double max = _hyperCuboids.at(0).getHighCorner().at(dimension);
170  for(unsigned int i = 1; i < _hyperCuboids.size(); i++){
171  double temp = _hyperCuboids.at(i).getHighCorner().at(dimension);
172  if (max < temp) max = temp;
173  }
174  return max;
175  }
176 
177  ERROR_LOG << "You are requesting a dimensionality that does not exist in this HyperVolume";
178  return -1.0;
179 
180 }
181 
185  HyperCuboid limits(getDimension());
186  for (int i = 0; i < getDimension(); i++){
187  limits.getLowCorner ().at(i) = getMin(i);
188  limits.getHighCorner().at(i) = getMax(i);
189  }
190  return limits;
191 }
192 
193 
196 void HyperVolume::print(std::ostream& os, int endline) const{
197 
198  for(unsigned int i = 0; i < _hyperCuboids.size(); i++){
199  _hyperCuboids.at(i).print(os, 1);
200  }
201  if (endline == 1) os << std::endl;
202 }
203 
210 HyperVolume HyperVolume::slice(const HyperPoint& coords, std::vector<int> dims) const{
211 
212  int currentDim = getDimension();
213  int sliceDim = (int)dims.size();
214  int newDim = currentDim - sliceDim;
215 
216  HyperVolume slicedVolume(newDim);
217 
218  for(unsigned int i = 0; i < _hyperCuboids.size(); i++){
219  if(_hyperCuboids.at(i).inVolume(coords, dims)==1){
220  //std::cout << "Woohoo - I'm in volume, lets project" << std::endl;
221  HyperCuboid cube = _hyperCuboids.at(i).projectOpposite(dims);
222  //std::cout << " ---- wow, it worked" << std::endl;
223  slicedVolume.addHyperCuboid(cube);
224  }
225  }
226 
227  return slicedVolume;
228 
229 }
230 
233 HyperVolume HyperVolume::splitAll(int dimension, double fractionalSplitPoint){
234 
235  HyperVolume hyperCuboidSet( getDimension() );
236 
237  for (int i = 0; i < size(); i++){
238  at(i).split(dimension, fractionalSplitPoint, hyperCuboidSet);
239  }
240 
241  return hyperCuboidSet;
242 
243 }
244 
245 
246 
250 }
251 
252 
253 
254 
HyperVolume splitAll(int dimension, double fractionalSplitPoint)
const HyperCuboid & at(int i) const
Definition: HyperVolume.h:55
int size() const
Definition: HyperVolume.h:60
double getMin(int dimension) const
void push_back(const HyperCuboid &hyperCuboid)
#define ERROR_LOG
bool inVolume(const HyperPoint &coords) const
Definition: HyperVolume.cpp:39
HyperCuboid getLimits() const
const int & getDimension() const
Definition: HyperCuboid.h:45
HyperVolume operator+(const HyperVolume &other) const
Definition: HyperVolume.cpp:63
HyperVolume & operator=(const HyperVolume &other)
Definition: HyperVolume.cpp:81
const HyperPoint & at(int i) const
const int & getDimension() const
Definition: HyperVolume.h:44
const HyperPoint & getHighCorner() const
Definition: HyperCuboid.h:89
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33
HyperVolume(int dimension)
Definition: HyperVolume.cpp:6
double volume() const
const double & at(int i) const
Definition: HyperPoint.cpp:433
int _dimension
Definition: HyperVolume.h:31
const HyperPoint & getLowCorner() const
Definition: HyperCuboid.h:87
unsigned int size() const
void addHyperCuboid(const HyperPoint &lowCorner, const HyperPoint &highCorner)
Definition: HyperVolume.cpp:91
HyperVolume slice(const HyperPoint &coords, std::vector< int > dims) const
const HyperCuboid & getHyperCuboid(int i) const
Definition: HyperVolume.h:54
void print(std::ostream &os=std::cout, int endline=1) const
HyperPoint getAverageCenter() const
HyperVolume split(int dimension, double fractionalSplitPoint) const
double getMax(int dimension) const