A 3D grid with regular cell sizes. More...
#include <Grid3D.h>
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 Point & | origin () 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 |
A 3D grid with regular cell sizes.
QGpCoreTools::Grid3D< ValueType >::Grid3D | ( | ) |
QGpCoreTools::Grid3D< ValueType >::Grid3D | ( | int | nx, |
int | ny, | ||
int | nz | ||
) |
QGpCoreTools::Grid3D< ValueType >::Grid3D | ( | const Grid3D< ValueType > & | m | ) |
References QGpCoreTools::Grid3D< ValueType >::init(), and TRACE.
QGpCoreTools::Grid3D< ValueType >::~Grid3D | ( | ) | [virtual] |
double QGpCoreTools::Grid3D< ValueType >::bottom | ( | int | iz | ) | const [inline] |
void QGpCoreTools::Grid3D< ValueType >::clear | ( | ) |
Point QGpCoreTools::Grid3D< ValueType >::coordinates | ( | int | ix, |
int | iy, | ||
int | iz | ||
) | const |
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; }
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; }
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; }
double QGpCoreTools::Grid3D< ValueType >::deltaX | ( | ) | const [inline] |
{return _delta.x();}
double QGpCoreTools::Grid3D< ValueType >::deltaY | ( | ) | const [inline] |
{return _delta.y();}
double QGpCoreTools::Grid3D< ValueType >::deltaZ | ( | ) | const [inline] |
{return _delta.z();}
double QGpCoreTools::Grid3D< ValueType >::east | ( | int | ix | ) | const [inline] |
int QGpCoreTools::Grid3D< ValueType >::indexOfX | ( | double | x | ) | const [inline] |
int QGpCoreTools::Grid3D< ValueType >::indexOfY | ( | double | y | ) | const [inline] |
int QGpCoreTools::Grid3D< ValueType >::indexOfZ | ( | double | z | ) | const [inline] |
void QGpCoreTools::Grid3D< ValueType >::init | ( | int | nx, |
int | ny, | ||
int | nz | ||
) |
References TRACE.
Referenced by QGpCoreTools::Grid3D< ValueType >::Grid3D(), and QGpCoreTools::operator>>().
void QGpCoreTools::Grid3D< ValueType >::init | ( | ValueType | value | ) |
void QGpCoreTools::Grid3D< ValueType >::init | ( | int | nx, |
int | ny, | ||
int | nz, | ||
ValueType | value | ||
) | [inline] |
ValueType QGpCoreTools::Grid3D< ValueType >::maximumValue | ( | ) | const |
ValueType QGpCoreTools::Grid3D< ValueType >::minimumValue | ( | ) | const |
double QGpCoreTools::Grid3D< ValueType >::north | ( | int | iy | ) | const [inline] |
int QGpCoreTools::Grid3D< ValueType >::nx | ( | ) | const [inline] |
{return _nx;}
int QGpCoreTools::Grid3D< ValueType >::ny | ( | ) | const [inline] |
{return _ny;}
int QGpCoreTools::Grid3D< ValueType >::nz | ( | ) | const [inline] |
{return _nz;}
const Point& QGpCoreTools::Grid3D< ValueType >::origin | ( | ) | const [inline] |
{return _origin;}
void QGpCoreTools::Grid3D< ValueType >::setDeltaX | ( | double | dx | ) | [inline] |
Referenced by QGpCoreTools::operator>>().
void QGpCoreTools::Grid3D< ValueType >::setDeltaY | ( | double | dy | ) | [inline] |
Referenced by QGpCoreTools::operator>>().
void QGpCoreTools::Grid3D< ValueType >::setDeltaZ | ( | double | dz | ) | [inline] |
Referenced by QGpCoreTools::operator>>().
void QGpCoreTools::Grid3D< ValueType >::setOrigin | ( | const Point & | p | ) | [inline] |
Referenced by QGpCoreTools::operator>>().
{_origin=p;}
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;}
double QGpCoreTools::Grid3D< ValueType >::south | ( | int | iy | ) | const [inline] |
double QGpCoreTools::Grid3D< ValueType >::top | ( | int | iz | ) | const [inline] |
ValueType QGpCoreTools::Grid3D< ValueType >::value | ( | int | ix, |
int | iy, | ||
int | iz | ||
) | const [inline] |
Referenced by QGpCoreTools::operator>>().
{return _values[ix+_nx*(iy+_ny*iz)];}
ValueType* QGpCoreTools::Grid3D< ValueType >::valuePointer | ( | int | ix, |
int | iy, | ||
int | iz | ||
) | [inline] |
{return _values+ix+_nx*(iy+_ny*iz);}
const ValueType* QGpCoreTools::Grid3D< ValueType >::valuePointer | ( | int | ix, |
int | iy, | ||
int | iz | ||
) | const [inline] |
{return _values+ix+_nx*(iy+_ny*iz);}
double QGpCoreTools::Grid3D< ValueType >::west | ( | int | ix | ) | const [inline] |
double QGpCoreTools::Grid3D< ValueType >::x | ( | int | ix | ) | const [inline] |
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:
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); }
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; }
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; }
virtual const QString& QGpCoreTools::Grid3D< ValueType >::xml_tagName | ( | ) | const [inline, virtual] |
Implements QGpCoreTools::XMLClass.
{return xmlGrid3DTag;}
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); }
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); }
double QGpCoreTools::Grid3D< ValueType >::y | ( | int | iy | ) | const [inline] |
double QGpCoreTools::Grid3D< ValueType >::z | ( | int | iz | ) | const [inline] |
const QString QGpCoreTools::Grid3D< ValueType >::xmlGrid3DTag = "Grid3D" [static] |