Esempio n. 1
0
        // Function will delete the point nearby on right mouse press
        public void RightButtonPress(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)
        {
            // Get x,y mouse position
            int[] pos = iren.GetEventPosition();
            int   x = pos[0]; int y = pos[1];

            // Find the nearest point
            double dist = 0; pointsel = -1;

            for (int i = 1; i < npoints - 1; i++)
            {
                dist = Math.Sqrt(Math.Pow((double)(pointsx[i] - x), 2) + Math.Pow((double)(pointsy[i] - y), 2));
                if (dist < rad)
                {
                    pointsel = i;
                }
            }

            // When point is found, delete it.
            if (pointsel > 0)
            {
                npoints--;
                for (int i = pointsel; i < npoints; i++)
                {
                    pointsx[i] = pointsx[i + 1];
                    pointsy[i] = pointsy[i + 1];
                    pointsc[i] = pointsc[i + 1];
                }

                // Draw and Render the histogram and transferfunction
                drawhisto(); drawcurve();
                renHist.Render();
            }
            pointsel = -1;
        }
Esempio n. 2
0
        public void MiddleButtonPress(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)
        {
            // Get x,y mouse position
            int[] pos = iren.GetEventPosition();
            int   x = pos[0]; int y = pos[1];

            // Find the nearest point
            double dist = 0; pointsel = -1;

            for (int i = 0; i < npoints; i++)
            {
                dist = Math.Sqrt(Math.Pow((double)(pointsx[i] - x), 2) + Math.Pow((double)(pointsy[i] - y), 2));
                if (dist < rad)
                {
                    pointsel = i;
                }
            }

            // When point is found
            if (pointsel > -1)
            {
                pointsc[pointsel]++; if (pointsc[pointsel] > 13)
                {
                    pointsc[pointsel] = 1;
                }
                drawhisto(); drawcurve();
                renHist.Render();
            }
            pointsel = -1;
        }
Esempio n. 3
0
        // Function moves a selected point during mouse movement
        public void MouseMove(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)
        {
            if (pointsel > -1) // Point selected
            {
                // Get x,y mouse position
                int[] pos = iren.GetEventPosition();
                int   x = pos[0]; int y = pos[1];

                // Limit mouse position to histogram window
                if (x < 0)
                {
                    x = 0;
                }
                else if (x > width - 1)
                {
                    x = width - 1;
                }
                if (y < 0)
                {
                    y = 0;
                }
                else if (y > height - 1)
                {
                    y = height - 1;
                }

                // Set the x variable of the selected point to the mouse x
                // (only if it's not the first or last point)
                if ((pointsel > 0) && (pointsel < npoints - 1))
                {
                    if (x <= pointsx[pointsel - 1])
                    {
                        x = pointsx[pointsel - 1] + 1;
                    }
                    if (x >= pointsx[pointsel + 1])
                    {
                        x = pointsx[pointsel + 1] - 1;
                    }
                    pointsx[pointsel] = x;
                }

                // Set the y variable of the selected point
                pointsy[pointsel] = y;

                // Draw and Render the histogram and transferfunction
                drawhisto(); drawcurve();
                renHist.Render();
            }
        }
Esempio n. 4
0
        static void PrintCameraPosition(vtk.vtkObject caller, uint eventId,
                                        object clientData, IntPtr callData)
        {
            System.Diagnostics.Debug.WriteLine("Callback has been called.");
            vtk.vtkRenderer ren = vtk.vtkRenderer.SafeDownCast(caller);
            if (ren != null)
            {
                double[] position = ren.GetActiveCamera().GetPosition();
                Console.WriteLine(String.Format("{0}, {1}, {2}",

                                                position[0], position[1], position[2]));
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Caller is not a renderer.");
            }
        }
Esempio n. 5
0
 static void myCallback(vtk.vtkObject caller, uint eventId,
                        object clientData, IntPtr callData)
 {
     System.Diagnostics.Debug.WriteLine("Callback has been called.");
     vtk.vtkBoxWidget boxWidget = vtk.vtkBoxWidget.SafeDownCast(caller);
     if (null != boxWidget)
     {
         using (vtk.vtkTransform t = new vtk.vtkTransform())
         {
             boxWidget.GetTransform(t);
             boxWidget.GetProp3D().SetUserTransform(t);
         }
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Caller is not a box widget.");
     }
 }
Esempio n. 6
0
 public void MouseRelease(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)
 {
     m_parent.ShowBusy(false);
 }
Esempio n. 7
0
 public void MousePress(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)
 {
     m_parent.ShowBusy(true);
 }
Esempio n. 8
0
 // Deselect point add mouse release
 public void LeftButtonRelease(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)
 {
     pointsel = -1;
 }
Esempio n. 9
0
        // This function will find or create a selectedpoint
        // on the position of the left button click
        public void LeftButtonPress(vtk.vtkObject obj, uint eventId, Object data, IntPtr clientdata)
        {
            // Get x,y mouse position
            int[] pos = iren.GetEventPosition();
            int   x = pos[0]; int y = pos[1];

            // Calculate the distance from mouse position to the points
            // a point near the mousecursor will be selected
            double dist = 0; pointsel = -1;

            for (int i = 0; i < npoints; i++)
            {
                dist = Math.Sqrt(Math.Pow((double)(pointsx[i] - x), 2) + Math.Pow((double)(pointsy[i] - y), 2));
                if (dist < rad)
                {
                    pointsel = i;
                }
            }

            // If no point beneath the mouse cursor then this code will
            // create a point. (if the mouse is close to the curve)
            if (pointsel == -1)
            {
                double mindistv = 999; int mindistx = 0; int mindisty = 0;
                int[]  linevector = makevector(); // Get an array with all curve pixels

                // Find pixel of the curve near the mouse position.
                for (int i = 0; i < width; i++)
                {
                    dist = Math.Sqrt(Math.Pow((double)(i - x), 2) + Math.Pow((double)(linevector[i] - y), 2));
                    if (dist < mindistv)
                    {
                        mindistv = dist;
                        mindistx = i;
                        mindisty = linevector[i];
                    }
                }

                // Add a new point (if mouse is position is near the curve)
                if (mindistv < rad)
                {
                    int dp = npoints - 1;
                    // Make room for the new point in the array
                    while (mindistx < pointsx[dp])
                    {
                        pointsx[dp + 1] = pointsx[dp];
                        pointsy[dp + 1] = pointsy[dp];
                        pointsc[dp + 1] = pointsc[dp];
                        dp--;
                    }
                    pointsx[dp + 1] = mindistx;
                    pointsy[dp + 1] = mindisty;
                    pointsc[dp + 1] = 1;
                    pointsel        = dp + 1;
                    npoints++;

                    // Draw and Render the histogram and transferfunction
                    drawhisto(); drawcurve();
                    renHist.Render();
                }
            }
        }