Esempio n. 1
0
 void m_iren_RightButtonPressEvt(vtkObject sender, vtkObjectEventArgs e)
 { //左键按下记录矩形的起始点
     if (m_pickTarget == ePickTarget.None)
     {
         return;
     }
     if (m_pickMode != ePickMode.RectPickMode) //如果不是框选则不用记录矩形起始点坐标
     {
         return;
     }
     m_iren.GetEventPosition(ref startx, ref starty);  //获取起始点
     endx = startx; endy = starty;
     //Console.WriteLine("startx:{0},starty:{1}", startx, starty);
 }
Esempio n. 2
0
        /// <summary>
        /// Highlights pieces
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void MotionCallback(vtkObject sender, vtkObjectEventArgs e)
        {
            //Make sure the piece isn't in an animation
            //durring a click or bad things happen
            if (!in_piece_rotation)
            {
                vtkRenderWindowInteractor iren   = renderWindowControl1.RenderWindow.GetInteractor();
                vtkInteractorStyleSwitch  istyle = (vtkInteractorStyleSwitch)iren.GetInteractorStyle();

                //return if the user is performing interaction
                if (istyle.GetState() != 0)
                {
                    return;
                }

                int[] pos = iren.GetEventPosition();
                int   x   = pos[0];
                int   y   = pos[1];

                vtkRenderer ren1 = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer();
                ren1.SetDisplayPoint(x, y, ren1.GetZ(x, y));
                ren1.DisplayToWorld();
                double [] pt  = ren1.GetWorldPoint();
                double    val = puzzle.SetPoint(pt[0], pt[1], pt[2]);
                if (!LastValExists || val != LastVal)
                {
                    renderWindowControl1.RenderWindow.Render();
                    LastVal       = val;
                    LastValExists = true;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Called when a key is pressed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CharCallback(vtkObject sender, vtkObjectEventArgs e)
        {
            vtkRenderWindowInteractor iren = renderWindowControl1.RenderWindow.GetInteractor();
            sbyte keycode = iren.GetKeyCode();

            //if the keycode is not M
            if (keycode != 109 && keycode != 77)
            {
                return;
            }
            int[] pos = iren.GetEventPosition();
            ButtonCallback(pos[0], pos[1]);
        }
Esempio n. 4
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();
                //}
            }
        }