public static bool GetCellNormals(vtkDataSet polydata)
        {
            var normalDataDouble = vtkDoubleArray.SafeDownCast(
                polydata.GetCellData().GetArray("Normals"));
            if (normalDataDouble != null)
                return true;

            var normalDataFloat = vtkFloatArray.SafeDownCast(
                polydata.GetCellData().GetArray("Normals"));
            if (normalDataFloat != null)
                return true;

            var normalsDouble = vtkDoubleArray.SafeDownCast(
                polydata.GetCellData().GetNormals());
            if (normalsDouble != null)
                return true;

            var normalsFloat = vtkFloatArray.SafeDownCast(
                polydata.GetCellData().GetNormals());
            if (normalsFloat != null)
                return true;

            var normalsGeneric = polydata.GetCellData().GetNormals();
            if (normalsGeneric != null)
                return true;

            return false;
        }
Beispiel #2
0
    // Use this for initialization
    void Start()
    {
        print("Using VTK version " + vtkVersion.GetVTKVersion());
        if (versionText != null)
        {
            versionText.text = "Using VTK version " + vtkVersion.GetVTKVersion();
        }

        vtkXMLImageDataReader imageDataReader = vtkXMLImageDataReader.New();

        imageDataReader.SetFileName(Application.streamingAssetsPath + "/test.vti");
        imageDataReader.Update();
        vtkDataSet dataSet    = imageDataReader.GetOutputAsDataSet();
        string     dataReport = "Test Data is of type " + dataSet.GetClassName() + " and has " + dataSet.GetNumberOfPoints() + " points.";

        print(dataReport);

        if (dataText != null)
        {
            dataText.text = dataReport;
        }
    }
Beispiel #3
0
 public PatchUnit(string name, vtkDataSet dataset) : base(name, dataset)
 {
 }
Beispiel #4
0
 public VTKFrame(string inputPath)
 {
     vtkModel = ReadVTKData(inputPath);
     ImportFrameBounds();
 }
Beispiel #5
0
    protected override void ValidateInput()
    {
        string[] dataArrays = gameObject.GetComponent <VTKProperties>().dataArrays;
        if (selectedDataArray < 0)
        {
            selectedDataArray = 0;
        }
        if (selectedDataArray > dataArrays.Length - 1)
        {
            selectedDataArray = dataArrays.Length - 1;
        }


        // Check for allowed contour numbers
        if (numContours < 1)
        {
            numContours = 1;
        }
        if (numContours > 30)
        {
            numContours = 30;
        }

        //Get allowed data range
        dataArray = gameObject.GetComponent <VTKProperties>().dataArrays[selectedDataArray];
        dataArray = dataArray.Remove(dataArray.IndexOf("[") - 1);

        vtkDataSet dataSet = vtkDataSet.SafeDownCast(node.parent.filter.vtkFilter.GetOutputDataObject(0));

        if (dataSet != null)
        {
            vtkPointData pointData = dataSet.GetPointData();
            if (pointData != null)
            {
                pointData.SetActiveScalars(dataArray);
                dataRange = pointData.GetScalars().GetRange();

                // Sets initial range
                if (range == Vector2.zero || dataArray == "" || dataArray != oldDataArray)
                {
                    oldDataArray = dataArray;
                    range        = new Vector2((float)dataRange[0], (float)dataRange[1]);
                }
            }
        }

        // Check for allowed data range
        if (range.x < dataRange[0])
        {
            range.x = (float)dataRange[0];
        }
        if (range.x > dataRange[1])
        {
            range.x = (float)dataRange[1];
        }
        if (range.y < dataRange[0])
        {
            range.y = (float)dataRange[0];
        }
        if (range.y > dataRange[1])
        {
            range.y = (float)dataRange[1];
        }
    }
Beispiel #6
0
 public InternalMeshUnit(string name, vtkDataSet dataset) : base(name, dataset)
 {
 }
Beispiel #7
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>();
        }
Beispiel #8
0
 private static List<string> GetArrayNames(vtkDataSet dataSet)
 {
     var arrayNames = new List<string>();
     var pointData = dataSet.GetPointData();
     var cellData = dataSet.GetCellData();
     for (var i = 0; i < pointData.GetNumberOfArrays(); i++)
         arrayNames.Add("P-" + pointData.GetArrayName(i));
     for (var i = 0; i < cellData.GetNumberOfArrays(); i++)
         arrayNames.Add("C-" + cellData.GetArrayName(i));
     return arrayNames;
 }
Beispiel #9
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVHyper(String [] argv)
    {
        //Prefix Content is: ""

          // Create the RenderWindow, Renderer and interactive renderer[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          VTK_INTEGRATE_BOTH_DIRECTIONS = 2;
          //[]
          // generate tensors[]
          ptLoad = new vtkPointLoad();
          ptLoad.SetLoadValue((double)100.0);
          ptLoad.SetSampleDimensions((int)20,(int)20,(int)20);
          ptLoad.ComputeEffectiveStressOn();
          ptLoad.SetModelBounds((double)-10,(double)10,(double)-10,(double)10,(double)-10,(double)10);
          //[]
          // If the current directory is writable, then test the witers[]
          //[]
          try
          {
         channel = new StreamWriter("test.tmp");
          tryCatchError = "NOERROR";
          }
          catch(Exception)
          {tryCatchError = "ERROR";}

        if(tryCatchError.Equals("NOERROR"))
          {
          channel.Close();
          File.Delete("test.tmp");
          wSP = new vtkDataSetWriter();
          wSP.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          wSP.SetFileName((string)"wSP.vtk");
          wSP.SetTensorsName((string)"pointload");
          wSP.SetScalarsName((string)"effective_stress");
          wSP.Write();
          rSP = new vtkDataSetReader();
          rSP.SetFileName((string)"wSP.vtk");
          rSP.SetTensorsName((string)"pointload");
          rSP.SetScalarsName((string)"effective_stress");
          rSP.Update();
          input = rSP.GetOutput();
          File.Delete("wSP.vtk");
        }
          else
        {
          input = ptLoad.GetOutput();
        }

          // Generate hyperstreamlines[]
          s1 = new vtkHyperStreamline();
          s1.SetInputData((vtkDataObject)input);
          s1.SetStartPosition((double)9,(double)9,(double)-9);
          s1.IntegrateMinorEigenvector();
          s1.SetMaximumPropagationDistance((double)18.0);
          s1.SetIntegrationStepLength((double)0.1);
          s1.SetStepLength((double)0.01);
          s1.SetRadius((double)0.25);
          s1.SetNumberOfSides((int)18);
          s1.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s1.Update();
          // Map hyperstreamlines[]
          lut = new vtkLogLookupTable();
          lut.SetHueRange((double).6667,(double)0.0);
          s1Mapper = vtkPolyDataMapper.New();
          s1Mapper.SetInputConnection((vtkAlgorithmOutput)s1.GetOutputPort());
          s1Mapper.SetLookupTable((vtkScalarsToColors)lut);
          ptLoad.Update();
          //force update for scalar range[]
          s1Mapper.SetScalarRange((double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[1]);
          s1Actor = new vtkActor();
          s1Actor.SetMapper((vtkMapper)s1Mapper);
          s2 = new vtkHyperStreamline();
          s2.SetInputData((vtkDataObject)input);
          s2.SetStartPosition((double)-9,(double)-9,(double)-9);
          s2.IntegrateMinorEigenvector();
          s2.SetMaximumPropagationDistance((double)18.0);
          s2.SetIntegrationStepLength((double)0.1);
          s2.SetStepLength((double)0.01);
          s2.SetRadius((double)0.25);
          s2.SetNumberOfSides((int)18);
          s2.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s2.Update();
          s2Mapper = vtkPolyDataMapper.New();
          s2Mapper.SetInputConnection((vtkAlgorithmOutput)s2.GetOutputPort());
          s2Mapper.SetLookupTable((vtkScalarsToColors)lut);
          s2Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0],(double)((vtkDataSet)input).GetScalarRange()[1]);
          s2Actor = new vtkActor();
          s2Actor.SetMapper((vtkMapper)s2Mapper);
          s3 = new vtkHyperStreamline();
          s3.SetInputData((vtkDataObject)input);
          s3.SetStartPosition((double)9,(double)-9,(double)-9);
          s3.IntegrateMinorEigenvector();
          s3.SetMaximumPropagationDistance((double)18.0);
          s3.SetIntegrationStepLength((double)0.1);
          s3.SetStepLength((double)0.01);
          s3.SetRadius((double)0.25);
          s3.SetNumberOfSides((int)18);
          s3.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s3.Update();
          s3Mapper = vtkPolyDataMapper.New();
          s3Mapper.SetInputConnection((vtkAlgorithmOutput)s3.GetOutputPort());
          s3Mapper.SetLookupTable((vtkScalarsToColors)lut);
          s3Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0],
          (double)((vtkDataSet)input).GetScalarRange()[1]);
          s3Actor = new vtkActor();
          s3Actor.SetMapper((vtkMapper)s3Mapper);
          s4 = new vtkHyperStreamline();
          s4.SetInputData((vtkDataObject)input);
          s4.SetStartPosition((double)-9,(double)9,(double)-9);
          s4.IntegrateMinorEigenvector();
          s4.SetMaximumPropagationDistance((double)18.0);
          s4.SetIntegrationStepLength((double)0.1);
          s4.SetStepLength((double)0.01);
          s4.SetRadius((double)0.25);
          s4.SetNumberOfSides((int)18);
          s4.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s4.Update();
          s4Mapper = vtkPolyDataMapper.New();
          s4Mapper.SetInputConnection((vtkAlgorithmOutput)s4.GetOutputPort());
          s4Mapper.SetLookupTable((vtkScalarsToColors)lut);
          s4Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0],(double)((vtkDataSet)input).GetScalarRange()[1]);
          s4Actor = new vtkActor();
          s4Actor.SetMapper((vtkMapper)s4Mapper);
          // plane for context[]
          //[]
          g = new vtkImageDataGeometryFilter();
          g.SetInputData((vtkDataObject)input);
          g.SetExtent((int)0,(int)100,(int)0,(int)100,(int)0,(int)0);
          g.Update();
          //for scalar range[]
          gm = vtkPolyDataMapper.New();
          gm.SetInputConnection((vtkAlgorithmOutput)g.GetOutputPort());
          gm.SetScalarRange((double)((vtkDataSet)g.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)g.GetOutput()).GetScalarRange()[1]);
          ga = new vtkActor();
          ga.SetMapper((vtkMapper)gm);
          // Create outline around data[]
          //[]
          outline = new vtkOutlineFilter();
          outline.SetInputData((vtkDataObject)input);
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          // Create cone indicating application of load[]
          //[]
          coneSrc = new vtkConeSource();
          coneSrc.SetRadius((double).5);
          coneSrc.SetHeight((double)2);
          coneMap = vtkPolyDataMapper.New();
          coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort());
          coneActor = new vtkActor();
          coneActor.SetMapper((vtkMapper)coneMap);
          coneActor.SetPosition((double)0,(double)0,(double)11);
          coneActor.RotateY((double)90);
          coneActor.GetProperty().SetColor((double)1,(double)0,(double)0);
          camera = new vtkCamera();
          camera.SetFocalPoint((double)0.113766,(double)-1.13665,(double)-1.01919);
          camera.SetPosition((double)-29.4886,(double)-63.1488,(double)26.5807);
          camera.SetViewAngle((double)24.4617);
          camera.SetViewUp((double)0.17138,(double)0.331163,(double)0.927879);
          camera.SetClippingRange((double)1,(double)100);
          ren1.AddActor((vtkProp)s1Actor);
          ren1.AddActor((vtkProp)s2Actor);
          ren1.AddActor((vtkProp)s3Actor);
          ren1.AddActor((vtkProp)s4Actor);
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)coneActor);
          ren1.AddActor((vtkProp)ga);
          ren1.SetBackground((double)1.0,(double)1.0,(double)1.0);
          ren1.SetActiveCamera((vtkCamera)camera);
          renWin.SetSize((int)300,(int)300);
          renWin.Render();
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Beispiel #10
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setinput(vtkDataSet toSet)
 {
     input = toSet;
 }
Beispiel #11
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setinput(vtkDataSet toSet)
 {
     input = toSet;
 }
        private void HighLightBadCells()
        {
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.Update();

            vtkTriangleFilter triangleFilter = vtkTriangleFilter.New();

            triangleFilter.SetInputConnection(sphereSource.GetOutputPort());
            triangleFilter.Update();

            //Create a mapper and actor
            vtkDataSetMapper sphereMapper = vtkDataSetMapper.New();

            sphereMapper.SetInputConnection(triangleFilter.GetOutputPort());
            vtkActor sphereActor = vtkActor.New();

            sphereActor.SetMapper(sphereMapper);

            vtkPolyData mesh = triangleFilter.GetOutput();

            Debug.WriteLine("There are " + mesh.GetNumberOfCells() + " cells.");

            vtkMeshQuality qualityFilter = vtkMeshQuality.New();

#if VTK_MAJOR_VERSION_5
            qualityFilter.SetInput(mesh);
#else
            qualityFilter.SetInputData(mesh);
#endif
            qualityFilter.SetTriangleQualityMeasureToArea();
            qualityFilter.Update();

            vtkDataSet     qualityMesh  = qualityFilter.GetOutput();
            vtkDoubleArray qualityArray = vtkDoubleArray.SafeDownCast(qualityMesh.GetCellData().GetArray("Quality"));
            Debug.WriteLine("There are " + qualityArray.GetNumberOfTuples() + " values.");

            for (int i = 0; i < qualityArray.GetNumberOfTuples(); i++)
            {
                double val = qualityArray.GetValue(i);
                Debug.WriteLine("value " + i + ": " + val);
            }

            vtkThreshold selectCells = vtkThreshold.New();
            selectCells.ThresholdByLower(.02);
            selectCells.SetInputArrayToProcess(
                0,
                0,
                0,
                1, // POINTS = 0, CELLS = 1, NONE = 2, POINTS_THEN_CELLS = 3, VERTICES = 4, EDGES = 5, ROWS = 6
                0  // SCALARS = 0, VECTORS = 1, NORMALS = 2, TCOORDS = 3, TENSORS = 4, GLOBALIDS = 5, PEDIGREEIDS = 6, EDGEFLAG = 7
                );

#if VTK_MAJOR_VERSION_5
            selectCells.SetInput(qualityMesh);
#else
            selectCells.SetInputData(qualityMesh);
#endif
            selectCells.Update();
            vtkUnstructuredGrid ug = selectCells.GetOutput();

            // Create a mapper and actor
            vtkDataSetMapper mapper = vtkDataSetMapper.New();
#if VTK_MAJOR_VERSION_5
            mapper.SetInput(ug);
#else
            mapper.SetInputData(ug);
#endif
            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(1.0, 0.0, 0.0);
            actor.GetProperty().SetRepresentationToWireframe();
            actor.GetProperty().SetLineWidth(5);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(1.0, 1.0, 1.0);
            // add our actors to the renderer
            renderer.AddActor(actor);
            renderer.AddActor(sphereActor);
        }
Beispiel #13
0
 public DatasetUnit(string name, vtkDataSet dataset) : this()
 {
     this.Name    = name;
     this.Dataset = dataset;
 }