Пример #1
0
    //Load all annotations out of File in List
    private void loadAnnotationFromFile(object obj = null)
    {
        //Clear Screen
        //clearAll ();

        //get Annotation.json

        string path = this.path + "/annotation.json"; //TODO read from meta.json??

        if (!File.Exists (path)) {
            return;
        }

        List<AnnotationJson> apjList = new List<AnnotationJson> ();
        // Read the file
        string line;
        System.IO.StreamReader file = new System.IO.StreamReader (path);
        while ((line = file.ReadLine ()) != null) {
            AnnotationJson apj = JsonUtility.FromJson<AnnotationJson> (line);
            apjList.Add (apj);
        }
        file.Close ();

        //List of Json Objects -> AnnotationList
        rawAnnotation = apjList;
    }
Пример #2
0
    //Called by load Method in Patient to Create all Annotations in File
    public void createAnnotation(AnnotationJson annotation)
    {
        Quaternion rotation     = new Quaternion((float)annotation.RotationX, (float)annotation.RotationY, (float)annotation.RotationZ, (float)annotation.RotationW);
        Quaternion meshRotation = new Quaternion((float)annotation.MeshRotationX, (float)annotation.MeshRotationY, (float)annotation.MeshRotationZ, (float)annotation.MeshRotationW);
        Vector3    position     = new Vector3((float)annotation.PositionX, (float)annotation.PositionY, (float)annotation.PositionZ);

        //setup new Annotation as maesh and in List
        GameObject newAnnotation = createAnnotationGroup(annotation.type, rotation, position);

        if (annotation.type == AnnotationType.plane || annotation.type == AnnotationType.sphere)
        {
            newAnnotation.GetComponent <Annotation> ().myAnnotationMesh.transform.localRotation = meshRotation;
        }

        newAnnotation.GetComponent <Annotation> ().setLabeText(annotation.Text);

        //Color not empty (Black)
        if (annotation.ColorR != 0.0f || annotation.ColorG != 0.0f || annotation.ColorB != 0.0f)
        {
            newAnnotation.GetComponent <Annotation> ().changeColor(new Color(annotation.ColorR, annotation.ColorG, annotation.ColorB));
        }
        if (annotation.ScaleX == 0f)
        {
            newAnnotation.GetComponent <Annotation> ().rescaleMesh(new Vector3(1f, 1f, 1f));
        }
        else
        {
            newAnnotation.GetComponent <Annotation> ().rescaleMesh(new Vector3(annotation.ScaleX, annotation.ScaleY, annotation.ScaleZ));
        }

        createNewAnnotationListEntry(newAnnotation);
    }
Пример #3
0
    //Saves all annotations in a file
    public void saveAnnotation()
    {
        if (loadedPatient == null) {
            return;
        }

        string path = loadedPatient.path + "/annotation.json";

        //Create file if it not exists
        if (!File.Exists (path)) {
            using (StreamWriter outputFile = new StreamWriter (path, true)) {
                outputFile.Close ();
            }
        }

        //Write annotations in file
        using (StreamWriter outputFile = new StreamWriter (path)) {
            foreach (GameObject apListEntry in mAnnotations) {
                GameObject ap = apListEntry.GetComponent<AnnotationListEntry> ().getAnnotation ();
                if (ap != null) {
                    AnnotationJson apj = new AnnotationJson ();
                    apj.type = ap.GetComponent<Annotation> ().myType;
                    apj.Text = ap.GetComponent<Annotation> ().getLabelText ();
                    apj.ColorR = ap.GetComponent<Annotation> ().getColor ().r;
                    apj.ColorG = ap.GetComponent<Annotation> ().getColor ().g;
                    apj.ColorB = ap.GetComponent<Annotation> ().getColor ().b;
                    apj.ScaleX = ap.GetComponent<Annotation> ().getMeshScale ().x;
                    apj.ScaleY = ap.GetComponent<Annotation> ().getMeshScale ().y;
                    apj.ScaleZ = ap.GetComponent<Annotation> ().getMeshScale ().z;
                    apj.PositionX = ap.transform.localPosition.x;
                    apj.PositionY = ap.transform.localPosition.y;
                    apj.PositionZ = ap.transform.localPosition.z;

                    apj.RotationW = ap.transform.localRotation.w;
                    apj.RotationX = ap.transform.localRotation.x;
                    apj.RotationY = ap.transform.localRotation.y;
                    apj.RotationZ = ap.transform.localRotation.z;

                    apj.MeshRotationW = ap.GetComponent<Annotation> ().myAnnotationMesh.transform.localRotation.w;
                    apj.MeshRotationX = ap.GetComponent<Annotation> ().myAnnotationMesh.transform.localRotation.x;
                    apj.MeshRotationY = ap.GetComponent<Annotation> ().myAnnotationMesh.transform.localRotation.y;
                    apj.MeshRotationZ = ap.GetComponent<Annotation> ().myAnnotationMesh.transform.localRotation.z;

                    apj.Creator = ap.GetComponent<Annotation> ().creator;
                    apj.CreationDate = ap.GetComponent<Annotation> ().creationDate;
                    outputFile.WriteLine (JsonUtility.ToJson (apj));
                }
            }
            outputFile.Close ();
        }
        return;
    }