File indexing completed on 2024-04-28 11:20:18
0001 /************************************************************************************* 0002 * Copyright (C) 2014 Aleix Pol Gonzalez <aleixpol@kde.org> * 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 <QGuiApplication> 0020 #include <QCommandLineParser> 0021 #include <QFileInfo> 0022 #include <QImage> 0023 #include <analitzaplot/plotter3d_es.h> 0024 #include <analitzaplot/plotsmodel.h> 0025 #include <analitzaplot/plotsfactory.h> 0026 #include <functiongraph.h> 0027 #include <iostream> 0028 0029 using namespace Analitza; 0030 0031 class ExportPlotter3D : public Plotter3DES 0032 { 0033 public: 0034 ExportPlotter3D(PlotsModel* m) : Plotter3DES(m) {} 0035 0036 virtual int currentPlot() const override { return -1; } 0037 virtual void renderGL() override {} 0038 virtual void modelChanged() override {} 0039 QImage grabImage() override { return {}; } 0040 }; 0041 0042 int main(int argc, char** argv) 0043 { 0044 QGuiApplication app(argc, argv); 0045 QCommandLineParser parser; 0046 parser.addPositionalArgument(QStringLiteral("expression"), QGuiApplication::translate("option description", "Expression to plot"), QStringLiteral("expression...")); 0047 parser.addPositionalArgument(QStringLiteral("output"), QGuiApplication::translate("option description", "Created filename"), QStringLiteral("output.x3d")); 0048 parser.addOption(QCommandLineOption(QStringLiteral("interval"), QGuiApplication::translate("option description", "Specifies an interval"), QStringLiteral("var=num..num"))); 0049 parser.addHelpOption(); 0050 0051 parser.process(app); 0052 PlotsModel model; 0053 0054 QMap<QString, QPair<double,double> > intervals; 0055 foreach(const QString& interval, parser.values(QLatin1String("interval"))) { 0056 int equalIdx = interval.indexOf('='); 0057 int dotdotIdx = interval.indexOf(QStringLiteral("..")); 0058 0059 if(equalIdx<0 || dotdotIdx<0) { 0060 qDebug() << "Intervals should be specified as x=b..c"; 0061 } 0062 bool ok; 0063 double from = QStringView(interval).mid(equalIdx+1, dotdotIdx-equalIdx).toDouble(&ok); 0064 Q_ASSERT(ok); 0065 double to = QStringView(interval).mid(dotdotIdx+2).toDouble(&ok); 0066 Q_ASSERT(ok); 0067 intervals[interval.left(equalIdx)] = qMakePair<double, double>(double(from), double(to)); 0068 } 0069 0070 QStringList args = parser.positionalArguments(); 0071 const QString output = args.takeLast(); 0072 0073 foreach(const QString& input, args) { 0074 Expression exp(input); 0075 if(!exp.isCorrect()) { 0076 std::cerr << "Incorrect expression: " << qPrintable(input) << std::endl; 0077 } 0078 PlotBuilder plot = PlotsFactory::self()->requestPlot(exp, Analitza::Dim3D); 0079 if(!plot.canDraw()) { 0080 std::cerr << "Cannot draw " << qPrintable(input) << " in 3D" << std::endl; 0081 return 1; 0082 } 0083 0084 FunctionGraph* it = plot.create(Qt::blue, QStringLiteral("hola")); 0085 foreach(const QString& bvar, plot.expression().bvarList()) { 0086 QMap< QString, QPair< double, double > >::const_iterator itF = intervals.constFind(bvar); 0087 if(itF != intervals.constEnd()) { 0088 it->setInterval(itF.key(), itF->first, itF->second); 0089 } 0090 } 0091 model.addPlot(it); 0092 } 0093 ExportPlotter3D plotter(&model); 0094 plotter.updatePlots(QModelIndex(), 0, model.rowCount()-1); 0095 plotter.exportSurfaces(output); 0096 0097 return 0; 0098 }