HyperspaceExplorer 0.7.1
FunctionHolder.impl.h
00001 /*
00002 Hyperspace Explorer - visualizing higher-dimensional geometry
00003 Copyright (C) 2010  Lene Preuss <lene.preuss@gmail.com>
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 */
00020 
00021 #ifndef FUNCTIONHOLDER_IMPL_H
00022 #define FUNCTIONHOLDER_IMPL_H
00023 
00024 #include "FunctionHolder.h"
00025 
00026 #include "FunctionValueGrid.h"
00027 #include "VertexHolder.impl.h"
00028 #include "TransformationFactory.impl.h"
00029 #include "Transformation.impl.h"
00030 #include "Projection.impl.h"
00031 #include "GridDrawer.impl.h"
00032 #include "DefinitionRangeOfDimension.impl.h"
00033 
00034 
00035 using VecMath::Vector;
00036 using VecMath::MultiDimensionalVector;
00037 
00038 using std::shared_ptr;
00039 
00040 template <unsigned N, unsigned P, typename NUM>
00041 class FunctionHolder<N, P, NUM>::Impl {
00042 
00043   public:
00044 
00045     Impl(double tmin, double tmax, double dt,
00046          double umin, double umax, double du,
00047          double vmin, double vmax, double dv):
00048         definitionRange_() {
00049         setDefinitionRange(tmin, tmax, dt, umin, umax, du, vmin, vmax, dv);
00050     }
00051   
00052     Impl(shared_ptr< function_type > f,
00053          double tmin, double tmax, double dt,
00054          double umin, double umax, double du,
00055          double vmin, double vmax, double dv):
00056         definitionRange_(), function_(f) {
00057         setDefinitionRange(tmin, tmax, dt, umin, umax, du, vmin, vmax, dv);
00058     }
00059 
00060 
00061     unsigned getNumParameters() {
00062       assert(function_);
00063       return function_->getNumParameters();
00064     }
00065 
00066     const DefinitionRangeOfDimension<P> &getDefinitionRange() const {
00067       return definitionRange_;
00068     }
00069 
00070     void setDefinitionRange(double tmin, double tmax, double dt,
00071                             double umin, double umax, double du,
00072                             double vmin, double vmax, double dv) {
00073         if (P > 0) definitionRange_.setRange(0, DefinitionSpaceRange(tmin, tmax, dt));
00074         if (P > 1) definitionRange_.setRange(1, DefinitionSpaceRange(umin, umax, du));
00075         if (P > 2) definitionRange_.setRange(2, DefinitionSpaceRange(vmin, vmax, dv));
00076     }
00077 
00078     Vector<P, unsigned> getNumSteps() {
00079         Vector<P, unsigned> numSteps = definitionRange_.getNumSteps();
00080         addSafetyMargin(numSteps);
00081         return numSteps;
00082     }
00083 
00084     Vector<P, NUM> min() { return definitionRange_.getMinValue(); }
00085     Vector<P, NUM> max() { return definitionRange_.getMaxValue(); }
00086     
00087     DefinitionRangeOfDimension<P> definitionRange_;
00088 
00090     shared_ptr< function_type > function_;
00091 
00092     void addSafetyMargin(Vector<P, unsigned> &steps) { steps += 2; }
00093 
00094 };
00095 
00097 
00098 template <unsigned N, unsigned P, typename NUM>
00099 FunctionHolder<N, P, NUM>::FunctionHolder(shared_ptr< function_type > f):
00100   VertexHolder<N, P, NUM>(ParameterMap()),
00101   pImpl_(new Impl(
00102       f,
00103       DefinitionSpaceRange::defaultMin, DefinitionSpaceRange::defaultMax, DefinitionSpaceRange::defaultStep,
00104       DefinitionSpaceRange::defaultMin, DefinitionSpaceRange::defaultMax, DefinitionSpaceRange::defaultStep,
00105       DefinitionSpaceRange::defaultMin, DefinitionSpaceRange::defaultMax, DefinitionSpaceRange::defaultStep)) { }
00106 
00107 template <unsigned N, unsigned P, typename NUM>
00108 FunctionHolder<N, P, NUM>::FunctionHolder(ParameterMap parms):
00109   VertexHolder<N, P, NUM>(parms),
00110   pImpl_(new Impl(
00111       DefinitionSpaceRange::defaultMin, DefinitionSpaceRange::defaultMax, DefinitionSpaceRange::defaultStep,
00112       DefinitionSpaceRange::defaultMin, DefinitionSpaceRange::defaultMax, DefinitionSpaceRange::defaultStep,
00113       DefinitionSpaceRange::defaultMin, DefinitionSpaceRange::defaultMax, DefinitionSpaceRange::defaultStep)) { }
00114 
00115 template <unsigned N, unsigned P, typename NUM>
00116 void FunctionHolder<N, P, NUM>::Draw(UI::View *view) {
00117   GridDrawer<P, NUM, 3> draw(this->X(), this->Xscr(), view);
00118   draw.execute();
00119 }
00120 
00121 template <unsigned N, unsigned P, typename NUM>
00122 void FunctionHolder<N, P, NUM>::setDefinitionRange(double tmin, double tmax, double dt,
00123                                                    double umin, double umax, double du,
00124                                                    double vmin, double vmax, double dv) {
00125   pImpl_->setDefinitionRange(tmin, tmax, dt, umin, umax, du, vmin, vmax, dv);
00126 }
00127 
00128 template <unsigned N, unsigned P, typename NUM>
00129 void FunctionHolder<N, P, NUM>::Initialize () {
00130   this->setX(
00131       FunctionValueGrid<N, P, NUM>(
00132           pImpl_->function_, pImpl_->getNumSteps(), pImpl_->min(), pImpl_->max()
00133       )
00134   );
00135   this->calibrateColors();
00136 }
00137 
00138 template <unsigned N, unsigned P, typename NUM>
00139 unsigned FunctionHolder<N, P, NUM>::getNumParameters() {
00140     return pImpl_->function_->getNumParameters();
00141 }
00142 
00143 template <unsigned N, unsigned P, typename NUM>
00144 const DefinitionRangeOfDimension<P> &FunctionHolder<N, P, NUM>::getDefinitionRange() const {
00145   return pImpl_->getDefinitionRange();
00146 }
00147 
00148 
00149 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

Generated on Mon Apr 9 2012 20:25:14 for HyperspaceExplorer 0.7.1 by doxygen 1.7.4  -  Hosted bySourceForge.net Logo