Interactive Ink

Answered

How to test myscript iink sdk using our private stroke data

We want to test the performance of Myscript sdk, and run the wpf demo successfully, but, we don't know how to use our own stroke data (contains point and stroke information) test the sdk. If there is any code or example for help, we will appreciate it. Thank you~


Best Answer

Dear Zhang Junhui,


Thank you for the ink, which helped understand the issue.


Currently, the issue is that you are using a "Text Document" part, while you should use a "Text" part instead. This can be done setting the "PART_TYPE" to "Text":

private const string PART_TYPE = "Text";


Once done, also ensure to disable the guide lines:

_engine.Configuration.SetString("content-package.temp-folder", tempFolder);
_engine.Configuration.SetString("lang", "zh_CN");
_engine.Configuration.SetBoolean("text.guides.enable", false);


You can also refer the to "Off-screen usage" part of the documentation, that explains how to proceed : https://developer.myscript.com/docs/interactive-ink/1.3/android/advanced/off-screen-usage/


Feel free to contact us if you have any other question.


Best regards,


Olivier


Dear Zhang Junhui,


Thank you for contacting us and your question.


Currently, to use your own stroke data, you can refer to the "Off-screen usage" part of the documentation: https://developer.myscript.com/docs/interactive-ink/1.3/windows/advanced/off-screen-usage/


You should then add your own ink as series of pointer events: https://developer.myscript.com/docs/interactive-ink/1.3/windows/fundamentals/editing/#input-capture


The result can be gotten doing an export: https://developer.myscript.com/docs/interactive-ink/1.3/windows/fundamentals/import-and-export/#exporting-content


Let us know if you have further questions.


Best regards,


Olivier

I successfully put our stroke points into editor, but an error occurred as: "ink rejected: stroke is too large (write smaller)". Is that mean, our stroke data should be rescaled? Is there any other way to solve the problem?  

I editted the code of iink wpf demo, by adding "test_stroke_data("../../../../transquence/data/stroke_data/data");" at last line:

 private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Initialize Interactive Ink runtime environment
                _engine = Engine.Create(MyScript.Certificate.MyCertificate.Bytes);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }

            // Folders "conf" and "resources" are currently parts of the layout
            // (for each conf/res file of the project => properties => "Build Action = content")
            string[] confDirs = new string[1];
            confDirs[0] = "conf";
            _engine.Configuration.SetStringArray("configuration-manager.search-path", confDirs);

            var localFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            var tempFolder =  Path.Combine(localFolder, "MyScript", "tmp");
            _engine.Configuration.SetString("content-package.temp-folder", tempFolder);
            _engine.Configuration.SetString("lang", "zh_CN");

            // Initialize the editor with the engine
            UcEditor.Engine = _engine;
            UcEditor.Initialize(this);
            // Force pointer to be a pen, for an automatic detection, set InputMode to AUTO
            SetInputMode(InputMode.PEN);
            NewFile();
            test_stroke_data("../../../../transquence/data/stroke_data/data");
        }

   and the the function like:  

private void test_stroke_data(String data_path) {
            StreamReader rd = File.OpenText(data_path);
            String line = rd.ReadLine();
            while (line!=null) {
                _editor.Clear();
                string[] data = line.Split(',');
                int num_stroke = Convert.ToInt32(data[0]);
                int[] num_stroke_coorxy = new int[num_stroke];
                for (int i = 1; i <= num_stroke; i++) {
                    num_stroke_coorxy[i - 1] = Convert.ToInt32(data[i]);
                }

                int st_point_xind = num_stroke + 1;
                int p_st = st_point_xind;
                for (int i = 0; i < num_stroke; i++)
                {
                    int stroke_num_point = num_stroke_coorxy[i];
                    for (int j = p_st; j < p_st + stroke_num_point - 1; )
                    {
                        float x = Convert.ToSingle(data[j]);
                        float y = Convert.ToSingle(data[j + 1]);
                        if (j == p_st)
                        {
                            _editor.PointerDown(x, y, -1, 0.0f, PointerType.PEN, -1);
                            if (stroke_num_point == 2) {
                                _editor.PointerUp(x, y, -1, 0.0f, PointerType.PEN, -1);
                            }
                        }
                        else if (j == p_st + stroke_num_point - 2) {
                            _editor.PointerUp(x, y, -1, 0.0f, PointerType.PEN, -1);
                        }
                        else
                        {
                            _editor.PointerMove(x, y, -1, 0.0f, PointerType.PEN, -1);
                        }
                        j += 2;
                    }
                    p_st += stroke_num_point;
                }

                _editor.WaitForIdle();
                var result = _editor.Export_(_editor.GetRootBlock(), MimeType.TEXT);
                Console.WriteLine(result);
                line = rd.ReadLine();
            }
        }

  

Dear Zhang Junhui,


thank you for the update.


After having a look to the way you add your strokes, this looks correct.


Nevertheless, in the EditorUserControl, can you confirm you set the proper resolution (the one of your input device) and a null render target when creating the renderer: _renderer = _engine.CreateRenderer(xinputDeviceResolution, yinputDeviceResolution, NULL);


Let us know if this helps. If not, please attach a data file, so that we can reproduce.


Best regards,


Olivier

thank you for your responce, I rescaled our stroke data, resolved the error, but got some new error like:"ink rejected: stroke is out of document bounds" and "ink rejected: stroke is above first line", is that mean I should put the stroke line to right position? what should I do?

I don't konw how to attach a file, so I paste one line of the rescaled data as below : 

...

Answer

Dear Zhang Junhui,


Thank you for the ink, which helped understand the issue.


Currently, the issue is that you are using a "Text Document" part, while you should use a "Text" part instead. This can be done setting the "PART_TYPE" to "Text":

private const string PART_TYPE = "Text";


Once done, also ensure to disable the guide lines:

_engine.Configuration.SetString("content-package.temp-folder", tempFolder);
_engine.Configuration.SetString("lang", "zh_CN");
_engine.Configuration.SetBoolean("text.guides.enable", false);


You can also refer the to "Off-screen usage" part of the documentation, that explains how to proceed : https://developer.myscript.com/docs/interactive-ink/1.3/android/advanced/off-screen-usage/


Feel free to contact us if you have any other question.


Best regards,


Olivier


1 person likes this

Thank you Oliver! I successfully tested our data under your suggestion, you are great!