コード例 #1
0
        public void WriteSimpleVTUExample()
        {
            string    filePath = "C:\\DatenE\\02Studium\\02WiSe1718\\06IndividualProjekt\\03Daten\\testData\\simpleTest4Points.vtu";
            vtkPoints points   = vtkPoints.New();

            points.InsertNextPoint(0, 0, 0);
            points.InsertNextPoint(1, 0, 0);
            points.InsertNextPoint(1, 1, 0);
            points.InsertNextPoint(0, 1, 1);

            points.InsertNextPoint(2, 0, 0);
            //points.InsertNextPoint(2, 2, 0);


            vtkTetra tetra = vtkTetra.New();

            tetra.GetPointIds().SetId(0, 0);
            tetra.GetPointIds().SetId(1, 1);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 3);

            vtkCellArray cellArray = vtkCellArray.New();

            cellArray.InsertNextCell(tetra);



            tetra.GetPointIds().SetId(0, 1);
            tetra.GetPointIds().SetId(1, 0);
            tetra.GetPointIds().SetId(2, 3);
            tetra.GetPointIds().SetId(3, 2);

            cellArray.InsertNextCell(tetra);
            tetra.GetPointIds().SetId(0, 0);
            tetra.GetPointIds().SetId(1, 2);
            tetra.GetPointIds().SetId(2, 3);
            tetra.GetPointIds().SetId(3, 1);

            cellArray.InsertNextCell(tetra);
            tetra.GetPointIds().SetId(0, 3);
            tetra.GetPointIds().SetId(1, 1);
            tetra.GetPointIds().SetId(2, 0);
            tetra.GetPointIds().SetId(3, 2);

            cellArray.InsertNextCell(tetra);

            tetra.GetPointIds().SetId(0, 3);
            tetra.GetPointIds().SetId(1, 0);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 4);

            cellArray.InsertNextCell(tetra);

            //tetra.GetPointIds().SetId(0, 4);
            //tetra.GetPointIds().SetId(1, 3);
            //tetra.GetPointIds().SetId(2, 0);
            //tetra.GetPointIds().SetId(3, 2);

            //cellArray.InsertNextCell(tetra);

            vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New();

            unstructuredGrid.SetPoints(points);
            const int VTK_TETRA = 10;

            unstructuredGrid.SetCells(VTK_TETRA, cellArray);


            // vX
            vtkDoubleArray scalarsX = new vtkDoubleArray();

            scalarsX.SetNumberOfValues(5);
            scalarsX.SetValue(0, 4);
            scalarsX.SetValue(1, 1);
            scalarsX.SetValue(2, 2);
            scalarsX.SetValue(3, 3);
            scalarsX.SetValue(4, 1);
            //scalarsX.SetValue(5, 2);
            scalarsX.SetName("Vx");
            unstructuredGrid.GetPointData().AddArray(scalarsX);
            // vY
            vtkDoubleArray scalarsY = new vtkDoubleArray();

            scalarsY.SetNumberOfValues(5);
            scalarsY.SetValue(0, 1);
            scalarsY.SetValue(1, 2);
            scalarsY.SetValue(2, 3);
            scalarsY.SetValue(3, 4);
            scalarsY.SetValue(4, 1);
            //scalarsY.SetValue(5, 2);
            scalarsY.SetName("Vy");
            unstructuredGrid.GetPointData().AddArray(scalarsY);
            // vZ
            vtkDoubleArray scalarsZ = new vtkDoubleArray();

            scalarsZ.SetNumberOfValues(5);
            scalarsZ.SetValue(0, 3);
            scalarsZ.SetValue(1, 1);
            scalarsZ.SetValue(2, 4);
            scalarsZ.SetValue(3, 2);
            scalarsZ.SetValue(4, 1);
            //scalarsZ.SetValue(5, 2);
            scalarsZ.SetName("Vz");
            unstructuredGrid.GetPointData().AddArray(scalarsZ);


            // Write file
            vtkXMLUnstructuredGridWriter writer = vtkXMLUnstructuredGridWriter.New();

            writer.SetFileName(filePath);
            writer.SetInput(unstructuredGrid);
            writer.Write();
        }
コード例 #2
0
        public void CalculateDifferences(List <Vector3d> registratedPoints, List <Vector3d> originalPoints, Dictionary <String, List <float> > scalarDataRegistratedPoints, Dictionary <String, List <float> > scalarDataOriginalPoints, List <int> interpolatedPointArray)
        {
            Dictionary <string, List <float> > .KeyCollection KeyCollRegistrated = scalarDataRegistratedPoints.Keys;
            int nKeysRegistrated = KeyCollRegistrated.Count();

            Dictionary <string, List <float> > .KeyCollection KeyCollOriginal = scalarDataOriginalPoints.Keys;
            int nKeysOriginal = KeyCollOriginal.Count();

            List <float> scalarValuesX = new List <float>();

            scalarDataOriginalPoints.TryGetValue(KeyCollOriginal.ElementAt <string>(0), out scalarValuesX);
            List <float> scalarValuesY = new List <float>();

            scalarDataOriginalPoints.TryGetValue(KeyCollOriginal.ElementAt <string>(1), out scalarValuesY);
            List <float> scalarValuesZ = new List <float>();

            scalarDataOriginalPoints.TryGetValue(KeyCollOriginal.ElementAt <string>(2), out scalarValuesZ);

            double maxVec1 = Double.MinValue;
            double maxVec2 = Double.MinValue;
            // create vectorfield
            List <Vector3d> vectorFielRegistratedPoints = new List <Vector3d>();

            for (int i = 0; i < scalarValuesX.Count(); i++)
            {
                Vector3d vec = new Vector3d(scalarValuesX[i], scalarValuesY[i], scalarValuesZ[i]);

                vectorFielRegistratedPoints.Add(vec);
                maxVec1 = Math.Max(vec.Length, maxVec1);
            }


            scalarDataRegistratedPoints.TryGetValue(KeyCollRegistrated.ElementAt <string>(0), out scalarValuesX);

            scalarDataRegistratedPoints.TryGetValue(KeyCollRegistrated.ElementAt <string>(1), out scalarValuesY);

            scalarDataRegistratedPoints.TryGetValue(KeyCollRegistrated.ElementAt <string>(2), out scalarValuesZ);

            // create vectorfield
            List <Vector3d> vectorFielOriginalPoints = new List <Vector3d>();

            for (int i = 0; i < scalarValuesX.Count(); i++)
            {
                Vector3d vec = new Vector3d(scalarValuesX[i], scalarValuesY[i], scalarValuesZ[i]);

                vectorFielOriginalPoints.Add(vec);
                maxVec2 = Math.Max(vec.Length, maxVec2);
            }


            List <double> oneDiff    = new List <double>();
            List <double> anglesList = new List <double>();

            vtkDoubleArray scalars       = new vtkDoubleArray();
            vtkDoubleArray anglesArray   = new vtkDoubleArray();
            vtkDoubleArray VxDifferences = new vtkDoubleArray();

            scalars.SetNumberOfValues(registratedPoints.Count());
            anglesArray.SetNumberOfValues(registratedPoints.Count());
            VxDifferences.SetNumberOfValues(registratedPoints.Count());
            int counter = 0;

            for (int j = 0; j < registratedPoints.Count(); j++)
            {
                double diff   = 0;
                double angle  = 0.0;
                double VxDiff = 0.0;
                if (vectorFielRegistratedPoints.Count() > j)
                {
                    Vector3d test2 = vectorFielRegistratedPoints[interpolatedPointArray[j]];
                    //if (test2 != new Vector3d(0, 0, 0))
                    //{

                    diff = Math.Abs(vectorFielRegistratedPoints[interpolatedPointArray[j]].Length - vectorFielOriginalPoints[j].Length);
                    Vector3D vec1 = new Vector3D(vectorFielRegistratedPoints[interpolatedPointArray[j]].X, vectorFielRegistratedPoints[interpolatedPointArray[j]].Y, vectorFielRegistratedPoints[interpolatedPointArray[j]].Z);
                    Vector3D vec2 = new Vector3D(vectorFielOriginalPoints[j].X, vectorFielOriginalPoints[j].Y, vectorFielOriginalPoints[j].Z);
                    if (vec1 != new Vector3D(0, 0, 0) && vec2 != new Vector3D(0, 0, 0))
                    {
                        angle = Vector3D.AngleBetween(vec1, vec2);
                    }

                    Vector3D vec1T     = new Vector3D(10, 10, 10);
                    Vector3D vec2T     = new Vector3D(-10, -10, -10);
                    double   angleTest = Vector3D.AngleBetween(vec1T, vec2T);
                    VxDiff = Math.Abs(vectorFielRegistratedPoints[interpolatedPointArray[j]].X - vectorFielOriginalPoints[j].X);
                    //}
                    if (test2 == new Vector3d(0, 0, 0))
                    {
                        counter++;
                    }
                }

                oneDiff.Add(diff);

                scalars.SetValue(j, diff);
                anglesArray.SetValue(j, angle);
                VxDifferences.SetValue(j, VxDiff);
            }
            vtkDataArray dataArray;

            dataArray = scalars;

            dataArray.SetName("VelocityDifferences");

            this.scalarData_Array.Add("VelocityDifferences", oneDiff);
            this.scalarNames.Add("VelocityDifferences");


            if (this.scalar_dataArray.ContainsKey("VelocityDifferences"))
            {
                this.scalar_dataArray["VelocityDifferences"] = dataArray;
            }
            else
            {
                this.scalar_dataArray.Add("VelocityDifferences", dataArray);
                this.arrayNames.Add("VelocityDifferences");
            }

            dataArray = anglesArray;
            dataArray.SetName("Angles");

            this.scalarData_Array.Add("Angles", oneDiff);
            this.scalarNames.Add("Angles");


            if (this.scalar_dataArray.ContainsKey("Angles"))
            {
                this.scalar_dataArray["Angles"] = dataArray;
            }
            else
            {
                this.scalar_dataArray.Add("Angles", dataArray);
                this.arrayNames.Add("Angles");
            }

            dataArray = VxDifferences;
            dataArray.SetName("VxDifferences");

            this.scalarData_Array.Add("VxDifferences", oneDiff);
            this.scalarNames.Add("VxDifferences");


            if (this.scalar_dataArray.ContainsKey("VxDifferences"))
            {
                this.scalar_dataArray["VxDifferences"] = dataArray;
            }
            else
            {
                this.scalar_dataArray.Add("VxDifferences", dataArray);
                this.arrayNames.Add("VxDifferences");
            }
        }