Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageCanvasGLBase.cpp
1 // Jan Woetzel
2 #ifdef WIN32
3 # pragma warning (disable: 4005) // for VS8 + WX
4 #endif
5 
6 #include "ImageCanvasGLBase.hh"
7 
8 #include <Base/Debug/Error.hh>
9 #include <Base/Debug/DebugSimple.hh>
10 
11 #include <Base/Image/ImageIO.hh>
12 #include <Base/Math/Vector2.hh>
13 
14 #include "GeometryGL.hh"
15 
16 // -----------------------------------------
17 using namespace std;
18 using namespace BIAS;
19 // -----------------------------------------
20 
21 
22 ImageCanvasGLBase::~ImageCanvasGLBase()
23 {}
24 
25 
26 ImageCanvasGLBase::ImageCanvasGLBase(
27  wxFrame* parent
28  ,wxWindowID id
29  ,const wxPoint& pos
30  ,const wxSize& size
31  ,long style
32  ,const wxString& name
33  ,int* attribList
34  ,const wxPalette& palette )
35  : OpenGLCanvas(parent,id,pos,size,style,name,attribList,palette )
36 {
37  //CALLINFO;
38  InitMembers(); // TODO : really required?
39 }
40 
41 
42 
44  wxFrame* parent
45  ,wxGLContext* sharedContext
46  ,wxWindowID id
47  ,const wxPoint& pos
48  ,const wxSize& size
49  ,long style
50  ,const wxString& name
51  ,int* attribList
52  ,const wxPalette& palette )
53  : OpenGLCanvas(parent,sharedContext,id,pos,size,style,name,attribList,palette)
54 {
55  //CALLINFO;
56  InitMembers();
57 }
58 
59 
61 {
62  // draw a fullscreen quad
63  // textured with the image
64  if ((texobj.widthBrutto>0) && (texobj.heightBrutto>0))
65  {
68  this->texobj,
69  false /*additionalFlipY*/ );
70  }
71 }
72 
73 
75 {
76  // call the parent initializing function
78 
79  // set our own additional members:
80  InterestPoint.Set(0.5, 0.5);
81  scalefactor=1.0f;
82 }
83 
84 
85 void ImageCanvasGLBase::EnableMipMapping(const bool & avoidAliasingByMipmapping)
86 {
87  if(avoidAliasingByMipmapping) {
88  texobj.minificationMode=GL_LINEAR_MIPMAP_LINEAR; // trilinear mipmapping
89  } else {
90  texobj.minificationMode=GL_NEAREST; // accept aliasing
91  };
92 }
93 
94 
95 // unique id for OpenGL texture object
97 {
98 #ifdef BIAS_DEBUG
99  if (texobj.id!=0) /* 0 marks unused, currently */
100  BIASASSERT(glIsTexture(texobj.id));
101 #endif
102 
103  return texobj.id;
104 }
105 
106 
107 // GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_NV
109 {
110  // must be pow2 in Base class which has no Cg.
111  BIASASSERT(texobj.target==GL_TEXTURE_2D);
112  return texobj.target;
113 }
114 
115 
116 // valid texobj for capabilities od this base class?
118 {
119  if (!glIsTexture(t.id))
120  {
121  BIASERR("texture id not valid");
122  return false;
123  } else if (t.target!=GL_TEXTURE_2D) {
124  BIASERR("texture target not valid. ImageCanvasBase can only handle GL_TEXTURE_2D");
125  return false;
127  BIASERR("texture must have (brutto) pow2 size. please pad it yourself. npot is not supporte din Base class.");
128  return false;
129  } else if (t.widthBrutto<=1){
130  BIASERR("texture widthBrutto too small");
131  return false;
132  } else if (t.heightBrutto<=1){
133  BIASERR("texture heightBrutto too small");
134  return false;
135  };
136  // OK
137  return true;
138 }
139 
140 
141 int ImageCanvasGLBase::Set(const ImgObjGL & NewTexobj,
142  const std::string & name)
143 {
144  this->name = name;
145  this->SetCurrent();
146  if (!ValidTexobj(NewTexobj)) {
147  //BIASERR("texture id not valid");
148  return -1;
149  };
150 
151  // OK
152  // clear old texobj, first:
154  delete this->texobj.p_valueImage;
155  this->texobj.p_valueImage=NULL;
156  }
157  // copy new texobj
158  this->texobj = NewTexobj;
159  // we should not deallocate because we didn't allocate and copied instead
161  this->name = name;
162 
163  // redisplay because we changed the texture
164  this->Display();
165 
166  return 0; // OK
167 }
168 
169 
171  const std::string & name,
172  const bool & forcePow2tex,
173  const bool & flipY
174  )
175 {
176  this->name = name;
177  // void SetCurrent on creation:
178  if (GetParent()->IsShown()) this->SetCurrent();
180  forcePow2tex, // true
181  flipY, // true
182  true /* ImmediateCopyData*/
183  );
184 
185  // redisplay because we changed the texture
186  this->Display();
187 
188  return 0; // OK
189 }
190 
191 
193  const std::string & name,
194  const bool & flipY )
195 {
196  this->GetTexobj().SetTargetRECT();
197  return this->Set(img,
198  name,
199  false, /* forcePow2tex */
200  flipY );
201 }
virtual void Display()
display call to be overridden by child classes
virtual void InitMembers()
any constructor should call this function to initialize all data members (e.g.
bool IsPowerOfTwoSize() const
Definition: ImageBase.cpp:940
virtual void InitMembers()
any constructor should call this function to initialize all data members (e.g.
BIAS::ImageBase * p_valueImage
Definition: ImgObjGL.hh:155
int SetRECT(BIAS::ImageBase &img, const std::string &name=std::string("RECT Image<unsigned char>"), const bool &flipY=true)
sets imaeg as a RECT texture JW
GLenum minificationMode
Definition: ImgObjGL.hh:143
void SetTargetRECT()
Definition: ImgObjGL.cpp:164
OpenGL canvases with additinal event handling (JW)
Definition: OpenGLCanvas.hh:68
unsigned int heightBrutto
Definition: ImgObjGL.hh:152
bool p_valueImage_SelfAllocated
Definition: ImgObjGL.hh:159
data holder describing OpenGL texture objects in addition to its unique texID.
Definition: ImgObjGL.hh:34
void Set(const T &scalar)
set all elements to a scalar value
Definition: Vector2.hh:190
static void DisplayQuadTexCoord2DFull(const BIAS::ImgObjGL &texobj, const bool &additionalFlipY)
Definition: GeometryGL.cpp:956
void EnableMipMapping(const bool &avoidAliasingByMipmapping=true)
set to true for prettier OpenGL texture mipmapping display (which costs performance) JW ...
CameraViewInternals GetInternals() const
ImgObjGL GetTexobj() const
void DisplayGL() const
int Set(const ImgObjGL &NewTexobj, const std::string &name=std::string("ImgObjGL"))
feed in an existing, possibly shared, GL texture obj for display note: it is no good idea to call th...
ImageCanvasGLBase(wxFrame *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=AsciiToWx("ImageCanvasGLBase"), int *attribList=NULL, const wxPalette &palette=wxNullPalette)
void CreateGLTexture(const BIAS::ImageBase &c_img, const bool &forcePow2tex=true, const bool &flipY=true, const bool ImmediateCopyData=IMGOBJ_IMMEDIATE_COPY_DEFAULT)
creates an OpenGL texture from p_valueImage JW if ImmediateCopyData is false the memory is just all...
Definition: ImgObjGL.cpp:182
bool ValidTexobj(const ImgObjGL &t) const
BIAS::Vector2< float > InterestPoint
GLenum target
Definition: ImgObjGL.hh:138
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
unsigned int widthBrutto
Definition: ImgObjGL.hh:151
CameraViewController GetViewController() const