/// <summary> /// Three-point calibration of coordinate-voltage mapping. Using the origin at 0V/0V and two points /// for averaging purposes /// </summary> /// <param name="origin">The coordinates of the origin at 0V/0V</param> /// <param name="p1">First calibration point</param> /// <param name="p2">Second calibration point</param> public void Calibrate(IppiPoint origin, PointVoltagePair p1, PointVoltagePair p2) { //distances from plane to mirror calculated for each point double x1d, x2d, y1d, y2d; //distance from the point in question to the origin double pointdist; //Calculate first distance measure for x-mirror pointdist = p1.Coordinate.x - origin.x; x1d = pointdist / Math.Tan(4 * Math.PI * p1.XVoltage / 180); //Calculate second distance measure for x-mirror pointdist = p2.Coordinate.x - origin.x; x2d = pointdist / Math.Tan(4 * Math.PI * p2.XVoltage / 180); //Calculate first distance measure for y-mirror pointdist = p1.Coordinate.y - origin.y; y1d = pointdist / Math.Tan(4 * Math.PI * p1.YVoltage / 180); //Calculate second distance measure for y-mirror pointdist = p2.Coordinate.y - origin.y; y2d = pointdist / Math.Tan(4 * Math.PI * p2.YVoltage / 180); //Calculate distance for x-mirror XDistance = (x1d + x2d) / 2; //Calculate distance for y-mirror YDistance = (y1d + y2d) / 2; //Create x-lookup table for (int x = 0; x < _imageWidth; x++) { _xVolts[x] = (float)(Math.Atan((x - origin.x) / XDistance) * 45 / Math.PI); } //Create y-lookup table for (int y = 0; y < _imageHeight; y++) { _yVolts[y] = (float)(Math.Atan((y - origin.y) / YDistance) * 45 / Math.PI); } Complete = true; }
/// <summary> /// Adds a new point to the calibration table without checking its validity. Returns /// true until the table is complete and provides the next point to target /// </summary> /// <param name="calibrationPoint">The new calibration point to add to the table</param> /// <param name="nextPoint">The point expected next in the calibration</param> /// <returns>True until the table is complete</returns> public bool ForceAddNext(PointVoltagePair calibrationPoint, out IppiPoint nextPoint) { if (_addIndex >= _xVolts.Length) { System.Diagnostics.Debug.WriteLine("Tried to add new point to already complete calibration table"); nextPoint = new IppiPoint(-1, -1); return(false); } int x, y; if (_addIndex == -1) { _addIndex++; //Compute next point x = _addIndex % _c; x = x * _spacing + _scanRoi.X; y = (_addIndex - _addIndex % _c) / _c; y = y * _spacing + _scanRoi.Y; nextPoint = new IppiPoint(x, y); return(true); } //Add point to table _xVolts[_addIndex] = calibrationPoint.XVoltage; _yVolts[_addIndex] = calibrationPoint.YVoltage; _addIndex++; if (_addIndex >= _xVolts.Length) { nextPoint = new IppiPoint(-1, -1); _complete = true; return(false); } else { //Compute next point x = _addIndex % _c; x = x * _spacing + _scanRoi.X; y = (_addIndex - _addIndex % _c) / _c; y = y * _spacing + _scanRoi.Y; nextPoint = new IppiPoint(x, y); return(true); } }
/// <summary> /// Adds a new point to the calibration table, verifies that it has the expected coordinates /// and returns true until the table is complete /// </summary> /// <param name="calibrationPoint">The new calibration point to add to the table</param> /// <param name="nextPoint">The point expected next in the calibration</param> /// <returns>True while still expecting new points</returns> /// <exception cref="ArgumentExcpetion">Thrown if the wrong calibration point is provided</exception> public bool AddNext(PointVoltagePair calibrationPoint, out IppiPoint nextPoint) { int x, y; //Verify new point if (_addIndex > -1 && _addIndex < _xVolts.Length) { x = _addIndex % _c; x = x * _spacing + _scanRoi.X; y = (_addIndex - _addIndex % _c) / _c; y = y * _spacing + _scanRoi.Y; if (calibrationPoint.Coordinate.x != x || calibrationPoint.Coordinate.y != y) { throw new ArgumentException("Wrong calibration point provided"); } } return(ForceAddNext(calibrationPoint, out nextPoint)); }
/// <summary> /// Three point calibration for coordinate voltage mapping. Uses three arbitrary points to calculate the mapping. /// The three points are used to form two pairs for mapping /// </summary> /// <param name="p1">The first point and its corresponding voltage</param> /// <param name="p2">The second point and its corresponding voltage</param> /// <param name="p3">The third point and its corresponding voltage</param> public void Calibrate(PointVoltagePair p1, PointVoltagePair p2, PointVoltagePair p3) { //distance from the point in question to the first point double pointdist; //To build the lookup table we need the coordinates of the origin //to have a rectangular triangle reference //We try linear interpolation based on the points we got IppiPoint origin = new IppiPoint(); pointdist = p2.Coordinate.x - p1.Coordinate.x; double distpervolts = pointdist / (p2.XVoltage - p1.XVoltage); origin.x = (int)(p1.Coordinate.x - p1.XVoltage * distpervolts); pointdist = p2.Coordinate.y - p1.Coordinate.y; distpervolts = pointdist / (p2.YVoltage - p1.YVoltage); origin.y = (int)(p1.Coordinate.y - p1.YVoltage * distpervolts); Calibrate(origin, p2, p3); return; }