Beispiel #1
0
        public static SKColor CalculateBloodColor(double sat)
        {
            // sat can variate between 0 - 10
            if (sat > 10)
            {
                sat = 10;
            }

            float remap = AnimatedElementHelper.Remap((float)sat, 0, 10, -2f, 1);

            if (remap < 0)
            {
                remap = 0;
            }

            byte red   = (byte)(remap * 200);
            byte green = (byte)(remap * 75);
            byte blue  = (byte)(80 + remap * 75);

            return(new SKColor(red, green, blue));
        }
Beispiel #2
0
        public void DrawConnector(SKCanvas canvas, float _radX, float _radY)
        {
            float totalFlow     = 0;
            float totalSpO2     = 0;
            float totalSpO2To   = 0;
            float totalSpO2From = 0;
            float currentVolume = 0;
            float radius        = 0;

            scale  = _radX * scaleRelative;
            radius = _radX / 2.5f;

            if (_radX > _radY)
            {
                scale  = _radY * scaleRelative;
                radius = _radY / 2.5f;
            }


            float left   = (float)Math.Sin(270 * 0.0174532925) * RadiusXOffset * radius;
            float right  = (float)Math.Sin(90 * 0.0174532925) * RadiusXOffset * radius;
            float top    = (float)Math.Cos(180 * 0.0174532925) * RadiusYOffset * radius;
            float bottom = (float)Math.Cos(0 * 0.0174532925) * RadiusYOffset * radius;



            // calculate the total volume and average spO2 if lumping is the case
            foreach (ValveConnector c in connectors)
            {
                totalFlow += (float)c.CurrentFlow * Speed;
                if (totalFlow >= 0)
                {
                    totalSpO2 += (float)c.Comp1.TO2;
                    if (NoLoss)
                    {
                        totalSpO2From += (float)c.Comp1.TO2;
                        totalSpO2To   += (float)c.Comp1.TO2;
                    }
                    else
                    {
                        totalSpO2From += (float)c.Comp1.TO2;
                        totalSpO2To   += (float)c.Comp2.TO2;
                    }
                }
                else
                {
                    totalSpO2 += (float)c.Comp2.TO2;
                    if (NoLoss)
                    {
                        totalSpO2From += (float)c.Comp2.TO2;
                        totalSpO2To   += (float)c.Comp2.TO2;
                    }
                    else
                    {
                        totalSpO2From += (float)c.Comp2.TO2;
                        totalSpO2To   += (float)c.Comp1.TO2;
                    }
                }
                Title = "";
            }

            tempAverageFlow += totalFlow;

            if (averageCounter > 100)
            {
                AverageFlow     = Math.Abs(tempAverageFlow) / averageCounter;
                tempAverageFlow = 0;
                averageCounter  = 0;
            }
            averageCounter++;

            //paint.Color = CalculateColor(totalSpO2 / connectors.Count);
            colorTo   = AnimatedElementHelper.CalculateBloodColor(totalSpO2To / connectors.Count);
            colorFrom = AnimatedElementHelper.CalculateBloodColor(totalSpO2From / connectors.Count);

            currentAngle += totalFlow * Direction;
            if (Math.Abs(currentAngle) > Math.Abs(StartAngle - EndAngle))
            {
                currentAngle = 0;
            }

            if (sizeCompartment != null)
            {
                currentVolume         = (float)sizeCompartment.VolCurrent;
                circleOut.StrokeWidth = AnimatedElementHelper.RadiusCalculator(currentVolume, scale);
            }
            else
            {
                StrokeWidth = AverageFlow * Width;
                if (StrokeWidth > 30)
                {
                    StrokeWidth = 30;
                }
                if (StrokeWidth < 2)
                {
                    StrokeWidth = 2;
                }

                strokeStepsize      = (StrokeWidth - currentStrokeWidth) / 10;
                currentStrokeWidth += strokeStepsize;
                if (Math.Abs(currentStrokeWidth - StrokeWidth) < Math.Abs(strokeStepsize))
                {
                    strokeStepsize     = 0;
                    currentStrokeWidth = StrokeWidth;
                }

                circleOut.StrokeWidth = currentStrokeWidth;
            }

            // calculate position
            locationOrigen = AnimatedElementHelper.GetPosition(StartAngle, radius, RadiusXOffset, RadiusYOffset);
            locationTarget = AnimatedElementHelper.GetPosition(EndAngle, radius, RadiusXOffset, RadiusYOffset);

            SKRect mainRect = new SKRect(left, top, right, bottom);


            circleOut.Shader = SKShader.CreateSweepGradient(
                new SKPoint(0f, 0f),
                new SKColor[] { colorFrom, colorTo },
                new float[] { StartAngle / 360f, EndAngle / 360f }
                );



            using (SKPath path = new SKPath())
            {
                path.AddArc(mainRect, StartAngle, Math.Abs(StartAngle - EndAngle));
                canvas.DrawPath(path, circleOut);
            }

            location1 = AnimatedElementHelper.GetPosition(StartAngle + currentAngle, radius, RadiusXOffset, RadiusYOffset);
            canvas.DrawCircle(location1.X + XOffset, location1.Y + YOffset, 7, paint);
        }
Beispiel #3
0
        public void DrawCompartment(SKCanvas canvas, float _radX, float _radY)
        {
            float totalVolume = 0;
            float totalSpO2   = 0;
            float radius      = 0;


            scale  = _radX * scaleRelative;
            radius = _radX / 2.5f;

            if (_radX > _radY)
            {
                scale  = _radY * scaleRelative;
                radius = _radY / 2.5f;
            }


            // calculate the total volume and average spO2 if lumping is the case
            foreach (BloodCompartment c in compartments)
            {
                totalVolume += (float)c.VolCurrent;
                totalSpO2   += (float)c.TO2;
            }

            paint.Color = AnimatedElementHelper.CalculateBloodColor(totalSpO2 / compartments.Count);

            float twidth = textPaint.MeasureText(Name);

            // calculate position
            location = AnimatedElementHelper.GetPosition(Degrees, radius, RadiusXOffset, RadiusYOffset);

            // calculate position
            locationOrigen = AnimatedElementHelper.GetPosition(StartAngle, radius, RadiusXOffset, RadiusYOffset);
            locationTarget = AnimatedElementHelper.GetPosition(EndAngle, radius, RadiusXOffset, RadiusYOffset);

            float left   = (float)Math.Sin(270 * 0.0174532925) * RadiusXOffset * radius;
            float right  = (float)Math.Sin(90 * 0.0174532925) * RadiusXOffset * radius;
            float top    = (float)Math.Cos(180 * 0.0174532925) * RadiusYOffset * radius;
            float bottom = (float)Math.Cos(0 * 0.0174532925) * RadiusYOffset * radius;

            float r = AnimatedElementHelper.RadiusCalculator(totalVolume, scale);

            if (IsVessel)
            {
                mainRect.Left   = left;
                mainRect.Top    = top;
                mainRect.Right  = right;
                mainRect.Bottom = bottom;

                using (SKPath path = new SKPath())
                {
                    path.AddArc(mainRect, StartAngle, Math.Abs(StartAngle - EndAngle) * Direction);
                    circleOut.Color = paint.Color;

                    circleOut.StrokeWidth = r;
                    canvas.DrawPath(path, circleOut);

                    offset.X = Math.Abs(locationOrigen.X - locationTarget.X) / OffsetXFactor;
                    canvas.DrawTextOnPath(Name, path, offset, textPaint2);
                }
            }
            else
            {
                paint.StrokeWidth = 10;
                canvas.DrawCircle(location, r, paint);
                canvas.DrawText(Name, location.X - twidth / 2, location.Y + 7, textPaint);

                if (compartments[0].IsPump)
                {
                    SKPoint or   = new SKPoint(0, 0);
                    SKPoint dest = new SKPoint(0, 0);
                    or     = location;
                    dest   = location;
                    or.X   = location.X + (float)Math.Cos(pumpLocation) * 40;
                    or.Y   = location.Y + (float)Math.Sin(pumpLocation) * 40;
                    dest.X = location.X + (float)Math.Cos(pumpLocation + Math.PI) * 40;
                    dest.Y = location.Y + (float)Math.Sin(pumpLocation + Math.PI) * 40;

                    pumpLocation += compartments[0].dataCollector.VolumeFlowOut / 10000;
                    if (pumpLocation > 2 * Math.PI)
                    {
                        pumpLocation = 0;
                    }

                    canvas.DrawLine(or, dest, pumpColorStroke);
                }
            }
        }