Exemple #1
0
        private void SelectPointClick(vtkObject sender, vtkObjectEventArgs e)
        {
            if (ModelLoaded == true && SelectionMode == true)
            {
                int[]          clickPos    = Inter.GetEventPosition();
                vtkPointPicker PointPicker = vtkPointPicker.New();
                PointPicker.SetTolerance(0.05);
                PointPicker.Pick(clickPos[0], clickPos[1], 0, Viewport);

                vtkPoints points = Faces.GetPoints();

                double[] PickPosition = PointPicker.GetPickPosition();

                for (int j = 0; j < points.GetNumberOfPoints(); j++)
                {
                    if (Math.Abs(points.GetPoint(j)[0] - PickPosition[0]) < 1e-6 &&
                        Math.Abs(points.GetPoint(j)[1] - PickPosition[1]) < 1e-6 &&
                        Math.Abs(points.GetPoint(j)[2] - PickPosition[2]) < 1e-6)
                    {
                        SelectionPoints.InsertNextPoint(PickPosition[0], PickPosition[1], PickPosition[2]);
                        break;
                    }
                }

                SelectionGlyph = vtkGlyph3D.New();
                SelectionGlyph.SetInput(SelectionPolyData);
                SelectionGlyph.SetSourceConnection(SelectionSphere.GetOutputPort());
                SelectionMapper.SetInputConnection(SelectionGlyph.GetOutputPort());
                SelectionActor.SetMapper(SelectionMapper);

                // Refresh Viewport
                Refresh();
            }
        }
Exemple #2
0
        private void VectorFieldNonZeroExtraction()
        {
            // Create an image
            vtkImageData image = vtkImageData.New();

            CreateVectorField(ref image);

            // This filter produces a vtkImageData with an array named "Magnitude"
            vtkImageMagnitude magnitudeFilter = vtkImageMagnitude.New();

            magnitudeFilter.SetInputConnection(image.GetProducerPort());
            magnitudeFilter.Update();

            image.GetPointData().AddArray(magnitudeFilter.GetOutput().GetPointData().GetScalars());
            image.GetPointData().SetActiveScalars("Magnitude");

            vtkThresholdPoints thresholdVector = vtkThresholdPoints.New();

            thresholdVector.SetInput(image);
            thresholdVector.SetInputArrayToProcess(
                0,
                0,
                (int)vtkDataObject.FieldAssociations.FIELD_ASSOCIATION_POINTS,
                (int)vtkDataSetAttributes.AttributeTypes.SCALARS,
                "Magnitude");
            thresholdVector.ThresholdByUpper(0.00001);
            thresholdVector.Update();

            // in case you want to save imageData
            //vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New();
            //writer.SetFileName("output.vtp");
            //writer.SetInputConnection(thresholdPoints.GetOutputPort());
            //writer.Write();

            // repesents the pixels
            vtkCubeSource cubeSource = vtkCubeSource.New();

            cubeSource.SetXLength(2.0);
            cubeSource.SetYLength(2.0);
            cubeSource.SetZLength(2.0);
            vtkGlyph3D glyph = vtkGlyph3D.New();

            glyph.SetInput(image);
            glyph.SetSourceConnection(cubeSource.GetOutputPort());
            // don't scale glyphs according to any scalar data
            glyph.SetScaleModeToDataScalingOff();

            vtkPolyDataMapper glyphMapper = vtkPolyDataMapper.New();

            glyphMapper.SetInputConnection(glyph.GetOutputPort());
            // don't color glyphs according to scalar data
            glyphMapper.ScalarVisibilityOff();
            glyphMapper.SetScalarModeToDefault();

            vtkActor actor = vtkActor.New();

            actor.SetMapper(glyphMapper);

            // represent vector field
            vtkGlyph3D        vectorGlyph       = vtkGlyph3D.New();
            vtkArrowSource    arrowSource       = vtkArrowSource.New();
            vtkPolyDataMapper vectorGlyphMapper = vtkPolyDataMapper.New();

            int n = image.GetPointData().GetNumberOfArrays();

            for (int i = 0; i < n; i++)
            {
                Debug.WriteLine("name of array[" + i + "]: " + image.GetPointData().GetArrayName(i));
            }

            vtkPolyData tmp = thresholdVector.GetOutput();

            Debug.WriteLine("number of thresholded points: " + tmp.GetNumberOfPoints());
            vectorGlyph.SetInputConnection(thresholdVector.GetOutputPort());

            // in case you want the point glyphs to be oriented according to
            // scalar values in array "ImageScalars" uncomment the following line
            image.GetPointData().SetActiveVectors("ImageScalars");

            vectorGlyph.SetSourceConnection(arrowSource.GetOutputPort());
            vectorGlyph.SetScaleModeToScaleByVector();
            vectorGlyph.SetVectorModeToUseVector();
            vectorGlyph.ScalingOn();
            vectorGlyph.OrientOn();
            vectorGlyph.SetInputArrayToProcess(
                1,
                0,
                (int)vtkDataObject.FieldAssociations.FIELD_ASSOCIATION_POINTS,
                (int)vtkDataSetAttributes.AttributeTypes.SCALARS,
                "ImageScalars");

            vectorGlyph.Update();

            vectorGlyphMapper.SetInputConnection(vectorGlyph.GetOutputPort());
            vectorGlyphMapper.Update();

            vtkActor vectorActor = vtkActor.New();

            vectorActor.SetMapper(vectorGlyphMapper);


            // 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);
            //Add the actors to the renderer, set the background and size
            renderer.AddActor(actor);
            renderer.AddActor(vectorActor);
        }
Exemple #3
0
        /// <summary>
        /// Update Boundary Condition actor (arrows) in Viewport
        /// </summary>
        public void Update_Arrows(Dictionary <int, Node> NodeLib, double scale, int Step, bool ClipMode)
        {
            vtkPoints PointsX = vtkPoints.New();
            vtkPoints PointsY = vtkPoints.New();
            vtkPoints PointsZ = vtkPoints.New();

            // Create Cone Sources for X, Y and Z direction
            vtkConeSource ConeSourceX = vtkConeSource.New();
            vtkConeSource ConeSourceY = vtkConeSource.New();
            vtkConeSource ConeSourceZ = vtkConeSource.New();

            ConeSourceX.SetAngle(15);
            ConeSourceX.SetHeight(scale);
            ConeSourceX.SetRadius(scale / 4);
            ConeSourceX.SetResolution(12);
            ConeSourceX.SetDirection(1, 0, 0);

            ConeSourceY.SetAngle(15);
            ConeSourceY.SetHeight(scale);
            ConeSourceY.SetRadius(scale / 4);
            ConeSourceY.SetResolution(12);
            ConeSourceY.SetDirection(0, 1, 0);

            ConeSourceZ.SetAngle(15);
            ConeSourceZ.SetHeight(scale);
            ConeSourceZ.SetRadius(scale / 4);
            ConeSourceZ.SetResolution(12);
            ConeSourceZ.SetDirection(0, 0, 1);

            // Create Points
            foreach (int i in NodalValues.Keys)
            {
                double X = NodeLib[i].X + NodeLib[i].GetDisp(Step, 0);
                double Y = NodeLib[i].Y + NodeLib[i].GetDisp(Step, 1);
                double Z = NodeLib[i].Z + NodeLib[i].GetDisp(Step, 2);

                if (NodalValues[i].Get(0, 0) != 0)
                {
                    PointsX.InsertNextPoint(X - scale / 2, Y, Z);
                }
                if (NodalValues[i].Get(1, 0) != 0)
                {
                    PointsY.InsertNextPoint(X, Y - scale / 2, Z);
                }
                if (NodalValues[i].Get(2, 0) != 0)
                {
                    PointsZ.InsertNextPoint(X, Y, Z - scale / 2);
                }
            }

            // Set Points to PolyData
            vtkPolyData PolyX = vtkPolyData.New(); PolyX.SetPoints(PointsX);
            vtkPolyData PolyY = vtkPolyData.New(); PolyY.SetPoints(PointsY);
            vtkPolyData PolyZ = vtkPolyData.New(); PolyZ.SetPoints(PointsZ);

            // Create Glyphs 3D
            GlyphX = vtkGlyph3D.New();
            GlyphY = vtkGlyph3D.New();
            GlyphZ = vtkGlyph3D.New();

            GlyphX.SetSourceConnection(ConeSourceX.GetOutputPort());
            GlyphX.SetInput(PolyX);
            GlyphX.Update();

            GlyphY.SetSourceConnection(ConeSourceY.GetOutputPort());
            GlyphY.SetInput(PolyY);
            GlyphY.Update();

            GlyphZ.SetSourceConnection(ConeSourceZ.GetOutputPort());
            GlyphZ.SetInput(PolyZ);
            GlyphZ.Update();

            // Set Mapper based on Clip Mode
            if (ClipMode == true)
            {
                // Add Clippers to Mapper
                ClipperX.SetInputConnection(GlyphX.GetOutputPort());
                ClipperX.Update();
                MapperX.SetInputConnection(ClipperX.GetOutputPort());
                MapperX.Update();

                ClipperY.SetInputConnection(GlyphY.GetOutputPort());
                ClipperY.Update();
                MapperY.SetInputConnection(ClipperY.GetOutputPort());
                MapperY.Update();

                ClipperZ.SetInputConnection(GlyphZ.GetOutputPort());
                ClipperZ.Update();
                MapperZ.SetInputConnection(ClipperZ.GetOutputPort());
                MapperZ.Update();
            }
            else
            {
                // Add Glyphs to Mapper
                MapperX.SetInputConnection(GlyphX.GetOutputPort());
                MapperY.SetInputConnection(GlyphY.GetOutputPort());
                MapperZ.SetInputConnection(GlyphZ.GetOutputPort());
                MapperX.Update();
                MapperY.Update();
                MapperZ.Update();
            }

            // Update Actor color
            ActorX.GetProperty().SetColor(
                GetColor()[0] / 255.0,
                GetColor()[1] / 255.0,
                GetColor()[2] / 255.0);

            ActorY.GetProperty().SetColor(
                GetColor()[0] / 255.0,
                GetColor()[1] / 255.0,
                GetColor()[2] / 255.0);

            ActorZ.GetProperty().SetColor(
                GetColor()[0] / 255.0,
                GetColor()[1] / 255.0,
                GetColor()[2] / 255.0);
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVclosedSplines(String [] argv)
    {
        //Prefix Content is: ""

          // get the interactor ui[]
          // Now create the RenderWindow, Renderer and Interactor[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          math = new vtkMath();
          numberOfInputPoints = 30;
          aKSplineX = new vtkKochanekSpline();
          aKSplineX.ClosedOn();
          aKSplineY = new vtkKochanekSpline();
          aKSplineY.ClosedOn();
          aKSplineZ = new vtkKochanekSpline();
          aKSplineZ.ClosedOn();
          aCSplineX = new vtkCardinalSpline();
          aCSplineX.ClosedOn();
          aCSplineY = new vtkCardinalSpline();
          aCSplineY.ClosedOn();
          aCSplineZ = new vtkCardinalSpline();
          aCSplineZ.ClosedOn();
          // add some points[]
          inputPoints = new vtkPoints();
          x = -1.0;
          y = -1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)0,(double)x);
          aKSplineY.AddPoint((double)0,(double)y);
          aKSplineZ.AddPoint((double)0,(double)z);
          aCSplineX.AddPoint((double)0,(double)x);
          aCSplineY.AddPoint((double)0,(double)y);
          aCSplineZ.AddPoint((double)0,(double)z);
          inputPoints.InsertPoint((int)0,(double)x,(double)y,(double)z);
          x = 1.0;
          y = -1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)1,(double)x);
          aKSplineY.AddPoint((double)1,(double)y);
          aKSplineZ.AddPoint((double)1,(double)z);
          aCSplineX.AddPoint((double)1,(double)x);
          aCSplineY.AddPoint((double)1,(double)y);
          aCSplineZ.AddPoint((double)1,(double)z);
          inputPoints.InsertPoint((int)1,(double)x,(double)y,(double)z);
          x = 1.0;
          y = 1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)2,(double)x);
          aKSplineY.AddPoint((double)2,(double)y);
          aKSplineZ.AddPoint((double)2,(double)z);
          aCSplineX.AddPoint((double)2,(double)x);
          aCSplineY.AddPoint((double)2,(double)y);
          aCSplineZ.AddPoint((double)2,(double)z);
          inputPoints.InsertPoint((int)2,(double)x,(double)y,(double)z);
          x = -1.0;
          y = 1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)3,(double)x);
          aKSplineY.AddPoint((double)3,(double)y);
          aKSplineZ.AddPoint((double)3,(double)z);
          aCSplineX.AddPoint((double)3,(double)x);
          aCSplineY.AddPoint((double)3,(double)y);
          aCSplineZ.AddPoint((double)3,(double)z);
          inputPoints.InsertPoint((int)3,(double)x,(double)y,(double)z);
          inputData = new vtkPolyData();
          inputData.SetPoints((vtkPoints)inputPoints);
          balls = new vtkSphereSource();
          balls.SetRadius((double).04);
          balls.SetPhiResolution((int)10);
          balls.SetThetaResolution((int)10);
          glyphPoints = new vtkGlyph3D();
          glyphPoints.SetInput((vtkDataObject)inputData);
          glyphPoints.SetSource((vtkPolyData)balls.GetOutput());
          glyphMapper = vtkPolyDataMapper.New();
          glyphMapper.SetInputConnection((vtkAlgorithmOutput)glyphPoints.GetOutputPort());
          glyph = new vtkActor();
          glyph.SetMapper((vtkMapper)glyphMapper);
          glyph.GetProperty().SetDiffuseColor((double) 1.0000, 0.3882, 0.2784 );
          glyph.GetProperty().SetSpecular((double).3);
          glyph.GetProperty().SetSpecularPower((double)30);
          ren1.AddActor((vtkProp)glyph);
          Kpoints = new vtkPoints();
          Cpoints = new vtkPoints();
          profileKData = new vtkPolyData();
          profileCData = new vtkPolyData();
          numberOfInputPoints = 5;
          numberOfOutputPoints = 100;
          offset = 1.0;
          //method moved
          fit();
          lines = new vtkCellArray();
          lines.InsertNextCell((int)numberOfOutputPoints);
          i = 0;
          while((i) < numberOfOutputPoints)
        {
          lines.InsertCellPoint((int)i);
          i = i + 1;
        }

          profileKData.SetPoints((vtkPoints)Kpoints);
          profileKData.SetLines((vtkCellArray)lines);
          profileCData.SetPoints((vtkPoints)Cpoints);
          profileCData.SetLines((vtkCellArray)lines);
          profileKTubes = new vtkTubeFilter();
          profileKTubes.SetNumberOfSides((int)8);
          profileKTubes.SetInput((vtkDataObject)profileKData);
          profileKTubes.SetRadius((double).01);
          profileKMapper = vtkPolyDataMapper.New();
          profileKMapper.SetInputConnection((vtkAlgorithmOutput)profileKTubes.GetOutputPort());
          profileK = new vtkActor();
          profileK.SetMapper((vtkMapper)profileKMapper);
          profileK.GetProperty().SetDiffuseColor((double) 0.8900, 0.8100, 0.3400 );
          profileK.GetProperty().SetSpecular((double).3);
          profileK.GetProperty().SetSpecularPower((double)30);
          ren1.AddActor((vtkProp)profileK);
          profileCTubes = new vtkTubeFilter();
          profileCTubes.SetNumberOfSides((int)8);
          profileCTubes.SetInput((vtkDataObject)profileCData);
          profileCTubes.SetRadius((double).01);
          profileCMapper = vtkPolyDataMapper.New();
          profileCMapper.SetInputConnection((vtkAlgorithmOutput)profileCTubes.GetOutputPort());
          profileC = new vtkActor();
          profileC.SetMapper((vtkMapper)profileCMapper);
          profileC.GetProperty().SetDiffuseColor((double) 0.2000, 0.6300, 0.7900 );
          profileC.GetProperty().SetSpecular((double).3);
          profileC.GetProperty().SetSpecularPower((double)30);
          ren1.AddActor((vtkProp)profileC);
          ren1.ResetCamera();
          ren1.GetActiveCamera().Dolly((double)1.5);
          ren1.ResetCameraClippingRange();
          renWin.SetSize((int)300,(int)300);
          // render the image[]
          //[]
          iren.Initialize();
          // prevent the tk window from showing up then start the event loop[]
          //method moved
          //method moved
          //method moved
          //method moved
          //method moved
          //method moved

        //deleteAllVTKObjects();
    }
Exemple #5
0
        public void CreateViewport(Grid Window)
        {
            WindowsFormsHost VTK_Window = new WindowsFormsHost(); // Create Windows Forms Host for VTK Window

            RenWinControl = new RenderWindowControl();            // Initialize VTK Renderer Window Control

            // Clear input Window and add new host
            Window.Children.Clear();
            Window.Children.Add(VTK_Window);
            VTK_Window.Child = RenWinControl;

            // Create Render Window
            renderWindow = RenWinControl.RenderWindow;

            // Initialize Interactor
            Inter = vtkRenderWindowInteractor.New();
            Inter.LeftButtonPressEvt  += new vtkObject.vtkObjectEventHandler(SelectPointClick);
            Inter.RightButtonPressEvt += new vtkObject.vtkObjectEventHandler(UnselectPointClick);
            renderWindow.SetInteractor(Inter);
            Inter.Initialize();

            InterStyleTrack = vtkInteractorStyleTrackballCamera.New();
            //Inter.SetInteractorStyle(InterStyleTrack);
            InterStylePick = vtkInteractorStyleRubberBandPick.New();
            Inter.SetInteractorStyle(InterStylePick);

            // Initialize View
            Viewport = renderWindow.GetRenderers().GetFirstRenderer();
            Viewport.RemoveAllViewProps();
            CreateViewportBorder(Viewport, new double[3] {
                128.0, 128.0, 128.0
            });

            // Set default background color
            Viewport.GradientBackgroundOn();
            Viewport.SetBackground(163.0 / 255.0, 163.0 / 255.0, 163.0 / 255.0);
            Viewport.SetBackground2(45.0 / 255.0, 85.0 / 255.0, 125.0 / 255.0);

            // Other properties
            Viewport.GetActiveCamera().ParallelProjectionOn();

            // Initialize Selection objects
            AppendFaces       = vtkAppendPolyData.New();
            Faces             = vtkPolyData.New();
            SelectionMode     = false;
            SelectionSize     = 0.1;
            SelectionPoints   = vtkPoints.New();
            SelectionActor    = vtkActor.New();
            SelectionPolyData = vtkPolyData.New();
            SelectionPolyData.SetPoints(SelectionPoints);

            SelectionSphere = vtkSphereSource.New();
            SelectionSphere.SetPhiResolution(12);
            SelectionSphere.SetThetaResolution(12);
            SelectionSphere.SetRadius(SelectionSize);
            SelectionGlyph = vtkGlyph3D.New();
            SelectionGlyph.SetInput(SelectionPolyData);
            SelectionGlyph.SetSourceConnection(SelectionSphere.GetOutputPort());
            SelectionMapper = vtkPolyDataMapper.New();
            SelectionMapper.SetInputConnection(SelectionGlyph.GetOutputPort());

            SelectionActor.SetMapper(SelectionMapper);
            SelectionActor.GetProperty().SetColor(1, 1, 1);
            SelectionActor.VisibilityOn();
            Viewport.AddActor(SelectionActor);

            // Create new Properties and Objects
            CreateColorMap();
            CreateScalarBar();
            CreateAxes();
            CreateSlider();
            CreateClipPlane();
        }
Exemple #6
0
        private void SelectAreaClick(vtkObject sender, vtkObjectEventArgs e)
        {
            int[]         clickPos = Inter.GetEventPosition();
            vtkAreaPicker picker   = vtkAreaPicker.New();

            picker.AreaPick(clickPos[0], clickPos[1], clickPos[0] + 100, clickPos[1] + 100, Viewport);

            if (picker.GetActor() != null)
            {
                vtkPlanes          Boundary = picker.GetFrustum();
                vtkExtractGeometry Box      = vtkExtractGeometry.New();
                Box.SetImplicitFunction(Boundary);
                Box.SetInput(picker.GetActor().GetMapper().GetInput());

                vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();
                glyphFilter.SetInputConnection(Box.GetOutputPort());
                glyphFilter.Update();

                vtkPolyData         selected = glyphFilter.GetOutput();
                vtkPoints           points   = vtkPoints.New();
                vtkUnstructuredGrid grid     = vtkUnstructuredGrid.New();
                for (int i = 0; i < selected.GetNumberOfPoints(); i++)
                {
                    points.InsertNextPoint(selected.GetPoint(i)[0], selected.GetPoint(i)[1], selected.GetPoint(i)[2]);
                }
                grid.SetPoints(points);
                vtkSphereSource sphere = vtkSphereSource.New();
                sphere.SetPhiResolution(6);
                sphere.SetThetaResolution(6);
                sphere.SetRadius(0.1);
                vtkGlyph3D glyph3D = vtkGlyph3D.New();
                glyph3D.SetInput(grid);
                glyph3D.SetSourceConnection(sphere.GetOutputPort());

                vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
                mapper.SetInputConnection(glyph3D.GetOutputPort());

                //double[] P = new double[3];
                //bool selected = false;
                //vtkPoints points = Faces.GetPoints();
                //double[] ClickedPoint = PointPicker.GetActor().GetMapper().GetInput().GetPoint(PointPicker.GetPointId());
                //for (int i = 0; i < points.GetNumberOfPoints(); i++)
                //{
                //    if (Math.Abs(points.GetPoint(i)[0] - ClickedPoint[0]) < 1e-6 &&
                //        Math.Abs(points.GetPoint(i)[1] - ClickedPoint[1]) < 1e-6 &&
                //        Math.Abs(points.GetPoint(i)[2] - ClickedPoint[2]) < 1e-6)
                //    {
                //        selected = true;
                //        P = points.GetPoint(i);
                //        break;
                //    }
                //}
                //
                //if (selected == true)
                //{
                //    SelectionPoints.InsertNextPoint(P[0], P[1], P[2]);
                //
                //    SelectionGlyph = vtkGlyph3D.New();
                //    SelectionGlyph.SetInput(SelectionPolyData);
                //    SelectionGlyph.SetSourceConnection(SelectionSphere.GetOutputPort());
                //    SelectionMapper.SetInputConnection(SelectionGlyph.GetOutputPort());
                //
                //    // Refresh Viewport
                //    Refresh();
                //}
            }
        }