示例#1
0
        public void Create(cPoint3D MinPt, cPoint3D MaxPt, Color Colour)
        {
            Position = new cPoint3D(0, 0, 0);

            this.Colour = Colour;
            BoundingBox = vtkCubeSource.New();
            BoundingBox.SetBounds(MinPt.X, MaxPt.X, MinPt.Y, MaxPt.Y, MinPt.Z, MaxPt.Z);

            vtk_PolyDataMapper = vtkPolyDataMapper.New();
            vtk_PolyDataMapper.SetInputConnection(BoundingBox.GetOutputPort());

            CreateVTK3DObject(0);
        }
示例#2
0
        private void Cube()
        {
            // Create a cube.
            vtkCubeSource cubeSource = vtkCubeSource.New();

            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(cubeSource.GetOutputPort());
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.3, 0.2, 0.1);
            renderer.AddActor(actor);
            renderer.ResetCamera();
        }
示例#3
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);
        }
示例#4
0
        /// <summary>
        /// 绘制立长方体的边缘
        /// </summary>
        /// <param name="bgColor">边缘的颜色</param>
        /// <param name="actors">添加至该对象</param>
        public void AddContainerEdgeToActorCollection(byte[] bgColor, ref vtkActorCollection actors)
        {
            vtkProperty pp = vtkProperty.New();

            pp.SetOpacity(0.5);
            pp.SetColor(bgColor[0], bgColor[1], bgColor[2]);
            pp.SetLineWidth(5);
            pp.SetLighting(false);

            vtkCubeSource cs = vtkCubeSource.New();

            cs.SetCenter(sideLen / 2, sideLen / 2, height / 2);
            cs.SetXLength(sideLen);
            cs.SetYLength(sideLen);
            cs.SetZLength(height);

            #region 采用描点的方式绘制长方体 只需要添加到mapper.SetInput(pd);即可
            //vtkPoints points = vtkPoints.New();
            //points.InsertNextPoint(0 + offset[0], 0 + offset[1], 0 + offset[2]);
            //points.InsertNextPoint(sideLen + offset[0], 0 + offset[1], 0 + offset[2]);
            //points.InsertNextPoint(sideLen + offset[0], sideLen + offset[1], 0 + offset[2]);
            //points.InsertNextPoint(0 + offset[0], sideLen + offset[1], 0 + offset[2]);

            //points.InsertNextPoint(0 + offset[0], sideLen + offset[1], height + offset[2]);
            //points.InsertNextPoint(sideLen + offset[0], sideLen + offset[1], height + offset[2]);
            //points.InsertNextPoint(sideLen + offset[0], 0 + offset[1], height + offset[2]);
            //points.InsertNextPoint(0 + offset[0], 0 + offset[1], height + offset[2]);

            //vtkPolyData pd = vtkPolyData.New();

            //vtkLine line = vtkLine.New();

            //vtkCellArray cellArr = vtkCellArray.New();

            ////描出边框
            //for (int i = 0; i < 4; i++)
            //{
            //    line.GetPointIds().SetId(0, i);
            //    line.GetPointIds().SetId(1, (i + 1) % 4);
            //    cellArr.InsertNextCell(line);

            //    line.GetPointIds().SetId(0, i + 4);
            //    line.GetPointIds().SetId(1, (i + 1) % 4 + 4);
            //    cellArr.InsertNextCell(line);

            //    line.GetPointIds().SetId(0, i);
            //    line.GetPointIds().SetId(1, 7 - i);
            //    cellArr.InsertNextCell(line);

            //}

            //IntPtr iColor = Marshal.AllocHGlobal(bgColor.Length);
            //Marshal.Copy(bgColor, 0, iColor, bgColor.Length);

            //vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();

            //colors.SetNumberOfComponents(3);
            //for (int i = 0; i < cellArr.GetNumberOfCells(); i++)
            //{
            //    colors.InsertNextTupleValue(iColor);
            //}

            //pd.SetPoints(points);
            //pd.SetLines(cellArr);
            //pd.GetCellData().SetScalars(colors);
            //Marshal.FreeHGlobal(iColor);
            #endregion

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
            //mapper.SetInput(pd);
            mapper.SetInputConnection(cs.GetOutputPort());
            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.SetProperty(pp);

            actors.AddItem(actor);
        }
示例#5
0
        public c3DWell(cPoint3D MinPt, cPoint3D MaxPt, Color Colour, cWell CurrentWell)
        {
            this.SetPosition(new cPoint3D(0, 0, 0));

            this.Colour = Colour;
            VTK_Cube = vtkCubeSource.New();
            //VTK_Cube.SetBounds(MinPt.X, MaxPt.X, MinPt.Y, MaxPt.Y, MinPt.Z, MaxPt.Z);
            VTK_Cube.SetXLength(MaxPt.X - MinPt.X);
            VTK_Cube.SetYLength(MaxPt.Y - MinPt.Y);
            VTK_Cube.SetZLength(MaxPt.Z - MinPt.Z);

            vtk_PolyDataMapper = vtkPolyDataMapper.New();
            vtk_PolyDataMapper.SetInputConnection(VTK_Cube.GetOutputPort());

            this.SetPosition(MinPt);
            this.Colour = Colour;
            this.AssociatedWell = CurrentWell;

            CreateVTK3DObject(1);
            Information = new cInformation(this);
        }
示例#6
0
        private void DrawAssembly()
        {
            //Create four parts: a top level assembly and three primitives

            vtkSphereSource   sphereSource = vtkSphereSource.New();
            vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New();

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

            sphereActor.SetMapper(sphereMapper);
            sphereActor.SetOrigin(2, 1, 3);
            sphereActor.RotateY(6);
            sphereActor.SetPosition(2.25, 0, 0);
            sphereActor.GetProperty().SetColor(1, 0, 1);

            vtkCubeSource     cubeSource = vtkCubeSource.New();
            vtkPolyDataMapper cubeMapper = vtkPolyDataMapper.New();

            cubeMapper.SetInputConnection(cubeSource.GetOutputPort());
            vtkActor cubeActor = vtkActor.New();

            cubeActor.SetMapper(cubeMapper);
            cubeActor.SetPosition(0, 2.25, 0);
            cubeActor.GetProperty().SetColor(0, 0, 1);

            vtkConeSource     coneSource = vtkConeSource.New();
            vtkPolyDataMapper coneMapper = vtkPolyDataMapper.New();

            coneMapper.SetInputConnection(coneSource.GetOutputPort());
            vtkActor coneActor = vtkActor.New();

            coneActor.SetMapper(coneMapper);
            coneActor.SetPosition(0, 0, 2.25);
            coneActor.GetProperty().SetColor(0, 1, 0);

            vtkCylinderSource cylinderSource = vtkCylinderSource.New();
            vtkPolyDataMapper cylinderMapper = vtkPolyDataMapper.New();

            cylinderMapper.SetInputConnection(cylinderSource.GetOutputPort());
            vtkActor cylinderActor = vtkActor.New();

            cylinderActor.SetMapper(cylinderMapper);
            //cylinderActor.SetPosition(0, 0, 0);
            cylinderActor.GetProperty().SetColor(1, 0, 0);

            vtkAssembly assembly = vtkAssembly.New();

            assembly.AddPart(cylinderActor);
            assembly.AddPart(sphereActor);
            assembly.AddPart(cubeActor);
            assembly.AddPart(coneActor);
            assembly.SetOrigin(5, 10, 5);
            assembly.AddPosition(5, 0, 0);
            assembly.RotateX(15);

            vtkRenderer     renderer = vtkRenderer.New();
            vtkRenderWindow renWin   = myRenderWindowControl.RenderWindow;

            renWin.AddRenderer(renderer);
            renderer.AddActor(assembly);
            renderer.AddActor(coneActor);
        }