All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Static Public Attributes | Protected Member Functions
QGpCoreTools::Grid3D< ValueType > Class Template Reference

A 3D grid with regular cell sizes. More...

#include <Grid3D.h>

Inheritance diagram for QGpCoreTools::Grid3D< ValueType >:
QGpCoreTools::XMLClass

List of all members.

Public Member Functions

double bottom (int iz) const
void clear ()
Point coordinates (int ix, int iy, int iz) const
Grid2D< ValueType > * crossSectionX (double x) const
Grid2D< ValueType > * crossSectionY (double y) const
Grid2D< ValueType > * crossSectionZ (double z) const
double deltaX () const
double deltaY () const
double deltaZ () const
double east (int ix) const
 Grid3D ()
 Grid3D (int nx, int ny, int nz)
 Grid3D (const Grid3D &m)
int indexOfX (double x) const
int indexOfY (double y) const
int indexOfZ (double z) const
void init (int nx, int ny, int nz)
void init (ValueType value)
void init (int nx, int ny, int nz, ValueType value)
ValueType maximumValue () const
ValueType minimumValue () const
double north (int iy) const
int nx () const
int ny () const
int nz () const
const Pointorigin () const
void setDeltaX (double dx)
void setDeltaY (double dy)
void setDeltaZ (double dz)
void setOrigin (const Point &p)
void setValue (int ix, int iy, int iz, double val)
double south (int iy) const
double top (int iz) const
ValueType value (int ix, int iy, int iz) const
ValueType * valuePointer (int ix, int iy, int iz)
const ValueType * valuePointer (int ix, int iy, int iz) const
double west (int ix) const
double x (int ix) const
virtual const QString & xml_tagName () const
double y (int iy) const
double z (int iz) const
virtual ~Grid3D ()

Static Public Attributes

static const QString xmlGrid3DTag = "Grid3D"

Protected Member Functions

virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual bool xml_setBinaryData (XML_SETBINARYDATA_ARGS)
virtual bool xml_setProperty (XML_SETPROPERTY_ARGS)
virtual void xml_writeBinaryData (XML_WRITEBINARYDATA_ARGS) const
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Detailed Description

template<class ValueType>
class QGpCoreTools::Grid3D< ValueType >

A 3D grid with regular cell sizes.


Constructor & Destructor Documentation

template<class ValueType >
QGpCoreTools::Grid3D< ValueType >::Grid3D ( )

References TRACE.

{
  TRACE;
  _nx=_ny=_nz=0;
  _delta=Point(1., 1. );
  _invDelta=Point(1., 1. );
  _origin=Point(0., 0. );
  _values=0;
}
template<class ValueType >
QGpCoreTools::Grid3D< ValueType >::Grid3D ( int  nx,
int  ny,
int  nz 
)

References TRACE.

{
  TRACE;
  _values=0;
  _delta=Point(1., 1., 1. );
  _invDelta=Point(1., 1., 1. );
  _origin=Point(0., 0., 0. );
  init(nx, ny, nz);
}
template<class ValueType >
QGpCoreTools::Grid3D< ValueType >::Grid3D ( const Grid3D< ValueType > &  m)

References QGpCoreTools::Grid3D< ValueType >::init(), and TRACE.

                                         : XMLClass()
{
  TRACE;
  _values=0;
  _delta=m._delta;
  _invDelta=m._invDelta;
  _origin=m._origin;
  init(m._nx, m._ny, m._nz);
  int n=_ny * _nx * _nz;
  for(int i=0; i < n; i++ )
    _values[ i ]=m._values[ i ];
}
template<class ValueType >
QGpCoreTools::Grid3D< ValueType >::~Grid3D ( ) [virtual]

References TRACE.

{
  TRACE;
  if(_values) delete [] _values;
}

Member Function Documentation

template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::bottom ( int  iz) const [inline]
{return z(iz)+_delta.z()*0.5;}
template<class ValueType>
void QGpCoreTools::Grid3D< ValueType >::clear ( )
template<class ValueType >
Point QGpCoreTools::Grid3D< ValueType >::coordinates ( int  ix,
int  iy,
int  iz 
) const

References TRACE.

{
  TRACE;
  double x=_origin.x() + (double) ix * _delta.x();
  double y=_origin.y() + (double) iy * _delta.y();
  double z=_origin.z() + (double) iz * _delta.z();
  return (Point(x, y, z));
}
template<class ValueType >
Grid2D< ValueType > * QGpCoreTools::Grid3D< ValueType >::crossSectionX ( double  x) const

References QGpCoreTools::Grid2D< ValueType >::setDeltaX(), QGpCoreTools::Grid2D< ValueType >::setDeltaY(), QGpCoreTools::Grid2D< ValueType >::setOrigin(), and QGpCoreTools::Grid2D< ValueType >::valuePointer().

{
  int ix=indexOfX(x);
  if(ix<0 || ix>=_nx) {
    return 0;
  }
  Grid2D<ValueType> * section=new Grid2D<ValueType>(_ny, _nz);
  section->setDeltaX(_delta.y());
  section->setDeltaY(_delta.z());
  section->setOrigin(Point2D(_origin.y(), _origin.z()));
  ValueType * gridPtr=_values;
  ValueType * sectionPtr=section->valuePointer(0, 0);
  gridPtr+=ix;
  for(int iz=0; iz<_nz; iz++) {
    for(int iy=0; iy<_ny; iy++) {
      *(sectionPtr++)=*gridPtr;
      gridPtr+=_nx;
    }
  }
  return section;
}
template<class ValueType >
Grid2D< ValueType > * QGpCoreTools::Grid3D< ValueType >::crossSectionY ( double  y) const

References QGpCoreTools::Grid2D< ValueType >::setDeltaX(), QGpCoreTools::Grid2D< ValueType >::setDeltaY(), QGpCoreTools::Grid2D< ValueType >::setOrigin(), and QGpCoreTools::Grid2D< ValueType >::valuePointer().

{
  int iy=indexOfY(y);
  if(iy<0 || iy>=_ny) {
    return 0;
  }
  Grid2D<ValueType> * section=new Grid2D<ValueType>(_nx, _nz);
  section->setDeltaX(_delta.x());
  section->setDeltaY(_delta.z());
  section->setOrigin(Point2D(_origin.x(), _origin.z()));
  ValueType * gridPtr=_values;
  ValueType * sectionPtr=section->valuePointer(0, 0);
  gridPtr+=iy*_nx;
  int d=(_ny-1)*_nx;
  for(int iz=0; iz<_nz; iz++) {
    for(int ix=0; ix<_nx; ix++) {
      *(sectionPtr++)=*(gridPtr++);
    }
    gridPtr+=d;
  }
  return section;
}
template<class ValueType >
Grid2D< ValueType > * QGpCoreTools::Grid3D< ValueType >::crossSectionZ ( double  z) const

References QGpCoreTools::Grid2D< ValueType >::setDeltaX(), QGpCoreTools::Grid2D< ValueType >::setDeltaY(), QGpCoreTools::Grid2D< ValueType >::setOrigin(), and QGpCoreTools::Grid2D< ValueType >::valuePointer().

{
  int iz=indexOfZ(z);
  if(iz<0 || iz>=_nz) {
    return 0;
  }
  Grid2D<ValueType> * section=new Grid2D<ValueType>(_nx, _ny);
  section->setDeltaX(_delta.x());
  section->setDeltaY(_delta.y());
  section->setOrigin(Point2D(_origin.x(), _origin.y()));
  ValueType * gridPtr=_values;
  ValueType * sectionPtr=section->valuePointer(0, 0);
  gridPtr+=iz*_nx*_ny;
  for(int iy=0; iy<_ny; iy++) {
    for(int ix=0; ix<_nx; ix++) {
      *(sectionPtr++)=*(gridPtr++);
    }
  }
  return section;
}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::deltaX ( ) const [inline]
{return _delta.x();}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::deltaY ( ) const [inline]
{return _delta.y();}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::deltaZ ( ) const [inline]
{return _delta.z();}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::east ( int  ix) const [inline]
{return x(ix)-_delta.x()*0.5;}
template<class ValueType>
int QGpCoreTools::Grid3D< ValueType >::indexOfX ( double  x) const [inline]
{return (int) round((x - _origin.x()) * _invDelta.x());}
template<class ValueType>
int QGpCoreTools::Grid3D< ValueType >::indexOfY ( double  y) const [inline]
{return (int) round((y - _origin.y()) * _invDelta.y());}
template<class ValueType>
int QGpCoreTools::Grid3D< ValueType >::indexOfZ ( double  z) const [inline]
{return (int) round((z - _origin.z()) * _invDelta.z());}
template<class ValueType >
void QGpCoreTools::Grid3D< ValueType >::init ( int  nx,
int  ny,
int  nz 
)

References TRACE.

Referenced by QGpCoreTools::Grid3D< ValueType >::Grid3D(), and QGpCoreTools::operator>>().

{
  TRACE;
  if(_values) delete [] _values;
  _nx=nx;
  _ny=ny;
  _nz=nz;
  _values=new ValueType[ _nz * _ny * _nx ];
}
template<class ValueType >
void QGpCoreTools::Grid3D< ValueType >::init ( ValueType  value)

References TRACE.

{
  TRACE;
  int n=_nx * _ny * _nz;
  for(int i=0; i < n; i++ ) _values[ i ]=value;
}
template<class ValueType >
void QGpCoreTools::Grid3D< ValueType >::init ( int  nx,
int  ny,
int  nz,
ValueType  value 
) [inline]
{
  init(nx, ny, nz);
  init(value);
}
template<class ValueType >
ValueType QGpCoreTools::Grid3D< ValueType >::maximumValue ( ) const

References TRACE.

{
  TRACE;
  int n=_nx*_ny*_nz;
  if(n<1) return 0;
  ValueType val=_values[0];
  for(int i=1; i<n; i++) {
    if(_values[i]>val) val=_values[i];
  }
  return val;
}
template<class ValueType >
ValueType QGpCoreTools::Grid3D< ValueType >::minimumValue ( ) const

References TRACE.

{
  TRACE;
  int n=_nx*_ny*_nz;
  if(n<1) return 0;
  ValueType val=_values[0];
  for(int i=1; i<n; i++) {
    if(_values[i]<val) val=_values[i];
  }
  return val;
}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::north ( int  iy) const [inline]
{return y(iy)+_delta.y()*0.5;}
template<class ValueType>
int QGpCoreTools::Grid3D< ValueType >::nx ( ) const [inline]
{return _nx;}
template<class ValueType>
int QGpCoreTools::Grid3D< ValueType >::ny ( ) const [inline]
{return _ny;}
template<class ValueType>
int QGpCoreTools::Grid3D< ValueType >::nz ( ) const [inline]
{return _nz;}
template<class ValueType>
const Point& QGpCoreTools::Grid3D< ValueType >::origin ( ) const [inline]
{return _origin;}
template<class ValueType>
void QGpCoreTools::Grid3D< ValueType >::setDeltaX ( double  dx) [inline]

Referenced by QGpCoreTools::operator>>().

{_delta.setX(dx); _invDelta.setX(1.0/dx);}
template<class ValueType>
void QGpCoreTools::Grid3D< ValueType >::setDeltaY ( double  dy) [inline]

Referenced by QGpCoreTools::operator>>().

{_delta.setY(dy); _invDelta.setY(1.0/dy);}
template<class ValueType>
void QGpCoreTools::Grid3D< ValueType >::setDeltaZ ( double  dz) [inline]

Referenced by QGpCoreTools::operator>>().

{_delta.setZ(dz); _invDelta.setZ(1.0/dz);}
template<class ValueType>
void QGpCoreTools::Grid3D< ValueType >::setOrigin ( const Point p) [inline]

Referenced by QGpCoreTools::operator>>().

{_origin=p;}
template<class ValueType>
void QGpCoreTools::Grid3D< ValueType >::setValue ( int  ix,
int  iy,
int  iz,
double  val 
) [inline]

Referenced by QGpCoreTools::operator>>().

{_values[ix+_nx*(iy+_ny*iz)]=val;}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::south ( int  iy) const [inline]
{return y(iy)-_delta.y()*0.5;}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::top ( int  iz) const [inline]
{return z(iz)-_delta.z()*0.5;}
template<class ValueType>
ValueType QGpCoreTools::Grid3D< ValueType >::value ( int  ix,
int  iy,
int  iz 
) const [inline]

Referenced by QGpCoreTools::operator>>().

{return _values[ix+_nx*(iy+_ny*iz)];}
template<class ValueType>
ValueType* QGpCoreTools::Grid3D< ValueType >::valuePointer ( int  ix,
int  iy,
int  iz 
) [inline]
{return _values+ix+_nx*(iy+_ny*iz);}
template<class ValueType>
const ValueType* QGpCoreTools::Grid3D< ValueType >::valuePointer ( int  ix,
int  iy,
int  iz 
) const [inline]
{return _values+ix+_nx*(iy+_ny*iz);}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::west ( int  ix) const [inline]
{return x(ix)+_delta.x()*0.5;}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::x ( int  ix) const [inline]
{return _origin.x()+ix*_delta.x();}
template<class ValueType >
XMLMember QGpCoreTools::Grid3D< ValueType >::xml_member ( XML_MEMBER_ARGS  ) [protected, virtual]

Re-implement this function to offer XML restore (children and properties) support to your class.

From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:

  • An integer: id number of a property
  • A XMLClass * : a child of this object identified by tag
  • Default constructor: error, unknow child or property

Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):

    static const QString tmp("childrenName");
    XMLRestoreAttributeIterator it=map.find(tmp);
    if(it!=map.end()) {
      // found attribute "childrenName"
    }

If the map of attributes is not used:

    Q_UNUSED(attributes);
    if(tag=="x1") return XMLMember(0);
    else if(tag=="y1") return XMLMember(1);
    else if(tag=="x2") return XMLMember(2);
    else if(tag=="y2") return XMLMember(3);
    else return XMLMember(XMLMember::Unknown);

Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.

    if(tag=="anInteger") return XMLMember(0);
    else if(tag=="aString") return XMLMember(1);
    else if(tag=="aDouble") return XMLMember(2);
    return AbstractLine::xml_member(tag, attributes, context)+3;

For the arguments of this function use Macro XML_MEMBER_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE, and QGpCoreTools::XMLMember::Unknown.

{
  TRACE;
  Q_UNUSED(attributes);
  Q_UNUSED(context);
  if(tag=="origin" ) return XMLMember(0);
  else if(tag=="delta" ) return XMLMember(1);
  else if(tag=="nx" ) return XMLMember(2);
  else if(tag=="ny" ) return XMLMember(3);
  else if(tag=="nz" ) return XMLMember(4);
  return XMLMember(XMLMember::Unknown);
}
template<class ValueType >
bool QGpCoreTools::Grid3D< ValueType >::xml_setBinaryData ( XML_SETBINARYDATA_ARGS  ) [protected, virtual]

This function must be re-implemented in all classes dealing with binary data that cannot be saved in an ASCII xml file (e.g. due to the amount of data).

See also xml_writeBinaryData().

The difference between xml_setBinaryData() and xml_setBinaryData200410() is detected by the type of tag at the beginning of each block if it can be read with QString ==> 200510, else try with a normal C string, if it match the current tag then execute xml_setBinaryData200411().

See also xml_setBinaryData200411() to maintain compatibility with previous versions of xml storages.

For the arguments of this function use Macro XML_SETBINARYDATA_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References QGpCoreTools::endl(), QGpCoreTools::App::stream(), QGpCoreTools::tr(), and TRACE.

{
  TRACE;
  Q_UNUSED(context);
  int nx, ny, nz;
  s >> nx;
  s >> ny;
  s >> nz;
  if(nx!=_nx || ny!=ny || nz!=nz) {
    App::stream() << tr( "Grid3D size in binary file: %1x%2x%3\n"
                  "            in XML data   : %4x%5x%6" )
    .arg(nx).arg(ny).arg(nz).arg(_nx).arg(_ny).arg(_nz) << endl;
    _nx=nx;
    _ny=ny;
    _nz=nz;
  }
  init(_nx, _ny, _nz);
  s.readRawData((char *)_values, sizeof(double)*_nx * _ny * _nz);
  return true;
}
template<class ValueType >
bool QGpCoreTools::Grid3D< ValueType >::xml_setProperty ( XML_SETPROPERTY_ARGS  ) [protected, virtual]

Re-implement this function to offer XML restore properties support to your class.

From memberID set the corresponding property with value content. The map of attributes is given as a supplementary information (not useful in all cases).

For a general case:

  Q_UNUSED(attributes);
  double val=content.toDouble();
  switch (memberID) {
  case 0:
    _x1=val;
    return true;
  case 1:
    _y1=val;
    return true;
  case 2:
    _x2=val;
    return true;
  case 3:
    _y2=val;
    return true;
  default:
    return false;
  }

For classes inheriting other classes (see also xml_member())

  switch (memberID) {
  case 0:
    _anInteger=content.toString();
    return true;
  case 1:
    _aString=content.toInt();
    return true;
  case 2:
    _aDouble=content.toDouble();
    return true;
  default:
    return AbstractLine::xml_setProperty(memberID-3, map, content);

For the arguments of this function use Macro XML_SETPROPERTY_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE.

{
  TRACE;
  Q_UNUSED(attributes);
  Q_UNUSED(context);
  switch (memberID) {
  case 0: _origin.fromString(content); return true;
  case 1:
    _delta.fromString(content);
    _invDelta.setX(1.0/_delta.x());
    _invDelta.setY(1.0/_delta.y());
    _invDelta.setZ(1.0/_delta.z());
    return true;
  case 2: _nx=content.toInt(); return true;
  case 3: _ny=content.toInt(); return true;
  case 4: _nz=content.toInt(); return true;
  }
  return false;
}
template<class ValueType>
virtual const QString& QGpCoreTools::Grid3D< ValueType >::xml_tagName ( ) const [inline, virtual]

Implements QGpCoreTools::XMLClass.

{return xmlGrid3DTag;}
template<class ValueType >
void QGpCoreTools::Grid3D< ValueType >::xml_writeBinaryData ( XML_WRITEBINARYDATA_ARGS  ) const [protected, virtual]

This function must be re-implemented in all classes dealing with binary data that cannot be saved in an ASCII xml file (e.g. due to the amount of data).

The way binary data is stored drastically changed in November 2006 with the introduction of tar.gz structures for xml files. Each class willing to store binary data can automatically generate a new file (with an automatic file name) in the .tar.gz structure by sending bytes to s.

See also xml_setBinaryData().

For the arguments of this function use Macro XML_WRITEBINARYDATA_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE.

{
  TRACE;
  Q_UNUSED(context);
  s << _nx;
  s << _ny;
  s << _nz;
  s.writeRawData((const char *)_values, sizeof(double)*_nx * _ny * _nz);
}
template<class ValueType >
void QGpCoreTools::Grid3D< ValueType >::xml_writeProperties ( XML_WRITEPROPERTIES_ARGS  ) const [protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References TRACE.

{
  TRACE;
  writeProperty(s, "nx", _nx);
  writeProperty(s, "ny", _ny);
  writeProperty(s, "nz", _nz);
  writeProperty(s, "origin", _origin.toString());
  writeProperty(s, "delta", _delta.toString());
  writeBinaryData(s, context);
}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::y ( int  iy) const [inline]
{return _origin.y()+iy*_delta.y();}
template<class ValueType>
double QGpCoreTools::Grid3D< ValueType >::z ( int  iz) const [inline]
{return _origin.z()+iz*_delta.z();}

Member Data Documentation

template<class ValueType>
const QString QGpCoreTools::Grid3D< ValueType >::xmlGrid3DTag = "Grid3D" [static]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines