All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
DinverDCCore::ParamProfile Class Reference

#include <ParamProfile.h>

Inheritance diagram for DinverDCCore::ParamProfile:
QGpCoreTools::XMLClass

List of all members.

Public Types

enum  Type { Param, Condition }

Public Member Functions

void addLayer (ParamLayer *layer)
void collectDepthLinks (LayerMap &links)
void collectDepths (QVector< double > &depths) const
void collectValueParameters (QList< Parameter * > &params) const
SimpleCondition::Type defaultCondition () const
double defaultMaximum () const
double defaultMinimum () const
bool hasGradient () const
void initFinalProfile ()
void insertLayer (int at, ParamLayer *layer)
ParamLayerlayer (int index) const
const QString & longName () const
const ProfilemaxRawProfile () const
const ProfilemaxResampledProfile () const
ProfilemaxResampledProfile ()
const ProfileminRawProfile () const
const ProfileminResampledProfile () const
ProfileminResampledProfile ()
int nLayers () const
 ParamProfile ()
 ParamProfile (const ParamProfile &o)
 ParamProfile (QString shortName, QString longName, QString unit, double defaultMinimum, double defaultMaximum, Type type, SimpleCondition::Type defaultCondition)
void pMaxRaw () const
void pMaxResampled () const
void pRaw () const
void pResampled () const
const ProfilerawProfile () const
const ProfileresampledProfile () const
ProfileresampledProfile ()
void resampleProfile (QVector< double > &baseD)
void setDepthLinkNames ()
void setDepthLinks (const LayerMap &links)
void setFinalDepths (int fromLayer=0)
void setFinalProfileAt (int layer)
void setFinalProfileDepths (int fromLayer=0)
void setFinalProfileFrom (int layer=0)
void setLinkedDepth (RealSpace &ps)
const QString & shortName () const
bool toParam (RealSpace &ps, LayerMap &links, const ParamGroundModel *groundModel)
Type type () const
const QString & unit () const
void writeReport (QDataStream &s) const
virtual ~ParamProfile ()

Protected Member Functions

virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual bool xml_setProperty (XML_SETPROPERTY_ARGS)
virtual const QString & xml_tagName () const
virtual void xml_writeChildren (XML_WRITECHILDREN_ARGS) const
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Protected Attributes

SimpleCondition::Type _defaultCondition
double _defaultMaximum
double _defaultMinimum
LayerList _layers
QString _longName
Profile _maxRaw
Profile _maxResampled
Profile _raw
Profile _resampled
QString _shortName
Type _type
QString _unit

Static Protected Attributes

static const QString xmlParamProfileTag = "ParamProfile"

Member Enumeration Documentation

Enumerator:
Param 
Condition 

Constructor & Destructor Documentation

Copy constructor. Used only by copy constructor of ParamGroundModel.

References _defaultCondition, _defaultMaximum, _defaultMinimum, _layers, _longName, _shortName, _type, _unit, layer(), DinverDCCore::ParamLayer::setProfile(), and TRACE.

  : XMLClass()
{
  TRACE;
  _longName=o._longName;
  _shortName=o._shortName;
  _unit=o._unit;
  _defaultMinimum=o._defaultMinimum;
  _defaultMaximum=o._defaultMaximum;
  _defaultCondition=o._defaultCondition;
  _type=o._type;

  LayerList::const_iterator it;
  for(it=o._layers.begin();it!=o._layers.end();++it) {
    ParamLayer * layer=new ParamLayer( **it);
    layer->setProfile(this);
    _layers.append(layer);
  }
}
DinverDCCore::ParamProfile::ParamProfile ( QString  shortName,
QString  longName,
QString  unit,
double  defaultMinimum,
double  defaultMaximum,
Type  type,
SimpleCondition::Type  defaultCondition 
)

References _layers, and TRACE.

{
  TRACE;
  LayerList::iterator it;
  for(it=_layers.begin();it!=_layers.end();++it) delete *it;
}

Member Function Documentation

Append all layers (except half spaces) to layer map links.

References _layers, layer(), DinverDCCore::ParamLayer::name(), and TRACE.

{
  TRACE;
  int lastLayer=_layers.size() - 1; // half space index
  for(int iLayer=0; iLayer<lastLayer; iLayer++) {
    ParamLayer * layer=_layers.at(iLayer);
    links.insert(layer->name(), layer);
  }
}
void DinverDCCore::ParamProfile::collectDepths ( QVector< double > &  depths) const [inline]
{_raw.collectDepths(depths);}

Append all value parameters that describe this profile to params.

References _layers, DinverDCCore::ParamLayer::collectValueParameters(), layer(), and TRACE.

Referenced by DinverDCCore::PoissonCondition::PoissonCondition().

{
  TRACE;
  int lastLayer=_layers.count() - 1;
  for(int iLayer=0; iLayer<lastLayer; iLayer++ ) {
    ParamLayer * layer=_layers.at(iLayer);
    layer->collectValueParameters(params);
  }
  _layers.at(lastLayer)->collectValueParameters(params);
}
double DinverDCCore::ParamProfile::defaultMaximum ( ) const [inline]
double DinverDCCore::ParamProfile::defaultMinimum ( ) const [inline]

References _layers, TRACE, and DinverDCCore::ParamLayer::Uniform.

{
  TRACE;
  LayerList::const_iterator it;
  for(it=_layers.begin();it!=_layers.end();++it) {
    if((*it)->shape()!=ParamLayer::Uniform) return true;
  }
  return false;
}

Initialize the final profiles with the correct number of sub layers and set the index of the top sub layer of each paramLayer.

References _layers, _maxRaw, _raw, _type, Condition, Param, QGpCoreWave::Profile::resize(), and TRACE.

{
  TRACE;
  int index=0;
  int n=_layers.count();
  for(int i=0; i<n; i++ ) {
    _layers.at(i)->setTopDepthIndex(index);
  }
  switch (_type) {
  case Condition:
    _maxRaw.resize(index);
  case Param:
    _raw.resize(index);
    break;
  }
}
void DinverDCCore::ParamProfile::insertLayer ( int  at,
ParamLayer layer 
)

Inserts layer at index at. Never call this function directly, use ParamGroundModel::insertLayer() instead.

References _layers, nLayers(), DinverDCCore::ParamLayer::setIndex(), and TRACE.

Referenced by DinverDCCore::ParamGroundModel::insertLayer().

{
  TRACE;
  _layers.insert(at, layer);
  int nLayers=_layers.size();
  for(int iLayer=at+1; iLayer<nLayers; iLayer++) {
    ParamLayer * layer=_layers.at(iLayer);
    layer->setIndex(iLayer);
  }
}
ParamLayer* DinverDCCore::ParamProfile::layer ( int  index) const [inline]
const QString& DinverDCCore::ParamProfile::longName ( ) const [inline]
{return _maxResampled;}

References _minRaw.

Referenced by DinverDCCore::TargetList2D::misfit().

{return _minRaw;}

References _minResampled.

{return _minResampled;}
int DinverDCCore::ParamProfile::nLayers ( ) const [inline]

Debug: prints maximum raw profile

References _maxRaw, QGpCoreWave::Profile::print(), and TRACE.

Debug: prints maximum resamples profile

References _maxResampled, QGpCoreWave::Profile::print(), and TRACE.

Debug: prints raw profile

References _raw, QGpCoreWave::Profile::print(), and TRACE.

{
  TRACE;
  _raw.print();
}

Debug: prints resampled profile

References _resampled, QGpCoreWave::Profile::print(), and TRACE.

Referenced by DinverDCCore::TargetList2D::misfit().

{return _raw;}
{return _resampled;}
void DinverDCCore::ParamProfile::resampleProfile ( QVector< double > &  baseD) [inline]

Set link names in each layer from the link pointers.

References _layers, layer(), DinverDCCore::ParamLayer::setLinkedTo(), and TRACE.

{
  TRACE;
  int lastLayer=_layers.size() - 1; // half space index
  for(int iLayer=0; iLayer<lastLayer; iLayer++) {
    ParamLayer * layer=_layers.at(iLayer);
    layer->setLinkedTo();
  }
}

Set the link pointers from the link names and from the layer map links.

References _layers, layer(), DinverDCCore::ParamLayer::linkedTo(), DinverDCCore::ParamLayer::setPtrLink(), and TRACE.

{
  TRACE;
  int lastLayer=_layers.size() - 1; // half space index
  for(int iLayer=0; iLayer<lastLayer; iLayer++) {
    ParamLayer * layer=_layers.at(iLayer);
    if(!layer->linkedTo().isEmpty()) {
      layer->setPtrLink(links[layer->linkedTo()]);
    }
  }
}
void DinverDCCore::ParamProfile::setFinalDepths ( int  fromLayer = 0)

Called routinely during inversion, it inits the depths from parameter values. Linked depth parameters are not considered.

References _layers, and TRACE.

Referenced by DinverDCCore::ParamGroundModel::updateFinalProfiles().

{
  TRACE;
  double z;
  if(fromLayer==0) {
    z=0.0;
  } else {
    z=_layers.at(fromLayer)->topDepth();
  }
  int n=_layers.count();
  for(int i=fromLayer; i<n; i++ ) {
    _layers.at(i)->setFinalDepths(z);
  }
}

References _layers, _raw, _type, Condition, Param, and TRACE.

Referenced by DinverDCCore::ParamGroundModel::updateFinalProfiles().

{
  TRACE;
  switch (_type) {
  case Param:
    _layers.at(layer)->setFinalProfileValuesParam(_raw);
  case Condition:
    break;
  }
}

Called routinely during inversion, it inits the depths from parameter values. Linked depth parameters are considered to build the final depth profile.

References _layers, _maxRaw, _minRaw, _raw, _type, Condition, Param, and TRACE.

Referenced by DinverDCCore::ParamGroundModel::updateFinalProfiles().

{
  TRACE;
  double z;
  if(fromLayer==0) {
    z=0.0;
  } else {
    z=_layers.at(fromLayer)->topDepth();
  }
  int n=_layers.count();
  switch (_type) {
  case Param:
    for(int i=fromLayer; i<n; i++) {
      _layers.at(i)->setFinalProfileDepthsParam(_raw, z);
    }
    break;
  case Condition:
    for(int i=fromLayer; i<n; i++) {
      _layers.at(i)->setFinalProfileDepthsCondition(_minRaw, _maxRaw, z);
    }
    break;
  }
}

References _layers, _raw, _type, Condition, Param, and TRACE.

Referenced by DinverDCCore::ParamGroundModel::updateFinalProfiles().

{
  TRACE;
  int n=_layers.count();
  switch (_type) {
  case Param:
    for(int i=layer; i<n; i++ ) {
      _layers.at(i)->setFinalProfileValuesParam(_raw);
    }
  case Condition:
    break;
  }
}

Delayed resolution of linked depths Needed by profiles for checking and adding condition for depth (across linked depths).

References _layers, layer(), DinverDCCore::ParamLayer::setLinkedDepth(), and TRACE.

{
  TRACE;
  ParamLayer * prevLayer=0;
  ParamLayer * layer;
  int lastLayer=_layers.size() - 1;
  int iLayer=0;
  for(LayerList::iterator it=_layers.begin();it!=_layers.end();++it, iLayer++ ) {
    layer=*it;
    layer->setLinkedDepth(iLayer==lastLayer, prevLayer, ps);
    prevLayer=layer;
  }
}
const QString& DinverDCCore::ParamProfile::shortName ( ) const [inline]
bool DinverDCCore::ParamProfile::toParam ( RealSpace ps,
LayerMap links,
const ParamGroundModel groundModel 
)

References _defaultCondition, _layers, _maxRaw, _minRaw, _type, DinverCore::RealSpace::addCondition(), DinverDCCore::ParamLayer::bottomParam(), DinverDCCore::ParamLayer::depthToParam(), QGpCoreTools::endl(), DinverDCCore::ParamLayer::isLastParamCondition(), layer(), DinverDCCore::ParamLayer::linkedTo(), DinverDCCore::ParamLayer::name(), nLayers(), Param, DinverDCCore::ParamLayer::setFinalProfileValuesCondition(), DinverDCCore::ParamLayer::setPtrLink(), DinverDCCore::ParamLayer::topParam(), QGpCoreTools::tr(), TRACE, and DinverDCCore::ParamLayer::valueToParam().

{
  TRACE;
  int nLayers=_layers.size();
  int lastLayer=nLayers - 1; // half space index
  ParamLayer * layer;
  ParamLayer * prevLayer=0;
  for(int iLayer=0; iLayer<nLayers; iLayer++ ) {
    layer=_layers.at(iLayer);
    if(layer->linkedTo()!="Not linked" && iLayer!=lastLayer) {
      // Links may be cascaded, look carefully for circular references
      LayerList browsedLinks;
      LayerList::iterator it;
      ParamLayer * link=layer;
      while(link && link->linkedTo()!="Not linked" ) {
        if(browsedLinks.contains(link)) {
          App::stream() << tr( "Circular referecences for depth links" ) << endl;
          LayerList::iterator it;
          for(it=browsedLinks.begin();it!=browsedLinks.end();++it) {
            App::stream() << tr( "        %1 ---> %2" ).arg(( *it) ->name()).arg(( *it) ->linkedTo()) << endl;
          }
          return false;
        } else browsedLinks.append(link);
        LayerMap::iterator itMap=links.find(link->linkedTo());
        if(itMap!=links.end()) link=itMap.value(); else link=0;
      }
      if(!link) {
        App::stream() << tr( "Bad depth link %1 for parameter %2" ).arg(layer->linkedTo()).arg(layer->name()) << endl;
        return false;
      } else layer->setPtrLink(link);
    } else layer->setPtrLink(0);
    // Convert layer into parameters
    if(_type==Param) {
      if(!layer->valueToParam(ps, groundModel)) {
        App::stream() << tr("Error initializing parameter %1").arg(layer->name()) << endl;
        return false;
      }
    } else {
      layer->setFinalProfileValuesCondition(_minRaw, _maxRaw);
    }
    if(!layer->depthToParam(iLayer==lastLayer, prevLayer, ps, groundModel)) {
      App::stream() << tr("Error initializing parameter %1").arg(layer->name()) << endl;
      return false;
    }
    // Condition between neighbour layers
    if(_type==Param) {
      if(prevLayer && layer->isLastParamCondition()) {
        switch (_defaultCondition) {
        case SimpleCondition::LessThan:
          ps.addCondition(new SimpleCondition (prevLayer->bottomParam(), SimpleCondition::LessThan, 1.0, layer->topParam(), 0.0) );
          break;
        case SimpleCondition::GreaterThan:
          ps.addCondition(new SimpleCondition (prevLayer->bottomParam(), SimpleCondition::GreaterThan, 1.0, layer->topParam(), 0.0) );
          break;
        case SimpleCondition::NoCondition:
          break;
        }
      }
    }
    prevLayer=layer;
  }
  return true;
}
const QString& DinverDCCore::ParamProfile::unit ( ) const [inline]
void DinverDCCore::ParamProfile::writeReport ( QDataStream &  s) const [inline]

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 _layers, nLayers(), and TRACE.

{
  TRACE;
  Q_UNUSED(attributes)
  Q_UNUSED(context);
  if(tag=="longName" ) return XMLMember(0);
  else if(tag=="shortName" ) return XMLMember(1);
  else if(tag=="unit" ) return XMLMember(2);
  else if(tag=="type" ) return XMLMember(6);
  else if(tag=="defaultMinimum" ) return XMLMember(3);
  else if(tag=="defaultMaximum" ) return XMLMember(4);
  else if(tag=="defaultCondition" ) return XMLMember(5);
  else if(tag=="ParamLayer" ) {
    ParamLayer * l=new ParamLayer(this, nLayers());
    _layers.append(l);
    return XMLMember(l);
  } else if(tag=="minDefault") return XMLMember(3); // Kept for compatibility
  else if(tag=="maxDefault") return XMLMember(4); // Kept for compatibility
  else return XMLMember(XMLMember::Unknown);
}

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 _defaultCondition, _defaultMaximum, _defaultMinimum, _longName, _shortName, _type, _unit, Condition, Param, and TRACE.

{
  TRACE;
  Q_UNUSED(tag)
  Q_UNUSED(context);
  Q_UNUSED(attributes)
  switch (memberID) {
  case 0: _longName=content.toString(); return true;
  case 1: _shortName=content.toString(); return true;
  case 2: _unit=content.toString(); return true;
  case 3: _defaultMinimum=content.toDouble(); return true;
  case 4: _defaultMaximum=content.toDouble(); return true;
  case 5: {
      bool ok=true;
      _defaultCondition=SimpleCondition::fromString(content.toString(), ok);
      return ok;
    }
  case 6:
    if(content=="Condition" )
      _type=Condition;
    else
      _type=Param;
    return true;
  default: return false;
  }
}
virtual const QString& DinverDCCore::ParamProfile::xml_tagName ( ) const [inline, protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References _layers, QGpCoreTools::XMLSaveAttributes::add(), and TRACE.

{
  TRACE;
  LayerList::const_iterator it;
  static const QString key("name");
  XMLSaveAttributes att;
  QString& value=att.add(key);
  for(it=_layers.begin();it!=_layers.end();++it) {
    value=( *it) ->name();
    ( *it) ->xml_save(s, context, att);
  }
}

Reimplemented from QGpCoreTools::XMLClass.

References _defaultCondition, _defaultMaximum, _defaultMinimum, _longName, _shortName, _type, _unit, Param, TRACE, and QGpCoreTools::XMLClass::writeProperty().

{
  TRACE;
  Q_UNUSED(context);
  writeProperty(s, "type", _type==Param ? "Param" : "Condition" );
  writeProperty(s, "longName", _longName);
  writeProperty(s, "shortName", _shortName);
  writeProperty(s, "unit", _unit);
  writeProperty(s, "defaultMinimum", _defaultMinimum);
  writeProperty(s, "defaultMaximum", _defaultMaximum);
  writeProperty(s, "defaultCondition", SimpleCondition::toString(_defaultCondition));
}

Member Data Documentation

Referenced by pMaxResampled(), and resampleProfile().

Referenced by pResampled(), and resampleProfile().

QString DinverDCCore::ParamProfile::_unit [protected]
const QString DinverDCCore::ParamProfile::xmlParamProfileTag = "ParamProfile" [static, protected]

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