/*! Calcola gli AlgorithmPointI sulla base di points, verificando di punto in punto lo step tra ascissa e ordinata; inserisce i punti calcolati in gPoints e in base alla quntita' di AlgorithmPointI trovati restituisce true(e' possibile interpolare) o false(non e' possibile). \param points Vettore di T3DPoints */ bool interpolate(const std::vector<T3DPointD> &points) { unsigned int curr, next; TPointI currStep, xStep, yStep, guideLine; TPointI xUnit(1, 0); TPointI yUnit(0, 1); bool chooseByDistance = false; curr = 0; next = 1; //int i = points.size(); while (next <= points.size() - 1) { if (points[next] != points[curr]) { gPoints.push_back(AlgorithmPointI(points[curr], curr)); guideLine = TPointI((int)(points[curr].x - points[next].x), (int)(points[curr].y - points[next].y)); currStep = gPoints.back(); double xStepTheta, yStepTheta; //TPointI a; while (norm2(TPointI((int)(points[next].x - currStep.x), (int)(points[next].y - currStep.y))) > 1) { TPointI nextPoint = TPointI((int)points[next].x, (int)points[next].y); //TPointI a = nextPoint - currStep; //int i = 0; if (currStep.x > nextPoint.x) xStep = currStep - xUnit; else if (currStep.x < nextPoint.x) xStep = currStep + xUnit; else { xStep = currStep; chooseByDistance = true; } if (currStep.y > nextPoint.y) yStep = currStep - yUnit; else if (currStep.y < nextPoint.y) yStep = currStep + yUnit; else { yStep = currStep; chooseByDistance = true; } if (chooseByDistance) { chooseByDistance = false; if (norm2(xStep - nextPoint) < norm2(yStep - nextPoint)) currStep = xStep; else currStep = yStep; } else { double aux = norm2(guideLine); xStepTheta = acos( (xStep - nextPoint) * guideLine / (sqrt(norm2(xStep - nextPoint) * aux))); yStepTheta = acos( (yStep - nextPoint) * guideLine / (sqrt(norm2(yStep - nextPoint) * aux))); if (xStepTheta > yStepTheta) currStep = yStep; else currStep = xStep; } gPoints.push_back(AlgorithmPointI(currStep, next)); } } curr++; next++; } gPoints.push_back(AlgorithmPointI(points[curr], curr)); if ((int)gPoints.size() < (2 * gMaxDist + 1)) return false; return true; }