// Use this for initialization /// <summary> /// Initialization function for the AlphaPanelHandler. /// </summary> void Start() { //panelRectTransform = transform as RectTransform; drawCanvasRectTransform = alphaCanvas.transform as RectTransform; //maxWidth = panelRectTransform.rect.width - borderSize; //maxHeight = panelRectTransform.rect.height - borderSize; //minWidth = borderSize; //minHeight = borderSize; maxWidth = drawCanvasRectTransform.rect.width; maxHeight = drawCanvasRectTransform.rect.height; minWidth = 0.0f; minHeight = 0.0f; transferFunctionHandler = (TransferFunctionHandler)GameObject.Find("Transfer Function Panel").GetComponent(typeof(TransferFunctionHandler)); volumeController = (VolumeController)GameObject.Find("VolumeController").GetComponent(typeof(VolumeController)); transferFunction = volumeController.getTransferFunction(); maxIsovalueLabel.text = transferFunction.IsovalueRange.ToString(); // Initialize the control point renderers controlPointRenderers = new List <ControlPointRenderer>(); for (int i = 0; i < transferFunction.AlphaPoints.Count; i++) { controlPointRenderers.Add(new ControlPointRenderer(transferFunction.AlphaPoints[i], createControlPointImage(transferFunction.AlphaPoints[i])) ); } }
private Button saveButton; // The button used to save the current transfer function /// <summary> /// Initialization function for the TransferFunctionHandler. /// </summary> void Start() { // Set up the reference to the VolumeController volumeController = (VolumeController)GameObject.Find("VolumeController").GetComponent(typeof(VolumeController)); // Initialize the reference to the transfer function stored in the volume controller transferFunction = volumeController.getTransferFunction(); // Initialize the panel script references alphaPanelHandler = (AlphaPanelHandler)alphaPanel.GetComponent(typeof(AlphaPanelHandler)); colorPanelHandler = (ColorPanelHandler)colorPanel.GetComponent(typeof(ColorPanelHandler)); colorPaletteHandler = (ColorPalette)colorPalettePanel.GetComponent(typeof(ColorPalette)); // Set up the transfer function loading drop down menu and load the first transfer function in the list if (transferFunction.IsovalueRange == 255) { savedTransferFunctionFolderPath = "Assets/Resources/TransferFunctions8Bit/"; } else { savedTransferFunctionFolderPath = "Assets/Resources/TransferFunctions16Bit/"; } transferFunctionFileExtension = ".txt"; Button loadButton = (GameObject.Find("Load Button").GetComponent <Button>()); Button saveButton = (GameObject.Find("Save Button").GetComponent <Button>()); // Load "Assets/Resources/TransferFunctions" files into a list of strings List <string> fileNames = new List <string>(Directory.GetFiles(savedTransferFunctionFolderPath, "*.txt")); // Trim the directories from the file names for (int i = 0; i < fileNames.Count; i++) { fileNames[i] = Path.GetFileNameWithoutExtension(fileNames[i]); } // Populate the dropdown menu with these OptionData objects if (fileNames.Count > 0) { // Add the list of files to the dropdown menu dropdownMenu.AddOptions(fileNames); // Set the currentTransferFunctionFile to the first one in the list currentTransferFunctionFile = fileNames[0]; // Load the control points from the currentTransferFunctionFile, if there is one loadTransferFunction(); } else { // Populate the dropdown menu with dropdownMenu.AddOptions(new List <string>(new string[] { "New Transfer Function" })); // Deactivate the load button loadButton.interactable = false; } // Reset the flag transferFunction.TransferFunctionChanged = true; }
/// <summary> /// Initialization function for ColorPalette. /// </summary> void Start() { // Initialize the color palette text fields redValueText.text = redSlider.value.ToString(); greenValueText.text = greenSlider.value.ToString(); blueValueText.text = blueSlider.value.ToString(); volumeController = (VolumeController)GameObject.Find("VolumeController").GetComponent(typeof(VolumeController)); transferFunction = volumeController.getTransferFunction(); currentColor = new Color(0, 0, 0, 1); // Don't display/use the color palette on startup this.gameObject.SetActive(false); }
private void OnGUI() { volRend = FindObjectOfType <VolumeController>(); if (volRend == null) { return; } tf = volRend.getTransferFunction(); Color oldColour = GUI.color; float bgWidth = Mathf.Min(this.position.width - 40.0f, (this.position.height - 50.0f) * 2.0f); Rect bgRect = new Rect(leftOff, 0.0f, bgWidth, bgWidth * 0.5f); tf.GenerateTexture(); tfGUIMat.SetTexture("_TFTex", tf.GetTexture()); tfGUIMat.SetTexture("_HistTex", tf.getHistogramTexture()); Graphics.DrawTexture(bgRect, tf.GetTexture(), tfGUIMat); Texture2D tfTexture = tf.GetTexture(); tfPaletteGUIMat.SetTexture("_TFTex", tf.GetTexture()); Graphics.DrawTexture(new Rect(bgRect.x, bgRect.y + bgRect.height + 20, bgRect.width, 20.0f), tfTexture, tfPaletteGUIMat); // Colour control points for (int iCol = 0; iCol < tf.colourControlPoints.Count; iCol++) { TFColourControlPoint colPoint = tf.colourControlPoints[iCol]; Rect ctrlBox = new Rect(bgRect.x + bgRect.width * colPoint.dataValue, bgRect.y + bgRect.height + 20, 10, 20); GUI.color = Color.red; GUI.skin.box.fontSize = 8; GUI.Box(ctrlBox, "|"); if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && ctrlBox.Contains(new Vector2(Event.current.mousePosition.x, Event.current.mousePosition.y))) { movingColPointIndex = iCol; selectedColPointIndex = iCol; } else if (movingColPointIndex == iCol) { colPoint.dataValue = Mathf.Clamp((Event.current.mousePosition.x - bgRect.x) / bgRect.width, 0.0f, 1.0f); } tf.colourControlPoints[iCol] = colPoint; } // Alpha control points for (int iAlpha = 0; iAlpha < tf.alphaControlPoints.Count; iAlpha++) { TFAlphaControlPoint alphaPoint = tf.alphaControlPoints[iAlpha]; Rect ctrlBox = new Rect(bgRect.x + bgRect.width * alphaPoint.dataValue, bgRect.y + (1.0f - alphaPoint.alphaValue) * bgRect.height, 10, 10); GUI.color = oldColour; GUI.skin.box.fontSize = 6; GUI.Box(ctrlBox, "a"); if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && ctrlBox.Contains(new Vector2(Event.current.mousePosition.x, Event.current.mousePosition.y))) { movingAlphaPointIndex = iAlpha; } else if (movingAlphaPointIndex == iAlpha) { alphaPoint.dataValue = Mathf.Clamp((Event.current.mousePosition.x - bgRect.x) / bgRect.width, 0.0f, 1.0f); alphaPoint.alphaValue = Mathf.Clamp(1.0f - (Event.current.mousePosition.y - bgRect.y) / bgRect.height, 0.0f, 1.0f); } tf.alphaControlPoints[iAlpha] = alphaPoint; } if (Event.current.type == EventType.MouseUp) { movingColPointIndex = -1; movingAlphaPointIndex = -1; } if (Event.current.type == EventType.MouseDown && Event.current.button == 1) { if (bgRect.Contains(new Vector2(Event.current.mousePosition.x, Event.current.mousePosition.y))) { tf.alphaControlPoints.Add(new TFAlphaControlPoint(Mathf.Clamp((Event.current.mousePosition.x - bgRect.x) / bgRect.width, 0.0f, 1.0f), Mathf.Clamp(1.0f - (Event.current.mousePosition.y - bgRect.y) / bgRect.height, 0.0f, 1.0f))); } else { tf.colourControlPoints.Add(new TFColourControlPoint(Mathf.Clamp((Event.current.mousePosition.x - bgRect.x) / bgRect.width, 0.0f, 1.0f), Random.ColorHSV())); } selectedColPointIndex = -1; } if (selectedColPointIndex != -1) { TFColourControlPoint colPoint = tf.colourControlPoints[selectedColPointIndex]; colPoint.colourValue = EditorGUI.ColorField(new Rect(bgRect.x, bgRect.y + bgRect.height + 50, 100.0f, 40.0f), colPoint.colourValue); tf.colourControlPoints[selectedColPointIndex] = colPoint; } updateController(); GUI.color = oldColour; }