Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SceneTexturedPlane.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __SCENETEXTUREDPLANE_HH__
26 #define __SCENETEXTUREDPLANE_HH__
27 
28 #include <bias_config.h>
29 
30 #include <GLviewer/Scenes/SceneBase.hh>
31 #include <Base/Image/Image.hh>
32 #include <Base/Math/Vector2.hh>
33 #include <Base/Math/Vector3.hh>
34 
35 namespace BIAS
36 {
37  /**
38  @class SceneTexturedPlane
39  @brief Display a textured plane. Lighting is computed appropriately.
40  @author esquivel
41  @ingroup g_glviewer
42  */
43  class BIASGLviewer_EXPORT SceneTexturedPlane : public SceneBase
44  {
45  public:
46 
47  /** @brief Create new plane with given position, size and orientation. */
49  const BIAS::Vector3<double> &width,
50  const BIAS::Vector3<double> &height,
51  const int widthSubsections = 1,
52  const int heightSubsections = 1,
53  const int minFilter = GL_NEAREST,
54  const int magFilter = GL_NEAREST,
55  const int wrapping = GL_REPEAT);
56 
57  virtual ~SceneTexturedPlane();
58 
59  /** @brief Reset position and size of plane. */
60  void Resize(const BIAS::Vector3<double> &topLeft,
61  const BIAS::Vector3<double> &width,
62  const BIAS::Vector3<double> &height,
63  const int widthSubsections = 1,
64  const int heightSubsections = 1);
65 
66  /** @brief Set texture image and reset texture coordinates for plane.
67  @attention Previously set texture will be deleted!
68  @return Returns ID of created texture, or <0 in case of errors.
69  */
70  int SetImage(const BIAS::Image<unsigned char> &image);
71 
72  /** @brief Load texture image and reset texture coordinates for plane.
73  @attention Previously set texture will be deleted!
74  @return Returns ID of created texture, or <0 in case of errors.
75  */
76  int SetImage(const std::string &imageFilename);
77 
78  /** @brief Set texture image from existing texture ID and reset texture
79  coordinates for plane.
80  @attention Previously set texture will be deleted!
81  @return Returns texture ID, or <0 in case of errors.
82  */
83  int SetImage(const int texID, const int width, const int height);
84 
85  /** @brief Set texture coordinates for plane texture in pixels. */
86  void SetTextureCoordinates(const BIAS::Vector2<int> topLeft,
87  const BIAS::Vector2<int> bottomRight);
88 
89  /** @brief Set texture coordinates for plane texture in texels. */
90  void SetTextureCoordinates(const BIAS::Vector2<float> topLeft,
91  const BIAS::Vector2<float> bottomRight);
92 
93  /** @brief Draw plane normal for debugging purposes? */
94  void DrawNormal(const bool draw = true, const float length = 1.0f)
95  { drawNormal_ = draw; if (draw) drawNormalLength_ = length; }
96 
97  /** @brief Implementation of the SceneBase GetBoundingBox method. */
98  virtual void GetBoundingBox(BIAS::Vector3<double> &minVal,
99  BIAS::Vector3<double> &maxVal);
100 
101  protected:
102 
103  /** @brief Implementation of the SceneBase Draw method. */
104  virtual void Draw();
105 
106  /** @brief Stores plane corners (top left/right, bottom right/left). */
107  BIAS::Vector3<float> corners_[4];
108 
109  /** @brief Stores normal direction of plane. */
111 
112  /** @brief Stores top left and bottom right texture coordinates. */
113  BIAS::Vector2<float> texCoords_[2];
114 
115  /** @brief Stores width and height of texture. */
117 
118  /** @brief Initialize and bind texture.
119  @return Returns ID of created texture, or <0 in case of errors.
120  */
121  int InitializeTexture_(BIAS::Image<unsigned char> &texture);
122 
123  /** @brief Specifies if texture of plane has been initialized. */
125 
126  /** @brief Draw plane normal for debugging purposes? */
129 
130  /** @brief Number of subsections in horizontal/vertical direction */
131  int subsectionsX_, subsectionsY_;
132 
133  /** @brief Texture ID use to identify the texture binding */
134  GLuint texID_;
135 
136  // Specifies OpenGL specific parameters for texture rendering. */
137  GLint minFilter_, magFilter_;
138  GLint wrapping_;
139 
140  };
141 }
142 
143 #endif // __SCENETEXTUREDPLANE_HH__
BIAS::Vector2< int > texSize_
Stores width and height of texture.
void DrawNormal(const bool draw=true, const float length=1.0f)
Draw plane normal for debugging purposes?
Display a textured plane.
Base class for all scenes.
Definition: SceneBase.hh:68
GLuint texID_
Texture ID use to identify the texture binding.
bool isInitialized_
Specifies if texture of plane has been initialized.
BIAS::Vector3< float > normal_
Stores normal direction of plane.
bool drawNormal_
Draw plane normal for debugging purposes?