Exemplo n.º 1
0
 public void Upload(TextureTarget target, Region2D region)
 {
     GL.TexImage3D(target, 0, InternalFormat,
                     Size.Width, Size.Height, Depth,
                     0, Format, Type,
                     IntPtr.Zero);
 }
Exemplo n.º 2
0
        public void Upload(TextureTarget target, Region2D region)
        {
            GL.PixelStore(PixelStoreParameter.UnpackRowLength, Size.Width);
            GL.PixelStore(PixelStoreParameter.UnpackSkipRows, Bounds.Index.Row);
            GL.PixelStore(PixelStoreParameter.UnpackSkipPixels, Bounds.Index.Column);

            UploadImage(target, region);

            GL.PixelStore(PixelStoreParameter.UnpackSkipRows, 0);
            GL.PixelStore(PixelStoreParameter.UnpackSkipPixels, 0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convert Region3D to Region2D
        /// </summary>
        /// <param name="region3D">3D Region</param>
        /// <returns>2D Region</returns>
        public static IRegion2D ConvertTo2D(IRegion3D region3D)
        {
            IRegion2D region2D = new Region2D
            {
                Outline = ConvertTo2D(region3D.Outline)
            };

            foreach (IPolyLine3D polyline in region3D.Openings)
            {
                region2D.Openings.Add(ConvertTo2D(polyline));
            }

            return(region2D);
        }
Exemplo n.º 4
0
 protected virtual void UploadImage(TextureTarget target, Region2D region)
 {
     if (region == Bounds)
     {
         GL.TexImage2D(target, 0, InternalFormat,
                       region.Size.Width, region.Size.Width, 0,
                       Format, Type, Pixels);
     }
     else
     {
         GL.TexSubImage2D(target, 0, region.Index.Column, region.Index.Row,
                          region.Size.Width, region.Size.Width,
                          Format, Type, Pixels);
     }
 }
Exemplo n.º 5
0
        public static IRegion2D Convert(this Region source)
        {
            var target   = new Region2D(source.Outline.Convert());
            var openings = source.Openings;

            if (openings != null && openings.Count > 0)
            {
                var targetOpenings = target.Openings;
                foreach (var opening in openings)
                {
                    targetOpenings.Add(opening.Convert());
                }
            }

            return(target);
        }
Exemplo n.º 6
0
        public static IRegion2D ConvertTo2D(IRegion3D region3D, IMatrix44 lcs)
        {
            var regionCopy = new Region3D(region3D);

            GeomOperation.TransformToLCS(lcs, regionCopy);
            var outline2D = ConvertTo2D(regionCopy.Outline);
            var region2D  = new Region2D(outline2D);

            if (regionCopy.OpeningsCount > 0)
            {
                foreach (var opening3D in regionCopy.Openings)
                {
                    region2D.Openings.Add(ConvertTo2D(opening3D));
                }
            }

            return(region2D);
        }
Exemplo n.º 7
0
        public void SetEye(Vector3 eye)
        {
            ImageArray imageArray = (ImageArray)Image;

            for (int level = 0; level < imageArray.Depth; level++)
            {
                float   levelScale = (float)(1 << (level + 1));
                Vector2 offset     = eye.Xy / levelScale;

                Index2D index = GetInitialIndex(imageArray[level], Image.Size.Width);
                index.Offset((int)offset.X, (int)offset.Y);

                Region2D bounds = imageArray[level].Bounds;

                if (bounds.Index != index)
                {
                    imageArray[level].Bounds = new Region2D(index, bounds.Size);
                    Dirty(level);
                }
            }
        }
Exemplo n.º 8
0
 public void Dirty(Region2D region)
 {
     dirtyRegions.Add(region);
 }
Exemplo n.º 9
0
        public Form1()
        {
            #region Инициализация формы
            InitializeComponent();
            lb0.BackColor  = JuniorPathFinderGrig.HSVColor.GetRGBColor(Layers.Layer0);
            lb7.BackColor  = JuniorPathFinderGrig.HSVColor.GetRGBColor(Layers.Layer7);
            lb13.BackColor = JuniorPathFinderGrig.HSVColor.GetRGBColor(Layers.Layer13);
            lb17.BackColor = JuniorPathFinderGrig.HSVColor.GetRGBColor(Layers.Layer17);
            lb20.BackColor = JuniorPathFinderGrig.HSVColor.GetRGBColor(Layers.Layer20);
            lb25.BackColor = JuniorPathFinderGrig.HSVColor.GetRGBColor(Layers.Layer25);
            #endregion

            #region Инициализация элементов PathFinder
            Region2D region = new Region2D(Vector3i.zero, 20, 20, Layers.Layer0);
            pfGrid.Map = region;
            weights.AddValue(Layers.Layer0, 4);
            weights.AddValue(Layers.Layer7, 8);
            weights.AddValue(Layers.Layer13, 12);
            weights.AddValue(Layers.Layer17, 16);
            weights.AddValue(Layers.Layer20, 20);
            weights.AddValue(Layers.Layer25, 24);
            #endregion

            #region События
            // Новый регион
            btNew.Click += (s, e) =>
            {
                region     = new Region2D(Vector3i.zero, (byte)tbXSize.Value, (byte)tbYsize.Value, Layers.Layer0);
                pfGrid.Map = region;
            };
            // Сохранить регион
            btSave.Click += (s, e) => {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.InitialDirectory = curDir;
                sfd.Filter           = "Region file (*.jpfr)|*.jpfr";
                if (sfd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                string filename = sfd.FileName;
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    byte[] array = pfGrid.Map.GetBytes();
                    fs.Write(array, 0, array.Length);
                    fs.Close();
                }
            };
            // Загрузить регион
            btLoad.Click += (s, e) =>
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.InitialDirectory = curDir;
                ofd.Filter           = "Region file (*.jpfr)|*.jpfr";
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                string filename = ofd.FileName;
                using (FileStream fs = new FileStream(filename, FileMode.Open))
                {
                    byte[] array = new byte[fs.Length];
                    fs.Read(array, 0, (int)fs.Length);
                    fs.Close();
                    pfGrid.Map.SetBytes(array);
                }
                pfGrid.UpdateMap();
            };
            ResizeEnd += (s, e) => {
                pfGrid.UpdateMap();
            };
            #endregion
        }
Exemplo n.º 10
0
 public void Dirty(int index, Region2D bounds)
 {
     dirtyRegions[index].Add(bounds);
 }
Exemplo n.º 11
0
        public static FaceRegion2D[] GetFaceRegion2Ds(IImage gray,
                                                      int faceWidth, int faceHeight, bool findEyes = true, bool findMouthRegions = true)
        {
            var ret = new List <FaceRegion2D>();

            var parameter = new PrepareImageParameter
            {
            };

            using (var grayGpu = new GpuImage <Gray, byte>((Image <Gray, byte>)gray))
            {
                IEnumerable <Region2D> faceRegions = FilterInstances.FaceFilter.GetResult(grayGpu, new FacePartParameter
                {
                    MinWidth  = faceWidth,
                    MinHeight = faceHeight
                });

                if (faceRegions == null)
                {
                    return(ret.ToArray());
                }


                foreach (Region2D faceRegion in faceRegions)
                {
                    Region2D leftEyeRegion  = null;
                    Region2D rightEyeRegion = null;
                    Region2D mouthRegion    = null;
                    double   angle          = 0;
                    IImage   faceImage      = null;

                    using (IImage cropFace = FilterInstances.CropFilter.GetResult(grayGpu, new CropParameter {
                        Region = faceRegion
                    }))
                    {
                        #region Face parts detection

                        if (findEyes)
                        {
                            #region Detect Eyes

                            #region Left

                            var leftRegion = new Region2D
                            {
                                Location = new Point
                                {
                                    X = 0,
                                    Y = 0
                                },
                                Width  = faceRegion.Width / 2,
                                Height = faceRegion.Height / 2
                            };

                            IEnumerable <Region2D> leftEyes = FilterInstances.EyeFilter.GetResult
                                                                  (cropFace, new FacePartParameter {
                                Region = leftRegion
                            });

                            if (leftEyes.Any())
                            {
                                leftEyeRegion = new Region2D
                                {
                                    Location = new Point
                                    {
                                        X = (int)leftEyes.Average(item => item.Location.X) + leftRegion.Location.X,
                                        Y = (int)leftEyes.Average(item => item.Location.Y) + leftRegion.Location.Y
                                    },
                                    Width  = (int)leftEyes.Average(item => item.Width),
                                    Height = (int)leftEyes.Average(item => item.Height)
                                };
                            }

                            #endregion

                            #region Right

                            var rightRegion = new Region2D
                            {
                                Location = new Point
                                {
                                    X = faceRegion.Width / 2,
                                    Y = 0,
                                },
                                Width  = faceRegion.Width / 2,
                                Height = faceRegion.Height / 2
                            };

                            IEnumerable <Region2D> rightEyes = FilterInstances.EyeFilter.GetResult
                                                                   (cropFace, new FacePartParameter {
                                Region = rightRegion
                            });

                            if (rightEyes.Any())
                            {
                                rightEyeRegion = new Region2D
                                {
                                    Location = new Point
                                    {
                                        X = (int)rightEyes.Average(item => item.Location.X) + rightRegion.Location.X,
                                        Y = (int)rightEyes.Average(item => item.Location.Y) + rightRegion.Location.Y
                                    },
                                    Width  = (int)rightEyes.Average(item => item.Width),
                                    Height = (int)rightEyes.Average(item => item.Height)
                                };
                            }

                            #endregion

                            #endregion

                            #region Calculate Face Angle

                            if (leftEyeRegion != null &&
                                rightEyeRegion != null)
                            {
                                int yCoord = (rightEyeRegion.Location.Y + rightEyeRegion.Height / 2)
                                             - (leftEyeRegion.Location.Y + leftEyeRegion.Height / 2);

                                int xCoord = (rightEyeRegion.Location.X + rightEyeRegion.Width / 2 + leftRegion.Width)
                                             - (leftEyeRegion.Location.X + leftEyeRegion.Width / 2);

                                // calc rotation angle in radians
                                angle = -Math.Atan2(yCoord, xCoord) * (180.0 / Math.PI);
                            }

                            #endregion
                        }

                        if (findMouthRegions)
                        {
                            #region Mouth

                            var mouthSearchRegion = new Region2D
                            {
                                Location = new Point
                                {
                                    X = 0,
                                    Y = faceRegion.Height / 2
                                },
                                Width  = faceRegion.Width,
                                Height = faceRegion.Height / 2
                            };

                            IEnumerable <Region2D> mouths = FilterInstances.MouthFilter.GetResult(cropFace, new FacePartParameter
                            {
                                Region = mouthSearchRegion
                            });

                            if (mouths.Any())
                            {
                                mouthRegion = new Region2D
                                {
                                    Location = new Point
                                    {
                                        X = (int)mouths.Average(item => item.Location.X) + mouthSearchRegion.Location.X,
                                        Y = (int)mouths.Average(item => item.Location.Y) + mouthSearchRegion.Location.Y
                                    },
                                    Width  = (int)mouths.Average(item => item.Width),
                                    Height = (int)mouths.Average(item => item.Height)
                                };
                            }

                            #endregion
                        }

                        #endregion

                        faceImage = FilterInstances.ResizeFilter.GetResult(cropFace, new ResizeParameter {
                            NewHeight = faceHeight, NewWidth = faceWidth
                        });
                    }

                    ret.Add(new FaceRegion2D
                    {
                        Face        = faceRegion,
                        LeftEye     = leftEyeRegion,
                        RightEye    = rightEyeRegion,
                        Mouth       = mouthRegion,
                        EyeAngle    = angle,
                        FaceImage   = (Image <Gray, byte>)faceImage,
                        SourceImage = (gray as Image <Gray, byte>) ?? ((GpuImage <Gray, byte>)grayGpu).ToImage()
                    });
                }
            }

            return(ret.ToArray());
        }
Exemplo n.º 12
0
 public void Dirty(Region2D region)
 {
     dirtyRegions.Add(region);
 }
        /// <summary>
        /// Creates the minimum 2D volume from the list of contours and the region of interest.
        /// </summary>
        /// <param name="contours">The contours by slice.</param>
        /// <param name="spacingX">The X-dimension pixel spacing.</param>
        /// <param name="spacingY">The Y-dimension pixel spacing.</param>
        /// <param name="origin">The patient position origin.</param>
        /// <param name="direction">The directional matrix.</param>
        /// <param name="region">The region of interest.</param>
        /// <returns>The minimum 2D volume.</returns>
        public static Volume2D <byte> CreateVolume2D(this IReadOnlyList <ContourPolygon> contours, double spacingX, double spacingY, Point2D origin, Matrix2 direction, Region2D <int> region)
        {
            // Convert every point to within the region
            var subContours = contours.Select(x =>
                                              new ContourPolygon(
                                                  x.ContourPoints.Select(
                                                      point => new PointF(point.X - region.MinimumX, point.Y - region.MinimumY)).ToArray(), 0)).ToList();

            // Create 2D volume
            var result = new Volume2D <byte>(region.MaximumX - region.MinimumX + 1, region.MaximumY - region.MinimumY + 1, spacingX, spacingY, origin, direction);

            result.Fill(subContours, ModelConstants.MaskForegroundIntensity);

            return(result);
        }
Exemplo n.º 14
0
        private void FillTGeneral()
        {
            //Example of custom T section
            CrossSectionComponent css = new CrossSectionComponent();

            css.Name = "CSS1";
            css.Id   = 6;


            LineSegment2D seg = null;

            //seg = new LineSegment2D(); seg.EndPoint = new Point2D() { X = -0.002, Y = -0.1 }; outline.Segments.Add(seg);
            //seg = new LineSegment2D(); seg.EndPoint = new Point2D() { X = 0.002, Y = -0.1 }; outline.Segments.Add(seg);
            //seg = new LineSegment2D(); seg.EndPoint = new Point2D() { X = 0.002, Y = -0.002 }; outline.Segments.Add(seg);
            //seg = new LineSegment2D(); seg.EndPoint = new Point2D() { X = 0.002, Y = 0.002 }; outline.Segments.Add(seg);
            //seg = new LineSegment2D(); seg.EndPoint = new Point2D() { X = 0.002, Y = 0.1 }; outline.Segments.Add(seg);
            //seg = new LineSegment2D(); seg.EndPoint = new Point2D() { X = -0.002, Y = 0.1 }; outline.Segments.Add(seg);
            //seg = new LineSegment2D(); seg.EndPoint = new Point2D() { X = -0.002, Y = 0.002 }; outline.Segments.Add(seg);

            {
                CssComponent comp = new CssComponent();
                comp.Material = new ReferenceElement(openStructModel.MatSteel.First());
                comp.Phase    = 0;
                var reg     = new Region2D();
                var outline = new PolyLine2D();
                outline.StartPoint = new Point2D()
                {
                    X = -0.15, Y = 0.002
                };
                seg = new LineSegment2D(); seg.EndPoint = new Point2D()
                {
                    X = -0.15, Y = -0.002
                }; outline.Segments.Add(seg);
                seg = new LineSegment2D(); seg.EndPoint = new Point2D()
                {
                    X = 0.15, Y = -0.002
                }; outline.Segments.Add(seg);
                seg = new LineSegment2D(); seg.EndPoint = new Point2D()
                {
                    X = 0.15, Y = 0.002
                }; outline.Segments.Add(seg);
                seg = new LineSegment2D(); seg.EndPoint = new Point2D()
                {
                    X = -0.15, Y = 0.002
                }; outline.Segments.Add(seg);
                reg.Outline   = outline;
                comp.Geometry = reg;
                css.Components.Add(comp);
            }
            {
                CssComponent comp = new CssComponent();
                comp.Material = new ReferenceElement(openStructModel.MatSteel.First());
                comp.Phase    = 0;
                var reg     = new Region2D();
                var outline = new PolyLine2D();
                outline.StartPoint = new Point2D()
                {
                    X = -0.002, Y = -0.002
                };
                seg = new LineSegment2D(); seg.EndPoint = new Point2D()
                {
                    X = -0.002, Y = -0.1
                }; outline.Segments.Add(seg);
                seg = new LineSegment2D(); seg.EndPoint = new Point2D()
                {
                    X = 0.002, Y = -0.1
                }; outline.Segments.Add(seg);
                seg = new LineSegment2D(); seg.EndPoint = new Point2D()
                {
                    X = 0.002, Y = 0.002
                }; outline.Segments.Add(seg);
                seg = new LineSegment2D(); seg.EndPoint = new Point2D()
                {
                    X = -0.002, Y = -0.002
                }; outline.Segments.Add(seg);
                reg.Outline   = outline;
                comp.Geometry = reg;
                css.Components.Add(comp);
            }


            openStructModel.AddObject(css);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Fill center line for general cold formed css
 /// </summary>
 /// <param name="gcf"></param>
 /// <param name="region2D">We need PolyLine2D from region2D</param>
 /// <param name="Thickness">Thickness</param>
 /// <param name="InsideRadius">Inside radius</param>
 public static void FillColdFormedGeneral(CrossSectionGeneralColdFormed gcf, Region2D region2D, double Thickness, double InsideRadius)
 {
     gcf.Centerline = region2D.Outline;
     gcf.Thickness  = Thickness;
     gcf.Radius     = InsideRadius;
 }
Exemplo n.º 16
0
 public void Dirty(int index, Region2D bounds)
 {
     dirtyRegions[index].Add(bounds);
 }