Esempio n. 1
0
    AnnotationInk CreateAnnotationInk(XmlNode xmlAnnotation)
    {
        AnnotationInk annotationInk = new AnnotationInk ();

        XmlNode xmlElements = null;
        XmlNodeList annotationChildNodeList = xmlAnnotation.ChildNodes;
        for (int w = 0; w < annotationChildNodeList.Count; w++) {
            xmlElements = annotationChildNodeList.Item (w);
            switch (xmlElements.Name) {

            case "formatting":
                //Debug.Log ("formatting: " + xmlElements.InnerText);
                XmlNodeList formattingChildNodes = xmlElements.ChildNodes;
                XmlNode xmlColor = formattingChildNodes.Item (0);

                FormattingInk formattingInk = new FormattingInk ();
                int red = Int32.Parse (formattingChildNodes.Item (0).ChildNodes.Item (0).InnerText);
                int green = Int32.Parse (formattingChildNodes.Item (0).ChildNodes.Item (1).InnerText);
                int blue = Int32.Parse (formattingChildNodes.Item (0).ChildNodes.Item (2).InnerText);
                formattingInk.Color = new Color32 ((byte)red, (byte)green, (byte)blue, 0);

                XmlNode xmlThickness = formattingChildNodes.Item (1);
                formattingInk.Thickness = Int32.Parse(xmlThickness.InnerText);
                annotationInk.FormattingInk = formattingInk;

                break;

            case "path":
                XmlNodeList pathXmlList = xmlElements.ChildNodes;
                List<Vector2> pathList = new List<Vector2>();
                int x = 0;
                for (int j = 0; j < pathXmlList.Count; j++) {
                    if(pathXmlList.Item (j).Name.Equals("x")) {
                        x = Int32.Parse(pathXmlList.Item (j).InnerText);
                    }
                    if(pathXmlList.Item (j).Name.Equals("y")) {
                        Vector2 position = new Vector2();
                        position.x = x;
                        position.y = Int32.Parse(pathXmlList.Item (j).InnerText);

                        pathList.Add(position);
                    }
                }
                annotationInk.Paths = pathList;

                break;

            default:
                break;
            }
        }

        annotationInk = (AnnotationInk) AddAnnotationCommonFields (xmlAnnotation, annotationInk);

        return annotationInk;
    }
Esempio n. 2
0
    public void LoadFromFile()
    {
        List<AnnotationText> textAnnotationList = new List<AnnotationText> ();
        List<AnnotationMark> markAnnotationList = new List<AnnotationMark> ();
        List<AnnotationInk> inkAnnotationList = new List<AnnotationInk> ();
        List<AnnotationLink> linkAnnotationList = new List<AnnotationLink>();

        if (annotationXmlPath == null) {
            Debug.Log ("ERROR - XML path null");
            return;
        }

        TextAsset textAsset = new TextAsset();
        textAsset = (TextAsset)Resources.Load(annotationXmlPath, typeof(TextAsset));

        if (textAsset == null) {
            if(annotationXmlPath.Contains(".xml")) {
               Debug.Log ("ERROR - the filename can't have extension. Delete .xml from the filename");
            }
            else {
                Debug.Log ("ERROR - There was a problem loading xml file");
            }
            return;
        }

        XmlDocument xml = new XmlDocument ();
        xml.LoadXml (textAsset.text);

        // Load Take
        XmlNodeList xmlTakeList = xml.SelectNodes ("/annotation_document/session/take");
        for (int j = 0; j < xmlTakeList.Count; j++) {

            XmlNodeList xmlAnnotationSetList = xmlTakeList.Item(j).SelectNodes("annotations/annotation_set");
            if(xmlAnnotationSetList.Count == 0)
                continue;

            take =  CreateTake(xmlTakeList.Item(j));
            if(take == null) {
                Debug.Log("ERROR creating class Take");
                return;
            }

            // Load Annotations
            //XmlNodeList xmlAnnotationSetList = xml.SelectNodes ("/annotation_document/session/take/annotations/annotation_set");
            int nNodes = xmlAnnotationSetList.Count;
            //Debug.Log ("annotation set count: " + nNodes);
            for (int i = 0; i < nNodes; i++) {
                    //Debug.Log("annotation set name: " + xmlAnnotationSetList.Item(i).Name);
                    XmlNodeList tmpList = xmlAnnotationSetList.Item (i).SelectNodes ("annotation");
                    //Debug.Log("annotation count: " + tmpList.Count);
                    for (int w = 0; w < tmpList.Count; w++) {
                            XmlNode xmlAnnotation = tmpList.Item (w);

                            //	Debug.Log("type = " + xmlAnnotation.Attributes[0].InnerText);
                            switch (xmlAnnotation.Attributes [0].InnerText) {

                            case "text":
                                    AnnotationText annotation = CreateAnnotationText (xmlAnnotation);
                                    if(annotation == null)
                                        continue;

                                    annotation.Type = "text";
                                    textAnnotationList.Add (annotation);
                                    Debug.Log ("TEXT annotation");
                                    continue;
                            case "mark":
                                    AnnotationMark annotationMark = new AnnotationMark ();
                                    annotationMark.Type = "mark";
                                    annotationMark = (AnnotationMark)AddAnnotationCommonFields (xmlAnnotation, annotationMark);
                                    markAnnotationList.Add (annotationMark);
                                    Debug.Log ("MARK annotation");
                                    continue;
                            case "ink":
                                    AnnotationInk annotationInk = new AnnotationInk ();
                                    annotationInk.Type = "ink";
                                    annotationInk = CreateAnnotationInk (xmlAnnotation);
                                    inkAnnotationList.Add (annotationInk);
                                    Debug.Log ("INK annotation");
                                    continue;
                            case "link":
                                    AnnotationLink annotationLink = new AnnotationLink ();
                                    annotationLink.Type = "link";
                                    annotationLink = CreateAnnotationLink (xmlAnnotation);
                                    linkAnnotationList.Add (annotationLink);
                                    Debug.Log ("LINK annotation");
                                    continue;
                            case "audio":
                                    Debug.Log ("Audio annotation");
                                    continue;
                            default:
                                    continue;
                            }
                    }
            }

            take.TextAnnotationList = textAnnotationList;
            take.InkAnnotationList = inkAnnotationList;
            take.MarkAnnotationList = markAnnotationList;
            take.LinkAnnotationList = linkAnnotationList;
            Debug.Log ("Number of Text Annotation: " + take.TextAnnotationList.Count);
            Debug.Log ("Number of Mark Annotation: " + take.MarkAnnotationList.Count);
            Debug.Log ("Number of Ink Annotation: " + take.InkAnnotationList.Count);
            Debug.Log ("Number of Link Annotation: " + take.LinkAnnotationList.Count);
        }
    }
    AnnotationInk CreateAnnotationInk(XmlNode xmlAnnotation)
    {
        AnnotationInk annotationInk = new AnnotationInk();

        XmlNode     xmlElements             = null;
        XmlNodeList annotationChildNodeList = xmlAnnotation.ChildNodes;

        for (int w = 0; w < annotationChildNodeList.Count; w++)
        {
            xmlElements = annotationChildNodeList.Item(w);
            switch (xmlElements.Name)
            {
            case "formatting":
                //Debug.Log ("formatting: " + xmlElements.InnerText);
                XmlNodeList formattingChildNodes = xmlElements.ChildNodes;
                XmlNode     xmlColor             = formattingChildNodes.Item(0);

                FormattingInk formattingInk = new FormattingInk();
                int           red           = Int32.Parse(formattingChildNodes.Item(0).ChildNodes.Item(0).InnerText);
                int           green         = Int32.Parse(formattingChildNodes.Item(0).ChildNodes.Item(1).InnerText);
                int           blue          = Int32.Parse(formattingChildNodes.Item(0).ChildNodes.Item(2).InnerText);
                formattingInk.Color = new Color32((byte)red, (byte)green, (byte)blue, 0);


                XmlNode xmlThickness = formattingChildNodes.Item(1);
                formattingInk.Thickness     = Int32.Parse(xmlThickness.InnerText);
                annotationInk.FormattingInk = formattingInk;

                break;

            case "path":
                XmlNodeList    pathXmlList = xmlElements.ChildNodes;
                List <Vector2> pathList    = new List <Vector2>();
                int            x           = 0;
                for (int j = 0; j < pathXmlList.Count; j++)
                {
                    if (pathXmlList.Item(j).Name.Equals("x"))
                    {
                        x = Int32.Parse(pathXmlList.Item(j).InnerText);
                    }
                    if (pathXmlList.Item(j).Name.Equals("y"))
                    {
                        Vector2 position = new Vector2();
                        position.x = x;
                        position.y = Int32.Parse(pathXmlList.Item(j).InnerText);

                        pathList.Add(position);
                    }
                }
                annotationInk.Paths = pathList;

                break;

            default:
                break;
            }
        }

        annotationInk = (AnnotationInk)AddAnnotationCommonFields(xmlAnnotation, annotationInk);

        return(annotationInk);
    }
    public void LoadFromFile()
    {
        List <AnnotationText> textAnnotationList = new List <AnnotationText> ();
        List <AnnotationMark> markAnnotationList = new List <AnnotationMark> ();
        List <AnnotationInk>  inkAnnotationList  = new List <AnnotationInk> ();
        List <AnnotationLink> linkAnnotationList = new List <AnnotationLink>();

        if (annotationXmlPath == null)
        {
            Debug.Log("ERROR - XML path null");
            return;
        }

        TextAsset textAsset = new TextAsset();

        textAsset = (TextAsset)Resources.Load(annotationXmlPath, typeof(TextAsset));

        if (textAsset == null)
        {
            if (annotationXmlPath.Contains(".xml"))
            {
                Debug.Log("ERROR - the filename can't have extension. Delete .xml from the filename");
            }
            else
            {
                Debug.Log("ERROR - There was a problem loading xml file");
            }
            return;
        }

        XmlDocument xml = new XmlDocument();

        xml.LoadXml(textAsset.text);



        // Load Take
        XmlNodeList xmlTakeList = xml.SelectNodes("/annotation_document/session/take");

        for (int j = 0; j < xmlTakeList.Count; j++)
        {
            XmlNodeList xmlAnnotationSetList = xmlTakeList.Item(j).SelectNodes("annotations/annotation_set");
            if (xmlAnnotationSetList.Count == 0)
            {
                continue;
            }

            take = CreateTake(xmlTakeList.Item(j));
            if (take == null)
            {
                Debug.Log("ERROR creating class Take");
                return;
            }

            // Load Annotations
            //XmlNodeList xmlAnnotationSetList = xml.SelectNodes ("/annotation_document/session/take/annotations/annotation_set");
            int nNodes = xmlAnnotationSetList.Count;
            //Debug.Log ("annotation set count: " + nNodes);
            for (int i = 0; i < nNodes; i++)
            {
                //Debug.Log("annotation set name: " + xmlAnnotationSetList.Item(i).Name);
                XmlNodeList tmpList = xmlAnnotationSetList.Item(i).SelectNodes("annotation");
                //Debug.Log("annotation count: " + tmpList.Count);
                for (int w = 0; w < tmpList.Count; w++)
                {
                    XmlNode xmlAnnotation = tmpList.Item(w);

                    //	Debug.Log("type = " + xmlAnnotation.Attributes[0].InnerText);
                    switch (xmlAnnotation.Attributes [0].InnerText)
                    {
                    case "text":
                        AnnotationText annotation = CreateAnnotationText(xmlAnnotation);
                        if (annotation == null)
                        {
                            continue;
                        }

                        annotation.Type = "text";
                        textAnnotationList.Add(annotation);
                        Debug.Log("TEXT annotation");
                        continue;

                    case "mark":
                        AnnotationMark annotationMark = new AnnotationMark();
                        annotationMark.Type = "mark";
                        annotationMark      = (AnnotationMark)AddAnnotationCommonFields(xmlAnnotation, annotationMark);
                        markAnnotationList.Add(annotationMark);
                        Debug.Log("MARK annotation");
                        continue;

                    case "ink":
                        AnnotationInk annotationInk = new AnnotationInk();
                        annotationInk.Type = "ink";
                        annotationInk      = CreateAnnotationInk(xmlAnnotation);
                        inkAnnotationList.Add(annotationInk);
                        Debug.Log("INK annotation");
                        continue;

                    case "link":
                        AnnotationLink annotationLink = new AnnotationLink();
                        annotationLink.Type = "link";
                        annotationLink      = CreateAnnotationLink(xmlAnnotation);
                        linkAnnotationList.Add(annotationLink);
                        Debug.Log("LINK annotation");
                        continue;

                    case "audio":
                        Debug.Log("Audio annotation");
                        continue;

                    default:
                        continue;
                    }
                }
            }

            take.TextAnnotationList = textAnnotationList;
            take.InkAnnotationList  = inkAnnotationList;
            take.MarkAnnotationList = markAnnotationList;
            take.LinkAnnotationList = linkAnnotationList;
            Debug.Log("Number of Text Annotation: " + take.TextAnnotationList.Count);
            Debug.Log("Number of Mark Annotation: " + take.MarkAnnotationList.Count);
            Debug.Log("Number of Ink Annotation: " + take.InkAnnotationList.Count);
            Debug.Log("Number of Link Annotation: " + take.LinkAnnotationList.Count);
        }
    }
Esempio n. 5
0
    void WriteInkAnnotation(AnnotationInk annotationInk)
    {
        List<Vector2> pointList = annotationInk.Paths;

        GameObject inkAnnotation3D = new GameObject ();
        LineRenderer lineRenderer = inkAnnotation3D.AddComponent<LineRenderer>();
        lineRenderer.SetVertexCount (pointList.Count);
        lineRenderer.material = new Material (Shader.Find("Particles/Additive")); // TODO
        lineRenderer.SetWidth((float) annotationInk.FormattingInk.Thickness,
                              (float)annotationInk.FormattingInk.Thickness);
        lineRenderer.material.color = annotationInk.FormattingInk.Color;
        lineRenderer.transform.position = annotationInk.PositionKin;

        int i = 0;
        foreach (Vector2 pos in pointList) {

            lineRenderer.SetPosition(i, new Vector3(pos.x, pos.y, 0));
            i++;
        }

        // CALIBRATION
        Calibration calibration = calibrations[currentCalibration];

        lineRenderer.transform.Rotate (calibration.RotationX,
                                       calibration.RotationY, calibration.RotationZ);

        lineRenderer.transform.Translate (calibration.Position.x,
                                          calibration.Position.y, calibration.Position.z);

        gameObjectsInTheScene.Add(lineRenderer.gameObject);
    }