EMAN2
boxingtools.h
Go to the documentation of this file.
00001 
00005 /*
00006  * Author: David Woolford, 04/15/2008 (woolford@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 #ifndef eman_boxingtools_h__
00037 #define eman_boxingtools_h__ 1
00038 
00039 #include "emdata.h"
00040 #include "geometry.h"
00041 #include <vector>
00042 using std::vector;
00043 
00044 #include <vector>
00045 using std::vector;
00046 
00047 #include <map>
00048 using std::map;
00049 
00050 #include <gsl/gsl_matrix.h>
00051 
00052 namespace EMAN
00053 {
00060         class BoxingTools
00061         {
00062         public:
00063                 BoxingTools() {}
00064                 ~BoxingTools() {}
00065 
00076                 static vector<float> get_min_delta_profile(const EMData* const image, int x, int y, int radius);
00077 
00089                 static bool is_local_maximum(const EMData* const image, int x, int y, int radius, EMData* const exclusion_map);
00090 
00091 
00092                 static vector<IntPoint> auto_correlation_pick(const EMData* const image, float threshold, int radius, const vector<float>& profile, EMData* const exclusion,const int cradius, int mode=1);
00093 
00094                 static bool hi_brid(const EMData* const image, int x, int y, int radius,EMData* const exclusion_map, vector<float>& profile);
00095 
00096                 static void set_radial_non_zero(EMData* const exclusion, int x, int y, int radius);
00097 
00098                 static IntPoint find_radial_max(const EMData* const map, int x, int y, int radius);
00099 
00100                 static map<unsigned int, unsigned int> classify(const vector<vector<float> >& data, const unsigned int& classes = 4);
00101 
00102                 static Vec3f get_color( const unsigned int index );
00103 
00104                 static void set_region( EMData* const image, const EMData* const mask, const int x, const int y, const float& val );
00105 
00106                 enum CmpMode {
00107                         SWARM_DIFFERENCE,
00108                         SWARM_RATIO,
00109                         SWARM_AVERAGE_RATIO
00110                 };
00111 
00112                 static void set_mode( const CmpMode m ) { mode = m; }
00113         private:
00114                 // A vector to store the "seed" starting colors, which exist at the corners of the cube.
00115                 // Then the vector is grown as more colours are asked for.
00116                 static vector<Vec3f> colors;
00117                 static CmpMode mode;
00118         };
00119 
00120         class BoxSVDClassifier
00121         {
00122                 public:
00123                         BoxSVDClassifier(const vector<vector<float> >& data, const unsigned int& classes = 4);
00124 
00125                         ~BoxSVDClassifier();
00126 
00127                         map< unsigned int, unsigned int> go();
00128 
00129         // Because the results of the classification always give a random class number, I thought it
00130         // be easier for the user if the classes with the greatest numbers always had the same colour.
00131         //  This is achieved using this function
00132                         static map< unsigned int, unsigned int> colorMappingByClassSize( const map< unsigned int, unsigned int>& grouping );
00133                 private:
00134                         const vector<vector<float> >& mData;
00135 
00136                         unsigned int mColumns;
00137                         unsigned int mRows;
00138 
00139                         unsigned int mClasses;
00140 
00141 
00142                         map< unsigned int, unsigned int> randomSeedCluster(const gsl_matrix* const svd_coords, unsigned int matrix_dims);
00143                         map< unsigned int, unsigned int> getIterativeCluster(const gsl_matrix* const svd_coords, const map< unsigned int, unsigned int>& current_grouping);
00144 
00145                         bool setDims( const vector<vector<float> >& data );
00146 
00147                         vector<vector<float> > getDistances( const gsl_matrix* const svd_coords, const gsl_matrix* const ref_coords);
00148 
00149                         map< unsigned int, unsigned int> getMapping(const vector<vector<float> >& distances);
00150         };
00151 
00152 } // namespace EMAN
00153 
00154 #endif // eman_boxingtools_h__