File indexing completed on 2024-05-05 03:41:15

0001 /*************************************************************************************
0002  *  Copyright (C) 2010-2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> *
0003  *                                                                                   *
0004  *  This program is free software; you can redistribute it and/or                    *
0005  *  modify it under the terms of the GNU General Public License                      *
0006  *  as published by the Free Software Foundation; either version 2                   *
0007  *  of the License, or (at your option) any later version.                           *
0008  *                                                                                   *
0009  *  This program is distributed in the hope that it will be useful,                  *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0012  *  GNU General Public License for more details.                                     *
0013  *                                                                                   *
0014  *  You should have received a copy of the GNU General Public License                *
0015  *  along with this program; if not, write to the Free Software                      *
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0017  *************************************************************************************/
0018 
0019 #include "private/abstractsurface.h"
0020 // #include "private/surfacefactory.h"
0021 #include "private/functiongraphfactory.h"
0022 #include <private/utils/mathutils.h>
0023 
0024 #include <analitza/value.h>
0025 #include <analitza/vector.h>
0026 
0027 using namespace Analitza;
0028 
0029 //TODO macros para las prop e abajo
0030 
0031 class Frp : public AbstractSurface/*, static class? better macros FooClass*/
0032 {
0033 public:
0034     explicit Frp(const Analitza::Expression& e);
0035     Frp(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v);
0036 
0037     TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Cylindrical Surface z=F(r: Radial, p: Polar)"))
0038     EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
0039                         Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
0040                         Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
0041                         Analitza::ExpressionType(Analitza::ExpressionType::Value)))
0042     COORDDINATE_SYSTEM(Cylindrical)
0043     PARAMETERS(QStringList(QStringLiteral("r")) << QStringLiteral("p"))
0044     ICON_NAME(QStringLiteral("newcylindrical"))
0045     EXAMPLES(QStringList())
0046 
0047     //Own
0048     virtual bool setInterval(const QString& argname, const Analitza::Expression& min, const Analitza::Expression& max) override;
0049     virtual bool setInterval(const QString& argname, double min, double max) override;
0050 
0051     QVector3D fromParametricArgs(double u, double v) override;
0052     void update(const QVector3D & oppositecorner1, const QVector3D & oppositecorner2viewport) override;
0053 
0054 
0055 };
0056 
0057 bool Frp::setInterval(const QString& argname, const Analitza::Expression& min, const Analitza::Expression& max)
0058 {
0059 
0060     Analitza::Analyzer *intervalsAnalizer = new Analitza::Analyzer(analyzer->variables());
0061 
0062     QPair<Analitza::Expression, Analitza::Expression> ival = interval(argname, true);
0063 
0064     double min_val = ival.first.toReal().value();
0065     double max_val = ival.second.toReal().value();
0066 
0067     delete intervalsAnalizer;
0068 
0069     if (min_val<0 || max_val < 0) // el radio es distancia por tanto es positivo, el angulo va de 0 hasta +inf
0070         return false;
0071 
0072     if (argname == QStringLiteral("p") && max_val >= 2*M_PI)
0073         return false;
0074 
0075     return AbstractFunctionGraph::setInterval(argname, min, max);
0076 }
0077 
0078 bool Frp::setInterval(const QString& argname, double min, double max)
0079 {
0080     if (min<0 || max < 0) // el radio es distancia por tanto es positivo, el angulo va de 0 hasta +inf
0081         return false;
0082 
0083     if (argname == QStringLiteral("p") && max >= 2*M_PI)
0084         return false;
0085 
0086 
0087     return AbstractFunctionGraph::setInterval(argname, min, max);
0088 }
0089 
0090 Frp::Frp(const Analitza::Expression& e): AbstractSurface(e)
0091 {
0092     setInterval(QStringLiteral("r"), 0,5);
0093     setInterval(QStringLiteral("p"), 0, M_PI);
0094 }
0095 
0096 Frp::Frp(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& /*v*/): AbstractSurface(e)
0097 {}
0098 
0099 QVector3D Frp::fromParametricArgs(double r, double p)
0100 {
0101 
0102     arg(QStringLiteral("r"))->setValue(r);
0103     arg(QStringLiteral("p"))->setValue(p);
0104 
0105     double h = analyzer->calculateLambda().toReal().value();
0106 
0107     return cylindricalToCartesian(r,p,h);
0108 }
0109 
0110 void Frp::update(const QVector3D & /*oppositecorner1*/, const QVector3D & /*oppositecorner2*/)
0111 {
0112     buildParametricSurface();
0113 }
0114 
0115 REGISTER_SURFACE(Frp)