Exemple #1
0
    /// <summary>
    /// Loads the transfer function file at the given file path, if there is one.
    /// </summary>
    /// <param name="filePath"></param>
    public void loadTransferFunction(string filePath)
    {
        try
        {
            // Read the JSON file specified by the path
            StreamReader reader       = new StreamReader(filePath);
            string       textFromFile = reader.ReadToEnd();
            reader.Close();

            // Create a temporary serializeable object to store the points
            ControlPointLists newPoints = JsonUtility.FromJson <ControlPointLists>(textFromFile);
            alphaPoints = newPoints.alphaPoints;
            colorPoints = newPoints.colorPoints;

            //// Scale the transfer function points to the current isovalue range (added for 16-bit support)
            //for (int i = 0; i < newPoints.alphaPoints.Count; i++)
            //{
            //	newPoints.alphaPoints[i].isovalue = (int) Mathf.Clamp((float)Math.Round((newPoints.alphaPoints[i].isovalue / 65535.0f) * isovalueRange), 0, isovalueRange);
            //}

            //for (int i = 0; i < newPoints.colorPoints.Count; i++)
            //{
            //	newPoints.colorPoints[i].isovalue = (int)Mathf.Clamp((float)Math.Round((newPoints.colorPoints[i].isovalue / 65535.0f) * isovalueRange), 0, isovalueRange);
            //}

            // Tell the transfer function update
            transferFunctionChanged = true;

            Debug.Log("Transfer function loaded.");
        }
        catch (Exception e)
        {
            Debug.Log("Failed to load transfer function due to exception: " + e);
        }
    }
Exemple #2
0
    /*****************************************************************************
    * TRANSFER FUNCTION FILE IO
    *****************************************************************************/
    /// <summary>
    /// Saves the current control points to the given path.
    /// </summary>
    /// <param name="filePath"></param>
    public void saveTransferFunction(string filePath)
    {
        try
        {
            // Create a temporary serializeable object for saving
            ControlPointLists points = new ControlPointLists();
            points.alphaPoints = alphaPoints;
            points.colorPoints = colorPoints;

            //// Scale the transfer function points to the 16-bit range (0-65535)
            //for (int i = 0; i < points.alphaPoints.Count; i++)
            //{
            //	points.alphaPoints[i].isovalue = (int)Mathf.Clamp((float)Math.Round((points.alphaPoints[i].isovalue / (float) isovalueRange) * 65535), 0, 65535);
            //}

            //for (int i = 0; i < points.colorPoints.Count; i++)
            //{
            //	points.colorPoints[i].isovalue = (int)Mathf.Clamp((float)Math.Round((points.colorPoints[i].isovalue / (float) isovalueRange) * 65535), 0, 65535);
            //}

            // Write the points object to JSON
            string jsonString = JsonUtility.ToJson(points, true);

            // Write the JSON to the file specified by the path
            StreamWriter writer = new StreamWriter(filePath, false);
            writer.Write(jsonString);
            writer.Close();

            Debug.Log("Transfer function saved.");
        }
        catch (Exception e)
        {
            Debug.Log("Failed to save transfer function due to exception: " + e);
        }
    }
Exemple #3
0
    /// <summary>
    /// Loads the transfer function file at the given file path, if there is one.
    /// </summary>
    /// <param name="filePath"></param>
    public void loadTransferFunction(string filePath)
    {
        try
        {
            // Read the JSON file specified by the path
            StreamReader reader       = new StreamReader(filePath);
            string       textFromFile = reader.ReadToEnd();
            reader.Close();

            // Create a temporary serializeable object to store the points
            ControlPointLists newPoints = JsonUtility.FromJson <ControlPointLists>(textFromFile);
            alphaPoints = newPoints.alphaPoints;
            colorPoints = newPoints.colorPoints;

            // Tell the transfer function update
            transferFunctionChanged = true;

            Debug.Log("Transfer function loaded.");
        }
        catch (Exception e)
        {
            Debug.Log("Failed to load transfer function due to exception: " + e);
        }
    }
Exemple #4
0
    /*****************************************************************************
    * TRANSFER FUNCTION FILE IO
    *****************************************************************************/
    /// <summary>
    /// Saves the current control points to the given path.
    /// </summary>
    /// <param name="filePath"></param>
    public void saveTransferFunction(string filePath)
    {
        try
        {
            // Create a temporary serializeable object for saving
            ControlPointLists points = new ControlPointLists();
            points.alphaPoints = alphaPoints;
            points.colorPoints = colorPoints;

            // Write the points object to JSON
            string jsonString = JsonUtility.ToJson(points, true);

            // Write the JSON to the file specified by the path
            StreamWriter writer = new StreamWriter(filePath, false);
            writer.Write(jsonString);
            writer.Close();

            Debug.Log("Transfer function saved.");
        }
        catch (Exception e)
        {
            Debug.Log("Failed to save transfer function due to exception: " + e);
        }
    }