コード例 #1
0
        protected virtual void SetXArray(vtkDoubleArray array, VtkPlotPointsModel plot)
        {
            VtkChartXyModel model = this.Model as VtkChartXyModel;

            if (model == null)
            {
                return;
            }

            vtkTable table = plot.Table;

            if (table.GetNumberOfColumns() <= 1)
            {
                table.Initialize();
                table.AddColumn(array);
            }
            else
            {
                vtkDoubleArray arrY = table.GetColumn(1) as vtkDoubleArray;
                if (arrY == null)
                {
                    this.Log.Error("SetXArray(): Could not cast table data to vtkDoubleArray");
                    return;
                }

                table.Initialize();
                table.AddColumn(array);
                table.AddColumn(arrY);

                vtkPlotPoints vtkPlot = plot.PlotItem as vtkPlotPoints;
                if (vtkPlot == null)
                {
                    this.Log.Error("SetXArray(): Could not cast plot item to vtkPlotPoints");
                    return;
                }

                vtkPlot.SetInputData(table, 0, 1);
            }
        }
コード例 #2
0
        protected virtual void SetYArray(vtkDoubleArray array, VtkPlotPointsModel plot)
        {
            VtkChartXyModel model = this.Model as VtkChartXyModel;

            if (model == null)
            {
                return;
            }

            vtkTable table = plot.Table;

            if (table.GetNumberOfColumns() == 0)
            {
                this.Log.Error("SetYArray(): No XArray data");
                return;
            }

            if (table.GetNumberOfColumns() == 1)
            {
                table.AddColumn(array);
            }
            else
            {
                table.RemoveColumn(1);
                table.AddColumn(array);
            }

            vtkPlotPoints vtkPlot = plot.PlotItem as vtkPlotPoints;

            if (vtkPlot == null)
            {
                this.Log.Error("SetYArray(): Could not cast plot item to vtkPlotPoints");
                return;
            }

            vtkPlot.SetInputData(table, 0, 1);
        }
コード例 #3
0
        /// <summary>
        /// 左键释放时获取选择的对象
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void m_interactor_LeftButtonReleaseEvt(vtkObject sender, vtkObjectEventArgs e)
        {
            if (m_pickTarget == ePickTarget.None)
            {
                return;
            }

            //if (m_iren.GetControlKey() != 0)
            //    m_pickBoolean = ePickBollean.Add;
            //else if (m_iren.GetShiftKey() != 0)
            //    m_pickBoolean = ePickBollean.Sub;

            m_iren.GetEventPosition(ref endx, ref endy);
            #region 点选对象
            if (m_pickMode == ePickMode.DotPickMode) //如果是点选模式
            {
                vtkCellPicker cellPicker = new vtkCellPicker();
                cellPicker.SetTolerance(0.005);
                if (0 == cellPicker.Pick(endx, endy, 0, m_renderer))
                {
                    return;  //什么都没有选到就返回
                }
                FEMActor actor = cellPicker.GetActor() as FEMActor;
                if (actor == null)
                {
                    return;
                }
                if (m_pickTarget == ePickTarget.Actor)
                {                          //如果选择对象为
                    actor.IsSelected = true;
                    m_RWCtrl.Invalidate(); //貌似必须要用这个函数,update 不行
                    OnObjectsSelected(sender, e);
                }
                else if (m_pickTarget == ePickTarget.Cell)
                {
                    int cellId = cellPicker.GetCellId();
                    actor.AddCellId(cellId, m_pickBoolean);
                    OnObjectsSelected(sender, e);
                    //if (cellId > 0)
                    //    Console.WriteLine("dotselect cellid:{0}", cellId);
                }
                else if (m_pickTarget == ePickTarget.Point)
                {
                    int pointId = cellPicker.GetPointId();
                    if (pointId != -1)
                    {
                        actor.AddPointId(pointId, m_pickBoolean);
                        OnObjectsSelected(sender, e);
                        //   Console.WriteLine("dotselect pointid:{0}", pointId);
                    }
                }
            }
            #endregion
            else if (m_pickMode == ePickMode.RectPickMode) //如果是框选
            {
                vtkAreaPicker areaPicker = new vtkAreaPicker();
                if (0 == areaPicker.AreaPick(startx, starty, endx, endy, m_renderer))
                { //如果什么也没选到就返回
                    //this.impactViewForm.ClearAllSelectCells();
                    return;
                }
                vtkProp3DCollection selectedActors = areaPicker.GetProp3Ds();
                selectedActors.InitTraversal();
                FEMActor selectedActor;
                while ((selectedActor = selectedActors.GetNextProp3D() as FEMActor) != null)
                {
                    vtkSelection     selection     = new vtkSelection();
                    vtkSelectionNode selectionNode = new vtkSelectionNode();
                    selection.AddNode(selectionNode);

                    vtkIdFilter idFilter = new vtkIdFilter();
                    idFilter.FieldDataOn();
                    idFilter.SetInput(selectedActor.GetMapper().GetInput());
                    idFilter.Update();

                    vtkExtractSelection frustum = new vtkExtractSelection();
                    frustum.SetInput(0, idFilter.GetOutput());
                    frustum.SetInput(1, selection);

                    selectionNode.Initialize();
                    selectionNode.SetContentType((int)vtkSelectionNode.SelectionContent.FRUSTUM);

                    if (m_pickTarget == ePickTarget.Cell)//如果选择的目标是cell
                    {
                        selectionNode.SetFieldType((int)vtkSelectionNode.SelectionField.CELL);
                    }
                    else if (m_pickTarget == ePickTarget.Point) //如果选择的目标是point
                    {
                        selectionNode.SetFieldType((int)vtkSelectionNode.SelectionField.POINT);
                    }

                    vtkPoints      points         = areaPicker.GetClipPoints();
                    vtkDoubleArray frustumcorners = new vtkDoubleArray();
                    frustumcorners.SetNumberOfComponents(4);
                    frustumcorners.SetNumberOfTuples(8);
                    for (int i = 0; i < 8; ++i)
                    {
                        double[] point = points.GetPoint(i);
                        frustumcorners.SetTuple4(i, point[0], point[1], point[2], 0.0);
                    }
                    selectionNode.SetSelectionList(frustumcorners);

                    frustum.Update();
                    vtkUnstructuredGrid grid = new vtkUnstructuredGrid();
                    grid = vtkUnstructuredGrid.SafeDownCast(frustum.GetOutput());
                    vtkIdTypeArray ids = null;
                    if (m_pickTarget == ePickTarget.Cell)
                    {
                        ids = vtkIdTypeArray.SafeDownCast(grid.GetCellData().GetArray("vtkOriginalCellIds"));
                        if (ids == null)
                        {
                            continue;
                        }
                        selectedActor.AddCellId(ids, m_pickBoolean);
                        OnObjectsSelected(sender, e);
                    }
                    else if (m_pickTarget == ePickTarget.Point)
                    {
                        ids = vtkIdTypeArray.SafeDownCast(grid.GetPointData().GetArray("vtkOriginalPointIds"));
                        if (ids == null)
                        {
                            continue;
                        }
                        selectedActor.AddPointId(ids, m_pickBoolean);
                        OnObjectsSelected(sender, e);
                    }
                }
            }
        }
コード例 #4
0
        public void WriteSimpleStructuredGrid(string filePath)
        {
            vtkPoints points = vtkPoints.New();

            double x, y, z;

            x = 0.0;
            y = 0.0;
            z = 0.0;

            for (uint k = 0; k < 2; k++)
            {
                z += 2.0;
                for (uint j = 0; j < 3; j++)
                {
                    y += 1.0;
                    for (uint i = 0; i < 2; i++)
                    {
                        x += .5;
                        points.InsertNextPoint(x, y, z);
                    }
                }
            }

            vtkDataArray dataArrayVx;
            vtkDataArray dataArrayVy;
            vtkDataArray dataArrayVz;

            vtkDoubleArray Vx = new vtkDoubleArray();
            vtkDoubleArray Vy = new vtkDoubleArray();
            vtkDoubleArray Vz = new vtkDoubleArray();

            for (int i = 0; i < 12; i++)
            {
                Vx.InsertNextValue(-1 + i);
                Vz.InsertNextValue(2 - i);
                Vy.InsertNextValue(-4 + i);
            }
            dataArrayVx = Vx;
            dataArrayVx.SetName("Vx");
            dataArrayVy = Vy;
            dataArrayVy.SetName("Vy");
            dataArrayVz = Vz;
            dataArrayVz.SetName("Vz");


            vtkStructuredGrid structuredGrid = vtkStructuredGrid.New();

            structuredGrid.SetDimensions(2, 3, 2);
            structuredGrid.SetPoints(points);

            structuredGrid.GetPointData().AddArray(dataArrayVx);
            structuredGrid.GetPointData().AddArray(dataArrayVy);
            structuredGrid.GetPointData().AddArray(dataArrayVz);

            // add file ending if it is not existent
            string suffix = (".vts");

            if (!(filePath.EndsWith(suffix)))
            {
                filePath += suffix;
            }
            // Write file
            vtkXMLStructuredGridWriter writer = vtkXMLStructuredGridWriter.New();

            writer.SetFileName(filePath);
            writer.SetInput(structuredGrid);
            writer.Write();

            // Read and display file for verification that it was written correctly
            vtkXMLStructuredGridReader reader = vtkXMLStructuredGridReader.New();

            if (reader.CanReadFile(filePath) == 0)
            {
                //MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            Console.WriteLine("VTU file was writen and is saved at {0}", filePath);
        }
コード例 #5
0
        protected virtual void PlotInternal(CodeContext context, ndarray array, IList <string> names = null, Type type = null)
        {
            VtkChartXyModel model = this.Model as VtkChartXyModel;

            if (model == null)
            {
                return;
            }

            int ndim = array.ndim;

            if (type == null || !type.IsSubclassOf(typeof(VtkPlotPointsModel)))
            {
                type = typeof(VtkPlotPointsModel);
            }

            ConstructorInfo cInfo = type.GetConstructor(new Type[] { });

            if (cInfo == null)
            {
                return;
            }

            switch (ndim)
            {
            case 1:
            {
                // Treat array as y-values
                VtkPlotPointsModel plot = cInfo.Invoke(new object[] {}) as VtkPlotPointsModel;
                if (plot == null)
                {
                    return;
                }

                int len = (int)array.Dims[0];

                ndarray linspace = Math.General.LinSpace(context, len, 0.0, 1.0);

                vtkDoubleArray arrX = NumpyVtk.NumpyToVtk(linspace) as vtkDoubleArray;
                vtkDoubleArray arrY = NumpyVtk.NumpyToVtk(array) as vtkDoubleArray;

                if (arrX == null || arrY == null)
                {
                    this.Log.Error("Plot(): Could not cast ndarrays to vtkDoubleArrays");
                    return;
                }

                numPlots++;
                arrX.SetName(DEFAULT_X_ARRAY + '_' + numPlots);

                if (names != null && !String.IsNullOrEmpty(names[0]))
                {
                    arrY.SetName(names[0]);
                }
                else
                {
                    numPlots++;
                    arrY.SetName(DEFAULT_Y_ARRAY + '_' + numPlots);
                }

                this.SetXArray(arrX, plot);
                this.SetYArray(arrY, plot);

                model.Plots.Add(plot);
            }
            break;

            case 2:
            {
                // Treat 1st array as x-values, rest as y-values
                // No need to check for dimensional conformity, ndarray won't allow asymmetric arrays to be created
                ndarray arrayX = array[0] as ndarray;
                if (arrayX == null)
                {
                    this.Log.Error("Plot(): Could not cast X-data to ndarray");
                    return;
                }

                vtkDoubleArray arrX = NumpyVtk.NumpyToVtk(arrayX) as vtkDoubleArray;
                if (arrX == null)
                {
                    this.Log.Error("Plot(): Could not cast X-ndarray to vtkDoubleArray");
                    return;
                }

                if (names != null && !String.IsNullOrEmpty(names[0]))
                {
                    arrX.SetName(names[0]);
                }
                else
                {
                    numPlots++;
                    arrX.SetName(DEFAULT_X_ARRAY + '_' + numPlots);
                }

                int numArrays = (int)array.Dims[0];

                for (int i = 1; i < numArrays; i++)
                {
                    VtkPlotPointsModel plot = cInfo.Invoke(new object[] { }) as VtkPlotPointsModel;
                    if (plot == null)
                    {
                        return;
                    }

                    ndarray arrayY = array[i] as ndarray;
                    if (arrayY == null)
                    {
                        this.Log.Error("Plot(): Could not cast Y-data to ndarray");
                        return;
                    }

                    vtkDoubleArray arrY = NumpyVtk.NumpyToVtk(arrayY) as vtkDoubleArray;
                    if (arrY == null)
                    {
                        this.Log.Error("Plot(): Could not cast Y-ndarray to vtkDoubleArray");
                        return;
                    }

                    if (names != null && names.Count > i && !String.IsNullOrEmpty(names[i]))
                    {
                        arrY.SetName(names[i]);
                    }
                    else
                    {
                        numPlots++;
                        arrY.SetName(DEFAULT_Y_ARRAY + '_' + numPlots);
                    }

                    this.SetXArray(arrX, plot);
                    this.SetYArray(arrY, plot);

                    model.Plots.Add(plot);
                }
            }
            break;

            default:
                this.Log.Error("Can only plot 1D and 2D arrays");
                break;
            }

            vtkChartXY chart = this._chartItem as vtkChartXY;

            if (chart == null)
            {
                return;
            }

            foreach (IVtkPlotItemModel plotItemModel in model.Plots)
            {
                plotItemModel.PropertyChanged += OnPlotItemChanged;
                vtkPlot plot = plotItemModel.PlotItem as vtkPlot;
                if (plot != null)
                {
                    chart.AddPlot(plot);
                }
            }

            this.RenderInternal();
        }
コード例 #6
0
        public void CalculateLambda2CriterionIrregularGrids(List <Vector3d> pointsToRegistrate, Dictionary <string, List <float> > scalarValues, List <string> scalarNames, List <Vector4> tetraPoints)
        {
            List <float> scalarValuesX = new List <float>();
            List <float> scalarValuesY = new List <float>();
            List <float> scalarValuesZ = new List <float>();

            //if (scalarNames.Count() <= 4)
            //{
            scalarValues.TryGetValue(scalarNames[0], out scalarValuesX);
            scalarValues.TryGetValue(scalarNames[1], out scalarValuesY);
            scalarValues.TryGetValue(scalarNames[2], out scalarValuesZ);
            //}
            //else
            //{
            //    scalarValues.TryGetValue(scalarNames[1], out scalarValuesX);
            //    scalarValues.TryGetValue(scalarNames[2], out scalarValuesY);
            //    scalarValues.TryGetValue(scalarNames[3], out scalarValuesZ);
            //}

            vtkDoubleArray lambda2Values     = new vtkDoubleArray();
            List <double>  lambda2ValuesList = new List <double>();

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

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

                vectorField.Add(vec);
            }

            int count = 0;

            double[,] lambda2ValuesArray = new double[pointsToRegistrate.Count(), 2];
            for (int k = 0; k < tetraPoints.Count(); k++)
            {
                // first rows and than columns
                double[,] A         = new double[12, 12];
                double[,] rightSide = new double[12, 1];
                int i = 0, j = 0;
                int s = 0;

                if (k == 779834)
                {
                    Console.WriteLine("Test");
                }

                for (int g = 0; g < 12; g += 3, i++, s++)
                {
                    //1-3 columns of 4x3 Matrix
                    for (int l = 0; l < 3; l++)
                    {
                        for (int m = 0; m < 3; m++)
                        {
                            if (l == m)
                            {
                                // Warum tetraPoints[k]
                                A[g + l, m] = pointsToRegistrate[(int)tetraPoints[k][i]].X;
                            }
                            else
                            {
                                A[g + l, m] = 0;
                            }
                        }
                    }
                    for (int l = 0; l < 3; l++)
                    {
                        for (int m = 3; m < 6; m++)
                        {
                            if (l == (m - 3))
                            {
                                A[g + l, m] = pointsToRegistrate[(int)tetraPoints[k][i]].Y;
                            }
                            else
                            {
                                A[g + l, m] = 0;
                            }
                        }
                    }
                    for (int l = 0; l < 3; l++)
                    {
                        for (int m = 6; m < 9; m++)
                        {
                            if (l == (m - 6))
                            {
                                A[g + l, m] = pointsToRegistrate[(int)tetraPoints[k][i]].Z;
                            }
                            else
                            {
                                A[g + l, m] = 0;
                            }
                        }
                    }

                    for (int l = 0; l < 3; l++)
                    {
                        for (int m = 9; m < 12; m++)
                        {
                            if (l == (m - 9))
                            {
                                A[g + l, m] = 1;
                            }
                            else
                            {
                                A[g + l, m] = 0;
                            }
                        }
                    }

                    rightSide[g, 0]     = vectorField[(int)tetraPoints[k][s]].X;
                    rightSide[g + 1, 0] = vectorField[(int)tetraPoints[k][s]].Y;
                    rightSide[g + 2, 0] = vectorField[(int)tetraPoints[k][s]].Z;
                }

                //for (int l = 0; l < 12; l++)
                //{
                //    for (int m = 0; m < 12; m++)
                //    {
                //        Console.Write(A[l, m] + " ");
                //    }
                //    Console.WriteLine("");
                //}



                double[,] Vold = Accord.Math.Matrix.Solve(A, rightSide, leastSquares: true);
                // Solve matrix with matlab
                //LGS lgsObj = new LGS();
                //MWNumericArray mwV = (MWNumericArray)lgsObj.solveLGS((MWNumericArray)A, (MWNumericArray)rightSide);
                //double[,] V = new double[mwV.Dimensions[0], 1];
                //for (i = 1; i <= mwV.Dimensions[1]; i++)
                //{
                //    V[i, 0] = (double)mwV[1, i];
                //}

                double[,] jacobiMat = new double[3, 3];
                int n = 0;
                for (i = 0; i < 3; i++)
                {
                    for (j = 0; j < 3; j++)
                    {
                        // first increas rows and than columns
                        jacobiMat[j, i] = Vold[n, 0];
                        //jacobiMat[i, j] = Vold[n, 0];
                        n++;
                    }
                }

                if (jacobiMat[1, 1] == 0 && jacobiMat[0, 0] == 0 && jacobiMat[2, 2] == 0)
                {
                    //lambda2Values.InsertNextValue(0);
                    //lambda2ValuesList.Add(0);

                    count++;
                }
                //only if diagonal elements are not equal zero
                else
                {
                    MatrixOperations classObj = new MatrixOperations();

                    double[,] transposedJacobiMat = classObj.TransposeRowsAndColumns(jacobiMat);
                    // calculation of S und Omega
                    double[,] S        = classObj.DivideArrayByValue(classObj.AddArrays(jacobiMat, transposedJacobiMat), 2);
                    double[,] squaredS = classObj.MultiplyArrays(S, S);

                    double[,] Omega        = classObj.DivideArrayByValue(classObj.SubtractArrays(jacobiMat, transposedJacobiMat), 2);
                    double[,] squaredOmega = classObj.MultiplyArrays(Omega, Omega);

                    double[,] summation = classObj.AddArrays(squaredS, squaredOmega);

                    var    eigenvalueDecomposition = new Accord.Math.Decompositions.EigenvalueDecomposition(summation, false, true, true);
                    var    eigenVec   = eigenvalueDecomposition.Eigenvectors;
                    var    eigenValue = eigenvalueDecomposition.RealEigenvalues;
                    double lambda2    = eigenValue[1];

                    //int t = (int)lambda2Values.InsertNextValue(lambda2);

                    //lambda2ValuesList.Add(lambda2);

                    lambda2ValuesArray[(int)tetraPoints[k][0], 0] += lambda2;
                    lambda2ValuesArray[(int)tetraPoints[k][0], 1] += 1;


                    lambda2ValuesArray[(int)tetraPoints[k][1], 0] += lambda2;
                    lambda2ValuesArray[(int)tetraPoints[k][1], 1] += 1;

                    lambda2ValuesArray[(int)tetraPoints[k][2], 0] += lambda2;
                    lambda2ValuesArray[(int)tetraPoints[k][2], 1] += 1;

                    lambda2ValuesArray[(int)tetraPoints[k][3], 0] += lambda2;
                    lambda2ValuesArray[(int)tetraPoints[k][3], 1] += 1;

                    //if (k == 779834)
                    //    Console.WriteLine("Test");

                    //if (lambda2 < 0)
                    //{
                    //    lambda2ValuesArray[(int)tetraPoints[k][0], 0] = lambda2;
                    //    lambda2ValuesArray[(int)tetraPoints[k][0], 1] += 1;
                    //}
                    ////else
                    ////{
                    ////    lambda2ValuesArray[(int)tetraPoints[k][0], 0] += lambda2;
                    ////    lambda2ValuesArray[(int)tetraPoints[k][0], 1] += 1;
                    ////}
                    //if (lambda2 < 0)
                    //{
                    //    lambda2ValuesArray[(int)tetraPoints[k][1], 0] = lambda2;
                    //    lambda2ValuesArray[(int)tetraPoints[k][1], 1] += 1;

                    //}
                    ////else
                    ////{
                    ////    lambda2ValuesArray[(int)tetraPoints[k][1], 0] += lambda2;
                    ////    lambda2ValuesArray[(int)tetraPoints[k][1], 1] += 1;
                    ////}
                    //if (lambda2 < 0)
                    //{
                    //    lambda2ValuesArray[(int)tetraPoints[k][2], 0] = lambda2;
                    //    lambda2ValuesArray[(int)tetraPoints[k][2], 1] += 1;

                    //}
                    ////else
                    ////{
                    ////    lambda2ValuesArray[(int)tetraPoints[k][2], 0] += lambda2;
                    ////    lambda2ValuesArray[(int)tetraPoints[k][2], 1] += 1;
                    ////}
                    //if (lambda2 < 0)
                    //{
                    //    lambda2ValuesArray[(int)tetraPoints[k][3], 0] = lambda2;
                    //    lambda2ValuesArray[(int)tetraPoints[k][3], 1] += 1;

                    //}

                    // if (lambda2ValuesArray[(int)tetraPoints[k][0], 1] == 0)
                    //{
                    //    lambda2ValuesArray[(int)tetraPoints[k][0], 0] = lambda2;
                    //}
                    // if (lambda2ValuesArray[(int)tetraPoints[k][1], 1] == 0)
                    //{
                    //    lambda2ValuesArray[(int)tetraPoints[k][1], 0] = lambda2;
                    //}
                    // if (lambda2ValuesArray[(int)tetraPoints[k][2], 1] == 0)
                    //{
                    //    lambda2ValuesArray[(int)tetraPoints[k][2], 0] = lambda2;
                    //}
                    // if (lambda2ValuesArray[(int)tetraPoints[k][3], 1] == 0)
                    //{
                    //    lambda2ValuesArray[(int)tetraPoints[k][3], 0] = lambda2;
                    //}
                }
            }
            for (int i = 0; i < pointsToRegistrate.Count(); i++)
            {
                if (lambda2ValuesArray[i, 1] > 1)
                {
                    double lambda2 = lambda2ValuesArray[i, 0] / lambda2ValuesArray[i, 1];
                    //if (lambda2 < 0)
                    //    Console.WriteLine("lambda2 ist " + lambda2);
                    lambda2ValuesList.Add(lambda2);
                    lambda2Values.InsertNextValue(lambda2);
                    count++;
                }
                else
                {
                    count++;
                    lambda2Values.InsertNextValue(lambda2ValuesArray[i, 0]);
                }
            }

            //WriteScalarDifferences(lambda2ValuesList, "..\\..\\..\\..\\..\\03Daten\\lambda2\\Tomo_lambda2regularGridsOwnEigen.txt");
            vtkDataArray dataArray;

            dataArray = lambda2Values;
            dataArray.SetName("lambda2");
            if (this.scalar_dataArray.ContainsKey("lambda2"))
            {
                this.scalar_dataArray["lambda2"] = lambda2Values;
            }

            else
            {
                this.scalar_dataArray.Add("lambda2", dataArray);
                this.arrayNames.Add("lambda2");
            }
        }
コード例 #7
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();
        }
コード例 #8
0
        public void CalculateLambdaCriterionRegularGrids(List <Vector3d> pointsToRegistrate, Dictionary <string, List <float> > scalarValues, List <string> scalarNames, int[] dimensions)
        {
            List <float> scalarValuesX = new List <float>();

            scalarValues.TryGetValue(scalarNames[0], out scalarValuesX);
            List <float> scalarValuesY = new List <float>();

            scalarValues.TryGetValue(scalarNames[1], out scalarValuesY);
            List <float> scalarValuesZ = new List <float>();

            scalarValues.TryGetValue(scalarNames[2], out scalarValuesZ);

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

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

                vectorField.Add(vec);
            }

            vtkDoubleArray lambda2Values = new vtkDoubleArray();
            // lambda2Values.SetNumberOfValues(vectorField.Count());

            int sizeJacobimat = 3;

            // iterating over all points
            for (int k = 0; k < vectorField.Count(); k++)
            {
                if (k == 356003)
                {
                    Console.WriteLine("ID");
                }
                double[,] jacobiMat = new double[sizeJacobimat, sizeJacobimat];

                for (int j = 0, i = 0; j < sizeJacobimat; j++, i++)
                {
                    Vector3d vec = vectorField[k];

                    Vector3d gradVec = new Vector3d();
                    // first column of jacobi matrix
                    if (i == 0)
                    {
                        // forward difference
                        if (k == 0)
                        {
                            double hx = Math.Abs(pointsToRegistrate[k + 1].X - pointsToRegistrate[k].X);
                            gradVec = (vectorField[k + 1] - vec) / hx;
                        }
                        // backward difference
                        else if (k == vectorField.Count() - 1)
                        {
                            double hx = Math.Abs(pointsToRegistrate[k - 1].X - pointsToRegistrate[k].X);
                            gradVec = (vec - vectorField[k - 1]) / hx;
                        }
                        // central difference
                        else
                        {
                            double   hx = Math.Abs(pointsToRegistrate[k + 1].X - pointsToRegistrate[k].X);
                            Vector3d f  = vectorField[k + 1];
                            Vector3d b  = vectorField[k - 1];
                            gradVec = (f - b) / (2 * hx);
                        }
                    }
                    // second column of jacobi matrix
                    else if (i == 1)
                    {
                        // forward difference
                        if (k - dimensions[0] < 0)
                        {
                            double hy = Math.Abs(pointsToRegistrate[k + dimensions[0]].Y - pointsToRegistrate[k].Y);
                            gradVec = (vectorField[k + dimensions[0]] - vec) / hy;
                        }
                        // backward difference
                        else if (k + dimensions[0] > vectorField.Count() - 1)
                        {
                            double hy = Math.Abs(pointsToRegistrate[k - dimensions[0]].Y - pointsToRegistrate[k].Y);
                            gradVec = (vec - vectorField[k - dimensions[0]]) / hy;
                        }
                        // central difference
                        else
                        {
                            double   hy = Math.Abs(pointsToRegistrate[k + dimensions[0]].Y - pointsToRegistrate[k].Y);
                            Vector3d f  = vectorField[k + dimensions[0]];
                            Vector3d b  = vectorField[k - dimensions[0]];
                            gradVec = (f - b) / (2 * hy);
                        }
                    }
                    // third column of jacobi matrix
                    else if (i == 2)
                    {
                        // forward difference
                        if (k - (dimensions[0] * dimensions[1]) < 0)
                        {
                            double hz = Math.Abs(pointsToRegistrate[k + (dimensions[0] * dimensions[1])].Z - pointsToRegistrate[k].Z);
                            gradVec = (vectorField[k + (dimensions[0] * dimensions[1])] - vec) / hz;
                        }
                        // backward difference
                        else if (k + (dimensions[0] * dimensions[1]) > vectorField.Count() - 1)
                        {
                            double hz = Math.Abs(pointsToRegistrate[k - (dimensions[0] * dimensions[1])].Z - pointsToRegistrate[k].Z);
                            gradVec = (vec - vectorField[k - (dimensions[0] * dimensions[1])]) / hz;
                        }
                        // central difference
                        else
                        {
                            double   hz = Math.Abs(pointsToRegistrate[k + (dimensions[0] * dimensions[1])].Z - pointsToRegistrate[k].Z);
                            Vector3d f  = vectorField[k + (dimensions[0] * dimensions[1])];
                            Vector3d b  = vectorField[k - (dimensions[0] * dimensions[1])];
                            gradVec = (f - b) / (2 * hz);
                        }
                    }
                    // fill jacobi matrix
                    jacobiMat[0, j] = gradVec[0];
                    jacobiMat[1, j] = gradVec[1];
                    if (sizeJacobimat == 3)
                    {
                        jacobiMat[2, j] = gradVec[2];
                    }
                }
                // only if diagonal elements are not equal zero
                if (jacobiMat[1, 1] == 0 && jacobiMat[0, 0] == 0 && jacobiMat[2, 2] == 0)
                {
                    lambda2Values.InsertNextValue(0);
                }
                else
                {
                    MatrixOperations classObj = new MatrixOperations();

                    double[,] transposedJacobiMat = classObj.TransposeRowsAndColumns(jacobiMat);
                    // calculation of S und Omega
                    double[,] S        = classObj.DivideArrayByValue(classObj.AddArrays(jacobiMat, transposedJacobiMat), 2);
                    double[,] squaredS = classObj.MultiplyArrays(S, S);

                    double[,] Omega        = classObj.DivideArrayByValue(classObj.SubtractArrays(jacobiMat, transposedJacobiMat), 2);
                    double[,] squaredOmega = classObj.MultiplyArrays(Omega, Omega);

                    double[,] summation = classObj.AddArrays(squaredS, squaredOmega);

                    var    eigenvalueDecomposition = new Accord.Math.Decompositions.EigenvalueDecomposition(summation, false, false, true);
                    var    eigenVec   = eigenvalueDecomposition.Eigenvectors;
                    var    eigenValue = eigenvalueDecomposition.RealEigenvalues;
                    double lambda2    = eigenValue[1];


                    lambda2Values.InsertNextValue(lambda2);
                }
            }
            vtkDataArray dataArray;

            dataArray = lambda2Values;
            dataArray.SetName("lambda2");
            Console.WriteLine("All lambda2 were calculated!");
            if (this.scalar_dataArray.ContainsKey("lambda2"))
            {
                this.scalar_dataArray["lambda2"] = lambda2Values;
            }

            else
            {
                this.scalar_dataArray.Add("lambda2", dataArray);
                this.arrayNames.Add("lambda2");
            }
        }
コード例 #9
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");
            }
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        private void RenderXYZColor()
        {
            FileStream   fs = null;
            StreamReader sr = null;
            String       sLineBuffer;

            String[]  sXYZ;
            char[]    chDelimiter = new char[] { ' ', '\t', ';' };
            double[]  xyz         = new double[3];
            double[]  rgb         = new double[3];
            vtkPoints points      = vtkPoints.New();
            vtkPoints colors      = vtkPoints.New();
            int       cnt         = 0;

            try
            {
                // in case file must be open in another application too use "FileShare.ReadWrite"
                fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                sr = new StreamReader(fs);

                vtkDoubleArray colorScalor = new vtkDoubleArray();
                int            n           = 1;
                while (!sr.EndOfStream)
                {
                    sLineBuffer = sr.ReadLine();
                    cnt++;
                    sXYZ = sLineBuffer.Split(chDelimiter, StringSplitOptions.RemoveEmptyEntries);
                    if (sXYZ == null || sXYZ.Length != 6)
                    {
                        MessageBox.Show("data seems to be in wrong format at line " + cnt, "Format Exception", MessageBoxButtons.OK);
                        return;
                    }
                    xyz[0] = double.Parse(sXYZ[0], CultureInfo.InvariantCulture) * 11100;
                    xyz[1] = double.Parse(sXYZ[1], CultureInfo.InvariantCulture) * 11100;
                    xyz[2] = double.Parse(sXYZ[2], CultureInfo.InvariantCulture);

                    rgb[0] = double.Parse(sXYZ[0], CultureInfo.InvariantCulture);
                    rgb[1] = double.Parse(sXYZ[1], CultureInfo.InvariantCulture);
                    rgb[2] = double.Parse(sXYZ[2], CultureInfo.InvariantCulture);

                    points.InsertNextPoint(xyz[0], xyz[1], xyz[2]);
                    colors.InsertNextPoint(rgb[0], rgb[1], rgb[2]);
                    colorScalor.InsertNextTuple1(n++);
                }
                vtkPolyData polydata = vtkPolyData.New();
                polydata.SetPoints(points);
                polydata.GetPointData().SetScalars(colorScalor); //设置点的Scalar(标量)属性

                vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();
                glyphFilter.SetInputConnection(polydata.GetProducerPort());

                vtkLookupTable lookupTable = new vtkLookupTable();
                lookupTable.SetNumberOfColors(n);
                // SetSetTableValue(vtkIdType  indx, double r, double g, double  b, double a);
                Random random = new Random();
                for (int i = 0; i < n; i++)
                {
                    double[] tmp = colors.GetPoint(i);
                    double   r   = tmp[0];
                    double   g   = tmp[1];
                    double   b   = tmp[2];
                    lookupTable.SetTableValue(i, r, g, b, 1);
                }

                // Visualize
                vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
                mapper.SetInputConnection(glyphFilter.GetOutputPort());
                mapper.SetLookupTable(lookupTable);
                mapper.SetScalarRange(1, n);

                vtkActor actor = vtkActor.New();
                actor.SetMapper(mapper);
                actor.GetProperty().SetPointSize(1);
                //actor.GetProperty().SetColor(1, 0.5, 0);
                // add our actor to the renderer
                m_Renderer.AddActor(actor);
                imgPropList.Add(actor);

                m_Renderer.ResetCamera();

                //Rerender the screen
                m_RenderWindow.Render();
                m_Renderer.Render();
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "IOException", MessageBoxButtons.OK);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                    sr = null;
                }
            }
        }
コード例 #12
0
        private void WarpVector()
        {
            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(0.0, 0.0, 0.0);
            points.InsertNextPoint(1.0, 0.0, 0.0);
            points.InsertNextPoint(2.0, 0.0, 0.0);
            points.InsertNextPoint(3.0, 0.0, 0.0);
            points.InsertNextPoint(4.0, 0.0, 0.0);

            vtkCellArray lines = vtkCellArray.New();
            vtkLine      line  = vtkLine.New();

            line.GetPointIds().SetId(0, 0);
            line.GetPointIds().SetId(1, 1);
            lines.InsertNextCell(line);
            line.GetPointIds().SetId(0, 1);
            line.GetPointIds().SetId(1, 2);
            lines.InsertNextCell(line);
            line.GetPointIds().SetId(0, 2);
            line.GetPointIds().SetId(1, 3);
            lines.InsertNextCell(line);
            line.GetPointIds().SetId(0, 3);
            line.GetPointIds().SetId(1, 4);
            lines.InsertNextCell(line);

            vtkDoubleArray warpData = vtkDoubleArray.New();

            warpData.SetNumberOfComponents(3);
            warpData.SetName("warpData");
            double[] warp = new double[] { 0.0, 0.0, 0.0 };
            warp[1] = 0.0;
            warpData.InsertNextTuple3(warp[0], warp[1], warp[2]);
            warp[1] = 0.1;
            warpData.InsertNextTuple3(warp[0], warp[1], warp[2]);
            warp[1] = 0.3;
            warpData.InsertNextTuple3(warp[0], warp[1], warp[2]);
            warp[1] = 0.0;
            warpData.InsertNextTuple3(warp[0], warp[1], warp[2]);
            warp[1] = 0.1;
            warpData.InsertNextTuple3(warp[0], warp[1], warp[2]);

            vtkPolyData polydata = vtkPolyData.New();

            polydata.SetPoints(points);
            polydata.SetLines(lines);
            polydata.GetPointData().AddArray(warpData);
            polydata.GetPointData().SetActiveVectors(warpData.GetName());

            //WarpVector will use the array marked as active vector in polydata
            //it has to be a 3 component array
            //with the same number of tuples as points in polydata
            vtkWarpVector warpVector = vtkWarpVector.New();

#if VTK_MAJOR_VERSION_5
            warpVector.SetInput(polydata);
#else
            warpVector.SetInputData(polydata);
#endif
            warpVector.Update();

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            mapper.SetInput(warpVector.GetPolyDataOutput());
#else
            mapper.SetInputData(warpVector.GetPolyDataOutput());
#endif
            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(.2, .6, .3);
            renderer.AddActor(actor);
        }