30 #include <boost/array.hpp>
32 #include "../common/WAssert.h"
33 #include "WDataSetSingle.h"
34 #include "WDataSetVector.h"
40 std::shared_ptr< WGrid > newGrid )
43 WAssert( newValueSet,
"No value set given." );
44 WAssert( newGrid,
"No grid given." );
45 WAssert( newValueSet->size() == newGrid->size(),
"Number of values unequal number of positions in grid." );
46 WAssert( newValueSet->order() == 1,
"The value set does not contain vectors." );
90 boost::array< double, 8 > computePrefactors(
const WPosition& pos,
91 std::shared_ptr< const WGrid > i_grid,
92 std::shared_ptr< const WValueSetBase > i_valueSet,
94 std::shared_ptr< WGridRegular3D::CellVertexArray > vertexIds )
96 std::shared_ptr< const WGridRegular3D > grid = std::dynamic_pointer_cast< const WGridRegular3D >( i_grid );
98 WAssert( grid,
"This data set has a grid whose type is not yet supported for interpolation." );
99 WAssert( ( i_valueSet->order() == 1 && i_valueSet->dimension() == 3 ),
100 "Only implemented for 3D Vectors so far." );
101 boost::array< double, 8 > h;
103 bool isInside =
true;
104 size_t cellId = grid->getCellId( pos, &isInside );
113 *vertexIds = grid->getCellVertexIds( cellId );
115 WPosition localPos = grid->getTransform().directionToGridSpace( pos - grid->getPosition( ( *vertexIds )[0] ) );
117 double lambdaX = localPos[0];
118 double lambdaY = localPos[1];
119 double lambdaZ = localPos[2];
130 h[0] = ( 1 - lambdaX ) * ( 1 - lambdaY ) * ( 1 - lambdaZ );
131 h[1] = ( lambdaX ) * ( 1 - lambdaY ) * ( 1 - lambdaZ );
132 h[2] = ( 1 - lambdaX ) * ( lambdaY ) * ( 1 - lambdaZ );
133 h[3] = ( lambdaX ) * ( lambdaY ) * ( 1 - lambdaZ );
134 h[4] = ( 1 - lambdaX ) * ( 1 - lambdaY ) * ( lambdaZ );
135 h[5] = ( lambdaX ) * ( 1 - lambdaY ) * ( lambdaZ );
136 h[6] = ( 1 - lambdaX ) * ( lambdaY ) * ( lambdaZ );
137 h[7] = ( lambdaX ) * ( lambdaY ) * ( lambdaZ );
146 boost::array< double, 8 > h = computePrefactors( pos,
m_grid,
m_valueSet, success, vertexIds );
151 for(
size_t i = 0; i < 8; ++i )
163 boost::array< double, 8 > h = computePrefactors( pos,
m_grid,
m_valueSet, success, vertexIds );
168 for(
size_t i = 0; i < 8; ++i )
175 result += h[i] * sign *
getVectorAt( ( *vertexIds )[i] );
186 case W_DT_UNSIGNED_CHAR:
188 return std::dynamic_pointer_cast< WValueSet< uint8_t > >(
getValueSet() )->getVector3D( index );
192 return std::dynamic_pointer_cast< WValueSet< int16_t > >(
getValueSet() )->getVector3D( index );
194 case W_DT_SIGNED_INT:
196 return std::dynamic_pointer_cast< WValueSet< int32_t > >(
getValueSet() )->getVector3D( index );
200 return std::dynamic_pointer_cast< WValueSet< float > >(
getValueSet() )->getVector3D( index );
204 return std::dynamic_pointer_cast< WValueSet< double > >(
getValueSet() )->getVector3D( index );
207 WAssert(
false,
"Unknow data type in dataset." );
A data set consisting of a set of values based on a grid.
std::shared_ptr< WValueSetBase > getValueSet() const
std::shared_ptr< WGrid > m_grid
Stores the reference of the WGrid of this DataSetSingle instance.
std::shared_ptr< WGrid > getGrid() const
std::shared_ptr< WValueSetBase > m_valueSet
Stores the reference of the WValueSet of this DataSetSingle instance.
std::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a std::shared_ptr.
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
virtual bool isTexture() const
Determines whether this dataset can be used as a texture.
virtual WDataSetSingle::SPtr clone() const
Creates a copy (clone) of this instance.
WVector3d eigenVectorInterpolate(const WPosition &pos, bool *success) const
Interpolates the very same way as interpolate but it assures that all vecs are aligned to point into ...
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
virtual ~WDataSetVector()
Destroys this DataSet instance.
WDataSetVector()
Construct an empty and unusable instance.
WVector3d getVectorAt(size_t index) const
Get the vector on the given position in value set.
WVector3d interpolate(const WPosition &pos, bool *success) const
Interpolates the vector field at the given position.
boost::array< size_t, 8 > CellVertexArray
Convenience typedef for a boost::array< size_t, 8 >.
This only is a 3d double vector.