EMAN2
geometry.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman_geometry_h_
33#define eman_geometry_h_
34
35#include <string>
36using std::string;
37
38#include <vector>
39using std::vector;
40
41#include <algorithm> // for copy
42
43namespace EMAN
44{
45
48 class IntSize
49 {
50 public:
51
57 explicit IntSize(int xx=0, int yy=0, int zz=0)
58 {
59 data[0] = xx;
60 data[1] = yy;
61 data[2] = zz;
62 }
63
64
68 int get_ndim() const
69 {
70 if (data[2] > 1) {
71 return 3;
72 }
73 else if (data[1] > 1) {
74 return 2;
75 }
76 return 1;
77 }
78
83 int operator[] (int i) const
84 {
85 return data[i];
86 }
87
92 int & operator[] (int i)
93 {
94 return data[i];
95 }
96
97 private:
98 int data[3];
99 };
100
105 {
106 public:
107
113 explicit FloatSize(float xx=0, float yy=0, float zz=0)
114 {
115 data[0] = xx;
116 data[1] = yy;
117 data[2] = zz;
118 }
119
125 FloatSize(int xx, int yy=0, int zz=0)
126 {
127 data[0] = (float)xx;
128 data[1] = (float)yy;
129 data[2] = (float)zz;
130 }
131
137 FloatSize(double xx, double yy=0, double zz=0)
138 {
139 data[0] = (float)xx;
140 data[1] = (float)yy;
141 data[2] = (float)zz;
142 }
143
147 int get_ndim() const
148 {
149 if (data[2] > 1) {
150 return 3;
151 }
152 else if (data[1] > 1) {
153 return 2;
154 }
155 else if (data[0] > 1) {
156 return 1;
157 }
158 else {
159 return 0;
160 }
161 }
162
167 float operator[] (int i) const
168 {
169 return data[i];
170 }
171
176 float & operator[] (int i)
177 {
178 return data[i];
179 }
180
181 inline operator vector<float>() const {
182 vector<float> t(data,data+3);
183 return t;
184 }
185
186 private:
187 float data[3];
188 };
189
192 class IntPoint {
193 public:
197 {
198 data[0] = 0;
199 data[1] = 0;
200 data[2] = 0;
201 ndim = 0;
202 }
203
207 explicit IntPoint(int xx)
208 {
209 data[0] = xx;
210 data[1] = 0;
211 data[2] = 0;
212 ndim = 1;
213 }
214
219 IntPoint(int xx, int yy)
220 {
221 data[0] = xx;
222 data[1] = yy;
223 data[2] = 0;
224 ndim = 2;
225 }
226
232 IntPoint(int xx, int yy, int zz)
233 {
234 data[0] = xx;
235 data[1] = yy;
236 data[2] = zz;
237 ndim = 3;
238 }
239
243 int get_ndim() const
244 {
245 return ndim;
246 }
247
252 int operator[] (int i) const
253 {
254 return data[i];
255 }
256
261 int & operator[] (int i)
262 {
263 return data[i];
264 }
265
266 private:
267 int data[3];
268 int ndim;
269 };
270
271 IntPoint operator -( const IntPoint& p);
272// {
273// return IntPoint(-p[0],-p[1],-p[2]);
274// }
275
279 public:
280
284 {
285 data[0] = 0;
286 data[1] = 0;
287 data[2] = 0;
288 ndim = 0;
289 }
290
294 explicit FloatPoint(float xx)
295 {
296 data[0] = xx;
297 data[1] = 0;
298 data[2] = 0;
299 ndim = 1;
300 }
301
306 FloatPoint(float xx, float yy)
307 {
308 data[0] = xx;
309 data[1] = yy;
310 data[2] = 0;
311 ndim = 2;
312 }
313
319 FloatPoint(float xx, float yy, float zz)
320 {
321 data[0] = xx;
322 data[1] = yy;
323 data[2] = zz;
324 ndim = 3;
325 }
326
330 explicit FloatPoint(int xx)
331 {
332 data[0] = (float)xx;
333 data[1] = 0;
334 data[2] = 0;
335 ndim = 1;
336 }
337
342 FloatPoint(int xx, int yy)
343 {
344 data[0] = (float)xx;
345 data[1] = (float)yy;
346 data[2] = 0;
347 ndim = 2;
348 }
349
355 FloatPoint(int xx, int yy, int zz)
356 {
357 data[0] = (float)xx;
358 data[1] = (float)yy;
359 data[2] = (float)zz;
360 ndim = 3;
361 }
362
366 explicit FloatPoint(double xx)
367 {
368 data[0] = (float)xx;
369 data[1] = 0;
370 data[2] = 0;
371 ndim = 1;
372 }
373
378 FloatPoint(double xx, double yy)
379 {
380 data[0] = (float)xx;
381 data[1] = (float)yy;
382 data[2] = 0;
383 ndim = 2;
384 }
385
391 FloatPoint(double xx, double yy, double zz)
392 {
393 data[0] = (float)xx;
394 data[1] = (float)yy;
395 data[2] = (float)zz;
396 ndim = 3;
397 }
398
400 {
401 data[0] = fp.data[0];
402 data[1] = fp.data[1];
403 data[2] = fp.data[2];
404 ndim = fp.ndim;
405 }
406
410 int get_ndim() const
411 {
412 return ndim;
413 }
414
419 float operator[] (int i) const
420 {
421 return data[i];
422 }
423
428 float & operator[] (int i)
429 {
430 return data[i];
431 }
432
433 inline operator vector<float>() const {
434 vector<float> t(data,data+3);
435 return t;
436 }
437
438 operator IntPoint () const { return IntPoint((int)data[0],(int)data[1],(int)data[2]); }
439
440 inline FloatPoint& operator=(const vector<float>& v) {
441 copy(v.begin(),v.end(),data);
442 return *this;
443 }
444
445 private:
446 float data[3];
447 int ndim;
448 };
449
452 class Pixel {
453 public:
460 Pixel(int xx, int yy, int zz, float vv) : x(xx), y(yy), z(zz), value(vv) { }
461
462 Pixel(const Pixel & p) : x(p.x), y(p.y), z(p.z), value(p.value) {}
463
468 {
469 return IntPoint(x, y, z);
470 }
471
475 float get_value() const
476 {
477 return value;
478 }
479
480 int x;
481 int y;
482 int z;
483 float value;
484 };
485
486
487 bool operator<(const Pixel& p1, const Pixel& p2);
488 bool operator==(const Pixel& p1, const Pixel& p2);
489 bool operator!=(const Pixel& p1, const Pixel& p2);
490
491
496 class Region
497 {
498 public:
503 {
504 origin = FloatPoint ();
505 size = FloatSize();
506 }
507
510 Region(int x, int xsize)
511 {
512 origin = FloatPoint (x);
513 size = FloatSize(xsize);
514 }
515
518 Region(int x, int y, int xsize, int ysize)
519 {
520 origin = FloatPoint (x, y);
521 size = FloatSize(xsize, ysize);
522 }
523
526 Region(int x, int y, int z, int xsize, int ysize, int zsize)
527 {
528 origin = FloatPoint(x, y, z);
529 size = FloatSize(xsize, ysize, zsize);
530 }
531
534 Region(float x, float xsize)
535 {
536 origin = FloatPoint (x);
537 size = FloatSize(xsize);
538 }
539
542 Region(float x, float y, float xsize, float ysize)
543 {
544 origin = FloatPoint (x, y);
545 size = FloatSize(xsize, ysize);
546 }
547
550 Region(float x, float y, float z, float xsize, float ysize, float zsize)
551 {
552 origin = FloatPoint(x, y, z);
553 size = FloatSize(xsize, ysize, zsize);
554 }
555
558 Region(double x, double xsize)
559 {
560 origin = FloatPoint (x);
561 size = FloatSize(xsize);
562 }
563
566 Region(double x, double y, double xsize, double ysize)
567 {
568 origin = FloatPoint (x, y);
569 size = FloatSize(xsize, ysize);
570 }
571
574 Region(double x, double y, double z, double xsize, double ysize, double zsize)
575 {
576 origin = FloatPoint(x, y, z);
577 size = FloatSize(xsize, ysize, zsize);
578 }
579
582 Region(const FloatPoint &o, const FloatSize & s):origin(o), size(s)
583 {
584 }
585
586 Region(const Region & r)
587 {
588 origin = r.origin;
589 size = r.size;
590 }
591
592
594 }
595
598 bool inside_region() const;
599 bool inside_region(const FloatPoint &p) const;
600 bool inside_region(float x) const;
601 bool inside_region(float x, float y) const;
602 bool inside_region(float x, float y, float z) const;
603
604
606 float get_width() const { return size[0]; }
608 float get_height() const { return size[1]; }
610 float get_depth() const { return size[2]; }
611
613 void set_width(const float& v) { size[0] = v; }
615 void set_height(const float& v) { size[1] = v; }
617 void set_depth(const float& v) { size[2] = v; }
618
620 float x_origin() const { return origin[0]; }
622 float y_origin() const { return origin[1]; }
624 float z_origin() const { return origin[2]; }
625
627 vector<float> get_size() const { return size; }
629 vector<float> get_origin() const { return origin; }
631 void set_origin(const vector<float>& v) { origin = v; }
632
633
639 bool is_region_in_box(const FloatSize & box) const;
640
644 int get_ndim() const
645 {
646 return origin.get_ndim();
647 }
648
652 string get_string() const;
653
654 FloatPoint origin; /* region original point. */
655 FloatSize size; /* region edge sizes. */
656 };
657}
658
659#endif
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:278
float operator[](int i) const
Get the ith direction's coordinate.
Definition: geometry.h:419
FloatPoint(float xx, float yy, float zz)
Construct a 3D point.
Definition: geometry.h:319
FloatPoint(double xx, double yy)
Construct a 2D point.
Definition: geometry.h:378
FloatPoint(float xx, float yy)
Construct a 2D point.
Definition: geometry.h:306
FloatPoint(float xx)
Construct a 1D point.
Definition: geometry.h:294
FloatPoint(const FloatPoint &fp)
Definition: geometry.h:399
FloatPoint(double xx)
Construct a 1D point.
Definition: geometry.h:366
int get_ndim() const
Get the dimension of the point, 1D/2D/3D.
Definition: geometry.h:410
FloatPoint(int xx, int yy, int zz)
Construct a 3D point.
Definition: geometry.h:355
FloatPoint()
Construct a point at the origin location.
Definition: geometry.h:283
FloatPoint(int xx)
Construct a 1D point.
Definition: geometry.h:330
FloatPoint & operator=(const vector< float > &v)
Definition: geometry.h:440
float data[3]
Definition: geometry.h:446
FloatPoint(double xx, double yy, double zz)
Construct a 3D point.
Definition: geometry.h:391
FloatPoint(int xx, int yy)
Construct a 2D point.
Definition: geometry.h:342
FloatSize is used to describe a 1D, 2D or 3D rectangular size in floating numbers.
Definition: geometry.h:105
float operator[](int i) const
Get the ith direction's size.
Definition: geometry.h:167
float data[3]
Definition: geometry.h:187
FloatSize(int xx, int yy=0, int zz=0)
Construct a FloatSize object.
Definition: geometry.h:125
FloatSize(double xx, double yy=0, double zz=0)
Construct a FloatSize object.
Definition: geometry.h:137
int get_ndim() const
Get its dimension, 1D, 2D, or 3D.
Definition: geometry.h:147
FloatSize(float xx=0, float yy=0, float zz=0)
Construct a FloatSize object.
Definition: geometry.h:113
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:192
IntPoint(int xx, int yy, int zz)
Construct a 3D point.
Definition: geometry.h:232
IntPoint(int xx)
Construct a 1D point.
Definition: geometry.h:207
IntPoint()
Construct a point at the origin location.
Definition: geometry.h:196
IntPoint(int xx, int yy)
Construct a 2D point.
Definition: geometry.h:219
int data[3]
Definition: geometry.h:267
int operator[](int i) const
Get the ith direction's coordinate.
Definition: geometry.h:252
int get_ndim() const
Get the dimension of the point, 1D/2D/3D.
Definition: geometry.h:243
IntSize is used to describe a 1D, 2D or 3D rectangular size in integers.
Definition: geometry.h:49
int operator[](int i) const
Get the ith direction's size.
Definition: geometry.h:83
IntSize(int xx=0, int yy=0, int zz=0)
Construct an IntSize object.
Definition: geometry.h:57
int get_ndim() const
Get its dimension, 1D, 2D, or 3D.
Definition: geometry.h:68
int data[3]
Definition: geometry.h:98
Pixel describes a 3D pixel's coordinates and its intensity value.
Definition: geometry.h:452
Pixel(const Pixel &p)
Definition: geometry.h:462
float value
Definition: geometry.h:483
Pixel(int xx, int yy, int zz, float vv)
Construct a Pixel object given its 3D coordinates and its value.
Definition: geometry.h:460
IntPoint get_point() const
Get the pixel's coordinates as an integer point.
Definition: geometry.h:467
float get_value() const
Get the pixel's intensity value.
Definition: geometry.h:475
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Definition: geometry.h:497
float get_width() const
get the width
Definition: geometry.h:606
Region(double x, double y, double xsize, double ysize)
Construct a 2D floating-number region.
Definition: geometry.h:566
void set_width(const float &v)
set the width
Definition: geometry.h:613
Region()
Construct a null region with its origin at coordinate origins and its sizes to be 0.
Definition: geometry.h:502
vector< float > get_size() const
get the size of each dimension as a vector
Definition: geometry.h:627
float y_origin() const
get the y element of the origin
Definition: geometry.h:622
Region(double x, double y, double z, double xsize, double ysize, double zsize)
Construct a 3D floating-number region.
Definition: geometry.h:574
bool inside_region() const
to check whether a point is inside this region
Definition: geometry.cpp:64
void set_depth(const float &v)
set the depth
Definition: geometry.h:617
float x_origin() const
get the x element of the origin
Definition: geometry.h:620
int get_ndim() const
Get the region's dimension.
Definition: geometry.h:644
Region(float x, float xsize)
Construct a 1D floating-number region.
Definition: geometry.h:534
void set_origin(const vector< float > &v)
set the origin using a vector
Definition: geometry.h:631
Region(const Region &r)
Definition: geometry.h:586
Region(float x, float y, float z, float xsize, float ysize, float zsize)
Construct a 3D floating-number region.
Definition: geometry.h:550
Region(int x, int y, int z, int xsize, int ysize, int zsize)
Construct a 3D integer region.
Definition: geometry.h:526
string get_string() const
Get the description of this region in a string.
Definition: geometry.cpp:138
Region(const FloatPoint &o, const FloatSize &s)
Construct a region given's orginal point and edge sizes.
Definition: geometry.h:582
void set_height(const float &v)
set the height
Definition: geometry.h:615
vector< float > get_origin() const
get the origin as a vector
Definition: geometry.h:629
bool is_region_in_box(const FloatSize &box) const
To check whether 'this' region is inside a given box assuming the box's origins are (0,...
Definition: geometry.cpp:123
float get_depth() const
get the depth
Definition: geometry.h:610
Region(int x, int xsize)
Construct a 1D integer region.
Definition: geometry.h:510
FloatSize size
Definition: geometry.h:655
FloatPoint origin
Definition: geometry.h:654
Region(int x, int y, int xsize, int ysize)
Construct a 2D integer region.
Definition: geometry.h:518
Region(float x, float y, float xsize, float ysize)
Construct a 2D floating-number region.
Definition: geometry.h:542
float z_origin() const
get the z element of the origin
Definition: geometry.h:624
Region(double x, double xsize)
Construct a 1D floating-number region.
Definition: geometry.h:558
float get_height() const
get the height
Definition: geometry.h:608
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
E2Exception class.
Definition: aligner.h:40
bool operator!=(const EMObject &e1, const EMObject &e2)
Definition: emobject.cpp:873
EMData * operator-(const EMData &em, float n)
Definition: emdata.cpp:3194
bool operator==(const EMObject &e1, const EMObject &e2)
Definition: emobject.cpp:770
bool operator<(const Pixel &p1, const Pixel &p2)
Definition: geometry.cpp:42
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517