EMAN2
Public Member Functions | Public Attributes | List of all members
EMAN::Region Class Reference

Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes. More...

#include <geometry.h>

Collaboration diagram for EMAN::Region:
Collaboration graph
[legend]

Public Member Functions

 Region ()
 Construct a null region with its origin at coordinate origins and its sizes to be 0. More...
 
 Region (int x, int xsize)
 Construct a 1D integer region. More...
 
 Region (int x, int y, int xsize, int ysize)
 Construct a 2D integer region. More...
 
 Region (int x, int y, int z, int xsize, int ysize, int zsize)
 Construct a 3D integer region. More...
 
 Region (float x, float xsize)
 Construct a 1D floating-number region. More...
 
 Region (float x, float y, float xsize, float ysize)
 Construct a 2D floating-number region. More...
 
 Region (float x, float y, float z, float xsize, float ysize, float zsize)
 Construct a 3D floating-number region. More...
 
 Region (double x, double xsize)
 Construct a 1D floating-number region. More...
 
 Region (double x, double y, double xsize, double ysize)
 Construct a 2D floating-number region. More...
 
 Region (double x, double y, double z, double xsize, double ysize, double zsize)
 Construct a 3D floating-number region. More...
 
 Region (const FloatPoint &o, const FloatSize &s)
 Construct a region given's orginal point and edge sizes. More...
 
 Region (const Region &r)
 
 ~Region ()
 
bool inside_region () const
 to check whether a point is inside this region More...
 
bool inside_region (const FloatPoint &p) const
 
bool inside_region (float x) const
 
bool inside_region (float x, float y) const
 
bool inside_region (float x, float y, float z) const
 
float get_width () const
 get the width More...
 
float get_height () const
 get the height More...
 
float get_depth () const
 get the depth More...
 
void set_width (const float &v)
 set the width More...
 
void set_height (const float &v)
 set the height More...
 
void set_depth (const float &v)
 set the depth More...
 
float x_origin () const
 get the x element of the origin More...
 
float y_origin () const
 get the y element of the origin More...
 
float z_origin () const
 get the z element of the origin More...
 
vector< float > get_size () const
 get the size of each dimension as a vector More...
 
vector< float > get_origin () const
 get the origin as a vector More...
 
void set_origin (const vector< float > &v)
 set the origin using a vector More...
 
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,0,0). More...
 
int get_ndim () const
 Get the region's dimension. More...
 
string get_string () const
 Get the description of this region in a string. More...
 

Public Attributes

FloatPoint origin
 
FloatSize size
 

Detailed Description

Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes.

The coordinates and edge sizes can be integer or floating numbers.

Definition at line 496 of file geometry.h.

Constructor & Destructor Documentation

◆ Region() [1/12]

EMAN::Region::Region ( )
inline

Construct a null region with its origin at coordinate origins and its sizes to be 0.

Definition at line 502 of file geometry.h.

503 {
504 origin = FloatPoint ();
505 size = FloatSize();
506 }
FloatSize size
Definition: geometry.h:655
FloatPoint origin
Definition: geometry.h:654

References origin, and size.

◆ Region() [2/12]

EMAN::Region::Region ( int  x,
int  xsize 
)
inline

Construct a 1D integer region.

Definition at line 510 of file geometry.h.

511 {
512 origin = FloatPoint (x);
513 size = FloatSize(xsize);
514 }
#define x(i)
Definition: projector.cpp:1517

References origin, size, and x.

◆ Region() [3/12]

EMAN::Region::Region ( int  x,
int  y,
int  xsize,
int  ysize 
)
inline

Construct a 2D integer region.

Definition at line 518 of file geometry.h.

519 {
520 origin = FloatPoint (x, y);
521 size = FloatSize(xsize, ysize);
522 }
#define y(i, j)
Definition: projector.cpp:1516

References origin, size, x, and y.

◆ Region() [4/12]

EMAN::Region::Region ( int  x,
int  y,
int  z,
int  xsize,
int  ysize,
int  zsize 
)
inline

Construct a 3D integer region.

Definition at line 526 of file geometry.h.

527 {
528 origin = FloatPoint(x, y, z);
529 size = FloatSize(xsize, ysize, zsize);
530 }

References origin, size, x, and y.

◆ Region() [5/12]

EMAN::Region::Region ( float  x,
float  xsize 
)
inline

Construct a 1D floating-number region.

Definition at line 534 of file geometry.h.

535 {
536 origin = FloatPoint (x);
537 size = FloatSize(xsize);
538 }

References origin, size, and x.

◆ Region() [6/12]

EMAN::Region::Region ( float  x,
float  y,
float  xsize,
float  ysize 
)
inline

Construct a 2D floating-number region.

Definition at line 542 of file geometry.h.

543 {
544 origin = FloatPoint (x, y);
545 size = FloatSize(xsize, ysize);
546 }

References origin, size, x, and y.

◆ Region() [7/12]

EMAN::Region::Region ( float  x,
float  y,
float  z,
float  xsize,
float  ysize,
float  zsize 
)
inline

Construct a 3D floating-number region.

Definition at line 550 of file geometry.h.

551 {
552 origin = FloatPoint(x, y, z);
553 size = FloatSize(xsize, ysize, zsize);
554 }

References origin, size, x, and y.

◆ Region() [8/12]

EMAN::Region::Region ( double  x,
double  xsize 
)
inline

Construct a 1D floating-number region.

Definition at line 558 of file geometry.h.

559 {
560 origin = FloatPoint (x);
561 size = FloatSize(xsize);
562 }

References origin, size, and x.

◆ Region() [9/12]

EMAN::Region::Region ( double  x,
double  y,
double  xsize,
double  ysize 
)
inline

Construct a 2D floating-number region.

Definition at line 566 of file geometry.h.

567 {
568 origin = FloatPoint (x, y);
569 size = FloatSize(xsize, ysize);
570 }

References origin, size, x, and y.

◆ Region() [10/12]

EMAN::Region::Region ( double  x,
double  y,
double  z,
double  xsize,
double  ysize,
double  zsize 
)
inline

Construct a 3D floating-number region.

Definition at line 574 of file geometry.h.

575 {
576 origin = FloatPoint(x, y, z);
577 size = FloatSize(xsize, ysize, zsize);
578 }

References origin, size, x, and y.

◆ Region() [11/12]

EMAN::Region::Region ( const FloatPoint o,
const FloatSize s 
)
inline

Construct a region given's orginal point and edge sizes.

Definition at line 582 of file geometry.h.

582 :origin(o), size(s)
583 {
584 }

◆ Region() [12/12]

EMAN::Region::Region ( const Region r)
inline

Definition at line 586 of file geometry.h.

587 {
588 origin = r.origin;
589 size = r.size;
590 }

References origin, and size.

◆ ~Region()

EMAN::Region::~Region ( )
inline

Definition at line 593 of file geometry.h.

593 {
594 }

Member Function Documentation

◆ get_depth()

float EMAN::Region::get_depth ( ) const
inline

get the depth

Definition at line 610 of file geometry.h.

610{ return size[2]; }

References size.

Referenced by EMAN::EMData::extract_box(), and EMAN::EMUtil::process_region_io().

◆ get_height()

float EMAN::Region::get_height ( ) const
inline

get the height

Definition at line 608 of file geometry.h.

608{ return size[1]; }

References size.

Referenced by EMAN::EMData::extract_box(), and EMAN::EMUtil::process_region_io().

◆ get_ndim()

int EMAN::Region::get_ndim ( ) const
inline

Get the region's dimension.

Returns
The region's dimension.

Definition at line 644 of file geometry.h.

645 {
646 return origin.get_ndim();
647 }
int get_ndim() const
Get the dimension of the point, 1D/2D/3D.
Definition: geometry.h:410

References EMAN::FloatPoint::get_ndim(), and origin.

Referenced by EMAN::ImageIO::check_region(), EMAN::EMUtil::get_region_dims(), EMAN::EMUtil::get_region_origins(), EMAN::EMUtil::process_region_io(), and EMAN::MrcIO::read_mrc_header().

◆ get_origin()

vector< float > EMAN::Region::get_origin ( ) const
inline

get the origin as a vector

Definition at line 629 of file geometry.h.

629{ return origin; }

References origin.

Referenced by EMAN::EMUtil::process_region_io().

◆ get_size()

vector< float > EMAN::Region::get_size ( ) const
inline

get the size of each dimension as a vector

Definition at line 627 of file geometry.h.

627{ return size; }

References size.

Referenced by EMAN::EMUtil::get_region_dims(), and EMAN::EMUtil::process_region_io().

◆ get_string()

string Region::get_string ( ) const

Get the description of this region in a string.

Returns
the description of this region in a string.

Definition at line 138 of file geometry.cpp.

139{
140 char str[1028];
141 int ndim = origin.get_ndim();
142
143 if (ndim == 2) {
144 sprintf(str, "(%2.1f, %2.1f; %2.1f, %2.1f)",
145 origin[0], origin[1], size[0], size[1]);
146 }
147 else if (ndim == 3) {
148 sprintf(str, "(%2.1f, %2.1f, %2.1f; %2.1f, %2.1f, %2.1f)",
149 origin[0], origin[1], origin[2], size[0], size[1], size[2]);
150 }
151
152 return string(str);
153}

References EMAN::FloatPoint::get_ndim(), origin, and size.

Referenced by EMAN::ImageIO::check_region().

◆ get_width()

float EMAN::Region::get_width ( ) const
inline

get the width

Definition at line 606 of file geometry.h.

606{ return size[0]; }

References size.

Referenced by EMAN::EMData::extract_box(), and EMAN::EMUtil::process_region_io().

◆ inside_region() [1/5]

bool Region::inside_region ( ) const

to check whether a point is inside this region

Definition at line 64 of file geometry.cpp.

65{
66 if (size[0] >= 0 && size[1] >= 0 && size[2] >= 0) {
67 return true;
68 }
69
70 return false;
71}

References size.

Referenced by inside_region().

◆ inside_region() [2/5]

bool Region::inside_region ( const FloatPoint p) const

Definition at line 73 of file geometry.cpp.

74{
75 if (p.get_ndim() == 1) {
76 return inside_region(p[0]);
77 }
78
79
80 if (p.get_ndim() == 2) {
81 return inside_region(p[0], p[1]);
82 }
83
84 return inside_region(p[0], p[1], p[2]);
85}
bool inside_region() const
to check whether a point is inside this region
Definition: geometry.cpp:64

References EMAN::FloatPoint::get_ndim(), and inside_region().

◆ inside_region() [3/5]

bool Region::inside_region ( float  x) const

Definition at line 87 of file geometry.cpp.

88{
89 if (size[0] >= 0 && origin[0] <= x &&
90 (origin[0] + size[0]) > x ) {
91 return true;
92 }
93 return false;
94}

References origin, size, and x.

◆ inside_region() [4/5]

bool Region::inside_region ( float  x,
float  y 
) const

Definition at line 97 of file geometry.cpp.

98{
99 if (size[0] >= 0 && size[1] >= 0 &&
100 origin[0] <= x && origin[1] <= y &&
101 (origin[0] + size[0]) > x && (origin[1] + size[1]) > y) {
102 return true;
103 }
104 return false;
105}

References origin, size, x, and y.

◆ inside_region() [5/5]

bool Region::inside_region ( float  x,
float  y,
float  z 
) const

Definition at line 111 of file geometry.cpp.

112{
113 if (size[0] >= 0 && size[1] >= 0 && size[2] >= 0 &&
114 origin[0] <= x && origin[1] <= y && origin[2] <= z &&
115 (origin[0] + size[0]) > x &&
116 (origin[1] + size[1]) > y && (origin[2] + size[2]) > z) {
117 return true;
118 }
119 return false;
120}

References origin, size, x, and y.

◆ is_region_in_box()

bool Region::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,0,0).

Parameters
boxThe nD rectangular box.
Returns
True if 'this' region is inside the box; Otherwise, false.

Definition at line 123 of file geometry.cpp.

124{
125 if (size[0] >= 0 && size[1] >= 0 && size[2] >= 0 &&
126 origin[0] >= 0 && origin[1] >= 0 && origin[2] >= 0 &&
127 (origin[0] + size[0]) <= box[0] &&
128 (origin[1] + size[1]) <= box[1] &&
129 (origin[2] + size[2]) <= box[2]) {
130 return true;
131 }
132
133 return false;
134}

References origin, and size.

Referenced by EMAN::ImageIO::check_region().

◆ set_depth()

void EMAN::Region::set_depth ( const float &  v)
inline

set the depth

Definition at line 617 of file geometry.h.

617{ size[2] = v; }

References size.

◆ set_height()

void EMAN::Region::set_height ( const float &  v)
inline

set the height

Definition at line 615 of file geometry.h.

615{ size[1] = v; }

References size.

◆ set_origin()

void EMAN::Region::set_origin ( const vector< float > &  v)
inline

set the origin using a vector

Definition at line 631 of file geometry.h.

631{ origin = v; }

References origin.

◆ set_width()

void EMAN::Region::set_width ( const float &  v)
inline

set the width

Definition at line 613 of file geometry.h.

613{ size[0] = v; }

References size.

◆ x_origin()

float EMAN::Region::x_origin ( ) const
inline

get the x element of the origin

Definition at line 620 of file geometry.h.

620{ return origin[0]; }

References origin.

Referenced by EMAN::EMData::extract_box(), and EMAN::EMUtil::process_region_io().

◆ y_origin()

float EMAN::Region::y_origin ( ) const
inline

get the y element of the origin

Definition at line 622 of file geometry.h.

622{ return origin[1]; }

References origin.

Referenced by EMAN::EMData::extract_box(), and EMAN::EMUtil::process_region_io().

◆ z_origin()

float EMAN::Region::z_origin ( ) const
inline

get the z element of the origin

Definition at line 624 of file geometry.h.

624{ return origin[2]; }

References origin.

Referenced by EMAN::EMData::extract_box(), and EMAN::EMUtil::process_region_io().

Member Data Documentation

◆ origin

FloatPoint EMAN::Region::origin

◆ size

FloatSize EMAN::Region::size

The documentation for this class was generated from the following files: