QuOc

 

Public Member Functions | Protected Member Functions | Protected Attributes

qc::TransformFunction< RealType, qc::QC_3D > Class Template Reference

#include <auxiliary.h>

Inheritance diagram for qc::TransformFunction< RealType, qc::QC_3D >:
aol::BiOp< aol::MultiVector< RealType > > aol::BiOpBase< aol::MultiVector< RealType > > aol::Op< aol::MultiVector< RealType > >

List of all members.

Public Member Functions

 TransformFunction (const qc::GridDefinition &Grid, const qc::BitArray< qc::QC_3D > *Mask=NULL)
void setDeformation (const aol::MultiVector< RealType > &Def)
void transform (const aol::MultiVector< RealType > &Arg, aol::MultiVector< RealType > &Dest, qc::BitArray< qc::QC_3D > &ValuesSet) const
void transform (const aol::MultiVector< RealType > &Arg, aol::MultiVector< RealType > &Dest, qc::BitArray< qc::QC_3D > &ValuesSet, const aol::MultiVector< RealType > &ExtendImage) const
void transform (const aol::Vector< RealType > &Arg, aol::Vector< RealType > &Dest, qc::BitArray< qc::QC_3D > &ValuesSet) const
void transform (const aol::Vector< RealType > &Arg, aol::Vector< RealType > &Dest, qc::BitArray< qc::QC_3D > &ValuesSet, const aol::Vector< RealType > &ExtendImage) const
void apply (const aol::MultiVector< RealType > &Arg, aol::MultiVector< RealType > &Dest) const
void applyAdd (const aol::MultiVector< RealType > &Arg, aol::MultiVector< RealType > &Dest) const

Protected Member Functions

void interpolateTetrahedron (const aol::Vec3< RealType > Coords[4], const RealType *Values, std::vector< qc::Array< RealType > * > &Array, const int NumComponents, qc::BitArray< qc::QC_3D > &ValuesSet) const

Protected Attributes

const qc::GridDefinition_grid
const aol::MultiVector
< RealType > * 
_def
const qc::BitArray< qc::QC_3D > * _mask

Detailed Description

template<typename RealType>
class qc::TransformFunction< RealType, qc::QC_3D >

Definition at line 305 of file auxiliary.h.


Constructor & Destructor Documentation

template<typename RealType >
qc::TransformFunction< RealType, qc::QC_3D >::TransformFunction ( const qc::GridDefinition Grid,
const qc::BitArray< qc::QC_3D > *  Mask = NULL 
) [inline]

Definition at line 311 of file auxiliary.h.

: _grid ( Grid ), _def ( NULL ), _mask( Mask ) {}


Member Function Documentation

template<typename RealType >
void qc::TransformFunction< RealType, qc::QC_3D >::apply ( const aol::MultiVector< RealType > &  Arg,
aol::MultiVector< RealType > &  Dest 
) const [inline, virtual]

Reimplemented from aol::Op< aol::MultiVector< RealType > >.

Definition at line 325 of file auxiliary.h.

                                                                                           {
    qc::BitArray<qc::QC_3D> valuesSet ( GridSize<QC_3D>::createFrom ( _grid ) );
    transform ( Arg, Dest, valuesSet );
  }

template<typename RealType >
void qc::TransformFunction< RealType, qc::QC_3D >::applyAdd ( const aol::MultiVector< RealType > &  Arg,
aol::MultiVector< RealType > &  Dest 
) const [inline, virtual]

when using applyAddMasked, implement applyAdd as applyAddMasked(Arg, Dest, INCLUDE_WRITE_DEFAULT).

Implements aol::Op< aol::MultiVector< RealType > >.

Definition at line 330 of file auxiliary.h.

References aol::MultiVector< _DataType >::numComponents().

                                                                                              {
    aol::MultiVector<RealType> tmp ( Dest.numComponents(), Dest[0].size() );
    apply ( Arg, tmp );
    Dest += tmp;
  }

template<typename RealType >
void qc::TransformFunction< RealType, qc::QC_3D >::interpolateTetrahedron ( const aol::Vec3< RealType >  Coords[4],
const RealType *  Values,
std::vector< qc::Array< RealType > * > &  Array,
const int  NumComponents,
qc::BitArray< qc::QC_3D > &  ValuesSet 
) const [protected]

Definition at line 423 of file auxiliary.cpp.

References qc::BitArray< qc::QC_3D >::get(), aol::isFinite(), aol::Max(), aol::Min(), aol::Vec3< _DataType >::set(), and qc::BitArray< qc::QC_3D >::set().

                                                                                                                                                                                                                                      {
  int minz = _grid.getWidth(), maxz = -1;
  int miny = _grid.getWidth(), maxy = -1;
  int minx = _grid.getWidth(), maxx = -1;

  for ( int loc = 0; loc < 4; loc++ ) {
    int qx = static_cast< int > ( Coords[loc][0] );
    int qy = static_cast< int > ( Coords[loc][1] );
    int qz = static_cast< int > ( Coords[loc][2] );

    maxz = aol::Max ( qz, maxz );
    if ( qz < Coords[loc][2] ) qz++;
    minz = aol::Min ( qz, minz );

    maxy = aol::Max ( qy, maxy );
    if ( qy < Coords[loc][1] ) qy++;
    miny = aol::Min ( qy, miny );

    maxx = aol::Max ( qx, maxx );
    if ( qx < Coords[loc][0] ) qx++;
    minx = aol::Min ( qx, minx );
  }

  // check bounds
  minx = aol::Max ( 0, minx );
  miny = aol::Max ( 0, miny );
  minz = aol::Max ( 0, minz );
  maxx = aol::Min ( _grid.getWidth() - 1, maxx );
  maxy = aol::Min ( _grid.getWidth() - 1, maxy );
  maxz = aol::Min ( _grid.getWidth() - 1, maxz );

  aol::Matrix33<RealType> mat, inv;
  for ( int i = 0; i < 3; i ++ ) {
    for ( int j = 0; j < 3; j ++ ) {
      mat[i][j] = Coords[j][i] - Coords[3][i];
    }
  }
  inv.makeCofactorMatrix ( mat );
  inv.transpose();
  const RealType matdet = mat.det();

  if ( matdet == 0. || ! aol::isFinite ( mat.det() ) )
    return;

  inv /= matdet;

  for ( int x = minx; x <= maxx; x++ ) {
    for ( int y = miny; y <= maxy; y++ ) {
      for ( int z = minz; z <= maxz; z++ ) {
        if ( ValuesSet.get ( x, y, z ) ) {} else {
          RealType sx = static_cast<RealType> ( x );
          RealType sy = static_cast<RealType> ( y );
          RealType sz = static_cast<RealType> ( z );
          aol::Vec3<RealType> lambda;
          aol::Vec3<RealType> r ( sx - Coords[3][0], sy - Coords[3][1], sz - Coords[3][2] );

          inv.mult ( r, lambda );

          // If the transformation is not invertible, it seems to be possible, that there are points, which aren't contained in one of the tetrahedrons. So it's necessary to set values also in the neighborhood of a given tetrahedron and mark those points, which are found in a given tetrahedron, to prevent overwriting of correct values.
          if ( lambda[0] < -5.e-1 || lambda[1] < -5.e-1 || lambda[2] < -5.e-1 || ( lambda[0] + lambda[1] + lambda[2] ) > 1. + 5.e-1 ) {} else {
            if ( ! ( lambda[0] < -1.e-6 || lambda[1] < -1.e-6 || lambda[2] < -1.e-6 || ( lambda[0] + lambda[1] + lambda[2] ) > 1. + 1.e-6 ) ) {
              ValuesSet.set ( x, y, z, true );
            }
            for ( int k = 0; k < NumComponents; k++ ) {
              RealType v = lambda[0] * Values[k*4] + lambda[1] * Values[k*4+1] + lambda[2] * Values[k*4+2] + ( aol::ZOTrait<RealType>::one - lambda[0] - lambda[1] - lambda[2] ) * Values[k*4+3];
              if ( aol::isFinite ( v ) ) {
                Array[k]->set ( x, y, z, v );
              }
            }
          }
        }
      }
    }
  }
}

template<typename RealType >
void qc::TransformFunction< RealType, qc::QC_3D >::setDeformation ( const aol::MultiVector< RealType > &  Def  )  [inline]

Definition at line 313 of file auxiliary.h.

                                                              {
    _def = &Def;
  }

template<typename RealType >
void qc::TransformFunction< RealType, qc::QC_3D >::transform ( const aol::Vector< RealType > &  Arg,
aol::Vector< RealType > &  Dest,
qc::BitArray< qc::QC_3D > &  ValuesSet,
const aol::Vector< RealType > &  ExtendImage 
) const

Definition at line 339 of file auxiliary.cpp.

References aol::MultiVector< _DataType >::appendReference().

                                                                                                                                                                                                 {
  aol::MultiVector<RealType> arg, dest, extendImage;
  arg.appendReference( Arg );
  dest.appendReference( Dest );
  extendImage.appendReference( ExtendImage );
  transform( arg, dest, ValuesSet, extendImage );
}

template<typename RealType >
void qc::TransformFunction< RealType, qc::QC_3D >::transform ( const aol::MultiVector< RealType > &  Arg,
aol::MultiVector< RealType > &  Dest,
qc::BitArray< qc::QC_3D > &  ValuesSet 
) const

Definition at line 324 of file auxiliary.cpp.

References aol::STRUCT_COPY.

                                                                                                                                                                   {
  aol::MultiVector<RealType> extendImage( Arg, aol::STRUCT_COPY );
  //extendImage.setZero();
  transform( Arg, Dest, ValuesSet, extendImage );
}

template<typename RealType >
void qc::TransformFunction< RealType, qc::QC_3D >::transform ( const aol::MultiVector< RealType > &  Arg,
aol::MultiVector< RealType > &  Dest,
qc::BitArray< qc::QC_3D > &  ValuesSet,
const aol::MultiVector< RealType > &  ExtendImage 
) const

Definition at line 348 of file auxiliary.cpp.

References qc::Array< DataType >::get(), aol::Max(), aol::Min(), aol::MultiVector< _DataType >::numComponents(), qc::BitArray< qc::QC_3D >::reallocate(), and aol::Vec3< _DataType >::set().

                                                                                                                                                                                                                {
  ValuesSet.reallocate( _grid.getWidth(), _grid.getWidth(), _grid.getWidth() );

  if ( !_def ) {
    throw aol::Exception ( "set deformation first\n", __FILE__, __LINE__ );
  }

  Dest = ExtendImage;

  const int numComponents = Arg.numComponents();

  std::vector<qc::Array<RealType>* > ADestVec ( numComponents );
  for ( int i = 0; i < numComponents; i++ ) {
    ADestVec[i] = new qc::Array<RealType> ( Dest[i], _grid );
  }

  std::vector<const qc::Array<RealType>* > AArgVec ( numComponents );
  for ( int i = 0; i < numComponents; i++ ) {
    AArgVec[i] = new const qc::Array<RealType> ( Arg[i], _grid );
  }

  qc::Array<RealType> defx ( ( *_def ) [0], _grid );
  qc::Array<RealType> defy ( ( *_def ) [1], _grid );
  qc::Array<RealType> defz ( ( *_def ) [2], _grid );

  qc::GridDefinition::OldFullElementIterator it;

  int offsets[8][3] = { {0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}, {0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {1, 1, 1} };
  int pts[8][3];
  RealType dx[8], dy[8], dz[8];
  aol::Vec3<RealType> coords[4];
  RealType *values = new RealType[numComponents*4];
  for ( it = _grid.begin(); it != _grid.end(); ++it ) {
    for ( int i = 0; i < 8; i++ ) {
      pts[i][0] = it->x() + offsets[i][0];
      pts[i][1] = it->y() + offsets[i][1];
      pts[i][2] = it->z() + offsets[i][2];

      dx[i] = static_cast< RealType > ( pts[i][0] ) + defx.get ( pts[i][0], pts[i][1], pts[i][2] ) / static_cast< RealType > (_grid.H());
      dy[i] = static_cast< RealType > ( pts[i][1] ) + defy.get ( pts[i][0], pts[i][1], pts[i][2] ) / static_cast< RealType > (_grid.H());
      dz[i] = static_cast< RealType > ( pts[i][2] ) + defz.get ( pts[i][0], pts[i][1], pts[i][2] ) / static_cast< RealType > (_grid.H());

      dx[i] = aol::Min ( dx[i], static_cast< RealType > ( _grid.getWidth() - 1 ) );
      dy[i] = aol::Min ( dy[i], static_cast< RealType > ( _grid.getWidth() - 1 ) );
      dz[i] = aol::Min ( dz[i], static_cast< RealType > ( _grid.getWidth() - 1 ) );
      dx[i] = aol::Max ( dx[i], static_cast< RealType > ( 0.0 ) );
      dy[i] = aol::Max ( dy[i], static_cast< RealType > ( 0.0 ) );
      dz[i] = aol::Max ( dz[i], static_cast< RealType > ( 0.0 ) );
    }

    // The nodes of the cube are numbered from 0 to 7, the cube is cut into 6 tetrahedrons
    int nodenumbers[6][4] = { {0, 1, 2, 4}, {1, 2, 3, 4}, {2, 3, 4, 6}, {1, 3, 4, 5}, {3, 4, 5, 6}, {3, 5, 6, 7} };

    for ( int i = 0; i < 6; i++ ) {
      bool mask = true;
      for ( int j = 0; j < 4; j++ ) {
        const int index = nodenumbers[i][j];
        coords[j].set ( dx[index], dy[index], dz[index] );
        for ( int k = 0; k < numComponents; k++ ) {
          values[k*4+j] = AArgVec[k]->get ( it->x() + offsets[index][0], it->y() + offsets[index][1], it->z() + offsets[index][2] );
        }
        mask = ( _mask == NULL ) || ( mask && _mask->get( it->x() + offsets[index][0], it->y() + offsets[index][1], it->z() + offsets[index][2] ) );
      }
      if ( mask )
        interpolateTetrahedron ( coords, values, ADestVec, numComponents, ValuesSet );
    }
  }
  for ( int i = 0; i < numComponents; i++ ) {
    delete ADestVec[i];
    delete AArgVec[i];
  }
  delete[] values;
}

template<typename RealType >
void qc::TransformFunction< RealType, qc::QC_3D >::transform ( const aol::Vector< RealType > &  Arg,
aol::Vector< RealType > &  Dest,
qc::BitArray< qc::QC_3D > &  ValuesSet 
) const

Definition at line 331 of file auxiliary.cpp.

References aol::MultiVector< _DataType >::appendReference().

                                                                                                                                                         {
  aol::MultiVector<RealType> arg, dest;
  arg.appendReference( Arg );
  dest.appendReference( Dest );
  transform( arg, dest, ValuesSet );
}


Member Data Documentation

template<typename RealType >
const aol::MultiVector<RealType>* qc::TransformFunction< RealType, qc::QC_3D >::_def [protected]

Definition at line 308 of file auxiliary.h.

template<typename RealType >
const qc::GridDefinition& qc::TransformFunction< RealType, qc::QC_3D >::_grid [protected]

Definition at line 307 of file auxiliary.h.

template<typename RealType >
const qc::BitArray<qc::QC_3D>* qc::TransformFunction< RealType, qc::QC_3D >::_mask [protected]

Definition at line 309 of file auxiliary.h.


The documentation for this class was generated from the following files:

Generated on Fri Sep 9 2011 21:09:37 for QuocMesh by doxygen 1.7.1