diff --git a/graphics/Qat/QatPlotting/QatPlotting/AbsPlotter.h b/graphics/Qat/QatPlotting/QatPlotting/AbsPlotter.h new file mode 100644 index 0000000000000000000000000000000000000000..c7c3d5fbf7b373d8ca80fae4ce5c2ee835335ca7 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/AbsPlotter.h @@ -0,0 +1,84 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------------// +// // +// Abstract base class for plotters // +// // +//----------------------------------------------------------------------------------------// + +#ifndef _ABSPLOTTER_H_ +#define _ABSPLOTTER_H_ + +class Graphic; +class QRectF; +class Plotable; +class QMatrix; +class QGraphicsItemGroup; +class QGraphicsScene; +class AbsPlotter { + +public: + + // Default constructor: + AbsPlotter(); + + // Virtual destructor: + virtual ~AbsPlotter(); + + // Add a plotable: + virtual void add(Plotable *)=0; + + // Get the scene + virtual QGraphicsScene *scene()=0; + + // Get the contents group: + virtual QGraphicsItemGroup *group()=0; + + // Get the transformation matrix. + virtual QMatrix matrix()=0; + + // Set the Plot Rectangle + virtual void setRect(const QRectF & ) = 0; + + // Get the Plot Rectangle: + virtual QRectF * rect() = 0; + virtual const QRectF * rect() const = 0; + + // Clear the Plots, and the rectangle as well: + virtual void clear() = 0; + + // Is this log scale X? + virtual bool isLogX() const=0; + + // Is this log scale Y? + virtual bool isLogY() const=0; + + // Start Animating + virtual void startAnimating(int frameRateMillisec)=0; + + // Stop Animating + virtual void stopAnimating()=0; +}; + +#endif + diff --git a/graphics/Qat/QatPlotting/QatPlotting/LinToLog.h b/graphics/Qat/QatPlotting/QatPlotting/LinToLog.h new file mode 100644 index 0000000000000000000000000000000000000000..2a09e9450860dddb1df6784a996373a1c7b90ba1 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/LinToLog.h @@ -0,0 +1,28 @@ +#ifndef Lin2Log +#define Lin2Log +#include <cmath> +#include <stdexcept> +class LinToLog { + + public: + + // Constructor: + LinToLog(double minVal, double maxVal):a(minVal),b(maxVal) + { + if (a>b) throw std::runtime_error ("Error in logarithmic mapper a>b "); + if (a<=0) throw std::runtime_error ("Error in logarithmic mapper a<=0 "); + c = (a-b)/log(a/b); + } + + double operator () (double x) const { + return a + c*log(x/a); + } + + private: + + double a; + double b; + double c; +}; +#endif + diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotBand1D.h b/graphics/Qat/QatPlotting/QatPlotting/PlotBand1D.h new file mode 100644 index 0000000000000000000000000000000000000000..e42e8ce6c9dae11027f937ade53a13f135d72564 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotBand1D.h @@ -0,0 +1,92 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable adaptor for Function1D's // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTBAND1D_H_ +#define _PLOTBAND1D_H_ +class AbsFunction; +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotBand1DProperties.h" +#include "CLHEP/GenericFunctions/CutBase.hh" +#include <QtCore/QRectF> +#include <vector> +#include <string> +#include <limits.h> + +namespace Genfun { + class AbsFunction; +} + +class PlotBand1D: public Plotable{ + +public: + + // Define Properties: + typedef PlotBand1DProperties Properties; + + // Constructors + PlotBand1D(const Genfun::AbsFunction & function1, + const Genfun::AbsFunction & function2, + const Cut<double> & domainRestriction, + const QRectF & rectHint = QRectF(QPointF(-10, -10), QSizeF(20, 20))); + + // Constructors + PlotBand1D(const Genfun::AbsFunction & function1, + const Genfun::AbsFunction & functino2, + const QRectF & rectHint = QRectF(QPointF(-10, -10), QSizeF(20, 20))); + + // Copy constructor: + PlotBand1D(const PlotBand1D &); + + // Assignment operator: + PlotBand1D & operator=(const PlotBand1D &); + + // Destructor + virtual ~PlotBand1D(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + +private: + + class Clockwork; + Clockwork *c; + + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotBand1DProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotBand1DProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..41ec2f1a71055f8603e165525ec86e6716944f93 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotBand1DProperties.h @@ -0,0 +1,18 @@ +#ifndef _PLOTBAND1DPROPERTIES_H_ +#define _PLOTBAND1DPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> +class PlotBand1DProperties { + + public: + + QPen pen; + QBrush brush; + + + // Construct Default: + PlotBand1DProperties(){} + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotBox.h b/graphics/Qat/QatPlotting/QatPlotting/PlotBox.h new file mode 100644 index 0000000000000000000000000000000000000000..1e92bce15ed1e33f286a0f768e509945f445754c --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotBox.h @@ -0,0 +1,78 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//---------------------------------------------------------------------------// +// // +// Plottable adaptor for Function1D's // +// // +//---------------------------------------------------------------------------// +#ifndef _PLOTBOX_H_ +#define _PLOTBOX_H_ +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotBoxProperties.h" +#include "CLHEP/Matrix/SymMatrix.h" +#include "CLHEP/Matrix/Vector.h" +#include <QtCore/QRectF> + +class PlotBox: public Plotable { + +public: + + // Define Properties: + typedef PlotBoxProperties Properties; + + // Constructors + PlotBox(double x, double y, double dx, double dy); + + // Destructor + virtual ~PlotBox(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + + +private: + + // Copy constructor: + PlotBox(const PlotBox &); + + // Assignment operator: + PlotBox & operator=(const PlotBox &); + + class Clockwork; + Clockwork *c; + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotBoxProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotBoxProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..b7796ac537ffab35d284364fbd9ab0108dcb50bb --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotBoxProperties.h @@ -0,0 +1,20 @@ +#ifndef _PLOTBOXPROPERTIES_H_ +#define _PLOTBOXPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> + +class PlotBoxProperties { + + public: + + + QPen pen; + QBrush brush; + + + // Construct Default: + PlotBoxProperties() {} + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotErrorEllipse.h b/graphics/Qat/QatPlotting/QatPlotting/PlotErrorEllipse.h new file mode 100644 index 0000000000000000000000000000000000000000..369ffab80f37699c4067e83fb03a98d65c82e7c5 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotErrorEllipse.h @@ -0,0 +1,88 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//---------------------------------------------------------------------------// +// // +// Plottable adaptor for Function1D's // +// // +//---------------------------------------------------------------------------// +#ifndef _PLOTERRORELLIPSE_H_ +#define _PLOTERRORELLIPSE_H_ +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotErrorEllipseProperties.h" +#include "CLHEP/Matrix/SymMatrix.h" +#include "CLHEP/Matrix/Vector.h" +#include <QtCore/QRectF> + +class PlotErrorEllipse: public Plotable { + +public: + + enum Style { + ONEUNITCHI2, + ONESIGMA, + TWOSIGMA, + THREESIGMA, + NINETY, + NINETYFIVE, + NINETYNINE }; + + // Define Properties: + typedef PlotErrorEllipseProperties Properties; + + // Constructors + PlotErrorEllipse(double x, double y, double sx2, double sy2, double sxy, Style style=ONESIGMA); + + // Destructor + virtual ~PlotErrorEllipse(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + + + +private: + + // Copy constructor: + PlotErrorEllipse(const PlotErrorEllipse &); + + // Assignment operator: + PlotErrorEllipse & operator=(const PlotErrorEllipse &); + + class Clockwork; + Clockwork *c; + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotErrorEllipseProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotErrorEllipseProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..3e88fe848df8b0d54caf500da5842038e77d65b5 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotErrorEllipseProperties.h @@ -0,0 +1,20 @@ +#ifndef _PLOTERRORELLIPSEPROPERTIES_H_ +#define _PLOTERRORELLIPSEPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> + +class PlotErrorEllipseProperties { + + public: + + + QPen pen; + QBrush brush; + + + // Construct Default: + PlotErrorEllipseProperties() {} + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotFunction1D.h b/graphics/Qat/QatPlotting/QatPlotting/PlotFunction1D.h new file mode 100644 index 0000000000000000000000000000000000000000..3e939b6c4a4b0a993e91daf974d57fc693655f8b --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotFunction1D.h @@ -0,0 +1,91 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable adaptor for Function1D's // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTFUNCTION1D_H_ +#define _PLOTFUNCTION1D_H_ +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotFunction1DProperties.h" +#include "CLHEP/GenericFunctions/CutBase.hh" +#include <QtCore/QRectF> +#include <vector> +#include <string> +#include <limits.h> + +namespace Genfun { + class AbsFunction; + class Parameter; +} + +class PlotFunction1D: public Plotable{ + +public: + + // Define Properties: + typedef PlotFunction1DProperties Properties; + + // Constructors + PlotFunction1D(const Genfun::AbsFunction & function, + const Cut<double> & domainRestriction, + const QRectF & rectHint = QRectF(QPointF(-10, -10), QSizeF(20, 20))); + + // Constructors + PlotFunction1D(const Genfun::AbsFunction & function, + const QRectF & rectHint = QRectF(QPointF(-10, -10), QSizeF(20, 20))); + + // Copy constructor: + PlotFunction1D(const PlotFunction1D &); + + // Assignment operator: + PlotFunction1D & operator=(const PlotFunction1D &); + + // Destructor + virtual ~PlotFunction1D(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + +protected: + + class Clockwork; + Clockwork *c; + + +}; +#include "QatPlotting/PlotFunction1D.icc" +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotFunction1D.icc b/graphics/Qat/QatPlotting/QatPlotting/PlotFunction1D.icc new file mode 100644 index 0000000000000000000000000000000000000000..359b51ef1ae246a7763344e84d49252c8f42252c --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotFunction1D.icc @@ -0,0 +1,101 @@ +#include "QatPlotting/LinToLog.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatDataAnalysis/Query.h" +#include "CLHEP/GenericFunctions/AbsFunction.hh" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <stdexcept> + +class PlotFunction1D::Clockwork { + +public: + + Clockwork() : + function(NULL), + domainRestriction(NULL), + myProperties(NULL) {} + + ~Clockwork() { + delete domainRestriction; + delete function; + } + + static bool intersect(const QRectF * rect, const QPointF & p1, const QPointF & p2, QPointF & p) { + + double min=rect->top(); + double max=rect->bottom(); + double y1=p1.y(); + double y2=p2.y(); + + if (rect->contains(p1) && rect->contains(p2)) { + return false; + } + else if (y1 < min || y2 < min) { + if (QLineF(p1,p2).intersect(QLineF(rect->topLeft(),rect->topRight()),&p)!=QLineF::BoundedIntersection){ + return false; + } + } + else if (y1 > max || y2 > max) { + if (QLineF(p1,p2).intersect(QLineF(rect->bottomLeft(),rect->bottomRight()),&p)!=QLineF::BoundedIntersection){ + return false; + } + } + return true; + } + + static bool maxOut(const QRectF * rect, const QPointF & p1, QPointF & p) { + + double min=rect->top(); + double max=rect->bottom(); + double y1=p1.y(); + + if (rect->contains(p1)) { + if (fabs(y1-max) < fabs(y1-min)) { + p.setX(p1.x()); + p.setY(max); + } + else { + p.setX(p1.x()); + p.setY(min); + } + } + else { + + if (y1>max) { + p.setX(p1.x()); + p.setY(max); + } + else if (y1<min) { + p.setX(p1.x()); + p.setY(min); + } + } + + return true; + } + + static void moveTo(QPainterPath *path, const QMatrix & m, const QPointF & p, const LinToLog *linToLogX=NULL, const LinToLog *linToLogY=NULL) { + double x=p.x(),y=p.y(); + if (linToLogX) x = (*linToLogX)(x); + if (linToLogY) y = (*linToLogY)(y); + + path->moveTo(m.map(QPointF(x,y))); + } + + static void lineTo(QPainterPath *path, const QMatrix & m, const QPointF & p, const LinToLog *linToLogX=NULL, const LinToLog *linToLogY=NULL) { + double x=p.x(),y=p.y(); + if (linToLogX) x = (*linToLogX)(x); + if (linToLogY) y = (*linToLogY)(y); + + path->lineTo(m.map(QPointF(x,y))); + } + + // This is state: + const Genfun::AbsFunction *function; // The function + QRectF rect; // The "natural" bounding rectangle + const Cut<double> *domainRestriction; // Domain restrictions. + Properties *myProperties; // My properties. May + Properties defaultProperties; + +}; diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotFunction1DProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotFunction1DProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..9e919baa03be46617e3d1f5fd848fbd788c636a2 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotFunction1DProperties.h @@ -0,0 +1,20 @@ +#ifndef _PLOTFUNCTION1DPROPERTIES_H_ +#define _PLOTFUNCTION1DPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> +class PlotFunction1DProperties { + + public: + + QPen pen; + QBrush brush; + double baseLine; + + + // Construct Default: + PlotFunction1DProperties(): + baseLine(0.0){} + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotHist1D.h b/graphics/Qat/QatPlotting/QatPlotting/PlotHist1D.h new file mode 100644 index 0000000000000000000000000000000000000000..f7ce6336457e9ee0d0415d85fed13b1efc52b755 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotHist1D.h @@ -0,0 +1,85 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable adaptor for Hist1D's // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTHIST1D_H_ +#define _PLOTHIST1D_H_ +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotHist1DProperties.h" +#include <QtCore/QRectF> +#include <vector> +class Hist1D; +class PlotHist1D: public Plotable { + +public: + + + // Define properties: + typedef PlotHist1DProperties Properties; + + // Constructor + PlotHist1D(const Hist1D &); + + // Copy constructor: + PlotHist1D(const PlotHist1D &); + + // Assignment operator: + PlotHist1D & operator=(const PlotHist1D &); + + // Destructor + virtual ~PlotHist1D(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Get the title: + virtual std::string title() const; + + // Get the text summary: + virtual std::string textSummary() const; + + // Get the histogram: + const Hist1D *histogram() const; + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + +private: + + class Clockwork; + Clockwork *c; + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotHist1DProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotHist1DProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..4bbe7d05be9b6ee6801ea40af103b72ac4a5b3c8 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotHist1DProperties.h @@ -0,0 +1,33 @@ +#ifndef _PLOTHIST1DPROPERTIES_H_ +#define _PLOTHIST1DPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> + +class PlotHist1DProperties { + + public: + + + QPen pen; + QBrush brush; + + enum PlotStyle {LINES, SYMBOLS} plotStyle; + + + enum SymbolStyle {CIRCLE, + SQUARE, + TRIANGLE_U, + TRIANGLE_L} symbolStyle; + + int symbolSize; + + // Construct Default: + PlotHist1DProperties(): + plotStyle(LINES), + symbolStyle(CIRCLE), + symbolSize(5) + {} + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotHist2D.h b/graphics/Qat/QatPlotting/QatPlotting/PlotHist2D.h new file mode 100644 index 0000000000000000000000000000000000000000..a01c9054d7f454eedd5555300c641f6f1b8df641 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotHist2D.h @@ -0,0 +1,79 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable adaptor for Hist2D's // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTHIST2D_H_ +#define _PLOTHIST2D_H_ +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotHist2DProperties.h" +#include <QtCore/QRectF> +#include <vector> +class Hist2D; +class PlotHist2D: public Plotable { + +public: + + + // Define properties: + typedef PlotHist2DProperties Properties; + + // Constructor + PlotHist2D(const Hist2D &); + + // Copy constructor: + PlotHist2D(const PlotHist2D &); + + // Assignment operator: + PlotHist2D & operator=(const PlotHist2D &); + + // Destructor + virtual ~PlotHist2D(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Get the histogram: + const Hist2D *histogram() const; + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + +private: + + class Clockwork; + Clockwork *c; + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotHist2DProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotHist2DProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..9ff80367ca018c8ccf57908e6ac08cf211256507 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotHist2DProperties.h @@ -0,0 +1,20 @@ +#ifndef _PLOTHIST2DPROPERTIES_H_ +#define _PLOTHIST2DPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> + +class PlotHist2DProperties { + + public: + + + QPen pen; + QBrush brush; + + // Construct Default: + PlotHist2DProperties() + {} + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotMeasure.h b/graphics/Qat/QatPlotting/QatPlotting/PlotMeasure.h new file mode 100644 index 0000000000000000000000000000000000000000..5785b533a536ca0a4c2711f1e4f95b56b3a54e1d --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotMeasure.h @@ -0,0 +1,79 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable Measure // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTMEASURE_H_ +#define _PLOTMEASURE_H_ +#include "QatPlotting/Plotable.h" +#include "PlotMeasureProperties.h" +#include <QtCore/QRectF> +#include <vector> +class PlotMeasure: public Plotable { + +public: + + + // Define properties: + typedef PlotMeasureProperties Properties; + + // Constructor + PlotMeasure(); + + // Destructor + virtual ~PlotMeasure(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Add Points: + void addPoint(const QPointF & point, double sizePlus, double sizeMnus); + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + +private: + + // Copy constructor: + PlotMeasure(const PlotMeasure &); + + // Assignment operator: + PlotMeasure & operator=(const PlotMeasure &); + + class Clockwork; + Clockwork *c; + + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotMeasureProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotMeasureProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..5f1f19f67436316fd2832d20cff81192937e0c5e --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotMeasureProperties.h @@ -0,0 +1,28 @@ +#ifndef _PLOTMEASUREPROPERTIES_H_ +#define _PLOTMEASUREPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> + +class PlotMeasureProperties { + + public: + + + QPen pen; + QBrush brush; + enum SymbolStyle {CIRCLE, + SQUARE, + TRIANGLE_U, + TRIANGLE_L} symbolStyle; + + int symbolSize; + + // Construct Default: + PlotMeasureProperties(): + symbolStyle(CIRCLE), + symbolSize(5){ + } + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotOrbit.h b/graphics/Qat/QatPlotting/QatPlotting/PlotOrbit.h new file mode 100644 index 0000000000000000000000000000000000000000..73c78023e87ec4491d8dc33196913ff8a7d44308 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotOrbit.h @@ -0,0 +1,89 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable adaptor for two Function1D's // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTORBIT_H_ +#define _PLOTORBIT_H_ +class AbsFunction; +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotOrbitProperties.h" +#include "CLHEP/GenericFunctions/CutBase.hh" +#include <QtCore/QRectF> +#include <vector> +#include <string> +#include <limits.h> + +namespace Genfun { + class AbsFunction; + class Parameter; +} + +class PlotOrbit: public Plotable{ + +public: + + // Define Properties: + typedef PlotOrbitProperties Properties; + + // Constructors + PlotOrbit(const Genfun::AbsFunction & functionX, + const Genfun::AbsFunction & functionY, + double t0, + double t1); + + // Copy constructor: + PlotOrbit(const PlotOrbit &); + + // Assignment operator: + PlotOrbit & operator=(const PlotOrbit &); + + // Destructor + virtual ~PlotOrbit(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + +protected: + + class Clockwork; + Clockwork *c; + + +}; +#include "QatPlotting/PlotOrbit.icc" +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotOrbit.icc b/graphics/Qat/QatPlotting/QatPlotting/PlotOrbit.icc new file mode 100644 index 0000000000000000000000000000000000000000..83d6e04a878f2b2d43265dbeedb3b7036e5273b8 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotOrbit.icc @@ -0,0 +1,113 @@ +#include "QatPlotting/LinToLog.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatDataAnalysis/Query.h" +#include "CLHEP/GenericFunctions/AbsFunction.hh" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <stdexcept> + +class PlotOrbit::Clockwork { + +public: + + Clockwork() : + functionX(NULL), + functionY(NULL), + t0(0.0), t1(1.0), + myProperties(NULL) {} + + ~Clockwork() { + delete functionX; + delete functionY; + delete myProperties; + } + + +public: + + + static bool intersect(const QRectF * rect, const QPointF & p1, const QPointF & p2, QPointF & p) { + + double min=rect->top(); + double max=rect->bottom(); + double y1=p1.y(); + double y2=p2.y(); + + if (rect->contains(p1) && rect->contains(p2)) { + return false; + } + else if (y1 < min || y2 < min) { + if (QLineF(p1,p2).intersect(QLineF(rect->topLeft(),rect->topRight()),&p)!=QLineF::BoundedIntersection){ + return false; + } + } + else if (y1 > max || y2 > max) { + if (QLineF(p1,p2).intersect(QLineF(rect->bottomLeft(),rect->bottomRight()),&p)!=QLineF::BoundedIntersection){ + return false; + } + } + return true; + } + + static bool maxOut(const QRectF * rect, const QPointF & p1, QPointF & p) { + + double min=rect->top(); + double max=rect->bottom(); + double y1=p1.y(); + + if (rect->contains(p1)) { + if (fabs(y1-max) < fabs(y1-min)) { + p.setX(p1.x()); + p.setY(max); + } + else { + p.setX(p1.x()); + p.setY(min); + } + } + else { + + if (y1>max) { + p.setX(p1.x()); + p.setY(max); + } + else if (y1<min) { + p.setX(p1.x()); + p.setY(min); + } + } + + return true; + } + + static void moveTo(QPainterPath *path, const QMatrix & m, const QPointF & p, const LinToLog *linToLogX=NULL, const LinToLog *linToLogY=NULL) { + double x=p.x(),y=p.y(); + if (linToLogX) x = (*linToLogX)(x); + if (linToLogY) y = (*linToLogY)(y); + + path->moveTo(m.map(QPointF(x,y))); + } + + static void lineTo(QPainterPath *path, const QMatrix & m, const QPointF & p, const LinToLog *linToLogX=NULL, const LinToLog *linToLogY=NULL) { + double x=p.x(),y=p.y(); + if (linToLogX) x = (*linToLogX)(x); + if (linToLogY) y = (*linToLogY)(y); + + path->lineTo(m.map(QPointF(x,y))); + } + + // This is state: + const Genfun::AbsFunction *functionX; // The first function + const Genfun::AbsFunction *functionY; // The second function + QRectF rect; // The "natural" bounding rectangle + double t0,t1; // Start and end times (or parameter values) + Properties *myProperties; // My properties. May + Properties defaultProperties; + +private: + + Clockwork (const Clockwork &); + Clockwork & operator=(const Clockwork &); + +}; diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotOrbitProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotOrbitProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..9a460f7eefa25bef629a19cf4c890a89734b1439 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotOrbitProperties.h @@ -0,0 +1,17 @@ +#ifndef _PLOTORBITPROPERTIES_H_ +#define _PLOTORBITPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> +class PlotOrbitProperties { + + public: + + QPen pen; + + // Construct Default: + PlotOrbitProperties(){} + + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotPoint.h b/graphics/Qat/QatPlotting/QatPlotting/PlotPoint.h new file mode 100644 index 0000000000000000000000000000000000000000..e9ff99d8bc173c11b98bf61ccd832473bd9c92d3 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotPoint.h @@ -0,0 +1,69 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#ifndef _PLOTPOINT_H_ +#define _PLOTPOINT_H_ +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotPointProperties.h" +#include <QtCore/QRectF> + +class PlotPoint: public Plotable { + +public: + + // Define Properties: + typedef PlotPointProperties Properties; + + // Constructors + PlotPoint(double x, double y); + + // Destructor + virtual ~PlotPoint(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + + // Copy constructor: + PlotPoint(const PlotPoint &); + + // Assignment operator: + PlotPoint & operator=(const PlotPoint &); + +private: + + class Clockwork; + Clockwork *c; + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotPointProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotPointProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..0c8da137bd64c48fbb2671fbe6741444cf21f9e8 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotPointProperties.h @@ -0,0 +1,27 @@ +#ifndef _PLOTPOINTPROPERTIES_H_ +#define _PLOTPOINTPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> + +class PlotPointProperties { + + public: + + + QPen pen; + QBrush brush; + enum SymbolStyle {CIRCLE, + SQUARE, + TRIANGLE_U, + TRIANGLE_L} symbolStyle; + + int symbolSize; + + // Construct Default: + PlotPointProperties(): + symbolStyle(CIRCLE), + symbolSize(5){} + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotProfile.h b/graphics/Qat/QatPlotting/QatPlotting/PlotProfile.h new file mode 100644 index 0000000000000000000000000000000000000000..accf04c1c26d2a8de186f0c88f2a230280f8b42d --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotProfile.h @@ -0,0 +1,82 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable Profile // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTPROFILE_H_ +#define _PLOTPROFILE_H_ +#include "QatPlotting/Plotable.h" +#include "PlotProfileProperties.h" +#include <QtCore/QRectF> +#include <vector> +class PlotProfile: public Plotable { + +public: + + + // Define properties: + typedef PlotProfileProperties Properties; + + // Constructor + PlotProfile(); + + // Destructor + virtual ~PlotProfile(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Add Points: + void addPoint(const QPointF & point, double size); + + // Add Points: + void addPoint(const QPointF & point, double errorPlus, double errorMinus); + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + +private: + + // Copy constructor: + PlotProfile(const PlotProfile &); + + // Assignment operator: + PlotProfile & operator=(const PlotProfile &); + + class Clockwork; + Clockwork *c; + + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotProfileProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotProfileProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..34d8bdc05821c4c0d761fec580b915f7ec168f5c --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotProfileProperties.h @@ -0,0 +1,32 @@ +#ifndef _PLOTPROFILEPROPERTIES_H_ +#define _PLOTPROFILEPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> + +class PlotProfileProperties { + + public: + + + QPen pen; + QBrush brush; + enum SymbolStyle {CIRCLE, + SQUARE, + TRIANGLE_U, + TRIANGLE_L} symbolStyle; + + int symbolSize; + int errorBarSize; + bool drawSymbol; + + // Construct Default: + PlotProfileProperties(): + symbolStyle(CIRCLE), + symbolSize(5), + errorBarSize(symbolSize), + drawSymbol(true){ + } + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotRect.h b/graphics/Qat/QatPlotting/QatPlotting/PlotRect.h new file mode 100644 index 0000000000000000000000000000000000000000..95fa7d1943bc8fb9ad473192ef82edbab5bd5da4 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotRect.h @@ -0,0 +1,69 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#ifndef _PLOTRECT_H_ +#define _PLOTRECT_H_ +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotRectProperties.h" +#include <QtCore/QRectF> + +class PlotRect: public Plotable { + +public: + + // Define Properties: + typedef PlotRectProperties Properties; + + // Constructors + PlotRect(const QRectF & rect); + + // Destructor + virtual ~PlotRect(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + + // Copy constructor: + PlotRect(const PlotRect &); + + // Assignment operator: + PlotRect & operator=(const PlotRect &); + +private: + + class Clockwork; + Clockwork *c; + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotRectProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotRectProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..69540e0f05acbe3cb1b1026b453155be340b3d5a --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotRectProperties.h @@ -0,0 +1,19 @@ +#ifndef _PLOTRECTPROPERTIES_H_ +#define _PLOTRECTPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> + +class PlotRectProperties { + + public: + + + QPen pen; + QBrush brush; + + // Construct Default: + PlotRectProperties() {} + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotResidual1D.h b/graphics/Qat/QatPlotting/QatPlotting/PlotResidual1D.h new file mode 100644 index 0000000000000000000000000000000000000000..ac3b46b70aab63c03e7b82ec662571c433f4aa54 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotResidual1D.h @@ -0,0 +1,87 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable adaptor for Residual1D's // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTRESIDUAL1D_H_ +#define _PLOTRESIDUAL1D_H_ +#include "QatPlotting/Plotable.h" +#include "PlotResidual1DProperties.h" +#include "CLHEP/GenericFunctions/AbsFunction.hh" +#include <QtCore/QRectF> +#include <vector> +class Hist1D; + +class PlotResidual1D: public Plotable { + +public: + + + // Define properties: + typedef PlotResidual1DProperties Properties; + + // Constructor + PlotResidual1D(const Hist1D &, Genfun::GENFUNCTION); + + // Copy constructor: + PlotResidual1D(const PlotResidual1D &); + + // Assignment operator: + PlotResidual1D & operator=(const PlotResidual1D &); + + // Destructor + virtual ~PlotResidual1D(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Get the title: + virtual std::string title() const; + + // Get the histogram: + const Hist1D *histogram() const; + + // Get the function: + const Genfun::AbsFunction *function () const; + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + +private: + + class Clockwork; + Clockwork *c; + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotResidual1DProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotResidual1DProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..70c7d703bc9f19d88afc815cca983aac6f14269b --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotResidual1DProperties.h @@ -0,0 +1,27 @@ +#ifndef _PLOTRESIDUAL1DPROPERTIES_H_ +#define _PLOTRESIDUAL1DPROPERTIES_H_ +#include <QtGui/QPen> + +class PlotResidual1DProperties { + + public: + + + QPen pen; + + enum SymbolStyle {CIRCLE, + SQUARE, + TRIANGLE_U, + TRIANGLE_L} symbolStyle; + + int symbolSize; + + // Construct Default: + PlotResidual1DProperties(): + symbolStyle(CIRCLE), + symbolSize(5) + {} + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotShadeBox.h b/graphics/Qat/QatPlotting/QatPlotting/PlotShadeBox.h new file mode 100644 index 0000000000000000000000000000000000000000..3184c5d387f63d03498284293f513b82c64cd5a6 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotShadeBox.h @@ -0,0 +1,82 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable ShadeBox // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTSHADEBOX_H_ +#define _PLOTSHADEBOX_H_ +#include "QatPlotting/Plotable.h" +#include "PlotShadeBoxProperties.h" +#include <QtCore/QRectF> +#include <vector> +class PlotShadeBox: public Plotable { + +public: + + + // Define properties: + typedef PlotShadeBoxProperties Properties; + + // Constructor + PlotShadeBox(); + + // Destructor + virtual ~PlotShadeBox(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Add Points: + void addPoint(const QPointF & point, double size); + + // Add Points: + void addPoint(const QPointF & point, double errorPlus, double errorMinus); + + // Set the properties + void setProperties(const Properties &properties); + + // Revert to default properties: + void resetProperties(); + + // Get the properties (either default, or specific) + const Properties &properties () const; + +private: + + // Copy constructor: + PlotShadeBox(const PlotShadeBox &); + + // Assignment operator: + PlotShadeBox & operator=(const PlotShadeBox &); + + class Clockwork; + Clockwork *c; + + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotShadeBoxProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotShadeBoxProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..e3cbbb3dad6c0656edb462237e242308f2331edb --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotShadeBoxProperties.h @@ -0,0 +1,23 @@ +#ifndef _PLOTSHADEBOXPROPERTIES_H_ +#define _PLOTSHADEBOXPROPERTIES_H_ +#include <QtGui/QPen> +#include <QtGui/QBrush> + +class PlotShadeBoxProperties { + + public: + + + QPen pen; + QBrush brush; + double horizontalSize; + + // Construct Default: + PlotShadeBoxProperties(): + horizontalSize(1.0) + { + } + +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotStream.h b/graphics/Qat/QatPlotting/QatPlotting/PlotStream.h new file mode 100644 index 0000000000000000000000000000000000000000..5185271f45a9a92e212501ad42a968a54d9b8aec --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotStream.h @@ -0,0 +1,221 @@ +#ifndef _PlotStream_h_ +#define _PlotStream_h_ +#include <sstream> +#include <iomanip> +#include <QtGui/QTextEdit> +#include <QtGui/QColor> +#include <string> +// This is a simple class to be used with editable label widgets +class PlotStream { + + public: + + class Clear { + public: + Clear() {} + }; + + class EndP { + public: + EndP() {} + }; + + class Family { + public: + Family(const std::string & name):name(name) {} + std::string name; + }; + + class Size { + public: + Size(unsigned int pointsize):pointsize(pointsize){} + unsigned int pointsize; + }; + + class Super { + public: + Super(){} + }; + + class Sub { + public: + Sub(){} + }; + + class Normal { + public: + Normal(){} + }; + + class Bold { + public: + Bold(){} + }; + + class Regular { + public: + Regular(){} + }; + + class Italic { + public: + Italic(){} + }; + + class Oblique { + public: + Oblique(){} + }; + + class Left { + public: + Left(){} + }; + + class Right { + public: + Right(){} + }; + + class Center { + public: + Center(){} + }; + + class Color { + public: + Color(const QColor &color):color(color){} + QColor color; + }; + + PlotStream (QTextEdit * textEdit):textEdit(textEdit){} + + PlotStream & operator << (const Clear &){ + textEdit->clear(); + stream.str(""); + return *this; + } + PlotStream & operator << (const EndP &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + return *this; + } + PlotStream & operator << (const Family & family){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setFontFamily(QString(family.name.c_str())); + return *this; + } + PlotStream & operator << (const Size & sz){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setFontPointSize(sz.pointsize); + return *this; + } + PlotStream & operator << (const Super &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + QTextCharFormat format=textEdit->currentCharFormat(); + format.setVerticalAlignment(QTextCharFormat::AlignSuperScript); + textEdit->setCurrentCharFormat(format); + return *this; + } + PlotStream & operator << (const Sub &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + QTextCharFormat format=textEdit->currentCharFormat(); + format.setVerticalAlignment(QTextCharFormat::AlignSubScript); + textEdit->setCurrentCharFormat(format); + return *this; + } + + PlotStream & operator << (const Normal &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + QTextCharFormat format=textEdit->currentCharFormat(); + format.setVerticalAlignment(QTextCharFormat::AlignNormal); + textEdit->setCurrentCharFormat(format); + return *this; + } + + PlotStream & operator << (const Left &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setAlignment(Qt::AlignLeft); + return *this; + } + + PlotStream & operator << (const Right &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setAlignment(Qt::AlignRight); + return *this; + } + + PlotStream & operator << (const Center &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setAlignment(Qt::AlignCenter); + return *this; + } + + PlotStream & operator << (const Bold &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setFontWeight(QFont::Bold); + return *this; + } + + PlotStream & operator << (const Regular &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setFontWeight(QFont::Normal); + return *this; + } + + PlotStream & operator << (const Italic &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setFontItalic(true); + return *this; + } + + PlotStream & operator << (const Oblique &){ + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setFontItalic(false); + return *this; + } + + PlotStream & operator << (const Color & color) { + textEdit->insertPlainText(stream.str().c_str()); + stream.str(""); + textEdit->setTextColor(color.color); + return *this; + } + + PlotStream & operator << (const std::string & text) { + stream << text; + return *this; + } + + PlotStream & operator << (const char c) { + stream << c; + return *this; + } + + PlotStream & operator << (double x) { + stream << x; + return *this; + } + + PlotStream & operator << (int i) { + stream << i; + return *this; + } + + QTextEdit *textEdit; + std::ostringstream stream; +}; + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotText.h b/graphics/Qat/QatPlotting/QatPlotting/PlotText.h new file mode 100644 index 0000000000000000000000000000000000000000..4ae22da0eeef1baf7d2674dab706b6360319bfca --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotText.h @@ -0,0 +1,63 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#ifndef _PLOTTEXT_H_ +#define _PLOTTEXT_H_ +#include "QatPlotting/Plotable.h" +#include <QtCore/QRectF> +#include <QtCore/QString> + +class QGraphicsTextItem; +class QTextDocument; + +class PlotText: public Plotable { + +public: + + // Constructors + PlotText(double x, double y, const QString & string=QString("")); + + // Destructor + virtual ~PlotText(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + // Set the document: + void setDocument(QTextDocument *document); + + // Copy constructor: + PlotText(const PlotText &); + + // Assignment operator: + PlotText & operator=(const PlotText &); + +private: + + class Clockwork; + Clockwork *c; + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotWave1D.h b/graphics/Qat/QatPlotting/QatPlotting/PlotWave1D.h new file mode 100644 index 0000000000000000000000000000000000000000..fbded1c95c9804d2df9cc79c49e4ef591f073ed6 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotWave1D.h @@ -0,0 +1,75 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//----------------------------------------------------------------------------------// +// // +// Plottable adaptor for Function1D's // +// // +//----------------------------------------------------------------------------------// +#ifndef _PLOTWAVE1D_H_ +#define _PLOTWAVE1D_H_ +class AbsFunction; +#include "QatPlotting/Plotable.h" +#include "QatPlotting/PlotFunction1D.h" +#include "QatPlotting/PlotWave1DProperties.h" +#include "CLHEP/GenericFunctions/CutBase.hh" +#include <QtCore/QRectF> +#include <vector> +#include <string> +#include <limits.h> + +namespace Genfun { + class AbsFunction; + class Parameter; +} + +class PlotWave1D: public PlotFunction1D{ + +public: + + // Define Properties: + typedef PlotWave1DProperties Properties; + + // Constructors + PlotWave1D(const Genfun::AbsFunction & function, + const Cut<double> & domainRestriction, + const QRectF & rectHint = QRectF(QPointF(-10, -10), QSizeF(20, 20))); + + // Constructors + PlotWave1D(const Genfun::AbsFunction & function, + const QRectF & rectHint = QRectF(QPointF(-10, -10), QSizeF(20, 20))); + + // Copy constructor: + PlotWave1D(const PlotWave1D &); + + // Assignment operator: + PlotWave1D & operator=(const PlotWave1D &); + + // Destructor + virtual ~PlotWave1D(); + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo(AbsPlotter *plotter) const; + + +}; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/PlotWave1DProperties.h b/graphics/Qat/QatPlotting/QatPlotting/PlotWave1DProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..e278571585d9769f1bfd65b4af7a39d7db1f7076 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/PlotWave1DProperties.h @@ -0,0 +1,5 @@ +#ifndef _PLOTWAVE1DPROPERTIES_H_ +#define _PLOTWAVE1DPROPERTIES_H_ +#include "QatPlotting/PlotFunction1DProperties.h" +typedef PlotFunction1DProperties PlotWave1DProperties; +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/Plotable.h b/graphics/Qat/QatPlotting/QatPlotting/Plotable.h new file mode 100644 index 0000000000000000000000000000000000000000..51043a81bbfba85b5b9839970c802142dac19d09 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/Plotable.h @@ -0,0 +1,59 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +//--------------------------------------------------------------------------// +// Class Plotable // +// // +// Joe Boudreau June 2K // +// // +// This class is a base class for all plotable objects. It describes // +// the plottable thing in terms of individual points and connected points // +// (polylines). The plotters can then blindly iterate through their // +// plottables, obtaining their points, scaling them, and plotting them. // +// // +// The plottables also hold the plot styles // +// // +//--------------------------------------------------------------------------// +#ifndef _PLOTABLE_H_ +#define _PLOTABLE_H_ +#include <string> +class QRectF; +class AbsPlotter; +class Plotable { + +public: + + // Constructor + Plotable(); + + // Destructor + virtual ~Plotable(); + + // Get the "natural rectangular border" + virtual const QRectF & rectHint() const=0; + + // Describe to plotter, in terms of primitives: + virtual void describeYourselfTo (AbsPlotter *plotter) const =0; + +}; +#endif + diff --git a/graphics/Qat/QatPlotting/QatPlotting/RealArg.h b/graphics/Qat/QatPlotting/QatPlotting/RealArg.h new file mode 100644 index 0000000000000000000000000000000000000000..bbe613fcd829fb6fd978cb3f2a2a98afff44e40a --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/RealArg.h @@ -0,0 +1,71 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +// ----------------------------------------------------------// +// // +// Set of domain restrictions for 1-D functions: // +// // +// // +// RealArg::Eq(value) // +// RealArg::Gt(value) // +// RealArg::Lt(value) // +// // +// These are useful for specifying where a function is valid // +// i.e. the domain of the function. // +// // +// ----------------------------------------------------------// + +#ifndef _REALARG_HH_ +#define _REALARG_HH_ +#include "CLHEP/GenericFunctions/CutBase.hh" +namespace RealArg { + + class Eq: public Cut<double> { + public: + Eq(double value); + virtual bool operator() (const double & x) const; + virtual Eq *clone() const; + private: + double _value; // value; + }; + + class Gt: public Cut<double> { + public: + Gt(double value); + virtual bool operator() (const double & x) const; + virtual Gt *clone() const; + private: + double _value; // value; + }; + + class Lt: public Cut<double> { + public: + Lt(double value); + virtual bool operator() (const double & x) const; + virtual Lt *clone() const; + private: + double _value; // value; + }; + +} + +#endif diff --git a/graphics/Qat/QatPlotting/QatPlotting/VisFunction.h b/graphics/Qat/QatPlotting/QatPlotting/VisFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..ebb86a707f46e9589682de85b8ac1664ae784a11 --- /dev/null +++ b/graphics/Qat/QatPlotting/QatPlotting/VisFunction.h @@ -0,0 +1,88 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + + +// *-----------------------------------------------------------------*/ +// * A base class for functions to be visualized in the presenter */ +// * ----------------------------------------------------------------*/ +#ifndef VisFunction_h_ +#define VisFunction_h_ +class Plotable; +#include <QtCore/QRectF> +#include <map> +#include <string> +#include "CLHEP/GenericFunctions/Parameter.hh" +#include "CLHEP/GenericFunctions/AbsFunction.hh" +#include "CLHEP/GenericFunctions/CutBase.hh" + +class VisFunction { + +public: + + // Constructor: + VisFunction(const std::string & name); + + // Destructor: + virtual ~VisFunction(); + + // Get the number of parameters: + unsigned int getNumParameters() const; + + // Get the Parameter: + Genfun::Parameter *getParameter(unsigned int i) const; + + // Add a parameter + void addParameter(Genfun::Parameter *parameter); + + // Get the number of functions: + unsigned int getNumFunctions() const; + + // Get the Function + const Genfun::AbsFunction *getFunction(unsigned int i) const; + + // Get the Domain Resctriction (NULL if unrestricted) + const Cut<double> *getDomainRestriction(unsigned int i) const; + + // Add a function. (Clones the function in, also the cut if any). + void addFunction(Genfun::GENFUNCTION f, const Cut<double> *domainRestriction=NULL); + + // Name + const std::string & name() const; + + // Rect Hint + const QRectF & rectHint() const; + + // Rect Hint + QRectF & rectHint(); + + private: + + // Illegal operations: + VisFunction (const VisFunction & ); + VisFunction & operator= (const VisFunction &); + + // Internals: + class Clockwork; + Clockwork *c; + +}; +#endif diff --git a/graphics/Qat/QatPlotting/cmt/requirements b/graphics/Qat/QatPlotting/cmt/requirements new file mode 100644 index 0000000000000000000000000000000000000000..1a3e520b7675cb331e926bec33e0e6f8bb4432a5 --- /dev/null +++ b/graphics/Qat/QatPlotting/cmt/requirements @@ -0,0 +1,19 @@ +package QatPlotting + +author Joe Boudreau +author Vakho Tsulaia + +use AtlasPolicy AtlasPolicy-* +use AtlasCLHEP AtlasCLHEP-* External +use QatDataAnalysis QatDataAnalysis-* graphics/Qat +use VP1Qt VP1Qt-* graphics/VP1 + + +macro_remove CLHEP_linkopts "-lCLHEP-Exceptions-$(CLHEP_native_version)" + +apply_tag notAsNeeded + +apply_pattern qt4based_library + +private + diff --git a/graphics/Qat/QatPlotting/src/AbsPlotter.cpp b/graphics/Qat/QatPlotting/src/AbsPlotter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..944effd2cd1cc8ea4dbfbb9af05968278832396b --- /dev/null +++ b/graphics/Qat/QatPlotting/src/AbsPlotter.cpp @@ -0,0 +1,29 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/AbsPlotter.h" + +AbsPlotter::AbsPlotter() { +} + +AbsPlotter::~AbsPlotter() { +} diff --git a/graphics/Qat/QatPlotting/src/PlotBand1D.cpp b/graphics/Qat/QatPlotting/src/PlotBand1D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c356a221ae87e38e5007d333d2480c92f34f3b3 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotBand1D.cpp @@ -0,0 +1,356 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "CLHEP/GenericFunctions/AbsFunction.hh" +#include "QatPlotting/PlotBand1D.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatPlotting/LinToLog.h" +#include "QatDataAnalysis/Query.h" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <stdexcept> + +class PlotBand1D::Clockwork { + +public: + + Clockwork() : + function1(NULL), + function2(NULL), + domainRestriction(NULL), + myProperties(NULL) {} + + ~Clockwork() { + delete domainRestriction; + delete function1; + delete function2; + } + + static bool intersect(const QRectF * rect, const QPointF & p1, const QPointF & p2, QPointF & p) { + + double min=rect->top(); + double max=rect->bottom(); + double y1=p1.y(); + double y2=p2.y(); + + if (rect->contains(p1) && rect->contains(p2)) { + return false; + } + else if (y1 < min || y2 < min) { + if (QLineF(p1,p2).intersect(QLineF(rect->topLeft(),rect->topRight()),&p)!=QLineF::BoundedIntersection){ + return false; + } + } + else if (y1 > max || y2 > max) { + if (QLineF(p1,p2).intersect(QLineF(rect->bottomLeft(),rect->bottomRight()),&p)!=QLineF::BoundedIntersection){ + return false; + } + } + return true; + } + + static bool maxOut(const QRectF * rect, const QPointF & p1, QPointF & p) { + + double min=rect->top(); + double max=rect->bottom(); + double y1=p1.y(); + + if (rect->contains(p1)) { + p=p1; + return false; + } + + if (y1>max) { + p.setX(p1.x()); + p.setY(max); + } + else if (y1<min) { + p.setX(p1.x()); + p.setY(min); + } + + return true; + } + + static void moveTo(QPainterPath *path, const QMatrix & m, const QPointF & p, const LinToLog *linToLogX=NULL, const LinToLog *linToLogY=NULL) { + double x=p.x(),y=p.y(); + if (linToLogX) x = (*linToLogX)(x); + if (linToLogY) y = (*linToLogY)(y); + + path->moveTo(m.map(QPointF(x,y))); + } + + static void lineTo(QPainterPath *path, const QMatrix & m, const QPointF & p, const LinToLog *linToLogX=NULL, const LinToLog *linToLogY=NULL) { + double x=p.x(),y=p.y(); + if (linToLogX) x = (*linToLogX)(x); + if (linToLogY) y = (*linToLogY)(y); + + path->lineTo(m.map(QPointF(x,y))); + } + + // This is state: + const Genfun::AbsFunction *function1; // The function defining the band. + const Genfun::AbsFunction *function2; // The function defining the band. + QRectF rect; // The "natural" bounding rectangle + const Cut<double> *domainRestriction; // Domain restrictions. + Properties *myProperties; // My properties. May + Properties defaultProperties; + +}; + +// Constructor +PlotBand1D::PlotBand1D(const Genfun::AbsFunction & function1, + const Genfun::AbsFunction & function2, + const QRectF & naturalRectangle): + Plotable(),c(new Clockwork()) +{ + c->function1=function1.clone(); + c->function2=function2.clone(); + c->rect=naturalRectangle; + c->domainRestriction=NULL; +} + +PlotBand1D::PlotBand1D(const Genfun::AbsFunction & function1, + const Genfun::AbsFunction & function2, + const Cut<double> & domainRestriction, + const QRectF & naturalRectangle): + Plotable(),c(new Clockwork()) +{ + c->function1=function1.clone(); + c->function2=function2.clone(); + c->rect=naturalRectangle; + c->domainRestriction=domainRestriction.clone(); +} + +// Copy constructor: +PlotBand1D::PlotBand1D(const PlotBand1D & source): + Plotable(),c(new Clockwork()) +{ + c->function1=source.c->function1->clone(); + c->function2=source.c->function2->clone(); + c->rect=source.c->rect; + c->domainRestriction=source.c->domainRestriction ? source.c->domainRestriction->clone() : NULL; +} + +// Assignment operator: +PlotBand1D & PlotBand1D::operator=(const PlotBand1D & source){ + if (&source!=this) { + c->function1=source.c->function1->clone(); + c->function2=source.c->function2->clone(); + c->rect=source.c->rect; + + delete c->domainRestriction; + c->domainRestriction = source.c->domainRestriction ? source.c->domainRestriction->clone() : NULL; + } + return *this; +} + + +#include <iostream> +// Destructor +PlotBand1D::~PlotBand1D(){ + delete c; +} + + + +const QRectF & PlotBand1D::rectHint() const { + return c->rect; +} + + +// Get the graphic description:: +void PlotBand1D::describeYourselfTo(AbsPlotter *plotter) const { + + + QPen pen = properties().pen; + QBrush brush=properties().brush; + + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + { + unsigned int dim = c->function1->dimensionality(); + if (dim!=1) throw std::runtime_error("PlotBand1D: requires a function of exactly 1 argument"); + } + { + unsigned int dim = c->function2->dimensionality(); + if (dim!=1) throw std::runtime_error("PlotBand1D: requires a function of exactly 1 argument"); + } + + double minX=plotter->rect()->left(), maxX=plotter->rect()->right(); + double minY=plotter->rect()->top(), maxY=plotter->rect()->bottom(); + + + int NPOINTS = 100; + double delta = (maxX-minX)/NPOINTS; + + const LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + const LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + if (brush.style()==Qt::NoBrush) { + for (int b=0;b<2;b++) { + + const Genfun::AbsFunction * function = b==0 ? c->function1: c->function2; + + // Just a line: + + Query<QPointF> cachedPoint; + QPainterPath *path=NULL; + bool empty=true; + for (int i=0; i<NPOINTS+1;i++) { + bool closePath=false; + double x = minX + i*delta; + if (!c->domainRestriction || (*c->domainRestriction)(x)) { // Check that X is in function domain + + double y = (*function) (x); + QPointF point(x,y); + if (y < maxY && y > minY) { // IN RANGE + if (!path) path = new QPainterPath(); + if (empty) { + empty=false; + if (cachedPoint.isValid()) { + QPointF intersection; + Clockwork::intersect(plotter->rect(),cachedPoint, point,intersection); + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + Clockwork::moveTo(path,m, point,toLogX,toLogY); + } + } + else { + Clockwork::lineTo(path,m,point,toLogX, toLogY); + } + } + else { // OUT OF RANGE + if (path) { + if (cachedPoint.isValid()) { + QPointF intersection; + Clockwork::intersect(plotter->rect(),cachedPoint, point,intersection); + Clockwork::lineTo(path,m,intersection,toLogX,toLogY); + } + closePath=true; + empty =true; + } + } + cachedPoint=point; + } + else { // OUT OF DOMAIN + if (path) { + closePath=true; + empty=true; + } + cachedPoint=Query<QPointF>(); + } + if (i==NPOINTS && path) closePath=true; + if (closePath) { + QGraphicsPathItem *polyline=new QGraphicsPathItem(*path); + polyline->setPen(pen); + polyline->setBrush(brush); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + delete path; + path=NULL; + } + } + } + } + else { + // A fill pattern of some sort.. + double yBase=0; + QPainterPath *path=NULL; + bool empty=true; + for (int b=0;b<2;b++) { + for (int i=0; i<NPOINTS+1;i++) { + bool closePath=false; + double x = b ? minX + i*delta : maxX-i*delta; + if (!c->domainRestriction || (*c->domainRestriction)(x)) { // Check that X is in function domain + + double y = b? (*c->function1) (x) : (*c->function2) (x) ; + QPointF point(x,y); + + if (!path) path = new QPainterPath(); + if (empty) { + empty=false; + Clockwork::moveTo(path,m, point, toLogX,toLogY); + } + + + if (y < maxY && y > minY) { // IN RANGE + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { // OUT OF RANGE + QPointF maxOut; + Clockwork::maxOut(plotter->rect(), point,maxOut); + Clockwork::lineTo(path,m,maxOut,toLogX,toLogY); + } + } + else { // OUT OF DOMAIN + if (path) { + closePath=true; + empty=true; + } + } + if (b==1 && i==NPOINTS && path) { + closePath=true; + } + if (closePath) { + QPointF position=mInverse.map(path->currentPosition()); + position.setY(yBase); + Clockwork::lineTo(path,m,position,toLogX,toLogY); + QGraphicsPathItem *polyline=new QGraphicsPathItem(*path); + polyline->setPen(pen); + polyline->setBrush(brush); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + delete path; + path=NULL; + } + } + } + } + delete toLogX; + delete toLogY; +} + + + +const PlotBand1D::Properties & PlotBand1D::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotBand1D::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotBand1D::resetProperties() { + delete c->myProperties; +} diff --git a/graphics/Qat/QatPlotting/src/PlotBox.cpp b/graphics/Qat/QatPlotting/src/PlotBox.cpp new file mode 100644 index 0000000000000000000000000000000000000000..434354f9e8cb8d617630e057d1ec13d77c73d3bc --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotBox.cpp @@ -0,0 +1,140 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotBox.h" +#include "QatPlotting/AbsPlotter.h" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsItemGroup> +#include <iostream> +#include <iomanip> +#include <sstream> + +class PlotBox::Clockwork { + + public: + + Clockwork():myProperties(NULL) {} + ~Clockwork() { delete myProperties;} + + + + QRectF rectangle; // The "natural" bounding rectangle + Properties *myProperties; + Properties defaultProperties; + double x,y,dx,dy; +}; + +// Constructor +PlotBox::PlotBox(double x, double y, double dx, double dy) + + :Plotable(),c(new Clockwork()) + +{ + c->rectangle=QRectF(QPointF(x,y),QSizeF(2*dx, 2*dy)); + c->x=x; + c->y=y; + c->dx=dx; + c->dy=dy; +} + + + +// Destructor +PlotBox::~PlotBox(){ + delete c; +} + + +// Get the "natural maximum R" +const QRectF & PlotBox::rectHint() const { + return c->rectangle; +} + + + +// Describe to plotter, in terms of primitives: +void PlotBox::describeYourselfTo(AbsPlotter *plotter) const{ + if (plotter->isLogY()) return; + if (plotter->isLogX()) return; + + QPen pen =properties().pen; + QBrush brush=properties().brush; + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + QPainterPath path; + bool started=false; + static CLHEP::HepVector U0(2); U0[0]=+c->dx; U0[1]=+c->dy; + static CLHEP::HepVector U1(2); U1[0]=+c->dx; U1[1]=-c->dy; + static CLHEP::HepVector U2(2); U2[0]=-c->dx; U2[1]=-c->dy; + static CLHEP::HepVector U3(2); U3[0]=-c->dx; U3[1]=+c->dy; + for (int i=0;i<5;i++) { + CLHEP::HepVector V(2); + V[0]=c->x; + V[1]=c->y; + if (i==0) V+=U0; + if (i==1) V+=U1; + if (i==2) V+=U2; + if (i==3) V+=U3; + if (i==4) V+=U0; + if (plotter->rect()->contains(QPointF(V[0],V[1]))){ + double x = V[0]; + double y = V[1]; + if (!started) { + started=true; + path.moveTo(m.map(QPointF(x,y))); + } + else { + path.lineTo(m.map(QPointF(x,y))); + } + } + } + + QGraphicsPathItem *polyline=new QGraphicsPathItem(path); + polyline->setPen(pen); + polyline->setBrush(brush); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + +} + + + +const PlotBox::Properties & PlotBox::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotBox::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotBox::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotErrorEllipse.cpp b/graphics/Qat/QatPlotting/src/PlotErrorEllipse.cpp new file mode 100644 index 0000000000000000000000000000000000000000..94fcb9b34bbb7613d161e2020b877e33ed11ee88 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotErrorEllipse.cpp @@ -0,0 +1,208 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotErrorEllipse.h" +#include "QatPlotting/AbsPlotter.h" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsItemGroup> +#include <iostream> +#include <iomanip> +#include <sstream> + +class PlotErrorEllipse::Clockwork { + + public: + + Clockwork():myProperties(NULL) {} + ~Clockwork() { delete myProperties;} + + + CLHEP::HepVector X; + CLHEP::HepVector U0; + CLHEP::HepVector U1; + QRectF nRectangle; // The "natural" bounding rectangle + Properties *myProperties; + Properties defaultProperties; + Style style; +}; + +// Constructor +PlotErrorEllipse::PlotErrorEllipse( + double x, double y, + double sx2, double sy2, double sxy, Style style) + :Plotable(),c(new Clockwork()) + +{ + c->X=CLHEP::HepVector(2); + c->U0=CLHEP::HepVector(2); + c->U1=CLHEP::HepVector(2); + c->style=style; + + CLHEP::HepSymMatrix M(2); + M[0][0]=sx2; + M[0][1]=sxy; + M[1][1]=sy2; + + c->X[0]=x; + c->X[1]=y; + double T = M.trace(); + double D = M.determinant(); + double L0 = (T+sqrt(T*T-4*D))/2.0; + double L1 = (T-sqrt(T*T-4*D))/2.0; + + if (sxy!=0) { + c->U0[0]=1; + c->U0[1]=(L0-sx2)/sxy; + c->U1[0]=1; + c->U1[1]=(L1-sx2)/sxy; + c->U0 /= c->U0.norm(); + c->U1 /= c->U1.norm(); + c->U0 *= sqrt(L0); + c->U1 *= sqrt(L1); + } + else { + c->U0[0]=sqrt(sx2); + c->U0[1]=0; + c->U1[0]=0; + c->U1[1]=sqrt(sy2); + } + + double factor=0; + if (c->style==ONEUNITCHI2) { + factor=1; + } + else if (c->style==ONESIGMA) { + factor=sqrt(2.30); + } + else if (c->style==TWOSIGMA) { + factor=sqrt(6.18); + } + else if (c->style==THREESIGMA) { + factor=sqrt(11.83); + } + else if (c->style==NINETY) { + factor=sqrt(4.61); + } + else if (c->style==NINETYFIVE) { + factor=sqrt(5.99); + } + else if (c->style==NINETYNINE) { + factor=sqrt(9.21); + } + + c->U0 *= factor; // For 68% confidence: + c->U1 *= factor; // For 68% confidence; + + // Now make the bounding box: + double minX=1E-30,maxX=-1E30; + double minY=1E-30,maxY=-1E30; + if (c->U0[0]>maxX) maxX=c->U0[0]; + if (c->U0[0]<minX) minX=c->U0[0]; + if (c->U1[0]>maxX) maxX=c->U1[0]; + if (c->U1[0]<minX) minX=c->U1[0]; + if (c->U0[1]>maxY) maxY=c->U0[1]; + if (c->U0[1]<minY) minY=c->U0[1]; + if (c->U1[1]>maxY) maxY=c->U1[1]; + if (c->U1[1]<minY) minY=c->U1[1]; + + minX += x; + maxX += x; + minY += y; + maxY += y; + // c->nRectangle=QRectF(QPointF(minX-(maxX-minX)/2.0,minY+(maxY-minY)/2.0),QSizeF(maxX-minX, maxY-minY)); + double max = std::max(c->U0.norm(),c->U1.norm()); + + c->nRectangle=QRectF(c->X[0]-2*max, c->X[1]-2*max, 4*max, 4*max); + +} + + + +// Destructor +PlotErrorEllipse::~PlotErrorEllipse(){ + delete c; +} + + +// Get the "natural maximum R" +const QRectF & PlotErrorEllipse::rectHint() const { + return c->nRectangle; +} + + + +// Describe to plotter, in terms of primitives: +void PlotErrorEllipse::describeYourselfTo(AbsPlotter *plotter) const{ + if (plotter->isLogY()) return; + if (plotter->isLogX()) return; + + QPen pen =properties().pen; + QBrush brush=properties().brush; + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + QPainterPath path; + bool started=false; + for (int i=0;i<360;i++) { + CLHEP::HepVector V=c->U0*sin(2*M_PI*i/360.0) + c->U1*cos(2*M_PI*i/360.0)+c->X; + if (plotter->rect()->contains(QPointF(V[0],V[1]))){ + double x = V[0]; + double y = V[1]; + if (!started) { + started=true; + path.moveTo(m.map(QPointF(x,y))); + } + else { + path.lineTo(m.map(QPointF(x,y))); + } + } + } + + QGraphicsPathItem *polyline=new QGraphicsPathItem(path); + polyline->setPen(pen); + polyline->setBrush(brush); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + +} + + + +const PlotErrorEllipse::Properties & PlotErrorEllipse::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotErrorEllipse::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotErrorEllipse::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotFunction1D.cpp b/graphics/Qat/QatPlotting/src/PlotFunction1D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a3def26837b672a533a466b8e32ed54bb49002e9 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotFunction1D.cpp @@ -0,0 +1,273 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotFunction1D.h" +#include "CLHEP/GenericFunctions/AbsFunction.hh" +#include "QatPlotting/AbsPlotter.h" + +#include "QatDataAnalysis/Query.h" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <stdexcept> + + +// Constructor +PlotFunction1D::PlotFunction1D(const Genfun::AbsFunction & function, + const QRectF & naturalRectangle): + Plotable(),c(new Clockwork()) +{ + c->function=function.clone(); + c->rect=naturalRectangle; + c->domainRestriction=NULL; +} + +PlotFunction1D::PlotFunction1D(const Genfun::AbsFunction & function, + const Cut<double> & domainRestriction, + const QRectF & naturalRectangle): + Plotable(),c(new Clockwork()) +{ + c->function=function.clone(); + c->rect=naturalRectangle; + c->domainRestriction=domainRestriction.clone(); +} + +// Copy constructor: +PlotFunction1D::PlotFunction1D(const PlotFunction1D & source): + Plotable(),c(new Clockwork()) +{ + c->function=source.c->function->clone(); + c->rect=source.c->rect; + c->domainRestriction=source.c->domainRestriction ? source.c->domainRestriction->clone() : NULL; +} + +// Assignment operator: +PlotFunction1D & PlotFunction1D::operator=(const PlotFunction1D & source){ + if (&source!=this) { + c->function=source.c->function->clone(); + c->rect=source.c->rect; + + delete c->domainRestriction; + c->domainRestriction = source.c->domainRestriction ? source.c->domainRestriction->clone() : NULL; + } + return *this; +} + + +#include <iostream> +// Destructor +PlotFunction1D::~PlotFunction1D(){ + delete c; +} + + + +const QRectF & PlotFunction1D::rectHint() const { + return c->rect; +} + + +// Get the graphic description:: +void PlotFunction1D::describeYourselfTo(AbsPlotter *plotter) const { + + + QPen pen = properties().pen; + QBrush brush=properties().brush; + + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + unsigned int dim = c->function->dimensionality(); + if (dim!=1) throw std::runtime_error("PlotFunction1D: requires a function of exactly 1 argument"); + + double minX=plotter->rect()->left(), maxX=plotter->rect()->right(); + double minY=plotter->rect()->top(), maxY=plotter->rect()->bottom(); + + + int NPOINTS = 100; + double delta = (maxX-minX)/NPOINTS; + + const LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + const LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + if (brush.style()==Qt::NoBrush) { + // Just a line: + + Query<QPointF> cachedPoint; + QPainterPath *path=NULL; + bool empty=true; + for (int i=0; i<NPOINTS+1;i++) { + bool closePath=false; + double x = minX + i*delta; + double y=0; + if ((!c->domainRestriction || (*c->domainRestriction)(x)) && finite((y=(*c->function)(x)))) { // Check that X is in function domain + + //double y = (*c->function) (x); + QPointF point(x,y); + if (y < maxY && y > minY) { // IN RANGE + if (!path) path = new QPainterPath(); + if (empty) { + empty=false; + if (cachedPoint.isValid()) { + QPointF intersection; + if (Clockwork::intersect(plotter->rect(),cachedPoint, point,intersection)) { + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + if (Clockwork::maxOut(plotter->rect(), point, intersection)) { + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + std::cerr << "Intersection is failing" << std::endl; + } + } + } + else { + Clockwork::moveTo(path,m, point,toLogX,toLogY); + } + } + else { + Clockwork::lineTo(path,m,point,toLogX, toLogY); + } + } + else { // OUT OF RANGE + if (path) { + if (cachedPoint.isValid()) { + QPointF intersection; + if (Clockwork::intersect(plotter->rect(),cachedPoint, point,intersection)) { + Clockwork::lineTo(path,m,intersection,toLogX,toLogY); + } + else { + if (Clockwork::maxOut(plotter->rect(), point, intersection)) { + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + std::cerr << "Intersection is failing" << std::endl; + } + } + } + closePath=true; + empty =true; + } + } + cachedPoint=point; + } + else { // OUT OF DOMAIN + if (path) { + closePath=true; + empty=true; + } + cachedPoint=Query<QPointF>(); + } + if (i==NPOINTS && path) closePath=true; + if (closePath) { + QGraphicsPathItem *polyline=new QGraphicsPathItem(*path); + polyline->setPen(pen); + polyline->setBrush(brush); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + delete path; + path=NULL; + } + } + } + else { + // A fill pattern of some sort.. + double yBase=std::max(std::min(maxY, properties().baseLine),minY); + + QPainterPath *path=NULL; + bool empty=true; + for (int i=0; i<NPOINTS+1;i++) { + bool closePath=false; + double x = minX + i*delta; + double y=0; + if ((!c->domainRestriction || (*c->domainRestriction)(x)) && finite((y=(*c->function)(x)))) { // Check that X is in function domain + + //double y = (*c->function) (x); + QPointF point(x,y); + + if (!path) path = new QPainterPath(); + if (empty) { + empty=false; + QPointF intersection; + Clockwork::moveTo(path,m, QPointF(x,yBase), toLogX,toLogY); + } + + + if (y < maxY && y > minY) { // IN RANGE + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { // OUT OF RANGE + QPointF maxOut; + Clockwork::maxOut(plotter->rect(), point,maxOut); + Clockwork::lineTo(path,m,maxOut,toLogX,toLogY); + } + } + else { // OUT OF DOMAIN + if (path) { + closePath=true; + empty=true; + } + } + if (i==NPOINTS && path) { + closePath=true; + } + if (closePath) { + QPointF position=mInverse.map(path->currentPosition()); + position.setY(yBase); + Clockwork::lineTo(path,m,position,toLogX,toLogY); + QGraphicsPathItem *polyline=new QGraphicsPathItem(*path); + polyline->setPen(pen); + polyline->setBrush(brush); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + delete path; + path=NULL; + } + } + } + delete toLogX; + delete toLogY; +} + + +const PlotFunction1D::Properties & PlotFunction1D::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotFunction1D::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotFunction1D::resetProperties() { + delete c->myProperties; +} diff --git a/graphics/Qat/QatPlotting/src/PlotHist1D.cpp b/graphics/Qat/QatPlotting/src/PlotHist1D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..20f6d71450e65ab1bbbf7178b16097478fbc61a9 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotHist1D.cpp @@ -0,0 +1,416 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatDataAnalysis/Hist1D.h" +#include "QatPlotting/PlotHist1D.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatPlotting/LinToLog.h" +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsEllipseItem> +#include <QtGui/QGraphicsPolygonItem> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsItemGroup> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsPathItem> +#include <iostream> +#include <iomanip> +#include <sstream> +#include <cfloat> +// Constructor + +class PlotHist1D::Clockwork { +public: + + Clockwork() : histogram(NULL), + myProperties(NULL) {} + + ~Clockwork() {delete myProperties;} + + // This is state: + const Hist1D *histogram; // The histogram + QRectF nRectangle; // The "natural" bounding rectangle + Properties *myProperties; // My properties. May + Properties defaultProperties; +}; + + +PlotHist1D::PlotHist1D(const Hist1D & histogram): + Plotable(),c(new Clockwork()) +{ + + c->histogram=&histogram; + + double yMin=FLT_MAX; + double yMax=FLT_MIN; + for (unsigned int i=0;i<histogram.nBins();i++) { + double yplus = histogram.bin(i) + histogram.binError(i); + double yminus = histogram.bin(i) - histogram.binError(i); + yMin = std::min(yMin,yminus); + yMax = std::max(yMax,yplus); + } + + double dist = yMax-yMin; + double marge = dist/10; + yMax += marge; + if (yMin>0) { + yMin=0; + } + else if (yMin<0) { + yMin-=marge; + } + + QPointF lowerRight(c->histogram->min(),yMin); + QPointF upperLeft (c->histogram->max(),yMax); + c->nRectangle.setLeft (histogram.min()); + c->nRectangle.setRight(histogram.max()); + c->nRectangle.setTop(yMin); + c->nRectangle.setBottom(yMax); +} + +// Copy constructor: +PlotHist1D::PlotHist1D(const PlotHist1D & source): + Plotable(),c(new Clockwork()) +{ + c->histogram=source.c->histogram; + c->nRectangle=source.c->nRectangle; + if (source.c->myProperties) c->myProperties = new Properties(*source.c->myProperties); + +} + +// Assignment operator: +PlotHist1D & PlotHist1D::operator=(const PlotHist1D & source) +{ + if (&source!=this) { + c->histogram=source.c->histogram; + c->nRectangle=source.c->nRectangle; + delete c->myProperties; + if (source.c->myProperties) { + c->myProperties = new Properties(*source.c->myProperties); + } + else { + c->myProperties=NULL; + } + } + return *this; +} + + +// Destructor +PlotHist1D::~PlotHist1D(){ + delete c; +} + + +const QRectF & PlotHist1D::rectHint() const { + + double yMin=FLT_MAX; + double yMax=FLT_MIN; + for (unsigned int i=0;i<c->histogram->nBins();i++) { + double yplus = c->histogram->bin(i) + c->histogram->binError(i); + double yminus = c->histogram->bin(i) - c->histogram->binError(i); + yMin = std::min(yMin,yminus); + yMax = std::max(yMax,yplus); + } + + c->nRectangle.setLeft (c->histogram->min()); + c->nRectangle.setRight(c->histogram->max()); + c->nRectangle.setTop(yMin); + c->nRectangle.setBottom(yMax); + return c->nRectangle; +} + + +// Get the graphic description:: +void PlotHist1D::describeYourselfTo(AbsPlotter *plotter) const { + QPen pen =properties().pen; + QBrush brush=properties().brush; + int symbolSize=properties().symbolSize; + PlotHist1D::Properties::SymbolStyle symbolStyle=properties().symbolStyle; + + LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + if (properties().plotStyle==PlotHist1DProperties::SYMBOLS) { + + for (unsigned int i=0;i<c->histogram->nBins();i++) { + double x = plotter->isLogX() ? (*toLogX) (c->histogram->binCenter(i)) : c->histogram->binCenter(i); + double y = plotter->isLogY() ? (*toLogY) (c->histogram->bin(i)) : c->histogram->bin(i); + double ydyp = plotter->isLogY() ? (*toLogY)(c->histogram->bin(i)+c->histogram->binError(i)) : c->histogram->bin(i)+c->histogram->binError(i); + double ydym = plotter->isLogY() ? (*toLogY)(c->histogram->bin(i)-c->histogram->binError(i)) : c->histogram->bin(i)-c->histogram->binError(i); + + if (plotter->isLogY() && !finite(ydym)) ydym=plotter->rect()->top()+FLT_MIN; + + QPointF loc(x, y ); + QSizeF siz(symbolSize,symbolSize); + QPointF ctr(siz.width()/2.0, siz.height()/2.0); + QPointF had(siz.width()/2.0, 0); + QPointF vad(0,siz.height()/2.0); + + QPointF plus(x,ydyp); + QPointF mnus(x,ydym); + + if (plotter->rect()->contains(loc)) { + QAbstractGraphicsShapeItem *shape=NULL; + if (symbolStyle==PlotHist1D::Properties::CIRCLE) { + shape = new QGraphicsEllipseItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==PlotHist1D::Properties::SQUARE) { + shape = new QGraphicsRectItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==PlotHist1D::Properties::TRIANGLE_U) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2,0))); + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else if (symbolStyle==PlotHist1D::Properties::TRIANGLE_L) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2, symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else { + throw std::runtime_error("In PlotHist1D: unknown plot symbol"); + } + + shape->setPen(pen); + shape->setBrush(brush); + shape->setMatrix(mInverse); + plotter->scene()->addItem(shape); + plotter->group()->addToGroup(shape); + + { + QLineF pLine(m.map(loc)-vad, m.map(plus)); + if (plotter->rect()->contains(plus)) { + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *topLine=new QGraphicsLineItem(QLineF(m.map(plus)+had,m.map(plus)-had)); + topLine->setPen(pen); + topLine->setMatrix(mInverse); + plotter->scene()->addItem(topLine); + plotter->group()->addToGroup(topLine); + + } + else { + QPointF intersection; + QLineF bottomLine(plotter->rect()->bottomLeft(),plotter->rect()->bottomRight()); + QLineF::IntersectType type=bottomLine.intersect(QLineF(loc,plus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF plus=intersection; + QLineF pLine(m.map(loc)-vad, m.map(plus)); + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + } + } + } + + { + QLineF mLine(m.map(loc)+vad, m.map(mnus)); + if (plotter->rect()->contains(mnus)) { + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *bottomLine=new QGraphicsLineItem(QLineF(m.map(mnus)+had,m.map(mnus)-had)); + bottomLine->setPen(pen); + bottomLine->setMatrix(mInverse); + plotter->scene()->addItem(bottomLine); + plotter->group()->addToGroup(bottomLine); + + } + else { + QPointF intersection; + QLineF topLine(plotter->rect()->topLeft(),plotter->rect()->topRight()); + QLineF::IntersectType type=topLine.intersect(QLineF(loc,mnus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF mnus=intersection; + QLineF mLine(m.map(loc)+vad, m.map(mnus)); + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + } + } + } + + + } + else if (plotter->rect()->contains(mnus)) { + QPointF intersection; + QLineF bottomLine(plotter->rect()->bottomLeft(),plotter->rect()->bottomRight()); + QLineF::IntersectType type=bottomLine.intersect(QLineF(loc,mnus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF loc=intersection; + QLineF mLine(m.map(loc), m.map(mnus)); + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *bottomLine=new QGraphicsLineItem(QLineF(m.map(mnus)+had,m.map(mnus)-had)); + bottomLine->setPen(pen); + bottomLine->setMatrix(mInverse); + plotter->scene()->addItem(bottomLine); + plotter->group()->addToGroup(bottomLine); + + } + } + else if (plotter->rect()->contains(plus)) { + QPointF intersection; + QLineF topLine(plotter->rect()->topLeft(),plotter->rect()->topRight()); + QLineF::IntersectType type=topLine.intersect(QLineF(loc,plus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF loc=intersection; + QLineF pLine(m.map(loc), m.map(plus)); + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *topLine=new QGraphicsLineItem(QLineF(m.map(plus)+had,m.map(plus)-had)); + topLine->setPen(pen); + topLine->setMatrix(mInverse); + plotter->scene()->addItem(topLine); + plotter->group()->addToGroup(topLine); + + } + } + } + } + else { // LINES + + QPainterPath path; + + double maxY=plotter->rect()->bottom(); + double minY=plotter->rect()->top(); + double minX=plotter->rect()->left(); + double maxX=plotter->rect()->right(); + bool started=false; + for (unsigned int i=0;i<c->histogram->nBins();i++) { + double y = plotter->isLogY() ? (*toLogY) (c->histogram->bin(i)) : c->histogram->bin(i); + if (plotter->isLogY() && !finite(y)) y=minY; + double binLow = c->histogram->binLowerEdge(i); + double binHi = c->histogram->binUpperEdge(i); + if (toLogX) binLow=(*toLogX)(binLow); + if (toLogX) binHi =(*toLogX)(binHi); + + + double yEff=std::max(std::min(maxY, y),minY); + double zEff=std::max(std::min(maxY,0.0),minY); + QPointF lowerPoint(binLow, yEff); + QPointF upperPoint(binHi, yEff); + if ( binHi >= minX && binLow <= maxX ) { + if (!started) { + started=true; + if (binLow > minX) { + path.moveTo(m.map(QPointF(binLow,zEff))); + path.lineTo(m.map(lowerPoint)); + path.lineTo(m.map(upperPoint)); + } + else { + path.moveTo(m.map(QPointF(minX,zEff))); + path.lineTo(m.map(QPointF(minX,yEff))); + path.lineTo(m.map(upperPoint)); + } + } + else if (binHi>=maxX) { + path.lineTo(m.map(lowerPoint)); + path.lineTo(m.map(QPointF(maxX,yEff))); + path.lineTo(m.map(QPointF(maxX,zEff))); + } + else { + path.lineTo(m.map(lowerPoint)); + path.lineTo(m.map(upperPoint)); + } + // AND: + if (i==c->histogram->nBins()-1) { + path.lineTo(m.map(QPointF(binHi,zEff))); + } + } + } + QGraphicsPathItem *polyline=new QGraphicsPathItem(path); + polyline->setPen(pen); + polyline->setBrush(brush); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + } + + delete toLogX; + delete toLogY; +} + +std::string PlotHist1D::title() const { + return c->histogram->name(); +} + +std::string PlotHist1D::textSummary() const { + std::ostringstream textSummaryStream; + textSummaryStream << std::setprecision(3) << std::showpoint << std::setfill(' '); + textSummaryStream << "Area: " << std::setw(9) << c->histogram->sum() << '\t' + << "Mean: " << std::setw(9) << c->histogram->mean() << '\t' + << "Sigma:" << std::setw(8) << sqrt(c->histogram->variance()) << '\t'; + return textSummaryStream.str(); +} + +// Get the histogram: +const Hist1D *PlotHist1D::histogram() const { + return c->histogram; +} + +const PlotHist1D::Properties & PlotHist1D::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotHist1D::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotHist1D::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotHist2D.cpp b/graphics/Qat/QatPlotting/src/PlotHist2D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ed1d9d03917c89d3928d82a660d4573de0c04f3 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotHist2D.cpp @@ -0,0 +1,192 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatDataAnalysis/Hist2D.h" +#include "QatPlotting/PlotHist2D.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatPlotting/LinToLog.h" +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsEllipseItem> +#include <QtGui/QGraphicsPolygonItem> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsItemGroup> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsPathItem> +#include <iostream> +#include <iomanip> +#include <sstream> +#include <cfloat> +// Constructor + +class PlotHist2D::Clockwork { +public: + + Clockwork() : histogram(NULL), + myProperties(NULL) {} + + ~Clockwork() {delete myProperties;} + + // This is state: + const Hist2D *histogram; // The histogram + QRectF nRectangle; // The "natural" bounding rectangle + Properties *myProperties; // My properties. May + Properties defaultProperties; +}; + + +PlotHist2D::PlotHist2D(const Hist2D & histogram): + Plotable(),c(new Clockwork()) +{ + + c->histogram=&histogram; + + c->nRectangle.setLeft (histogram.minX()); + c->nRectangle.setRight(histogram.maxX()); + c->nRectangle.setTop(histogram.minY()); + c->nRectangle.setBottom(histogram.maxY()); +} + +// Copy constructor: +PlotHist2D::PlotHist2D(const PlotHist2D & source): + Plotable(),c(new Clockwork()) +{ + c->histogram=source.c->histogram; + c->nRectangle=source.c->nRectangle; + if (source.c->myProperties) c->myProperties = new Properties(*source.c->myProperties); + +} + +// Assignment operator: +PlotHist2D & PlotHist2D::operator=(const PlotHist2D & source) +{ + if (&source!=this) { + c->histogram=source.c->histogram; + c->nRectangle=source.c->nRectangle; + delete c->myProperties; + if (source.c->myProperties) { + c->myProperties = new Properties(*source.c->myProperties); + } + else { + c->myProperties=NULL; + } + } + return *this; +} + + +// Destructor +PlotHist2D::~PlotHist2D(){ + delete c; +} + + +const QRectF & PlotHist2D::rectHint() const { + return c->nRectangle; +} + + +// Get the graphic description:: +void PlotHist2D::describeYourselfTo(AbsPlotter *plotter) const { + QPen pen =properties().pen; + QBrush brush=properties().brush; + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + if (plotter->isLogX()) return; + if (plotter->isLogY()) return; + + + double max = c->histogram->maxContents(); + for (unsigned int i=0;i<c->histogram->nBinsX();i++) { + for (unsigned int j=0;j<c->histogram->nBinsY();j++) { + + double bin = c->histogram->bin(i,j); + if (bin==0) continue; + + double x = c->histogram->binCenterX(i,j); + double y = c->histogram->binCenterY(i,j); + double wx = c->histogram->binWidthX(); + double wy = c->histogram->binWidthY(); + + double frac = bin/(max); + double sqfrac = sqrt(frac); + + double minX = x - wx*sqfrac/2.0; + double maxX = x + wx*sqfrac/2.0; + double minY = y - wy*sqfrac/2.0; + double maxY = y + wy*sqfrac/2.0; + + if (plotter->rect()->contains(QPointF(minX, minY)) || + plotter->rect()->contains(QPointF(minX, maxY)) || + plotter->rect()->contains(QPointF(maxX, maxY)) || + plotter->rect()->contains(QPointF(maxX, minY)) ) { + + minX = std::max(c->histogram->minX(), minX); + minY = std::max(c->histogram->minY(), minY); + maxX = std::min(c->histogram->maxX(), maxX); + maxY = std::min(c->histogram->maxY(), maxY); + + QPainterPath path; + path.moveTo(m.map(QPointF(minX,minY))); + path.lineTo(m.map(QPointF(minX,maxY))); + path.lineTo(m.map(QPointF(maxX,maxY))); + path.lineTo(m.map(QPointF(maxX,minY))); + path.lineTo(m.map(QPointF(minX,minY))); + + + QAbstractGraphicsShapeItem *shape = new QGraphicsPathItem(path); + + shape->setPen(pen); + shape->setBrush(brush); + shape->setMatrix(mInverse); + plotter->scene()->addItem(shape); + plotter->group()->addToGroup(shape); + + } + } + } +} + + +// Get the histogram: +const Hist2D *PlotHist2D::histogram() const { + return c->histogram; +} + +const PlotHist2D::Properties & PlotHist2D::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotHist2D::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotHist2D::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotMeasure.cpp b/graphics/Qat/QatPlotting/src/PlotMeasure.cpp new file mode 100644 index 0000000000000000000000000000000000000000..152618ad1a2718f9cc0360c6372977c7bcdaed7c --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotMeasure.cpp @@ -0,0 +1,285 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotMeasure.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatPlotting/LinToLog.h" +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsEllipseItem> +#include <QtGui/QGraphicsPolygonItem> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsItemGroup> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsPathItem> + +class PlotMeasure::Clockwork { + + +public: + + Clockwork():myProperties(NULL) {} + ~Clockwork() { delete myProperties;} + + QRectF nRectangle; + Properties *myProperties; + Properties defaultProperties; + std::vector<QPointF> points; + std::vector<double> sizePlus; + std::vector<double> sizeMnus; +}; + + +// Constructor +PlotMeasure::PlotMeasure(): + Plotable(),c(new Clockwork()) +{ + c->nRectangle.setLeft (+1.0E100); + c->nRectangle.setRight (-1.0E100); + c->nRectangle.setTop (+1.0E100); + c->nRectangle.setBottom(-1.0E100); + +} + + + +// Destructor +PlotMeasure::~PlotMeasure(){ + delete c; +} + + + +const QRectF & PlotMeasure::rectHint() const { + return c->nRectangle; +} + + + + +void PlotMeasure::addPoint( const QPointF & point, double sizePlus, double sizeMnus) { + + c->points.push_back(point); + c->sizePlus.push_back(sizePlus); + c->sizeMnus.push_back(sizeMnus); + + + c->nRectangle.setLeft(std::min(c->nRectangle.left(),point.x()-sizeMnus)); + c->nRectangle.setRight(std::max(c->nRectangle.right(),point.x()+sizePlus)); + c->nRectangle.setBottom(std::min(c->nRectangle.bottom(),point.y())); + c->nRectangle.setTop(std::max(c->nRectangle.top(),point.y())); +} + + +void PlotMeasure::describeYourselfTo(AbsPlotter * plotter) const { + + QPen pen =properties().pen; + QBrush brush=properties().brush; + int symbolSize=properties().symbolSize; + Properties::SymbolStyle symbolStyle=properties().symbolStyle; + + LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + + for (unsigned int i=0;i<c->points.size();i++) { + double x = plotter->isLogX() ? (*toLogX) (c->points[i].x()) : c->points[i].x(); + + double y = plotter->isLogY() ? (*toLogY) (c->points[i].y()) : c->points[i].y(); + double xdxp = plotter->isLogX() ? (*toLogX)(c->points[i].x() + c->sizePlus[i]) : c->points[i].x() + c->sizePlus[i]; + double xdxm = plotter->isLogX() ? (*toLogX)(c->points[i].x() - c->sizeMnus[i]) : c->points[i].x() - c->sizeMnus[i]; + + QPointF loc(x, y ); + QSizeF siz(symbolSize,symbolSize); + QPointF ctr(siz.width()/2.0, siz.height()/2.0); + QPointF had(siz.width()/2.0, 0); + QPointF vad(0,siz.height()/2.0); + //QPointF penShiftLeft(-pen.widthF()/2.0, 0.0); + QPointF penShiftLeft(0,0); + QPointF plus(xdxp,y); + QPointF mnus(xdxm,y); + + if (plotter->rect()->contains(loc)) { + QAbstractGraphicsShapeItem *shape=NULL; + if (symbolStyle==Properties::CIRCLE) { + shape = new QGraphicsEllipseItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==Properties::SQUARE) { + shape = new QGraphicsRectItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==Properties::TRIANGLE_U) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2,0))); + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else if (symbolStyle==Properties::TRIANGLE_L) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2, symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else { + throw std::runtime_error("In PlotMeasure: unknown plot symbol"); + } + + shape->setPen(pen); + shape->setBrush(brush); + shape->setMatrix(mInverse); + plotter->scene()->addItem(shape); + plotter->group()->addToGroup(shape); + + { + QLineF pLine(m.map(loc)-had, m.map(plus)); + if (plotter->rect()->contains(plus)) { + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *topLine=new QGraphicsLineItem(QLineF(m.map(plus)+vad+penShiftLeft,m.map(plus)-vad+penShiftLeft)); + topLine->setPen(pen); + topLine->setMatrix(mInverse); + plotter->scene()->addItem(topLine); + plotter->group()->addToGroup(topLine); + + } + else { + QPointF intersection; + QLineF bottomLine(plotter->rect()->bottomRight(),plotter->rect()->topRight()); + QLineF::IntersectType type=bottomLine.intersect(QLineF(loc,plus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF plus=intersection; + QLineF pLine(m.map(loc)-had, m.map(plus)); + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + } + } + } + + { + QLineF mLine(m.map(loc)+had, m.map(mnus)); + if (plotter->rect()->contains(mnus)) { + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *bottomLine=new QGraphicsLineItem(QLineF(m.map(mnus)+vad+penShiftLeft,m.map(mnus)-vad+penShiftLeft)); + bottomLine->setPen(pen); + bottomLine->setMatrix(mInverse); + plotter->scene()->addItem(bottomLine); + plotter->group()->addToGroup(bottomLine); + + } + else { + QPointF intersection; + QLineF topLine(plotter->rect()->topLeft(),plotter->rect()->bottomLeft()); + QLineF::IntersectType type=topLine.intersect(QLineF(loc,mnus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF mnus=intersection; + QLineF mLine(m.map(loc)+had, m.map(mnus)); + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + } + } + } + } + else if (plotter->rect()->contains(mnus)) { + QPointF intersection; + QLineF bottomLine(plotter->rect()->bottomLeft(),plotter->rect()->bottomRight()); + QLineF::IntersectType type=bottomLine.intersect(QLineF(loc,mnus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF loc=intersection; + QLineF mLine(m.map(loc), m.map(mnus)); + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *bottomLine=new QGraphicsLineItem(QLineF(m.map(mnus)+vad-QPointF(pen.widthF(),0),m.map(mnus)-vad)); + bottomLine->setPen(pen); + bottomLine->setMatrix(mInverse); + plotter->scene()->addItem(bottomLine); + plotter->group()->addToGroup(bottomLine); + + } + } + else if (plotter->rect()->contains(plus)) { + QPointF intersection; + QLineF topLine(plotter->rect()->topLeft(),plotter->rect()->topRight()); + QLineF::IntersectType type=topLine.intersect(QLineF(loc,plus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF loc=intersection; + QLineF pLine(m.map(loc), m.map(plus)); + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *topLine=new QGraphicsLineItem(QLineF(m.map(plus)+vad+penShiftLeft,m.map(plus)-vad+penShiftLeft)); + topLine->setPen(pen); + topLine->setMatrix(mInverse); + plotter->scene()->addItem(topLine); + plotter->group()->addToGroup(topLine); + + } + } + } + delete toLogX; + delete toLogY; +} + +const PlotMeasure::Properties & PlotMeasure::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotMeasure::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotMeasure::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotOrbit.cpp b/graphics/Qat/QatPlotting/src/PlotOrbit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b03d01b5375479b9e58a1567eeb9f7ff2e3dbaa9 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotOrbit.cpp @@ -0,0 +1,234 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotOrbit.h" +#include "CLHEP/GenericFunctions/AbsFunction.hh" +#include "QatPlotting/AbsPlotter.h" + +#include "QatDataAnalysis/Query.h" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <stdexcept> + + +// Constructor +PlotOrbit::PlotOrbit(const Genfun::AbsFunction & functionX, + const Genfun::AbsFunction & functionY, + double t0, double t1): + Plotable(),c(new Clockwork()) +{ + c->functionX=functionX.clone(); + c->functionY=functionY.clone(); + c->t0=t0; + c->t1=t1; +} + +// Copy constructor: +PlotOrbit::PlotOrbit(const PlotOrbit & source): + Plotable(),c(new Clockwork()) +{ + c->functionX=source.c->functionX->clone(); + c->functionY=source.c->functionY->clone(); + c->rect=source.c->rect; + c->t0=source.c->t0; + c->t1=source.c->t1; + +} + +// Assignment operator: +PlotOrbit & PlotOrbit::operator=(const PlotOrbit & source){ + if (&source!=this) { + delete c->functionX; + delete c->functionY; + delete c->myProperties; + c->functionX=source.c->functionX->clone(); + c->functionY=source.c->functionY->clone(); + c->myProperties = source.c->myProperties ? new Properties(*source.c->myProperties):NULL; + c->rect=source.c->rect; + } + return *this; +} + + +#include <iostream> +// Destructor +PlotOrbit::~PlotOrbit(){ + delete c; +} + + + +const QRectF & PlotOrbit::rectHint() const { + static const int NSTEPS=500;// Synch to value in describeYourself(); + double interval = (c->t1-c->t0); + double d=interval/NSTEPS; + double minX=1E100,maxX=-minX, minY=minX, maxY=maxX; + + for (int i=0;i<NSTEPS;i++) { + double t = c->t0 + i*d; + double x= (*c->functionX)(t); + double y= (*c->functionY)(t); + minX=std::min(minX,x); + maxX=std::max(maxX,x); + minY=std::min(minY,y); + maxY=std::max(maxY,y); + } + double iX=maxX-minX,iY=maxY-minY; + minX-=iX/10.0; + minY-=iY/10.0; + maxX+=iX/10.0; + maxY+=iY/10.0; + c->rect.setLeft(minX); + c->rect.setRight(maxX); + c->rect.setTop(minY); + c->rect.setBottom(maxY); + + return c->rect; +} + + +// Get the graphic description:: +void PlotOrbit::describeYourselfTo(AbsPlotter *plotter) const { + + + QPen pen = properties().pen; + + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + { + unsigned int dimX = c->functionX->dimensionality(); + unsigned int dimY = c->functionY->dimensionality(); + if (dimX!=1|| dimY!=1) throw std::runtime_error("PlotOrbit: requires two functions of exactly 1 argument"); + } + double minX=plotter->rect()->left(), maxX=plotter->rect()->right(); + double minY=plotter->rect()->top(), maxY=plotter->rect()->bottom(); + + + int NPOINTS = 500; // Synch to value in rectHint(); + double interval = (c->t1-c->t0); + double d=interval/NPOINTS; + + const LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + const LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + { + // Just a line: + + Query<QPointF> cachedPoint; + QPainterPath *path=NULL; + bool empty=true; + for (int i=0; i<NPOINTS+1;i++) { + bool closePath=false; + double t = c->t0 + d*i; + double x = (*c->functionX)(t); + double y = (*c->functionY)(t); + { + + //double y = (*c->function) (x); + QPointF point(x,y); + if (y < maxY && y > minY && x < maxX && x > minX) { // IN RANGE + if (!path) path = new QPainterPath(); + if (empty) { + empty=false; + if (cachedPoint.isValid()) { + QPointF intersection; + if (Clockwork::intersect(plotter->rect(),cachedPoint, point,intersection)) { + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + if (Clockwork::maxOut(plotter->rect(), point, intersection)) { + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + std::cerr << "Intersection is failing" << std::endl; + } + } + } + else { + Clockwork::moveTo(path,m, point,toLogX,toLogY); + } + } + else { + Clockwork::lineTo(path,m,point,toLogX, toLogY); + } + } + else { // OUT OF RANGE + if (path) { + if (cachedPoint.isValid()) { + QPointF intersection; + if (Clockwork::intersect(plotter->rect(),cachedPoint, point,intersection)) { + Clockwork::lineTo(path,m,intersection,toLogX,toLogY); + } + else { + if (Clockwork::maxOut(plotter->rect(), point, intersection)) { + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + std::cerr << "Intersection is failing" << std::endl; + } + } + } + closePath=true; + empty =true; + } + } + cachedPoint=point; + } + if (i==NPOINTS && path) closePath=true; + if (closePath) { + QGraphicsPathItem *polyline=new QGraphicsPathItem(*path); + polyline->setPen(pen); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + delete path; + path=NULL; + } + } + } + + delete toLogX; + delete toLogY; +} + + +const PlotOrbit::Properties & PlotOrbit::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotOrbit::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotOrbit::resetProperties() { + delete c->myProperties; +} diff --git a/graphics/Qat/QatPlotting/src/PlotPoint.cpp b/graphics/Qat/QatPlotting/src/PlotPoint.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6af7129968c9503b025c2703757cbf50a2b5ac94 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotPoint.cpp @@ -0,0 +1,180 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotPoint.h" +#include "QatPlotting/LinToLog.h" +#include "QatPlotting/AbsPlotter.h" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsItemGroup> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsEllipseItem> +#include <QtGui/QGraphicsPolygonItem> +#include <QtGui/QGraphicsRectItem> +#include <iostream> +#include <iomanip> +#include <sstream> + +class PlotPoint::Clockwork { + + public: + + Clockwork():myProperties(NULL) {} + ~Clockwork() { delete myProperties;} + + + double x,y; + QRectF nRectangle; + Properties *myProperties; + Properties defaultProperties; +}; + + + +PlotPoint::PlotPoint (const PlotPoint & right):Plotable(),c(new Clockwork()){ + if (right.c->myProperties) { + c->myProperties= new Properties(*right.c->myProperties); + } + c->x=right.c->x; + c->y=right.c->y; + c->nRectangle=right.c->nRectangle; +} + +PlotPoint & PlotPoint::operator=(const PlotPoint & right) { + if (&right!=this) { + if (right.c->myProperties) c->myProperties= new Properties(*right.c->myProperties); + c->x=right.c->x; + c->y=right.c->y; + c->nRectangle=right.c->nRectangle; + } + return *this; +} + +// Constructor +PlotPoint::PlotPoint(double x, double y) + :Plotable(),c(new Clockwork()) + +{ + c->x=x; + c->y=y; + + c->nRectangle=QRectF(c->x-1E-10, c->y-1E-10, 2E-10, 2E-10); + +} + + + +// Destructor +PlotPoint::~PlotPoint(){ + delete c; +} + + +// Get the "natural maximum R" +const QRectF & PlotPoint::rectHint() const { + return c->nRectangle; +} + + + +// Describe to plotter, in terms of primitives: +void PlotPoint::describeYourselfTo(AbsPlotter *plotter) const{ + + LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + double x=c->x; + double y=c->y; + + QPen pen =properties().pen; + QBrush brush=properties().brush; + int symbolSize=properties().symbolSize; + PlotPoint::Properties::SymbolStyle symbolStyle=properties().symbolStyle; + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + if (toLogX) x = (*toLogX)(x); + if (toLogY) y = (*toLogY)(y); + + QPointF loc(x, y ); + QSizeF siz(symbolSize,symbolSize); + QPointF ctr(siz.width()/2.0, siz.height()/2.0); + QPointF had(siz.width()/2.0, 0); + QPointF vad(0,siz.height()/2.0); + + if (plotter->rect()->contains(loc)) { + QAbstractGraphicsShapeItem *shape=NULL; + if (symbolStyle==PlotPoint::Properties::CIRCLE) { + shape = new QGraphicsEllipseItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==PlotPoint::Properties::SQUARE) { + shape = new QGraphicsRectItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==PlotPoint::Properties::TRIANGLE_U) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2,0))); + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else if (symbolStyle==PlotPoint::Properties::TRIANGLE_L) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2, symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else { + throw std::runtime_error("In PlotPoint: unknown plot symbol"); + } + + shape->setPen(pen); + shape->setBrush(brush); + shape->setMatrix(mInverse); + plotter->scene()->addItem(shape); + plotter->group()->addToGroup(shape); + + } + + delete toLogX; + delete toLogY; +} + +const PlotPoint::Properties & PlotPoint::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotPoint::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotPoint::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotProfile.cpp b/graphics/Qat/QatPlotting/src/PlotProfile.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c415e04d5cab786d37804382385f08aea2298230 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotProfile.cpp @@ -0,0 +1,301 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotProfile.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatPlotting/LinToLog.h" +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsEllipseItem> +#include <QtGui/QGraphicsPolygonItem> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsItemGroup> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsPathItem> + +class PlotProfile::Clockwork { + + +public: + + Clockwork():myProperties(NULL) {} + ~Clockwork() { delete myProperties;} + + QRectF nRectangle; + Properties *myProperties; + Properties defaultProperties; + std::vector<QPointF> points; + std::vector<double> sizePlus; + std::vector<double> sizeMnus; +}; + + +// Constructor +PlotProfile::PlotProfile(): + Plotable(),c(new Clockwork()) +{ + c->nRectangle.setLeft (+1.0E100); + c->nRectangle.setRight (-1.0E100); + c->nRectangle.setTop (+1.0E100); + c->nRectangle.setBottom(-1.0E100); + +} + + + +// Destructor +PlotProfile::~PlotProfile(){ + delete c; +} + + + +const QRectF & PlotProfile::rectHint() const { + return c->nRectangle; +} + + + + // Add Points: +void PlotProfile::addPoint(const QPointF & point, double errorPlus, double errorMinus) { + c->points.push_back(point); + c->sizePlus.push_back(errorPlus); + c->sizeMnus.push_back(errorMinus); + + + c->nRectangle.setLeft(std::min(c->nRectangle.left(),point.x())); + c->nRectangle.setRight(std::max(c->nRectangle.right(),point.x())); + c->nRectangle.setBottom(std::min(c->nRectangle.bottom(),point.y()+errorPlus)); + c->nRectangle.setTop(std::max(c->nRectangle.top(),point.y()-errorMinus)); +} + +void PlotProfile::addPoint( const QPointF & point, double size) { + + c->points.push_back(point); + c->sizePlus.push_back(size); + c->sizeMnus.push_back(size); + + + c->nRectangle.setLeft(std::min(c->nRectangle.left(),point.x())); + c->nRectangle.setRight(std::max(c->nRectangle.right(),point.x())); + c->nRectangle.setBottom(std::min(c->nRectangle.bottom(),point.y()+size)); + c->nRectangle.setTop(std::max(c->nRectangle.top(),point.y()-size)); +} + + +void PlotProfile::describeYourselfTo(AbsPlotter * plotter) const { + + QPen pen =properties().pen; + QBrush brush=properties().brush; + int symbolSize=properties().symbolSize; + int errorBarSize=properties().errorBarSize; + Properties::SymbolStyle symbolStyle=properties().symbolStyle; + bool drawSymbol=properties().drawSymbol; + + LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + + for (unsigned int i=0;i<c->points.size();i++) { + double x = plotter->isLogX() ? (*toLogX) (c->points[i].x()) : c->points[i].x(); + + double y = plotter->isLogY() ? (*toLogY) (c->points[i].y()) : c->points[i].y(); + double ydyp = plotter->isLogY() ? (*toLogY)(c->points[i].y() + c->sizePlus[i]) : c->points[i].y() + c->sizePlus[i]; + double ydym = plotter->isLogY() ? (*toLogY)(c->points[i].y() - c->sizeMnus[i]) : c->points[i].y() - c->sizeMnus[i]; + + QPointF loc(x, y ); + QSizeF siz(symbolSize,symbolSize); + QSizeF esiz(errorBarSize,errorBarSize); + QPointF ctr(siz.width()/2.0, siz.height()/2.0); + QPointF had(esiz.width()/2.0, 0); + QPointF vad(0,siz.height()/2.0); + + QPointF plus(x,ydyp); + QPointF mnus(x,ydym); + + if (plotter->rect()->contains(loc)) { + QAbstractGraphicsShapeItem *shape=NULL; + if (drawSymbol) { + if (symbolStyle==Properties::CIRCLE) { + shape = new QGraphicsEllipseItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==Properties::SQUARE) { + shape = new QGraphicsRectItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==Properties::TRIANGLE_U) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2,0))); + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else if (symbolStyle==Properties::TRIANGLE_L) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2, symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else { + throw std::runtime_error("In PlotProfile: unknown plot symbol"); + } + shape->setPen(pen); + shape->setBrush(brush); + shape->setMatrix(mInverse); + plotter->scene()->addItem(shape); + plotter->group()->addToGroup(shape); + + } + + { + QLineF pLine(m.map(loc)-vad, m.map(plus)); + if (plotter->rect()->contains(plus)) { + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *topLine=new QGraphicsLineItem(QLineF(m.map(plus)+had,m.map(plus)-had)); + topLine->setPen(pen); + topLine->setMatrix(mInverse); + plotter->scene()->addItem(topLine); + plotter->group()->addToGroup(topLine); + + } + else { + QPointF intersection; + QLineF bottomLine(plotter->rect()->bottomLeft(),plotter->rect()->bottomRight()); + QLineF::IntersectType type=bottomLine.intersect(QLineF(loc,plus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF plus=intersection; + QLineF pLine(m.map(loc)-vad, m.map(plus)); + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + } + } + } + + { + QLineF mLine(m.map(loc)+vad, m.map(mnus)); + if (plotter->rect()->contains(mnus)) { + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *bottomLine=new QGraphicsLineItem(QLineF(m.map(mnus)+had,m.map(mnus)-had)); + bottomLine->setPen(pen); + bottomLine->setMatrix(mInverse); + plotter->scene()->addItem(bottomLine); + plotter->group()->addToGroup(bottomLine); + + } + else { + QPointF intersection; + QLineF topLine(plotter->rect()->topLeft(),plotter->rect()->topRight()); + QLineF::IntersectType type=topLine.intersect(QLineF(loc,mnus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF mnus=intersection; + QLineF mLine(m.map(loc)+vad, m.map(mnus)); + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + } + } + } + } + else if (plotter->rect()->contains(mnus)) { + QPointF intersection; + QLineF bottomLine(plotter->rect()->bottomLeft(),plotter->rect()->bottomRight()); + QLineF::IntersectType type=bottomLine.intersect(QLineF(loc,mnus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF loc=intersection; + QLineF mLine(m.map(loc), m.map(mnus)); + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *bottomLine=new QGraphicsLineItem(QLineF(m.map(mnus)+had,m.map(mnus)-had)); + bottomLine->setPen(pen); + bottomLine->setMatrix(mInverse); + plotter->scene()->addItem(bottomLine); + plotter->group()->addToGroup(bottomLine); + + } + } + else if (plotter->rect()->contains(plus)) { + QPointF intersection; + QLineF topLine(plotter->rect()->topLeft(),plotter->rect()->topRight()); + QLineF::IntersectType type=topLine.intersect(QLineF(loc,plus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF loc=intersection; + QLineF pLine(m.map(loc), m.map(plus)); + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *topLine=new QGraphicsLineItem(QLineF(m.map(plus)+had,m.map(plus)-had)); + topLine->setPen(pen); + topLine->setMatrix(mInverse); + plotter->scene()->addItem(topLine); + plotter->group()->addToGroup(topLine); + + } + } + } + delete toLogX; + delete toLogY; +} + +const PlotProfile::Properties & PlotProfile::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotProfile::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotProfile::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotRect.cpp b/graphics/Qat/QatPlotting/src/PlotRect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c50a3f7139f37a01763d06a43760a1171b9b5519 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotRect.cpp @@ -0,0 +1,148 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotRect.h" +#include "QatPlotting/LinToLog.h" +#include "QatPlotting/AbsPlotter.h" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsItemGroup> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsEllipseItem> +#include <QtGui/QGraphicsPolygonItem> +#include <QtGui/QGraphicsRectItem> +#include <iostream> +#include <iomanip> +#include <sstream> + +class PlotRect::Clockwork { + + public: + + Clockwork():myProperties(NULL) {} + ~Clockwork() { delete myProperties;} + + + + QRectF rectangle; + Properties *myProperties; + Properties defaultProperties; +}; + + + +PlotRect::PlotRect (const PlotRect & right):Plotable(),c(new Clockwork()){ + if (right.c->myProperties) { + c->myProperties= new Properties(*right.c->myProperties); + } + c->rectangle=right.c->rectangle; +} + +PlotRect & PlotRect::operator=(const PlotRect & right) { + if (&right!=this) { + if (right.c->myProperties) c->myProperties= new Properties(*right.c->myProperties); + c->rectangle=right.c->rectangle; + } + return *this; +} + +// Constructor +PlotRect::PlotRect(const QRectF & rectangle) + :Plotable(),c(new Clockwork()) + +{ + c->rectangle=rectangle; + +} + + + +// Destructor +PlotRect::~PlotRect(){ + delete c; +} + + +// Get the "natural maximum R" +const QRectF & PlotRect::rectHint() const { + return c->rectangle; +} + + + +// Describe to plotter, in terms of primitives: +void PlotRect::describeYourselfTo(AbsPlotter *plotter) const{ + + LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + double x0=c->rectangle.left(); + double x1=c->rectangle.right(); + double y0=c->rectangle.bottom(); + double y1=c->rectangle.top(); + + QPen pen =properties().pen; + QBrush brush=properties().brush; + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + if (toLogX) x0 = (*toLogX)(x0); + if (toLogY) y0 = (*toLogY)(y0); + if (toLogX) x1 = (*toLogX)(x1); + if (toLogY) y1 = (*toLogY)(y1); + + QVector<QPointF> points; + points.push_back(m.map(QPointF(x0,y0))); + points.push_back(m.map(QPointF(x0,y1))); + points.push_back(m.map(QPointF(x1,y1))); + points.push_back(m.map(QPointF(x1,y0))); + points.push_back(m.map(QPointF(x0,y0))); + QGraphicsPolygonItem *shape = new QGraphicsPolygonItem(QPolygonF(points)); + + shape->setPen(pen); + shape->setBrush(brush); + shape->setMatrix(mInverse); + plotter->scene()->addItem(shape); + plotter->group()->addToGroup(shape); + + + delete toLogX; + delete toLogY; +} + +const PlotRect::Properties & PlotRect::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotRect::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotRect::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotResidual1D.cpp b/graphics/Qat/QatPlotting/src/PlotResidual1D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fc0429c51079a926466f64eedbb45f9b7b7e2698 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotResidual1D.cpp @@ -0,0 +1,340 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatDataAnalysis/Hist1D.h" +#include "QatPlotting/PlotResidual1D.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatPlotting/LinToLog.h" +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsEllipseItem> +#include <QtGui/QGraphicsPolygonItem> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsItemGroup> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsPathItem> +#include <iostream> +#include <iomanip> +#include <sstream> +#include <cfloat> +// Constructor + +class PlotResidual1D::Clockwork { +public: + + Clockwork() : histogram(NULL), + myProperties(NULL) {} + + ~Clockwork() {delete myProperties;} + + // This is state: + const Hist1D *histogram; // The histogram + const Genfun::AbsFunction *function; // The function + QRectF nRectangle; // The "natural" bounding rectangle + Properties *myProperties; // My properties. May + Properties defaultProperties; +}; + + +PlotResidual1D::PlotResidual1D(const Hist1D & histogram, Genfun::GENFUNCTION function): + Plotable(),c(new Clockwork()) +{ + + c->histogram=&histogram; + c->function = function.clone(); + double yMin=FLT_MAX; + double yMax=FLT_MIN; + for (unsigned int i=0;i<histogram.nBins();i++) { + double x = histogram.binCenter(i); + double yplus = histogram.bin(i) -(*c->function)(x)+ histogram.binError(i); + double yminus = histogram.bin(i) -(*c->function)(x)- histogram.binError(i); + yMin = std::min(yMin,yminus); + yMax = std::max(yMax,yplus); + } + + double dist = yMax-yMin; + double marge = dist/10; + yMax += marge; + if (yMin>0) { + yMin=0; + } + else if (yMin<0) { + yMin-=marge; + } + + QPointF lowerRight(histogram.min(),yMin); + QPointF upperLeft (histogram.max(),yMax); + c->nRectangle.setLeft (histogram.min()); + c->nRectangle.setRight(histogram.max()); + c->nRectangle.setTop(yMin); + c->nRectangle.setBottom(yMax); +} + +// Copy constructor: +PlotResidual1D::PlotResidual1D(const PlotResidual1D & source): + Plotable(),c(new Clockwork()) +{ + + c->histogram=source.c->histogram; + c->function = source.c->function->clone(); + c->nRectangle=source.c->nRectangle; + if (source.c->myProperties) c->myProperties = new Properties(*source.c->myProperties); + +} + +// Assignment operator: +PlotResidual1D & PlotResidual1D::operator=(const PlotResidual1D & source) +{ + if (&source!=this) { + c->histogram=source.c->histogram; + c->nRectangle=source.c->nRectangle; + delete c->function; + c->function = source.c->function->clone(); + delete c->myProperties; + if (source.c->myProperties) { + c->myProperties = new Properties(*source.c->myProperties); + } + else { + c->myProperties=NULL; + } + } + return *this; +} + + +// Destructor +PlotResidual1D::~PlotResidual1D(){ + delete c->function; + delete c; +} + + +const QRectF & PlotResidual1D::rectHint() const { + return c->nRectangle; +} + + +// Get the graphic description:: +void PlotResidual1D::describeYourselfTo(AbsPlotter *plotter) const { + QPen pen =properties().pen; + int symbolSize=properties().symbolSize; + PlotResidual1D::Properties::SymbolStyle symbolStyle=properties().symbolStyle; + + LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + + for (unsigned int i=0;i<c->histogram->nBins();i++) { + double x = plotter->isLogX() ? (*toLogX) (c->histogram->binCenter(i)) : c->histogram->binCenter(i); + double y = plotter->isLogY() ? (*toLogY) (c->histogram->bin(i)-(*c->function)(x)) : c->histogram->bin(i)-(*c->function)(x); + double ydyp = plotter->isLogY() ? (*toLogY)(c->histogram->bin(i)-(*c->function)(x)+c->histogram->binError(i)) : c->histogram->bin(i)-(*c->function)(x)+c->histogram->binError(i); + double ydym = plotter->isLogY() ? (*toLogY)(c->histogram->bin(i)-(*c->function)(x)-c->histogram->binError(i)) : c->histogram->bin(i)-(*c->function)(x)-c->histogram->binError(i); + + QPointF loc(x, y ); + QSizeF siz(symbolSize,symbolSize); + QPointF ctr(siz.width()/2.0, siz.height()/2.0); + QPointF had(siz.width()/2.0, 0); + QPointF vad(0,siz.height()/2.0); + + QPointF plus(x,ydyp); + QPointF mnus(x,ydym); + + if (plotter->rect()->contains(loc)) { + QAbstractGraphicsShapeItem *shape=NULL; + if (symbolStyle==PlotResidual1D::Properties::CIRCLE) { + shape = new QGraphicsEllipseItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==PlotResidual1D::Properties::SQUARE) { + shape = new QGraphicsRectItem(QRectF(m.map(loc)-ctr,siz)); + } + else if (symbolStyle==PlotResidual1D::Properties::TRIANGLE_U) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize,symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2,0))); + points.push_back(m.map(loc)-ctr+(QPointF(0,symbolSize))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else if (symbolStyle==PlotResidual1D::Properties::TRIANGLE_L) { + QVector<QPointF> points; + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize, 0))); + points.push_back(m.map(loc)-ctr+(QPointF(symbolSize/2, symbolSize))); + points.push_back(m.map(loc)-ctr+(QPointF(0, 0))); + shape = new QGraphicsPolygonItem(QPolygonF(points)); + } + else { + throw std::runtime_error("In PlotResidual1D: unknown plot symbol"); + } + + shape->setPen(pen); + shape->setMatrix(mInverse); + plotter->scene()->addItem(shape); + plotter->group()->addToGroup(shape); + + { + QLineF pLine(m.map(loc)-vad, m.map(plus)); + if (plotter->rect()->contains(plus)) { + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *topLine=new QGraphicsLineItem(QLineF(m.map(plus)+had,m.map(plus)-had)); + topLine->setPen(pen); + topLine->setMatrix(mInverse); + plotter->scene()->addItem(topLine); + plotter->group()->addToGroup(topLine); + + } + else { + QPointF intersection; + QLineF bottomLine(plotter->rect()->bottomLeft(),plotter->rect()->bottomRight()); + QLineF::IntersectType type=bottomLine.intersect(QLineF(loc,plus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF plus=intersection; + QLineF pLine(m.map(loc)-vad, m.map(plus)); + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + } + } + } + + { + QLineF mLine(m.map(loc)+vad, m.map(mnus)); + if (plotter->rect()->contains(mnus)) { + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *bottomLine=new QGraphicsLineItem(QLineF(m.map(mnus)+had,m.map(mnus)-had)); + bottomLine->setPen(pen); + bottomLine->setMatrix(mInverse); + plotter->scene()->addItem(bottomLine); + plotter->group()->addToGroup(bottomLine); + + } + else { + QPointF intersection; + QLineF topLine(plotter->rect()->topLeft(),plotter->rect()->topRight()); + QLineF::IntersectType type=topLine.intersect(QLineF(loc,mnus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF mnus=intersection; + QLineF mLine(m.map(loc)+vad, m.map(mnus)); + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + } + } + } + + + } + else if (plotter->rect()->contains(mnus)) { + QPointF intersection; + QLineF bottomLine(plotter->rect()->bottomLeft(),plotter->rect()->bottomRight()); + QLineF::IntersectType type=bottomLine.intersect(QLineF(loc,mnus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF loc=intersection; + QLineF mLine(m.map(loc), m.map(mnus)); + QGraphicsLineItem *line=new QGraphicsLineItem(mLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *bottomLine=new QGraphicsLineItem(QLineF(m.map(mnus)+had,m.map(mnus)-had)); + bottomLine->setPen(pen); + bottomLine->setMatrix(mInverse); + plotter->scene()->addItem(bottomLine); + plotter->group()->addToGroup(bottomLine); + + } + } + else if (plotter->rect()->contains(plus)) { + QPointF intersection; + QLineF topLine(plotter->rect()->topLeft(),plotter->rect()->topRight()); + QLineF::IntersectType type=topLine.intersect(QLineF(loc,plus),&intersection); + if (type==QLineF::BoundedIntersection) { + QPointF loc=intersection; + QLineF pLine(m.map(loc), m.map(plus)); + QGraphicsLineItem *line=new QGraphicsLineItem(pLine); + line->setPen(pen); + line->setMatrix(mInverse); + plotter->scene()->addItem(line); + plotter->group()->addToGroup(line); + + QGraphicsLineItem *topLine=new QGraphicsLineItem(QLineF(m.map(plus)+had,m.map(plus)-had)); + topLine->setPen(pen); + topLine->setMatrix(mInverse); + plotter->scene()->addItem(topLine); + plotter->group()->addToGroup(topLine); + + } + } + } + delete toLogX; + delete toLogY; +} + +std::string PlotResidual1D::title() const { + return c->histogram->name(); +} + +// Get the histogram: +const Hist1D *PlotResidual1D::histogram() const { + return c->histogram; +} + +// Get the function: +const Genfun::AbsFunction *PlotResidual1D::function() const { + return c->function; +} + +const PlotResidual1D::Properties & PlotResidual1D::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotResidual1D::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotResidual1D::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotShadeBox.cpp b/graphics/Qat/QatPlotting/src/PlotShadeBox.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8e7f50cc13e374a0b61f88fb35b6eb0542ed771 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotShadeBox.cpp @@ -0,0 +1,177 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotShadeBox.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatPlotting/LinToLog.h" +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsEllipseItem> +#include <QtGui/QGraphicsPolygonItem> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsItemGroup> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsPathItem> +#include <iostream> +class PlotShadeBox::Clockwork { + + +public: + + Clockwork():myProperties(NULL) {} + ~Clockwork() { delete myProperties;} + + QRectF nRectangle; + Properties *myProperties; + Properties defaultProperties; + std::vector<QPointF> points; + std::vector<double> sizePlus; + std::vector<double> sizeMnus; +}; + + +// Constructor +PlotShadeBox::PlotShadeBox(): + Plotable(),c(new Clockwork()) +{ + c->nRectangle.setLeft (+1.0E100); + c->nRectangle.setRight (-1.0E100); + c->nRectangle.setTop (+1.0E100); + c->nRectangle.setBottom(-1.0E100); + +} + + + +// Destructor +PlotShadeBox::~PlotShadeBox(){ + delete c; +} + + + +const QRectF & PlotShadeBox::rectHint() const { + return c->nRectangle; +} + + + + // Add Points: +void PlotShadeBox::addPoint(const QPointF & point, double errorPlus, double errorMinus) { + c->points.push_back(point); + c->sizePlus.push_back(errorPlus); + c->sizeMnus.push_back(errorMinus); + + + c->nRectangle.setLeft(std::min(c->nRectangle.left(),point.x())); + c->nRectangle.setRight(std::max(c->nRectangle.right(),point.x())); + c->nRectangle.setBottom(std::min(c->nRectangle.bottom(),point.y()+errorPlus)); + c->nRectangle.setTop(std::max(c->nRectangle.top(),point.y()-errorMinus)); +} + +void PlotShadeBox::addPoint( const QPointF & point, double size) { + + c->points.push_back(point); + c->sizePlus.push_back(size); + c->sizeMnus.push_back(size); + + + c->nRectangle.setLeft(std::min(c->nRectangle.left(),point.x())); + c->nRectangle.setRight(std::max(c->nRectangle.right(),point.x())); + c->nRectangle.setBottom(std::min(c->nRectangle.bottom(),point.y()+size)); + c->nRectangle.setTop(std::max(c->nRectangle.top(),point.y()-size)); +} + + +void PlotShadeBox::describeYourselfTo(AbsPlotter * plotter) const { + + QPen pen =properties().pen; + QBrush brush=properties().brush; + double hSize=properties().horizontalSize; + + LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + + for (unsigned int i=0;i<c->points.size();i++) { + + + + double xdxp = c->points[i].x() + hSize/2; + double xdxm = c->points[i].x() - hSize/2; + double ydyp = c->points[i].y() + c->sizePlus[i]; + double ydym = c->points[i].y() - c->sizeMnus[i]; + + + xdxp = plotter->isLogX() ? (*toLogX) (xdxp): xdxp; + xdxm = plotter->isLogX() ? (*toLogX) (xdxm): xdxm; + ydyp = plotter->isLogY() ? (*toLogY) (ydyp): ydyp; + ydym = plotter->isLogY() ? (*toLogY) (ydym): ydym; + + if (ydyp<plotter->rect()->top()) return; + if (ydym>plotter->rect()->bottom()) return; + if (xdxp<plotter->rect()->left()) return; + if (xdxm>plotter->rect()->right()) return; + + xdxp = std::min(xdxp,plotter->rect()->right()); + xdxm = std::max(xdxm,plotter->rect()->left()); + ydyp = std::min(ydyp,plotter->rect()->bottom()); + ydym = std::max(ydym,plotter->rect()->top()); + + QRectF rect; + rect.setTop(ydym); + rect.setBottom(ydyp); + rect.setLeft(xdxm); + rect.setRight(xdxp); + QGraphicsRectItem *shape = new QGraphicsRectItem(m.mapRect(rect)); + + shape->setPen(pen); + shape->setBrush(brush); + shape->setMatrix(mInverse); + plotter->scene()->addItem(shape); + plotter->group()->addToGroup(shape); + } + + delete toLogX; + delete toLogY; +} + +const PlotShadeBox::Properties & PlotShadeBox::properties() const { + return c->myProperties ? *c->myProperties : c->defaultProperties; +} + +void PlotShadeBox::setProperties(const Properties & properties) { + if (!c->myProperties) { + c->myProperties = new Properties(properties); + } + else { + *c->myProperties=properties; + } +} + +void PlotShadeBox::resetProperties() { + delete c->myProperties; +} + diff --git a/graphics/Qat/QatPlotting/src/PlotText.cpp b/graphics/Qat/QatPlotting/src/PlotText.cpp new file mode 100644 index 0000000000000000000000000000000000000000..08db2d6355fb656a5bdb3c01ec827bf2074bc066 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotText.cpp @@ -0,0 +1,143 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/PlotText.h" +#include "QatPlotting/LinToLog.h" +#include "QatPlotting/AbsPlotter.h" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsItemGroup> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QGraphicsRectItem> +#include <QtGui/QTextDocument> +#include <iostream> +#include <iomanip> +#include <sstream> + +class PlotText::Clockwork { + + public: + + Clockwork():textDocument() {} + ~Clockwork() { + delete textDocument; + delete nRect; + } + + + QPointF point; + QTextDocument *textDocument; + QRectF *nRect; +}; + + + +PlotText::PlotText (const PlotText & right):Plotable(),c(new Clockwork()){ + c->point=right.c->point; + c->textDocument=right.c->textDocument->clone(); + c->nRect=NULL; +} + +PlotText & PlotText::operator=(const PlotText & right) { + if (&right!=this) { + c->point=right.c->point; + c->textDocument=right.c->textDocument->clone(); + c->nRect=NULL; + } + return *this; +} + +// Constructor +PlotText::PlotText(double x, double y, const QString & text) + :Plotable(),c(new Clockwork()) + +{ + c->point=QPointF(x,y); + c->textDocument=new QTextDocument(text); + c->nRect=NULL; +} + + + +// Destructor +PlotText::~PlotText(){ + delete c; +} + + +// Get the "natural maximum R" +const QRectF & PlotText::rectHint() const { + if (!c->nRect) { + QGraphicsTextItem aux; + aux.setDocument(c->textDocument); + aux.setPos(c->point); + aux.adjustSize(); + c->nRect = new QRectF( aux.boundingRect()); + } + return *c->nRect; +} + + + +// Describe to plotter, in terms of primitives: +void PlotText::describeYourselfTo(AbsPlotter *plotter) const{ + + LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + double x=c->point.x(); + double y=c->point.y(); + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + if (toLogX) x = (*toLogX)(x); + if (toLogY) y = (*toLogY)(y); + + + + QGraphicsTextItem *item = new QGraphicsTextItem(); + QPointF p=c->point; + QPointF p1 = m.map(c->point); + QPointF p2 = mInverse.map(c->point); + + + QPointF P(plotter->rect()->left(), plotter->rect()->bottom()); + QPointF Q(c->point); + + item->setDocument(c->textDocument); + item->setPos(Q-P); + item->setMatrix(mInverse); + plotter->scene()->addItem(item); + plotter->group()->addToGroup(item); + + delete toLogX; + delete toLogY; +} + + +void PlotText::setDocument(QTextDocument *document) { + delete c->textDocument; + c->textDocument=document->clone(); +} + + diff --git a/graphics/Qat/QatPlotting/src/PlotWave1D.cpp b/graphics/Qat/QatPlotting/src/PlotWave1D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a2a9109ce534612123fa36c9de9345b300ac9a4 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/PlotWave1D.cpp @@ -0,0 +1,242 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "CLHEP/GenericFunctions/AbsFunction.hh" +#include "QatPlotting/PlotWave1D.h" +#include "QatPlotting/AbsPlotter.h" +#include "QatPlotting/LinToLog.h" +#include "QatDataAnalysis/Query.h" +#include <QtGui/QGraphicsPathItem> +#include <QtGui/QPainterPath> +#include <QtGui/QGraphicsScene> +#include <stdexcept> +#include <sys/time.h> + +// Constructor +PlotWave1D::PlotWave1D(const Genfun::AbsFunction & function, + const QRectF & naturalRectangle): + PlotFunction1D(function, naturalRectangle) {} + + +PlotWave1D::PlotWave1D(const Genfun::AbsFunction & function, + const Cut<double> & domainRestriction, + const QRectF & naturalRectangle): + PlotFunction1D(function, domainRestriction, naturalRectangle) {} + +// Copy constructor: +PlotWave1D::PlotWave1D(const PlotWave1D & source): + PlotFunction1D(source) {} + +// Assignment operator: +PlotWave1D & PlotWave1D::operator=(const PlotWave1D & source){ + if (&source !=this) { + PlotFunction1D::operator=(source); + } + return *this; +} + + +// Destructor +PlotWave1D::~PlotWave1D(){ +} + + +// Get the graphic description:: +void PlotWave1D::describeYourselfTo(AbsPlotter *plotter) const { + + plotter->startAnimating(20); + + Genfun::Argument arg(2); + timeval tv; + gettimeofday(&tv,NULL); + arg[1] = double(tv.tv_sec) + tv.tv_usec/double(1000000); + + + + QPen pen = properties().pen; + QBrush brush=properties().brush; + + + QMatrix m=plotter->matrix(),mInverse=m.inverted(); + + unsigned int dim = c->function->dimensionality(); + if (dim!=2) throw std::runtime_error("PlotWave1D: requires a function of exactly 2 arguments"); + + double minX=plotter->rect()->left(), maxX=plotter->rect()->right(); + double minY=plotter->rect()->top(), maxY=plotter->rect()->bottom(); + + + int NPOINTS = 100; + double delta = (maxX-minX)/NPOINTS; + + const LinToLog *toLogX= plotter->isLogX() ? new LinToLog (plotter->rect()->left(),plotter->rect()->right()) : NULL; + const LinToLog *toLogY= plotter->isLogY() ? new LinToLog (plotter->rect()->top(),plotter->rect()->bottom()) : NULL; + + if (brush.style()==Qt::NoBrush) { + // Just a line: + + Query<QPointF> cachedPoint; + QPainterPath *path=NULL; + bool empty=true; + for (int i=0; i<NPOINTS+1;i++) { + bool closePath=false; + double x = minX + i*delta; + arg[0] = x; + double y=0; + if ((!c->domainRestriction || (*c->domainRestriction)(x)) && finite((y=(*c->function)(arg)))) { // Check that X is in function domain + + //double y = (*c->function) (x); + QPointF point(x,y); + if (y < maxY && y > minY) { // IN RANGE + if (!path) path = new QPainterPath(); + if (empty) { + empty=false; + if (cachedPoint.isValid()) { + QPointF intersection; + if (Clockwork::intersect(plotter->rect(),cachedPoint, point,intersection)) { + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + if (Clockwork::maxOut(plotter->rect(), point, intersection)) { + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + std::cerr << "Intersection is failing" << std::endl; + } + } + } + else { + Clockwork::moveTo(path,m, point,toLogX,toLogY); + } + } + else { + Clockwork::lineTo(path,m,point,toLogX, toLogY); + } + } + else { // OUT OF RANGE + if (path) { + if (cachedPoint.isValid()) { + QPointF intersection; + if (Clockwork::intersect(plotter->rect(),cachedPoint, point,intersection)) { + Clockwork::lineTo(path,m,intersection,toLogX,toLogY); + } + else { + if (Clockwork::maxOut(plotter->rect(), point, intersection)) { + Clockwork::moveTo(path,m,intersection,toLogX,toLogY); + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { + std::cerr << "Intersection is failing" << std::endl; + } + } + } + closePath=true; + empty =true; + } + } + cachedPoint=point; + } + else { // OUT OF DOMAIN + if (path) { + closePath=true; + empty=true; + } + cachedPoint=Query<QPointF>(); + } + if (i==NPOINTS && path) closePath=true; + if (closePath) { + QGraphicsPathItem *polyline=new QGraphicsPathItem(*path); + polyline->setPen(pen); + polyline->setBrush(brush); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + delete path; + path=NULL; + } + } + } + else { + // A fill pattern of some sort.. + double yBase=std::max(std::min(maxY, properties().baseLine),minY); + + QPainterPath *path=NULL; + bool empty=true; + for (int i=0; i<NPOINTS+1;i++) { + bool closePath=false; + double x = minX + i*delta; + arg[0]=x; + double y=0; + if ((!c->domainRestriction || (*c->domainRestriction)(x)) && finite((y=(*c->function)(arg)))) { // Check that X is in function domain + + //double y = (*c->function) (x); + QPointF point(x,y); + + if (!path) path = new QPainterPath(); + if (empty) { + empty=false; + QPointF intersection; + Clockwork::moveTo(path,m, QPointF(x,yBase), toLogX,toLogY); + } + + + if (y < maxY && y > minY) { // IN RANGE + Clockwork::lineTo(path,m,point,toLogX,toLogY); + } + else { // OUT OF RANGE + QPointF maxOut; + Clockwork::maxOut(plotter->rect(), point,maxOut); + Clockwork::lineTo(path,m,maxOut,toLogX,toLogY); + } + } + else { // OUT OF DOMAIN + if (path) { + closePath=true; + empty=true; + } + } + if (i==NPOINTS && path) { + closePath=true; + } + if (closePath) { + QPointF position=mInverse.map(path->currentPosition()); + position.setY(yBase); + Clockwork::lineTo(path,m,position,toLogX,toLogY); + QGraphicsPathItem *polyline=new QGraphicsPathItem(*path); + polyline->setPen(pen); + polyline->setBrush(brush); + polyline->setMatrix(mInverse); + plotter->scene()->addItem(polyline); + plotter->group()->addToGroup(polyline); + delete path; + path=NULL; + } + } + } + delete toLogX; + delete toLogY; +} + + + diff --git a/graphics/Qat/QatPlotting/src/Plotable.cpp b/graphics/Qat/QatPlotting/src/Plotable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9a31f3fe0c2702c35d8ac4e114bccfb934477401 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/Plotable.cpp @@ -0,0 +1,29 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/Plotable.h" +Plotable::Plotable() { +} + +Plotable::~Plotable() { +} + diff --git a/graphics/Qat/QatPlotting/src/QatPlotting.pro b/graphics/Qat/QatPlotting/src/QatPlotting.pro new file mode 100644 index 0000000000000000000000000000000000000000..3d2958c637dde5aaee2abb5c45c7b11a6ae75725 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/QatPlotting.pro @@ -0,0 +1,73 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Thu Sep 18 19:41:36 2008 +###################################################################### + +TEMPLATE = lib dll +TARGET = +DEPENDPATH += . +INCLUDEPATH += . .. ../../QatDataAnalysis +DESTDIR=../../../lib +CONFIG += build_all debug + +# Input +HEADERS += ../QatPlotting/AbsPlotter.h \ + ../QatPlotting/LinToLog.h \ + ../QatPlotting/PlotStream.h \ + ../QatPlotting/Plotable.h \ + ../QatPlotting/PlotHist1D.h \ + ../QatPlotting/PlotHist1DProperties.h \ + ../QatPlotting/PlotHist2D.h \ + ../QatPlotting/PlotHist2DProperties.h \ + ../QatPlotting/PlotFunction1DProperties.h \ + ../QatPlotting/PlotFunction1D.h \ + ../QatPlotting/PlotProfileProperties.h \ + ../QatPlotting/PlotProfile.h \ + ../QatPlotting/PlotErrorEllipseProperties.h \ + ../QatPlotting/PlotErrorEllipse.h \ + ../QatPlotting/PlotOrbit.h \ + ../QatPlotting/PlotOrbitProperties.h \ + ../QatPlotting/PlotPointProperties.h \ + ../QatPlotting/PlotPoint.h \ + ../QatPlotting/PlotResidual1D.h \ + ../QatPlotting/PlotResidual1DProperties.h \ + ../QatPlotting/RealArg.h \ + ../QatPlotting/PlotRectProperties.h \ + ../QatPlotting/PlotRect.h \ + ../QatPlotting/PlotShadeBox.h \ + ../QatPlotting/PlotText.h \ + ../QatPlotting/PlotMeasure.h \ + ../QatPlotting/PlotMeasureProperties.h \ + ../QatPlotting/PlotBand1D.h \ + ../QatPlotting/PlotBand1DProperties.h \ + ../QatPlotting/VisFunction.h \ + ../QatPlotting/PlotWave1D.h \ + ../QatPlotting/PlotWave1DProperties.h \ + ../QatPlotting/PlotFunction1D.icc + +SOURCES += AbsPlotter.cpp \ + Plotable.cpp \ + PlotHist1D.cpp \ + PlotHist2D.cpp \ + PlotFunction1D.cpp \ + PlotOrbit.cpp \ + PlotProfile.cpp \ + PlotErrorEllipse.cpp \ + PlotPoint.cpp \ + PlotResidual1D.cpp \ + PlotShadeBox.cpp \ + RealArg.cpp \ + PlotRect.cpp \ + PlotText.cpp \ + PlotMeasure.cpp \ + PlotBand1D.cpp \ + VisFunction.cpp \ + PlotWave1D.cpp + +INSTALLS += target +target.path=/usr/local/lib + +headers.path=/usr/local/include/QatPlotting +headers.files= ../QatPlotting/*h ../QatPlotting/*.icc +INSTALLS += headers + + diff --git a/graphics/Qat/QatPlotting/src/RealArg.cpp b/graphics/Qat/QatPlotting/src/RealArg.cpp new file mode 100644 index 0000000000000000000000000000000000000000..90ef194ed2f7a37261515488343a74aa12035c85 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/RealArg.cpp @@ -0,0 +1,39 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/RealArg.h" +namespace RealArg { + + Eq::Eq(double value): _value(value){} + bool Eq::operator() (const double & x) const {return x==_value;} + Eq *Eq::clone() const { return new Eq(*this);} + + Lt::Lt(double value): _value(value){} + bool Lt::operator() (const double & x) const {return x<_value;} + Lt *Lt::clone() const { return new Lt(*this);} + + Gt::Gt(double value): _value(value) {} + bool Gt::operator() (const double & x) const {return x>_value;} + Gt *Gt::clone() const { return new Gt(*this);} + +} + diff --git a/graphics/Qat/QatPlotting/src/VisFunction.cpp b/graphics/Qat/QatPlotting/src/VisFunction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..26d54adb74c938e0d2205299dcd0ba5572b88274 --- /dev/null +++ b/graphics/Qat/QatPlotting/src/VisFunction.cpp @@ -0,0 +1,97 @@ +//---------------------------------------------------------------------------// +// // +// This file is part of the Pittsburgh Visualization System (PVS) // +// // +// Copyright (C) 2004 Joe Boudreau, University of Pittsburgh // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // +// --------------------------------------------------------------------------// + + +#include "QatPlotting/VisFunction.h" +#include <vector> +#include <iostream> +class VisFunction::Clockwork { +public: + std::string name; + std::vector<Genfun::Parameter *> parameter; + std::vector<const Genfun::AbsFunction *> function; + std::vector<const Cut<double> *> domainRestriction; + QRectF rectHint; +}; + +VisFunction::VisFunction(const std::string & name): + c(new Clockwork()) +{ + c->name = name; +} + +VisFunction::~VisFunction() +{ + for (unsigned int i=0;i<c->function.size();i++) { + delete c->function[i]; + delete c->domainRestriction[i]; + } + for (unsigned int i=0;i<c->parameter.size();i++) { + delete c->parameter[i]; + } + delete c; +} + + +void VisFunction::addParameter(Genfun::Parameter *p) { + c->parameter.push_back(p); +} + +unsigned int VisFunction::getNumParameters() const { + return c->parameter.size(); +} + +Genfun::Parameter *VisFunction::getParameter(unsigned int i) const { + return c->parameter[i]; +} + + +void VisFunction::addFunction(Genfun::GENFUNCTION f, const Cut<double> * domainRestriction) { + c->function.push_back(f.clone()); + c->domainRestriction.push_back(domainRestriction ? domainRestriction->clone(): NULL); +} + +unsigned int VisFunction::getNumFunctions() const { + return c->function.size(); +} + +const Genfun::AbsFunction *VisFunction::getFunction(unsigned int i) const { + return c->function[i]; +} + +const Cut<double> *VisFunction::getDomainRestriction(unsigned int i) const { + return c->domainRestriction[i]; +} + + +const std::string & VisFunction::name() const { + return c->name; +} + + +const QRectF & VisFunction::rectHint() const { + return c->rectHint; +} + + +QRectF & VisFunction::rectHint() { + return c->rectHint; +}