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
9173c84b
Commit
9173c84b
authored
May 27, 2013
by
Mathias Goldau
Browse files
[ADD] New member function to scale 2D histograms to spherical textures.
parent
0aca3abe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
6 deletions
+62
-6
src/core/common/WHistogram2D.cpp
src/core/common/WHistogram2D.cpp
+55
-5
src/core/common/WHistogram2D.h
src/core/common/WHistogram2D.h
+7
-1
No files found.
src/core/common/WHistogram2D.cpp
View file @
9173c84b
...
...
@@ -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
)
...
...
@@ -149,6 +149,56 @@ WGETexture2D::RPtr WHistogram2D::getTexture()
data
[
i
+
j
*
imageWidth
]
=
static_cast
<
float
>
(
m_bins
(
i
,
j
)
)
/
maxCount
;
}
}
;
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 @
9173c84b
...
...
@@ -42,7 +42,6 @@
class
WHistogram2D
:
public
WHistogramND
<
2
>
// NOLINT
{
public:
/**
* Convenience type for a shared_ptr on this type.
*/
...
...
@@ -132,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