示例#1
0
int TraceStoreCol::CalcMedianReference (size_t row, size_t col,
                           GridMesh<std::vector<float> > &regionMed,
                           std::vector<double> &dist,
                           std::vector<std::vector<float> *> &values,
                           std::vector<float> &reference) {
    int retVal = TraceStore::TS_OK;
    reference.resize(mFrames);
    std::fill(reference.begin(), reference.end(), 0.0);
    regionMed.GetClosestNeighbors (row, col, mUseMeshNeighbors, dist, values);
    int num_good = 0;
    size_t valSize = values.size();
    for (size_t i =0; i < valSize; i++) {
      if (values[i]->size() > 0) {
        num_good++;
      }
    }
    // try reaching a little farther if no good reference close by
    if (num_good == 0) {
      regionMed.GetClosestNeighbors (row, col, 2*mUseMeshNeighbors, dist, values);
    }
    size_t size = 0;
    double maxDist = 0;
    for (size_t i = 0; i < values.size(); i++) {
        size = max (values[i]->size(), size);
        maxDist = max(dist[i], maxDist);
    }
    reference.resize (size);
    std::fill (reference.begin(), reference.end(), 0.0);
    double distWeight = 0;
         valSize = values.size();

    for (size_t i = 0; i < valSize; i++) {
      if (values[i]->size()  == 0) {
        continue;
      }
      double w = TraceStore::WeightDist (dist[i], mRowRefStep); //1/sqrt(dist[i]+1);
      distWeight += w;
      size_t vSize = values[i]->size();
      for (size_t j = 0; j < vSize; j++) {
        reference[j] += w * values[i]->at (j);
      }
    }
    // Divide by our total weight to get weighted mean
    if (distWeight > 0)  {
      for (size_t i = 0; i < reference.size(); i++) {
        reference[i] /= distWeight;
      }
      retVal = TraceStore::TS_OK;
    }
    else {
      retVal = TraceStore::TS_BAD_DATA;
    }
    return retVal;
  }
示例#2
0
文件: Traces.cpp 项目: Jorges1000/TS
bool Traces::CalcStartFrame(size_t row, size_t col, 
                            GridMesh<SampleStats<float> > &regionStart, float &start) {
  std::vector<double> dist(7);
  std::vector<SampleStats<float> *> values;
  bool allOk = false;
  regionStart.GetClosestNeighbors(row, col, mUseMeshNeighbors, dist, values);
  double distWeight = 0;
  double startX = 0;
  start = 0;
  for (size_t i = 0; i < values.size(); i++) {
    if (values[i]->GetCount() > 0) {
      double w = WeightDist(dist[i]); //1/sqrt(dist[i] + 1);
      distWeight += w;
      startX += w * values[i]->GetMean();
    }
  }

  if (distWeight > 0 && start >= 0) {
    start = startX / distWeight;
    if (startX >= 0 && isfinite(startX)) {
      allOk = true; 
    }
  }

  return allOk;
}
示例#3
0
文件: Traces.cpp 项目: Jorges1000/TS
int Traces::CalcMedianReference(int row, int col, 
				GridMesh<std::vector<float> > &regionMed,
				std::vector<double> &dist,
				std::vector<std::vector<float> *> &values,
				std::vector<float> &reference) {
  int retVal = OK;
  // vector<float> &binVal = regionMed.GetItemByRowCol(row,col);
  // if (binVal.size() > 0) {
  //   reference.resize(binVal.size());
  //   copy(binVal.begin(), binVal.end(), reference.begin());
  //   return OK;
  // }
  regionMed.GetClosestNeighbors(row, col, mUseMeshNeighbors, dist, values);
  size_t size = 0;
  for (size_t i = 0; i < values.size(); i++) {
    size = max(values[i]->size(), size);
  }
  reference.resize(size);
  fill(reference.begin(), reference.end(), 0.0);
  double distWeight = 0;
  size_t valSize = values.size();
  for (size_t i = 0; i < valSize; i++) {
    if (values[i]->size()  == 0) {
      continue;
    }
    double w = WeightDist(dist[i]); //1/sqrt(dist[i]+1);
    distWeight += w;
    size_t vSize = values[i]->size();
    for (size_t j = 0; j < vSize; j++) {
      reference[j] += w * values[i]->at(j);
    }
  }
  // Divide by our total weight to get weighted mean
  if (distWeight > 0) {
    for (size_t i = 0; i < reference.size(); i++) {
      reference[i] /= distWeight;
    }
    retVal = OK;
  }
  else {
    retVal = BAD_DATA;
  }
  return retVal;
}