//----------------------------------------------------------------------------------
//! Handle field changes of the field field.
//----------------------------------------------------------------------------------
void SegmentationEvaluationMetric::handleNotification (Field *field)
{
  ML_TRACE_IN("SegmentationEvaluationMetric::handleNotification ()");

  if (_isAutoApplyFld->isOn() || (field == _applyFld)) {
    if (getUpdatedInImg(0) && getUpdatedInImg(1) ) {
	    _process();
    } else {
      _reset();
    }
  }
}
//----------------------------------------------------------------------------------
//! Handle field changes of the field field.
//----------------------------------------------------------------------------------
void FuzzyConnectedness::handleNotification (Field *field)
{
  ML_TRACE_IN("FuzzyConnectedness::handleNotification ()");
  // Calculation will only be performed if either the start 
  // button is pressed or  the auto update mechanism is used. 
  if ((field ==_startButtonFld) || ((field != _startButtonFld) && _autoUpdateFld->isOn()))
  {
    _state = ML_RESULT_OK;
    //If either input image is open the calculation will be cancelled.
    if(!getUpdatedInImg(0) || !getUpdatedInImg(1))
    {
      _state = ML_DISCONNECTED_GRAPH;
      clearData();
      getOutImg(0)->setOutOfDate();
      getOutImg(1)->setOutOfDate();
      getOutField(0)->notifyAttachments();
      getOutField(1)->notifyAttachments();
    }
    else
    {
      // Same extent of image data and seed point image are required
      if ( getUpdatedInImg(0)->getImgExt() != getUpdatedInImg(1)->getImgExt() )
      {
        _state=ML_BAD_DIMENSION;
      }
      // Calculation will be started here
      else{
        _state = calculate(getUpdatedInImg(0),getUpdatedInImg(1));
      }
    }
    // Let the connected modules know that the output has changed.
    getOutField(0)->notifyAttachments();
    getOutField(1)->notifyAttachments();
  }
}
//----------------------------------------------------------------------------------
//! Handle field changes of the field \c field.
//----------------------------------------------------------------------------------
void METKSurfaceDistance3D::handleNotification(Field *field) {
    ML_TRACE_IN("METKSurfaceDistance3D::handleNotification(Field *field)");
    if (field == _nearDistance || field == _nearDistanceColor || field == _farDistance || field == _farDistanceColor) {
        if (_nearDistance->getFloatValue() > _farDistance->getFloatValue()) {
            _nearDistance->setFloatValue(_farDistance->getFloatValue());
        }
        if (_nearDistance->getFloatValue() < 0.0f) {
            _nearDistance->setFloatValue(0.0f);
        }
        if (_farDistance->getFloatValue() < 0.0f) {
            _farDistance->setFloatValue(0.0f);
        }
        T_ColorShapeIterator iter;
        for (iter = _colorShapeVec.begin(); iter != _colorShapeVec.end(); iter++) {
            (*iter)->_nearDistance = _nearDistance->getFloatValue();
            (*iter)->_farDistance = _farDistance->getFloatValue();
            float r, g, b;
            _nearDistanceColor->getColorValue(r, g, b);
            (*iter)->_nearDistanceColor.setValue(r, g, b);
            _farDistanceColor->getColorValue(r, g, b);
            (*iter)->_farDistanceColor.setValue(r, g, b);
            (*iter)->compute();
        }
    }

    if (field == getInField(0)) {
        _inputImageIsValid = false;
        _image = getUpdatedInImg(0);

        if (_image) {
            _inImageBox = new SubImgBox(_image->getBoxFromImgExt());
            _inputImageIsValid = true;
            T_ColorShapeIterator iter;
            for (iter = _colorShapeVec.begin(); iter != _colorShapeVec.end(); iter++) {
                (*iter)->compute();
            }

        } else {
            _inputImageIsValid = false;

            if (_inImageBox) {
                delete _inImageBox;
                _inImageBox = 0;
            }
            _inImageBox = NULL;
            _image      = NULL;
        }
    }
    inherited::handleNotification(field);
}