Here you can find the source of interpolateNonZeroValues(double[] contour)
Parameter | Description |
---|---|
contour | contour |
public static double[] interpolateNonZeroValues(double[] contour)
//package com.java2s; /**/*from w w w . j a v a 2 s.c o m*/ * Copyright 2004-2006 DFKI GmbH. * All Rights Reserved. Use is subject to license terms. * * This file is part of MARY TTS. * * MARY TTS is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ public class Main { /** * To interpolate Zero values with respect to NonZero values * * @param contour * contour * @return contour */ public static double[] interpolateNonZeroValues(double[] contour) { for (int i = 0; i < contour.length; i++) { if (contour[i] == 0) { int index = findNextIndexNonZero(contour, i); // System.out.println("i: "+i+"index: "+index); if (index == -1) { for (int j = (i == 0 ? 1 : i); j < contour.length; j++) { contour[j] = contour[j - 1]; } break; } else { for (int j = i; j < index; j++) { // contour[j] = contour[i-1] * (index - j) + contour[index] * (j - (i-1)) / ( index - i ); if (i == 0) { contour[j] = contour[index]; } else { contour[j] = contour[j - 1] + ((contour[index] - contour[i - 1]) / (index - i + 1)); } } i = index - 1; } } } return contour; } /** * To find next NonZero index in a given array * * @param contour * contour * @param current * current * @return -1 */ public static int findNextIndexNonZero(double[] contour, int current) { for (int i = current + 1; i < contour.length; i++) { if (contour[i] != 0) { return i; } } return -1; } }