Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef IMAGELAYER_H
00030 #define IMAGELAYER_H
00031
00032 #include <math.h>
00033
00034 #include "GraphContentLayer.h"
00035
00036 namespace SciFigs {
00037
00038 class ImageLayerProperties;
00039
00040 class SCIFIGS_EXPORT ImageLayer: public GraphContentLayer
00041 {
00042 Q_OBJECT
00043 Q_PROPERTY(QString imageFile READ fileName WRITE setFileName)
00044 Q_PROPERTY(double xScale READ xScale WRITE setXScale)
00045 Q_PROPERTY(double yScale READ yScale WRITE setYScale)
00046 Q_PROPERTY(double xOrigin READ xOrigin WRITE setXOrigin)
00047 Q_PROPERTY(double yOrigin READ yOrigin WRITE setYOrigin)
00048 public:
00049 ImageLayer(AxisWindow * parent=0);
00050 ~ImageLayer();
00051
00052 virtual const QString& xml_tagName() const {return xmlImageLayerTag;}
00053 static const QString xmlImageLayerTag;
00054
00055 void loadImage(QString fileName);
00056 void loadImage();
00057 void colorHistogram(Rect r);
00058 enum TrackingModes{Scale=0, Histogram};
00059 virtual bool trackRectangle(int id, double rx1,double ry1, double rx2, double ry2, Qt::KeyboardModifiers m);
00060 virtual bool mouseReleaseEvent (QMouseEvent * e, int id=-1);
00061 virtual void toggleTrackingAction(bool checked, int id=-1);
00062 virtual Rect boundingRect() const;
00063 void grayFilter(int tol,int threshold);
00064 void lowPassFilter(int hThres, int sThres, int vThres);
00065 void highPassFilter(int hThres, int sThres, int vThres);
00066 void redPassFilter();
00067
00068 QString fileName() const {return _fileName;}
00069 void setFileName(QString s) {_fileName=s;}
00070
00071 const Point2D& origin() const {return _origin;}
00072 Point2D& origin() {return _origin;}
00073 void setOrigin(const Point2D& o) {_origin=o;}
00074
00075 const Point2D& scale() const {return _scale;}
00076 Point2D& scale() {return _scale;}
00077 void setScale(const Point2D& s) {_scale=s;}
00078
00079 double xScale() const {return _scale.x();}
00080 void setXScale(double s) {_scale.setX(s);}
00081 double yScale() const {return _scale.y();}
00082 void setYScale(double s) {_scale.setY(s);}
00083
00084 double xOrigin() const {return _origin.x();}
00085 void setXOrigin(double s) {_origin.setX(s);}
00086 double yOrigin() const {return _origin.y();}
00087 void setYOrigin(double s) {_origin.setY(s);}
00088
00089 void setScaling();
00090
00091 QRgb * image(int& n);
00092
00093 virtual bool hasProperties() {return true;}
00094 virtual void addProperties(PropertyProxy * pp);
00095 virtual void removeProperties(PropertyProxy * pp);
00096 virtual void properties(PropertyWidget * w) const;
00097 virtual void setProperty(uint wid, int pid, QVariant val);
00098
00099 class ReferencePoint: public XMLClass
00100 {
00101 public:
00102 ReferencePoint() : XMLClass() {}
00103 ReferencePoint(const ReferencePoint& o)
00104 : XMLClass(), _name(o._name), _image(o._image), _real(o._real) {}
00105
00106 virtual const QString& xml_tagName() const {return xmlReferencePointTag;}
00107 static const QString xmlReferencePointTag;
00108
00109 void setName(const QString& n) {_name=n;}
00110 const QString& name() const {return _name;}
00111
00112 void setImage(const QPoint& p) {_image=p;}
00113 const QPoint& image() const {return _image;}
00114 QPoint& image() {return _image;}
00115
00116 void setReal(const Point2D& p) {_real=p;}
00117 const Point2D& real() const {return _real;}
00118 Point2D& real() {return _real;}
00119 protected:
00120 virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00121 virtual XMLMember xml_member(XML_MEMBER_ARGS);
00122 virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00123 private:
00124 QString _name;
00125 QPoint _image;
00126 Point2D _real;
00127 };
00128
00129 void setReferences(const QList<ReferencePoint>& ref) {_references=ref;}
00130 const QList<ReferencePoint>& references() const {return _references;}
00131
00132 static void scaling(const QList<ReferencePoint> ref, Point2D& origin, Point2D& scale);
00133 protected:
00134 virtual void paintData(const LayerPainterRequest& lp, QPainter& p, double dotpercm) const;
00135 virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00136 virtual void xml_writeChildren(XML_WRITECHILDREN_ARGS) const;
00137 virtual XMLMember xml_member(XML_MEMBER_ARGS);
00138 virtual void xml_polish(XML_POLISH_ARGS) {Q_UNUSED(context); loadImage();}
00139 private:
00140 inline QPoint r2i(const Point2D& p) const;
00141
00142 QImage _trueImage;
00143 QTransform _transform;
00144 QString _fileName;
00145 Point2D _origin;
00146 Point2D _scale;
00147 QList<ReferencePoint> _references;
00148 static uint _tabImage;
00149 signals:
00150 void editedColors(QRgb * colors, int numC);
00151 void pointPicked(QPoint p);
00152 };
00153
00154 inline QPoint ImageLayer::r2i(const Point2D& p) const
00155 {
00156 return QPoint((int)round((p.x()-_origin.x())/_scale.x()),
00157 (int)round((p.y()-_origin.y())/_scale.y()));
00158 }
00159
00160
00161 }
00162
00163 #endif // IMAGELAYER_H