File indexing completed on 2024-05-05 03:41:15
0001 /************************************************************************************* 0002 * Copyright (C) 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 0023 #include <analitza/value.h> 0024 #include <analitza/vector.h> 0025 0026 #include "private/utils/marchingcubes.h" 0027 0028 using namespace Analitza; 0029 0030 class ImplicitSurf : public AbstractSurface , public MarchingCubes/*, static class? better macros FooClass*/ 0031 { 0032 public: 0033 ImplicitSurf(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v); 0034 0035 TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Implicit Surface")) 0036 EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda) 0037 .addParameter(Analitza::ExpressionType(Analitza::ExpressionType::Value)) 0038 .addParameter(Analitza::ExpressionType(Analitza::ExpressionType::Value)) 0039 .addParameter(Analitza::ExpressionType(Analitza::ExpressionType::Value)) 0040 .addParameter(Analitza::ExpressionType(Analitza::ExpressionType::Value))) 0041 COORDDINATE_SYSTEM(Cartesian) 0042 PARAMETERS(QStringList(QStringLiteral("x")) << QStringLiteral("y") << QStringLiteral("z")) 0043 ICON_NAME(QStringLiteral("draw-square-inverted-corners")) 0044 EXAMPLES(QStringList()) 0045 0046 //Own 0047 ~ImplicitSurf() override { } 0048 void update(const QVector3D & oppositecorner1, const QVector3D & oppositecorner2) override; 0049 0050 double evalScalarField(double x, double y, double z) override; 0051 }; 0052 0053 double ImplicitSurf::evalScalarField(double x, double y, double z) 0054 { 0055 arg(QStringLiteral("x"))->setValue(x); 0056 arg(QStringLiteral("y"))->setValue(y); 0057 arg(QStringLiteral("z"))->setValue(z); 0058 0059 return analyzer->calculateLambda().toReal().value(); 0060 } 0061 0062 0063 ImplicitSurf::ImplicitSurf(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v): AbstractSurface(e, v) 0064 { 0065 0066 } 0067 0068 void ImplicitSurf::update(const QVector3D & /*oppositecorner1*/, const QVector3D & /*oppositecorner2*/) 0069 { 0070 SpaceLimits spaceLimits; 0071 0072 double tmpsize = 6.0; 0073 0074 spaceLimits.minX = -tmpsize; 0075 spaceLimits.maxX = tmpsize; 0076 spaceLimits.minY = -tmpsize; 0077 spaceLimits.maxY = tmpsize; 0078 spaceLimits.minZ = -tmpsize; 0079 spaceLimits.maxZ = tmpsize; 0080 0081 if (hasIntervals()) 0082 { 0083 QPair<double, double> intervalx = interval(QStringLiteral("x")); 0084 QPair<double, double> intervaly = interval(QStringLiteral("y")); 0085 QPair<double, double> intervalz = interval(QStringLiteral("z")); 0086 0087 spaceLimits.minX = intervalx.first; 0088 spaceLimits.maxX = intervalx.second; 0089 spaceLimits.minY = intervaly.first; 0090 spaceLimits.maxY = intervaly.second; 0091 spaceLimits.minZ = intervalz.first; 0092 spaceLimits.maxZ = intervalz.second; 0093 } 0094 0095 0096 setupSpace(spaceLimits); 0097 0098 buildGeometry(); 0099 0100 // qDebug() << "A: " << ntrigs() << nverts(); 0101 0102 //TODO find a better way to avoi this loops 0103 for (int i = 0; i < nverts(); ++i) 0104 { 0105 auto v = vert(i); 0106 0107 vertices.append(QVector3D(v->x, v->y, v->z)); 0108 normals.append(QVector3D(v->nx, v->ny, v->nz)); 0109 } 0110 0111 for (int i = 0; i < ntrigs(); ++i) 0112 { 0113 auto t = trig(i); 0114 indexes << t->v1 << t->v2 << t->v3; 0115 } 0116 } 0117 0118 REGISTER_SURFACE(ImplicitSurf)