EMAN2
geometry.cpp
Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  *
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  *
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  *
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  *
00034  * */
00035 
00036 #include <cstdio>
00037 #include "geometry.h"
00038 
00039 using namespace EMAN;
00040 
00041 IntPoint EMAN::operator -( const IntPoint& p)
00042 {
00043         return IntPoint(-p[0],-p[1],-p[2]);
00044 }
00045 
00046 bool EMAN::operator<(const Pixel& p1, const Pixel& p2)
00047 {
00048         if (p1.value < p2.value) {
00049                 return true;
00050         }
00051         return false;
00052 }
00053 
00054 bool EMAN::operator==(const Pixel& p1, const Pixel& p2)
00055 {
00056         if (p1.x == p2.x && p1.y == p2.y && p1.z == p2.z && p1.value == p2.value) {
00057                 return true;
00058         }
00059         return false;
00060 }
00061 
00062 bool EMAN::operator!=(const Pixel& p1, const Pixel& p2)
00063 {
00064         return !(p1 == p2);
00065 }
00066 
00067 
00068 bool Region::inside_region() const
00069 {
00070         if (size[0] >= 0 && size[1] >= 0 && size[2] >= 0) {
00071                 return true;
00072         }
00073 
00074         return false;
00075 }
00076 
00077 bool Region::inside_region(const FloatPoint & p) const
00078 {
00079         if (p.get_ndim() == 1) {
00080                 return inside_region(p[0]);
00081         }
00082 
00083 
00084         if (p.get_ndim() == 2) {
00085                 return inside_region(p[0], p[1]);
00086         }
00087 
00088         return inside_region(p[0], p[1], p[2]);
00089 }
00090 
00091 bool Region::inside_region(float x) const
00092 {
00093         if (size[0] >= 0 && origin[0] <= x &&
00094                 (origin[0] + size[0]) > x ) {
00095                 return true;
00096         }
00097         return false;
00098 }
00099 
00100 
00101 bool Region::inside_region(float x, float y) const
00102 {
00103         if (size[0] >= 0 && size[1] >= 0 &&
00104                 origin[0] <= x && origin[1] <= y &&
00105                 (origin[0] + size[0]) > x && (origin[1] + size[1]) > y) {
00106                 return true;
00107         }
00108         return false;
00109 }
00110 
00111 #include <iostream>
00112 using std::cout;
00113 using std::endl;
00114 
00115 bool Region::inside_region(float x, float y, float z) const
00116 {
00117         if (size[0] >= 0 && size[1] >= 0 && size[2] >= 0 &&
00118                 origin[0] <= x && origin[1] <= y && origin[2] <= z &&
00119                 (origin[0] + size[0]) > x &&
00120                 (origin[1] + size[1]) > y && (origin[2] + size[2]) > z) {
00121                 return true;
00122         }
00123         return false;
00124 }
00125 
00126 
00127 bool Region::is_region_in_box(const FloatSize & box) const
00128 {
00129         if (size[0] >= 0 && size[1] >= 0 && size[2] >= 0 &&
00130                 origin[0] >= 0 && origin[1] >= 0 && origin[2] >= 0 &&
00131                 (origin[0] + size[0]) <= box[0] &&
00132                 (origin[1] + size[1]) <= box[1] &&
00133                 (origin[2] + size[2]) <= box[2]) {
00134                 return true;
00135         }
00136 
00137         return false;
00138 }
00139 
00140 
00141 
00142 string Region::get_string() const
00143 {
00144         char str[1028];
00145         int ndim = origin.get_ndim();
00146 
00147         if (ndim == 2) {
00148                 sprintf(str, "(%2.1f, %2.1f; %2.1f, %2.1f)",
00149                                 origin[0], origin[1], size[0], size[1]);
00150         }
00151         else if (ndim == 3) {
00152                 sprintf(str, "(%2.1f, %2.1f, %2.1f; %2.1f, %2.1f, %2.1f)",
00153                                 origin[0], origin[1], origin[2], size[0], size[1], size[2]);
00154         }
00155 
00156         return string(str);
00157 }