OSDN Git Service

first
[psychlops/cpp.git] / psychlops / extension / prototype / figure / psychlops_figure_gabor.h
1 /*
2  *  psychlops_figure_prototype.h
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2005/10/05 by Kenchi HOSOKAWA
6  *  (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9 #ifndef HEADER_PSYCHLOPS_FIGURE_GABOR_PROTOTYPE
10 #define HEADER_PSYCHLOPS_FIGURE_GABOR_PROTOTYPE
11
12 #include <vector>
13
14 #include "../../../psychlops_core.h"
15
16
17
18 namespace Psychlops {
19
20 //      double gaussian(double sigma, double x);
21
22
23 namespace StimulusTemplate {
24
25         class Gabor : virtual public Figure {
26                 public:
27                 Length wavelength;
28                 Angle orientation, phase;
29                 double contrast;
30
31                 protected:
32                 double sigma_;
33                 double left_, top_;
34                 int width_, height_;
35                 public:
36                 int sigma_index_;
37
38
39                 public:
40                 virtual ~Gabor();
41                 virtual Gabor& set(double freq, double sigma, double contrast = 0.5, double orient = 0.0, double phs=0.0) = 0;
42                 virtual Gabor& set(Length freq, Length sigma, double contrast = 0.5, Angle orient = 0.0*degree, Angle phs=0.0*degree) = 0;
43
44                 virtual Gabor& setContrast(double cont);
45                 virtual Gabor& setWavelength(Length length);
46                 virtual Gabor& setOrientation(Angle orient);
47                 virtual Gabor& setPhase(Angle phs);
48
49                 virtual Gabor& shift(const double x, const double y, const double z = 0.0) = 0;
50                 virtual Gabor& centering(const double x, const double y, const double z = 0.0) = 0;
51                 virtual Gabor& centering(const Point &po) = 0;
52                 virtual Gabor& centering(const Drawable &target = *Drawable::prime) = 0;
53                 virtual const Point getDatum() const;
54
55                 virtual Gabor& draw(Drawable &target = *Drawable::prime) = 0;
56                 virtual Gabor& draw(int x, int y, Drawable &target = *Drawable::prime) = 0;
57         };
58
59 }
60
61 namespace Figures {
62
63         int substructImages(Image &result, const Image &s1, const Image &s2, const double factor);
64         void drawImageCoordinateTuner(Image &img);
65
66         void drawGrating(Image &img, int width, int height, double wavelength, double contrast, double orientation, double phase);
67         void drawGaussian(Image &img, double sigma, double factor);
68         void drawGabor(Image &img, double sigma, double wavelength, double contrast, double orientation, double phase);
69
70
71         class GaborBase : public Rectangle {
72         public:
73                 Color peak[2];
74
75                 Length wavelength;
76                 double orientation, phase;
77                 double contrast;
78
79         public:
80                 GaborBase();
81                 virtual GaborBase& setSigma(double sigma);
82                 virtual GaborBase& setSigma(Length sigma);
83                 virtual GaborBase& setWave(double wavelen, double cont = 0.5, double orient = 0.0, double phs=0.0);
84                 virtual GaborBase& setWave(Length wavelen, double cont = 0.5, Angle orient = 0.0*degree, Angle phs=0.0*degree);
85                 virtual GaborBase& cache(DrawableWithCache &target = *DrawableWithCache::prime) = 0;
86                 virtual GaborBase& draw(Drawable &target = *DrawableWithCache::prime) = 0;
87                 virtual void to(Image &dest, Canvas &media = *Display::the_canvas) = 0;
88         };
89
90
91         class ImageGabor : public GaborBase {
92         protected:
93                 struct Key
94                 {
95                         double data[5];
96                         const bool operator <(Key rhs) const;
97                         const bool operator >(Key rhs) const;
98                 };
99                 std::map<Key, Image*> cache_list;
100                 Image normal_;
101
102         public:
103                 ImageGabor();
104                 virtual ImageGabor& cache(DrawableWithCache &target = *DrawableWithCache::prime);
105                 virtual ImageGabor& draw(Drawable &target = *DrawableWithCache::prime);
106                 virtual void to(Image &dest, Canvas &media = *Display::the_canvas);
107         };
108
109 }
110
111         class QuickGabor : public StimulusTemplate::Gabor {
112                 class Instance {
113                         friend class QuickGabor;
114                         protected:
115                         int referenced_count_;
116                         int size_;
117                         Length sigma_;
118                         Image *envelope_;
119                         Rectangle *carrier_;
120                         bool instantiated;
121                         void set(double sigma);
122                         void setEnvelope();
123                         void setCarrier();
124                         public:
125                         Instance();
126                         ~Instance();
127                         void release();
128                         Instance& draw(int x, int y, Length frequency, Angle orientation, Angle phase, double consrast, Drawable &target);
129                 };
130                 static std::vector<Instance *> instance_;
131
132                 int setInstance(double sigma);
133                 void release();
134
135                 public:
136                 QuickGabor();
137                 // it is not good to call virtual function from constructors.
138                 QuickGabor(double freq, double sigma, double contrast = 0.5, double orient = 0.0, double phs=0.0);
139                 QuickGabor(Length freq, Length sigma, double contrast = 0.5, Angle orient = 0.0*degree, Angle phs=0.0*degree);
140                 virtual ~QuickGabor();
141                 virtual QuickGabor& set(double freq, double sigma, double contrast = 0.5, double orient = 0.0, double phs=0.0);
142                 virtual QuickGabor& set(Length freq, Length sigma, double contrast = 0.5, Angle orient = 0.0*degree, Angle phs=0.0*degree);
143
144                 virtual QuickGabor& setDatum(const Point &po);
145                 virtual QuickGabor& shift(const double x, const double y, const double z = 0.0);
146                 virtual QuickGabor& centering(const double x, const double y, const double z = 0.0);
147                 virtual QuickGabor& centering(const Point &po);
148                 virtual QuickGabor& centering(const Drawable &target = *Drawable::prime);
149
150                 virtual QuickGabor& draw(Drawable &target = *Drawable::prime);
151                 virtual QuickGabor& draw(int x, int y, Drawable &target = *Drawable::prime);
152         };
153
154 }
155
156
157 #endif