public void Generate(Rectd window, int maxIterations)
        {
            if (window.Width < 0.000004 || window.Width > 20 ||
                window.Height < 0.000004 || window.Height > 20)
            {
                return;
            }

            if (maxIterations < 0)
            {
                maxIterations = 0;
            }

            abortThreads();

            this.window        = window;
            this.maxIterations = maxIterations;

            foreach (Tile t in tiles)
            {
                t.MaxIterations  = maxIterations;
                t.TextureIsReady = false;
                t.WindowRect     = new Rectd(
                    GetWindowCoord(t.ScreenPos.X, t.ScreenPos.Y),
                    GetWindowCoord(t.ScreenPos.X + TileSize, t.ScreenPos.Y + TileSize));
            }

            threads[0] = new Thread(new ThreadStart(threadTileManager_main));
            threads[0].Start();
        }
		public void Generate(Rectd window, int maxIterations)
		{
			if (window.Width < 0.000004 || window.Width > 20 ||
				window.Height < 0.000004 || window.Height > 20)
				return;

			if (maxIterations < 0)
				maxIterations = 0;

			abortThreads();

			this.window = window;
			this.maxIterations = maxIterations;

			foreach (Tile t in tiles)
			{
				t.MaxIterations = maxIterations;
				t.TextureIsReady = false;
				t.WindowRect = new Rectd(
					GetWindowCoord(t.ScreenPos.X, t.ScreenPos.Y),
					GetWindowCoord(t.ScreenPos.X + TileSize, t.ScreenPos.Y + TileSize));
			}

			threads[0] = new Thread(new ThreadStart(threadTileManager_main));
			threads[0].Start();
		}
        public void FillPixels(byte[] byteArray, Rectd destRect)
        {
            var screenRect = new Recti(transxi(destRect.X), transyi(destRect.Y),
                                       (int)(Width * (destRect.Width)), (int)(Height * (destRect.Height)));

            int stride = 4 * ((screenRect.Width * (_bitmap.Format.BitsPerPixel / 8) + 3) / 4);

            _bitmap.WritePixels(new System.Windows.Int32Rect(0, 0, screenRect.Width, screenRect.Height), byteArray, stride, screenRect.X, screenRect.Y);
        }
Beispiel #4
0
 public void EndRender(Rectd screenRect, IRenderContext context)
 {
     if (context == null)
     {
         return;
     }
     if (buffer.Length > 0)
     {
         context.FillPixels(buffer, screenRect);
     }
 }
Beispiel #5
0
 //here for debugging... remove and move to local function when done
 public void BeginRender(Rectd screenRect, IRenderContext context)
 {
     if (context == null)
     {
         return;
     }
     totalRows       = (int)(screenRect.Height * context.Height);
     totalCols       = (int)(screenRect.Width * context.Width);
     TotalScreenRect = screenRect;
     buffer          = new byte[totalRows * totalCols * bytespp];
 }
Beispiel #6
0
        private void RenderImages(IRenderContext context)
        {
            var primaryImgRect   = new Rectd(0, 0, 1, 1);
            var secondaryImgRect = new Rectd(0, 0, 1, 1);

            if (ImageRenderContext != null)
            {
                ImageRenderer?.BeginRender(primaryImgRect, context);
                ImageRenderer?.Render(FromImage(PrimaryImage, BlendMode.None, new Rectd(0, 0, 1, 1)), Camera, context);
                ImageRenderer?.Render(FromImage(SecondaryImage, BlendMode.OverWhereNonZero, SpyGlass), Camera, context);
                foreach (var img in AdditionalImages)
                {
                    ImageRenderer?.Render(img, Camera, context);
                }

                ImageRenderer?.EndRender(primaryImgRect, context);
                //ImageRenderContext?.DrawString("" + ImageRenderer.iy, 0, 0, 12, DicomColors.Yellow);
            }
        }
Beispiel #7
0
 public DicomPanelModel()
 {
     Camera           = new Camera();
     ImageRenderer    = new ImageRenderer();
     DoseRenderer     = new DoseRenderer();
     ROIRenderer      = new ROIRenderer();
     VectorRenderer   = new VoxelFieldRenderer();
     ROIs             = new List <RegionOfInterest>();
     POIs             = new List <PointOfInterest>();
     ContouredDoses   = new List <IDoseObject>();
     BeamRenderer     = new BeamRenderer();
     Beams            = new List <Beam>();
     OrthogonalModels = new List <DicomPanelModel>();
     Overlays         = new List <IOverlay>();
     ToolBox          = new ToolBox();
     Overlays.Add(new ScaleOverlay());
     SpyGlass         = new Rectd(0, 0, 1, 1);
     AdditionalImages = new List <RenderableImage>();
     VectorFields     = new List <VectorField>();
 }
Beispiel #8
0
        /// <summary>
        /// Returns a rectangle on the screen which bounds the 3D object defined by the three ranges
        /// </summary>
        /// <param name="xrange">The xrange of the object</param>
        /// <param name="yrange">The yrange of the object</param>
        /// <param name="zrange">The zrange of the object</param>
        /// <returns></returns>
        public Rectd GetBoundingScreenRect(Range xrange, Range yrange, Range zrange, Rectd normDeviceRect)
        {
            Point2d minPoint = new Point2d(double.MaxValue, double.MaxValue);
            Point2d maxPoint = new Point2d(double.MinValue, double.MinValue);

            // Project each vertex of the 3d cube onto the screen
            // and find the minimum rect surrounding those points.
            Point2d[] projectedVertices = new Point2d[8];
            projectedVertices[0] = ConvertWorldToScreenCoords(xrange.Minimum, yrange.Minimum, zrange.Minimum);
            projectedVertices[1] = ConvertWorldToScreenCoords(xrange.Minimum, yrange.Minimum, zrange.Maximum);
            projectedVertices[2] = ConvertWorldToScreenCoords(xrange.Maximum, yrange.Minimum, zrange.Maximum);
            projectedVertices[3] = ConvertWorldToScreenCoords(xrange.Maximum, yrange.Minimum, zrange.Minimum);
            projectedVertices[4] = ConvertWorldToScreenCoords(xrange.Minimum, yrange.Maximum, zrange.Minimum);
            projectedVertices[5] = ConvertWorldToScreenCoords(xrange.Minimum, yrange.Maximum, zrange.Maximum);
            projectedVertices[6] = ConvertWorldToScreenCoords(xrange.Maximum, yrange.Maximum, zrange.Maximum);
            projectedVertices[7] = ConvertWorldToScreenCoords(xrange.Maximum, yrange.Maximum, zrange.Minimum);

            foreach (var projectedVertex in projectedVertices)
            {
                if (projectedVertex.X < minPoint.X)
                {
                    minPoint.X = projectedVertex.X;
                }
                if (projectedVertex.X > maxPoint.X)
                {
                    maxPoint.X = projectedVertex.X;
                }
                if (projectedVertex.Y < minPoint.Y)
                {
                    minPoint.Y = projectedVertex.Y;
                }
                if (projectedVertex.Y > maxPoint.Y)
                {
                    maxPoint.Y = projectedVertex.Y;
                }
            }
            Rectd boundingRect = new Rectd(minPoint, maxPoint);

            boundingRect = boundingRect.Intersect(normDeviceRect);
            return(boundingRect);
        }
Beispiel #9
0
        private RenderableImage FromImage(DicomImageObject image, BlendMode blendMode, Rectd screenRect)
        {
            if (image == null)
            {
                return(new RenderableImage());
            }
            Random r = new Random();

            return(new RenderableImage()
            {
                Grid = image.Grid,
                Alpha = 0.5f,
                BlendMode = blendMode,
                Name = image.Grid.Name,
                LUT = image.LUT,
                Scaling = 1,
                Units = "HU",
                ScreenRect = screenRect
            });
        }
Beispiel #10
0
        public void Render(RenderableImage image, Camera camera, IRenderContext context)
        {
            if (image.Grid == null)
            {
                return;
            }

            // Get the direction we move in each iteration from the top left of the camera
            Rectd screenRect = camera.GetBoundingScreenRect(image.Grid.XRange, image.Grid.YRange, image.Grid.ZRange, image.ScreenRect);

            //Rectd screenRect = new Rectd(0,0,1,1);

            if (screenRect == null)
            {
                return;
            }

            //align the screenRect position to a pixel to avoid shifting artefacts.
            screenRect.X -= (screenRect.X) % (1.0f / context.Width);
            screenRect.Y -= (screenRect.Y) % (1.0f / context.Height);

            Point3d initPosn = camera.ConvertScreenToWorldCoords(screenRect.Y, screenRect.X);
            Point3d posn     = camera.ConvertScreenToWorldCoords(screenRect.Y, screenRect.X);

            int rows        = (int)Math.Round(screenRect.Height * context.Height);
            int cols        = (int)Math.Round(screenRect.Width * context.Width);
            int startingRow = (int)Math.Round((screenRect.Y / TotalScreenRect.Height) * totalRows);
            int startingCol = (int)Math.Round((screenRect.X / TotalScreenRect.Width) * totalCols);

            double ix, iy, iz, px, py, pz, cx, cy, cz, rx, ry, rz;

            ix = initPosn.X;
            iy = initPosn.Y;
            iz = initPosn.Z;
            px = initPosn.X;
            py = initPosn.Y;
            pz = initPosn.Z;
            cx = screenRect.Width * camera.ColDir.X * camera.GetFOV().X / (cols * camera.Scale * camera.MMPerPixel);
            cy = screenRect.Width * camera.ColDir.Y * camera.GetFOV().X / (cols * camera.Scale * camera.MMPerPixel);
            cz = screenRect.Width * camera.ColDir.Z * camera.GetFOV().X / (cols * camera.Scale * camera.MMPerPixel);
            rx = screenRect.Height * camera.RowDir.X * camera.GetFOV().Y / (rows * camera.Scale * camera.MMPerPixel);
            ry = screenRect.Height * camera.RowDir.Y * camera.GetFOV().Y / (rows * camera.Scale * camera.MMPerPixel);
            rz = screenRect.Height * camera.RowDir.Z * camera.GetFOV().Y / (rows * camera.Scale * camera.MMPerPixel);

            int   k;
            int   dr = 0;
            float value;
            byte  blue, green, red;
            byte  actualBlue = 0, actualGreen = 0, actualRed = 0;
            byte  actualAlpha = (byte)(255 * alpha);

            byte[] bgr = new byte[3];
            Voxel  interpolatedVoxel = new Voxel();
            double val1, val2, val3;
            var    norm = image.Grid.GetNormalisationAmount();

            for (int r = startingRow; r < rows + startingRow; r += 1)
            {
                dr++;
                k  = r * totalCols * bytespp + startingCol * bytespp;
                px = ix + rx * dr; py = iy + ry * dr; pz = iz + rz * dr;
                for (int c = startingCol; c < cols + startingCol; c += 1)
                {
                    image.Grid.Interpolate(px, py, pz, interpolatedVoxel);
                    value = interpolatedVoxel.Value * image.Grid.Scaling;
                    image.LUT.Compute(value, bgr);

                    blue  = (byte)(bgr[0]);
                    green = (byte)(bgr[1]);
                    red   = (byte)(bgr[2]);

                    switch (image.BlendMode)
                    {
                    case Blending.BlendMode.None:
                        actualRed   = red;
                        actualGreen = green;
                        actualBlue  = blue; break;

                    case Blending.BlendMode.Over:
                        val1 = buffer[k] * alpha + blue * image.Alpha;
                        val2 = buffer[k + 1] * (1 - image.Alpha) + green * image.Alpha;
                        val3 = buffer[k + 2] * (1 - image.Alpha) + red * image.Alpha;
                        if (val1 > 255)
                        {
                            val1 = 255;
                        }
                        if (val2 > 255)
                        {
                            val2 = 255;
                        }
                        if (val3 > 255)
                        {
                            val3 = 255;
                        }
                        actualBlue  = (byte)val1;
                        actualGreen = (byte)val2;
                        actualRed   = (byte)val3;
                        break;

                    case Blending.BlendMode.OverWhereNonZero:
                        if (blue == 0)
                        {
                            actualBlue = buffer[k];
                        }
                        else
                        {
                            val1 = buffer[k] * alpha + blue * image.Alpha;
                            if (val1 > 255)
                            {
                                val1 = 255;
                            }
                            actualBlue = (byte)val1;
                        }
                        if (green == 0)
                        {
                            actualGreen = buffer[k + 1];
                        }
                        else
                        {
                            val2 = buffer[k + 1] * alpha + green * image.Alpha;
                            if (val2 > 255)
                            {
                                val2 = 255;
                            }
                            actualGreen = (byte)val2;
                        }

                        if (red == 0)
                        {
                            actualRed = buffer[k + 2];
                        }
                        else
                        {
                            val3 = buffer[k + 2] * alpha + red * image.Alpha;
                            if (val3 > 255)
                            {
                                val3 = 255;
                            }
                            actualRed = (byte)val3;
                        }
                        break;
                    }

                    buffer[k]     = actualBlue;
                    buffer[k + 1] = actualGreen;
                    buffer[k + 2] = actualRed;
                    buffer[k + 3] = actualAlpha;

                    k  += bytespp;
                    px += cx; py += cy; pz += cz;
                }
            }
        }
Beispiel #11
0
 public void FillPixels(byte[] byteArray, Rectd destRect)
 {
 }
		public void Generate(Rectd window)
		{
			Generate(window, maxIterations);
		}
Beispiel #13
0
        public void Render(VectorField vectorField, Camera camera, IRenderContext context, Rectd screenRect)
        {
            var boundingRect = camera.GetBoundingScreenRect(vectorField.X.XRange, vectorField.X.YRange, vectorField.X.ZRange, screenRect);

            if (boundingRect != null)
            {
                var initPosn = camera.ConvertScreenToWorldCoords(boundingRect.Y, boundingRect.X);

                double rows            = 80;
                double cols            = 80;
                double gridSpacingRows = rows / camera.GetFOV().Y;
                double gridSpacingCols = cols / camera.GetFOV().X;
                double gridSpacing     = Math.Min(gridSpacingRows, gridSpacingCols);

                var vertices = new List <double>();

                var cnorm = camera.ColDir.Length();
                var rnorm = camera.RowDir.Length();
                var cx    = (cnorm * camera.ColDir.X) * gridSpacingCols;
                var cy    = (cnorm * camera.ColDir.Y) * gridSpacingCols;
                var cz    = (cnorm * camera.ColDir.Z) * gridSpacingCols;
                var rx    = (rnorm * camera.RowDir.X) * gridSpacingRows;
                var ry    = (rnorm * camera.RowDir.Y) * gridSpacingRows;
                var rz    = (rnorm * camera.RowDir.Z) * gridSpacingRows;

                for (int i = 0; i < cols; i++)
                {
                    for (int j = 0; j < rows; j++)
                    {
                        worldCoord.X = initPosn.X + cx * i + rx * j + cx + rx;
                        worldCoord.Y = initPosn.Y + cy * i + ry * j + cy + ry;
                        worldCoord.Z = initPosn.Z + cz * i + rz * j + cz + rz;

                        var x = vectorField.X.Interpolate(worldCoord).Value;
                        var y = vectorField.Y.Interpolate(worldCoord).Value;
                        var z = vectorField.Z.Interpolate(worldCoord).Value;

                        float len = (float)Math.Sqrt(x * x + y * y + z * z);

                        if (len <= 0.01)
                        {
                            continue;
                        }

                        // The additional cx, rx, cy, ry etc. are because the marching squares
                        // offsets the grid during calculation... trust me future self.

                        vertices.Add(worldCoord.X);
                        vertices.Add(worldCoord.Y);
                        vertices.Add(worldCoord.Z);

                        x /= len;
                        y /= len;
                        z /= len;

                        vertices.Add(x * gridSpacing + worldCoord.X);
                        vertices.Add(y * gridSpacing + worldCoord.Y);
                        vertices.Add(z * gridSpacing + worldCoord.Z);
                    }
                }

                double[] screenVertices = getScreenVertices(vertices, camera);

                for (int i = 0; i < screenVertices.Length; i += 4)
                {
                    double x0 = screenVertices[i];
                    double y0 = screenVertices[i + 1];
                    double x1 = screenVertices[i + 2];
                    double y1 = screenVertices[i + 3];
                    context.DrawArrow(x0, y0, x1, y1, DicomColors.Red);
                }
                //context.DrawLines(screenVertices, DicomColors.Red);
            }
        }
Beispiel #14
0
        public void Render(IEnumerable <PointOfInterest> pois, Camera camera, IRenderContext context, Rectd screenRect)
        {
            POIOverlay poiOverlay = new POIOverlay();

            poiOverlay.RenderCircle         = true;
            poiOverlay.SizeInMM             = 6;
            poiOverlay.KeepSameSizeOnScreen = false;
            foreach (PointOfInterest poi in pois)
            {
                poiOverlay.Position = poi.Position;
                poiOverlay.Render(camera, context);
            }
        }
Beispiel #15
0
        public void Render(IEnumerable <RegionOfInterest> rois, Camera camera, IRenderContext context, Rectd screenRect)
        {
            foreach (RegionOfInterest roi in rois)
            {
                var boundingRect = camera.GetBoundingScreenRect(roi.XRange, roi.YRange, roi.ZRange, screenRect);

                if (boundingRect != null)
                {
                    var    initPosn    = camera.ConvertScreenToWorldCoords(boundingRect.Y, boundingRect.X);
                    double gridSpacing = 2;
                    var    rows        = (int)Math.Round((boundingRect.Height * (camera.GetFOV().Y) / gridSpacing)) + 1;
                    var    cols        = (int)Math.Round((boundingRect.Width * (camera.GetFOV().X) / gridSpacing)) + 1;
                    var    grid        = new bool[rows * cols];
                    var    cnorm       = camera.ColDir.Length();
                    var    rnorm       = camera.RowDir.Length();
                    var    cx          = (cnorm * camera.ColDir.X) * gridSpacing / camera.Scale;
                    var    cy          = (cnorm * camera.ColDir.Y) * gridSpacing / camera.Scale;
                    var    cz          = (cnorm * camera.ColDir.Z) * gridSpacing / camera.Scale;
                    var    rx          = (rnorm * camera.RowDir.X) * gridSpacing / camera.Scale;
                    var    ry          = (rnorm * camera.RowDir.Y) * gridSpacing / camera.Scale;
                    var    rz          = (rnorm * camera.RowDir.Z) * gridSpacing / camera.Scale;

                    for (int i = 0; i < cols; i++)
                    {
                        for (int j = 0; j < rows; j++)
                        {
                            // The additional cx, rx, cy, ry etc. are because the marching squares
                            // offsets the grid during calculation... trust me future self.
                            worldCoord.X       = initPosn.X + cx * i + rx * j + cx + rx;
                            worldCoord.Y       = initPosn.Y + cy * i + ry * j + cy + ry;
                            worldCoord.Z       = initPosn.Z + cz * i + rz * j + cz + rz;
                            grid[j * cols + i] = roi.ContainsPointNonInterpolated(worldCoord.X, worldCoord.Y, worldCoord.Z);
                        }
                    }

                    double[] vertices       = ms.GetVertices(grid, rows, cols, initPosn.X, initPosn.Y, initPosn.Z, rx, ry, rz, cx, cy, cz);
                    double[] screenVertices = getScreenVertices(vertices, camera);
                    context.DrawLines(screenVertices, roi.Color);
                }
            }
        }
Beispiel #16
0
 public void FillPixels(byte[] byteArray, Rectd destRect)
 {
     //Currently don't know how to do this...
 }
Beispiel #17
0
        public void Render(IDoseObject doseObject, Camera camera, IRenderContext context, Rectd screenRect, LineType lineType)
        {
            if (doseObject == null || doseObject.Grid == null)
            {
                return;
            }

            if (doseObject.Grid.GetNormalisationAmount() == 0)
            {
                return;
            }

            //Translates screen to world points and vice versa
            var ms = new MarchingSquares();
            List <PlanarPolygon> polygons = new List <PlanarPolygon>();
            var interpolatedDoseGrid      = new InterpolatedDoseGrid(doseObject, MaxNumberOfGridPoints, camera, screenRect);

            foreach (ContourInfo contourInfo in ContourInfo)
            {
                var contour = ms.GetContour(interpolatedDoseGrid.Data, interpolatedDoseGrid.Rows, interpolatedDoseGrid.Columns, interpolatedDoseGrid.Coords, contourInfo.Threshold, contourInfo.Color);
                //var polygon = contour.ToPlanarPolygon(camera);

                Point2d screenPoint1 = new Point2d();
                Point2d screenPoint2 = new Point2d();
                Point3d worldPoint1  = new Point3d();
                Point3d worldPoint2  = new Point3d();

                var screenVertices = getScreenVertices(contour.Vertices, camera);

                context.DrawLines(screenVertices, contourInfo.Color);
            }
        }
Beispiel #18
0
        public void Render(Beam beam, Camera camera, IRenderContext context, Rectd screenRect, LineType lineType)
        {
            var iso = beam.Isocentre.Position;
            RTCoordinateTransform transform = new RTCoordinateTransform();

            transform.CollimatorAngle = beam.CollimatorAngle;
            transform.GantryAngle     = beam.GantryStart;
            transform.CouchAngle      = beam.CouchAngle;
            //calculate the initial position from the gantry, couch and sad
            var sourcePosn = new Point3d(iso.X, iso.Y - beam.SAD, iso.Z);

            transform.Transform(sourcePosn, iso, sourcePosn);

            var scrnSource = camera.ConvertWorldToScreenCoords(sourcePosn);

            double x1 = beam.XJaw.NegativeJawPosition;
            double x2 = beam.XJaw.PositiveJawPosition;
            double y1 = beam.YJaw.NegativeJawPosition;
            double y2 = beam.YJaw.PositiveJawPosition;

            //Draw to middle of each jaw
            Point3d X1 = new Point3d(iso.X + x1, iso.Y, iso.Z);

            transform.Transform(X1, iso, X1);

            var sX1 = camera.ConvertWorldToScreenCoords(X1);

            context.DrawLine(scrnSource.X, scrnSource.Y, sX1.X, sX1.Y, DicomColors.Yellow);

            //The v coordinates below represent the corners of the jaws projected at isocentre with gantry=couch=coll=0
            //v11 means the corner of the jaws x1 and y1
            //u is the transformed coordinates
            Point3d v11 = new Point3d(iso.X + x1, iso.Y, iso.Z + y1);
            Point3d v12 = new Point3d(iso.X + x1, iso.Y, iso.Z + y2);
            Point3d v21 = new Point3d(iso.X + x2, iso.Y, iso.Z + y1);
            Point3d v22 = new Point3d(iso.X + x2, iso.Y, iso.Z + y2);
            Point3d u11 = new Point3d(), u12 = new Point3d(), u21 = new Point3d(), u22 = new Point3d();

            transform.Transform(v11, iso, u11);
            transform.Transform(v12, iso, u12);
            transform.Transform(v21, iso, u21);
            transform.Transform(v22, iso, u22);
            //We now have four jaw coordinates in the coordinate system.
            //Now interesect the line between the source and each coordinates and draw lines between those
            Point3d w11, w12, w21, w22;

            w11 = camera.Intersect(sourcePosn, u11);
            w12 = camera.Intersect(sourcePosn, u12);
            w21 = camera.Intersect(sourcePosn, u21);
            w22 = camera.Intersect(sourcePosn, u22);

            var s11 = camera.ConvertWorldToScreenCoords(w11);
            var s12 = camera.ConvertWorldToScreenCoords(w12);
            var s21 = camera.ConvertWorldToScreenCoords(w21);
            var s22 = camera.ConvertWorldToScreenCoords(w22);

            context.DrawLine(s11.X, s11.Y, s21.X, s21.Y, DicomColors.Yellow);
            context.DrawLine(s22.X, s22.Y, s21.X, s21.Y, DicomColors.Yellow);
            context.DrawLine(s22.X, s22.Y, s12.X, s12.Y, DicomColors.Yellow);
            context.DrawLine(s11.X, s11.Y, s12.X, s12.Y, DicomColors.Yellow);

            //Draw the line between source and isocentre
            var line = (sourcePosn - iso);

            if (camera.Normal.Dot(line) == 0)
            {
                var scrnIso = camera.ConvertWorldToScreenCoords(iso);
                context.DrawLine(scrnIso.X, scrnIso.Y, scrnSource.X, scrnSource.Y, DicomColors.Yellow);
            }
            else
            {
                //var scrnIso = camera.ConvertWorldToScreenCoords(camera.Intersect(iso, sourcePosn));
                //context.DrawLine(scrnIso.X, scrnIso.Y, scrnSource.X, scrnSource.Y, DicomColors.Yellow);
                //context.DrawEllipse(scrnIso.X, scrnIso.Y, .02, .02, DicomColors.Yellow);
            }
        }
Beispiel #19
0
		static bool device_OnEvent(Event evnt)
		{
			if (evnt.Type == EventType.Mouse)
			{
				Dimension2Di s = device.VideoDriver.ScreenSize;

				if (evnt.Mouse.Type == MouseEventType.Wheel)
				{
					Rectd r = new Rectd();

					if (evnt.Mouse.Wheel > 0)
					{
						// zoom in

						int x1 = evnt.Mouse.X - s.Width / 2 + (int)evnt.Mouse.Wheel * s.Width / 10;
						int y1 = evnt.Mouse.Y - s.Height / 2 + (int)evnt.Mouse.Wheel * s.Height / 10;

						r.UpperLeftCorner = fGen.GetWindowCoord(x1, y1);
						r.LowerRightCorner = fGen.GetWindowCoord(2 * evnt.Mouse.X - x1, 2 * evnt.Mouse.Y - y1);

						device.CursorControl.Position = new Vector2Di(s.Width / 2, s.Height / 2);
					}
					else
					{
						// zoom out

						int x1 = s.Width / 10;
						int y1 = s.Height / 10;

						r.UpperLeftCorner = fGen.GetWindowCoord(-x1, -y1);
						r.LowerRightCorner = fGen.GetWindowCoord(s.Width + x1, s.Height + y1);
					}

					fGen.Generate(r);
					return true;
				}

				if (evnt.Mouse.Type == MouseEventType.LeftDown)
				{
					mouseMoveStart = new Vector2Di(evnt.Mouse.X, evnt.Mouse.Y);
					return true;
				}

				if (evnt.Mouse.Type == MouseEventType.LeftUp)
				{
					Vector2Dd p1 = fGen.GetWindowCoord(evnt.Mouse.X, evnt.Mouse.Y);
					Vector2Dd p2 = fGen.GetWindowCoord(mouseMoveStart.X, mouseMoveStart.Y);
					Rectd r = fGen.GetWindow() + p2 - p1;

					fGen.Generate(r);

					mouseMoveStart = null;
					return true;
				}
			}

			if (evnt.Type == EventType.Key)
			{
				if (evnt.Key.PressedDown)
				{
					if (evnt.Key.Key == KeyCode.Esc)
					{
						device.Close();
						return true;
					}

					if (evnt.Key.Key == KeyCode.F1)
					{
						showHelp = !showHelp;
						return true;
					}

					switch (evnt.Key.Char)
					{
						case '+':
							fGen.Generate(fGen.GetMaxIterations() + 1);
							return true;

						case '-':
							fGen.Generate(fGen.GetMaxIterations() - 1);
							return true;

						case '*':
							fGen.Generate(fGen.GetMaxIterations() + 10);
							return true;

						case '/':
							fGen.Generate(fGen.GetMaxIterations() - 10);
							return true;
					}
				}

				if (evnt.Key.Key == KeyCode.PrintScreen) // PrintScreen never comes with "evnt.Key.PressedDown == true" so we process it without checking that
				{
					string n = "Screenshot-" + DateTime.Now.Ticks + ".png";
					Image i = device.VideoDriver.CreateScreenShot();
					device.VideoDriver.WriteImage(i, n);
					i.Drop();

					device.Logger.Log("Screenshot saved as " + n);
					return true;
				}
			}

			return false;
		}
 public void Generate(Rectd window)
 {
     Generate(window, maxIterations);
 }
Beispiel #21
0
        static bool device_OnEvent(Event evnt)
        {
            if (evnt.Type == EventType.Mouse)
            {
                Dimension2Di s = device.VideoDriver.ScreenSize;

                if (evnt.Mouse.Type == MouseEventType.Wheel)
                {
                    Rectd r = new Rectd();

                    if (evnt.Mouse.Wheel > 0)
                    {
                        // zoom in

                        int x1 = evnt.Mouse.X - s.Width / 2 + (int)evnt.Mouse.Wheel * s.Width / 10;
                        int y1 = evnt.Mouse.Y - s.Height / 2 + (int)evnt.Mouse.Wheel * s.Height / 10;

                        r.UpperLeftCorner  = fGen.GetWindowCoord(x1, y1);
                        r.LowerRightCorner = fGen.GetWindowCoord(2 * evnt.Mouse.X - x1, 2 * evnt.Mouse.Y - y1);

                        device.CursorControl.Position = new Vector2Di(s.Width / 2, s.Height / 2);
                    }
                    else
                    {
                        // zoom out

                        int x1 = s.Width / 10;
                        int y1 = s.Height / 10;

                        r.UpperLeftCorner  = fGen.GetWindowCoord(-x1, -y1);
                        r.LowerRightCorner = fGen.GetWindowCoord(s.Width + x1, s.Height + y1);
                    }

                    fGen.Generate(r);
                    return(true);
                }

                if (evnt.Mouse.Type == MouseEventType.LeftDown)
                {
                    mouseMoveStart = new Vector2Di(evnt.Mouse.X, evnt.Mouse.Y);
                    return(true);
                }

                if (evnt.Mouse.Type == MouseEventType.LeftUp)
                {
                    Vector2Dd p1 = fGen.GetWindowCoord(evnt.Mouse.X, evnt.Mouse.Y);
                    Vector2Dd p2 = fGen.GetWindowCoord(mouseMoveStart.X, mouseMoveStart.Y);
                    Rectd     r  = fGen.GetWindow() + p2 - p1;

                    fGen.Generate(r);

                    mouseMoveStart = null;
                    return(true);
                }
            }

            if (evnt.Type == EventType.Key)
            {
                if (evnt.Key.PressedDown)
                {
                    if (evnt.Key.Key == KeyCode.Esc)
                    {
                        device.Close();
                        return(true);
                    }

                    if (evnt.Key.Key == KeyCode.F1)
                    {
                        showHelp = !showHelp;
                        return(true);
                    }

                    switch (evnt.Key.Char)
                    {
                    case '+':
                        fGen.Generate(fGen.GetMaxIterations() + 1);
                        return(true);

                    case '-':
                        fGen.Generate(fGen.GetMaxIterations() - 1);
                        return(true);

                    case '*':
                        fGen.Generate(fGen.GetMaxIterations() + 10);
                        return(true);

                    case '/':
                        fGen.Generate(fGen.GetMaxIterations() - 10);
                        return(true);
                    }
                }

                if (evnt.Key.Key == KeyCode.PrintScreen)                 // PrintScreen never comes with "evnt.Key.PressedDown == true" so we process it without checking that
                {
                    string n = "Screenshot-" + DateTime.Now.Ticks + ".png";
                    Image  i = device.VideoDriver.CreateScreenShot();
                    device.VideoDriver.WriteImage(i, n);
                    i.Drop();

                    device.Logger.Log("Screenshot saved as " + n);
                    return(true);
                }
            }

            return(false);
        }
Beispiel #22
0
        public InterpolatedDoseGrid(IDoseObject doseObject, int maxNumberOfGrids, Camera camera, Rectd normRect)
        {
            //Intersect the camera screen and cube surrounding the dose object to limit the rendering.
            var boundingRect = camera.GetBoundingScreenRect(doseObject.Grid.XRange, doseObject.Grid.YRange, doseObject.Grid.ZRange, normRect);

            if (boundingRect == null)
            {
                return;
            }

            Rows    = maxNumberOfGrids;
            Columns = maxNumberOfGrids;

            var dy = boundingRect.Height / maxNumberOfGrids;
            var dx = boundingRect.Width / maxNumberOfGrids;

            Point2d screenPoint         = new Point2d(boundingRect.X, boundingRect.Y);
            var     normalisationAmount = doseObject.Grid.GetNormalisationAmount();
            Point3d worldPoint          = new Point3d();

            Coords = new double[Rows][][];
            Data   = new float[Rows][];
            Voxel voxel = new Voxel();

            for (int row = 0; row < Rows; row++)
            {
                Coords[row] = new double[Columns][];
                Data[row]   = new float[Columns];
                for (int col = 0; col < Columns; col++)
                {
                    screenPoint.X = boundingRect.X + col * dx;
                    screenPoint.Y = boundingRect.Y + row * dy;

                    camera.ConvertScreenToWorldCoords(screenPoint.Y, screenPoint.X, worldPoint);
                    Coords[row][col] = new double[3] {
                        worldPoint.X, worldPoint.Y, worldPoint.Z
                    };

                    doseObject.Grid.Interpolate(worldPoint, voxel);

                    Data[row][col] = (voxel.Value * doseObject.Grid.Scaling) / normalisationAmount;
                }
            }
        }