1 #include "SceneTexturedPlane.hh"
3 #include <bias_config.h>
4 #include <Gui/biasgl.h>
5 #include <Base/Image/ImageIO.hh>
14 const int widthSubsections,
15 const int heightSubsections,
16 const int minFilter,
const int magFilter,
19 isInitialized_ =
false;
21 drawNormalLength_ = 1.0f;
23 texCoords_[0].Set(0.0f, 0.0f);
24 texCoords_[1].Set(1.0f, 1.0f);
26 minFilter_ = minFilter;
27 magFilter_ = magFilter;
29 Resize(topLeft, width, height, widthSubsections, heightSubsections);
40 const int widthSubsections,
41 const int heightSubsections)
45 for (
unsigned int i = 0; i < 3; i++) {
46 corners_[0][i] = topLeft[i];
47 corners_[1][i] = topLeft[i] + width[i];
48 corners_[2][i] = topLeft[i] + width[i] + height[i];
49 corners_[3][i] = topLeft[i] + height[i];
50 normal_[i] = -normal[i];
52 subsectionsX_ = subsectionsY_ = 1;
53 if (widthSubsections > 1)
54 subsectionsX_ = widthSubsections;
55 if (heightSubsections > 1)
56 subsectionsY_ = heightSubsections;
64 minVal.
Set(corners_[0][0], corners_[0][1], corners_[0][2]);
65 maxVal.
Set(corners_[2][0], corners_[2][1], corners_[2][2]);
70 if (!isInitialized_)
return;
72 glPushAttrib(GL_TEXTURE_BIT);
73 glPushAttrib(GL_LIGHTING);
74 glEnable(GL_TEXTURE_2D);
75 glEnable(GL_LIGHTING);
77 glBindTexture(GL_TEXTURE_2D, texID_);
79 glMatrixMode(GL_TEXTURE);
85 float material[] = { 1.0f, 1.0f, 1.0f, 1.0f };
86 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, material);
90 if (subsectionsX_ < 2 && subsectionsY_ < 2) {
92 glTexCoord2f(texCoords_[0][0], texCoords_[0][1]);
93 glNormal3f(normal_[0], normal_[1], normal_[2]);
94 glVertex3f(corners_[0][0], corners_[0][1], corners_[0][2]);
97 glTexCoord2f(texCoords_[1][0], texCoords_[0][1]);
98 glNormal3f(normal_[0], normal_[1], normal_[2]);
99 glVertex3f(corners_[1][0], corners_[1][1], corners_[1][2]);
102 glTexCoord2f(texCoords_[1][0], texCoords_[1][1]);
103 glNormal3f(normal_[0], normal_[1], normal_[2]);
104 glVertex3f(corners_[2][0], corners_[2][1], corners_[2][2]);
107 glTexCoord2f(texCoords_[0][0], texCoords_[1][1]);
108 glNormal3f(normal_[0], normal_[1], normal_[2]);
109 glVertex3f(corners_[3][0], corners_[3][1], corners_[3][2]);
119 dx /= (float)subsectionsX_; dy /= (float)subsectionsY_;
120 dtex[0] /= subsectionsX_; dtex[1] /= subsectionsY_;
122 for (
int j = 0; j < subsectionsY_; j++) {
126 for (
int i = 0; i < subsectionsX_; i++, pos += dx, tex[0] += dtex[0]) {
128 glTexCoord2f(tex[0], tex[1]);
129 glNormal3f(normal_[0], normal_[1], normal_[2]);
130 glVertex3f(pos[0], pos[1], pos[2]);
133 glTexCoord2f(tex[0] + dtex[0], tex[1]);
134 glNormal3f(normal_[0], normal_[1], normal_[2]);
135 glVertex3f(pos[0] + dx[0], pos[1] + dx[1], pos[2] + dx[2]);
138 glTexCoord2f(tex[0] + dtex[0], tex[1] + dtex[1]);
139 glNormal3f(normal_[0], normal_[1], normal_[2]);
140 glVertex3f(pos[0] + dx[0] + dy[0], pos[1] + dx[1] + dy[1], pos[2] + dx[2] + dy[2]);
143 glTexCoord2f(tex[0], tex[1] + dtex[1]);
144 glNormal3f(normal_[0], normal_[1], normal_[2]);
145 glVertex3f(pos[0] + dy[0], pos[1] + dy[1], pos[2] + dy[2]);
156 (corners_[0] + corners_[1] + corners_[2] + corners_[3]) * 0.25f;
158 glDisable(GL_LIGHTING);
159 glDisable(GL_TEXTURE_2D);
162 glColor3f(1.0f, 1.0f, 0.0f);
163 glVertex3f(start[0], start[1], start[2]);
164 glVertex3f(end[0], end[1], end[2]);
168 glGetFloatv(GL_POINT_SIZE, &pointSize);
171 glColor3f(1.0f, 1.0f, 0.0f);
172 glVertex3f(end[0], end[1], end[2]);
174 glPointSize(pointSize);
185 texCoords_[0][0] = topLeft[0] / (float)texSize_[0];
186 texCoords_[0][1] = topLeft[1] / (float)texSize_[1];
187 texCoords_[1][0] = bottomRight[0] / (float)texSize_[0];
188 texCoords_[1][1] = bottomRight[1] / (float)texSize_[1];
195 texCoords_[0][0] = topLeft[0];
196 texCoords_[0][1] = topLeft[1];
197 texCoords_[1][0] = bottomRight[0];
198 texCoords_[1][1] = bottomRight[1];
202 SetImage(
const int texID,
const int width,
const int height)
205 glDeleteTextures(1, &texID_);
209 while (texSize_[0] < width) texSize_[0] *= 2;
210 while (texSize_[1] < height) texSize_[1] *= 2;
213 texCoords_[0].Set(0.0f, 0.0f);
214 texCoords_[1].Set(width / (
float)texSize_[0], height / (
float)texSize_[1]);
218 isInitialized_ =
true;
227 return SetImage(image);
236 BIASERR(
"Unsupported texture color model (use Gray or RGB)!");
244 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
245 if ((
int)texture.
GetWidth() > maxTexSize ||
247 BIASERR(
"Texture size is too large (use max. " << maxTexSize <<
")!");
252 texCoords_[0].Set(0.0f, 0.0f);
257 if (!isInitialized_ || (
int)texture.
GetWidth() != texSize_[0] ||
258 (int)texture.
GetHeight() != texSize_[1]) {
259 return InitializeTexture_(texture);
263 glBindTexture(GL_TEXTURE_2D, texID_);
264 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
265 glPixelStorei(GL_PACK_ALIGNMENT, 1);
268 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texSize_[0], texSize_[1],
273 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texSize_[0], texSize_[1],
274 GL_LUMINANCE, GL_UNSIGNED_BYTE, texture.
GetImageData());
285 glDeleteTextures(1, &texID_);
286 glGenTextures(1, &texID_);
289 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
290 glPixelStorei(GL_PACK_ALIGNMENT, 1);
291 glBindTexture(GL_TEXTURE_2D, texID_);
296 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texSize_[0], texSize_[1], 0,
301 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, texSize_[0], texSize_[1], 0,
302 GL_LUMINANCE, GL_UNSIGNED_BYTE, texture.
GetImageData());
304 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter_);
306 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter_);
307 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping_);
308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping_);
311 isInitialized_ =
true;
int SetImage(const BIAS::Image< unsigned char > &image)
Set texture image and reset texture coordinates for plane.
void Set(const T *pv)
copy the array of vectorsize beginning at *T to this->data_
void SetTextureCoordinates(const BIAS::Vector2< int > topLeft, const BIAS::Vector2< int > bottomRight)
Set texture coordinates for plane texture in pixels.
SceneTexturedPlane(const BIAS::Vector3< double > &topLeft, const BIAS::Vector3< double > &width, const BIAS::Vector3< double > &height, const int widthSubsections=1, const int heightSubsections=1, const int minFilter=GL_NEAREST, const int magFilter=GL_NEAREST, const int wrapping=GL_REPEAT)
Create new plane with given position, size and orientation.
virtual void Draw()
Implementation of the SceneBase Draw method.
virtual ~SceneTexturedPlane()
void Resize(const BIAS::Vector3< double > &topLeft, const BIAS::Vector3< double > &width, const BIAS::Vector3< double > &height, const int widthSubsections=1, const int heightSubsections=1)
Reset position and size of plane.
unsigned int GetWidth() const
void CrossProduct(const Vector3< T > &argvec, Vector3< T > &destvec) const
cross product of two vectors destvec = this x argvec
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
color values, 3 channels, order: red,green,blue
unsigned int GetHeight() const
int InitializeTexture_(BIAS::Image< unsigned char > &texture)
Initialize and bind texture.
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
enum EColorModel GetColorModel() const
virtual void GetBoundingBox(BIAS::Vector3< double > &minVal, BIAS::Vector3< double > &maxVal)
Implementation of the SceneBase GetBoundingBox method.
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Vector3< T > & Normalize()
normalize this vector to length 1
int PadToPowerOfTwo(BIAS::ImageBase &dest, const int &padVal=0) const
increase the size of this image to next power of two (e.g.