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 
0020 #include "private/abstractsurface.h"
0021 // #include "private/surfacefactory.h"
0022 #include "private/functiongraphfactory.h"
0023 
0024 #include <analitza/value.h>
0025 #include <analitza/vector.h>
0026 #include <QVector3D>
0027 
0028 using namespace Analitza;
0029 
0030 //TODO below is a macros for the prop e
0031 
0032 //NOTE 
0033 //FUTURE
0034 //TODO GSOC Equipotential Curve -> Contour Plot: can be achieved by separating the type
0035 // of surface e.g. a surface generated by a f (a, b) contains isolines ...
0036 // in this way, it is possible to have a function f (a, b, c, d) and draw their
0037 // contourplot3d. This is the proposal:
0038 // class SurfaceByFunctionOfTwoVars change the name as appropriate
0039 // {
0040 //     ...
0041 // public:
0042 //     setISOCONTOURSValues(list of const values)
0043 //     setISOCONTOURSVale(const value) -- a single value to which all the environments are equipotential
0044 //     ...
0045 // }
0046 //
0047 
0048 class  Fxy : public AbstractSurface/*, static class? better macros FooClass*/
0049 {
0050 public:
0051     CONSTRUCTORS(Fxy)
0052     TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Surface z=F(x,y)"))
0053     EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
0054                         Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
0055                         Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
0056                         Analitza::ExpressionType(Analitza::ExpressionType::Value)))
0057     COORDDINATE_SYSTEM(Cartesian)
0058     PARAMETERS(QStringList(QStringLiteral("x")) << QStringLiteral("y"))
0059     ICON_NAME(QStringLiteral("newfunction3d"))
0060     EXAMPLES(QStringList(QStringLiteral("x*x+y")) << QStringLiteral("x+y*sin(x)") << QStringLiteral("x*y"))
0061 
0062     //Own
0063 
0064     QVector3D fromParametricArgs(double u, double v) override;
0065     void update(const QVector3D & oppositecorner1, const QVector3D & oppositecorner2) override;
0066 };
0067 
0068 QVector3D Fxy::fromParametricArgs(double u, double v)
0069 {
0070     arg(QStringLiteral("x"))->setValue(u);
0071     arg(QStringLiteral("y"))->setValue(v);    
0072     
0073     return QVector3D(u,v,analyzer->calculateLambda().toReal().value());
0074 }
0075 
0076 void Fxy::update(const QVector3D & /*oppositecorner1*/, const QVector3D & /*oppositecorner2*/)
0077 {
0078     buildParametricSurface();
0079 //     vertices.clear();
0080 //     normals.clear();
0081 //     indices.clear();
0082 // 
0083 //     vertices << 0 << 0 << 0 << 0 << 0 << 1 << 1 << 0 << 0; // 3 for each index
0084 //     normals << 0 << 1 << 0; // 1 by primitive = 1 by face (tri-face) -1 by every 3 index
0085 //     indices << 0 << 1 << 2; // enumeration starts from scratch
0086 }
0087 
0088 REGISTER_SURFACE(Fxy)
0089 
0090 class Fxz : public AbstractSurface/*, static class? better macros FooClass*/
0091 {
0092 public:
0093     CONSTRUCTORS(Fxz)
0094     TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Surface y=F(x,z)"))
0095     EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
0096                         Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
0097                         Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
0098                         Analitza::ExpressionType(Analitza::ExpressionType::Value)))
0099     COORDDINATE_SYSTEM(Cartesian)
0100     PARAMETERS(QStringList(QStringLiteral("x")) << QStringLiteral("z"))
0101     ICON_NAME(QStringLiteral("newfunction3d"))
0102     EXAMPLES(QStringList(QStringLiteral("x+z")))
0103 
0104     QVector3D fromParametricArgs(double u, double v) override;
0105     void update(const QVector3D & oppositecorner1, const QVector3D & oppositecorner2) override;
0106 };
0107 
0108 QVector3D Fxz::fromParametricArgs(double u, double v)
0109 {
0110     arg(QStringLiteral("x"))->setValue(u);
0111     arg(QStringLiteral("z"))->setValue(v);    
0112     
0113     return QVector3D(u,analyzer->calculateLambda().toReal().value(),v);
0114 }
0115 
0116 void Fxz::update(const QVector3D & /*oppositecorner1*/, const QVector3D & /*oppositecorner2*/)
0117 {
0118     buildParametricSurface();
0119 }
0120 
0121 REGISTER_SURFACE(Fxz)
0122 
0123 class Fyz : public AbstractSurface/*, static class? better macros FooClass*/
0124 {
0125 public:
0126     CONSTRUCTORS(Fyz)
0127     TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Surface x=F(y,z)"))
0128     EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
0129                         Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
0130                         Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
0131                         Analitza::ExpressionType(Analitza::ExpressionType::Value)))
0132     COORDDINATE_SYSTEM(Cartesian)
0133     PARAMETERS(QStringList(QStringLiteral("y")) << QStringLiteral("z"))
0134     ICON_NAME(QStringLiteral("newfunction3d"))
0135     EXAMPLES(QStringList(QStringLiteral("y+z")))
0136 
0137     QVector3D fromParametricArgs(double u, double v) override;
0138     void update(const QVector3D & oppositecorner1, const QVector3D & oppositecorner2) override;
0139 };
0140 
0141 QVector3D Fyz::fromParametricArgs(double u, double v)
0142 {
0143     arg(QStringLiteral("y"))->setValue(u);
0144     arg(QStringLiteral("z"))->setValue(v);    
0145     
0146     return QVector3D(u,analyzer->calculateLambda().toReal().value(),v);
0147 }
0148 
0149 void Fyz::update(const QVector3D & /*oppositecorner1*/, const QVector3D & /*oppositecorner2*/)
0150 {
0151     buildParametricSurface();
0152 }
0153 
0154 REGISTER_SURFACE(Fyz)