Exemple #1
0
    TransferFunction SerializeToTransferFunction()
    {
        TransferFunction serTf = new TransferFunction();

        serTf.type    = 0;
        serTf.maskMax = -maxGameObject.transform.localPosition.y / 3.0f;
        serTf.maskMin = -minGameObject.transform.localPosition.y / 3.0f;

        serTf.points = new List <TfPoint>();

        var pContainer = transform.Find("Points");

        //Clear old
        foreach (Transform child in pContainer.transform)
        {
            //Position
            TfPoint tp = new TfPoint();
            tp.pos = Mathf.Abs(child.localPosition.y / 3.0f);

            //Color
            Color colTemp = child.GetComponent <TransferFunctionSwatch>().selectedColor;
            tp.rgba = new Vector4(colTemp.r, colTemp.g, colTemp.b, colTemp.a);
            serTf.points.Add(tp);
        }

        return(serTf);
    }
    public TransferFunction loadTransferFunction(string filename)
    {
        var         fileContents = File.ReadAllText(filename);
        XmlDocument xmlDoc       = new XmlDocument();

        xmlDoc.Load(new StringReader(fileContents));
        string  xmlPathPattern = ".//Processor[@type='org.inviwo.VolumeRaycaster']//TransferFunction";
        XmlNode tfNode         = xmlDoc.SelectSingleNode(xmlPathPattern);

        Debug.Log(tfNode.ToString());
        TransferFunction tf = new TransferFunction();

        tf.points = new List <TfPoint>();

        if (tfNode != null)
        {
            try
            {
                //Create tf
                if (tfNode.SelectSingleNode("type/@content") != null)
                {
                    tf.type = Int32.Parse(tfNode.SelectSingleNode("type/@content").Value);
                }
                else
                {
                    tf.type = 0;
                }
                tf.maskMax = float.Parse(tfNode.SelectSingleNode("maskMax/@content").Value);
                tf.maskMin = float.Parse(tfNode.SelectSingleNode("maskMin/@content").Value);
                XmlNodeList points = tfNode.SelectSingleNode("Points").ChildNodes;
                foreach (XmlNode p in points)
                {
                    TfPoint tfp = new TfPoint();
                    tfp.pos    = float.Parse(p.SelectSingleNode("pos/@content").Value, CultureInfo.InvariantCulture);
                    tfp.rgba.x = float.Parse(p.SelectSingleNode("rgba/@x").Value, CultureInfo.InvariantCulture);
                    tfp.rgba.y = float.Parse(p.SelectSingleNode("rgba/@y").Value, CultureInfo.InvariantCulture);
                    tfp.rgba.z = float.Parse(p.SelectSingleNode("rgba/@z").Value, CultureInfo.InvariantCulture);
                    tfp.rgba.w = float.Parse(p.SelectSingleNode("rgba/@w").Value, CultureInfo.InvariantCulture);
                    tf.points.Add(tfp);
                }
            }
            catch (Exception e)
            {
                Debug.LogWarning("TF parsing failed! Dump: " + e.Message + tfNode.InnerXml);
            }
        }
        return(tf);
    }