00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eman_geometry_h_
00037 #define eman_geometry_h_
00038
00039 #include <string>
00040 using std::string;
00041
00042 #include <vector>
00043 using std::vector;
00044
00045 #include <algorithm>
00046
00047 namespace EMAN
00048 {
00049
00052 class IntSize
00053 {
00054 public:
00055
00061 explicit IntSize(int xx=0, int yy=0, int zz=0)
00062 {
00063 data[0] = xx;
00064 data[1] = yy;
00065 data[2] = zz;
00066 }
00067
00068
00072 int get_ndim() const
00073 {
00074 if (data[2] > 1) {
00075 return 3;
00076 }
00077 else if (data[1] > 1) {
00078 return 2;
00079 }
00080 return 1;
00081 }
00082
00087 int operator[] (int i) const
00088 {
00089 return data[i];
00090 }
00091
00096 int & operator[] (int i)
00097 {
00098 return data[i];
00099 }
00100
00101 private:
00102 int data[3];
00103 };
00104
00108 class FloatSize
00109 {
00110 public:
00111
00117 explicit FloatSize(float xx=0, float yy=0, float zz=0)
00118 {
00119 data[0] = xx;
00120 data[1] = yy;
00121 data[2] = zz;
00122 }
00123
00129 FloatSize(int xx, int yy=0, int zz=0)
00130 {
00131 data[0] = (float)xx;
00132 data[1] = (float)yy;
00133 data[2] = (float)zz;
00134 }
00135
00141 FloatSize(double xx, double yy=0, double zz=0)
00142 {
00143 data[0] = (float)xx;
00144 data[1] = (float)yy;
00145 data[2] = (float)zz;
00146 }
00147
00151 int get_ndim() const
00152 {
00153 if (data[2] > 1) {
00154 return 3;
00155 }
00156 else if (data[1] > 1) {
00157 return 2;
00158 }
00159 else if (data[0] > 1) {
00160 return 1;
00161 }
00162 else {
00163 return 0;
00164 }
00165 }
00166
00171 float operator[] (int i) const
00172 {
00173 return data[i];
00174 }
00175
00180 float & operator[] (int i)
00181 {
00182 return data[i];
00183 }
00184
00185 inline operator vector<float>() const {
00186 vector<float> t(data,data+3);
00187 return t;
00188 }
00189
00190 private:
00191 float data[3];
00192 };
00193
00196 class IntPoint {
00197 public:
00200 IntPoint()
00201 {
00202 data[0] = 0;
00203 data[1] = 0;
00204 data[2] = 0;
00205 ndim = 0;
00206 }
00207
00211 explicit IntPoint(int xx)
00212 {
00213 data[0] = xx;
00214 data[1] = 0;
00215 data[2] = 0;
00216 ndim = 1;
00217 }
00218
00223 IntPoint(int xx, int yy)
00224 {
00225 data[0] = xx;
00226 data[1] = yy;
00227 data[2] = 0;
00228 ndim = 2;
00229 }
00230
00236 IntPoint(int xx, int yy, int zz)
00237 {
00238 data[0] = xx;
00239 data[1] = yy;
00240 data[2] = zz;
00241 ndim = 3;
00242 }
00243
00247 int get_ndim() const
00248 {
00249 return ndim;
00250 }
00251
00256 int operator[] (int i) const
00257 {
00258 return data[i];
00259 }
00260
00265 int & operator[] (int i)
00266 {
00267 return data[i];
00268 }
00269
00270 private:
00271 int data[3];
00272 int ndim;
00273 };
00274
00275 IntPoint operator -( const IntPoint& p);
00276
00277
00278
00279
00282 class FloatPoint {
00283 public:
00284
00287 FloatPoint()
00288 {
00289 data[0] = 0;
00290 data[1] = 0;
00291 data[2] = 0;
00292 ndim = 0;
00293 }
00294
00298 explicit FloatPoint(float xx)
00299 {
00300 data[0] = xx;
00301 data[1] = 0;
00302 data[2] = 0;
00303 ndim = 1;
00304 }
00305
00310 FloatPoint(float xx, float yy)
00311 {
00312 data[0] = xx;
00313 data[1] = yy;
00314 data[2] = 0;
00315 ndim = 2;
00316 }
00317
00323 FloatPoint(float xx, float yy, float zz)
00324 {
00325 data[0] = xx;
00326 data[1] = yy;
00327 data[2] = zz;
00328 ndim = 3;
00329 }
00330
00334 explicit FloatPoint(int xx)
00335 {
00336 data[0] = (float)xx;
00337 data[1] = 0;
00338 data[2] = 0;
00339 ndim = 1;
00340 }
00341
00346 FloatPoint(int xx, int yy)
00347 {
00348 data[0] = (float)xx;
00349 data[1] = (float)yy;
00350 data[2] = 0;
00351 ndim = 2;
00352 }
00353
00359 FloatPoint(int xx, int yy, int zz)
00360 {
00361 data[0] = (float)xx;
00362 data[1] = (float)yy;
00363 data[2] = (float)zz;
00364 ndim = 3;
00365 }
00366
00370 explicit FloatPoint(double xx)
00371 {
00372 data[0] = (float)xx;
00373 data[1] = 0;
00374 data[2] = 0;
00375 ndim = 1;
00376 }
00377
00382 FloatPoint(double xx, double yy)
00383 {
00384 data[0] = (float)xx;
00385 data[1] = (float)yy;
00386 data[2] = 0;
00387 ndim = 2;
00388 }
00389
00395 FloatPoint(double xx, double yy, double zz)
00396 {
00397 data[0] = (float)xx;
00398 data[1] = (float)yy;
00399 data[2] = (float)zz;
00400 ndim = 3;
00401 }
00402
00403 FloatPoint(const FloatPoint & fp)
00404 {
00405 data[0] = fp.data[0];
00406 data[1] = fp.data[1];
00407 data[2] = fp.data[2];
00408 ndim = fp.ndim;
00409 }
00410
00414 int get_ndim() const
00415 {
00416 return ndim;
00417 }
00418
00423 float operator[] (int i) const
00424 {
00425 return data[i];
00426 }
00427
00432 float & operator[] (int i)
00433 {
00434 return data[i];
00435 }
00436
00437 inline operator vector<float>() const {
00438 vector<float> t(data,data+3);
00439 return t;
00440 }
00441
00442 operator IntPoint () const { return IntPoint((int)data[0],(int)data[1],(int)data[2]); }
00443
00444 inline FloatPoint& operator=(const vector<float>& v) {
00445 copy(v.begin(),v.end(),data);
00446 return *this;
00447 }
00448
00449 private:
00450 float data[3];
00451 int ndim;
00452 };
00453
00456 class Pixel {
00457 public:
00464 Pixel(int xx, int yy, int zz, float vv) : x(xx), y(yy), z(zz), value(vv) { }
00465
00466 Pixel(const Pixel & p) : x(p.x), y(p.y), z(p.z), value(p.value) {}
00467
00471 IntPoint get_point() const
00472 {
00473 return IntPoint(x, y, z);
00474 }
00475
00479 float get_value() const
00480 {
00481 return value;
00482 }
00483
00484 int x;
00485 int y;
00486 int z;
00487 float value;
00488 };
00489
00490
00491 bool operator<(const Pixel& p1, const Pixel& p2);
00492 bool operator==(const Pixel& p1, const Pixel& p2);
00493 bool operator!=(const Pixel& p1, const Pixel& p2);
00494
00495
00500 class Region
00501 {
00502 public:
00506 Region()
00507 {
00508 origin = FloatPoint ();
00509 size = FloatSize();
00510 }
00511
00514 Region(int x, int xsize)
00515 {
00516 origin = FloatPoint (x);
00517 size = FloatSize(xsize);
00518 }
00519
00522 Region(int x, int y, int xsize, int ysize)
00523 {
00524 origin = FloatPoint (x, y);
00525 size = FloatSize(xsize, ysize);
00526 }
00527
00530 Region(int x, int y, int z, int xsize, int ysize, int zsize)
00531 {
00532 origin = FloatPoint(x, y, z);
00533 size = FloatSize(xsize, ysize, zsize);
00534 }
00535
00538 Region(float x, float xsize)
00539 {
00540 origin = FloatPoint (x);
00541 size = FloatSize(xsize);
00542 }
00543
00546 Region(float x, float y, float xsize, float ysize)
00547 {
00548 origin = FloatPoint (x, y);
00549 size = FloatSize(xsize, ysize);
00550 }
00551
00554 Region(float x, float y, float z, float xsize, float ysize, float zsize)
00555 {
00556 origin = FloatPoint(x, y, z);
00557 size = FloatSize(xsize, ysize, zsize);
00558 }
00559
00562 Region(double x, double xsize)
00563 {
00564 origin = FloatPoint (x);
00565 size = FloatSize(xsize);
00566 }
00567
00570 Region(double x, double y, double xsize, double ysize)
00571 {
00572 origin = FloatPoint (x, y);
00573 size = FloatSize(xsize, ysize);
00574 }
00575
00578 Region(double x, double y, double z, double xsize, double ysize, double zsize)
00579 {
00580 origin = FloatPoint(x, y, z);
00581 size = FloatSize(xsize, ysize, zsize);
00582 }
00583
00586 Region(const FloatPoint &o, const FloatSize & s):origin(o), size(s)
00587 {
00588 }
00589
00590 Region(const Region & r)
00591 {
00592 origin = r.origin;
00593 size = r.size;
00594 }
00595
00596
00597 ~Region() {
00598 }
00599
00602 bool inside_region() const;
00603 bool inside_region(const FloatPoint &p) const;
00604 bool inside_region(float x) const;
00605 bool inside_region(float x, float y) const;
00606 bool inside_region(float x, float y, float z) const;
00607
00608
00610 float get_width() const { return size[0]; }
00612 float get_height() const { return size[1]; }
00614 float get_depth() const { return size[2]; }
00615
00617 void set_width(const float& v) { size[0] = v; }
00619 void set_height(const float& v) { size[1] = v; }
00621 void set_depth(const float& v) { size[2] = v; }
00622
00624 float x_origin() const { return origin[0]; }
00626 float y_origin() const { return origin[1]; }
00628 float z_origin() const { return origin[2]; }
00629
00631 vector<float> get_size() const { return size; }
00633 vector<float> get_origin() const { return origin; }
00635 void set_origin(const vector<float>& v) { origin = v; }
00636
00637
00643 bool is_region_in_box(const FloatSize & box) const;
00644
00648 int get_ndim() const
00649 {
00650 return origin.get_ndim();
00651 }
00652
00656 string get_string() const;
00657
00658 FloatPoint origin;
00659 FloatSize size;
00660 };
00661 }
00662
00663 #endif