Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
a9bf2594
Commit
a9bf2594
authored
Apr 23, 2013
by
Mathias Goldau
Browse files
[ADD] Texture generation for 2D Histograms
parent
6fc26f74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
src/core/common/WHistogram2D.cpp
src/core/common/WHistogram2D.cpp
+34
-0
src/core/common/WHistogram2D.h
src/core/common/WHistogram2D.h
+15
-0
No files found.
src/core/common/WHistogram2D.cpp
View file @
a9bf2594
...
...
@@ -24,6 +24,8 @@
#include <utility>
#include <osg/Texture2D>
#include "WAssert.h"
#include "WHistogram2D.h"
#include "WLimits.h"
...
...
@@ -118,3 +120,35 @@ void WHistogram2D::insert( double x, double y )
insert
(
values
);
}
osg
::
ref_ptr
<
osg
::
Texture2D
>
WHistogram2D
::
getTexture
()
{
osg
::
ref_ptr
<
osg
::
Image
>
image
=
new
osg
::
Image
();
size_t
imageWidth
=
m_buckets
[
0
];
size_t
imageHeight
=
m_buckets
[
1
];
//get max bin for scaling
size_t
maxCount
=
0
;
for
(
int
j
=
0
;
j
<
imageHeight
;
j
++
)
{
for
(
int
i
=
0
;
i
<
imageWidth
;
i
++
)
{
if
(
m_bins
(
i
,
j
)
>
maxCount
)
{
maxCount
=
m_bins
(
i
,
j
);
}
}
}
// allocate the image data, size x 1 x 1 with 4 rgba floats - equivalent to a Vec4!
image
->
allocateImage
(
imageWidth
,
imageHeight
,
1
,
GL_RED
,
GL_FLOAT
);
image
->
setInternalTextureFormat
(
GL_RED
);
float
*
data
=
reinterpret_cast
<
float
*
>
(
image
->
data
()
);
for
(
int
j
=
0
;
j
<
imageHeight
;
j
++
)
{
for
(
int
i
=
0
;
i
<
imageWidth
;
i
++
)
{
data
[
i
+
j
*
imageWidth
]
=
(
float
)
m_bins
(
i
,
j
)
/
(
float
)
maxCount
;
}
}
return
new
osg
::
Texture2D
(
image
);
}
src/core/common/WHistogram2D.h
View file @
a9bf2594
...
...
@@ -31,6 +31,8 @@
#include <Eigen/Core>
#include <osg/Texture2D>
#include "WHistogramND.h"
/**
...
...
@@ -40,6 +42,12 @@
class
WHistogram2D
:
public
WHistogramND
<
2
>
// NOLINT
{
public:
/**
* Convenience type for a shared_ptr on this type.
*/
typedef
boost
::
shared_ptr
<
WHistogram2D
>
SPtr
;
/**
* Creates a two dimensional histogram field, bounded by the given limits, containing the demanded number of buckets in each dimension.
*
...
...
@@ -117,6 +125,13 @@ public:
*/
void
insert
(
double
x
,
double
y
);
/**
* Copy-convert this into an OSG texture.
*
* \return osg::Texture2D representing this histogram.
*/
osg
::
ref_ptr
<
osg
::
Texture2D
>
getTexture
();
protected:
private:
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment