////----------------------------------------
//void CBratAlgoFilterGaussian::SumWeights(ComputeMode mode, uint32_t from)
//{
//  ComputeInitialWeights();
//
//  CUIntArray missingValue;
//  missingValue.resize(m_initialWeights.size());
//  m_weights.resize(m_initialWeights.size());
//
//  // Sum weight (exclude 'default value')
//  double sumWeight = 0.0;
//
//  for (uint32_t i = 0; i < m_dataWindowLength; i++)
//  {
//    if (CTools::IsDefaultValue(m_rawDataWindow.at(i)))
//    {
//      missingValue[i] = 1;
//    }
//    else
//    {
//  	  sumWeight += m_initialWeights[i];
//      missingValue[i] = 0;
//    }
//  }
//
//  // Scale weight
//  for (uint32_t i = 0; i < m_dataWindowLength; i++)
//  {
//    if (missingValue.at(i) == 1)
//    {
//      CTools::SetDefaultValue(m_weights[i]);
//    }
//    else
//    {
//      m_weights[i] = m_initialWeights[i] / sumWeight;
//    }
//  }
//
//  //string str;
//  //if (mode == ModeHorizontal)
//  //{
//  //  str.append("Mode Horizontal: ");
//  //}
//  //else
//  //{
//  //  str.append("Mode Vertical: ");
//  //}
//  //str.append("computed weights are: ");
//
//  //for (uint32_t i  = 0; i < m_dataWindowLength; i++)
//  //{
//	 // str.append(CTools::Format("%f ", m_weights[i]));
//  //}
//  //str.append("\n");
//
//  //CTrace::Tracer(str);
//}
//----------------------------------------
double CBratAlgoFilterGaussian::ApplyFilter(ComputeMode mode, uint32_t from)
{
  ComputeInitialWeights();

  //m_weights.resize(m_initialWeights.size());

  // Sum weight (exclude 'default value')
  double sumWeight = 0.0;

	//   Apply filter - calculate weighted mean
	double sum = 0.0;
  for (uint32_t i = 0; i < m_dataWindowLength; i++)
  {
    if (CTools::IsDefaultValue(m_rawDataWindow.at(i)))
    {
      continue;
    }

    sumWeight += m_initialWeights[i];

    sum += m_initialWeights.at(i) * m_rawDataWindow.at(i);
  }

#if _DEBUG_BRAT_ALGO    
  string str;
  if (mode == ModeHorizontal)
  {
    str.append("Mode Horizontal: ");
  }
  else
  {
    str.append("Mode Vertical: ");
  }
  str.append("computed weights are: ");

  for (uint32_t i  = 0; i < m_dataWindowLength; i++)
  {
	  str.append(CTools::Format("%f ", m_initialWeights[i]));
  }
  str.append("\n");
  str.append(CTools::Format("sumWeight is: %f \n", sumWeight));

  CTrace::Tracer(str);
#endif

  if (sumWeight == 0.0)
  {
    return sum;
  }

	return sum / sumWeight;
}
//----------------------------------------
double CBratAlgoFilterLoess2D::ApplyFilter()
{
  ComputeInitialWeights();

  uint32_t windowSize = GetDataWindowSize();

  // Sum weight (exclude 'default value')
  double sumWeight = 0.0;

  uint32_t nbMissingValue = 0;

	//   Apply filter - calculate weighted mean
	double sum = 0.0;
  for (uint32_t i = 0; i < windowSize; i++)
  {
    if (isDefaultValue(m_rawDataWindow.at(i)))
    {
      nbMissingValue++;
      continue;
    }

    sumWeight += m_initialWeights[i];

    sum += m_initialWeights.at(i) * m_rawDataWindow.at(i);

#if _DEBUG_BRAT_ALGO    
    CTrace::Tracer(CTools::Format("ApplyFilter sum = %f m_initialWeights = %f value = %f" , 
                                      sum, m_initialWeights.at(i), m_rawDataWindow.at(i)));
#endif
  }

  uint32_t nbValidPts = windowSize - nbMissingValue;

  if (nbValidPts < m_validPts)
  {
    setDefaultValue(sum);
    return sum;
  }

  if (sumWeight == 0.0)
  {
    return sum;
  }

	return sum / sumWeight;
}
//----------------------------------------
double CBratAlgoFilterLanczos::ApplyFilter(ComputeMode mode, uint32_t from)
{
  ComputeInitialWeights();

  uint32_t halfWindow = static_cast<uint32_t>(m_dataWindowLength) / 2;

  // Sum weight (exclude 'default value')
  double sumWeight = 0.0;


  //   Apply filter - calculate weighted mean
	double sum = 0.0;
  for (uint32_t i = 0; i < m_dataWindowLength; i++)
  {
    if (CTools::IsDefaultValue(m_rawDataWindow.at(i)))
    {
      continue;
    }

    sumWeight += m_initialWeights[i];

    // At the middle, weight have already been set to (2.0 * m_cutOffFrequency)
    // Don't divide by sumWeight
    // Treat middle point outside the loop
    if (i == halfWindow)
    {
      continue;
    }


    sum += m_initialWeights.at(i) * m_rawDataWindow.at(i);
  }


  if (sumWeight != 0.0)
  {
    sum /= sumWeight;
  }

  // Middle point treatment
  if (!CTools::IsDefaultValue(m_rawDataWindow.at(halfWindow)))
  {
    sum += m_initialWeights.at(halfWindow) * m_rawDataWindow.at(halfWindow);
  }

#if _DEBUG_BRAT_ALGO    

  string str;
  if (mode == ModeHorizontal)
  {
    str.append("Mode Horizontal: ");
  }
  else
  {
    str.append("Mode Vertical: ");
  }
  str.append("computed weights are: ");

  for (uint32_t i  = 0; i < m_dataWindowLength; i++)
  {
	  str.append(CTools::Format("%f ", m_initialWeights[i]));
  }
  str.append("\n");
  str.append(CTools::Format("sumWeight is: %f \n", sumWeight));

  CTrace::Tracer(str);
#endif

	return sum;
}