AggregPacking
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
aggregate.hpp
Go to the documentation of this file.
1 /*
2 *
3 * AggregPacking : Generator of random aggregate packings in concrete
4 *
5 * version 0.1 (2014-08-22)
6 *
7 * Copyright (C) 2014 Jan Stransky
8 *
9 * Czech Technical University, Faculty of Civil Engineering,
10 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
11 *
12 * AggregPacking is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License as published by the
14 * Free Software Foundation, either version 3 of the License, or (at your
15 * option) any later version.
16 *
17 * AggregPacking is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
31 #ifndef AGGREGATE_HPP
32 #define AGGREGATE_HPP
33 
34 #include "math.hpp"
35 #ifdef AGGREGPACKING_BOOST_PYTHON
36  #include <boost/python.hpp>
37  namespace bp = boost::python;
38 #endif
39 
40 #ifdef AGGREGPACKING_SERIALIZATION
41 #include <string>
42 #include <iostream>
43 #include <fstream>
44 using std::string;
45 using std::istream;
46 using std::ostream;
47 using std::ifstream;
48 using std::ofstream;
49 #endif
50 
51 
52 namespace aggregpacking {
53 
54 
55 class Sphere;
56 
57 /**********************************************************************
58 * AGGREGATE
59 **********************************************************************/
61 
63 class Aggregate {
64  protected:
66  int number;
67 
70 
73 
74  public:
76 
77  Aggregate() : Aggregate(Vector3::Zero(),Quaternion::Identity()) {}
78 
80 
83  Aggregate(const Vector3& pos) : Aggregate(pos,Quaternion::Identity()) {}
84 
86 
89  Aggregate(const Quaternion& ori) : Aggregate(Vector3::Zero(),ori) {}
90 
92 
96  Aggregate(const Vector3& pos, const Quaternion& ori) : number(-1), pos(pos), ori(ori) {}
97 
99 
102  bool operator==(const Aggregate& other) const { return &other == this; }
103 
105 
108  bool operator!=(const Aggregate& other) const { return &other != this; }
109 
111 
114  virtual bool containsPoint(const Vector3& p) const = 0;
115 
117 
120  virtual bool containsSphere(const Sphere& s) const = 0;
121 
123 
127  virtual double computeDistanceFrom(const Aggregate& aggreg) const = 0;
128 
130 
132  virtual double computeMaxCoord(int axis) const = 0;
133 
135 
137  virtual double computeMinCoord(int axis) const = 0;
138 
140 
143  bool isInsideCube(double s) const;
144 
146  virtual double computeVolume() const = 0;
147 
149 
151  virtual void fromSize(double s) = 0;
152 
154  virtual double getSize() const = 0;
155 
157  virtual double getMaxSize() const = 0;
158 
159  //static bool compare(Aggregate* a1, Aggregate* a2) { return a2->getSize() < a1->getSize(); }
161  int getNumber() { return number; }
162 
164 
166  void setNumber(int n) { number = n; }
167 
169  const Vector3& getPos() const { return pos; }
170 
172  Vector3 getPos() { return pos; }
173 
175 
177  void setPos(const Vector3& p) { pos = p; }
178 
180 
184  void setPos(double x, double y, double z) {
185  pos.x() = x;
186  pos.y() = y;
187  pos.z() = z;
188  }
189 
191  const Quaternion& getOri() const { return ori; }
192 
194  Quaternion getOri() { return ori; }
195 
197 
199  void setOri(const Quaternion& q) { ori = q; ori.normalize(); }
200 
201 #ifdef AGGREGPACKING_SERIALIZATION
202  virtual const string& getClassName() = 0;
204 
206 
208  static Aggregate* Load(istream& is);
209 
211  friend ostream& operator<<(ostream& os, const Aggregate& o);
212 
213 #endif
214 
216  friend double get_x(const Aggregate& a) { return a.pos.x(); }
217 
219  friend double get_y(const Aggregate& a) { return a.pos.y(); }
220 
222  friend double get_z(const Aggregate& a) { return a.pos.z(); }
223 
225  friend double get_size(const Aggregate& a) { return a.getMaxSize(); }
226 
228  friend double get_x(const Aggregate* a) { return a->pos.x(); }
229 
231  friend double get_y(const Aggregate* a) { return a->pos.y(); }
232 
234  friend double get_z(const Aggregate* a) { return a->pos.z(); }
235 
237  friend double get_size(const Aggregate* a) { return a->getMaxSize(); }
238 };
239 
240 
241 
242 
243 /**********************************************************************
244 * SPHERE
245 **********************************************************************/
247 
251 class Sphere : public Aggregate {
252  private:
254  double radius;
255 
256  public:
258  Sphere() : Sphere(Vector3::Zero(),0.) {}
259 
261 
263  Sphere(const Vector3& p) : Sphere(p,0.) {}
264 
266 
268  Sphere(double r) : Sphere(Vector3::Zero(),r) {}
269 
271 
274  Sphere(const Vector3& p, double r) : Aggregate(p), radius(r) {}
275 
277  double getRadius() const { return radius; }
278 
280 
282  void setRadius(double r) { radius = r; }
283 
284  virtual bool containsPoint(const Vector3& p) const;
285 
286  virtual bool containsSphere(const Sphere& s) const;
287 
288  virtual double computeDistanceFrom(const Aggregate& aggreg) const;
289 
290  virtual double computeVolume() const { return 4./3.*PI*pow(radius,3); }
291 
292  virtual void fromSize(double s);
293 
294  virtual double computeMaxCoord(int axis) const { return pos[axis] + radius; };
295 
296  virtual double computeMinCoord(int axis) const { return pos[axis] - radius; };
297 
298  virtual double getSize() const { return 2*radius; }
299 
300  virtual double getMaxSize() const { return 2*radius; }
301 
303  const static string className;
304 
305 #ifdef AGGREGPACKING_SERIALIZATION
306  virtual const string& getClassName() { return Sphere::className; }
308 
310  friend ostream& operator<<(ostream& os, const Sphere& o);
311 
313  friend istream& operator>>(istream& is, Sphere& o);
314 #endif
315 };
316 
317 
318 
319 /**********************************************************************
320 * ELLIPSOID
321 **********************************************************************/
323 
335 class Ellipsoid : public Aggregate {
336  private:
338  double a;
339 
341  double b;
342 
344  double c;
345 
347 
349  static double randomAxesRatio;
350 
351  public:
353  Ellipsoid() : Ellipsoid(Vector3::Zero(),0.,0.,0.) {}
354 
356 
358  Ellipsoid(const Vector3& p) : Ellipsoid(p,0.,0.,0.) {}
359 
361 
365  Ellipsoid(double a, double b, double c) : Ellipsoid(Vector3::Zero(),a,b,c) {}
366 
368 
373  Ellipsoid(const Vector3& p, double a, double b, double c) : Aggregate(p), a(a), b(b), c(c) {}
374 
376 
378  Ellipsoid(const Sphere& s);
379 
381  double getA() { return a; }
382 
384  double getB() { return b; }
385 
387  double getC() { return c; }
388 
390 
392  void setA(double a) { this->a = a; }
393 
395 
397  void setB(double b) { this->b = b; }
398 
400 
402  void setC(double c) { this->c = c; }
403 
405  double getRandomAxesRatio() { return randomAxesRatio; }
406 
408  void setRandomAxesRatio(double v) { randomAxesRatio = v; }
409 
411 
415  static double computeRelativeDistanceFrom(const Vector3&p, const Matrix3& bT, const Vector3& pos);
416 
418 
420  double computeRelativeDistanceFrom(const Vector3& p) const;
421 
423 
427  static bool containsPoint(const Vector3&p, const Matrix3& bT, const Vector3& pos);
428 
429  virtual bool containsPoint(const Vector3& p) const;
430 
431  virtual bool containsSphere(const Sphere& s) const;
432 
433  virtual double computeDistanceFrom(const Aggregate& aggreg) const;
434 
435  virtual double computeVolume() const { return 4./3.*PI*a*b*c; }
436 
438 
440  virtual void fromSize(double s);
441 
443 
447  void computeProjectionOnCoordAxis(double& s0, double& w, int axis) const;
448 
449  virtual double computeMaxCoord(int axis) const;
450 
451  virtual double computeMinCoord(int axis) const;
452 
454  virtual double getSize() const;
455 
456  virtual double getMaxSize() const { return 2*std::max(a,std::max(b,c)); }
457 
459  Matrix3 computeMatrixB() const;
460 
462  Matrix3 computeMatrixBT() const;
463 
466 
469 
471  Matrix3 computeMatrixSigma() const;
472 
475 
478 
480  Matrix3 computeMatrixA() const;
481 
483 
487  static Vector3 computeNearestPointFrom(const Vector3& p, const Matrix3& bT, const Vector3& pos);
488 
490 
492  Vector3 computeNearestPointFrom(const Vector3& p) const;
493 
495 
499  static Vector3 computeFarthestPointFrom(const Vector3& p, const Matrix3& bT, const Vector3& pos);
500 
502 
504  Vector3 computeFarthestPointFrom(const Vector3& p) const;
505 
507 
509  double computeEstimatedDistanceFrom(const Ellipsoid& e) const;
510 
512  const static string className;
513 
514 #ifdef AGGREGPACKING_SERIALIZATION
515  virtual const string& getClassName() { return Ellipsoid::className; }
517 
519  friend ostream& operator<<(ostream& os, const Ellipsoid& o);
520 
522  friend istream& operator>>(istream& is, Ellipsoid& o);
523 #endif
524 };
525 
526 
527 
528 /**********************************************************************
529 * PYTHON
530 **********************************************************************/
531 #ifdef AGGREGPACKING_BOOST_PYTHON
532 void py_aggregate();
535 #endif
536 
537 } // namespace
538 #endif
Representation of spherical aggregate.
Definition: aggregate.hpp:251
3 component vector of real numbers.
virtual double computeVolume() const
Computes volume of receiver.
Definition: aggregate.hpp:290
Vector3 pos
Position.
Definition: aggregate.hpp:69
Ellipsoid()
Default constructor.
Definition: aggregate.hpp:353
int getNumber()
Getter for number.
Definition: aggregate.hpp:161
Quaternion - for rotation representation.
friend double get_z(const Aggregate *a)
Auxiliary function to get z coordinate from Aggregate pointer (used by Octree)
Definition: aggregate.hpp:234
virtual double computeMinCoord(int axis) const =0
Computes minimum coordinate along given axis.
3x3 matrix of real numbers
virtual void fromSize(double s)
Adjust receiver dimensions accodring to given size. Sets b=0.5*s, a=b*(1+0.5*random), c=b*(1-0.5*random)
Definition: aggregate.cpp:196
double getC()
Getter for 3rd semiaxis.
Definition: aggregate.hpp:387
friend double get_size(const Aggregate *a)
Auxiliary function to get (max) size from Aggregate pointer (used by Octree)
Definition: aggregate.hpp:237
virtual bool containsSphere(const Sphere &s) const =0
Ckecks, whether given sphere is contained by receiver.
Ellipsoid(const Vector3 &p)
Constructor from position.
Definition: aggregate.hpp:358
friend double get_z(const Aggregate &a)
Auxiliary function to get z coordinate from Aggregate reference (used by Octree)
Definition: aggregate.hpp:222
void setOri(const Quaternion &q)
Setter for orientation.
Definition: aggregate.hpp:199
virtual void fromSize(double s)=0
Adjust receiver dimensions accodring to given size.
Representation of ellipsoidal aggregate.
Definition: aggregate.hpp:335
bool operator!=(const Aggregate &other) const
Inequality operator.
Definition: aggregate.hpp:108
void setA(double a)
Setter for 1st semiaxis.
Definition: aggregate.hpp:392
static Vector3 computeFarthestPointFrom(const Vector3 &p, const Matrix3 &bT, const Vector3 &pos)
Computes farthest point of Ellipsoid to given point. Returns point on its surface. The computation is based on Monte-Carlo random sampling.
Definition: aggregate.cpp:332
void setB(double b)
Setter for 2nd semiaxis.
Definition: aggregate.hpp:397
double getRandomAxesRatio()
Getter for randomAxesRatio.
Definition: aggregate.hpp:405
void setNumber(int n)
Setter for number.
Definition: aggregate.hpp:166
virtual bool containsSphere(const Sphere &s) const
Ckecks, whether given sphere is contained by receiver.
Definition: aggregate.cpp:96
friend istream & operator>>(istream &is, Sphere &o)
Sphere from istream shift operator.
Definition: aggregate.cpp:126
Matrix3 computeMatrixA() const
Computes matrix .
Definition: aggregate.cpp:442
double c
3rd semiaxis lengths
Definition: aggregate.hpp:344
virtual double getSize() const
Returns size of receiver (what sieve opening it would normally pass)
Definition: aggregate.hpp:298
static double randomAxesRatio
Random axes ratio. Given semiaxis b, a=b*(1+randomAxesRatio*R), c=b*(1-randomAxesRatio*R), R is a random number in range (0,1)
Definition: aggregate.hpp:349
void computeProjectionOnCoordAxis(double &s0, double &w, int axis) const
Computes parameters of its projction onto coordinate axis (such that the projection is s0+-w) ...
Definition: aggregate.cpp:364
virtual double computeMaxCoord(int axis) const =0
Computes maximum coordinate along given axis.
Sphere(double r)
Constructor from radius.
Definition: aggregate.hpp:268
const Vector3 & getPos() const
Getter for position (by reference)
Definition: aggregate.hpp:169
Abstract class representing one aggregate particle.
Definition: aggregate.hpp:63
Matrix3 computeMatrixSigmaInversed() const
Computes matrix , a diagonal matrix with , where is th smiaxis length.
Definition: aggregate.cpp:404
static const string className
String representation of Sphere class name.
Definition: aggregate.hpp:303
virtual double getMaxSize() const =0
Returns maximum size of receiver.
virtual double computeMinCoord(int axis) const
Computes minimum coordinate along given axis.
Definition: aggregate.cpp:388
friend ostream & operator<<(ostream &os, const Sphere &o)
Sphere to ostream shift operator.
Definition: aggregate.cpp:120
Sphere()
Default constructor.
Definition: aggregate.hpp:258
virtual double computeMaxCoord(int axis) const
Computes maximum coordinate along given axis.
Definition: aggregate.hpp:294
Matrix3 computeMatrixBTInversed() const
Computes matrix .
Definition: aggregate.cpp:437
double getRadius() const
Getter for radius.
Definition: aggregate.hpp:277
Quaternion ori
Orientation.
Definition: aggregate.hpp:72
Ellipsoid(double a, double b, double c)
Constructor from semiaxes.
Definition: aggregate.hpp:365
virtual double computeDistanceFrom(const Aggregate &aggreg) const
Computes distance of receiver from given Aggregate.
Definition: aggregate.cpp:107
friend double get_x(const Aggregate *a)
Auxiliary function to get x coordinate from Aggregate pointer (used by Octree)
Definition: aggregate.hpp:228
friend double get_size(const Aggregate &a)
Auxiliary function to get (max) size from Aggregate reference (used by Octree)
Definition: aggregate.hpp:225
double b
2nd semiaxis lengths
Definition: aggregate.hpp:341
virtual double getMaxSize() const
Returns maximum size of receiver.
Definition: aggregate.hpp:456
File containing basic math declarations.
friend ostream & operator<<(ostream &os, const Ellipsoid &o)
Ellipsoid to ostream shift operator.
Definition: aggregate.cpp:451
Quaternion getOri()
Getter for orientation (by value)
Definition: aggregate.hpp:194
Aggregate(const Vector3 &pos, const Quaternion &ori)
Constructor from position and orientation.
Definition: aggregate.hpp:96
Aggregate(const Quaternion &ori)
Constructor from orientation.
Definition: aggregate.hpp:89
double a
1st semiaxis lengths
Definition: aggregate.hpp:338
virtual const string & getClassName()
Returns string representation of Sphere class name.
Definition: aggregate.hpp:307
static bool containsPoint(const Vector3 &p, const Matrix3 &bT, const Vector3 &pos)
Auxiliary structure to test if point lies inside given Ellipsoid.
Definition: aggregate.cpp:158
Vector3 getPos()
Getter for position (by value)
Definition: aggregate.hpp:172
Ellipsoid(const Vector3 &p, double a, double b, double c)
Constructor from position and semiaxes.
Definition: aggregate.hpp:373
virtual void fromSize(double s)
Adjust receiver dimensions accodring to given size.
Definition: aggregate.cpp:102
virtual bool containsSphere(const Sphere &s) const
Ckecks, whether given sphere is contained by receiver.
Definition: aggregate.cpp:169
virtual double computeVolume() const =0
Computes volume of receiver.
Aggregate(const Vector3 &pos)
Constructor from position.
Definition: aggregate.hpp:83
double computeEstimatedDistanceFrom(const Ellipsoid &e) const
Computes estimated distance between receiver and given Ellipsoid. Mainly used as a quick check if two...
Definition: aggregate.cpp:239
Matrix3 computeMatrixSigmaSquare() const
Computes matrix .
Definition: aggregate.cpp:413
bool isInsideCube(double s) const
Determines if receiver is entirely inside cube. The cube is in positive octant and has one corner in ...
Definition: aggregate.cpp:42
virtual double getSize() const =0
Returns size of receiver (what sieve opening it would normally pass)
virtual const string & getClassName()
Returns string representation of Ellipsoid class name.
Definition: aggregate.hpp:516
Matrix3 computeMatrixBT() const
Computes matrix .
Definition: aggregate.cpp:427
friend double get_y(const Aggregate *a)
Auxiliary function to get y coordinate from Aggregate pointer (used by Octree)
Definition: aggregate.hpp:231
bool operator==(const Aggregate &other) const
Equality operator.
Definition: aggregate.hpp:102
virtual bool containsPoint(const Vector3 &p) const
Ckecks, whether given point is contained by receiver.
Definition: aggregate.cpp:91
double getB()
Getter for 2nd semiaxis.
Definition: aggregate.hpp:384
Matrix3 computeMatrixB() const
Computes matrix .
Definition: aggregate.cpp:422
friend istream & operator>>(istream &is, Ellipsoid &o)
Ellipsoid from istream shift operator.
Definition: aggregate.cpp:457
friend ostream & operator<<(ostream &os, const Aggregate &o)
Aggregate to ostream shift operator.
Definition: aggregate.cpp:68
Sphere(const Vector3 &p)
Constructor from position.
Definition: aggregate.hpp:263
static const string className
String representation of Ellipsoid class name.
Definition: aggregate.hpp:512
virtual double computeDistanceFrom(const Aggregate &aggreg) const =0
Computes distance of receiver from given Aggregate.
virtual double computeMinCoord(int axis) const
Computes minimum coordinate along given axis.
Definition: aggregate.hpp:296
void setRadius(double r)
Setter for radius.
Definition: aggregate.hpp:282
virtual double computeMaxCoord(int axis) const
Computes maximum coordinate along given axis.
Definition: aggregate.cpp:381
virtual double getSize() const
Returns size of receiver (what sieve opening it would normally pass), i.e. the middle value from a...
Definition: aggregate.cpp:356
Sphere(const Vector3 &p, double r)
Constructor from position and radius.
Definition: aggregate.hpp:274
static Vector3 computeNearestPointFrom(const Vector3 &p, const Matrix3 &bT, const Vector3 &pos)
Computes nearest point of Ellipsoid to given point. Returns given point if it lies inside the Ellipso...
Definition: aggregate.cpp:275
double radius
radius
Definition: aggregate.hpp:254
int number
Number.
Definition: aggregate.hpp:66
static double computeRelativeDistanceFrom(const Vector3 &p, const Matrix3 &bT, const Vector3 &pos)
Computes relative distance between gvien point and given Ellipsoid. Relative distance means in direct...
Definition: aggregate.cpp:147
virtual bool containsPoint(const Vector3 &p) const =0
Ckecks, whether given point is contained by receiver.
virtual const string & getClassName()=0
Returns string representation of class name.
void setRandomAxesRatio(double v)
Setter for randomAxesRatio.
Definition: aggregate.hpp:408
void setPos(const Vector3 &p)
Setter for position.
Definition: aggregate.hpp:177
friend double get_x(const Aggregate &a)
Auxiliary function to get x coordinate from Aggregate reference (used by Octree)
Definition: aggregate.hpp:216
virtual double computeDistanceFrom(const Aggregate &aggreg) const
Computes distance of receiver from given Aggregate.
Definition: aggregate.cpp:207
Matrix3 computeMatrixBInversed() const
Computes matrix .
Definition: aggregate.cpp:432
void setC(double c)
Setter for 3rd semiaxis.
Definition: aggregate.hpp:402
Aggregate()
Default constructor.
Definition: aggregate.hpp:77
const Quaternion & getOri() const
Getter for orientation (by reference)
Definition: aggregate.hpp:191
double getA()
Getter for 1st semiaxis.
Definition: aggregate.hpp:381
virtual double getMaxSize() const
Returns maximum size of receiver.
Definition: aggregate.hpp:300
const double PI
PI.
Definition: math.hpp:51
static Aggregate * Load(istream &is)
Create and return a new aggregate from given istream.
Definition: aggregate.cpp:51
void setPos(double x, double y, double z)
Setter for position (from individual components)
Definition: aggregate.hpp:184
Matrix3 computeMatrixSigma() const
Computes matrix , a diagonal matrix with , where is th smiaxis length.
Definition: aggregate.cpp:395
virtual double computeVolume() const
Computes volume of receiver.
Definition: aggregate.hpp:435
friend double get_y(const Aggregate &a)
Auxiliary function to get y coordinate from Aggregate reference (used by Octree)
Definition: aggregate.hpp:219