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
833e6154
Commit
833e6154
authored
May 28, 2013
by
Sebastian Eichelbaum
Browse files
[MERGE]
parents
e6e58f2c
b0dc6bf6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
4 deletions
+61
-4
src/core/common/WHistogram2D.cpp
src/core/common/WHistogram2D.cpp
+54
-4
src/core/common/WHistogram2D.h
src/core/common/WHistogram2D.h
+7
-0
No files found.
src/core/common/WHistogram2D.cpp
View file @
833e6154
...
...
@@ -24,6 +24,7 @@
#include <utility>
#include <core/common/math/WMath.h>
#include <core/graphicsEngine/WGETexture.h>
#include "WAssert.h"
#include "WHistogram2D.h"
...
...
@@ -124,10 +125,9 @@ WGETexture2D::RPtr 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
float
maxCount
=
0
;
for
(
size_t
j
=
0
;
j
<
imageHeight
;
++
j
)
for
(
size_t
j
=
0
;
j
<
imageHeight
;
++
j
)
// get max bin for scaling
{
for
(
size_t
i
=
0
;
i
<
imageWidth
;
++
i
)
{
...
...
@@ -140,8 +140,8 @@ WGETexture2D::RPtr WHistogram2D::getTexture()
image
->
allocateImage
(
imageWidth
,
imageHeight
,
1
,
GL_RED
,
GL_FLOAT
);
image
->
setInternalTextureFormat
(
GL_RED
);
float
*
data
=
reinterpret_cast
<
float
*
>
(
image
->
data
()
);
for
(
size_t
j
=
0
;
j
<
imageHeight
;
++
j
)
{
for
(
size_t
i
=
0
;
i
<
imageWidth
;
++
i
)
...
...
@@ -152,3 +152,53 @@ WGETexture2D::RPtr WHistogram2D::getTexture()
return
WGETexture2D
::
RPtr
(
new
WGETexture2D
(
image
)
);
}
/**
* Unnamed namespace for helper functions keeping the code DRY as possible.
*/
namespace
{
double
calcAreaScale
(
const
double
bucket
,
const
size_t
j
)
{
double
theta
=
piDouble
-
(
j
*
bucket
+
(
bucket
/
2.0
)
);
return
1.0
/
sin
(
theta
);
}
}
WGETexture2D
::
RPtr
WHistogram2D
::
getSphereTexture
()
{
osg
::
ref_ptr
<
osg
::
Image
>
image
=
new
osg
::
Image
();
size_t
imageWidth
=
m_buckets
[
0
];
size_t
imageHeight
=
m_buckets
[
1
];
double
maxCount
=
0.0
;
const
double
bucket
=
piDouble
/
static_cast
<
double
>
(
imageHeight
);
double
areaScale
=
0.0
;
for
(
size_t
j
=
0
;
j
<
imageHeight
;
++
j
)
// get max bin for scaling
{
areaScale
=
calcAreaScale
(
bucket
,
j
);
for
(
size_t
i
=
0
;
i
<
imageWidth
;
++
i
)
{
if
(
areaScale
*
m_bins
(
i
,
j
)
>
maxCount
)
{
maxCount
=
areaScale
*
static_cast
<
double
>
(
m_bins
(
i
,
j
)
);
}
}
}
image
->
allocateImage
(
imageWidth
,
imageHeight
,
1
,
GL_RED
,
GL_FLOAT
);
image
->
setInternalTextureFormat
(
GL_RED
);
float
*
data
=
reinterpret_cast
<
float
*
>
(
image
->
data
()
);
for
(
size_t
j
=
0
;
j
<
imageHeight
;
++
j
)
{
areaScale
=
calcAreaScale
(
bucket
,
j
);
for
(
size_t
i
=
0
;
i
<
imageWidth
;
++
i
)
{
data
[
i
+
j
*
imageWidth
]
=
areaScale
*
static_cast
<
double
>
(
m_bins
(
i
,
j
)
)
/
maxCount
;
}
}
return
WGETexture2D
::
RPtr
(
new
WGETexture2D
(
image
)
);
}
src/core/common/WHistogram2D.h
View file @
833e6154
...
...
@@ -131,6 +131,13 @@ public:
*/
WGETexture2D
::
RPtr
getTexture
();
/**
* Copy-convert this into a spherical texture. \e Spherical means hereby, that buckets representing areas near the poles have scaled counters.
*
* \return \c osg::ref_ptr to the two-dimensional spherical texture.
*/
WGETexture2D
::
RPtr
getSphereTexture
();
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