typename unicubicInterpolation<scalartype_>::vectortype unicubicInterpolation<scalartype_>::operator()(vectortype newcoord) {
  
  vectortype newval(2);
  newval.setZero();

  vectortype d = this->maxCoord - this->minCoord;
  vectortype x = newcoord - this->minCoord;
  scalartype t = x(0)/d(0);

  if(t > 1 || t < 0){
    // Trow exception
    return newval/(scalartype)0.0;
  }

  
  for(int i = 0; i < 4; ++i){
    // Function value
    newval(0) += alpha(i,0) * pow(t,i);
    // Derivative of first variable - problem if t==0??
    if(i > 0)
      newval(1) += i * alpha(i,0) * pow(t,i-1) / d(0);
    // Derivative of second variable
  }
  return newval;
};
Beispiel #2
0
void MeshManager::colorMeshByGeoDistance(int vidx)
{
  auto laplacianSmoother = [&](const vector<double> &val, HDS_Mesh *mesh) {
    const double lambda = 0.25;
    const double sigma = 1.0;
    unordered_map<HDS_Vertex*, double> L(mesh->verts().size());
    vector<double> newval(mesh->verts().size());
    for (auto vi : mesh->verts()) {
      auto neighbors = vi->neighbors();

      double denom = 0.0;
      double numer = 0.0;

      for (auto vj : neighbors) {
        //double wij = 1.0 / (vi->pos.distanceToPoint(vj->pos) + sigma);
        double wij = 1.0 / neighbors.size();
        denom += wij;
        numer += wij * val[vj->index];
      }

      L.insert(make_pair(vi, numer / denom - val[vi->index]));
  }
    for (auto p : L) {
      newval[p.first->index] = val[p.first->index] + lambda * p.second;
    }

    return newval;
  };
#if 1
  auto dists = gcomp->distanceTo(vidx);
  int niters = 100;
  for (int i = 0; i < niters; ++i)
    dists = laplacianSmoother(dists, hds_mesh.data());
#else
  auto Q = MeshIterator::BFS(hds_mesh.data(), vidx);
  vector<double> dists(hds_mesh->verts().size());
  while (!Q.empty()){
    auto cur = Q.front();
    Q.pop();
    dists[cur.first->index] = cur.second;
  }
#endif

  // save it to a file
  ofstream fout("geodist.txt");
  for (auto x : dists) {
    fout << x << endl;
  }
  fout.close();

  double maxDist = *(std::max_element(dists.begin(), dists.end()));
  std::for_each(dists.begin(), dists.end(), [=](double &x){
    x /= maxDist;
    x -= 0.5;
    //cout << x << endl;
  });
  hds_mesh->colorVertices(dists);
}
Beispiel #3
0
Eigen::VectorXd TrapezoidalInt::integrate(const unsigned long long &u_ts, const Eigen::VectorXd &dx) {
	// TODO -- This function should use the u_time stamp from zero. Then it can also be used as an integral time counter and makes best possible use of the available time variable dynamic range

	if (u_ts < u_stime) {
		std::cout << "TrapezoidalInt::integrate is jumping back in time. This was not expected -- behavior will be unpredictable.\n";
		u_stime = u_ts;
	}
	if (first_pass) {
		u_stime = u_ts;
		first_pass = false;
	}

	// Eigen does not ensure self assigned computations x = x + 1
	Eigen::VectorXd newval(size);
	newval = int_dx + 0.5*(dx + prev_dx)*(u_ts-u_stime)*1E-6;
	int_dx = newval;

	u_stime = u_ts;
	prev_dx = dx;

	return int_dx;
}
Beispiel #4
0
      ModifierFilter(unsigned int type, const unsigned int* vec, size_t length) :
        RemapFilterBase(type)
      {
        targets_.reserve(length / 2);

        {
          Vector_ModifierFlag v;
          targets_.push_back(v);
        }

        for (size_t i = 0; i < length - 1; i += 2) {
          AddDataType datatype(vec[i]);
          AddValue newval(vec[i + 1]);

          switch (datatype) {
            case BRIDGE_DATATYPE_MODIFIERFLAG:
              if (! targets_.empty()) {
                targets_.back().push_back(ModifierFlag(datatype, newval));
              }
              break;

            case BRIDGE_DATATYPE_MODIFIERFLAGS_END:
            {
              Vector_ModifierFlag v;
              targets_.push_back(v);
              break;
            }

            default:
              IOLOG_ERROR("ModifierFilter::add invalid datatype:%u\n", static_cast<unsigned int>(datatype));
              break;
          }
        }

        if (length % 2 > 0) {
          IOLOG_WARN("Invalid length(%d) in BRIDGE_FILTERTYPE_MODIFIER_*\n", static_cast<int>(length));
        }
      }
/// Copy contents to new variable
template<> AMI_DLLEXPORT BasicVariable::ptr Variable<double>::NewCopy() const
{
  boost::shared_ptr<double> newval( new double(Value()));
  Variable<double>::ptr newvar(new Variable<double>(newval));
  return newvar;
}
Beispiel #6
0
int main(int argc, char *argv[]) {

    if (argc != 3) {
        std::cerr << "Usage: " << argv[0] << " OSMFILE OUTFILE\n";
        exit(1);
    }

    std::string outfile(argv[2]);

    stringv fields_nodes;
    stringv fields_ways;
    stringv fields_areas;
    stringv translation_tables;

    if (const char* str = getenv("CDE_FIELDS_NODES")) 
    {
        boost::split(fields_nodes, str, boost::is_any_of(","));
    }
    if (const char* str = getenv("CDE_FIELDS_WAYS")) 
    {
        boost::split(fields_ways, str,  boost::is_any_of(","));
    }
    if (const char* str = getenv("CDE_FIELDS_AREAS")) 
    {
        boost::split(fields_areas, str, boost::is_any_of(","));
    }
    if (const char* str = getenv("CDE_TRANSLATION_TABLES")) 
    {
        boost::split(translation_tables, str, boost::is_any_of(","));
    }

    if (fields_nodes.empty() || fields_ways.empty() || fields_areas.empty()) 
    {
        std::cerr << "You need to set the env variables CDE_FIELDS_NODES, CDE_FIELDS_WAYS, and CDE_FIELDS_AREAS before calling this program!\n";
        exit(1);
    }

    transmap tm;

    BOOST_FOREACH(std::string tt, translation_tables)
    {
        std::string line;
        std::ifstream file(tt.c_str());
        boost::regex translation_regex("^((\\S+)=)?(\\S+)\\s+(.*?)\\s*$", boost::regex::perl);
        boost::regex empty_regex("^\\S*(#.*)?$", boost::regex::perl);
        boost::cmatch matches;

        if (file.is_open())
        {
            std::cerr << "loading translations from " << tt << "..." << std::endl;
            int count = 0;
            int lineno = 0;
            while(file.good())
            {
                lineno++;
                getline(file, line);
                if (boost::regex_match(line.c_str(), empty_regex))
                {
                    // ignore
                }
                else if (boost::regex_match(line.c_str(), matches, translation_regex))
                {
                    std::string key(matches[2].first, matches[2].second);
                    std::string oldval(matches[3].first, matches[3].second);
                    std::string newval(matches[4].first, matches[4].second);
                    tm[key][oldval] = newval;
                    count++;
                }
                else
                {
                    std::cerr << "line " << lineno << " cannot be parsed: " << line << std::endl;
                }
            }
            file.close();
            std::cerr << count << " translations loaded from " << tt << std::endl;
        }
        else
        {
            std::cerr << "cannot open translation file '" << tt << "', continuing without" << std::endl;
        }
    }
Beispiel #7
0
bool value::loadcsv (const string &filename, bool withHeaders,
                     const string &key)
{
    file csvFile;

    if (! csvFile.openread (filename))
        return false;

    value headerNames;
    int rowc, colc;
    int numColumns;
    bool withKey;
    int keyPos;
    value columnSplit;
    string row;

    clear();
    if (key.strlen()) withKey = true;
    else withKey = false;

    keyPos = 0;

    if (csvFile.eof())
    {
        csvFile.close();
        return false;
    }

    numColumns = 0;

    if (withHeaders)
    {
        row = csvFile.gets();
        __csv_breakme();
        columnSplit = strutil::splitcsv(row);
        numColumns = columnSplit.count();
        if (! numColumns)
        {
            csvFile.close();
            return false;
        }

        for (colc=0; colc<numColumns; ++colc)
        {
            if (withKey && (columnSplit[colc].sval() == key))
            {
                keyPos = colc;
            }
            headerNames.newval() = columnSplit[colc].sval();
        }
    }
    try
    {
        while (! csvFile.eof())
        {
            row = csvFile.gets();
            if (row.strlen())
            {
                columnSplit = strutil::splitcsv (row);

                if (withKey)
                {
                    (*this)[columnSplit[keyPos].sval()].type ("row");
                }
                else
                {
                    newval("row");
                }

                for (colc=0; colc<numColumns; ++colc)
                {
                    if (withHeaders)
                    {
                        if (colc != keyPos)
                        {
                            (*this)[-1][headerNames[colc].sval()] =
                                columnSplit[colc];
                        }
                    }
                    else
                    {
                        (*this)[-1].newval() = columnSplit[colc];
                    }
                }
            }
        }
    }
    catch (...)
    {
    }
    csvFile.close();
    return true;
}
Beispiel #8
0
// ========================================================================
// METHOD ::fromcsv
// ----------------
// Converts a string containing CSV format data to a two-dimensional array
// of values.
// ========================================================================
bool value::fromcsv (const string &csvData, bool withHeaders,
                     const string &key)
{
    value headerNames;
    int rowc, colc;
    bool withKey;
    int keyPos;
    int numColumns, numRows;
    value rowSplit;
    value columnSplit;
    string row;

    if (key.strlen()) withKey = true;
    else withKey = false;
    keyPos = 0;

    clear();

    rowSplit = strutil::splitlines (csvData);
    rowc = 0;
    numRows = rowSplit.count();
    numColumns = 0;

    if (! numRows) return false;

    if (withHeaders)
    {
        row = rowSplit[0].sval();
        columnSplit = strutil::splitcsv (row);
        numColumns = columnSplit.count();
        if (! numColumns) return false;

        for (colc=0; colc<numColumns; ++colc)
        {
            headerNames.newval() = columnSplit[colc].sval();
            if (headerNames[-1].sval() == key)
            {
                keyPos = colc;
            }
        }
        ++rowc;
    }
    for (; rowc<numRows; ++rowc)
    {
        row = rowSplit[rowc].sval();

        if (row.strlen())
        {
            columnSplit = strutil::splitquoted (row, ',');

            if (withKey)
            {
                (*this)[columnSplit[keyPos].sval()].type ("row");
            }
            else
            {
                newval("row");
            }
            for (colc=0; colc<numColumns; ++colc)
            {
                if (withHeaders)
                {
                    (*this)[-1][headerNames[colc].sval()] =
                        columnSplit[colc];
                }
                else
                {
                    (*this)[-1].newval() = columnSplit[colc];
                }
            }
        }
    }
    return true;
}