~ubuntu-branches/debian/sid/3depict/sid

« back to all changes in this revision

Viewing changes to src/effect.h

  • Committer: Bazaar Package Importer
  • Author(s): D Haley, Sylvestre Ledru
  • Date: 2011-04-12 17:44:06 UTC
  • mfrom: (1.2.1 upstream) (3.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110412174406-zz06iu3xmardt43s
Tags: 0.0.5-1
[ Sylvestre Ledru ]
* watch file added
* Switch to dpkg-source 3.0 (quilt) format

* New upstream version 

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#ifndef EFFECT_H
20
20
#define EFFECT_H
21
21
 
22
 
#include "basics.h"
 
22
#include <string>
 
23
#include <libxml/xmlreader.h>
23
24
 
24
25
//OpenGL includes
25
26
//MacOS is "special" and puts it elsewhere
31
32
 
32
33
#include "cameras.h"
33
34
 
34
 
//opengl allows up to 8 clipping planes
 
35
 
 
36
//opengl allows up to 6 clipping planes
35
37
const unsigned int MAX_OPENGL_CLIPPLANES=6;
36
38
 
37
 
//Effect6 IDs
 
39
                        
 
40
 
 
41
//Effect IDs
38
42
enum
39
43
{
40
 
        EFFECT_PLANE_CROP=1,
 
44
        EFFECT_BOX_CROP=0,
 
45
        EFFECT_ANAGLYPH,
41
46
        EFFECT_ENUM_END
42
47
};
43
48
 
 
49
 
 
50
enum{
 
51
        //Colour mask methods
 
52
        ANAGLYPH_REDBLUE,
 
53
        ANAGLYPH_REDGREEN,
 
54
        ANAGLYPH_REDCYAN,
 
55
        ANAGLYPH_GREENMAGENTA,
 
56
        //Colour matrix +accumulation buffer methods
 
57
        ANAGLYPH_HALF_COLOUR,
 
58
        ANAGLYPH_MIXED
 
59
                ,
 
60
        ANAGLYPH_ENUM_END //Not a method. end of enum
 
61
};
 
62
 
44
63
class Effect
45
64
{
46
65
        protected:
47
 
                static const Camera *curCam;
 
66
                static Camera *curCam;
 
67
                static BoundCube bc;
48
68
                unsigned int effectType;
49
69
        public:
50
 
                virtual void enable() const=0;
 
70
                virtual void enable(unsigned int pass=0) const =0;
51
71
                virtual void disable() const=0;
52
 
                virtual unsigned int getMax() const=0;
 
72
 
 
73
 
 
74
                //Write the effect's state information to file
 
75
                virtual bool writeState(std::ofstream &f, 
 
76
                                unsigned int format, unsigned int depth) const=0;
 
77
                //read the effects state information from an XML file
 
78
                virtual bool readState(xmlNodePtr &n)=0;
 
79
 
 
80
                virtual bool needCamUpdate() const { return false;}
 
81
 
 
82
                //!Returns true if the effect has any influence on the output
 
83
                virtual bool willDoSomething() const=0;
 
84
 
 
85
                virtual unsigned int numPassesNeeded() const { return 1;}
53
86
 
54
87
                virtual unsigned int getType() const { return effectType;};
55
88
                static void setCurCam(Camera *c) {curCam=c;}
56
 
 
57
 
};
58
 
 
59
 
class PlaneCropEffect : public Effect
60
 
{
61
 
        private:
62
 
                static unsigned int nextGLId;
63
 
                unsigned int openGLId;
64
 
                Point3D origin, normal;
65
 
        public:
66
 
                PlaneCropEffect(){effectType=EFFECT_PLANE_CROP;openGLId=nextGLId; 
67
 
                        nextGLId++; ASSERT(nextGLId < MAX_OPENGL_CLIPPLANES);}
68
 
 
69
 
                void enable() const;
70
 
 
71
 
                void disable() const;
72
 
                virtual unsigned int getMax() const;
73
 
};
 
89
                static void setBoundingCube(const BoundCube &c) {bc=c;}
 
90
 
 
91
};
 
92
 
 
93
 
 
94
class BoxCropEffect : public Effect
 
95
{
 
96
        private:
 
97
                //controlling ID values for gl plane. No more than MAX_OPENGL_CLIPPLANES allowed
 
98
                unsigned int openGLIdStart,openGLIdEnd;
 
99
                //Cropping margins (Fraction from edge towards opposite edge (complete)). 0->1. 
 
100
                //Opposing edges must sum to 0->1. (xLo,xHi,yLo...)
 
101
                float cropFractions[6];
 
102
                //!True if we should transform to camera coordinates before applying crop
 
103
                bool useCamCoordinates;
 
104
 
 
105
                //!Aspect ratio of output image
 
106
                float outputAspect;
 
107
 
 
108
                void doClip(const Point3D &origin, const Point3D & normal,unsigned int glOffset) const;
 
109
        public:
 
110
                BoxCropEffect(){useCamCoordinates=false;effectType=EFFECT_BOX_CROP;openGLIdStart=0; }
 
111
                ~BoxCropEffect(){}; 
 
112
 
 
113
                //!Enable the clipping plane. Values *must* be set before calling
 
114
                void enable(unsigned int pass) const;
 
115
 
 
116
                //!DIsable the clipping plane
 
117
                void disable() const;
 
118
 
 
119
 
 
120
 
 
121
                //Write the effect's state information to file
 
122
                bool writeState(std::ofstream &f, unsigned int format,
 
123
                                unsigned int depth) const;
 
124
                //read the effects state information from an XML file
 
125
                bool readState(xmlNodePtr &n);
 
126
 
 
127
                //!Returns true if the effect has any influence on the output
 
128
                bool willDoSomething() const;
 
129
 
 
130
                //!Set the fractions of cube from margin
 
131
                //-- there should be 6 floats (x,y,z)_(low,high) (x_lo, x_hi....)
 
132
                //  each low/hi should form a sum between 0 and 1.
 
133
                void setFractions(const float *fractionArray);
 
134
 
 
135
                void useCamCoords(bool enable){useCamCoordinates=enable;};
 
136
 
 
137
                //!Alters the input box to generate cropping bounding box
 
138
                //note the box may be inside out if the cropping limits
 
139
                //exceed themselves..
 
140
                void getCroppedBounds(BoundCube &b) const;
 
141
 
 
142
                float getCropValue(unsigned int pos) const {ASSERT(pos<6); return cropFractions[pos];}
 
143
};
 
144
 
 
145
class AnaglyphEffect : public Effect
 
146
{
 
147
        private:
 
148
                unsigned int colourMode;
 
149
                bool eyeFlip;
 
150
                
 
151
                mutable Camera *oldCam;
 
152
                float baseShift;
 
153
 
 
154
        public:
 
155
                AnaglyphEffect(){effectType=EFFECT_ANAGLYPH;colourMode=ANAGLYPH_REDBLUE;oldCam=0;baseShift=0.01f; eyeFlip=false;}
 
156
                ~AnaglyphEffect(){}; 
 
157
 
 
158
                //!Enable the clipping plane. Values *must* be set before calling
 
159
                void enable(unsigned int pass) const;
 
160
 
 
161
                //!DIsable the clipping plane
 
162
                void disable() const;
 
163
 
 
164
                //Write the effect's state information to file
 
165
                bool writeState(std::ofstream &f, unsigned int format,
 
166
                                unsigned int depth) const;
 
167
                //read the effects state information from an XML file
 
168
                bool readState(xmlNodePtr &n);
 
169
                
 
170
                //!Whether we should be flipping the lens from its hard-coded left-right
 
171
                void setFlip(bool shouldFlip) {eyeFlip=shouldFlip;};
 
172
 
 
173
                void setMode(unsigned int mode){ASSERT(colourMode<ANAGLYPH_ENUM_END);colourMode=mode;};
 
174
                void setBaseShift(float shift) { baseShift=shift;};
 
175
 
 
176
                bool needCamUpdate() const { return true;}
 
177
                //!Returns true if the effect has any influence on the output
 
178
                bool willDoSomething() const {return true;};
 
179
 
 
180
                virtual unsigned int numPassesNeeded() const { return 2;}
 
181
 
 
182
 
 
183
                float getBaseShift() const { return baseShift;};
 
184
                unsigned int getMode() const { return colourMode;};
 
185
 
 
186
                        
 
187
};
 
188
 
 
189
 
 
190
Effect *makeEffect(unsigned int effectID);
 
191
 
 
192
Effect *makeEffect(const std::string &s);
 
193
 
74
194
 
75
195
#endif