Esempio n. 1
0
        private Tuple<ValueMapping, ValueMapping> calcRatios(int epsilon, List<DMXImgSetupMappingValue> points)
        {
            //TODO: add error handling for division by 0!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
            // get the point, closest to 0,0
            for (int i = 0; i < points.Count; i++)
            {
                Log.DebugFormat("calcRatios: points[{0}]: {1}, {2} - {3}, {4}", i, points[i].DMXImgVal.X, points[i].DMXImgVal.Y, points[i].VirtualVal.X, points[i].VirtualVal.Y);
            }
            Point p = new Point(0, 0);
            int index = getDMXImgMappingClosestToPoint(p, points);
            Log.DebugFormat("calcRatios: index: {0}", index);
            // find point, closest on X and farest away on Y
            int indexX = getDMXImgMappingClosestOnOneFarestOnOther(p, points, getValueOfX, getValueOfY, epsilon);
            Log.DebugFormat("calcRatios: indexX: {0}", indexX);
            // find point, closest on Y and farest away on X
            int indexY = getDMXImgMappingClosestOnOneFarestOnOther(p, points, getValueOfY, getValueOfX, epsilon);
            Log.DebugFormat("calcRatios: indexY: {0}", indexY);
            p = new Point(Model.Map.GetWidth(), Model.Map.GetHeight());
            int indexMax = getDMXImgMappingClosestToPoint(p, points);
            Log.DebugFormat("calcRatios: index: {0}", index);
            // find point, closest on X and farest away on Y
            int indexMaxX = getDMXImgMappingClosestOnOneFarestOnOther(p, points, getValueOfX, getValueOfY, epsilon);
            Log.DebugFormat("calcRatios: indexX: {0}", indexX);
            // find point, closest on Y and farest away on X
            int indexMaxY = getDMXImgMappingClosestOnOneFarestOnOther(p, points, getValueOfY, getValueOfX, epsilon);
            Log.DebugFormat("calcRatios: indexY: {0}", indexY);

            // calc first ratios
            double dmx1 = points[indexY].DMXImgVal.X;
            double dmx2 = points[index].DMXImgVal.X;
            double img1 = points[indexY].VirtualVal.X;
            double img2 = points[index].VirtualVal.X;
            if (img1 == img2 || dmx1 == dmx2)
            {
                List<Point> involvedPoints = new List<Point>();
                involvedPoints.Add(points[index].DMXImgVal);
                involvedPoints.Add(points[indexY].DMXImgVal);
                involvedPoints.Add(points[indexY].VirtualVal);
                involvedPoints.Add(points[index].VirtualVal);

                // This is the first exception that may occur in Debug-Mode
                string msg = "Some of the X values are the same, when trying to calculate xRatio1!";
                if (!IsDevEnv)
                    throw new VMServiceSetupException(msg, involvedPoints);
                else {
                    // Exit silently
                    Log.Warn(msg);
                    return null;
                }
            }
            double xRatio1 = (dmx1 - dmx2) / (img1 - img2);
            Log.DebugFormat("calcRatios: xRatio1: {0}", xRatio1);
            double xRatio1Reverse = 1 / xRatio1;
            Log.DebugFormat("calcRatios: xRatio1Reverse: {0}", xRatio1Reverse);
            img1 = points[indexY].VirtualVal.Y;
            img2 = points[index].VirtualVal.Y;
            double xRatio1YValue = (img1 + img2) / 2;
            Log.DebugFormat("calcRatios: xRatio1YValue: {0}", xRatio1YValue);
            dmx1 = points[indexY].DMXImgVal.Y;
            dmx2 = points[index].DMXImgVal.Y;
            double xRatio1YValueReverse = (dmx1 + dmx2) / 2;
            Log.DebugFormat("calcRatios: xRatio1YValueReverse: {0}", xRatio1YValueReverse);

            dmx1 = points[indexX].DMXImgVal.Y;
            dmx2 = points[index].DMXImgVal.Y;
            img1 = points[indexX].VirtualVal.Y;
            img2 = points[index].VirtualVal.Y;
            if (img1 == img2 || dmx1 == dmx2)
            {
                List<Point> involvedPoints = new List<Point>();
                involvedPoints.Add(points[index].DMXImgVal);
                involvedPoints.Add(points[indexX].DMXImgVal);
                involvedPoints.Add(points[indexX].VirtualVal);
                involvedPoints.Add(points[index].VirtualVal);
                throw new VMServiceSetupException("Some of the Y values are the same, when trying to calculate yRatio1!", involvedPoints);
            }
            double yRatio1 = (dmx1 - dmx2) / (img1 - img2);
            Log.DebugFormat("calcRatios: yRatio1: {0}", yRatio1);
            double yRatio1Reverse = 1 / yRatio1;
            Log.DebugFormat("calcRatios: yRatio1Reverse: {0}", yRatio1Reverse);
            img1 = points[indexX].VirtualVal.X;
            img2 = points[index].VirtualVal.X;
            double yRatio1XValue = (img1 + img2) / 2;
            Log.DebugFormat("calcRatios: yRatio1XValue: {0}", yRatio1XValue);
            dmx1 = points[indexX].DMXImgVal.X;
            dmx2 = points[index].DMXImgVal.X;
            double yRatio1XValueReverse = (dmx1 + dmx2) / 2;
            Log.DebugFormat("calcRatios: yRatio1XValueReverse: {0}", yRatio1XValueReverse);

            // calc start values for x
            double x1 = points[indexX].DMXImgVal.X;
            double x2 = points[index].DMXImgVal.X;
            double y1 = points[indexX].VirtualVal.Y;
            double y2 = points[index].VirtualVal.Y;
            if (y1 == y2)
            {
                List<Point> involvedPoints = new List<Point>();
                involvedPoints.Add(points[indexX].VirtualVal);
                involvedPoints.Add(points[index].VirtualVal);
                throw new VMServiceSetupException("The Y values are the same, when trying to calculate the start values for x!", involvedPoints);
            }
            Log.Debug("calcRatios: calc start values for x");
            double k = (x1 - x2) / (y1 - y2);
            Log.DebugFormat("calcRatios: k: {0}", k);
            double d = x2 - k * y2;
            Log.DebugFormat("calcRatios: d: {0}", d);
            LinearEquation getStartX = new LinearEquation(k, d);

            // calc start values for y
            x1 = points[indexY].VirtualVal.X;
            x2 = points[index].VirtualVal.X;
            y1 = points[indexY].DMXImgVal.Y;
            y2 = points[index].DMXImgVal.Y;
            if (x1 == x2)
            {
                List<Point> involvedPoints = new List<Point>();
                involvedPoints.Add(points[indexY].VirtualVal);
                involvedPoints.Add(points[index].VirtualVal);
                throw new VMServiceSetupException("The X values are the same, when trying to calculate the start values for y!", involvedPoints);
            }
            Log.Debug("calcRatios: calc start values for y");
            k = (y1 - y2) / (x1 - x2);
            Log.DebugFormat("calcRatios: k: {0}", k);
            d = y2 - k * x2;
            Log.DebugFormat("calcRatios: d: {0}", d);
            LinearEquation getStartY = new LinearEquation(k, d);

            // calc second ratios
            dmx1 = points[indexMaxY].DMXImgVal.X;
            dmx2 = points[indexMax].DMXImgVal.X;
            img1 = points[indexMaxY].VirtualVal.X;
            img2 = points[indexMax].VirtualVal.X;
            if (img1 == img2 || dmx1 == dmx2)
            {
                List<Point> involvedPoints = new List<Point>();
                involvedPoints.Add(points[indexMax].DMXImgVal);
                involvedPoints.Add(points[indexMaxY].DMXImgVal);
                involvedPoints.Add(points[indexMaxY].VirtualVal);
                involvedPoints.Add(points[indexMax].VirtualVal);
                throw new VMServiceSetupException("Some of the X values are the same, when trying to calculate xRatio2!", involvedPoints);
            }
            double xRatio2 = (dmx1 - dmx2) / (img1 - img2);
            Log.DebugFormat("calcRatios: xRatio2: {0}", xRatio2);
            double xRatio2Reverse = 1 / xRatio2;
            Log.DebugFormat("calcRatios: xRatio2Reverse: {0}", xRatio2Reverse);
            img1 = points[indexMaxY].VirtualVal.Y;
            img2 = points[indexMax].VirtualVal.Y;
            double xRatio2YValue = (img1 + img2) / 2;
            Log.DebugFormat("calcRatios: xRatio2YValue: {0}", xRatio2YValue);
            dmx1 = points[indexMaxY].DMXImgVal.Y;
            dmx2 = points[indexMax].DMXImgVal.Y;
            double xRatio2YValueReverse = (dmx1 + dmx2) / 2;
            Log.DebugFormat("calcRatios: xRatio2YValueReverse: {0}", xRatio2YValueReverse);

            dmx1 = points[indexMaxX].DMXImgVal.Y;
            dmx2 = points[indexMax].DMXImgVal.Y;
            img1 = points[indexMaxX].VirtualVal.Y;
            img2 = points[indexMax].VirtualVal.Y;
            if (img1 == img2 || dmx1 == dmx2)
            {
                List<Point> involvedPoints = new List<Point>();
                involvedPoints.Add(points[indexMax].DMXImgVal);
                involvedPoints.Add(points[indexMaxX].DMXImgVal);
                involvedPoints.Add(points[indexMaxX].VirtualVal);
                involvedPoints.Add(points[indexMax].VirtualVal);
                throw new VMServiceSetupException("Some of the Y values are the same, when trying to calculate yRatio2!", involvedPoints);
            }
            double yRatio2 = (dmx1 - dmx2) / (img1 - img2);
            Log.DebugFormat("calcRatios: yRatio2: {0}", yRatio2);
            double yRatio2Reverse = 1 / yRatio2;
            Log.DebugFormat("calcRatios: yRatio2Reverse: {0}", yRatio2Reverse);
            img1 = points[indexMaxX].VirtualVal.X;
            img2 = points[indexMax].VirtualVal.X;
            double yRatio2XValue = (img1 + img2) / 2;
            Log.DebugFormat("calcRatios: yRatio2XValue: {0}", yRatio2XValue);
            dmx1 = points[indexMaxX].DMXImgVal.X;
            dmx2 = points[indexMax].DMXImgVal.X;
            double yRatio2XValueReverse = (dmx1 + dmx2) / 2;
            Log.DebugFormat("calcRatios: yRatio2XValueReverse: {0}", yRatio2XValueReverse);

            // calc equation for x ratios
            Log.Debug("calcRatios: calc equation for x ratios");
            k = (xRatio2 - xRatio1) / (xRatio2YValue - xRatio1YValue);
            Log.DebugFormat("calcRatios: k: {0}", k);
            d = xRatio1 - k * xRatio1YValue;
            Log.DebugFormat("calcRatios: d: {0}", d);
            LinearEquation getXRatio = new LinearEquation(k, d);
            // calc reverse
            //TODO: correct?
            Log.Debug("calcRatios: calc reverse");
            k = (xRatio2Reverse - xRatio1Reverse) / (xRatio2YValueReverse - xRatio1YValueReverse);
            Log.DebugFormat("calcRatios: k: {0}", k);
            d = xRatio1Reverse - k * xRatio1YValueReverse;
            Log.DebugFormat("calcRatios: d: {0}", d);
            LinearEquation getXRatioReverse = new LinearEquation(k, d);

            // calc reverse start values for x
            //TODO: correct?
            Log.Debug("calcRatios: calc reverse start values for x");
            x1 = points[indexX].DMXImgVal.X;
            x2 = points[index].DMXImgVal.X;
            y1 = points[indexX].DMXImgVal.Y;
            y2 = points[index].DMXImgVal.Y;
            k = (x1 - x2) / (y1 - y2);
            Log.DebugFormat("calcRatios: k: {0}", k);
            d = x2 - k * y2;
            Log.DebugFormat("calcRatios: d: {0}", d);
            LinearEquation getStartXReverse = new LinearEquationNegativeMultipliedWithOther(k, d, getXRatioReverse);

            // calc equation for y ratios
            Log.Debug("calcRatios: calc equation for y ratios");
            k = (yRatio2 - yRatio1) / (yRatio2XValue - yRatio1XValue);
            Log.DebugFormat("calcRatios: k: {0}", k);
            d = yRatio1 - k * yRatio1XValue;
            Log.DebugFormat("calcRatios: d: {0}", d);
            LinearEquation getYRatio = new LinearEquation(k, d);
            // calc reverse
            //TODO: correct?
            Log.DebugFormat("calcRatios: calc reverse");
            k = (yRatio2Reverse - yRatio1Reverse) / (yRatio2XValueReverse - yRatio1XValueReverse);
            Log.DebugFormat("calcRatios: k: {0}", k);
            d = yRatio1Reverse - k * yRatio1XValueReverse;
            Log.DebugFormat("calcRatios: d: {0}", d);
            LinearEquation getYRatioReverse = new LinearEquation(k, d);

            // calc reverse start values for y
            Log.Debug("calcRatios: calc reverse start values for y");
            //TODO: correct?
            x1 = points[indexY].DMXImgVal.X;
            x2 = points[index].DMXImgVal.X;
            y1 = points[indexY].DMXImgVal.Y;
            y2 = points[index].DMXImgVal.Y;
            k = (y1 - y2) / (x1 - x2);
            Log.DebugFormat("calcRatios: k2: {0}", k);
            d = y2 - k * x2;
            Log.DebugFormat("calcRatios: d: {0}", d);
            LinearEquation getStartYReverse = new LinearEquationNegativeMultipliedWithOther(k, d, getYRatioReverse);

            ValueMapping reverseMappingFuncs = new ValueMapping(getStartXReverse, getStartYReverse, getXRatioReverse, getYRatioReverse);
            Log.DebugFormat("calcRatios: reverseMappingFuncs.GetStartY.K: {0}", reverseMappingFuncs.GetStartY.K);
            Log.DebugFormat("calcRatios: reverseMappingFuncs.GetStartY.D: {0}", reverseMappingFuncs.GetStartY.D);
            ValueMapping mappingFuncs = new ValueMapping(getStartX, getStartY, getXRatio, getYRatio);
            Tuple<ValueMapping, ValueMapping> returnVal = new Tuple<ValueMapping, ValueMapping>(mappingFuncs, reverseMappingFuncs);
            return returnVal;
        }
Esempio n. 2
0
        public void Start()
        {
            Log.Debug("VMService Method Start called.");
            MovingHeads = new Dictionary<int, VMovingHead>();
            ImgParseResults = new Dictionary<int, VImageParseResultEntity>();
            DMXSetupValues = new Dictionary<int, List<DMXImgSetupMappingValue>>();
            MhNrEntityIdMapping = new Dictionary<int, int>();
            MhNrSetupComplete = new Dictionary<int, bool>();
            LinearEquation standardEquation = new LinearEquation(1, 0);
            VirtualToDMXMapping = new Dictionary<int, ValueMapping>();
            DMXToVirtualMapping = new Dictionary<int, ValueMapping>();
            VirtualToImgMapping = new ValueMapping(standardEquation, standardEquation, standardEquation, standardEquation);
            ImgToVirtualMapping = new ValueMapping(standardEquation, standardEquation, standardEquation, standardEquation);
            ImgSetupValues = new List<DMXImgSetupMappingValue>();
            ImgSetupPositions = new Dictionary<int, Position>();
            ImgSetupDone = false;
            MhNrIsVirtual = new Dictionary<int, bool>();
            EntityIdVirtualObjectIdMapping = new Dictionary<int, int>();
            AvailableEntityIds = new List<int>();

            for (int i = 0; i < Conf.MhAdresses.Count; i++)
            {
                MovingHeads.Add(i, new VMovingHead() { ID = i });
            }
        }