Commit 372156e1 authored by reichenbach's avatar reichenbach

[MERGE]

parents 299648e7 2352fe09
......@@ -27,7 +27,7 @@
#include "WAssert.h"
#include "WHistogram.h"
WHistogram::WHistogram( double min, double max, size_t buckets ):
WHistogram::WHistogram( double min, double max, std::size_t buckets ):
m_minimum( min ),
m_maximum( max ),
m_nbBuckets( buckets )
......@@ -65,3 +65,4 @@ double WHistogram::getMaximum() const
{
return m_maximum;
}
......@@ -25,10 +25,9 @@
#ifndef WHISTOGRAM_H
#define WHISTOGRAM_H
#include <cstddef> // for std::size_t
#include <utility>
/**
* 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.
......@@ -43,7 +42,7 @@ public:
* \param max the largest value
* \param buckets the number of buckets
*/
WHistogram( double min, double max, size_t buckets = 1000 );
WHistogram( double min, double max, std::size_t buckets = 1000 );
/**
* Copy constructor. Creates a deep copy of the specified histogram.
......@@ -64,7 +63,7 @@ public:
*
* \return elements in the bucket.
*/
virtual size_t operator[]( size_t index ) const = 0;
virtual std::size_t operator[]( std::size_t index ) const = 0;
/**
* Get the count of the specified bucket. Testing if the position is valid.
......@@ -73,14 +72,14 @@ public:
*
* \return elements in the bucket
*/
virtual size_t at( size_t index ) const = 0;
virtual std::size_t at( std::size_t index ) const = 0;
/**
* Returns the number of buckets in the histogram with the actual mapping.
*
* \return number of buckets
*/
virtual size_t size() const;
virtual std::size_t size() const;
/**
* Returns the minimum value.
......@@ -103,7 +102,7 @@ public:
*
* \return the size of a bucket.
*/
virtual double getBucketSize( size_t index = 0 ) const = 0;
virtual double getBucketSize( std::size_t index = 0 ) const = 0;
/**
* Returns the actual interval associated with the given index. The interval is open, meaning that
......@@ -114,7 +113,7 @@ public:
*
* \return the open interval.
*/
virtual std::pair< double, double > getIntervalForIndex( size_t index ) const = 0;
virtual std::pair< double, double > getIntervalForIndex( std::size_t index ) const = 0;
protected:
/**
......@@ -136,3 +135,4 @@ private:
};
#endif // WHISTOGRAM_H
......@@ -32,7 +32,7 @@
#include "WLimits.h"
#include "WLogger.h"
WHistogramBasic::WHistogramBasic( double min, double max, size_t buckets ):
WHistogramBasic::WHistogramBasic( double min, double max, std::size_t buckets ):
WHistogram( min, max, buckets ),
m_bins( buckets, 0 ),
m_intervalWidth( std::abs( m_maximum - m_minimum ) / static_cast< double >( m_nbBuckets ) )
......@@ -51,12 +51,12 @@ WHistogramBasic::~WHistogramBasic()
{
}
size_t WHistogramBasic::operator[]( size_t index ) const
size_t WHistogramBasic::operator[]( std::size_t index ) const
{
return m_bins[ index ];
}
size_t WHistogramBasic::at( size_t index ) const
size_t WHistogramBasic::at( std::size_t index ) const
{
if( index >= m_bins.size() )
{
......@@ -66,12 +66,12 @@ size_t WHistogramBasic::at( size_t index ) const
return m_bins[ index ];
}
double WHistogramBasic::getBucketSize( size_t /* index */ ) const
double WHistogramBasic::getBucketSize( std::size_t /* index */ ) const
{
return m_intervalWidth;
}
std::pair< double, double > WHistogramBasic::getIntervalForIndex( size_t index ) const
std::pair< double, double > WHistogramBasic::getIntervalForIndex( std::size_t index ) const
{
double first = m_minimum + m_intervalWidth * index;
double second = m_minimum + m_intervalWidth * ( index + 1 );
......@@ -97,7 +97,7 @@ void WHistogramBasic::insert( double value )
}
else
{
m_bins.at( static_cast< size_t >( ( value - m_minimum ) / std::abs( m_maximum - m_minimum ) * ( m_nbBuckets ) ) )++;
m_bins.at( static_cast< std::size_t >( ( value - m_minimum ) / std::abs( m_maximum - m_minimum ) * ( m_nbBuckets ) ) )++;
}
}
......
......@@ -25,6 +25,7 @@
#ifndef WHISTOGRAMBASIC_H
#define WHISTOGRAMBASIC_H
#include <cstddef> // for std::size_t
#include <utility>
#include <vector>
......@@ -45,7 +46,7 @@ public:
* \param max the largest value
* \param buckets the number of buckets
*/
WHistogramBasic( double min, double max, size_t buckets = 1000 );
WHistogramBasic( double min, double max, std::size_t buckets = 1000 );
/**
* Copy constructor. Creates a deep copy of the specified histogram.
......@@ -66,7 +67,7 @@ public:
*
* \return elements in the bucket.
*/
virtual size_t operator[]( size_t index ) const;
virtual std::size_t operator[]( std::size_t index ) const;
/**
* Get the count of the specified bucket. Testing if the position is valid.
......@@ -75,7 +76,7 @@ public:
*
* \return elements in the bucket
*/
virtual size_t at( size_t index ) const;
virtual std::size_t at( std::size_t index ) const;
/**
* Return the size of one specific bucket.
......@@ -84,7 +85,7 @@ public:
*
* \return the size of a bucket.
*/
virtual double getBucketSize( size_t index = 0 ) const;
virtual double getBucketSize( std::size_t index = 0 ) const;
/**
* Returns the actual interval associated with the given index. The interval is open, meaning that
......@@ -95,14 +96,14 @@ public:
*
* \return the open interval.
*/
virtual std::pair< double, double > getIntervalForIndex( size_t index ) const;
virtual std::pair< double, double > getIntervalForIndex( std::size_t index ) const;
/**
* Computes the number of inserted values so far.
*
* \return Number of values so far.
*/
size_t valuesSize() const;
std::size_t valuesSize() const;
/**
* Inserts a given value within the given range (min, max) into exactly one bin and increment its size.
......@@ -116,7 +117,7 @@ private:
/**
* Bins to associate with the values. Each bin has the width of m_intervalWidth;
*/
std::vector< size_t > m_bins;
std::vector< std::size_t > m_bins;
/**
* The width of an interval is precomputed to save performance.
......
......@@ -338,6 +338,16 @@ WPosition WDataSetFibers::getPosition( size_t fiber, size_t vertex ) const
return WPosition( m_vertices->at( index ), m_vertices->at( index + 1 ), m_vertices->at( index + 2 ) );
}
std::size_t WDataSetFibers::getLengthOfLine( std::size_t fiber ) const
{
return m_lineLengths->at( fiber );
}
std::size_t WDataSetFibers::getStartIndex( std::size_t fiber ) const
{
return m_lineStartIndexes->at( fiber );
}
WPosition WDataSetFibers::getTangent( size_t fiber, size_t vertex ) const
{
WPosition point = getPosition( fiber, vertex );
......@@ -490,9 +500,9 @@ WFiberIterator::operator bool() const
std::size_t WFiberIterator::numPoints() const
{
WAssert( m_index < m_fibers->getLineLengths()->size(), "" );
WAssert( m_index < m_fibers->size(), "" );
return m_fibers->getLineLengths()->operator[] ( m_index );
return m_fibers->getLengthOfLine( m_index );
}
WFiberPointsIterator WFiberIterator::begin()
......@@ -577,7 +587,7 @@ WIteratorRange< WFiberSegmentsIterator > WFiberIterator::segmentsReverse() const
std::size_t WFiberIterator::getLineStartIndex() const
{
return m_fibers->getLineStartIndexes()->operator[]( getIndex() );
return m_fibers->getStartIndex( m_index );
}
std::size_t WFiberIterator::getIndex() const
......@@ -678,23 +688,20 @@ WFiberPointsIterator WFiberPointsIterator::operator- ( size_t n )
std::size_t WFiberPointsIterator::getBaseIndex() const
{
WAssert( m_fibers, "" );
WAssert( m_fiberIndex < m_fibers->getLineLengths()->size(), "" );
WAssert( m_index < m_fibers->getLineLengths()->operator[] ( m_fiberIndex ), "" );
WAssert( m_fiberIndex < m_fibers->size(), "Index must be smaller than the number of fibers!" );
WAssert( m_index < m_fibers->getLengthOfLine( m_fiberIndex ), "Point index must be smaller than the number of points!" );
std::size_t i = m_index;
if( m_reverse )
{
i = m_fibers->getLineLengths()->operator[] ( m_fiberIndex ) - i - 1;
i = m_fibers->getLengthOfLine( m_fiberIndex ) - i - 1;
}
return m_fibers->getLineStartIndexes()->operator[] ( m_fiberIndex ) + i;
return m_fibers->getStartIndex( m_fiberIndex ) + i;
}
WPosition WFiberPointsIterator::operator*() const
{
std::size_t v = getBaseIndex();
return WPosition( m_fibers->getVertices()->operator[]( 3 * v + 0 ),
m_fibers->getVertices()->operator[]( 3 * v + 1 ),
m_fibers->getVertices()->operator[]( 3 * v + 2 ) );
return m_fibers->getPosition( m_fiberIndex, m_index );
}
bool WFiberPointsIterator::operator==( WFiberPointsIterator const& rhs ) const
......@@ -719,11 +726,12 @@ WIteratorRangeUnpacker< WFiberPointsIterator > WFiberPointsIterator::operator,(
WFiberPointsIterator::operator bool() const
{
return m_fibers != NULL && m_fiberIndex < m_fibers->getLineLengths()->size() && m_index < m_fibers->getLineLengths()->at( m_fiberIndex );
return m_fibers != NULL && m_fiberIndex < m_fibers->size() && m_index < m_fibers->getLengthOfLine( m_fiberIndex );
}
double WFiberPointsIterator::getParameter( double def ) const
{
// TODO(reichenbach): change this to avoid the copy of a shared_ptr
if( m_fibers->getVertexParameters() )
{
return m_fibers->getVertexParameters()->operator[]( getBaseIndex() );
......@@ -733,13 +741,9 @@ double WFiberPointsIterator::getParameter( double def ) const
WPosition WFiberPointsIterator::getTangent() const
{
std::size_t v = getBaseIndex();
return WPosition( m_fibers->getTangents()->operator[]( 3 * v + 0 ),
m_fibers->getTangents()->operator[]( 3 * v + 1 ),
m_fibers->getTangents()->operator[]( 3 * v + 2 ) );
return m_fibers->getTangent( m_fiberIndex, m_index );
}
WColor WFiberPointsIterator::getColor( const boost::shared_ptr< WDataSetFibers::ColorScheme > scheme ) const
{
std::size_t v = getBaseIndex();
......@@ -882,7 +886,7 @@ WIteratorRangeUnpacker< WFiberSegmentsIterator > WFiberSegmentsIterator::operato
WFiberSegmentsIterator::operator bool() const
{
return m_fibers != NULL && m_fiberIndex < m_fibers->getLineLengths()->size() && m_index < m_fibers->getLineLengths()->at( m_fiberIndex ) - 1;
return m_fibers != NULL && m_fiberIndex < m_fibers->size() && m_index < m_fibers->getLengthOfLine( m_fiberIndex ) - 1;
}
WFiberPointsIterator WFiberSegmentsIterator::start() const
......@@ -897,7 +901,7 @@ WFiberPointsIterator WFiberSegmentsIterator::end() const
osg::Vec3 WFiberSegmentsIterator::direction() const
{
if( m_index > m_fibers->getLineLengths()->at( m_fiberIndex ) - 2 )
if( m_index > m_fibers->getLengthOfLine( m_fiberIndex ) - 2 )
return osg::Vec3( 0.0, 0.0, 0.0 );
return *end() - *start();
......
......@@ -404,6 +404,26 @@ public:
*/
WPosition getTangent( size_t fiber, size_t vertex ) const;
/**
* Returns the number of points for a given fiber.
*
* \param fiber The index of the fiber.
*
* \return The number of points of the fiber.
*/
std::size_t getLengthOfLine( std::size_t fiber ) const;
/**
* Get the index of the first vertex of a given fiber.
* This is used to find the three components 3 * start, 3 * start + 1
* and 3 * start + 2 of the first vertex in the vertices vector.
*
* \param fiber The fiber to find the start index for.
*
* \return The start index.
*/
std::size_t getStartIndex( std::size_t fiber ) const;
/**
* Get the bounding box.
* \return The bounding box of all lines.
......
//---------------------------------------------------------------------------
//
// 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 <string>
#include "WDataSetHistogram1D.h"
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WDataSetHistogram1D::m_prototype = boost::shared_ptr< WPrototyped >();
WDataSetHistogram1D::WDataSetHistogram1D( boost::shared_ptr< WHistogramBasic const > const& histo )
: WDataSet(),
m_histogram( new WHistogramBasic( *histo ) )
{
}
WDataSetHistogram1D::WDataSetHistogram1D()
: WDataSet(),
m_histogram()
{
}
WDataSetHistogram1D::~WDataSetHistogram1D()
{
}
std::string const WDataSetHistogram1D::getName() const
{
return "WDataSetHistogram1D";
}
std::string const WDataSetHistogram1D::getDescription() const
{
return "A dataset that contains some 1D histogram.";
}
boost::shared_ptr< WPrototyped > WDataSetHistogram1D::getPrototype()
{
if( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetHistogram1D() );
}
return m_prototype;
}
boost::shared_ptr< WHistogramBasic const > const& WDataSetHistogram1D::getHistogram() const
{
return m_histogram;
}
//---------------------------------------------------------------------------
//
// 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 WDATASETHISTOGRAM1D_H
#define WDATASETHISTOGRAM1D_H
#include <string>
#include "../common/WHistogramBasic.h"
#include "WDataSet.h"
/**
* This data set type contains a 1D histogram.
* \ingroup dataHandler
*/
class WDataSetHistogram1D : public WDataSet // NOLINT
{
public:
/**
* shared_ptr abbreviation
*/
typedef boost::shared_ptr< WDataSetHistogram1D > SPtr;
/**
* const shared_ptr abbreviation
*/
typedef boost::shared_ptr< const WDataSetHistogram1D > ConstSPtr;
/**
* Creates a dataset encapsulating a histogram.
* The histogram will be copied in order to prevent changes to the data.
*
* \param histo The histogram to use.
*/
explicit WDataSetHistogram1D( boost::shared_ptr< WHistogramBasic const > const& histo );
/**
* Construct an empty and unusable instance. This is needed for the prototype mechanism.
*/
WDataSetHistogram1D();
/**
* Destroys this DataSet instance
*/
virtual ~WDataSetHistogram1D();
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual const std::string getName() const;
/**
* Gets the description for this prototype.
*
* \return the description
*/
virtual const std::string getDescription() const;
/**
* Returns the histogram.
*
* \return A const ref pointer to the histogram.
*/
boost::shared_ptr< WHistogramBasic const > const& getHistogram() const;
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static boost::shared_ptr< WPrototyped > getPrototype();
protected:
/**
* The prototype as singleton.
*/
static boost::shared_ptr< WPrototyped > m_prototype;
private:
//! The histogram.
boost::shared_ptr< WHistogramBasic const > const m_histogram;
};
#endif // WDATASETHISTOGRAM1D_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2014 OpenWalnut Community, Nemtics, BSV-Leipzig
// 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 <string>
#include "../../core/kernel/WKernel.h"
#include "WMCalculateHistogram.h"
// This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
W_LOADABLE_MODULE( WMCalculateHistogram )
WMCalculateHistogram::WMCalculateHistogram():
WModule()
{
}
WMCalculateHistogram::~WMCalculateHistogram()
{
}
boost::shared_ptr< WModule > WMCalculateHistogram::factory() const
{
return boost::shared_ptr< WModule >( new WMCalculateHistogram() );
}
const char** WMCalculateHistogram::getXPMIcon() const
{
return NULL;
}
const std::string WMCalculateHistogram::getName() const
{
// Specify your module name here. This name must be UNIQUE!
return "CalculateHistogram";
}
const std::string WMCalculateHistogram::getDescription() const
{
return "Calculates the histogram of the values found in the input dataset.";
}
void WMCalculateHistogram::connectors()
{
m_dataInput = boost::shared_ptr< WModuleInputData< WDataSetSingle > >( new WModuleInputData< WDataSetSingle >(
shared_from_this(), "Input data", "A dataset to calculate the histogram from." ) );
addConnector( m_dataInput );
m_histogramOutput = boost::shared_ptr< WModuleOutputData< WDataSetHistogram1D > >( new WModuleOutputData< WDataSetHistogram1D >(
shared_from_this(), "Histogram", "The calculated histogram." ) );
addConnector( m_histogramOutput );
WModule::connectors();
}
void WMCalculateHistogram::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition );
m_histogramBins = m_properties->addProperty( "Histogram bins", "The number of bins in the calculated histogram.", 100, m_propCondition );
m_histogramBins->setMin( 1 );
m_histogramBins->setMax( 1000 );
WModule::properties();
}
void WMCalculateHistogram::requirements()
{
}
void WMCalculateHistogram::moduleMain()
{
m_moduleState.setResetable( true, true );
m_moduleState.add( m_propCondition );
m_moduleState.add( m_dataInput->getDataChangedCondition() );
ready();
while( !m_shutdownFlag() )
{
debugLog() << "Waiting ...";
m_moduleState.wait();
if( m_shutdownFlag() )
{
break;
}
if( m_dataInput->getData() && m_data != m_dataInput->getData() )
{
m_data = m_dataInput->getData();
updateOutput();
}
if( m_data && m_histogramBins->changed() )
{
updateOutput();
}
}