MrepModel.hpp

00001 // This file is part of the imaging2 class library.
00002 //
00003 // University of Innsbruck, Infmath Imaging, 2009.
00004 // http://infmath.uibk.ac.at
00005 //
00006 // All rights reserved.
00007 
00008 
00009 #ifndef MREPMODEL_H
00010 #define MREPMODEL_H
00011 
00012 #include <shape/ShapeInterface.hpp>
00013 
00014 
00015 namespace imaging
00016 {
00018   template<class position_t, class atom_t, class connection_t>
00019   class MrepModel : public ShapeInterface
00020   {
00021   protected:
00022     position_t _position;
00023 
00024     std::vector<atom_t> _atoms;
00025     std::vector<connection_t> _connections;
00026 
00027   public:
00028     MrepModel() : _atoms(0), _connections(0) {}
00029     
00030     MrepModel(const position_t & position, size_t n_atoms = 0, size_t n_connections = 0) :
00031         _position(position), _atoms(n_atoms), _connections(n_connections)
00032     {}
00033 
00034     void resize(size_t n_atoms, size_t n_connections)
00035     {
00036       _atoms.resize(n_atoms);
00037       _connections.resize(n_connections);
00038     }
00039 
00040     const atom_t & atom(size_t i) const { return _atoms[i]; }
00041     void set_atom(size_t i, const atom_t & atom) { _atoms[i] = atom; }
00042     size_t n_atoms() const { return _atoms.size(); }
00043 
00044     const connection_t & connection(size_t i) const {return _connections[i]; }
00045     void set_connection(size_t i, const connection_t & connection) { _connections[i] = connection; }
00046     size_t n_connections() const { return _connections.size(); }
00047 
00048     const position_t & position() const {return _position; }
00049     void set_position(const position_t & position) { _position = position; }
00050 
00051     size_t start_atom(size_t atom_index) const
00052     {
00053       return _atoms[atom_index].start_atom();
00054     }
00055 
00056     size_t atom_connection(size_t atom_index) const
00057     {
00058       return _atoms[atom_index].connection();
00059     }
00060 
00061 
00062     void exponential(const ublas::vector<float_t> & vector, ShapeInterface & shape) const
00063     {
00064       MrepModel<position_t, atom_t, connection_t> * shape_ptr = dynamic_cast< MrepModel<position_t, atom_t, connection_t> *>(& shape);
00065       
00066       if(! shape_ptr)
00067         throw Exception("Exception: Wrong type of argument 'shape' in MrepModel::exponential().");
00068 
00069       shape_ptr->resize(n_atoms(), n_connections());
00070 
00071       ublas::vector<float_t>::const_iterator iter = vector.begin();
00072       _position.exponential(iter, shape_ptr->_position);
00073 
00074       for (size_t j = 0; j < n_atoms(); j++)
00075         _atoms[j].exponential(iter, shape_ptr->_atoms[j]);
00076 
00077       if (n_connections() > 0)
00078         _connections[0].exponential_without_rotation(iter, shape_ptr->_connections[0]);
00079 
00080       for (size_t j = 1; j < n_connections(); j++)
00081         _connections[j].exponential(iter, shape_ptr->_connections[j]);
00082     }
00083 
00084 
00085     void logarithm(const ShapeInterface & shape, ublas::vector<float_t> & vector) const
00086     {
00087       const MrepModel<position_t, atom_t, connection_t> * shape_ptr = dynamic_cast< const MrepModel<position_t, atom_t, connection_t> *>(& shape);
00088       
00089       if(! shape_ptr)
00090         throw Exception("Exception: Wrong type of argument 'shape' in MrepModel::logarithm().");
00091         
00092       if(n_atoms() != shape_ptr->n_atoms() || n_connections() != shape_ptr->n_connections())
00093         throw Exception("Exception: Wrong type of M-Rep in MrepModel::logarithm().");
00094       
00095       ublas::vector<float_t>::iterator iter = vector.begin();
00096       
00097       _position.logarithm(shape_ptr->_position, iter);
00098 
00099       for (size_t j = 0; j < n_atoms(); j++)
00100         _atoms[j].logarithm(shape_ptr->_atoms[j], iter);
00101 
00102       if (n_connections() > 0)
00103         _connections[0].logarithm_without_rotation(shape_ptr->_connections[0], iter);
00104 
00105       for (size_t j = 1; j < n_connections(); j++)
00106         _connections[j].logarithm(shape_ptr->_connections[j], iter);
00107     }
00108 
00109     size_t dimension() const
00110     {
00111       size_t dimension = 0;
00112 
00113       dimension += _position.dimension();
00114 
00115       for(size_t j = 0; j < n_atoms(); j++)
00116         dimension += _atoms[j].dimension();
00117 
00118       if(n_connections() > 0)
00119         dimension += _connections[0].dimension_without_rotation();
00120 
00121       for(size_t j = 1; j < n_connections(); j++)
00122         dimension += _connections[j].dimension();
00123 
00124       return dimension;
00125     }
00126   };
00127 
00128 
00129   /*template <class T, class P, class A, class C>
00130   std::ostream& operator<<( std::ostream & os, const MrepModel<T, P, A, C> & model)
00131   {
00132     os << "MrepModel";
00133 
00134     os << "\n";
00135 
00136     os << "  position: " << model.get_position() << "\n";
00137     os << "  atoms: " << model._atoms;
00138     os << "  connections: " << model._connections;
00139 
00140     os << "  atom table: " << model._atom_table;
00141     //     os << "  knot table: " << model._knot_table;
00142 
00143     os << std::endl;
00144 
00145     return os;
00146   }*/
00147 
00148 }
00149 
00150 #endif
00151 

Generated on Tue Feb 10 10:01:30 2009 for imaging2 by  doxygen 1.5.5