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

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

#include <Grid2D.h>

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

List of all members.

Public Member Functions

void clear ()
Point2D coordinates (int ix, int iy) const
double deltaX () const
double deltaY () const
double east (int ix) const
 Grid2D ()
 Grid2D (int nx, int ny)
 Grid2D (const Grid2D &m)
int indexOfX (double x) const
int indexOfY (double y) const
void init (int nx, int ny)
void init (ValueType value)
void init (int nx, int ny, ValueType value)
ValueType maximumValue () const
ValueType minimumValue () const
double north (int iy) const
int nx () const
int ny () const
const Point2Dorigin () const
void setDeltaX (double dx)
void setDeltaY (double dy)
void setOrigin (const Point2D &p)
void setValue (int ix, int iy, double val)
double south (int iy) const
ValueType value (int ix, int iy) const
ValueType * valuePointer (int ix, int iy)
const ValueType * valuePointer (int ix, int iy) const
double west (int ix) const
double x (int ix) const
virtual const QString & xml_tagName () const
double y (int iy) const
virtual ~Grid2D ()

Static Public Attributes

static const QString xmlGrid2DTag = "Grid2D"

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::Grid2D< ValueType >

A 2D grid with regular cell sizes.


Constructor & Destructor Documentation

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

References TRACE.

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

References TRACE.

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

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

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

References TRACE.

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

Member Function Documentation

template<class ValueType>
void QGpCoreTools::Grid2D< ValueType >::clear ( )
template<class ValueType >
Point2D QGpCoreTools::Grid2D< ValueType >::coordinates ( int  ix,
int  iy 
) const

References TRACE.

Referenced by SciFigs::GridViewer::trackRectangle().

{
  TRACE;
  double x=_origin.x() + (double) ix * _delta.x();
  double y=_origin.y() + (double) iy * _delta.y();
  return (Point2D(x, y));
}
template<class ValueType>
double QGpCoreTools::Grid2D< ValueType >::deltaX ( ) const [inline]
template<class ValueType>
double QGpCoreTools::Grid2D< ValueType >::deltaY ( ) const [inline]
template<class ValueType>
double QGpCoreTools::Grid2D< ValueType >::east ( int  ix) const [inline]

Referenced by SciFigs::GridViewer::boundingRect(), and SciFigs::GridPlot::drawGridLines().

{return x(ix)+_delta.x()*0.5;}
template<class ValueType>
int QGpCoreTools::Grid2D< ValueType >::indexOfX ( double  x) const [inline]

Referenced by SciFigs::GridViewer::mouseReleaseEvent().

{return (int) round((x - _origin.x()) * _invDelta.x());}
template<class ValueType>
int QGpCoreTools::Grid2D< ValueType >::indexOfY ( double  y) const [inline]

Referenced by SciFigs::GridViewer::mouseReleaseEvent().

{return (int) round((y - _origin.y()) * _invDelta.y());}
template<class ValueType >
void QGpCoreTools::Grid2D< ValueType >::init ( int  nx,
int  ny 
)

References TRACE.

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

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

References TRACE.

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

References TRACE.

{
  TRACE;
  int n=_nx*_ny;
  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::Grid2D< ValueType >::minimumValue ( ) const

References TRACE.

{
  TRACE;
  int n=_nx*_ny;
  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::Grid2D< ValueType >::north ( int  iy) const [inline]

Referenced by SciFigs::GridViewer::boundingRect(), and SciFigs::GridPlot::drawGridLines().

{return y(iy)+_delta.y()*0.5;}
template<class ValueType>
int QGpCoreTools::Grid2D< ValueType >::nx ( ) const [inline]
template<class ValueType>
int QGpCoreTools::Grid2D< ValueType >::ny ( ) const [inline]
template<class ValueType>
const Point2D& QGpCoreTools::Grid2D< ValueType >::origin ( ) const [inline]
template<class ValueType>
void QGpCoreTools::Grid2D< ValueType >::setDeltaX ( double  dx) [inline]
template<class ValueType>
void QGpCoreTools::Grid2D< ValueType >::setDeltaY ( double  dy) [inline]
template<class ValueType>
void QGpCoreTools::Grid2D< ValueType >::setOrigin ( const Point2D p) [inline]
template<class ValueType>
void QGpCoreTools::Grid2D< ValueType >::setValue ( int  ix,
int  iy,
double  val 
) [inline]

Referenced by QGpCoreTools::operator>>(), and SciFigs::GridViewer::trackRectangle().

{_values[ix+_nx*iy]=val;}
template<class ValueType>
double QGpCoreTools::Grid2D< ValueType >::south ( int  iy) const [inline]

Referenced by SciFigs::GridViewer::boundingRect(), and SciFigs::GridPlot::drawGridLines().

{return y(iy)-_delta.y()*0.5;}
template<class ValueType>
ValueType QGpCoreTools::Grid2D< ValueType >::value ( int  ix,
int  iy 
) const [inline]

Referenced by QGpCoreTools::operator>>().

{return _values[ix+_nx*iy];}
template<class ValueType>
ValueType* QGpCoreTools::Grid2D< ValueType >::valuePointer ( int  ix,
int  iy 
) [inline]
template<class ValueType>
const ValueType* QGpCoreTools::Grid2D< ValueType >::valuePointer ( int  ix,
int  iy 
) const [inline]
{return _values+ix+_nx*iy;}
template<class ValueType>
double QGpCoreTools::Grid2D< ValueType >::west ( int  ix) const [inline]

Referenced by SciFigs::GridViewer::boundingRect(), and SciFigs::GridPlot::drawGridLines().

{return x(ix)-_delta.x()*0.5;}
template<class ValueType>
double QGpCoreTools::Grid2D< ValueType >::x ( int  ix) const [inline]
{return _origin.x()+ix*_delta.x();}
template<class ValueType >
XMLMember QGpCoreTools::Grid2D< 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);
  return XMLMember(XMLMember::Unknown);
}
template<class ValueType >
bool QGpCoreTools::Grid2D< 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;
  s >> nx;
  s >> ny;
  if(nx!=_nx || ny!=ny) {
    App::stream() << tr( "Grid2D size in binary file: %1x%2\n"
                  "            in XML data   : %3x%4" )
    .arg(nx).arg(ny).arg(_nx).arg(_ny) << endl;
    _nx=nx;
    _ny=ny;
  }
  init(_nx, _ny);
  s.readRawData((char *)_values, sizeof(double)*_nx * _ny);
  return true;
}
template<class ValueType >
bool QGpCoreTools::Grid2D< 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(tag);
  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());
    return true;
  case 2: _nx=content.toInt(); return true;
  case 3: _ny=content.toInt(); return true;
  }
  return false;
}
template<class ValueType>
virtual const QString& QGpCoreTools::Grid2D< ValueType >::xml_tagName ( ) const [inline, virtual]

Implements QGpCoreTools::XMLClass.

{return xmlGrid2DTag;}
template<class ValueType >
void QGpCoreTools::Grid2D< 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.writeRawData((const char *)_values, sizeof(double)*_nx * _ny);
}
template<class ValueType >
void QGpCoreTools::Grid2D< 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, "origin", _origin.toString());
  writeProperty(s, "delta", _delta.toString());
  writeBinaryData(s, context);
}
template<class ValueType>
double QGpCoreTools::Grid2D< ValueType >::y ( int  iy) const [inline]
{return _origin.y()+iy*_delta.y();}

Member Data Documentation

template<class ValueType>
const QString QGpCoreTools::Grid2D< ValueType >::xmlGrid2DTag = "Grid2D" [static]

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