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
27d9921d
Commit
27d9921d
authored
Aug 04, 2010
by
Alexander Wiebel
Browse files
[MERGE]
parents
fe424a95
ee4c22e9
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1243 additions
and
297 deletions
+1243
-297
src/common/WHistogram.cpp
src/common/WHistogram.cpp
+18
-37
src/common/WHistogram.h
src/common/WHistogram.h
+64
-31
src/common/WHistogramBasic.cpp
src/common/WHistogramBasic.cpp
+102
-0
src/common/WHistogramBasic.h
src/common/WHistogramBasic.h
+127
-0
src/common/test/WHistogramBasic_test.h
src/common/test/WHistogramBasic_test.h
+17
-17
src/dataHandler/WDataSetScalar.cpp
src/dataHandler/WDataSetScalar.cpp
+19
-30
src/dataHandler/WDataSetScalar.h
src/dataHandler/WDataSetScalar.h
+25
-16
src/dataHandler/WDataTexture3D.cpp
src/dataHandler/WDataTexture3D.cpp
+7
-122
src/dataHandler/WDataTexture3D.h
src/dataHandler/WDataTexture3D.h
+0
-41
src/dataHandler/WValueSet.h
src/dataHandler/WValueSet.h
+42
-0
src/dataHandler/WValueSetBase.h
src/dataHandler/WValueSetBase.h
+16
-0
src/dataHandler/datastructures/WValueSetHistogram.cpp
src/dataHandler/datastructures/WValueSetHistogram.cpp
+239
-0
src/dataHandler/datastructures/WValueSetHistogram.h
src/dataHandler/datastructures/WValueSetHistogram.h
+204
-0
src/dataHandler/datastructures/test/WJoinContourTree_test.h
src/dataHandler/datastructures/test/WJoinContourTree_test.h
+24
-0
src/dataHandler/datastructures/test/WValueSetHistogram_test.h
...dataHandler/datastructures/test/WValueSetHistogram_test.h
+206
-0
src/dataHandler/test/WDataSetScalar_test.h
src/dataHandler/test/WDataSetScalar_test.h
+29
-0
src/dataHandler/test/WDataSetSingle_test.h
src/dataHandler/test/WDataSetSingle_test.h
+22
-0
src/dataHandler/test/WDataSetVector_test.h
src/dataHandler/test/WDataSetVector_test.h
+30
-1
src/dataHandler/test/WThreadedPerVoxelOperation_test.h
src/dataHandler/test/WThreadedPerVoxelOperation_test.h
+29
-0
src/dataHandler/test/WValueSetBase_test.h
src/dataHandler/test/WValueSetBase_test.h
+23
-2
No files found.
src/common/WHistogram.cpp
View file @
27d9921d
...
...
@@ -23,64 +23,45 @@
//---------------------------------------------------------------------------
#include <algorithm>
#include <iomanip>
#include <numeric>
#include "WAssert.h"
#include "WHistogram.h"
#include "WLimits.h"
#include "WLogger.h"
WHistogram
::
WHistogram
(
double
min
,
double
max
,
size_t
size
)
:
m_
b
in
s
(
size
,
0
),
m_m
in
(
m
in
),
m_
max
(
max
)
WHistogram
::
WHistogram
(
double
min
,
double
max
,
size_t
buckets
)
:
m_
m
in
imum
(
min
),
m_m
aximum
(
m
ax
),
m_
nbBuckets
(
buckets
)
{
if
(
min
>
max
)
{
std
::
swap
(
m_min
,
m_max
);
std
::
swap
(
m_min
imum
,
m_max
imum
);
}
WAssert
(
m_bins
.
size
()
>
0
,
"Error: A histogram with a size of 0 does not make any sense"
);
m_intervalWid
th
=
s
td
::
abs
(
m_min
-
m_max
)
/
m_bins
.
size
(
);
WAssert
(
buckets
>
0
,
"Error: A histogram wi
th
a
s
ize of 0 does not make any sense."
);
}
WHistogram
::~
WHistogram
()
WHistogram
::
WHistogram
(
const
WHistogram
&
hist
)
:
m_minimum
(
hist
.
m_minimum
),
m_maximum
(
hist
.
m_maximum
),
m_nbBuckets
(
hist
.
m_nbBuckets
)
{
}
void
WHistogram
::
insert
(
double
value
)
WHistogram
::
~
WHistogram
(
)
{
if
(
value
>
m_max
||
value
<
m_min
)
{
wlog
::
warn
(
"WHistogram"
)
<<
std
::
scientific
<<
std
::
setprecision
(
16
)
<<
"Inserted value out of bounds, thread: "
<<
value
<<
" as min, resp. max: "
<<
m_min
<<
","
<<
m_max
;
return
;
// value = ( value > m_max ? m_max : m_min );
}
if
(
value
==
m_max
)
{
value
=
m_max
-
wlimits
::
DBL_EPS
;
}
m_bins
.
at
(
static_cast
<
size_t
>
(
std
::
abs
(
value
-
m_min
)
/
m_intervalWidth
)
)
++
;
}
size_t
WHistogram
::
binS
ize
()
const
size_t
WHistogram
::
s
ize
()
const
{
return
m_
bins
.
size
()
;
return
m_
nbBuckets
;
}
size_t
WHistogram
::
valuesSize
()
const
double
WHistogram
::
getMinimum
()
const
{
return
std
::
accumulate
(
m_
b
in
s
.
begin
(),
m_bins
.
end
(),
0
)
;
return
m_
m
in
imum
;
}
size_t
WHistogram
::
operator
[](
size_t
index
)
const
double
WHistogram
::
getMaximum
(
)
const
{
if
(
index
>=
m_bins
.
size
()
)
{
wlog
::
error
(
"WHistogram"
)
<<
index
<<
"th interval is not available, there are only: "
<<
m_bins
.
size
();
return
0
;
}
return
m_bins
[
index
];
return
m_maximum
;
}
src/common/WHistogram.h
View file @
27d9921d
...
...
@@ -25,80 +25,113 @@
#ifndef WHISTOGRAM_H
#define WHISTOGRAM_H
#include <
vector
>
#include <
utility
>
/**
* Container which associate values with (uniform width) bins (aka intervals or buckets).
* Container which associate values with (uniform width) bins (aka intervals or buckets). This class implements the abstract interface and
* therefore builds the base class for all histogram classes. The interface also allows programming histogram of different bucket sizes.
*/
class
WHistogram
{
public:
/**
* Default constructor.
* Default constructor.
Creates an empty histogram covering the specified min and max values with the specified number of buckets.
*
* \param min
* \param max
* \param
size
* \param min
the smallest value
* \param max
the largest value
* \param
buckets the number of buckets
*/
WHistogram
(
double
min
,
double
max
,
size_t
size
=
1000
);
WHistogram
(
double
min
,
double
max
,
size_t
buckets
=
1000
);
/**
* Copy constructor. Creates a deep copy of the specified histogram.
*
* \param hist the histogram to copy.
*/
WHistogram
(
const
WHistogram
&
hist
);
/**
* Default destructor.
*/
~
WHistogram
();
virtual
~
WHistogram
();
/**
* Inserts a given value within the given range (min, max) into exactly one bin and increment its size.
* Get the count of the specified bucket.
*
* \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
*
* \
param value Value to inser
t.
* \
return elements in the bucke
t.
*/
v
oid
insert
(
double
value
)
;
v
irtual
size_t
operator
[](
size_t
index
)
const
=
0
;
/**
* Computes number of invervals.
* Get the count of the specified bucket. Testing if the position is valid.
*
* \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
*
* \return
Number of intervals.
* \return
elements in the bucket
*/
size_t
binSize
(
)
const
;
virtual
size_t
at
(
size_t
index
)
const
=
0
;
/**
*
Compute
s the number of
inserted values so far
.
*
Return
s the number of
buckets in the histogram with the actual mapping
.
*
* \return
N
umber of
values so far.
* \return
n
umber of
buckets
*/
size_t
valuesS
ize
()
const
;
virtual
size_t
s
ize
()
const
;
/**
*
LooksUp how many elements are in this bin with the given index
.
*
Returns the minimum value
.
*
* \param index The bin number to look up for
* \return minimum
*/
virtual
double
getMinimum
()
const
;
/**
* Returns the maximum value.
*
* \return
Number of values associated with this interval.
* \return
maximum
*/
size_t
operator
[](
size_t
index
)
const
;
virtual
double
getMaximum
(
)
const
;
protected:
/**
* Return the size of one specific bucket.
*
* \param index the width for this bucket is queried.
*
* \return the size of a bucket.
*/
virtual
double
getBucketSize
(
size_t
index
=
0
)
const
=
0
;
private:
/**
* Bins to associate with the values. Each bin has the width of m_intervalWidth;
* Returns the actual interval associated with the given index. The interval is open, meaning that
* getIntervalForIndex( i ).second == getIntervalForIndex( i + 1 ).first but does not belong anymore to the interval itself but every value
* smaller than getIntervalForIndex( i ).second.
*
* \param index the intex
*
* \return the open interval.
*/
std
::
vector
<
size_t
>
m_bins
;
virtual
std
::
pair
<
double
,
double
>
getIntervalForIndex
(
size_t
index
)
const
=
0
;
protected:
/**
*
Minimal
value
*
The smallest
value
*/
double
m_min
;
double
m_min
imum
;
/**
*
Maximal
value
*
The biggest
value
*/
double
m_max
;
double
m_max
imum
;
/**
* The
width of an interval is precomputed to save performance
.
* The
number of buckets
.
*/
double
m_intervalWidth
;
double
m_nbBuckets
;
private:
};
#endif // WHISTOGRAM_H
src/common/WHistogramBasic.cpp
0 → 100644
View file @
27d9921d
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <utility>
#include "WAssert.h"
#include "WHistogramBasic.h"
#include "WLimits.h"
#include "WLogger.h"
WHistogramBasic
::
WHistogramBasic
(
double
min
,
double
max
,
size_t
buckets
)
:
WHistogram
(
min
,
max
,
buckets
),
m_bins
(
buckets
,
0
),
m_intervalWidth
(
(
m_maximum
-
m_minimum
)
/
static_cast
<
double
>
(
m_nbBuckets
)
)
{
}
WHistogramBasic
::
WHistogramBasic
(
const
WHistogramBasic
&
hist
)
:
WHistogram
(
hist
),
m_bins
(
hist
.
m_bins
),
m_intervalWidth
(
hist
.
m_intervalWidth
)
{
}
WHistogramBasic
::~
WHistogramBasic
()
{
}
size_t
WHistogramBasic
::
operator
[](
size_t
index
)
const
{
return
m_bins
[
index
];
}
size_t
WHistogramBasic
::
at
(
size_t
index
)
const
{
if
(
index
>=
m_bins
.
size
()
)
{
wlog
::
error
(
"WHistogramBasic"
)
<<
index
<<
"th interval is not available, there are only: "
<<
m_bins
.
size
();
return
0
;
}
return
m_bins
[
index
];
}
double
WHistogramBasic
::
getBucketSize
(
size_t
/* index */
)
const
{
return
m_intervalWidth
;
}
std
::
pair
<
double
,
double
>
WHistogramBasic
::
getIntervalForIndex
(
size_t
index
)
const
{
double
first
=
m_minimum
+
m_intervalWidth
*
index
;
double
second
=
m_minimum
+
m_intervalWidth
*
(
index
+
1
);
return
std
::
make_pair
(
first
,
second
);
}
void
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 );
}
if
(
value
==
m_maximum
)
{
value
=
m_maximum
-
wlimits
::
DBL_EPS
;
}
m_bins
.
at
(
static_cast
<
size_t
>
(
std
::
abs
(
value
-
m_minimum
)
/
m_intervalWidth
)
)
++
;
}
size_t
WHistogramBasic
::
valuesSize
()
const
{
return
std
::
accumulate
(
m_bins
.
begin
(),
m_bins
.
end
(),
0
);
}
src/common/WHistogramBasic.h
0 → 100644
View file @
27d9921d
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WHISTOGRAMBASIC_H
#define WHISTOGRAMBASIC_H
#include <utility>
#include <vector>
#include "WHistogram.h"
/**
* Container which associate values with (uniform width) bins (aka intervals or buckets). This class implements a very simple and easy to use
* generic histogram with uniform bucket sizes.
*/
class
WHistogramBasic
:
public
WHistogram
{
public:
/**
* Default constructor. Creates an empty histogram covering the specified min and max values with the specified number of buckets.
*
* \param min the smallest value
* \param max the largest value
* \param buckets the number of buckets
*/
WHistogramBasic
(
double
min
,
double
max
,
size_t
buckets
=
1000
);
/**
* Copy constructor. Creates a deep copy of the specified histogram.
*
* \param hist the histogram to copy.
*/
WHistogramBasic
(
const
WHistogramBasic
&
hist
);
/**
* Default destructor.
*/
~
WHistogramBasic
();
/**
* Get the count of the specified bucket.
*
* \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
*
* \return elements in the bucket.
*/
virtual
size_t
operator
[](
size_t
index
)
const
;
/**
* Get the count of the specified bucket. Testing if the position is valid.
*
* \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
*
* \return elements in the bucket
*/
virtual
size_t
at
(
size_t
index
)
const
;
/**
* Return the size of one specific bucket.
*
* \param index the width for this bucket is queried.
*
* \return the size of a bucket.
*/
virtual
double
getBucketSize
(
size_t
index
=
0
)
const
;
/**
* Returns the actual interval associated with the given index. The interval is open, meaning that
* getIntervalForIndex( i ).second == getIntervalForIndex( i + 1 ).first but does not belong anymore to the interval itself but every value
* smaller than getIntervalForIndex( i ).second.
*
* \param index the intex
*
* \return the open interval.
*/
virtual
std
::
pair
<
double
,
double
>
getIntervalForIndex
(
size_t
index
)
const
;
/**
* Computes the number of inserted values so far.
*
* \return Number of values so far.
*/
size_t
valuesSize
()
const
;
/**
* Inserts a given value within the given range (min, max) into exactly one bin and increment its size.
*
* \param value Value to insert.
*/
virtual
void
insert
(
double
value
);
protected:
private:
/**
* Bins to associate with the values. Each bin has the width of m_intervalWidth;
*/
std
::
vector
<
size_t
>
m_bins
;
/**
* The width of an interval is precomputed to save performance.
*/
double
m_intervalWidth
;
};
#endif // WHISTOGRAMBASIC_H
src/common/test/WHistogram_test.h
→
src/common/test/WHistogram
Basic
_test.h
View file @
27d9921d
...
...
@@ -22,21 +22,21 @@
//
//---------------------------------------------------------------------------
#ifndef WHISTOGRAM_TEST_H
#define WHISTOGRAM_TEST_H
#ifndef WHISTOGRAM
BASIC
_TEST_H
#define WHISTOGRAM
BASIC
_TEST_H
#include <cxxtest/TestSuite.h>
#include "../WHistogram.h"
#include "../WHistogram
Basic
.h"
#include "../WLimits.h"
#include "../WLogger.h"
static
WLogger
logger
;
/**
* Unit tests the WHistogram class.
* Unit tests the WHistogram
Basic
class.
*/
class
WHistogramTest
:
public
CxxTest
::
TestSuite
class
WHistogram
Basic
Test
:
public
CxxTest
::
TestSuite
{
public:
/**
...
...
@@ -44,8 +44,8 @@ public:
*/
void
testInitialization
(
void
)
{
WHistogram
h
(
0.0
,
1.0
);
TS_ASSERT_EQUALS
(
h
.
binS
ize
(),
1000
);
WHistogram
Basic
h
(
0.0
,
1.0
);
TS_ASSERT_EQUALS
(
h
.
s
ize
(),
1000
);
TS_ASSERT_EQUALS
(
h
.
valuesSize
(),
0
);
}
...
...
@@ -54,9 +54,9 @@ public:
*/
void
testInsert
(
void
)
{
WHistogram
h
(
0.0
,
1.0
);
WHistogram
Basic
h
(
0.0
,
1.0
);
h
.
insert
(
0.7234
);
TS_ASSERT_EQUALS
(
h
.
binS
ize
(),
1000
);
TS_ASSERT_EQUALS
(
h
.
s
ize
(),
1000
);
TS_ASSERT_EQUALS
(
h
.
valuesSize
(),
1
);
TS_ASSERT_EQUALS
(
h
[
723
],
1
);
}
...
...
@@ -66,7 +66,7 @@ public:
*/
void
testInsertOnIntervalBorder
(
void
)
{
WHistogram
h
(
0.0
,
1.0
);
WHistogram
Basic
h
(
0.0
,
1.0
);
h
.
insert
(
0.001
);
TS_ASSERT_EQUALS
(
h
[
1
],
1
);
h
.
insert
(
0.0039999
);
...
...
@@ -80,7 +80,7 @@ public:
*/
void
testInsertMin
(
void
)
{
WHistogram
h
(
0.0
,
1.0
);
WHistogram
Basic
h
(
0.0
,
1.0
);
h
.
insert
(
0.0
);
TS_ASSERT_EQUALS
(
h
[
0
],
1
);
TS_ASSERT_EQUALS
(
h
[
1
],
0
);
...
...
@@ -91,7 +91,7 @@ public:
*/
void
testInsertMax
(
void
)
{
WHistogram
h
(
0.0
,
1.0
);
WHistogram
Basic
h
(
0.0
,
1.0
);
h
.
insert
(
0.0
);
h
.
insert
(
1.0
);
TS_ASSERT_EQUALS
(
h
[
999
],
1
);
...
...
@@ -103,10 +103,10 @@ public:
*/
void
testInsertOutOfBounds
(
void
)
{
WHistogram
h
(
0.0
,
1.0
);
WHistogram
Basic
h
(
0.0
,
1.0
);
h
.
insert
(
1.0
+
wlimits
::
DBL_EPS
);
h
.
insert
(
0.0
-
wlimits
::
DBL_EPS
);
for
(
size_t
i
=
0
;
i
<
h
.
binS
ize
();
++
i
)
for
(
size_t
i
=
0
;
i
<
h
.
s
ize
();
++
i
)
{
TS_ASSERT_EQUALS
(
h
[
i
],
0
);
}
...
...
@@ -117,8 +117,8 @@ public:
*/
void
testOperatorToGetNumberOfElementsInsideTheBin
(
void
)
{
WHistogram
h
(
0.0
,
1.0
);
for
(
size_t
i
=
0
;
i
<
h
.
binS
ize
();
++
i
)
WHistogram
Basic
h
(
0.0
,
1.0
);
for
(
size_t
i
=
0
;
i
<
h
.
s
ize
();
++
i
)
{
TS_ASSERT_EQUALS
(
h
[
i
],
0
);
}
...
...
@@ -128,4 +128,4 @@ public:
}
};
#endif // WHISTOGRAM_TEST_H
#endif // WHISTOGRAM
BASIC
_TEST_H
src/dataHandler/WDataSetScalar.cpp
View file @
27d9921d
...
...
@@ -27,6 +27,7 @@
#include "../common/WAssert.h"
#include "../common/WLimits.h"
#include "datastructures/WValueSetHistogram.h"
#include "WDataSetSingle.h"
#include "WDataSetScalar.h"
...
...
@@ -42,18 +43,6 @@ WDataSetScalar::WDataSetScalar( boost::shared_ptr< WValueSetBase > newValueSet,
WAssert
(
newGrid
,
"No grid given."
);
WAssert
(
newValueSet
->
size
()
==
newGrid
->
size
(),
"Number of values unequal number of positions in grid."
);
WAssert
(
newValueSet
->
order
()
==
0
,
"The value set does not contain scalars."
);
double
max
=
wlimits
::
MIN_DOUBLE
;
double
min
=
wlimits
::
MAX_DOUBLE
;
for
(
size_t
i
=
0
;
i
<
newValueSet
->
size
();
++
i
)
{
double
tmp
=
newValueSet
->
getScalarDouble
(
i
);
max
=
max
<
tmp
?
tmp
:
max
;
min
=
min
>
tmp
?
tmp
:
min
;
}
m_maximum
=
max
;
m_minimum
=
min
;
}
WDataSetScalar
::
WDataSetScalar
()
...
...
@@ -62,34 +51,18 @@ WDataSetScalar::WDataSetScalar()
// default constructor used by the prototype mechanism
}
WDataSetScalar
::
WDataSetScalar
(
boost
::
shared_ptr
<
WValueSetBase
>
newValueSet
,
boost
::
shared_ptr
<
WGrid
>
newGrid
,
double
max
,
double
min
)
:
WDataSetSingle
(
newValueSet
,
newGrid
)
{
WAssert
(
newValueSet
,
"No value set given."
);
WAssert
(
newGrid
,
"No grid given."
);
WAssert
(
newValueSet
->
size
()
==
newGrid
->
size
(),
"Number of values unequal number of positions in grid."
);
WAssert
(
newValueSet
->
order
()
==
0
,
"The value set does not contain scalars."
);
WAssert
(
max
>=
min
,
"max must be at least as large as min."
);
m_maximum
=
max
;
m_minimum
=
min
;
}
WDataSetScalar
::~
WDataSetScalar
()
{
}
double
WDataSetScalar
::
getMax
()
const
{
return
m_
maximum
;
return
m_
valueSet
->
getMaximumValue
()
;
}
double
WDataSetScalar
::
getMin
()
const
{