Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenWalnut Core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
3a3b3a27
Commit
3a3b3a27
authored
Nov 17, 2014
by
reichenbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] added colors to histogram dataset bins
parent
20fa73ce
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
8 deletions
+61
-8
src/core/common/WHistogramBasic.cpp
src/core/common/WHistogramBasic.cpp
+8
-6
src/core/common/WHistogramBasic.h
src/core/common/WHistogramBasic.h
+3
-1
src/core/dataHandler/WDataSetHistogram1D.cpp
src/core/dataHandler/WDataSetHistogram1D.cpp
+21
-1
src/core/dataHandler/WDataSetHistogram1D.h
src/core/dataHandler/WDataSetHistogram1D.h
+29
-0
No files found.
src/core/common/WHistogramBasic.cpp
View file @
3a3b3a27
...
...
@@ -78,27 +78,29 @@ std::pair< double, double > WHistogramBasic::getIntervalForIndex( std::size_t in
return
std
::
make_pair
(
first
,
second
);
}
void
WHistogramBasic
::
insert
(
double
value
)
std
::
size_t
WHistogramBasic
::
insert
(
double
value
)
{
if
(
value
>
m_maximum
||
value
<
m_minimum
)
{
wlog
::
warn
(
"WHistogramBasic"
)
<<
std
::
scientific
<<
std
::
setprecision
(
16
)
<<
"Inserted value out of bounds, thread: "
<<
value
<<
" as min, resp. max: "
<<
m_minimum
<<
","
<<
m_maximum
;
return
;
// value = ( value > m_maximum ? m_maximum : m_minimum )
;
return
0u
-
1u
;
}
if
(
std
::
abs
(
m_minimum
-
m_maximum
)
<=
2.0
*
wlimits
::
DBL_EPS
)
{
m_bins
.
at
(
m_nbBuckets
-
1
)
++
;
return
m_nbBuckets
-
1
;
}
else
if
(
value
>=
(
m_maximum
-
m_intervalWidth
)
&&
value
<=
m_maximum
)
// last bin deserves extra treatment due to possbl out of bounds index
{
m_bins
.
at
(
m_nbBuckets
-
1
)
++
;
return
m_nbBuckets
-
1
;
}
else
{
m_bins
.
at
(
static_cast
<
std
::
size_t
>
(
(
value
-
m_minimum
)
/
std
::
abs
(
m_maximum
-
m_minimum
)
*
(
m_nbBuckets
)
)
)
++
;
}
std
::
size_t
bin
=
static_cast
<
std
::
size_t
>
(
(
value
-
m_minimum
)
/
std
::
abs
(
m_maximum
-
m_minimum
)
*
(
m_nbBuckets
)
);
m_bins
.
at
(
bin
)
++
;
return
bin
;
}
size_t
WHistogramBasic
::
valuesSize
()
const
...
...
src/core/common/WHistogramBasic.h
View file @
3a3b3a27
...
...
@@ -109,8 +109,10 @@ public:
* Inserts a given value within the given range (min, max) into exactly one bin and increment its size.
*
* \param value Value to insert.
*
* \return The index of the bin the value was inserted into or the maximum size_t if it was out of range.
*/
virtual
void
insert
(
double
value
);
virtual
std
::
size_t
insert
(
double
value
);
protected:
private:
...
...
src/core/dataHandler/WDataSetHistogram1D.cpp
View file @
3a3b3a27
...
...
@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include "WDataSetHistogram1D.h"
...
...
@@ -31,7 +32,16 @@ boost::shared_ptr< WPrototyped > WDataSetHistogram1D::m_prototype = boost::share
WDataSetHistogram1D
::
WDataSetHistogram1D
(
boost
::
shared_ptr
<
WHistogramBasic
const
>
const
&
histo
)
:
WDataSet
(),
m_histogram
(
new
WHistogramBasic
(
*
histo
)
)
m_histogram
(
new
WHistogramBasic
(
*
histo
)
),
m_colors
()
{
}
WDataSetHistogram1D
::
WDataSetHistogram1D
(
boost
::
shared_ptr
<
WHistogramBasic
const
>
const
&
histo
,
boost
::
shared_ptr
<
std
::
vector
<
WColor
>
const
>
const
&
colors
)
:
WDataSet
(),
m_histogram
(
new
WHistogramBasic
(
*
histo
)
),
m_colors
(
colors
)
{
}
...
...
@@ -70,3 +80,13 @@ boost::shared_ptr< WHistogramBasic const > const& WDataSetHistogram1D::getHistog
return
m_histogram
;
}
bool
WDataSetHistogram1D
::
hasColors
()
const
{
return
m_histogram
&&
m_colors
&&
m_colors
->
size
()
==
m_histogram
->
size
();
}
WColor
WDataSetHistogram1D
::
getColor
(
std
::
size_t
bin
)
const
{
return
m_colors
->
at
(
bin
);
}
src/core/dataHandler/WDataSetHistogram1D.h
View file @
3a3b3a27
...
...
@@ -26,8 +26,10 @@
#define WDATASETHISTOGRAM1D_H
#include <string>
#include <vector>
#include "../common/WHistogramBasic.h"
#include "../common/WColor.h"
#include "WDataSet.h"
...
...
@@ -56,6 +58,14 @@ public:
*/
explicit
WDataSetHistogram1D
(
boost
::
shared_ptr
<
WHistogramBasic
const
>
const
&
histo
);
/**
* Construct a histogram and allows to set an array of colors used for the bins.
*
* \param histo The histogram.
* \param colors An array of one color per bin.
*/
WDataSetHistogram1D
(
boost
::
shared_ptr
<
WHistogramBasic
const
>
const
&
histo
,
boost
::
shared_ptr
<
std
::
vector
<
WColor
>
const
>
const
&
colors
);
/**
* Construct an empty and unusable instance. This is needed for the prototype mechanism.
*/
...
...
@@ -94,6 +104,22 @@ public:
*/
static
boost
::
shared_ptr
<
WPrototyped
>
getPrototype
();
/**
* Whether this dataset has colors associated with the bins.
*
* \return true, if this dataset has colors.
*/
bool
hasColors
()
const
;
/**
* Get the color of a bin.
*
* \param bin The index of the bin to get the color from.
*
* \return The color of the bin.
*/
WColor
getColor
(
std
::
size_t
bin
)
const
;
protected:
/**
* The prototype as singleton.
...
...
@@ -103,6 +129,9 @@ protected:
private:
//! The histogram.
boost
::
shared_ptr
<
WHistogramBasic
const
>
const
m_histogram
;
//! The colors for the bins.
boost
::
shared_ptr
<
std
::
vector
<
WColor
>
const
>
const
m_colors
;
};
#endif // WDATASETHISTOGRAM1D_H
...
...
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