transformable.cpp

00001 
00002 /***************************************************************************
00003  *  transformable.h - Transformable interface
00004  *
00005  *  Created: Thu Oct 02 16:53:27 2008
00006  *  Copyright  2008  Daniel Beck
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <geometry/transformable.h>
00025 
00026 namespace fawkes {
00027 
00028 /** @class fawkes::Transformable <geometry/transformable.h> 
00029  * Interface class for all transformable objects. In order to be
00030  * tranformable by multiplying the geometric object with a
00031  * fawkes::HomTransform it should be derived from this class (although
00032  * it doesn't have to).
00033  *
00034  * @author Daniel Beck
00035  */
00036 
00037 /** @fn void fawkes::Transformable::register_primitives()
00038  * Here, a derived class should register its primitives (HomPoints and
00039  * HomVectors) by calling add_primitive for each of those.
00040  */
00041 
00042 /** @fn void fawkes::Transformable::post_transform()
00043  * This method is called after the primitives are transformed. Any
00044  * additional updates that need to be done should be done here.
00045  */
00046 
00047 /** Constructor. */
00048 Transformable::Transformable()
00049 {
00050 }
00051 
00052 
00053 /** Destructor. */
00054 Transformable::~Transformable()
00055 {
00056 }
00057 
00058 /** Add a primitive to the list of primitives that is transformed.
00059 * @param c a primitive (a HomCoord or an object of a derived class)
00060 */
00061 void
00062 Transformable::add_primitive(HomCoord* c)
00063 {
00064   m_primitives.push_back(c);
00065 }
00066 
00067 /** Clear the list of primitives. */
00068 void
00069 Transformable::clear_primitives()
00070 {
00071   m_primitives.clear();
00072 }
00073 
00074 /** Apply the transform to all registered primitives and call the
00075  * post_transform() method.
00076  * @param t a transform
00077  */
00078 void
00079 Transformable::transform(const HomTransform& t)
00080 {
00081   std::vector<HomCoord*>::const_iterator iter;
00082   for ( iter  = m_primitives.begin();
00083         iter != m_primitives.end();
00084         ++iter )
00085     { 
00086       HomCoord* c = *iter;
00087       c->transform(t); 
00088     }
00089   
00090   post_transform();
00091 }
00092 
00093 } // end namespace fawkes