//DTW calculation between two vectors. one is query and other Data sequence double simpleDTW(const std::vector<double>& t1, const std::vector<double>& t2) { // std::cout << "t1" << std::endl; // for (int k=0; k< t1.size(); k++) { // std::cout << t1[k] << " "; // } // std::cout << std::endl << "t2" << std::endl; // for (int l=0; l< t2.size(); l++ ) { // std::cout << t2[l] << " "; // } // std::cout << std::endl << std::endl; int m = t1.size(); int n = t2.size(); // create cost matrix double cost[m][n]; cost[0][0] = distFunc(t1[0], t2[0]); // calculate first row for(int i = 1; i < m; i++) { cost[i][0] = cost[i-1][0] + distFunc(t1[i], t2[0]); } // calculate first column for(int j = 1; j < n; j++) { cost[0][j] = cost[0][j-1] + distFunc(t1[0], t2[j]); } // fill matrix for(int i = 1; i < m; i++) { for(int j = 1; j < n; j++) { cost[i][j] = distFunc(t1[i],t2[j])+ std::min(cost[i-1][j],std::min(cost[i][j-1], cost[i-1][j-1])); } } // std::cout << "dist: " << cost[m-1][n-1] << std::endl; return cost[m-1][n-1]; }
/// Snap `pos` to the perceptually closest piece of visible geometry /// /// `normalScaling` - Distance along the camera direction will be scaled by /// this factor when computing the closest point. /// `newPos` - Returned new position /// `pointInfo` - Returned descriptive string of point attributes. /// Ignored if null. /// /// Returns true if a close piece of geometry was found, false otherwise. bool View3D::snapToGeometry(const Imath::V3d& pos, double normalScaling, Imath::V3d* newPos, QString* pointInfo) { // Ray out from the camera to the given point V3d cameraPos = m_camera.position(); V3d viewDir = (pos - cameraPos).normalized(); EllipticalDist distFunc(pos, viewDir, normalScaling); double nearestDist = DBL_MAX; // Snap cursor to position of closest point and center on it QModelIndexList sel = m_selectionModel->selectedRows(); for (int i = 0; i < sel.size(); ++i) { int geomIdx = sel[i].row(); V3d pickedVertex; double dist = 0; std::string info; if(m_geometries->get()[geomIdx]->pickVertex(cameraPos, distFunc, pickedVertex, &dist, (pointInfo != 0) ? &info : 0)) { if (dist < nearestDist) { *newPos = pickedVertex; nearestDist = dist; if (pointInfo) *pointInfo = QString::fromStdString(info); } } } return nearestDist < DBL_MAX; }
float HClustering<Pt>::getDistance(unsigned i, unsigned j, Pt *p_data) { static Pt *data = NULL; if (data == NULL) { // data must be initialized before getDistance is called with p_data being NULL. assert(p_data != NULL); data = p_data; } return distFunc(data[i], data[j]); }
bool distributor::distribute(MVar *arg0, MVar *arg1, MVar *arg2, MVar *arg3, std::string &func, int nr) { numCplx z; numReal d; bool res = false; if (nr == 1) { //if (charac->isZero()) { res = intDist(arg0,func); if (!res) { res = algCplxDist(arg0,func); } if (!res) { res = numRealDist(arg0,func); } if (!res) { res = numFuncDist(arg0,func); } if(arg0->getType()==DISTDAT) { DistDat dd; numReal nr; arg0->getDistDat(&dd); res = dd.prop(combiC,nr,func); if (res) { arg0->setNumReal(nr); } else { validC->setErr(ERRPROPDIST,dd.name); } } if (!res && func == "derivative") { Function f,g; if (arg0->getFunction(&f)){ if (derivative(g,f)) { arg0->setFunction(g); res = true; } else validC->setErr(NOTDIFFBAR); } } if (!res) { res = calcDist(arg0,func); } /*} else { if (!res && !charac->isZero()) { res = restDist(arg0,func); } }*/ if (!res) { res = matrixDist(arg0,func); } } else if (nr == 2) { //if (charac->isZero()) { res = twoIntDist(arg0,arg1,func); if (!res) { res = doubleIntDist(arg0,arg1,func); } if (!res) { res = tempDist(arg0,arg1,func); } if (!res) { res = doubleDoubleDist(arg0,arg1,func); } if (!res) { res = funcDoubleDist(arg0,arg1,func); } if (!res) { res = CplxCplxDist(arg0,arg1,func); } if (!res) { res = euklidDist(arg0,arg1,func); } if(arg0->getType()==DISTDAT) { DistDat dd; arg0->getDistDat(&dd); res = distFunc(dd,*arg1,func); *arg0 = *arg1; } /*} else { if (!res && (arg0->getType()==RESTPOLY || arg1->getType()==RESTPOLY)) { res = twoRestPolyDist(arg0,arg1,func); } if (!res) { res = restRestDist(arg0,arg1,func); } }*/ if (!res) { res = matrixDist(arg0,arg1,func); } if (!res) { res = matrixMatrixDist(arg0,arg1,func); } } else if (nr == 3) { /*MaceInt mi; if (func == "IF") { if (arg0->getInt(&mi)) { res = true; if (!mi.isZero()) *arg0 = *arg1; else *arg0 = *arg2; } else { validC->setErr(NOTBOOL,"IF"); } } if (!res) { res = dbldbldblDist(arg0,arg1,arg2,func); } if (!res) { res = matrixIntIntDist(arg0,arg1,arg2,func); } if (!res) { res = funcDblDblDist(arg0,arg1,arg2,func); }*/ } if (nr == 4) { /*res = matrixIntIntCplxDist(arg0,arg1,arg2,arg3,func); if (func == "spHarm") { if (*function) validC->setErr(CPLX,func); MaceInt mi0, mi1; numCplx resC; numReal nr0, nr1; double theta, phi; unsigned int m, n; if (arg0->getNumReal(&nr0) && arg1->getNumReal(&nr1)) { phi = nr0.get(); theta = nr1.get(); if (arg2->getInt(&mi0) && arg3->getInt(&mi1)) { clInt(mi0,m); clInt(mi1,n); resC.val.real() = boost::math::spherical_harmonic_r(n,m,theta,phi); resC.val.imag() = boost::math::spherical_harmonic_i(n,m,theta,phi); arg0->setNumCplx(resC); } else validC->setErr(NOTIR,"spHarm"); } else validC->setErr(NOTIR,"spHarm"); res = true; }*/ } if (!res) { combiCalc::dist dist; bool withInt; int vars; combiC.findDist(&withInt, func, dist, vars); if (dist != combiCalc::NONE && vars == nr) { DistDat dd; dd.name = func; if (distdist(arg0,arg1,arg2,dd,dist,nr,withInt)) { arg0->setDistDat(dd); } else { validC->setErr(ERRDIST,dd.name); } res = true; } } return res; }