Kinetic Visualization (Visualisierung 2 - S2012)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ParticleMap.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4 http://msdn.microsoft.com/en-us/library/sa28fef8.aspx
5 */
6 #pragma warning(disable : 4290)
7 
8 #include <list>
9 #include <vector>
10 #include <string>
11 
12 class Particle;
13 
15 class ParticleMapException : public std::exception {
16 public:
17  ParticleMapException(const std::string &msg): _msg(msg) {}
18  virtual ~ParticleMapException() {}
19 
20  const char* what() const { return _msg.c_str(); }
21 private:
22  std::string _msg;
23 };
24 
25 // note: we unfortunately can't use a shared_ptr here. This might be a problem if we delete all particles and then try to
26 // use this map. We can't use shared_ptr, since particles must update their position themselves in the map.
27 // Just be a good citizen and don't use this map anymore if the particles are destroyed and noone will get hurt!
28 typedef std::vector<std::list<Particle *>> Map3D;
29 
31 
42 public:
43  ParticleMapIterator(int x, int y, int z, float sigma, int w, int h, int d, Map3D &m);
45 
49  bool next();
50 
51  Particle *get();
52  float getGaussian();
53 private:
54  int _x, _y, _z;
55  float _sigma;
56  int _w, _h, _d;
58 
59  int _posX, _posY, _posZ;
61  int _toX, _toY, _toZ;
62 
63  std::list<Particle *>::iterator _current;
64  bool _firstRun;
65 };
66 
68 class ParticleMap {
69 public:
70  ParticleMap(int width, int height, int depth);
71  ~ParticleMap();
72 
76  ParticleMapIterator iterator(int x, int y, int z, float sigma) throw (ParticleMapException);
80  void add(int x, int y, int z, Particle* p) throw (ParticleMapException);
84  void remove(int x, int y, int z, Particle *p) throw (ParticleMapException);
85 
89  bool isFree(int x, int y, int z, int n) throw (ParticleMapException);
90 private:
91  void checkBounds(int x, int y, int z, const std::string &method = "") throw (ParticleMapException);
92 
95 };