Commit b191760c authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD] moved this class from the modules repository to this main repository

parent 498ff7ce
//---------------------------------------------------------------------------
//
// 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 "WDataSetMatrix.h"
// prototype instance as singleton
std::shared_ptr< WPrototyped > WDataSetMatrix::m_prototype = std::shared_ptr< WPrototyped >();
WDataSetMatrix::WDataSetMatrix()
: WDataSetSingle()
{
// default constructor used by the prototype mechanism
}
WDataSetMatrix::WDataSetMatrix( std::shared_ptr< WValueSetBase > newValueSet, std::shared_ptr< WGrid > newGrid, size_t nbRows, size_t nbColumns )
: 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() == 1, "The value set does not contain vectors." );
rows = nbRows;
columns = nbColumns;
}
WDataSetMatrix::~WDataSetMatrix()
{
}
WDataSetSingle::SPtr WDataSetMatrix::clone( std::shared_ptr< WValueSetBase > newValueSet ) const
{
return WDataSetSingle::SPtr( new WDataSetMatrix( newValueSet, getGrid(), rows, columns ) );
}
WDataSetSingle::SPtr WDataSetMatrix::clone( std::shared_ptr< WGrid > newGrid ) const
{
return WDataSetSingle::SPtr( new WDataSetMatrix( getValueSet(), newGrid, rows, columns ) );
}
WDataSetSingle::SPtr WDataSetMatrix::clone() const
{
return WDataSetSingle::SPtr( new WDataSetMatrix( getValueSet(), getGrid(), rows, columns ) );
}
WMatrix< double > WDataSetMatrix::getMatrixDouble( size_t index ) const
{
std::shared_ptr< WValueSet< double > > values = std::dynamic_pointer_cast< WValueSet< double > >( m_valueSet );
WAssert( values, "The value set of a WDataSetMatrix must be a WValueSet< double >, nothing else!" );
int d = rows * columns;
WMatrix< double > m( rows, columns );
if( ( index + 1 ) * d > values->rawSize() )
{
wlog::debug( "Size exceeds Array. Array Size: " + std::to_string( values->rawSize() ) );
wlog::debug( "Wanted: " + std::to_string( ( index + 1 ) * d ) );
wlog::debug( "For index " + std::to_string( index ) );
}
WValueSet< double >::SubArray sa = values->getSubArray( index * d, d );
for( int i = 0; i < d; i++ )
{
m[i] = sa[i];
}
return m;
}
const std::string WDataSetMatrix::getName() const
{
return "WDataSetMatrix";
}
const std::string WDataSetMatrix::getDescription() const
{
return "Contains matrices.";
}
std::shared_ptr< WPrototyped > WDataSetMatrix::getPrototype()
{
if( !m_prototype )
{
m_prototype = std::shared_ptr< WPrototyped >( new WDataSetMatrix() );
}
return m_prototype;
}
//---------------------------------------------------------------------------
//
// 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 WDATASETMATRIX_H
#define WDATASETMATRIX_H
#include <string>
#include "WDataSetSingle.h"
/**
* Represents dataset with a matrix at every point.
*/
class WDataSetMatrix : public WDataSetSingle
{
public:
/**
* Creates a new matrix dataset out of a value set and a grid.
*
* \param newValueSet Valueset having vectors of number of entries of the matrix.
* \param newGrid The grid for the dataset
* \param nbRows Number of rows of stored matrices
* \param nbColumns Number of columns of stored matrices
*/
WDataSetMatrix( std::shared_ptr< WValueSetBase > newValueSet, std::shared_ptr< WGrid > newGrid, size_t nbRows, size_t nbColumns );
/**
* Constructs a new set of matrices. The constructed instance is not usable but needed for prototype mechanism.
*/
WDataSetMatrix();
/**
* Destructs this dataset.
*/
~WDataSetMatrix();
/**
* Creates a copy (clone) of this instance but allows one to change the valueset. Unlike copy construction, this is a very useful function if you
* want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
*
* \param newValueSet the new valueset.
*
* \return the clone
*/
virtual WDataSetSingle::SPtr clone( std::shared_ptr< WValueSetBase > newValueSet ) const;
/**
* Creates a copy (clone) of this instance but allows one to change the grid. Unlike copy construction, this is a very useful function if you
* want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
*
* \param newGrid the new grid.
*
* \return the clone
*/
virtual WDataSetSingle::SPtr clone( std::shared_ptr< WGrid > newGrid ) const;
/**
* Creates a copy (clone) of this instance. Unlike copy construction, this is a very useful function if you
* want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
*
* \return the clone
*/
virtual WDataSetSingle::SPtr clone() const;
/**
* Retrieves the i'th matrix.
*
* \warning Here is dynamical allocation used inside, this may be a problem when used with multithreading.
*
* \param index The position of the matrix to retrieve
*
* \return The new constructed matrix.
*/
WMatrix< double > getMatrixDouble( size_t index ) const;
/**
* 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 a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static std::shared_ptr< WPrototyped > getPrototype();
protected:
/**
* The prototype as singleton.
*/
static std::shared_ptr< WPrototyped > m_prototype;
private:
size_t rows; //!< Number of rows of stored matrices
size_t columns; //!< Number of columns of stored matrices
};
#endif // WDATASETMATRIX_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment