00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #if !defined(MATHCLASSES_H)
00028 #define MATHCLASSES_H
00029
00030 #define _USE_MATH_DEFINES
00031
00032 #include <math.h>
00033
00034 #include "Object.h"
00035 #include "Collection.h"
00036 #include "ObjectCollection.h"
00037 #include "XMLParser.h"
00038
00039 namespace cmlabs {
00040
00041
00042
00043
00044
00045 class Size : public Object
00046 {
00047 public:
00048 Size();
00049 Size(JString xml);
00050 Size(XMLNode* node);
00051 Size(double width, double height, double depth = 0);
00052 virtual ~Size();
00053
00054 Object* clone() const;
00055
00056 double w;
00057 double h;
00058 double d;
00059
00060 bool equals(const Size& size) const;
00061 bool operator==(const Size &p) const;
00062
00063 double getHeight() const;
00064 double getWidth() const;
00065 double getDepth() const;
00066
00067 bool setHeight(double height);
00068 bool setWidth(double width);
00069 bool setDepth(double depth);
00070
00071 bool isNonZero() const;
00072 double getArea() const;
00073 double getDiagonalLenth() const;
00074
00075 JString print() ;
00076 JString toXML() ;
00077 bool fromXML(XMLNode* node);
00078 };
00079
00080
00081
00082
00083
00084
00085 class PointFloat;
00086
00087 class Point : public Object
00088 {
00089 public:
00090 Point();
00091 Point(JString xml);
00092 Point(XMLNode* node);
00093 Point(int px, int py, int pz=0, Size psize=Size());
00094 virtual ~Point();
00095
00096 Object* clone() const;
00097 operator PointFloat() const;
00098
00099 int x;
00100 int y;
00101 int z;
00102 Size size;
00103
00104 int operator[](int n) const;
00105 bool operator==(const Point &p) const;
00106 bool operator==(const PointFloat &p) const;
00107 Point operator-(const Point &p) const;
00108 PointFloat operator-(const PointFloat &p) const;
00109 Point operator+(const Point &p) const;
00110 PointFloat operator+(const PointFloat &p) const;
00111 Point operator*(const Point &p) const;
00112 PointFloat operator*(const PointFloat &p) const;
00113 Point operator-(double a) const;
00114 Point operator+(double a) const;
00115 Point operator*(double a) const;
00116
00117 int getX() const;
00118 int getY() const;
00119 int getZ() const;
00120 Size getSize() const;
00121
00122 bool set(int x, int y, int z=0);
00123 bool setX(int n);
00124 bool setY(int n);
00125 bool setZ(int n);
00126 bool setSize(Size s);
00127
00128 double getDistanceTo(Point &p) const;
00129 double getDistanceTo(PointFloat &p) const;
00130
00131 JString print() ;
00132 JString toXML() ;
00133 bool fromXML(XMLNode* node);
00134 };
00135
00136
00137
00138
00139
00140
00141 class PointFloat : public Object
00142 {
00143 public:
00144 PointFloat();
00145 PointFloat(JString xml);
00146 PointFloat(XMLNode* node);
00147 PointFloat(double px, double py, double pz=0, Size psize=Size());
00148 virtual ~PointFloat();
00149
00150 Object* clone() const;
00151 operator Point() const;
00152
00153 double x;
00154 double y;
00155 double z;
00156 Size size;
00157
00158 double operator[](int n) const;
00159 bool operator==(const Point &p) const;
00160 bool operator==(const PointFloat &p) const;
00161 PointFloat operator-(const Point &p) const;
00162 PointFloat operator-(const PointFloat &p) const;
00163 PointFloat operator+(const Point &p) const;
00164 PointFloat operator+(const PointFloat &p) const;
00165 PointFloat operator*(const Point &p) const;
00166 PointFloat operator*(const PointFloat &p) const;
00167 PointFloat operator-(double a) const;
00168 PointFloat operator+(double a) const;
00169 PointFloat operator*(double a) const;
00170
00171 double getX() const;
00172 double getY() const;
00173 double getZ() const;
00174 Size getSize() const;
00175
00176 bool set(double x, double y, double z=0);
00177 bool setX(double v);
00178 bool setY(double v);
00179 bool setZ(double v);
00180 bool setSize(Size s);
00181
00182 double getDistanceTo(const Point &p) const;
00183 double getDistanceTo(const PointFloat &p) const;
00184
00185 JString print() ;
00186 JString toXML() ;
00187 bool fromXML(XMLNode* node);
00188 };
00189
00190
00191
00192
00193
00194
00195 class Line : public Object
00196 {
00197 public:
00198 Line();
00199 Line(JString xml);
00200 Line(XMLNode* node);
00201 Line(PointFloat startpoint, PointFloat endpoint, double width = 0);
00202 virtual ~Line();
00203
00204 Object* clone() const;
00205
00206 PointFloat startPoint;
00207 PointFloat endPoint;
00208 double lineWidth;
00209
00210 PointFloat getStartPoint() const;
00211 PointFloat getEndPoint() const;
00212 double getLineWidth() const;
00213
00214 bool setStartPoint(PointFloat point);
00215 bool setEndPoint(PointFloat point);
00216 bool setLineWidth(double width);
00217
00218 JString print() ;
00219 JString toXML() ;
00220 bool fromXML(XMLNode* node);
00221 };
00222
00223
00224
00225
00226
00227
00228 class PolyLine : public Object
00229 {
00230 public:
00231 PolyLine();
00232 PolyLine(JString xml);
00233 PolyLine(XMLNode* node);
00234 virtual ~PolyLine();
00235
00236 Object* clone() const;
00237
00238 ObjectCollection lines;
00239
00240 int getLineCount() const;
00241 Line getLine(int pos) const;
00242 bool addLine(Line line);
00243 bool replaceLine(int pos, Line newline);
00244 bool removeLine(int pos);
00245
00246 JString print() ;
00247 JString toXML() ;
00248 bool fromXML(XMLNode* node);
00249 };
00250
00251
00252
00253
00254
00255
00256 class VectorOfInts : public Object
00257 {
00258 public:
00259 VectorOfInts();
00260 VectorOfInts(JString xml);
00261 VectorOfInts(XMLNode* node);
00262 virtual ~VectorOfInts();
00263
00264 Object* clone() const;
00265
00266 Collection coll;
00267
00268 int operator[](int n) const;
00269
00270 int get(int pos) const;
00271 bool set(int pos, int val);
00272 bool add(int val);
00273 bool remove(int pos);
00274
00275 int getSize() const;
00276
00277 JString print() ;
00278 JString toXML() ;
00279 bool fromXML(XMLNode* node);
00280 };
00281
00282
00283
00284
00285
00286
00287 class VectorOfDoubles : public Object
00288 {
00289 public:
00290 VectorOfDoubles();
00291 VectorOfDoubles(JString xml);
00292 VectorOfDoubles(XMLNode* node);
00293 virtual ~VectorOfDoubles();
00294
00295 Object* clone() const;
00296
00297 Collection coll;
00298
00299 double operator[](int n) const;
00300
00301 double get(int pos) const;
00302 bool set(int pos, double val);
00303 bool add(double val);
00304 bool remove(int pos);
00305
00306 int getSize() const;
00307
00308 JString print() ;
00309 JString toXML() ;
00310 bool fromXML(XMLNode* node);
00311 };
00312
00313
00314
00315
00316
00317
00318 class VectorOfPoints : public Object
00319 {
00320 public:
00321 VectorOfPoints();
00322 VectorOfPoints(JString xml);
00323 VectorOfPoints(XMLNode* node);
00324 virtual ~VectorOfPoints();
00325
00326 Object* clone() const;
00327
00328 ObjectCollection coll;
00329
00330 Point operator[](int n) const;
00331
00332 Point get(int pos) const;
00333 bool set(int pos, Point p);
00334 bool add(Point p);
00335 bool remove(int pos);
00336
00337 int getSize() const;
00338
00339 JString print() ;
00340 JString toXML() ;
00341 bool fromXML(XMLNode* node);
00342 };
00343
00344
00345
00346
00347
00348 class Box : public Object
00349 {
00350 public:
00351 Box();
00352 Box(JString xml);
00353 Box(XMLNode* node);
00354 Box(PointFloat upperleft, Size boxsize, double linewidth = 0);
00355 Box(PointFloat upperleft, PointFloat lowerright, double linewidth = 0);
00356 Box(double x, double y, double w, double h, double linewidth = 0);
00357 virtual ~Box();
00358
00359 Object* clone() const;
00360
00361 PointFloat upperLeft;
00362 Size size;
00363 double lineWidth;
00364 JString name;
00365 JString comment;
00366 double orientation;
00367
00368 double getUpperY() const;
00369 double getLowerY() const;
00370 double getLeftX() const;
00371 double getRightX() const;
00372 double getArea() const;
00373
00374 double getCMX() const;
00375 double getCMY() const;
00376 PointFloat getCM() const;
00377
00378 PointFloat getUpperLeft() const;
00379 PointFloat getUpperRight() const;
00380 PointFloat getLowerLeft() const;
00381 PointFloat getLowerRight() const;
00382 double getLineWidth() const;
00383 Size getSize() const;
00384 double getWidth() const;
00385 double getHeight() const;
00386
00387 bool move(double dx, double dy);
00388 bool moveTo(double x, double y);
00389 bool set(double x, double y, double w, double h, double linewidth = 0);
00390 bool setUpperLeft(const PointFloat& point);
00391 bool setSize(const Size& boxsize);
00392 bool setLineWidth(double width);
00393 bool grow(double dw, double dh);
00394
00395 bool isPointWithin(const PointFloat& point) const;
00396 bool isPointWithin(int x, int y) const;
00397 PointFloat getCentreMass() const;
00398
00399 bool hasZeroSize() const;
00400 bool equals(const Box &otherbox) const;
00401 bool equals(const Box &otherbox, double maxerror) const;
00402 Box getBoundingBox(const Box &otherbox) const;
00403 bool growToBoundingBox(const Box &otherbox);
00404 bool growToIncludePoint(const Point& point, int padX = 0, int padY = 0);
00405 Box getOverlapBox(const Box &otherbox) const;
00406 double percentOverlap(const Box &otherbox) const;
00407
00408 Box getDoubleSizeSameCenter();
00409 bool constrainTo(const Box& box);
00410 bool constrainTo(double x, double y, double w, double h);
00411 Box getConstrainedCopy(const Box& box);
00412 Box getConstrainedCopy(double x, double y, double w, double h);
00413
00414 JString print() ;
00415 JString toXML() ;
00416 bool fromXML(XMLNode* node);
00417 bool fromXML(XMLNode* node, const Box &parentBox);
00418 };
00419
00420
00421
00422
00423
00424
00425 class StatSample : public Object
00426 {
00427 public:
00428 StatSample() {}
00429 Object* clone() const { StatSample* s = new StatSample(); *s = *this; return s; }
00430
00431 bool add(double val);
00432 bool removeAll();
00433
00434 int getCount() const;
00435 double getMax() const;
00436 double getMin() const;
00437 double getMean() const;
00438 double getRobustMean() const;
00439 double getVariance() const;
00440 double getStandardDeviation() const;
00441 double getRobustStandardDeviation() const;
00442
00443 JString print() ;
00444 JString printList() ;
00445
00446 Collection values;
00447 };
00448
00449
00450
00451
00452
00453 class Vector2D : public Object
00454 {
00455 public:
00456 Vector2D();
00457 Vector2D(JString xml);
00458 Vector2D(XMLNode* node);
00459 Vector2D(double x, double y);
00460 virtual ~Vector2D();
00461
00462 Object* clone() const;
00463
00464 double x;
00465 double y;
00466
00467 double operator[](int n) const;
00468 bool operator==(const Vector2D &v) const;
00469 Vector2D operator-(const Vector2D &v) const;
00470 Vector2D operator+(const Vector2D &v) const;
00471 double operator*(const Vector2D &v) const;
00472 Vector2D operator-(double a) const;
00473 Vector2D operator+(double a) const;
00474 Vector2D operator*(double a) const;
00475 const Vector2D& operator-=(const Vector2D &v);
00476 const Vector2D& operator+=(const Vector2D &v);
00477 const Vector2D& operator-=(double a);
00478 const Vector2D& operator+=(double a);
00479 const Vector2D& operator*=(double a);
00480
00481 double getX() const;
00482 double getY() const;
00483
00484 bool set(const PointFloat& p1, const PointFloat& p2);
00485 bool set(double x1, double y1, double x2, double y2);
00486 bool set(double x, double y);
00487 bool setX(double v);
00488 bool setY(double v);
00489
00490 double length() const;
00491 double det(const Vector2D &v) const;
00492 bool isOrthogonalWith(const Vector2D &v) const;
00493 bool isParallelWith(const Vector2D &v) const;
00494 Vector2D getProjectionOn(const Vector2D &v) const;
00495 Vector2D getUnitVector() const;
00496 Vector2D getOrthogonalVector() const;
00497 double getAngle(const Vector2D &v) const;
00498 double getArea(const Vector2D &v) const;
00499
00500
00501
00502 JString print() ;
00503 JString toXML() ;
00504 bool fromXML(XMLNode* node);
00505 };
00506
00507
00508
00509
00510
00511
00512 class Vector3D : public Object
00513 {
00514 public:
00515 Vector3D();
00516 Vector3D(JString xml);
00517 Vector3D(XMLNode* node);
00518 Vector3D(double x, double y, double z);
00519 virtual ~Vector3D();
00520
00521 Object* clone() const;
00522
00523 double x;
00524 double y;
00525 double z;
00526
00527 double operator[](int n) const;
00528 bool operator==(const Vector3D &v) const;
00529 Vector3D operator-(const Vector3D &v) const;
00530 Vector3D operator+(const Vector3D &v) const;
00531 double operator*(const Vector3D &v) const;
00532 Vector3D operator-(double a) const;
00533 Vector3D operator+(double a) const;
00534 Vector3D operator*(double a) const;
00535 const Vector3D& operator-=(const Vector3D &v);
00536 const Vector3D& operator+=(const Vector3D &v);
00537 const Vector3D& operator-=(double a);
00538 const Vector3D& operator+=(double a);
00539 const Vector3D& operator*=(double a);
00540
00541 double getX() const;
00542 double getY() const;
00543 double getZ() const;
00544
00545 bool set(const PointFloat& p1, const PointFloat& p2);
00546 bool set(double x1, double y1, double z1, double x2, double y2, double z2);
00547 bool set(double x, double y, double z);
00548 bool setX(double v);
00549 bool setY(double v);
00550 bool setZ(double v);
00551
00552 double length() const;
00553 Vector3D product(const Vector3D &v) const;
00554 bool isOrthogonalWith(const Vector3D &v) const;
00555 bool isParallelWith(const Vector3D &v) const;
00556 Vector3D getProjectionOn(const Vector3D &v) const;
00557 Vector3D getUnitVector() const;
00558 double getAngle(const Vector3D &v) const;
00559 double getArea(const Vector3D &v) const;
00560
00561
00562
00563 JString print() ;
00564 JString toXML() ;
00565 bool fromXML(XMLNode* node);
00566 };
00567
00568 }
00569
00570 #endif // !defined(MATHCLASSES_H)
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582