MINT2
Public Member Functions | Private Attributes | List of all members
HyperVolume Class Reference

#include <HyperVolume.h>

Public Member Functions

 HyperVolume (int dimension)
 
 HyperVolume (const HyperPoint &lowCorner, const HyperPoint &highCorner)
 
 HyperVolume (const HyperCuboid &cuboid)
 Constuctor that adds just one HyperCuboid to the HyperVolume. More...
 
 HyperVolume (const HyperCuboid &cuboid1, const HyperCuboid &cuboid2)
 Constuctor that adds just two HyperCuboids to the HyperVolume. More...
 
const int & getDimension () const
 
void addHyperCuboid (const HyperPoint &lowCorner, const HyperPoint &highCorner)
 
void addHyperCuboid (const HyperCuboid &hyperCuboid)
 
void push_back (const HyperCuboid &hyperCuboid)
 
const std::vector< HyperCuboid > & getHyperCuboids () const
 
const HyperCuboidgetHyperCuboid (int i) const
 
const HyperCuboidat (int i) const
 
HyperCuboidat (int i)
 
int size () const
 
HyperVolumeoperator= (const HyperVolume &other)
 
HyperVolume operator+ (const HyperVolume &other) const
 
HyperPoint getAverageCenter () const
 
void print (std::ostream &os=std::cout, int endline=1) const
 
bool inVolume (const HyperPoint &coords) const
 
bool inVolume (const HyperPointSet &coords) const
 
double volume () const
 
HyperVolume slice (const HyperPoint &coords, std::vector< int > dims) const
 
double getMin (int dimension) const
 
double getMax (int dimension) const
 
HyperCuboid getLimits () const
 
HyperVolume splitAll (int dimension, double fractionalSplitPoint)
 
 ~HyperVolume ()
 

Private Attributes

int _dimension
 
std::vector< HyperCuboid_hyperCuboids
 

Detailed Description

Definition at line 27 of file HyperVolume.h.

Constructor & Destructor Documentation

◆ HyperVolume() [1/4]

HyperVolume::HyperVolume ( int  dimension)

Simple constuctor that only takes the dimensionality of the HyperVolume.

Definition at line 6 of file HyperVolume.cpp.

6  :
7  _dimension ( dimension )
8 {
9 }
int _dimension
Definition: HyperVolume.h:31

◆ HyperVolume() [2/4]

HyperVolume::HyperVolume ( const HyperPoint lowCorner,
const HyperPoint highCorner 
)

Constuctor that adds just one HyperCuboid to the HyperVolume, defined by its upper and lower corners.

Definition at line 13 of file HyperVolume.cpp.

13  :
14  _dimension ( lowCorner.size() )
15 {
16  _hyperCuboids.push_back(HyperCuboid(lowCorner, highCorner));
17 }
int size() const
Definition: HyperPoint.h:96
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33
int _dimension
Definition: HyperVolume.h:31

◆ HyperVolume() [3/4]

HyperVolume::HyperVolume ( const HyperCuboid cuboid)

Constuctor that adds just one HyperCuboid to the HyperVolume.

Definition at line 21 of file HyperVolume.cpp.

21  :
22  _dimension ( cuboid.getDimension() )
23 {
24 
25  _hyperCuboids.push_back(cuboid);
26 
27 }
const int & getDimension() const
Definition: HyperCuboid.h:45
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33
int _dimension
Definition: HyperVolume.h:31

◆ HyperVolume() [4/4]

HyperVolume::HyperVolume ( const HyperCuboid cuboid1,
const HyperCuboid cuboid2 
)

Constuctor that adds just two HyperCuboids to the HyperVolume.

Definition at line 30 of file HyperVolume.cpp.

30  :
31  _dimension ( cuboid1.getDimension() )
32 {
33  push_back(cuboid1);
34  push_back(cuboid2);
35 }
void push_back(const HyperCuboid &hyperCuboid)
const int & getDimension() const
Definition: HyperCuboid.h:45
int _dimension
Definition: HyperVolume.h:31

◆ ~HyperVolume()

HyperVolume::~HyperVolume ( )

Destructor

Definition at line 249 of file HyperVolume.cpp.

249  {
250 }

Member Function Documentation

◆ addHyperCuboid() [1/2]

void HyperVolume::addHyperCuboid ( const HyperPoint lowCorner,
const HyperPoint highCorner 
)

add a HyperCuboid (defined by upper and lower HyperPoints) to the HyperVolume

Definition at line 91 of file HyperVolume.cpp.

91  {
92 
93  addHyperCuboid( HyperCuboid(lowCorner, highCorner) );
94 }
void addHyperCuboid(const HyperPoint &lowCorner, const HyperPoint &highCorner)
Definition: HyperVolume.cpp:91

◆ addHyperCuboid() [2/2]

void HyperVolume::addHyperCuboid ( const HyperCuboid hyperCuboid)

add a HyperCuboid to the HyperVolume

Definition at line 98 of file HyperVolume.cpp.

98  {
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 }
#define ERROR_LOG
const int & getDimension() const
Definition: HyperCuboid.h:45
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33
int _dimension
Definition: HyperVolume.h:31

◆ at() [1/2]

const HyperCuboid& HyperVolume::at ( int  i) const
inline

Definition at line 55 of file HyperVolume.h.

55 {return _hyperCuboids.at(i);}
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33

◆ at() [2/2]

HyperCuboid& HyperVolume::at ( int  i)
inline

return one of the HyperCuboids

Definition at line 56 of file HyperVolume.h.

◆ getAverageCenter()

HyperPoint HyperVolume::getAverageCenter ( ) const

Find the center of mass of the HyperVolume, assuming the mass is proportional to volume.

Definition at line 114 of file HyperVolume.cpp.

114  {
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 }
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33
int _dimension
Definition: HyperVolume.h:31

◆ getDimension()

const int& HyperVolume::getDimension ( ) const
inline

get the dimensionality of the HyperVolume

Definition at line 44 of file HyperVolume.h.

◆ getHyperCuboid()

const HyperCuboid& HyperVolume::getHyperCuboid ( int  i) const
inline

Definition at line 54 of file HyperVolume.h.

54 {return _hyperCuboids.at(i);}
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33

◆ getHyperCuboids()

const std::vector<HyperCuboid>& HyperVolume::getHyperCuboids ( ) const
inline

return the std::vector containing the HyperCuboids

Definition at line 51 of file HyperVolume.h.

◆ getLimits()

HyperCuboid HyperVolume::getLimits ( ) const

get the limits of the HyperVolume

Definition at line 184 of file HyperVolume.cpp.

184  {
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 }
double getMin(int dimension) const
const int & getDimension() const
Definition: HyperVolume.h:44
double getMax(int dimension) const

◆ getMax()

double HyperVolume::getMax ( int  dimension) const

Find the Maximum value in a given dimension.

Definition at line 166 of file HyperVolume.cpp.

166  {
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 }
#define ERROR_LOG
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33
int _dimension
Definition: HyperVolume.h:31

◆ getMin()

double HyperVolume::getMin ( int  dimension) const

Find the Minimum value in a given dimension.

Definition at line 148 of file HyperVolume.cpp.

148  {
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 }
#define ERROR_LOG
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33
int _dimension
Definition: HyperVolume.h:31

◆ inVolume() [1/2]

bool HyperVolume::inVolume ( const HyperPoint coords) const

Check to see if a HyperPoint is within the HyperVolume

Definition at line 39 of file HyperVolume.cpp.

39  {
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 }
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33

◆ inVolume() [2/2]

bool HyperVolume::inVolume ( const HyperPointSet coords) const

Check to see if all the HyperPoint in a HyperPointSet are within the HyperVolume.

Definition at line 51 of file HyperVolume.cpp.

51  {
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 }
bool inVolume(const HyperPoint &coords) const
Definition: HyperVolume.cpp:39
const HyperPoint & at(int i) const
unsigned int size() const

◆ operator+()

HyperVolume HyperVolume::operator+ ( const HyperVolume other) const

Make a HyperVolume that contains the HyperCuboids from both HyperVolumes.

Definition at line 63 of file HyperVolume.cpp.

63  {
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 }
int size() const
Definition: HyperVolume.h:60
#define ERROR_LOG
const int & getDimension() const
Definition: HyperVolume.h:44
double volume() const
const HyperCuboid & getHyperCuboid(int i) const
Definition: HyperVolume.h:54

◆ operator=()

HyperVolume & HyperVolume::operator= ( const HyperVolume other)

Overwrite this HyperVolume with another.

Definition at line 81 of file HyperVolume.cpp.

81  {
82 
84  _dimension = other._dimension;
85 
86  return *this;
87 }
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33
int _dimension
Definition: HyperVolume.h:31

◆ print()

void HyperVolume::print ( std::ostream &  os = std::cout,
int  endline = 1 
) const

Print the HyperCuboids that define the HyperVolume

Definition at line 196 of file HyperVolume.cpp.

196  {
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 }
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33

◆ push_back()

void HyperVolume::push_back ( const HyperCuboid hyperCuboid)

add a HyperCuboid to the HyperVolume

Definition at line 105 of file HyperVolume.cpp.

105  {
106  addHyperCuboid(hyperCuboid);
107 }
void addHyperCuboid(const HyperPoint &lowCorner, const HyperPoint &highCorner)
Definition: HyperVolume.cpp:91

◆ size()

int HyperVolume::size ( ) const
inline

return the number of HyperCuboids that make up the HyperVolume

Definition at line 60 of file HyperVolume.h.

◆ slice()

HyperVolume HyperVolume::slice ( const HyperPoint coords,
std::vector< int >  dims 
) const

Used for taking a slice through a HyperVolume. Pick a HyperPoint 'coords' e.g coords =(-1,5,4) then pick the dimensions you wish to slice through e.g. dims = (0). You can then imagine the plane defined by x_0 = -1, which intersects your HyperVolume. The 2D shape of this intersection is what will be returned. Further if you were to set dims = (0,1) you would get the 1D bin boundarys defined by the intersection of the line (x_0 = -1, x_1 = 5) and the HyperVolume.

Definition at line 210 of file HyperVolume.cpp.

210  {
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 }
const int & getDimension() const
Definition: HyperVolume.h:44
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33

◆ splitAll()

HyperVolume HyperVolume::splitAll ( int  dimension,
double  fractionalSplitPoint 
)

Split all of the HyperCuboids within the HyperVolume in the dimension given, and at the fractionalSplitPoint given.

Definition at line 233 of file HyperVolume.cpp.

233  {
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 }
const HyperCuboid & at(int i) const
Definition: HyperVolume.h:55
int size() const
Definition: HyperVolume.h:60
const int & getDimension() const
Definition: HyperVolume.h:44
HyperVolume split(int dimension, double fractionalSplitPoint) const

◆ volume()

double HyperVolume::volume ( ) const

Find the volume of the HyperVolume (sum of the volume of the HyperCuboids, doesn't consider overlap).

Definition at line 136 of file HyperVolume.cpp.

136  {
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 }
std::vector< HyperCuboid > _hyperCuboids
Definition: HyperVolume.h:33
double volume() const

Member Data Documentation

◆ _dimension

int HyperVolume::_dimension
private

Dimensionality of the HyperVolume

Definition at line 31 of file HyperVolume.h.

◆ _hyperCuboids

std::vector<HyperCuboid> HyperVolume::_hyperCuboids
private

vector containing HyperCuboids that define the HyperVolume

Definition at line 33 of file HyperVolume.h.


The documentation for this class was generated from the following files: