H3D API  2.4.1
H3DImageObject.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
28 //
30 #ifndef __H3DIMAGEOBJECT_H__
31 #define __H3DIMAGEOBJECT_H__
32 
34 #include <H3DUtil/Image.h>
35 #include "GL/glew.h"
36 
37 namespace H3D {
38 
45  class H3DAPI_API H3DImageObject {
46  public:
49  class H3DAPI_API SFImage:
50  public RefCountSField< Image, ParsableField > {
51 
52  public:
54  SFImage() : x_min( -1 ), y_min( -1 ),
55  x_max(-1), y_max( -1 ), z_min( -1 ), z_max( -1 ) {
56  }
57 
60  inline virtual void beginEditing() { resetChanges(); }
61 
64  inline virtual void endEditing() { touch(); }
65 
67  inline void setEditedArea( int _min_x, int _min_y, int _min_z,
68  int _max_x, int _max_y, int _max_z ) {
69  x_min = _min_x;
70  y_min = _min_y;
71  z_min = _min_z;
72  x_max = _max_x;
73  y_max = _max_y;
74  z_max = _max_z;
75  }
76 
83  virtual void setPixel( unsigned int x, unsigned int y,
84  const RGBA &color );
85 
94  virtual void setPixel( const Vec2f &tex_coord,
95  const RGBA &color );
96 
103  virtual void setPixel( unsigned int x, unsigned int y, unsigned int z,
104  const RGBA &color );
105 
114  virtual void setPixel( const Vec3f &tex_coord,
115  const RGBA &color );
116 
120  inline int xMin() { return x_min; }
121 
125  inline int yMin() { return y_min; }
126 
130  inline int zMin() { return z_min; }
131 
135  inline int xMax() { return x_max; }
136 
140  inline int yMax() { return y_max; }
141 
145  inline int zMax() { return z_max; }
146 
149  inline int xOffset() { return x_min; }
150 
153  inline int yOffset() { return y_min; }
154 
157  inline int zOffset() { return z_min; }
158 
161  inline int changedWidth() { return x_max - x_min + 1; }
162 
165  inline int changedHeight() { return y_max - y_min + 1; }
166 
169  inline int changedDepth() { return z_max - z_min + 1; }
170 
173  inline bool imageChanged() { return x_min != -1; }
174 
177  inline void resetChanges() { x_min = -1; }
178 
179  protected:
180  virtual void setValueFromString( const string &s ) {
181  setValue( X3D::X3DStringTo3DImage( s ) );
182  }
183  int x_min, y_min, x_max, y_max, z_min, z_max;
184  };
185 
187  H3DImageObject( Inst< SFImage > _image = 0 ):
188  image( _image ) {}
189 
191  H3DUniquePtr< SFImage > image;
192 
193  };
194 }
195 
196 #endif
Header file for X3DAppearanceChildNode, X3D scene-graph node.
The SFImage field is a field containing an Image pointer.
Definition: H3DImageObject.h:50
int xMin()
Returns the minimum value in x that has been changed by the setPixel functions.
Definition: H3DImageObject.h:120
int changedDepth()
Returns the depth of the changed part of the image.
Definition: H3DImageObject.h:169
int changedHeight()
Returns the height of the changed part of the image.
Definition: H3DImageObject.h:165
void resetChanges()
Resets all variables that keep track of what part of the image has been updated.
Definition: H3DImageObject.h:177
int yOffset()
Returns the offset in y of the changed part of the image.
Definition: H3DImageObject.h:153
virtual void endEditing()
Call this function after doing editing to the image in order to send an event that editing has been d...
Definition: H3DImageObject.h:64
int changedWidth()
Returns the width of the changed part of the image.
Definition: H3DImageObject.h:161
virtual void beginEditing()
Call this function before doing any calls to any setPixel functions in order to record all the change...
Definition: H3DImageObject.h:60
virtual void setValueFromString(const string &s)
Set the value of the field given a string.
Definition: H3DImageObject.h:180
int zMin()
Returns the minimum value in z that has been changed by the setPixel functions.
Definition: H3DImageObject.h:130
void setEditedArea(int _min_x, int _min_y, int _min_z, int _max_x, int _max_y, int _max_z)
Set the volume that has been edited manually.
Definition: H3DImageObject.h:67
int yMax()
Returns the maximum value in y that has been changed by the setPixel functions.
Definition: H3DImageObject.h:140
int yMin()
Returns the minimum value in y that has been changed by the setPixel functions.
Definition: H3DImageObject.h:125
int xMax()
Returns the maximum value in x that has been changed by the setPixel functions.
Definition: H3DImageObject.h:135
bool imageChanged()
Returns true if the image has been updated with the setPixel functions.
Definition: H3DImageObject.h:173
SFImage()
Constructor.
Definition: H3DImageObject.h:54
int xOffset()
Returns the offset in x of the changed part of the image.
Definition: H3DImageObject.h:149
int zMax()
Returns the maximum value in z that has been changed by the setPixel functions.
Definition: H3DImageObject.h:145
int zOffset()
Returns the offset in z of the changed part of the image.
Definition: H3DImageObject.h:157
This abstract interface is inherited by all nodes that contains an SFImage object with an Image conta...
Definition: H3DImageObject.h:45
H3DUniquePtr< SFImage > image
Field containing the Image to use as a texture.
Definition: H3DImageObject.h:191
H3DImageObject(Inst< SFImage > _image=0)
Constructor.
Definition: H3DImageObject.h:187
RefCountSField is almost like any SField but it encapsulates a pointer to a RefCountedClass.
Definition: RefCountSField.h:42
H3DDouble x
Vec2f()
PixelImage * X3DStringTo3DImage(const string &x3d_string)
Convert a string to a 3D PixelImage according to the X3D spec for Pixel3DTexture.
Definition: X3DFieldConversion.cpp:36
H3D API namespace.
Definition: Anchor.h:38