HyperspaceExplorer 0.7.1
RealFunctionImplementations.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 REALFUNCTIONIMPLEMENTATIONS_H
00022 #define REALFUNCTIONIMPLEMENTATIONS_H
00023 
00024 #include "RealFunction.h"
00025 
00027 
00028 class ParametricTestFunction: public ParametricFunction<4, 3> {
00029 
00030   public:
00031 
00032     ParametricTestFunction() {
00033       setName("ParametricTestFunction");
00034       setDescription("Testing a ParametricFunction to initialize a RealFunction with");
00035     }
00036    
00037     virtual return_type f(const argument_type &x) {
00038       return_type F;
00039       F[0] = x[0];
00040       F[1] = x[1];
00041       F[2] = x[2];
00042       F[3] = a0
00043            + a1x*x[0] + a1y*x[1] + a1z*x[2]
00044            + a2xx*x[0]*x[0] + a2xy*x[0]*x[1] + a2xz*x[0]*x[2]  
00045            + a2yy*x[1]*x[1] + a2yz*x[1]*x[2]  
00046            + a2zz*x[2]*x[2]  
00047         ;
00048       return F;  
00049     }    
00050 
00051   private:
00052     
00053     static constexpr double a0 = 0,
00054                         a1x = 1, a1y = -1, a1z = 1,
00055                         a2xx = -1, a2xy = 1, a2xz = -1,
00056                         a2yy = 1, a2yz = -1,
00057                         a2zz = 1;
00058 };
00059 
00060 namespace {
00061     Displayable *createParametricTestFunction() { return new RealFunction(new ParametricTestFunction()); }
00062     const bool registeredR0 = TheFunctionFactory::Instance().registerFunction(createParametricTestFunction, "RealFunction");
00063 }
00064 
00066 
00074 class Hypersphere: public RealFunction {
00075 
00076   public:
00077 
00078     Hypersphere(): RealFunction(), _radius(1.) {
00079       _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00080     }
00081     Hypersphere (double _tmin, double _tmax, double _dt,
00082                  double _umin, double _umax, double _du,
00083                  double _vmin, double _vmax, double _dv,
00084                  double _rad = 1);
00085     virtual ~Hypersphere() { }
00086     virtual void SetParameters(const ParameterMap &);
00087     virtual std::string getFunctionName() const { return "Hypersphere"; }
00088 
00089   protected:
00090 
00092     class DefiningFunction: public ParametricFunction<4, 3> {
00093 
00094       public:
00095 
00096         DefiningFunction(Hypersphere *parent): _parent(parent) { }
00097         virtual return_type f(const argument_type &x);
00098 
00099       private:
00100 
00102         Hypersphere* _parent;
00103 
00104     };
00105 
00106     virtual function_type normal;
00107 
00108     double _radius;         
00109 
00110 };
00111 
00112 namespace {
00113     Displayable *createHypersphere() { return new Hypersphere(); }
00114     const bool registeredR1 = TheFunctionFactory::Instance().registerFunction(createHypersphere, "RealFunction");
00115 }
00116 
00118 
00120 
00125 class Torus1: public RealFunction {
00126 
00127   public:
00128     Torus1(): RealFunction(), _R(2.), _r(1.), _rho(0.5) { 
00129       _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00130     }
00131     Torus1 (double tmin, double tmax, double dt,
00132             double umin, double umax, double du,
00133             double vmin, double vmax, double dv,
00134             double R = 2, double r = 1, double rho = 0.5);
00135     virtual ~Torus1() { }
00136 
00137     virtual std::string getFunctionName() const { return "Ditorus"; }
00138 
00139     virtual void SetParameters(const ParameterMap &parms) {
00140       //  parms["Radius"].value must be set!
00141 #     if 1
00142       for (ParameterMap::const_iterator i = parms.begin(); i != parms.end(); ++i) {
00143         if (i->second->getName() == "Major Radius") _R = i->second->toDouble();
00144         if (i->second->getName() == "Minor Radius") _r = i->second->toDouble();
00145         if (i->second->getName() == "Micro Radius") _rho = i->second->toDouble();
00146       }
00147 #     else
00148         setParameter(parms, this->_R, "Major Radius");
00149         setParameter(parms, this->_r, "Minor Radius");
00150         setParameter(parms, this->_rho, "Micro Radius");
00151 #     endif
00152     }
00153 
00154   protected:
00155 
00157     class DefiningFunction: public ParametricFunction<4, 3> {
00158 
00159       public:
00160 
00161         DefiningFunction(Torus1 *parent): _parent(parent) { }
00162         virtual return_type f(const argument_type &x);
00163 
00164       private:
00165 
00167         Torus1* _parent;
00168 
00169     };
00170 
00171     double _R;       
00172     double _r;       
00173     double _rho;     
00174 };
00175 
00176 namespace {
00177     Displayable *createTorus1() { return new Torus1(); }
00178     const bool registeredR2 = TheFunctionFactory::Instance().registerFunction(createTorus1, "RealFunction");
00179 }
00180 
00182 
00184 
00187 class Torus2: public RealFunction {
00188     public:
00189         Torus2(): RealFunction(), _R(1.), _r(0.5) { 
00190           _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00191         }
00192         Torus2 (double tmin, double tmax, double dt,
00193                 double umin, double umax, double du,
00194                 double vmin, double vmax, double dv,
00195                 double R = 1, double r = 0.5);
00196         virtual ~Torus2 () { }
00197 
00198         virtual std::string getFunctionName() const { return "Toraspherinder"; }
00199 
00200         virtual void SetParameters(const ParameterMap &parms) {
00201             //  parms["Radius"].value must be set!
00202 #if 1
00203             for (ParameterMap::const_iterator i = parms.begin();
00204                  i != parms.end(); ++i) {
00205                 if (i->second->getName() == "Major Radius")
00206                     _R = i->second->toDouble();
00207                 if (i->second->getName() == "Minor Radius")
00208                     _r = i->second->toDouble();
00209             }
00210 #else
00211             setParameter(parms, this->_R, "Major Radius");
00212             setParameter(parms, this->_r, "Minor Radius");
00213 #endif
00214         }
00215 
00216   protected:
00217 
00219     class DefiningFunction: public ParametricFunction<4, 3> {
00220 
00221       public:
00222 
00223         DefiningFunction(Torus2 *parent): _parent(parent) { }
00224         virtual return_type f(const argument_type &x);
00225 
00226       private:
00227 
00229         Torus2* _parent;
00230 
00231     };
00232 
00233     double _R;   
00234     double _r;   
00235 };
00236 
00237 namespace {
00238     Displayable *createTorus2() { return new Torus2(); }
00239     const bool registeredR3 = TheFunctionFactory::Instance().registerFunction(createTorus2, "RealFunction");
00240 }
00241 
00243 
00245 
00250 class Fr3r: public RealFunction {
00251     public:
00252         Fr3r(): RealFunction() { 
00253           _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00254         }
00255         Fr3r (double tmin, double tmax, double dt,
00256               double umin, double umax, double du,
00257               double vmin, double vmax, double dv);
00258         virtual ~Fr3r() { }
00259 
00260         virtual std::string getFunctionName() const { return "1/(r"+Util::sup2()+"+1)"; }
00261 
00262     protected:
00263 
00265     class DefiningFunction: public ParametricFunction<4, 3> {
00266 
00267       public:
00268 
00269         DefiningFunction(Fr3r *parent): _parent(parent) { }
00270         virtual return_type f(const argument_type &x);
00271 
00272       private:
00273 
00275         Fr3r* _parent;
00276 
00277     };
00278 };
00279 
00280 namespace {
00281     Displayable *createFr3r() { return new Fr3r(); }
00282     const bool registeredR4 = TheFunctionFactory::Instance().registerFunction(createFr3r, "RealFunction");
00283 }
00284 
00286 
00288 
00289 class GravitationPotential: public RealFunction {
00290 
00291   public:
00292 
00293     GravitationPotential(): RealFunction(), _M(1.), _R(0.25) { 
00294           _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00295         }
00296 
00297     GravitationPotential (double tmin, double tmax, double dt,
00298                           double umin, double umax, double du,
00299                           double vmin, double vmax, double dv,
00300                           double M = 1, double R = 0.25);
00301     virtual ~GravitationPotential () { }
00302 
00303     virtual std::string getFunctionName() const { return "Gravitation Potential"; }
00304 
00305     virtual void SetParameters(const ParameterMap &parms) {
00306 #if 1
00307             for (ParameterMap::const_iterator i = parms.begin();
00308                  i != parms.end(); ++i) {
00309                 if (i->second->getName() == "M") _M = i->second->toDouble();
00310                 if (i->second->getName() == "R") _R = i->second->toDouble();
00311             }
00312 #else
00313             setParameter(parms, this->_M, "M");
00314             setParameter(parms, this->_R, "R");
00315 #endif
00316         }
00317 
00318     protected:
00319 
00321     class DefiningFunction: public ParametricFunction<4, 3> {
00322 
00323       public:
00324 
00325         DefiningFunction(GravitationPotential *parent): _parent(parent) { }
00326         virtual return_type f(const argument_type &x);
00327 
00328       private:
00329 
00331         GravitationPotential* _parent;
00332 
00333     };
00334 
00335     double _M;   
00336     double _R;   
00337 };
00338 
00339 namespace {
00340     Displayable *createGravitationPotential() { return new GravitationPotential(); }
00341     const bool registeredR5 = TheFunctionFactory::Instance().registerFunction(createGravitationPotential, "RealFunction");
00342 }
00343 
00345 
00347 
00348 class Fr3rSin: public RealFunction {
00349     public:
00350         Fr3rSin(): RealFunction() { 
00351           _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00352         }
00353         Fr3rSin (double tmin, double tmax, double dt,
00354                  double umin, double umax, double du,
00355                  double vmin, double vmax, double dv);
00356         virtual ~Fr3rSin () { }
00357 
00358         virtual std::string getFunctionName() const { return "sin (r"+Util::sup2()+")"; }
00359 
00360     protected:
00361 
00363     class DefiningFunction: public ParametricFunction<4, 3> {
00364 
00365       public:
00366 
00367         DefiningFunction(Fr3rSin *parent): _parent(parent) { }
00368         virtual return_type f(const argument_type &x);
00369 
00370       private:
00371 
00373         Fr3rSin* _parent;
00374 
00375     };
00376 };
00377 
00378 namespace {
00379     Displayable *createFr3rSin() { return new Fr3rSin(); }
00380     const bool registeredR6 = TheFunctionFactory::Instance().registerFunction(createFr3rSin, "RealFunction");
00381 }
00382 
00384 
00386 
00387 class Fr3rExp: public RealFunction {
00388     public:
00389         Fr3rExp(): RealFunction() { 
00390           _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00391         }
00392         Fr3rExp (double tmin, double tmax, double dt,
00393                  double umin, double umax, double du,
00394                  double vmin, double vmax, double dv);
00395         virtual ~Fr3rExp () { }
00396 
00397         virtual std::string getFunctionName() const { return "exp (r"+Util::sup2()+")"; }
00398 
00399     protected:
00400 
00402     class DefiningFunction: public ParametricFunction<4, 3> {
00403 
00404       public:
00405 
00406         DefiningFunction(Fr3rExp *parent): _parent(parent) { }
00407         virtual return_type f(const argument_type &x);
00408 
00409       private:
00410 
00412         Fr3rExp* _parent;
00413 
00414     };
00415 };
00416 
00417 namespace {
00418     Displayable *createFr3rExp() { return new Fr3rExp(); }
00419     const bool registeredR7 = TheFunctionFactory::Instance().registerFunction(createFr3rExp, "RealFunction");
00420 }
00421 
00423 
00425 
00426 class Polar: public RealFunction {
00427     public:
00428         Polar (double tmin, double tmax, double dt,
00429                double umin, double umax, double du,
00430                double vmin, double vmax, double dv);
00431         virtual ~Polar() { }
00432 
00433     protected:
00434 
00436     class DefiningFunction: public ParametricFunction<4, 3> {
00437 
00438       public:
00439 
00440         DefiningFunction(Polar *parent): _parent(parent) { }
00441         virtual return_type f(const argument_type &x);
00442 
00443       private:
00444 
00446         Polar* _parent;
00447 
00448     };
00449 };
00450 
00452 
00454 
00455 class PolarSin: public RealFunction {
00456     public:
00457         PolarSin(): RealFunction(), _phase(2.) { 
00458           _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00459         }
00460         PolarSin (double tmin, double tmax, double dt,
00461                   double umin, double umax, double du,
00462                   double vmin, double vmax, double dv,
00463                   double phase = 2);
00464         virtual ~PolarSin () { }
00465 
00466         virtual std::string getFunctionName() const { return "Polar: r = 1/2+sin (Phase*pi*t*u*v)"; }
00467 
00468         virtual void SetParameters(const ParameterMap &parms) {
00469 #       if 1
00470             for (ParameterMap::const_iterator i = parms.begin();
00471                  i != parms.end(); ++i) {
00472                 if (i->second->getName() == "Phase") _phase = i->second->toDouble();
00473             }
00474 #       else
00475             setParameter(parms, this->_phase, "Phase");
00476 #       endif
00477         }
00478 
00479     protected:
00480 
00482     class DefiningFunction: public ParametricFunction<4, 3> {
00483 
00484       public:
00485 
00486         DefiningFunction(PolarSin *parent): _parent(parent) { }
00487         virtual return_type f(const argument_type &x);
00488 
00489       private:
00490 
00492         PolarSin* _parent;
00493 
00494     };
00495 
00496     double _phase;               
00497 };
00498 
00499 namespace {
00500     Displayable *createPolarSin() { return new PolarSin(); }
00501     const bool registeredR8 = TheFunctionFactory::Instance().registerFunction(createPolarSin, "RealFunction");
00502 }
00503 
00505 
00507 
00508 class PolarSin2: public RealFunction {
00509     public:
00510         PolarSin2(): RealFunction() { 
00511           _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00512         }
00513         PolarSin2 (double tmin, double tmax, double dt,
00514                    double umin, double umax, double du,
00515                    double vmin, double vmax, double dv);
00516         virtual ~PolarSin2 () { }
00517 
00518         virtual std::string getFunctionName() const { return "Polar: r = sin (pi/3.*(t+u+v))"; }
00519 
00520     protected:
00521 
00523     class DefiningFunction: public ParametricFunction<4, 3> {
00524 
00525       public:
00526 
00527         DefiningFunction(PolarSin2 *parent): _parent(parent) { }
00528         virtual return_type f(const argument_type &x);
00529 
00530       private:
00531 
00533         PolarSin2* _parent;
00534 
00535     };
00536 };
00537 
00538 namespace {
00539     Displayable *createPolarSin2() { return new PolarSin2(); }
00540     const bool registeredR9 = TheFunctionFactory::Instance().registerFunction(createPolarSin2, "RealFunction");
00541 }
00542 
00544 
00546 
00547 class PolarR: public RealFunction {
00548     public:
00549         PolarR(): RealFunction(), _phase(2.) { 
00550           _function = std::shared_ptr< ParametricFunction<4, 3> >(new DefiningFunction(this));
00551         }
00552         PolarR (double _tmin, double _tmax, double _dt,
00553                 double _umin, double _umax, double _du,
00554                 double _vmin, double _vmax, double _dv,
00555                 double _phase = 2);
00556         virtual ~PolarR () { }
00557 
00558         virtual std::string getFunctionName() const { 
00559           return "Polar: r = sqrt (t"+Util::sup2()+"+u"+Util::sup2()+"+v"+Util::sup2()+")"; 
00560         }
00561 
00562         virtual void SetParameters(const ParameterMap &parms) {
00563 #       if 1
00564             for (ParameterMap::const_iterator i = parms.begin();
00565                  i != parms.end(); ++i) {
00566                 if (i->second->getName() == "Phase") _phase = i->second->toDouble();
00567             }
00568 #       else
00569             setParameter(parms, this->_phase, "Phase");
00570 #       endif
00571         }
00572 
00573     protected:
00574 
00576     class DefiningFunction: public ParametricFunction<4, 3> {
00577 
00578       public:
00579 
00580         DefiningFunction(PolarR *parent): _parent(parent) { }
00581         virtual return_type f(const argument_type &x);
00582 
00583       private:
00584 
00586         PolarR* _parent;
00587 
00588     };
00589 
00590     double _phase;               
00591 };
00592 
00593 namespace {
00594     Displayable *createPolarR() { return new PolarR(); }
00595     const bool registeredR10 = TheFunctionFactory::Instance().registerFunction(createPolarR, "RealFunction");
00596 }
00597 
00598 #endif // REALFUNCTIONIMPLEMENTATIONS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

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