transforms.hpp

Go to the documentation of this file.
00001 // -*- mode: c++; indent-tabs-mode: nil; -*-
00002 //
00003 //The Biomolecule Toolkit (BTK) is a C++ library for use in the
00004 //modeling, analysis, and design of biological macromolecules.
00005 //Copyright (C) 2005-2006, Tim Robertson <kid50@users.sourceforge.net>,
00006 //                         Chris Saunders <ctsa@users.sourceforge.net>
00007 //
00008 //This program is free software; you can redistribute it and/or modify
00009 //it under the terms of the GNU Lesser General Public License as published
00010 //by the Free Software Foundation; either version 2.1 of the License, or (at
00011 //your option) any later version.
00012 //
00013 //This program is distributed in the hope that it will be useful,  but
00014 //WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //Lesser General Public License for more details.
00017 //
00018 //You should have received a copy of the GNU Lesser General Public License
00019 //along with this program; if not, write to the Free Software Foundation,
00020 //Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00024 
00025 #ifndef BTK_ALGORITHMS_TRANSFORMS_HPP
00026 #define BTK_ALGORITHMS_TRANSFORMS_HPP
00027 
00028 #include <btk/core/algorithms/properties.hpp>
00029 #include <btk/core/math/rotation.hpp>
00030 
00031 namespace BTK {
00032 namespace ALGORITHMS {
00033 
00041 
00044 template <typename AtomIterator>
00045 void
00046 translate(AtomIterator begin,
00047           AtomIterator end,
00048           BTK::MATH::BTKVector const & T)
00049 {
00050   for (;begin!=end;++begin) {
00051     begin->set_position(begin->position()+T);
00052   }
00053 }
00054 
00060 template <typename AtomIterator>
00061 void
00062 center(AtomIterator begin,
00063        AtomIterator end)
00064 {
00065   BTK::MATH::BTKVector COM(geometric_center(begin,end));
00066 
00067   translate(begin,end,-COM);
00068 }
00069 
00076 template <typename AtomIterator1,typename AtomIterator2>
00077 void
00078 align_centers(AtomIterator1 fixed_begin,
00079               AtomIterator1 fixed_end,
00080               AtomIterator2 mobile_begin,
00081               AtomIterator2 mobile_end)
00082  {
00083    BTK::MATH::BTKVector fixedCOM(geometric_center(fixed_begin,fixed_end));
00084    BTK::MATH::BTKVector COM(geometric_center(mobile_begin,mobile_end));
00085   translate(mobile_begin,mobile_end,fixedCOM-COM);
00086  }
00087 
00088 
00096 template <typename AtomIterator>
00097 void
00098 rotate(AtomIterator begin,
00099        AtomIterator end,
00100        double phi,
00101        double theta,
00102        double psi,
00103        BTK::MATH::BTKVector const & fixed_point)
00104 {
00105   using BTK::MATH::create_rotation_matrix;
00106 
00107   BTK::MATH::BTKMatrix R(create_rotation_matrix(phi,theta,psi));
00108   BTK::MATH::BTKVector T(prec_prod(R,-fixed_point)+fixed_point);
00109 
00110   for(; begin != end; ++begin) {
00111     begin->set_position(prec_prod(R,begin->position())+T);
00112   }
00113 }
00114 
00122 template <typename AtomIterator>
00123 inline
00124 void
00125 rotate(AtomIterator begin,
00126        AtomIterator end,
00127        double phi,
00128        double theta,
00129        double psi)
00130 {
00131   rotate(begin,end,phi,theta,psi,
00132          geometric_center(begin,end));
00133 }
00134 
00141 template <typename AtomIterator>
00142 void
00143 rotate(AtomIterator begin,
00144        AtomIterator end,
00145        BTK::MATH::BTKVector const & axis,
00146        double theta,
00147        BTK::MATH::BTKVector const & fixed_point)
00148 {
00149   using BTK::MATH::create_rotation_matrix;
00150   BTK::MATH::BTKMatrix R(create_rotation_matrix(axis,theta));
00151   BTK::MATH::BTKVector T(prec_prod(R,-fixed_point)+fixed_point);
00152 
00153   for(; begin != end; ++begin) {
00154     begin->set_position(prec_prod(R,begin->position())+T);
00155   }
00156 }
00157 
00166 template <typename AtomIterator>
00167 inline
00168 void
00169 rotate(AtomIterator begin,
00170        AtomIterator end,
00171        BTK::MATH::BTKVector const & axis,
00172        double theta)
00173 {
00174   rotate(begin,end,axis,theta,
00175          geometric_center(begin,end));
00176 }
00177 
00182 template <typename AtomIterator>
00183 void
00184 rotate(AtomIterator  begin,
00185        AtomIterator end,
00186        BTK::MATH::BTKMatrix const & R)
00187 {
00188   for (; begin != end; ++begin)
00189     begin->set_position(prec_prod(R,begin->position()));
00190 }
00191 
00197 template <typename AtomIterator>
00198 void
00199 transform(AtomIterator begin,
00200           AtomIterator end,
00201           BTK::MATH::BTKMatrix const & R,
00202           BTK::MATH::BTKVector const & T)
00203 {
00204   for(;begin!=end;++begin) {
00205     begin->set_position(prec_prod(R,begin->position())+T);
00206   }
00207 }
00208 
00209 } // namespace ALGORITHMS
00210 } // namespace BTK
00211 
00212 #endif 

Generated on Sun Jul 15 20:46:27 2007 for BTK Core by  doxygen 1.5.1