EMAN2
geometry.cpp
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#include <cstdio>
33#include "geometry.h"
34
35using namespace EMAN;
36
38{
39 return IntPoint(-p[0],-p[1],-p[2]);
40}
41
42bool EMAN::operator<(const Pixel& p1, const Pixel& p2)
43{
44 if (p1.value < p2.value) {
45 return true;
46 }
47 return false;
48}
49
50bool EMAN::operator==(const Pixel& p1, const Pixel& p2)
51{
52 if (p1.x == p2.x && p1.y == p2.y && p1.z == p2.z && p1.value == p2.value) {
53 return true;
54 }
55 return false;
56}
57
58bool EMAN::operator!=(const Pixel& p1, const Pixel& p2)
59{
60 return !(p1 == p2);
61}
62
63
64bool Region::inside_region() const
65{
66 if (size[0] >= 0 && size[1] >= 0 && size[2] >= 0) {
67 return true;
68 }
69
70 return false;
71}
72
73bool Region::inside_region(const FloatPoint & p) const
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}
86
87bool Region::inside_region(float x) const
88{
89 if (size[0] >= 0 && origin[0] <= x &&
90 (origin[0] + size[0]) > x ) {
91 return true;
92 }
93 return false;
94}
95
96
97bool Region::inside_region(float x, float y) const
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}
106
107#include <iostream>
108using std::cout;
109using std::endl;
110
111bool Region::inside_region(float x, float y, float z) const
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}
121
122
123bool Region::is_region_in_box(const FloatSize & box) const
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}
135
136
137
138string Region::get_string() const
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}
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:278
int get_ndim() const
Get the dimension of the point, 1D/2D/3D.
Definition: geometry.h:410
FloatSize is used to describe a 1D, 2D or 3D rectangular size in floating numbers.
Definition: geometry.h:105
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:192
Pixel describes a 3D pixel's coordinates and its intensity value.
Definition: geometry.h:452
float value
Definition: geometry.h:483
bool inside_region() const
to check whether a point is inside this region
Definition: geometry.cpp:64
string get_string() const
Get the description of this region in a string.
Definition: geometry.cpp:138
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
FloatSize size
Definition: geometry.h:655
FloatPoint origin
Definition: geometry.h:654
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