Ejemplo n.º 1
0
        protected static VtkAlgorithm OnSelectedArrayChange(VtkAlgorithm algorithm,
			tkDefaultContext context, int index)
        {
            algorithm.SelectedArrayIndex = index;
            return algorithm;
        }
Ejemplo n.º 2
0
        private void UpdateVtk(VtkAlgorithm algorithm, tkDefaultContext context)
        {
            if (!IsInitialized())
                return;
            if (_input)
            {
                _algorithm.SetInputConnection(_input.Algorithm.GetOutputPort());
                _input.UpdateVtk(_input, null);
            }

            if (_triangleFilter == null || _algorithm == null || _vtkMesh == null ||
                _gameObject == null)
                return;
            _algorithm.Update();
            _output = (vtkDataSet)_algorithm.GetOutputDataObject(0);
            // Input connection has to be set here because _algorithm address changes somehow
            // because of FullInspector serialization
            if (OutputDataDataType != DataType.vtkPolyData)
            {
                if (_geometryFilter == null)
                    _geometryFilter = vtkGeometryFilter.New();
                //_geometryFilter.MergingOff();
                _geometryFilter.SetInputConnection(_algorithm.GetOutputPort());
                _triangleFilter.SetInputConnection(_geometryFilter.GetOutputPort());
            }
            else
                _triangleFilter.SetInputConnection(_algorithm.GetOutputPort());
            _triangleFilter.PassVertsOn();
            _triangleFilter.PassLinesOn();
            _triangleFilter.Update();
            _polyDataOutput = _triangleFilter.GetOutput();

            if (_polyDataOutput == null ||
                _polyDataOutput.GetNumberOfPoints() == 0 ||
                _polyDataOutput.GetNumberOfCells() == 0)
            {
                // Debug.Log("Polydata output empty!");
                return;
            }

            if (GenerateNormals && !VtkNormalsHelper.GetPointNormals(_polyDataOutput))
            {
                if (_normalsFilter == null)
                    _normalsFilter = vtkPolyDataNormals.New();
                _normalsFilter.SetInputConnection(_triangleFilter.GetOutputPort());
                _normalsFilter.ComputePointNormalsOn();
                _normalsFilter.ComputeCellNormalsOff();
                _normalsFilter.Update();
                _polyDataOutput = _normalsFilter.GetOutput();
            }

            _arrayNames = GetArrayNames(_polyDataOutput);
            _arrayLabels = _arrayNames.Select(t => new GUIContent(t)).ToArray();

            if(!GenerateMesh)
                return;

            _vtkMesh.Update(_polyDataOutput);
            UpdateMeshColors(_selectedArrayIndex);
            DestroyImmediate(_gameObject.GetComponent<MeshRenderer>());
            DestroyImmediate(_gameObject.GetComponent<MeshFilter>());
            if (_vtkMesh.Meshes.Count == 1)
            {
                _gameObject.AddComponent<MeshFilter>().sharedMesh = _vtkMesh.Meshes[0];
                var meshRenderer = _gameObject.AddComponent<MeshRenderer>();
                meshRenderer.material =
                    new Material(Shader.Find("Diffuse")) { color = Color.gray };
                for(var i = 0; i < _gameObject.transform.childCount; i++)
                    DestroyImmediate(_gameObject.transform.GetChild(i));
            }
            else
            {
                for (var i = 0; i < _vtkMesh.Meshes.Count; i++)
                {
                    var currentName = Name + "-" + i;
                    GameObject child;
                    var childTransform = _gameObject.transform.FindChild(currentName);
                    if (childTransform == null)
                    {
                        child = new GameObject(currentName);
                        child.transform.parent = _gameObject.transform;
                        child.transform.localPosition = new Vector3();
                        child.AddComponent<MeshFilter>();
                        var meshRenderer = child.AddComponent<MeshRenderer>();
                        meshRenderer.material =
                            new Material(Shader.Find("Diffuse")) {color = Color.gray};
                    }
                    else
                        child = childTransform.gameObject;
                    child.GetComponent<MeshFilter>().sharedMesh = _vtkMesh.Meshes[i];
                }
                while (_vtkMesh.Meshes.Count < _gameObject.transform.childCount)
                    DestroyImmediate(_gameObject.transform.GetChild(
                        _gameObject.transform.childCount - 1));
            }
            if(MaterialProperties == null)
                MaterialProperties = _gameObject.AddComponent<MaterialProperties>();
        }
Ejemplo n.º 3
0
        protected static VtkAlgorithm OnArrayToProcessChange(VtkAlgorithm algorithm,
			tkDefaultContext context, int index)
        {
            algorithm.ArrayToProcessIndex = index;
            return algorithm;
        }