KurusView  1.0
MCell.h
Go to the documentation of this file.
1 
9 #ifndef INC_KURUSVIEW_MCELL_H
10 #define INC_KURUSVIEW_MCELL_H
11 
12 
13 #include <iostream>
14 #include <fstream>
15 #include <vector>
16 #include <memory>
17 
18 #include "MVector.h"
19 #include "MMaterial.h"
20 
24 class MCell {
25 private:
26 
28  static unsigned long int MCellInstanceCount;
29 
30 
31 protected:
32 
42  explicit MCell(std::vector<std::shared_ptr<MVector>> vertices, std::shared_ptr<MMaterial> material, long int id);
43 
48  MCell() = delete;
49 
51  ~MCell();
52 
61  mutable double MCellVolume{};
63 
65  mutable double MCellWeight{};
66 
68  const long int MCellID;
69 
75  std::vector<std::shared_ptr<MVector>> MCellVertices;
77 
96  std::vector<unsigned int> vertexIDs;
97 
99  std::shared_ptr<MMaterial> MCellMaterial;
100 
101 
106  mutable std::shared_ptr<MVector> MCellCOG;
107 
108 
115  enum class MCellType_TypeDef {
116  NONE,
117  TETRAHEDRON,
118  HEXAHEDRON,
119  PYRAMID,
120  };
121 
122 
125 
132  virtual double calcVolume() const = 0;
133 
140  virtual double calcWeight() const = 0;
141 
150  virtual std::shared_ptr<MVector> calcCentreOfGrav() const = 0;
151 
152 
153 public:
154 
155  // TODO: do overloaded operators and friends require this visibility?
156  // ====================== OPERATORS ==========================
157 
159  //MCell& operator=( const MCell& _mcell );
160 
168  friend std::ostream &operator<<(std::ostream &os, const MCell &mCell);
169 
177  friend std::ofstream &operator<<(std::ofstream &os, const MCell &mCell);
178 
179  // ======================= ACCESSORS =========================
180 
181  // XXX: a note on const return: https://stackoverflow.com/questions/8406898/benefits-of-using-const-with-scalar-type-e-g-const-double-or-const-int
182  // XXX: a note on return by value https://en.wikipedia.org/wiki/Copy_elision#Return_value_optimization
183  // XXX: a not on returning vector: std::vector: http://www.cplusplus.com/forum/general/56177/
184 
189  double getVolume() const;
190 
195  double getWeight() const;
196 
201  double getID() const;
202 
207  static double getCount();
208 
215  std::vector<std::string> getType() const;
216 
221  std::shared_ptr<MVector> getCentreOfGrav() const;
222 
227  std::shared_ptr<MMaterial> getMaterial() const;
228 
233  std::vector<std::shared_ptr<MVector>> getVertices() const;
234 
241  const std::vector<unsigned int> &getVertexIndices();
242 
256  void setMaterial(std::shared_ptr<MMaterial> material);
257 
262  void setVertices(std::vector<std::shared_ptr<MVector>> vertices);
263 
264 };
265 
266 #endif //INC_KURUSVIEW_MCELL_H
Header file for MVector class.
friend std::ostream & operator<<(std::ostream &os, const MCell &mCell)
Unsure if useful. should perform deep (not shallow) copy to avoid accidental freeing.
Definition: MCell.cpp:116
MCellType_TypeDef
Definition: MCell.h:115
const std::vector< unsigned int > & getVertexIndices()
getVertexIndices (accessor)
Definition: MCell.cpp:144
std::shared_ptr< MVector > getCentreOfGrav() const
get MCellCOG (accessor)
Definition: MCell.cpp:35
MCell()=delete
default constructor - deleted
std::vector< std::string > getType() const
get MCellType (accessor)
Definition: MCell.cpp:68
virtual double calcWeight() const =0
calculates weight of the cell
std::shared_ptr< MMaterial > getMaterial() const
get MCellMaterial (accessor)
Definition: MCell.cpp:43
void setVertices(std::vector< std::shared_ptr< MVector >> vertices)
set MCellMaterial accesor
Definition: MCell.cpp:60
std::shared_ptr< MMaterial > MCellMaterial
holds a the material of the cell
Definition: MCell.h:99
const long int MCellID
MCellDensity - stores the density of the cell, , can not be set by accessors.
Definition: MCell.h:68
double MCellWeight
MCellWeight - stores the weight of the cell, can not be set by accessors.
Definition: MCell.h:65
MCell - Interface (abstract) class for all the cell shapes.
Definition: MCell.h:24
std::shared_ptr< MVector > MCellCOG
holds the Centre Of Gravity of the cell as a shared pointer MVector
Definition: MCell.h:106
std::vector< std::shared_ptr< MVector > > getVertices() const
get MCellVertices (accessor)
Definition: MCell.cpp:47
std::vector< unsigned int > vertexIDs
holds a list of all the vertices IDs, populated on construction
Definition: MCell.h:96
virtual double calcVolume() const =0
calculates volume of the cell
~MCell()
destructor - decrements InstanceCount
Definition: MCell.cpp:23
virtual std::shared_ptr< MVector > calcCentreOfGrav() const =0
calculates centre of gravity of the cell
double getVolume() const
get MCellVolume (accessor)
Definition: MCell.cpp:27
double getID() const
get MCellID (accessor)
Definition: MCell.cpp:39
double getWeight() const
get MCellWeight (accessor)
Definition: MCell.cpp:31
MCellType_TypeDef MCellType
MCellType - holds the type of the current cell.
Definition: MCell.h:124
static double getCount()
get MCellInstanceCount (accessor)
Definition: MCell.cpp:51
std::vector< std::shared_ptr< MVector > > MCellVertices
holds a vector of MVectors defining the vertex of the cell
Definition: MCell.h:76
void setMaterial(std::shared_ptr< MMaterial > material)
set MCellMaterial accesor
Definition: MCell.cpp:56
double MCellVolume
MCellVolume - stores the volume of the cell, can not be set by accessors.
Definition: MCell.h:62