EMAN::OptimumOrientationGenerator Class Reference

Optimum orientation generator. More...

#include <symmetry.h>

Inheritance diagram for EMAN::OptimumOrientationGenerator:

Inheritance graph
[legend]
Collaboration diagram for EMAN::OptimumOrientationGenerator:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 OptimumOrientationGenerator ()
virtual ~OptimumOrientationGenerator ()
virtual string get_name () const
 Return "opt".
virtual string get_desc () const
 Get a description.
virtual TypeDict get_param_types () const
 Get a dictionary containing the permissable parameters of this class.
virtual vector< Transformgen_orientations (const Symmetry3D *const sym) const
 Generate Saff orientations in the asymmetric unit of the symmetry.

Static Public Member Functions

static OrientationGeneratorNEW ()
 Factory support function NEW.

Static Public Attributes

static const string NAME = "opt"
 The name of this class - used to access it from factories etc. Should be "icos".

Private Member Functions

 OptimumOrientationGenerator (const OptimumOrientationGenerator &)
 Disallow copy construction.
OptimumOrientationGeneratoroperator= (const OptimumOrientationGenerator &)
 Disallow assignment.
virtual int get_orientations_tally (const Symmetry3D *const sym, const float &delta) const
 This function returns how many orientations will be generated for a given delta (angular spacing) It does this by simulated gen_orientations.
vector< Vec3foptimize_distances (const vector< Transform > &v) const
 Optimize the distances in separating points on the unit sphere, as described by the the rotations in Transform objects.

Detailed Description

Optimum orientation generator.

Optimally distributes points on a unit sphere, then slices out a correctly sized asymmetric unit, depending on the symmetry type. The approach relies on an initial distribution of points on the unit sphere, which may be generated using any of the other orientation generators. By default, the Saff orientation generator is used.

Author:
David Woolford
Date:
March 2008

Definition at line 1304 of file symmetry.h.


Constructor & Destructor Documentation

EMAN::OptimumOrientationGenerator::OptimumOrientationGenerator (  )  [inline]

Definition at line 1307 of file symmetry.h.

Referenced by NEW().

01307 {}

virtual EMAN::OptimumOrientationGenerator::~OptimumOrientationGenerator (  )  [inline, virtual]

Definition at line 1308 of file symmetry.h.

01308 {}

EMAN::OptimumOrientationGenerator::OptimumOrientationGenerator ( const OptimumOrientationGenerator  )  [private]

Disallow copy construction.


Member Function Documentation

vector< Transform > OptimumOrientationGenerator::gen_orientations ( const Symmetry3D *const   sym  )  const [virtual]

Generate Saff orientations in the asymmetric unit of the symmetry.

Parameters:
sym the symmetry which defines the interesting asymmetric unit
Returns:
a vector of Transform objects containing the set of evenly distributed orientations

Implements EMAN::OrientationGenerator.

Definition at line 762 of file symmetry.cpp.

References EMAN::OrientationGenerator::add_orientation(), angles, EMAN::FactoryBase::copy_relevant_params(), EMAN::OrientationGenerator::gen_orientations(), EMAN::OrientationGenerator::get_optimal_delta(), InvalidParameterException, EMAN::Symmetry3D::is_in_asym_unit(), EMAN::RandomOrientationGenerator::NAME, optimize_distances(), EMAN::FactoryBase::params, EMAN::Dict::set_default(), and EMAN::FactoryBase::set_params().

00763 {
00764         float delta = params.set_default("delta", 0.0f);
00765         int n = params.set_default("n", 0);
00766 
00767         bool inc_mirror = params.set_default("inc_mirror",false);
00768 
00769         if ( delta <= 0 && n <= 0 ) throw InvalidParameterException("Error, you must specify a positive non-zero delta or n");
00770         if ( delta > 0 && n > 0 ) throw InvalidParameterException("Error, the delta and the n arguments are mutually exclusive");
00771 
00772         string generatorname = params.set_default("use","saff");
00773 
00774         if ( n > 0 && generatorname != RandomOrientationGenerator::NAME ) {
00775                 params["delta"] = get_optimal_delta(sym,n);
00776                 params["n"] = (int)0;
00777         }
00778 
00779         // Force the orientation generator to include the mirror - this is because
00780         // We will enventually use it to generate orientations over the intire sphere
00781         // which is C1 symmetry, with the inc_mirror flag set to true
00782         params["inc_mirror"] = true;
00783         OrientationGenerator* g = Factory < OrientationGenerator >::get(generatorname);
00784         g->set_params(copy_relevant_params(g));
00785 
00786 
00787         // get the starting orientation distribution
00788         CSym* unit_sphere = new CSym();
00789         Dict nsym; nsym["nsym"] = 1; unit_sphere->set_params(nsym);
00790 
00791         vector<Transform> unitsphereorientations = g->gen_orientations(unit_sphere);
00792         delete g; g = 0;
00793         delete unit_sphere; unit_sphere = 0;
00794 
00795         vector<Vec3f> angles = optimize_distances(unitsphereorientations);
00796 
00797         vector<Transform> ret;
00798         for (vector<Vec3f>::const_iterator it = angles.begin(); it != angles.end(); ++it ) {
00799                 if ( sym->is_in_asym_unit((*it)[1],(*it)[0],inc_mirror) ) {
00800                         add_orientation(ret,(*it)[0],(*it)[1]);
00801                 }
00802         }
00803 
00804         // reset the params to what they were before they were acted upon by this class
00805         params["inc_mirror"] = inc_mirror;
00806         params["delta"] = delta;
00807         params["n"] = n;
00808 
00809         return ret;
00810 }

virtual string EMAN::OptimumOrientationGenerator::get_desc (  )  const [inline, virtual]

Get a description.

Returns:
a clear desciption of this class

Implements EMAN::FactoryBase.

Definition at line 1326 of file symmetry.h.

01326 { return "Generate optimally distributed orientations within an asymmetric using a basic optimization technique"; }

virtual string EMAN::OptimumOrientationGenerator::get_name (  )  const [inline, virtual]

Return "opt".

Returns:
the unique name of this class

Implements EMAN::FactoryBase.

Definition at line 1321 of file symmetry.h.

References NAME.

01321 { return NAME; }

int OptimumOrientationGenerator::get_orientations_tally ( const Symmetry3D *const   sym,
const float &  delta 
) const [private, virtual]

This function returns how many orientations will be generated for a given delta (angular spacing) It does this by simulated gen_orientations.

Parameters:
sym the symmetry which defines the interesting asymmetric unit
delta the desired angular spacing of the orientations
Returns:
the number of orientations that will be generated using these parameters

Implements EMAN::OrientationGenerator.

Definition at line 747 of file symmetry.cpp.

References EMAN::OrientationGenerator::get_orientations_tally(), EMAN::FactoryBase::params, and EMAN::Dict::set_default().

00748 {
00749         string deltaoptname = params.set_default("use","saff");
00750         Dict a;
00751         a["inc_mirror"] = (bool)params.set_default("inc_mirror",false);
00752         OrientationGenerator *g = Factory < OrientationGenerator >::get(deltaoptname,a);
00753         if (g) {
00754                 int tally = g->get_orientations_tally(sym,delta);
00755                 delete g;
00756                 g = 0;
00757                 return tally;
00758         }
00759         else throw;
00760 }

virtual TypeDict EMAN::OptimumOrientationGenerator::get_param_types (  )  const [inline, virtual]

Get a dictionary containing the permissable parameters of this class.

Returns:
a dictionary containing the permissable parameters of this class parameters are explained in the dictionary itself

Reimplemented from EMAN::OrientationGenerator.

Definition at line 1332 of file symmetry.h.

References EMAN::EMObject::BOOL, EMAN::EMObject::FLOAT, EMAN::OrientationGenerator::get_param_types(), EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.

01333                 {
01334                         TypeDict d = OrientationGenerator::get_param_types();
01335                         d.put("n", EMObject::INT, "The number of orientations to generate. This option is mutually exclusively of the delta argument.Will attempt to get as close to the number specified as possible.");
01336                         d.put("inc_mirror", EMObject::BOOL, "Indicates whether or not to include the mirror portion of the asymmetric unit. Default is false.");
01337                         d.put("delta", EMObject::FLOAT, "The angular separation of orientations in degrees. This option is mutually exclusively of the n argument.");
01338                         d.put("use", EMObject::STRING, "The orientation generation technique used to generate the initial distribution on the unit sphere.");
01339                         return d;
01340                 }

static OrientationGenerator* EMAN::OptimumOrientationGenerator::NEW (  )  [inline, static]

Factory support function NEW.

Returns:
a newly instantiated class of this type

Definition at line 1313 of file symmetry.h.

References OptimumOrientationGenerator().

01314                 {
01315                         return new OptimumOrientationGenerator();
01316                 }

OptimumOrientationGenerator& EMAN::OptimumOrientationGenerator::operator= ( const OptimumOrientationGenerator  )  [private]

Disallow assignment.

vector< Vec3f > OptimumOrientationGenerator::optimize_distances ( const vector< Transform > &  v  )  const [private]

Optimize the distances in separating points on the unit sphere, as described by the the rotations in Transform objects.

Definition at line 812 of file symmetry.cpp.

References EMAN::Vec3< Type >::normalize(), and EMAN::EMConsts::rad2deg.

Referenced by gen_orientations().

00813 {
00814         vector<Vec3f> points;
00815 
00816         for (vector<Transform>::const_iterator it = v.begin(); it != v.end(); ++it ) {
00817                 points.push_back(Vec3f(0,0,1)*(*it));
00818         }
00819 
00820         if ( points.size() >= 2 ) {
00821                 int max_it = 100;
00822                 float percentage = 0.01f;
00823 
00824                 for ( int i = 0; i < max_it; ++i ){
00825                         unsigned int p1 = 0;
00826                         unsigned int p2 = 1;
00827 
00828                         float distsquared = (points[p1]-points[p2]).squared_length();
00829 
00830                         // Find the nearest points
00831                         for(unsigned int j = 0; j < points.size(); ++j) {
00832                                 for(unsigned int k = j+1; k < points.size(); ++k) {
00833                                         float d = (points[j]-points[k]).squared_length();
00834                                         if ( d < distsquared ) {
00835                                                 distsquared = d;
00836                                                 p1 = j;
00837                                                 p2 = k;
00838                                         }
00839                                 }
00840                         }
00841 
00842                         // Move them apart by a small fraction
00843                         Vec3f delta = percentage*(points[p2]-points[p1]);
00844 
00845                         points[p2] += delta;
00846                         points[p2].normalize();
00847                         points[p1] -= delta;
00848                         points[p1].normalize();
00849                 }
00850         }
00851 
00852         vector<Vec3f> ret;
00853         for (vector<Vec3f>::const_iterator it = points.begin(); it != points.end(); ++it ) {
00854                 float altitude = (float)(EMConsts::rad2deg*acos((*it)[2]));
00855                 float azimuth = (float)(EMConsts::rad2deg*atan2((*it)[1],(*it)[0]));
00856                 ret.push_back(Vec3f(90.0f+azimuth,altitude,0));
00857         }
00858 
00859         return ret;
00860 }


Member Data Documentation

const string OptimumOrientationGenerator::NAME = "opt" [static]

The name of this class - used to access it from factories etc. Should be "icos".

Definition at line 1349 of file symmetry.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Thu Nov 17 12:47:44 2011 for EMAN2 by  doxygen 1.4.7