Commit e2f0c980 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD] Convinience methods to iterate over axis related informations, which may...

[ADD] Convinience methods to iterate over axis related informations, which may bloat your code otherwise
parent ab6bd054
......@@ -25,22 +25,24 @@
#ifndef WGRIDREGULAR3D_H
#define WGRIDREGULAR3D_H
#include <vector>
#include <utility>
#include <vector>
#include <boost/array.hpp>
#include <boost/shared_ptr.hpp>
#include <osg/Matrix>
#include <osg/Vec3>
#include "../common/math/WMatrix.h"
#include "../common/math/WMatrix4x4.h"
#include "../common/math/WPosition.h"
#include "../common/math/WVector3D.h"
#include "../common/WBoundingBox.h"
#include "WGridTransformOrtho.h"
#include "../common/WCondition.h"
#include "WExportDataHandler.h"
#include "WGrid.h"
#include "WGridTransformOrtho.h"
/**
* A grid that has parallelepiped cells which all have the same proportion. I.e.
......@@ -504,6 +506,58 @@ private:
WGridTransformOrtho const m_transform;
};
/**
* Convinience function returning all offsets per axis.
* 0 : xAxis, 1 : yAxis, 2 : zAxis
* \param grid The grid having the information.
* \note Implementing this as NonMemberNonFriend was intentional.
* \return Array of number of samples per axis.
*/
inline boost::array< double, 3 > getOffsets( boost::shared_ptr< const WGridRegular3D > grid )
{
boost::array< double, 3 > result = { { grid->getOffsetX(), grid->getOffsetY(), grid->getOffsetZ() } }; // NOLINT curly braces
return result;
}
/**
* Convinience function returning all number coords per axis.
* 0 : xAxis, 1 : yAxis, 2 : zAxis
* \param grid The grid having the information.
* \note Implementing this as NonMemberNonFriend was intentional.
* \return Array of number of samples per axis.
*/
inline boost::array< unsigned int, 3 > getNbCoords( boost::shared_ptr< const WGridRegular3D > grid )
{
boost::array< unsigned int, 3 > result = { { grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ() } }; // NOLINT curly braces
return result;
}
/**
* Convinience function returning all axis directions.
* 0 : xAxis, 1 : yAxis, 2 : zAxis
* \param grid The grid having the information.
* \note Implementing this as NonMemberNonFriend was intentional.
* \return The direction of each axis as array
*/
inline boost::array< WVector3D, 3 > getDirections( boost::shared_ptr< const WGridRegular3D > grid )
{
boost::array< WVector3D, 3 > result = { { grid->getDirectionX(), grid->getDirectionY(), grid->getDirectionZ() } }; // NOLINT curly braces
return result;
}
/**
* Convinience function returning all axis unit directions.
* 0 : xAxis, 1 : yAxis, 2 : zAxis
* \param grid The grid having the information.
* \note Implementing this as NonMemberNonFriend was intentional.
* \return The direction of each axis as array
*/
inline boost::array< WVector3D, 3 > getUnitDirections( boost::shared_ptr< const WGridRegular3D > grid )
{
boost::array< WVector3D, 3 > result = { { grid->getUnitDirectionX(), grid->getUnitDirectionY(), grid->getUnitDirectionZ() } }; // NOLINT curly braces
return result;
}
inline unsigned int WGridRegular3D::getNbCoordsX() const
{
return m_nbPosX;
......
......@@ -72,6 +72,21 @@ public:
TS_ASSERT_EQUALS( grid.size(), 27 );
}
/**
* Each convinience function just assembles the three values into an boost array.
*/
void testConvinienceFunctions( void )
{
boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( 3, 3, 3 ) );
boost::array< unsigned int, 3 > expectedNbCoords = { { 3, 3, 3 } }; // NOLINT curly braces
TS_ASSERT_EQUALS( expectedNbCoords, getNbCoords( grid ) );
boost::array< double, 3 > expectedOffsets = { { 1.0, 1.0, 1.0 } }; // NOLINT curly braces
TS_ASSERT_EQUALS( expectedOffsets, getOffsets( grid ) );
boost::array< WVector3D, 3 > expectedDirections = { { WVector3D( 1.0, 0.0, 0.0 ), WVector3D( 0.0, 1.0, 0.0 ), WVector3D( 0.0, 0.0, 1.0 ) } }; // NOLINT curly braces line length
TS_ASSERT_EQUALS( expectedDirections, getDirections( grid ) );
TS_ASSERT_EQUALS( expectedDirections, getUnitDirections( grid ) );
}
/**
* After instantiation there should be the right vectors, matrix and origin.
*/
......
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