コード例 #1
0
        bool ensureTextures(int penId)
        {
            if (penId > -1)
            {
                PenData pen = null;
                if (!pens.TryGetValue(penId, out pen))
                {
                    pen = new PenData();
                    pens.Add(penId, pen);
                }
            }
            if (rtCurrent == null)
            {
                rtCurrent = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
                if (rtCurrent.useMipMap)
                {
                    rtCurrent.Release();
                    rtCurrent.useMipMap = false;
                    rtCurrent.Create();
                }
                rtCurrent.wrapMode = tex.wrapMode;
                Graphics.Blit(tex, rtCurrent);
                targetMaterial.mainTexture = rtCurrent;
                tex = null;
            }
            bool ret = ensureTextureProcessor();

            return(ret);
        }
コード例 #2
0
 public void OnSpeechKeywordRecognized(SpeechEventData eventData)
 {
     if (eventData.RecognizedText == "Calibrate")
     {
         if (calibrating)
         {
             if (!uiController.userNameSubmitted)
             {
                 uiController.enabled = true;
                 speechRecognition.SetActive(false);
             }
             cd = vc.FetchFrame("Cube");
             ComputeViconToHoloTransform();
             cube.SetActive(false);
             vcToWorld.SetActive(true);
             cur_model.SetActive(true);
             cur_model.transform.parent.position = cube.transform.position;
             sketch.SetActive(true);
             calibrating = false;
         }
         else
         {
             cube.SetActive(true);
             vcToWorld.SetActive(false);
             cur_model.SetActive(false);
             sketch.SetActive(false);
             calibrating = true;
         }
     }
 }
コード例 #3
0
ファイル: FormMain.cs プロジェクト: waitlamp/spen-digitizer
        public FormMain()
        {
            InitializeComponent();

            pen = new PenData(this);

            init(12333);
        }
コード例 #4
0
ファイル: FormMain.cs プロジェクト: fwswdev/spendigitizer
        public FormMain()
        {
            InitializeComponent();

            pen = new PenData(this);

            init(12333);
        }
コード例 #5
0
ファイル: Form.cs プロジェクト: siegjan6/HMI
        private void button2_Click(object sender, EventArgs e)
        {
            PenDialog dlg = new PenDialog(pd);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                pd = dlg.penData;
            }
        }
コード例 #6
0
        /// <summary>
        /// 鼠标创建控件时绘制图形
        /// </summary>
        /// <param name="g"></param>
        public override void CreatingPaint(Graphics g)
        {
            List <PointF> ds = /*CALCTool.CopyListPoint*/ (NodeDatas);

            if (ds != null && ds.Count > 1)
            {
                Pen p = PenData.CreatePen(Rect, Path);
                g.DrawLines(p, ds.ToArray());
                p.Dispose();
            }
        }
コード例 #7
0
ファイル: DrawBezier.cs プロジェクト: siegjan6/HMI
        public override void CreatingPaint(Graphics g)
        {
            List <PointF> ds = NodeDatas;

            if (ds != null && ds.Count > 1)
            {
                Pen           p   = PenData.CreatePen(Rect, Path);
                List <PointF> dis = MyTools.ConvertBeziers(NodeDatas, false);
                PointF[]      ary = dis.ToArray();
                g.DrawBeziers(p, ary);
                p.Dispose();
            }
        }
コード例 #8
0
 // Update is called once per frame
 void Update()
 {
     /*if (!initialized) {
      *  pd = vc.FetchFrame("Pen_experimental");
      *  initialized = true;
      * }
      * else {
      *  PenData cur_pd = vc.FetchFrame("Pen_experimental");
      *  JitterRemoval(cur_pd);
      * }*/
     pd = vc.FetchFrame("Pen_experimental");
     if (pd.valid == 2)
     {
         transform.localPosition = convertToLeftHandPosition(pd.x, pd.y, pd.z);
         transform.localRotation = convertToLeftHandRotation(pd.qx, pd.qy, pd.qz, pd.qw);
     }
 }
コード例 #9
0
    private void JitterRemoval(PenData cur_pd)
    {
        Vector3 new_pos   = new Vector3(cur_pd.x, cur_pd.y, cur_pd.z);
        Vector3 old_pos   = new Vector3(pd.x, pd.y, pd.z);
        Vector3 diff      = new_pos - old_pos;
        float   minimum   = Mathf.Min(jittery_tolerance, diff.magnitude);
        Vector3 delta_pos = minimum * diff.normalized;

        pd.x    += delta_pos.x;
        pd.y    += delta_pos.y;
        pd.z    += delta_pos.z;
        pd.qx    = cur_pd.qx;
        pd.qy    = cur_pd.qy;
        pd.qz    = cur_pd.qz;
        pd.qw    = cur_pd.qw;
        pd.valid = cur_pd.valid;
        return;
    }
コード例 #10
0
    public PenData FetchFrame(string tracked_ojbect)
    {
        PenData point    = FetchNewViconFrame(tracked_ojbect);
        int     attempts = 0;

        while (point.valid != 2 && attempts < 20)
        {
            point = FetchNewViconFrame(tracked_ojbect);
            attempts++;
        }
#if Debug
        if (point.valid != 2)
        {
            Debug.LogFormat("Failed to fetch a new frame! Result: {0}", point.valid);
        }
#endif

        return(point);
    }
コード例 #11
0
ファイル: ChartArea.cs プロジェクト: aracosta1/rt-chart
        /// <summary>
        /// Calculate the currently highest and lowest value, for Relative ScaleMode
        /// and put the result in the Pen data area
        /// </summary>
        /// <returns></returns>
        private void GetMinMaxValueForRelativeMode(PenData pen)
        {
            Int32 maxValue = Int32.MinValue;
            Int32 minValue = Int32.MaxValue;

            for (int i = 0; i < pen.dataValues.Count; i++)
            {
                // Set if higher then previous max value
                if (pen.dataValues[i] > maxValue)
                {
                    maxValue = pen.dataValues[i];
                }
                if (pen.dataValues[i] < minValue)
                {
                    minValue = pen.dataValues[i];
                }
            }
            pen.currentMinValue = minValue;
            pen.currentMaxValue = maxValue;
        }
コード例 #12
0
ファイル: ChartArea.cs プロジェクト: aracosta1/rt-chart
        /// <summary>
        /// Calculates the vertical Position of a value in relation the chart size,
        /// Scale Mode and, if ScaleMode is Relative, to the current maximum value
        /// </summary>
        /// <param name="value">performance value</param>
        /// <returns>vertical Point position in Pixels</returns>
        private double CalcVerticalPosition(PenData pen, Int32 value)
        {
            double result = 0;

            if (pen.penStyle.ScaleMode == ScaleMode.Absolute)
            {
                result = (((double)value + pen.penStyle.Offset) / pen.penStyle.Scale) * (double)this.Height;
            }
            else if (pen.penStyle.ScaleMode == ScaleMode.Relative)
            {
                int delta = (pen.currentMaxValue - pen.currentMinValue);

                result = (delta > 0) ? ((value - pen.currentMinValue) * this.Height / delta) : 0;
            }

            // Invert the graph to have Y going up
            result = this.Height - result;

            return(result);
        }
コード例 #13
0
        public void maintainPens()
        {
            List <int> removalQueue = new List <int>();

            foreach (int penId in pens.Keys)
            {
                PenData pen = pens[penId];
                pen.lastDrawn--;
                if (pen.lastDrawn <= 0)
                {
                    discardRT(pen.rtHist);
                    discardRT(pen.rtOldPos);
                    removalQueue.Add(penId);
                }
            }
            foreach (int penId in removalQueue)
            {
                pens.Remove(penId);
            }
        }
コード例 #14
0
ファイル: DrawNodes.cs プロジェクト: siegjan6/HMI
        /// <summary>
        /// 更新流动画笔
        /// </summary>
        private void UpdateDisPen(bool IsStream)
        {
            if (disPen == null)
            {
                disPen = PenData.CreatePen(Rect, Path);
            }
            else if (disPen.Width != PenData.Width)
            {
                disPen.Dispose();
                disPen = PenData.CreatePen(Rect, Path);
            }

            if (IsStream)
            {
                if (disPen != null && disPen.DashStyle != DashStyle.Custom)
                {
                    float[] dashValues = { 1, 1 };
                    disPen.DashPattern = dashValues;
                }
            }
        }
コード例 #15
0
        public override void CreatingPaint(Graphics g)
        {
            List <PointF> ds = NodeDatas;

            if (ds != null && ds.Count > 1)
            {
                Pen           p    = PenData.CreatePen(Rect, Path);
                Brush         br   = BrushData.CreateBrush(Rect, Path);
                List <PointF> list = MyTools.ConvertBeziers(ds, true);

                if (list.Count > 0)
                {
                    GraphicsPath path = new GraphicsPath();
                    path.AddBeziers(list.ToArray());
                    g.FillPath(br, path);
                    g.DrawPath(p, path);
                }
                p.Dispose();
                br.Dispose();
            }
        }
コード例 #16
0
ファイル: ChartArea.cs プロジェクト: aracosta1/rt-chart
        public ChartArea()
        {
            InitializeComponent();

            // Initialize Variables

            chartSize     = 5000;
            waitingValues = new ConcurrentQueue <DataSample>();

            penData = new PenData[MAX_PEN];
            for (int i = 0; i < MAX_PEN; i++)
            {
                penData[i] = new PenData(ChartSize);
            }

            chartStyle = new ChartStyle();
            chartStyle.BackgroundColorBottom = Color.Black;
            chartStyle.BackgroundColorTop    = Color.Black;

            penData[0].penStyle.ChartLinePen.Color = Color.Red;
            penData[1].penStyle.ChartLinePen.Color = Color.LimeGreen;
            penData[2].penStyle.ChartLinePen.Color = Color.Blue;
            penData[3].penStyle.ChartLinePen.Color = Color.Yellow;

            chartStyle = new ChartStyle();


            // Set Optimized Double Buffer to reduce flickering
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            // Redraw when resized
            this.SetStyle(ControlStyles.ResizeRedraw, true);

            this.Font = SystemInformation.MenuFont;
        }
コード例 #17
0
        public FormMain()
        {
            InitializeComponent();
            checkProcessArchMatch();
            checkOSVersion();

            CurrentPath       = new Uri(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
            CurrentPath       = System.IO.Path.GetDirectoryName(CurrentPath);
            LogFilePacketTime = CurrentPath + "\\PacketTime.log";
            if (!DeviceManager.Found())
            {
                installCert();
                DeviceManager.installDevice();
                if (!DeviceManager.Found())
                {
                    MessageBox.Show("Could not find S-Pen Virtual Device. Did you agree to install the driver?", "SPenClient error - no device");
                    Environment.Exit(1);
                }
            }
            hwr = new HIDWriter();
            pen = new PenData(this);
            init(12333);
            updateScreenProperties();
        }
コード例 #18
0
        private void runShader(DrawCommand dc)  //int penId, RenderTexture rtPos, Color color, float maxDist, bool preserveAlpha, bool smoothTip, float smoothTipExp, float width, float strength, float opacity, float fade, bool prevPainted, bool historyDecay, float historyDecayTime) {
        {
            if (!ensureTextures(dc.penId))
            {
                return;
            }

            RenderTexture rtHist   = null;
            RenderTexture rtOldPos = null;
            PenData       pen      = null;

            if (pens.TryGetValue(dc.penId, out pen))
            {
                rtHist   = pen.rtHist;
                rtOldPos = pen.rtOldPos;
                if (dc.rtPos != null && (dc.strength > 0.0f || dc.opacity > 0.0f))
                {
                    pen.lastDrawn = 3;
                }
                dc.prevPainted = pen.checkPrevPainted(dc.strength, dc.opacity, dc.color, dc.prevPainted, dc.smoothTip, dc.smoothTipExp);
            }

            texProcMat.SetTexture("_MainTex", rtCurrent);
            texProcMat.SetTexture("_OrigTex", rtOriginal);
            if (dc.prevPainted)
            {
                texProcMat.SetTexture("_HistTex", rtHist);
                texProcMat.SetTexture("_CoordTexA", rtOldPos);
            }
            else
            {
                if (pen != null && pen.rtHist != null)
                {
                    discardRT(pen.rtHist);
                    pen.rtHist = null;
                    rtHist     = null;
                }
                texProcMat.SetTexture("_HistTex", null);
                texProcMat.SetTexture("_CoordTexA", dc.rtPos);
            }
            if (dc.rtPos == null)
            {
                texProcMat.SetTexture("_CoordTexA", null);
            }
            texProcMat.SetTexture("_CoordTexB", dc.rtPos);
            texProcMat.SetFloat("_Fade", dc.fade);
            texProcMat.SetFloat("_SurfaceID", (float)id);
            texProcMat.SetFloat("_MaxDist", dc.maxDist / (float)rtCurrent.width);
            texProcMat.SetFloat("_PreserveAlpha", dc.preserveAlpha ? 1.0f : 0.0f);
            texProcMat.SetColor("_PenColor", dc.color);
            texProcMat.SetFloat("_PenThickness", dc.width / (float)rtCurrent.width);
            texProcMat.SetFloat("_SmoothTip", dc.smoothTip ? 1.0f : 0.0f);
            texProcMat.SetFloat("_SmoothExp", dc.smoothTipExp);
            texProcMat.SetFloat("_Opacity", dc.opacity);
            texProcMat.SetFloat("_EraserStrength", dc.strength);
            texProcMat.SetTexture("_StampTex", dc.stampTexture);
            Vector4 stampSize = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);

            stampSize.x = (dc.stampPixelSize.x / rtCurrent.width) * dc.stampScaleFactor.x;
            stampSize.y = (dc.stampPixelSize.y / rtCurrent.width) * dc.stampScaleFactor.y;
            texProcMat.SetVector("_StampSize", stampSize);
            texProcMat.SetFloat("_StampAngle", dc.stampAngle);
            texProcMat.SetFloat("_StampAlpha", dc.stampOpacity);
            texProcMat.SetColor("_StampTint", dc.tintColor);
            texProcMat.SetColor("_StampTintFactor", dc.enableTint ? dc.tintStrength : new Vector4(0.0f, 0.0f, 0.0f, 0.0f));
            texProcMat.SetFloat("_HistoryWrite", 0.0f);
            texProcMat.SetFloat("_HistoryTime", dc.historyDecay ? dc.historyDecayTime : 0.000001f);
            if (pen != null)
            {
                float decay = dc.historyDecay ? Time.time - pen.lastTime : 0.0f;
                texProcMat.SetFloat("_HistoryDecay", decay);
            }
            else
            {
                texProcMat.SetFloat("_HistoryDecay", 0.0f);
            }

            RenderTexture rtNew = RenderTexture.GetTemporary(rtCurrent.width, rtCurrent.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);

            if (rtNew.useMipMap)
            {
                rtNew.Release();
                rtNew.useMipMap = false;
                rtNew.Create();
            }
            rtNew.wrapMode = rtCurrent.wrapMode;
            if (rtCurrent == targetMaterial.mainTexture)
            {
                Graphics.Blit(rtCurrent, rtNew, texProcMat);
            }
            else
            {
                Graphics.Blit(targetMaterial.mainTexture, rtNew, texProcMat);
            }
            targetMaterial.mainTexture = rtNew;
            discardRT(rtCurrent);
            rtCurrent = rtNew;

            if (pen != null)
            {
                if ((dc.opacity > 0.0f && dc.opacity < 1.0f) || (dc.strength > 0.0f && dc.strength < 1.0f) || dc.smoothTip)
                {
                    rtNew = RenderTexture.GetTemporary(rtCurrent.width, rtCurrent.height, 0, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear);
                    if (rtNew.useMipMap)
                    {
                        rtNew.Release();
                        rtNew.useMipMap = false;
                        rtNew.Create();
                    }
                    rtNew.wrapMode = rtCurrent.wrapMode;
                    texProcMat.SetTexture("_MainTex", null);
                    texProcMat.SetTexture("_OrigTex", null);
                    texProcMat.SetTexture("_HistTex", rtHist);
                    texProcMat.SetFloat("_Fade", 0.0f);
                    texProcMat.SetColor("_PenColor", Color.white);
                    texProcMat.SetVector("_StampSize", new Vector2(0.0f, 0.0f));
                    texProcMat.SetFloat("_Opacity", 1.0f);
                    texProcMat.SetFloat("_EraserStrength", 0.0f);
                    pen.lastTime = Time.time;
                    texProcMat.SetFloat("_HistoryWrite", 1.0f);
                    Graphics.Blit(rtCurrent, rtNew, texProcMat);
                    discardRT(pen.rtHist);
                    pen.rtHist = rtNew;
                }
                else
                {
                    discardRT(pen.rtHist);
                    pen.rtHist = null;
                }
                Graphics.Blit(dc.rtPos, pen.rtOldPos);
            }
            targetMaterial.renderQueue = renderQueue;
        }