Пример #1
0
void Spectrum_drawLogFreq (Spectrum me, Graphics g, double fmin, double fmax, double minimum, double maximum, int garnish) {
	int autoscaling = minimum >= maximum;
	if (fmax <= fmin) { fmin = my xmin; fmax = my xmax; }
	long ifmin, ifmax;
	if (! Matrix_getWindowSamplesX (me, fmin, fmax, & ifmin, & ifmax)) return;
if(ifmin==1)ifmin=2;  /* BUG */
	autoNUMvector <double> xWC (ifmin, ifmax);
	autoNUMvector <double> yWC (ifmin, ifmax);

	/*
	 * First pass: compute power density.
	 */
	if (autoscaling) maximum = -1e6;
	for (long ifreq = ifmin; ifreq <= ifmax; ifreq ++) {
		xWC [ifreq] = log10 (my x1 + (ifreq - 1) * my dx);
		yWC [ifreq] = my v_getValueAtSample (ifreq, 0, 2);
		if (autoscaling && yWC [ifreq] > maximum) maximum = yWC [ifreq];
	}
	if (autoscaling) minimum = maximum - 60;   /* Default dynamic range is 60 dB. */

	/*
	 * Second pass: clip.
	 */
	for (long ifreq = ifmin; ifreq <= ifmax; ifreq ++) {
		if (yWC [ifreq] < minimum) yWC [ifreq] = minimum;
		else if (yWC [ifreq] > maximum) yWC [ifreq] = maximum;
	}

	Graphics_setInner (g);
	Graphics_setWindow (g, log10 (fmin), log10 (fmax), minimum, maximum);
	Graphics_polyline (g, ifmax - ifmin + 1, & xWC [ifmin], & yWC [ifmin]);
	Graphics_unsetInner (g);
	if (garnish) {
		Graphics_drawInnerBox (g);
		Graphics_textBottom (g, 1, L"Frequency (Hz)");
		Graphics_marksBottomLogarithmic (g, 3, TRUE, TRUE, FALSE);
		Graphics_textLeft (g, 1, L"Sound pressure level (dB/Hz)");
		Graphics_marksLeftEvery (g, 1.0, 20.0, TRUE, TRUE, FALSE);
	}
}
Пример #2
0
void ParamCurve_draw (ParamCurve me, Graphics g, double t1, double t2, double dt,
	double x1, double x2, double y1, double y2, int garnish)
{
	if (t2 <= t1) {
		double tx1 = my x -> x1;
		double ty1 = my y -> x1;
		double tx2 = my x -> x1 + (my x -> nx - 1) * my x -> dx;
		double ty2 = my y -> x1 + (my y -> nx - 1) * my y -> dx;
		t1 = tx1 > ty1 ? tx1 : ty1;
		t2 = tx2 < ty2 ? tx2 : ty2;
	}
	if (x2 <= x1) Matrix_getWindowExtrema (my x, 0, 0, 1, 1, & x1, & x2);
	if (x1 == x2) { x1 -= 1.0; x2 += 1.0; }
	if (y2 <= y1) Matrix_getWindowExtrema (my y, 0, 0, 1, 1, & y1, & y2);
	if (y1 == y2) { y1 -= 1.0; y2 += 1.0; }
	if (dt <= 0.0)
		dt = my x -> dx < my y -> dx ? my x -> dx : my y -> dx;
	long numberOfPoints = (long) ceil ((t2 - t1) / dt) + 1;
	if (numberOfPoints > 0) {
		autoNUMvector <double> x (1, numberOfPoints);
		autoNUMvector <double> y (1, numberOfPoints);
		for (long i = 1; i <= numberOfPoints; i ++) {
			double t = i == numberOfPoints ? t2 : t1 + (i - 1) * dt;
			double index = my x -> f_xToIndex (t);
			x [i] = NUM_interpolate_sinc (my x -> z [1], my x -> nx, index, 50);
			index = my y -> f_xToIndex (t);
			y [i] = NUM_interpolate_sinc (my y -> z [1], my y -> nx, index, 50);
		}
		Graphics_setWindow (g, x1, x2, y1, y2);
		Graphics_setInner (g);
		Graphics_polyline (g, numberOfPoints, & x [1], & y [1]);
		Graphics_unsetInner (g);
	}
	if (garnish) {
		Graphics_drawInnerBox (g);
		Graphics_marksBottom (g, 2, 1, 1, 0);
		Graphics_marksLeft (g, 2, 1, 1, 0);
	}
}
Пример #3
0
void Artword_draw (Artword me, Graphics g, int feature, bool garnish) {
	long numberOfTargets = my data [feature]. numberOfTargets;
	if (numberOfTargets > 0) {
		autoNUMvector <double> x (1, numberOfTargets);
		autoNUMvector <double> y (1, numberOfTargets);
		Graphics_setInner (g);
		Graphics_setWindow (g, 0, my totalTime, -1.0, 1.0);
		for (int i = 1; i <= numberOfTargets; i ++) {
			x [i] = my data [feature]. times [i];
			y [i] = my data [feature]. targets [i];
		}
		Graphics_polyline (g, numberOfTargets, & x [1], & y [1]);         
		Graphics_unsetInner (g);
	}

	if (garnish) {
		Graphics_drawInnerBox (g);
		Graphics_marksBottom (g, 2, true, true, false);
		Graphics_marksLeft (g, 3, true, true, true);
		Graphics_textTop (g, false, kArt_muscle_getText (feature));
		Graphics_textBottom (g, true, U"Time (s)");
	}
}
Пример #4
0
static void Polygon_drawInside (Polygon me, Graphics g) {
	Graphics_polyline (g, my numberOfPoints, & my x[1], & my y[1]);
}
Пример #5
0
void Polygon_draw (Polygon me, Graphics g, double xmin, double xmax, double ymin, double ymax) {
	Graphics_setInner (g);
	setWindow (me, g, xmin, xmax, ymin, ymax);
	Graphics_polyline (g, my numberOfPoints, & my x [1], & my y [1]);
	Graphics_unsetInner (g);
}
Пример #6
0
void Graphics_surface (Graphics me, double **z,
                       long ix1, long ix2, double x1, double x2,
                       long iy1, long iy2, double y1, double y2,
                       double minimum, double maximum,
                       double elevation, double azimuth)
{
    double dx, dy;

    /* 'sum' is the running sum of the x and y indices of the back corner of each tetragon.
     * The x and y indices of the back corner of the backmost tetragon are ix2 and iy2,
     * The x and y indices of the front corner of the frontmost tetragon are ix1 and iy1,
     * so that the x and y indices of its back corner are ix1 + 1 and iy1 + 1.
     */
    long maxsum = ix2 + iy2, minsum = (ix1 + 1) + (iy1 + 1), sum;
    (void) elevation;   /* BUG */
    (void) azimuth;   /* BUG */
    if (ix2 <= ix1 || iy2 <= iy1) return;
    dx = (x2 - x1) / (ix2 - ix1);
    dy = (y2 - y1) / (iy2 - iy1);

    /* We start at the back of the surface plot.
     * This part of the picture may be overdrawn by points more forward.
     */
    for (sum = maxsum; sum >= minsum; sum --) {

        /* We are going to cycle over a diagonal sequence of points.
         * Compute the row boundaries of this sequence.
         */
        long iymin = iy1 + 1, iymax = iy2, iy;
        if (iymin < sum - ix2) iymin = sum - ix2;
        if (iymax > sum - (ix1 + 1)) iymax = sum - (ix1 + 1);
        for (iy = iymin; iy <= iymax; iy ++) {

            /* Compute the indices of all four points.
             */
            long ix = sum - iy;
            long ixback = ix, ixfront = ix - 1, ixleft = ix - 1, ixright = ix;
            long iyback = iy, iyfront = iy - 1, iyleft = iy, iyright = iy - 1;

            /* Compute the world coordinates of all four points.
             */
            double xback = x1 + (ixback - ix1) * dx, xright = xback;
            double xfront = x1 + (ixfront - ix1) * dx, xleft = xfront;
            double yback = y1 + (iyback - iy1) * dy, yleft = yback;
            double yfront = y1 + (iyfront - iy1) * dy, yright = yfront;
            double zback = z [iyback] [ixback], zfront = z [iyfront] [ixfront];
            double zleft = z [iyleft] [ixleft], zright = z [iyright] [ixright];

            /* The Graphics library uses a two-dimensional world, so we have to convert
             * to 2-D world coordinates, which we call x [0..3] and y [0..3].
             * We suppose that world coordinate "x" = 0 is in the centre of the figure,
             * and that the left and right borders of the figure have world coordinates -1 and +1.
             * Also, we suppose that the bottom and top are around 'minimum' and 'maximum'.
             */
            double x [5], y [5];

            /* Elevation and azimuth fixed???
             */
            double up = 0.3 * (maximum - minimum), xscale = 1 / (x2 - x1), yscale = 1 / (y2 - y1);

            /* The back point.
             */
            x [0] = (xback - x1) * xscale - (yback - y1) * yscale;
            y [0] = up * ((xback - x1) * xscale + (yback - y1) * yscale) + zback;

            /* The right point.
             */
            x [1] = (xright - x1) * xscale - (yright - y1) * yscale;
            y [1] = up * ((xright - x1) * xscale + (yright - y1) * yscale) + zright;

            /* The front point.
             */
            x [2] = (xfront - x1) * xscale - (yfront - y1) * yscale;
            y [2] = up * ((xfront - x1) * xscale + (yfront - y1) * yscale) + zfront;

            /* The left point.
             */
            x [3] = (xleft - x1) * xscale - (yleft - y1) * yscale;
            y [3] = up * ((xleft - x1) * xscale + (yleft - y1) * yscale) + zleft;

            /* Paint the tetragon in the average grey value, white at the top.
             * This gives the idea of height.
             */
            Graphics_setGrey (me, (0.25 * (zback + zright + zfront + zleft) - minimum) / (maximum - minimum));
            Graphics_fillArea (me, 4, & x [0], & y [0]);

            /* Draw the borders of the tetragon in black.
             * This gives the idea of steepness and viewing angle.
             */
            Graphics_setGrey (me, 0);
            x [4] = x [0];
            y [4] = y [0];   /* Close polygon. */
            Graphics_polyline (me, 5, & x [0], & y [0]);
        }
    }
}
void Sampled_drawInside (Sampled me, Graphics g, double xmin, double xmax, double ymin, double ymax,
	double speckle_mm, long ilevel, int unit)
{
	try {
		if (speckle_mm != 0.0) {
			Sampled_speckleInside (me, g, xmin, xmax, ymin, ymax, speckle_mm, ilevel, unit);
			return;
		}
		Function_unidirectionalAutowindow (me, & xmin, & xmax);
		long ixmin, ixmax, startOfDefinedStretch = -1;
		Sampled_getWindowSamples (me, xmin, xmax, & ixmin, & ixmax);
		if (Function_isUnitLogarithmic (me, ilevel, unit)) {
			ymin = Function_convertStandardToSpecialUnit (me, ymin, ilevel, unit);
			ymax = Function_convertStandardToSpecialUnit (me, ymax, ilevel, unit);
		}
		if (ymax <= ymin) return;
		Graphics_setWindow (g, xmin, xmax, ymin, ymax);
		autoNUMvector <double> xarray (ixmin - 1, ixmax + 1);
		autoNUMvector <double> yarray (ixmin - 1, ixmax + 1);
		double previousValue = Sampled_getValueAtSample (me, ixmin - 1, ilevel, unit);
		if (NUMdefined (previousValue)) {
			startOfDefinedStretch = ixmin - 1;
			xarray [ixmin - 1] = Sampled_indexToX (me, ixmin - 1);
			yarray [ixmin - 1] = previousValue;
		}
		for (long ix = ixmin; ix <= ixmax; ix ++) {
			double x = Sampled_indexToX (me, ix), value = Sampled_getValueAtSample (me, ix, ilevel, unit);
			if (NUMdefined (value)) {
				if (NUMdefined (previousValue)) {
					xarray [ix] = x;
					yarray [ix] = value;
				} else {
					startOfDefinedStretch = ix - 1;
					xarray [ix - 1] = x - 0.5 * my dx;
					yarray [ix - 1] = value;
					xarray [ix] = x;
					yarray [ix] = value;
				}
			} else if (NUMdefined (previousValue)) {
				Melder_assert (startOfDefinedStretch >= ixmin - 1);
				if (ix > ixmin) {
					xarray [ix] = x - 0.5 * my dx;
					yarray [ix] = previousValue;
					if (xarray [startOfDefinedStretch] < xmin) {
						double phase = (xmin - xarray [startOfDefinedStretch]) / my dx;
						xarray [startOfDefinedStretch] = xmin;
						yarray [startOfDefinedStretch] = phase * yarray [startOfDefinedStretch + 1] + (1.0 - phase) * yarray [startOfDefinedStretch];
					}
					Graphics_polyline (g, ix + 1 - startOfDefinedStretch, & xarray [startOfDefinedStretch], & yarray [startOfDefinedStretch]);
				}
				startOfDefinedStretch = -1;
			}
			previousValue = value;
		}
		if (startOfDefinedStretch > -1) {
			double x = Sampled_indexToX (me, ixmax + 1), value = Sampled_getValueAtSample (me, ixmax + 1, ilevel, unit);
			Melder_assert (NUMdefined (previousValue));
			if (NUMdefined (value)) {
				xarray [ixmax + 1] = x;
				yarray [ixmax + 1] = value;
			} else {
				xarray [ixmax + 1] = x - 0.5 * my dx;
				yarray [ixmax + 1] = previousValue;
			}
			if (xarray [startOfDefinedStretch] < xmin) {
				double phase = (xmin - xarray [startOfDefinedStretch]) / my dx;
				xarray [startOfDefinedStretch] = xmin;
				yarray [startOfDefinedStretch] = phase * yarray [startOfDefinedStretch + 1] + (1.0 - phase) * yarray [startOfDefinedStretch];
			}
			if (xarray [ixmax + 1] > xmax) {
				double phase = (xarray [ixmax + 1] - xmax) / my dx;
				xarray [ixmax + 1] = xmax;
				yarray [ixmax + 1] = phase * yarray [ixmax] + (1.0 - phase) * yarray [ixmax + 1];
			}
			Graphics_polyline (g, ixmax + 2 - startOfDefinedStretch, & xarray [startOfDefinedStretch], & yarray [startOfDefinedStretch]);
		}
	} catch (MelderError) {
		Melder_clearError ();
	}
}