AMBeamConfigurationWizard::AMBeamConfigurationWizard(QWidget* parent)
	: AMGraphicsViewWizard(parent)
{
	/// two points for each square, three squares.
	setNumberOfPoints(6);
	setNumberOfPages(numberOfPoints());
	setFreePage(Page_Free);

	setRotationEnabled(false);

	setPage(Page_Intro, new AMWizardPage);
	setPage(Page_Final, new AMWizardPage);
	setPage(Page_Option, new AMWizardOptionPage);
	for(int i = 0; i < numberOfPages(); i++)
	{
		setPage(pageWait(i), new AMBeamWaitPage);
		/* kind of a dirty hack here, but this makes the
		   wait logic cleaner */
		if(i < 3)
			setPage(pageSet(i), new AMBeamCheckPage);
		else
			setPage(pageSet(i), new AMBeamSelectPage);
	}
	setStartId(Page_Intro);
	setOption(HaveHelpButton, true);
	connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));
	setWindowTitle(message(Wizard_Title));
	/* have to disconnect/connect the buttons to get them to work with the new slots */
	disconnect(button(QWizard::BackButton), SIGNAL(clicked()), this, SLOT(back()));
	connect(button(QWizard::BackButton), SIGNAL(clicked()), this, SLOT(back()));
	disconnect(button(QWizard::NextButton), SIGNAL(clicked()), this, SLOT(next()));
	connect(button(QWizard::NextButton), SIGNAL(clicked()), this, SLOT(next()));

	setMinimumSize(600,600);

	setting_ = false;
	reviewBeamShape_ = true;




	for(int i = 0; i < numberOfPoints(); i++)
	{
		pointListAppend(new QPointF(0,0));
	}

	topLeft_ = true;

	coordinateListAppend(new QVector3D(0,0,0));
	coordinateListAppend(new QVector3D(0,-1,0));
	coordinateListAppend(new QVector3D(0,1,0));
	coordinateListAppend(new QVector3D(0,0,0));
	coordinateListAppend(new QVector3D(0,-1,0));
	coordinateListAppend(new QVector3D(0,1,0));


	addOptionPage(Page_Intro);

}
Esempio n. 2
0
void DrawingPolylineItem::render(QPainter* painter, const DrawingStyleOptions& styleOptions)
{
	DrawingItemPoint* point0 = point(0);
	DrawingItemPoint* point1 = point(numberOfPoints() - 1);
	QList<DrawingItemPoint*> lPoints = points();
	QPolygonF polygon;
	DrawingItemPoint* otherPoint;
	qreal theta;

	// Polyline
	for(auto pointIter = lPoints.begin(); pointIter != lPoints.end(); pointIter++)
		polygon.append((*pointIter)->pos());

	setupPainter(painter, styleOptions, pen());
	painter->drawPolyline(polygon);

	// Arrows
	if (pen().style() != Qt::NoPen)
	{
		QPen arrowPen = pen();
		arrowPen.setStyle(Qt::SolidLine);
		setupPainter(painter, styleOptions, arrowPen, styleOptions.outputBrush(DrawingStyleOptions::Background));

		otherPoint = point(1);
		if (otherPoint)
		{
			theta = qAtan2(otherPoint->y() - point0->y(),
				otherPoint->x() - point0->x()) * 180.0 / 3.1414592654;

			if (Drawing::magnitude(otherPoint->pos() - point0->pos()) > startArrowSize())
				startArrow().render(painter, point0->pos(), theta);
		}

		otherPoint = point(numberOfPoints() - 2);
		if (otherPoint)
		{
			theta = qAtan2(otherPoint->y() - point1->y(),
				otherPoint->x() - point1->x()) * 180.0 / 3.1414592654;

			if (Drawing::magnitude(otherPoint->pos() - point1->pos()) > endArrowSize())
				endArrow().render(painter, point1->pos(), theta);
		}
	}

#ifdef DEBUG_DRAW_ITEM_SHAPE
	painter->setBrush(Qt::magenta);
	painter->setPen(QPen(Qt::magenta, 1));
	painter->drawPath(shape());
#endif
}
Esempio n. 3
0
TableOfReal RealTier_downto_TableOfReal (RealTier me, const char32 *timeLabel, const char32 *valueLabel) {
	try {
		autoTableOfReal thee = TableOfReal_create (my numberOfPoints (), 2);
		TableOfReal_setColumnLabel (thee.peek(), 1, timeLabel);
		TableOfReal_setColumnLabel (thee.peek(), 2, valueLabel);
		for (long i = 1; i <= my numberOfPoints (); i ++) {
			RealPoint point = my point (i);
			thy data [i] [1] = point -> number;
			thy data [i] [2] = point -> value;
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, U": not converted to TableOfReal.");
	}
}
Esempio n. 4
0
void structRealTier :: v_shiftX (double xfrom, double xto) {
	RealTier_Parent :: v_shiftX (xfrom, xto);
	for (long i = 1; i <= our numberOfPoints (); i ++) {
		RealPoint point = our point (i);
		NUMshift (& point -> number, xfrom, xto);
	}
}
Esempio n. 5
0
void structRealTier :: v_scaleX (double xminfrom, double xmaxfrom, double xminto, double xmaxto) {
	RealTier_Parent :: v_scaleX (xminfrom, xmaxfrom, xminto, xmaxto);
	for (long i = 1; i <= our numberOfPoints (); i ++) {
		RealPoint point = our point (i);
		NUMscale (& point -> number, xminfrom, xmaxfrom, xminto, xmaxto);
	}
}
Esempio n. 6
0
double RealTier_getArea (RealTier me, double tmin, double tmax) {
	long n = my numberOfPoints (), imin, imax;
	RealPoint *points = my peekPoints ();
	if (n == 0) return NUMundefined;
	if (n == 1) return (tmax - tmin) * points [1] -> value;
	imin = AnyTier_timeToLowIndex (me, tmin);
	if (imin == n) return (tmax - tmin) * points [n] -> value;
	imax = AnyTier_timeToHighIndex (me, tmax);
	if (imax == 1) return (tmax - tmin) * points [1] -> value;
	Melder_assert (imin < n);
	Melder_assert (imax > 1);
	/*
	 * Sum the areas between the points.
	 * This works even if imin is 0 (offleft) and/or imax is n + 1 (offright).
	 */
	double area = 0.0;
	for (long i = imin; i < imax; i ++) {
		double tleft, fleft, tright, fright;
		if (i == imin) tleft = tmin, fleft = RealTier_getValueAtTime (me, tmin);
		else tleft = points [i] -> number, fleft = points [i] -> value;
		if (i + 1 == imax) tright = tmax, fright = RealTier_getValueAtTime (me, tmax);
		else tright = points [i + 1] -> number, fright = points [i + 1] -> value;
		area += 0.5 * (fleft + fright) * (tright - tleft);
	}
	return area;
}
Esempio n. 7
0
void RealTier_removePointsBelow (RealTier me, double level) {
	for (long ipoint = my numberOfPoints (); ipoint > 0; ipoint --) {
		RealPoint point = my point (ipoint);
		if (point -> value < level) {
			AnyTier_removePoint (me, ipoint);
		}
	}
}
Esempio n. 8
0
void RealTier_multiplyPart (RealTier me, double tmin, double tmax, double factor) {
	for (long ipoint = 1; ipoint <= my numberOfPoints (); ipoint ++) {
		RealPoint point = my point (ipoint);
		double t = point -> number;
		if (t >= tmin && t <= tmax) {
			point -> value *= factor;
		}
	}
}
/// Normalize residuals by subtracting the average value from each cell, so that
/// the sum is 0 afterwards.
void PoldiAnalyseResiduals::normalizeResiduals(
    DataObjects::Workspace2D_sptr &residuals,
    const std::vector<int> &validWorkspaceIndices) {
  double sumOfResiduals = sumCounts(residuals, validWorkspaceIndices);
  double dataPointCount =
      static_cast<double>(numberOfPoints(residuals, validWorkspaceIndices));

  addValue(residuals, -sumOfResiduals / dataPointCount, validWorkspaceIndices);
}
Esempio n. 10
0
double RealTier_getMinimumValue (RealTier me) {
	double result = NUMundefined;
	long n = my numberOfPoints ();
	for (long i = 1; i <= n; i ++) {
		RealPoint point = my point (i);
		if (result == NUMundefined || point -> value < result)
			result = point -> value;
	}
	return result;
}
Esempio n. 11
0
double RealTier_getMean_points (RealTier me, double tmin, double tmax) {
	long n = my numberOfPoints (), imin, imax;
	double sum = 0.0;
	RealPoint *points = my peekPoints ();
	if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; }   // autowindow
	n = AnyTier_getWindowPoints (me, tmin, tmax, & imin, & imax);
	if (n == 0) return NUMundefined;
	for (long i = imin; i <= imax; i ++)
		sum += points [i] -> value;
	return sum / n;
}
Esempio n. 12
0
Table RealTier_downto_Table (RealTier me, const char32 *indexText, const char32 *timeText, const char32 *valueText) {
	try {
		autoTable thee = Table_createWithoutColumnNames (my numberOfPoints (),
			(indexText != NULL) + (timeText != NULL) + (valueText != NULL));
		long icol = 0;
		if (indexText != NULL) Table_setColumnLabel (thee.peek(), ++ icol, indexText);
		if (timeText  != NULL) Table_setColumnLabel (thee.peek(), ++ icol, timeText);
		if (valueText != NULL) Table_setColumnLabel (thee.peek(), ++ icol, valueText);
		for (long ipoint = 1; ipoint <= my numberOfPoints (); ipoint ++) {
			RealPoint point = my point (ipoint);
			icol = 0;
			if (indexText != NULL) Table_setNumericValue (thee.peek(), ipoint, ++ icol, ipoint);
			if (timeText != NULL)  Table_setNumericValue (thee.peek(), ipoint, ++ icol, point -> number);
			if (valueText != NULL) Table_setNumericValue (thee.peek(), ipoint, ++ icol, point -> value);
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, U": not converted to Table.");
	}
}
Esempio n. 13
0
autoAmplitudeTier IntensityTier_to_AmplitudeTier (IntensityTier me) {
	try {
		autoAmplitudeTier thee = Thing_new (AmplitudeTier);
		my structRealTier :: v_copy (thee.peek());
		for (long i = 1; i <= thy numberOfPoints(); i ++) {
			RealPoint point = thy point (i);
			point -> value = pow (10.0, point -> value / 20.0) * 2.0e-5;
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted to AmplitudeTier.");
	}
}
Esempio n. 14
0
double RealTier_getStandardDeviation_points (RealTier me, double tmin, double tmax) {
	long n = my numberOfPoints (), imin, imax;
	double mean, sum = 0.0;
	RealPoint *points = my peekPoints ();
	if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; }   // autowindow
	n = AnyTier_getWindowPoints (me, tmin, tmax, & imin, & imax);
	if (n < 2) return NUMundefined;
	mean = RealTier_getMean_points (me, tmin, tmax);
	for (long i = imin; i <= imax; i ++) {
		double diff = points [i] -> value - mean;
		sum += diff * diff;
	}
	return sqrt (sum / (n - 1));
}
Esempio n. 15
0
void RealTier_formula (RealTier me, const char32 *expression, Interpreter interpreter, RealTier thee) {
	try {
		Formula_compile (interpreter, me, expression, kFormula_EXPRESSION_TYPE_NUMERIC, true);
		if (thee == NULL) thee = me;
		for (long icol = 1; icol <= my numberOfPoints (); icol ++) {
			struct Formula_Result result;
			Formula_run (0, icol, & result);
			if (result. result.numericResult == NUMundefined)
				Melder_throw (U"Cannot put an undefined value into the tier.");
			thy point (icol) -> value = result. result.numericResult;
		}
	} catch (MelderError) {
		Melder_throw (me, U": formula not completed.");
	}
}
Esempio n. 16
0
autoIntensityTier AmplitudeTier_to_IntensityTier (AmplitudeTier me, double threshold_dB) {
	try {
		double threshold_Pa = pow (10.0, threshold_dB / 20.0) * 2.0e-5;   // often zero!
		autoIntensityTier thee = Thing_new (IntensityTier);
		my structRealTier :: v_copy (thee.peek());
		for (long i = 1; i <= thy numberOfPoints(); i ++) {
			RealPoint point = thy point (i);
			double absoluteValue = fabs (point -> value);
			point -> value = absoluteValue <= threshold_Pa ? threshold_dB : 20.0 * log10 (absoluteValue / 2.0e-5);
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted to IntensityTier.");
	}
}
Esempio n. 17
0
double RealTier_getValueAtTime (RealTier me, double t) {
	long n = my numberOfPoints ();
	if (n == 0) return NUMundefined;
	RealPoint pointRight = my point (1);
	if (t <= pointRight -> number) return pointRight -> value;   // constant extrapolation
	RealPoint pointLeft = my point (n);
	if (t >= pointLeft -> number) return pointLeft -> value;   // constant extrapolation
	Melder_assert (n >= 2);
	long ileft = AnyTier_timeToLowIndex (me, t), iright = ileft + 1;
	Melder_assert (ileft >= 1 && iright <= n);
	pointLeft = my point (ileft);
	pointRight = my point (iright);
	double tleft = pointLeft -> number, fleft = pointLeft -> value;
	double tright = pointRight -> number, fright = pointRight -> value;
	return t == tright ? fright   // be very accurate
		: tleft == tright ? 0.5 * (fleft + fright)   // unusual, but possible; no preference
		: fleft + (t - tleft) * (fright - fleft) / (tright - tleft);   // linear interpolation
}
Esempio n. 18
0
void RealTier_draw (RealTier me, Graphics g, double tmin, double tmax, double fmin, double fmax,
	int garnish, const char32 *method, const char32 *quantity)
{
	bool drawLines = str32str (method, U"lines") || str32str (method, U"Lines");
	bool drawSpeckles = str32str (method, U"speckles") || str32str (method, U"Speckles");
	long n = my numberOfPoints (), imin, imax, i;
	if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; }
	Graphics_setWindow (g, tmin, tmax, fmin, fmax);
	Graphics_setInner (g);
	imin = AnyTier_timeToHighIndex (me, tmin);
	imax = AnyTier_timeToLowIndex (me, tmax);
	if (n == 0) {
	} else if (imax < imin) {
		double fleft = RealTier_getValueAtTime (me, tmin);
		double fright = RealTier_getValueAtTime (me, tmax);
		if (drawLines) Graphics_line (g, tmin, fleft, tmax, fright);
	} else for (i = imin; i <= imax; i ++) {
		RealPoint point = my point (i);
		double t = point -> number, f = point -> value;
		if (drawSpeckles) Graphics_speckle (g, t, f);
		if (drawLines) {
			if (i == 1)
				Graphics_line (g, tmin, f, t, f);
			else if (i == imin)
				Graphics_line (g, t, f, tmin, RealTier_getValueAtTime (me, tmin));
			if (i == n)
				Graphics_line (g, t, f, tmax, f);
			else if (i == imax)
				Graphics_line (g, t, f, tmax, RealTier_getValueAtTime (me, tmax));
			else {
				RealPoint pointRight = my point (i + 1);
				Graphics_line (g, t, f, pointRight -> number, pointRight -> value);
			}
		}
	}
	Graphics_unsetInner (g);
	if (garnish) {
		Graphics_drawInnerBox (g);
		Graphics_textBottom (g, true, my v_getUnitText (0, 0, 0));
		Graphics_marksBottom (g, 2, true, true, false);
		Graphics_marksLeft (g, 2, true, true, false);
		if (quantity) Graphics_textLeft (g, true, quantity);
	}
}
Esempio n. 19
0
double RealTier_getStandardDeviation_curve (RealTier me, double tmin, double tmax) {
	long n = my numberOfPoints (), imin, imax;
	RealPoint *points = my peekPoints ();
	double mean, integral = 0.0;
	if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; }   // autowindow
	if (n == 0) return NUMundefined;
	if (n == 1) return 0.0;
	imin = AnyTier_timeToLowIndex (me, tmin);
	if (imin == n) return 0.0;
	imax = AnyTier_timeToHighIndex (me, tmax);
	if (imax == 1) return 0.0;
	Melder_assert (imin < n);
	Melder_assert (imax > 1);
	/*
	 * Add the areas between the points.
	 * This works even if imin is 0 (offleft) and/or imax is n + 1 (offright).
	 */
	mean = RealTier_getMean_curve (me, tmin, tmax);
	for (long i = imin; i < imax; i ++) {
		double tleft, fleft, tright, fright, sum, diff;
		if (i == imin) tleft = tmin, fleft = RealTier_getValueAtTime (me, tmin);
		else tleft = points [i] -> number, fleft = points [i] -> value - mean;
		if (i + 1 == imax) tright = tmax, fright = RealTier_getValueAtTime (me, tmax);
		else tright = points [i + 1] -> number, fright = points [i + 1] -> value - mean;
		/*
		 * The area is integral dt f^2
		 *   = integral dt [f1 + (f2-f1)/(t2-t1) (t-t1)]^2
		 *   = int dt f1^2 + int dt 2 f1 (f2-f1)/(t2-t1) (t-t1) + int dt [(f2-f1)/(t2-t1)]^2 (t-t1)^2
		 *   = f1^2 (t2-t1) + f1 (f2-f1)/(t2-t1) (t2-t1)^2 + 1/3 [(f2-f1)/(t2-t1)]^2 (t2-t1)^3
		 *   = (t2-t1) [f1 f2 + 1/3 (f2-f1)^2]
		 *   = (t2-t1) (f1^2 + f2^2 + 1/3 f1 f2)
		 *   = (t2-t1) [1/4 (f1+f2)^2 + 1/12 (f1-f2)^2]
		 * In the last expression, we have a sum of squares, which is computationally best.
		 */
		sum = fleft + fright;
		diff = fleft - fright;
		integral += (sum * sum + (1.0/3.0) * diff * diff) * (tright - tleft);
	}
	return sqrt (0.25 * integral / (tmax - tmin));
}
Esempio n. 20
0
void RealTier_interpolateQuadratically (RealTier me, long numberOfPointsPerParabola, int logarithmically) {
	try {
		autoRealTier thee = Data_copy (me);
		for (long ipoint = 1; ipoint < my numberOfPoints (); ipoint ++) {
			RealPoint point1 = my point (ipoint), point2 = my point (ipoint + 1);
			double time1 = point1 -> number, time2 = point2 -> number, tmid = 0.5 * (time1 + time2);
			double value1 = point1 -> value, value2 = point2 -> value, valuemid;
			double timeStep = (tmid - time1) / (numberOfPointsPerParabola + 1);
			if (logarithmically) value1 = log (value1), value2 = log (value2);
			valuemid = 0.5 * (value1 + value2);
			/*
			 * Left from the midpoint.
			 */
			for (long inewpoint = 1; inewpoint <= numberOfPointsPerParabola; inewpoint ++) {
				double newTime = time1 + inewpoint * timeStep;
				double phase = (newTime - time1) / (tmid - time1);
				double newValue = value1 + (valuemid - value1) * phase * phase;
				if (logarithmically) newValue = exp (newValue);
				RealTier_addPoint (thee.peek(), newTime, newValue);
			}
			/*
			 * The midpoint.
			 */
			RealTier_addPoint (thee.peek(), tmid, logarithmically ? exp (valuemid) : valuemid);
			/*
			 * Right from the midpoint.
			 */
			for (long inewpoint = 1; inewpoint <= numberOfPointsPerParabola; inewpoint ++) {
				double newTime = tmid + inewpoint * timeStep;
				double phase = (time2 - newTime) / (time2 - tmid);
				double newValue = value2 + (valuemid - value2) * phase * phase;
				if (logarithmically) newValue = exp (newValue);
				RealTier_addPoint (thee.peek(), newTime, newValue);
			}
		}
		Thing_swap (me, thee.peek());
	} catch (MelderError) {
		Melder_throw (me, U": not interpolated quadratically.");
	}
}
AMSimpleBeamConfigurationWizard::AMSimpleBeamConfigurationWizard(QWidget *parent)
	: AMGraphicsViewWizard(parent)
{
	setNumberOfPoints(3);
	setNumberOfPages(numberOfPoints());
	setFreePage(Page_Free);

	coordinateListAppend(new QVector3D(0,0,0));
	coordinateListAppend(new QVector3D(0,2,0));
	coordinateListAppend(new QVector3D(0,-2,0));

	setPage(Page_Intro, new AMWizardPage);
	setPage(Page_Option, new AMWizardOptionPage);
	setPage(Page_Final, new AMWizardPage);
	for(int i = 0; i < numberOfPages(); i++)
	{
		setPage(pageWait(i), new AMSimpleBeamConfigurationWaitPage);
		setPage(pageSet(i), new AMSimpleBeamConfigurationSetPage);
		connect(page(pageSet(i)), SIGNAL(initBeamShape()), this, SLOT(initBeamShape()));
		connect(page(pageSet(i)), SIGNAL(signalMousePressed(QPointF)), this, SLOT(mousePressedHandler(QPointF)));
		connect(page(pageSet(i)), SIGNAL(moveBeamShape(QPointF)), this, SLOT(moveBeamShapeHandler(QPointF)));
	}

	setStartId(Page_Intro);
	setOption(HaveHelpButton, true);
	connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));

	setWindowTitle(message(Wizard_Title));

	disconnect(button(QWizard::BackButton), SIGNAL(clicked()), this, SLOT(back()));
	connect(button(QWizard::BackButton), SIGNAL(clicked()), this, SLOT(back()));

	setMinimumSize(600,600);

	/// Add options button to intro page
	addOptionPage(Page_Intro);

}
void AMBeamConfigurationWizard::addPoint(QPointF position)
{

	int index = relativeId() - numberOfPoints()/2;
	QPointF* newPoint;

	if(topLeft_)
	{
		newPoint = (*pointList())[2*(index)];
		connect(view(), SIGNAL(mouseMoved(QPointF)), this, SLOT(addPoint(QPointF)));
		topLeft_ = !topLeft_;
	}
	else
	{
		newPoint = (*pointList())[2*(index) + 1];
	}

	*newPoint = mapPointToVideo(position);

	emit showShape(index);


}
Esempio n. 23
0
double RealTier_getValueAtIndex (RealTier me, long i) {
	if (i < 1 || i > my numberOfPoints ()) return NUMundefined;
	return my point (i) -> value;
}
Esempio n. 24
0
double AMScanAxisRegion::timePerRegion() const
{
	return numberOfPoints()*double(regionTime());
}
Esempio n. 25
0
bool DrawingPolygonItem::canRemovePoint(DrawingItemPoint* point) const
{
	return (DrawingPolyItem::canRemovePoint(point) && numberOfPoints() > 3);
}
Esempio n. 26
0
DrawingItemPoint* DrawingPolylineItem::endPoint() const
{
	return point(numberOfPoints() - 1);
}
Esempio n. 27
0
void structRealTier :: v_info () {
	structFunction :: v_info ();
	MelderInfo_writeLine (U"Number of points: ", our numberOfPoints ());
	MelderInfo_writeLine (U"Minimum value: ", RealTier_getMinimumValue (this));
	MelderInfo_writeLine (U"Maximum value: ", RealTier_getMaximumValue (this));
}