AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ImageValueInterpreter.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXIO_IMAGEVALUEINTERPRETER_H
18#define AGXIO_IMAGEVALUEINTERPRETER_H
19
20#include <agxIO/Image.h>
21#include <agx/Vec4.h>
22
23namespace agxIO
24{
25 typedef float (*GetValueFunction)( float val );
26 typedef float (*ReadValue01Function)( agxIO::Image* image, size_t x, size_t y );
27
28 inline float linearValueFunction( float val )
29 {
30 return val;
31 }
32
33 inline float quadraticValueFunction( float val )
34 {
35 return val*val;
36 }
37
38 inline float cubicValueFunction( float val )
39 {
40 return val*val*val;
41 }
42
43 inline float readOneOrTwoChannelValue01( agxIO::Image* image, size_t x, size_t y )
44 {
45 size_t pos = (size_t)image->getWidth() * y + x;
46 pos *= (size_t)image->getChannels();
47 return 0.00392156863f * image->getData()[ pos ]; // unsigned char / 255.0.
48 }
49
50 inline float readThreeChannelMergedValue01( agxIO::Image* image, size_t x, size_t y )
51 {
52 const unsigned char* data = image->getData();
53 size_t pos = (size_t)image->getWidth() * y + x;
54 pos *= 3;
55 return 0.00392156863f * float(( 77 * data[ pos ] + 150 * data[ pos + 1 ] + 29 * data[ pos + 2 ] ) >> 8);
56 }
57
58 inline float readFourChannelMergedValue01( agxIO::Image* image, size_t x, size_t y )
59 {
60 const unsigned char* data = image->getData();
61 size_t pos = (size_t)image->getWidth() * y + x;
62 pos *= 4;
63 return 0.00392156863f * float(( 77 * data[ pos ] + 150 * data[ pos + 1 ] + 29 * data[ pos + 2 ] ) >> 8);
64 }
65
66 inline float readSingleChannelValue01( agxIO::Image* image, size_t x, size_t y, size_t channel )
67 {
68 const unsigned char* data = image->getData();
69 size_t pos = (size_t)image->getWidth() * y + x;
70 pos *= (size_t)image->getChannels();
71 return 0.00392156863f * data[ pos + channel ];
72 }
73
74 inline void writeSingleChannelValue01( unsigned char val, agxIO::Image* image, size_t x, size_t y, size_t channel )
75 {
76 unsigned char* data = image->getData();
77 size_t pos = (size_t)image->getWidth() * y + x;
78 pos *= (size_t)image->getChannels();
79 data[ pos + channel ] = val;
80 }
81
83 {
84 public:
89
95 PNGImageValueInterpreter( float minValue, float maxValue );
96
101 bool read( const std::string& filename );
102
106 bool valid() const;
107
112 void setMaxValue( float maxValue );
113
118 void setMinValue( float minValue );
119
123 float getMaxValue() const;
124
128 float getMinValue() const;
129
134
138 size_t getImageHeight() const;
139
143 size_t getImageWidth() const;
144
154 float getValue( size_t x, size_t y, GetValueFunction func = linearValueFunction ) const;
155
163 float getValueR( size_t x, size_t y, GetValueFunction func = linearValueFunction ) const;
164
173 float getValueG( size_t x, size_t y, GetValueFunction func = linearValueFunction ) const;
174
183 float getValueB( size_t x, size_t y, GetValueFunction func = linearValueFunction ) const;
184
194 float getValueA( size_t x, size_t y, GetValueFunction func = linearValueFunction ) const;
195
203 agx::Vec3f getValueRGB( size_t x, size_t y, GetValueFunction func = linearValueFunction ) const;
204
213 agx::Vec4f getValueRGBA( size_t x, size_t y, GetValueFunction func = linearValueFunction ) const;
214
219 void setValueR( unsigned char val, size_t x, size_t y );
220
225 void setValueG( unsigned char val, size_t x, size_t y );
226
231 void setValueB( unsigned char val, size_t x, size_t y );
232
237 void setValueA( unsigned char val, size_t x, size_t y );
238
239 protected:
244
245 protected:
250 };
251
253}
254
255#endif
#define AGXPHYSICS_EXPORT
Class to represent Images.
Definition Image.h:33
unsigned int getChannels() const
unsigned char * getData()
unsigned int getWidth() const
float getValueA(size_t x, size_t y, GetValueFunction func=linearValueFunction) const
Reads single "Alpha" channel at pixel (x,y) and returns value between given minimum and maximum.
agx::Vec3f getValueRGB(size_t x, size_t y, GetValueFunction func=linearValueFunction) const
Reads R, G, and B channels and returns Vec3f with result at pixel (x,y).
PNGImageValueInterpreter()
Default constructor.
float getValueG(size_t x, size_t y, GetValueFunction func=linearValueFunction) const
Reads single "Green" channel at pixel (x,y) and returns value between given minimum and maximum.
virtual ~PNGImageValueInterpreter()
Reference counted object.
void setMaxValue(float maxValue)
Set new maximum value for the accessors methods (i.e., channel value = 255 => maximum value).
agx::Vec4f getValueRGBA(size_t x, size_t y, GetValueFunction func=linearValueFunction) const
Reads R, G, B and A channels and returns Vec4f with result at pixel (x,y).
void setValueG(unsigned char val, size_t x, size_t y)
Set current value to the "Green" channel.
void setValueA(unsigned char val, size_t x, size_t y)
Set current value to the "Alpha" channel.
bool read(const std::string &filename)
Read PNG image.
float getValueR(size_t x, size_t y, GetValueFunction func=linearValueFunction) const
Reads single "Red" channel at pixel (x,y) and returns value between given minimum and maximum.
agxIO::Image * getImage() const
void setMinValue(float minValue)
Set new minimum value for the accessors methods (i.e., channel value = 0 => minimum value).
void setValueR(unsigned char val, size_t x, size_t y)
Set current value to the "Red" channel.
PNGImageValueInterpreter(float minValue, float maxValue)
Construct given minimum- and maximum value.
float getValue(size_t x, size_t y, GetValueFunction func=linearValueFunction) const
Reads image at pixel (x,y) and returns value between given minimum and maximum.
void setValueB(unsigned char val, size_t x, size_t y)
Set current value to the "Blue" channel.
float getValueB(size_t x, size_t y, GetValueFunction func=linearValueFunction) const
Reads single "Blue" channel at pixel (x,y) and returns value between given minimum and maximum.
Base class providing referencing counted objects.
Definition Referenced.h:120
A class holding 4 dimensional vectors and providing basic arithmetic.
The agxIO namespace contains classes for reading, writing and finding files.
Definition Material.h:42
float linearValueFunction(float val)
float readThreeChannelMergedValue01(agxIO::Image *image, size_t x, size_t y)
float cubicValueFunction(float val)
float quadraticValueFunction(float val)
float readSingleChannelValue01(agxIO::Image *image, size_t x, size_t y, size_t channel)
float readOneOrTwoChannelValue01(agxIO::Image *image, size_t x, size_t y)
float(* GetValueFunction)(float val)
float readFourChannelMergedValue01(agxIO::Image *image, size_t x, size_t y)
agx::ref_ptr< PNGImageValueInterpreter > PNGImageValueInterpreterRef
void writeSingleChannelValue01(unsigned char val, agxIO::Image *image, size_t x, size_t y, size_t channel)
float(* ReadValue01Function)(agxIO::Image *image, size_t x, size_t y)