src/qcplot.cpp

00001 /***************************************************************************
00002  *   Quantum Construct (qC++)                                              *
00003  *   The Quantum Physics Computational Library                             *
00004  *   Copyright (C) 2005 by Shekhar S. Chandra                              *
00005  *   Shekhar.Chandra@sci.monash,edu.au                                     *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /*
00023         Ver Info - QCPlot.cpp
00024         1.0.0 - Original Implementation
00025 */
00026 
00027 #include "qcplot.h"
00028 #include <QFile>
00029 #include <QTextStream>
00030 
00031 QCPlot::QCPlot()
00032 {
00033         setTitle("Simulation Plot");
00034         setScale(1,1,10);
00035         setShift(0.15,0,0);
00036         setZoom(1.0);
00037         for (unsigned i=0; i!=coordinates()->axes.size(); ++i)
00038         {
00039                 coordinates()->axes[i].setMajors(7);
00040                 coordinates()->axes[i].setMinors(4);
00041         }
00042         coordinates()->axes[X1].setLabelString("x-axis");
00043         coordinates()->axes[Y1].setLabelString("y-axis");
00044         coordinates()->axes[Z1].setLabelString("z-axis");
00045         setCoordinateStyle(FRAME);
00046         setPlotStyle(FILLED);
00047         showColorLegend(true);
00048         updateData();
00049         updateGL();
00050 }
00051 
00052 QCPlot::~QCPlot()
00053 {
00054         free(ptrField);
00055 }
00056 
00057 void QCPlot::realPartOf(QCComplexField<2> field, double minXRange, double maxXRange, double minYRange, double maxYRange)
00058 {
00059         free(ptrField);
00060         ptrField = (double **)malloc(field.noOfRows() * sizeof(double *));
00061         for(int j = 0; j < field.noOfRows(); j++)
00062                 ptrField[j] = (double *)malloc(field.noOfColumns() * sizeof(double));
00063 
00064         for(int k = 0; k < field.noOfColumns(); k ++)
00065                 for(int j = 0; j < field.noOfRows(); j ++)
00066                         ptrField[j][k] = (double)field.array()(j,k).real();
00067 
00068         loadFromData(ptrField, field.noOfColumns(), field.noOfRows(), minXRange, maxXRange, minYRange, maxYRange);
00069         resize(800,600);
00070 }
00071 
00072 void QCPlot::imagPartOf(QCComplexField<2> field, double minXRange, double maxXRange, double minYRange, double maxYRange)
00073 {
00074         free(ptrField);
00075         ptrField = (double **)malloc(field.noOfRows() * sizeof(double *));
00076         for(int j = 0; j < field.noOfRows(); j++)
00077                 ptrField[j] = (double *)malloc(field.noOfColumns() * sizeof(double));
00078 
00079         for(int k = 0; k < field.noOfColumns(); k ++)
00080                 for(int j = 0; j < field.noOfRows(); j ++)
00081                         ptrField[j][k] = (double)field.array()(j,k).imag();
00082 
00083         loadFromData(ptrField, field.noOfColumns(), field.noOfRows(), minXRange, maxXRange, minYRange, maxYRange);
00084         resize(800,600);
00085 }
00086 
00087 void QCPlot::normOf(QCComplexField<2> field, double minXRange, double maxXRange, double minYRange, double maxYRange)
00088 {
00089         free(ptrField);
00090         ptrField = (double **)malloc(field.noOfRows() * sizeof(double *));
00091         for(int j = 0; j < field.noOfRows(); j++)
00092                 ptrField[j] = (double *)malloc(field.noOfColumns() * sizeof(double));
00093 
00094         for(int k = 0; k < field.noOfColumns(); k ++)
00095                 for(int j = 0; j < field.noOfRows(); j ++)
00096                         ptrField[j][k] = (double)norm(field.array()(j,k));
00097 
00098         loadFromData(ptrField, field.noOfColumns(), field.noOfRows(), minXRange, maxXRange, minYRange, maxYRange);
00099         resize(800,600);
00100 }
00101 
00102 void QCPlot::normOf(QCComplexField<3> field, int slice, double minXRange, double maxXRange, double minYRange, double maxYRange)
00103 {
00104         free(ptrField);
00105         ptrField = (double **)malloc(field.noOfRows() * sizeof(double *));
00106         for(int j = 0; j < field.noOfRows(); j++)
00107                 ptrField[j] = (double *)malloc(field.noOfColumns() * sizeof(double));
00108 
00109         for(int k = 0; k < field.noOfColumns(); k ++)
00110                 for(int j = 0; j < field.noOfRows(); j ++)
00111                         ptrField[j][k] = (double)norm(field.array()(j,k,slice));
00112 
00113         loadFromData(ptrField, field.noOfColumns(), field.noOfRows(), minXRange, maxXRange, minYRange, maxYRange);
00114         resize(800,600);
00115 }
00116 
00117 void QCPlot::phaseOf(QCComplexField<2> field, double minXRange, double maxXRange, double minYRange, double maxYRange)
00118 {
00119         free(ptrField);
00120         ptrField = (double **)malloc(field.noOfRows() * sizeof(double *));
00121         for(int j = 0; j < field.noOfRows(); j++)
00122                 ptrField[j] = (double *)malloc(field.noOfColumns() * sizeof(double));
00123 
00124         for(int k = 0; k < field.noOfColumns(); k ++)
00125                 for(int j = 0; j < field.noOfRows(); j ++)
00126                         ptrField[j][k] = atan2(field.array()(j,k).imag(),field.array()(j,k).real());
00127 
00128         loadFromData(ptrField, field.noOfColumns(), field.noOfRows(), minXRange, maxXRange, minYRange, maxYRange);
00129         resize(800,600);
00130 }
00131 
00132 void QCPlot::phaseOf(QCComplexField<3> field, int slice, double minXRange, double maxXRange, double minYRange, double maxYRange)
00133 {
00134         free(ptrField);
00135         ptrField = (double **)malloc(field.noOfRows() * sizeof(double *));
00136         for(int j = 0; j < field.noOfRows(); j++)
00137                 ptrField[j] = (double *)malloc(field.noOfColumns() * sizeof(double));
00138 
00139         for(int k = 0; k < field.noOfColumns(); k ++)
00140                 for(int j = 0; j < field.noOfRows(); j ++)
00141                         ptrField[j][k] = atan2(field.array()(j,k,slice).imag(),field.array()(j,k,slice).real());
00142 
00143         loadFromData(ptrField, field.noOfColumns(), field.noOfRows(), minXRange, maxXRange, minYRange, maxYRange);
00144         resize(800,600);
00145 }
00146 
00147 void QCPlot::loadFile(QString filename, int rows, int columns, double minXRange, double maxXRange, double minYRange, double maxYRange)
00148 {
00149         /*QFile file(filename);
00150         QFile file2("test.csv");*/
00151         ofstream out("test.csv",ios::out);
00152         ifstream in(filename.toStdString().c_str(),ios::in);
00153         int j = 0, k = 0;
00154         char comma;
00155 
00156         free(ptrField);
00157         ptrField = (double **)malloc(rows * sizeof(double *));
00158         for(int l = 0; l < rows; l++)
00159                 ptrField[l] = (double *)malloc(columns * sizeof(double));
00160 
00161     /*if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
00162         exit(0);
00163     if (!file2.open(QIODevice::WriteOnly | QIODevice::Text))
00164         exit(0);*/
00165 
00166         /*QTextStream in(&file);
00167         QTextStream out(stderr);
00168         in.setRealNumberNotation(QTextStream::ScientificNotation);
00169         out.setRealNumberNotation(QTextStream::ScientificNotation);*/
00170     while (!in.eof() && k < columns)
00171         {
00172                 in >> ptrField[j][k];
00173                 in >> comma;
00174                 out << ptrField[j][k];
00175                 out << comma;
00176                 j ++;
00177                 if (j == rows)
00178                 {
00179                         k ++;
00180                         j = 0;
00181                 }
00182     }
00183 
00184         loadFromData(ptrField, columns, rows, minXRange, maxXRange, minYRange, maxYRange);
00185 }
00186 
00187 void QCPlot::outputPDF(QString filename)
00188 {
00189         save(filename,"PDF");
00190 }
00191 
00192 void QCPlot::outputPS(QString filename)
00193 {
00194         save(filename,"PS");
00195 }
00196 
00197 void QCPlot::outputEPS(QString filename)
00198 {
00199         save(filename,"EPS");
00200 }
00201 

Generated on Sat May 13 13:22:49 2006 for Quantum Construct (qC++) by  doxygen 1.4.6-NO