コード例 #1
0
        public void setMap()
        {
            //  try
            {
                var mesh = setBorderMap();
                mesh.TextureCoordinates = setMapCollection();
                ImageBrush brush = new ImageBrush();
                //  brush.ImageSource = new BitmapImage(new Uri(pgmMapPath, UriKind.Absolute));
                BitmapImage bi = new BitmapImage(new Uri(pgmMapPath, UriKind.Absolute));;

                var grayBitmapSource = new FormatConvertedBitmap();
                grayBitmapSource.BeginInit();
                grayBitmapSource.Source            = bi;
                grayBitmapSource.DestinationFormat = PixelFormats.Gray32Float;

                grayBitmapSource.EndInit();


                IplImage canny = BitmapConverter.ToIplImage(BitmapImage2Bitmap(bi));
                IplImage img   = new IplImage();
                Cv.Threshold(canny, canny, 15, 255, ThresholdType.BinaryInv);
                IntPtr Dynstorage = CvInvoke.cvCreateMemStorage(0);
                IntPtr Dyncontour = new IntPtr();
                var    contours   = new List <IntPtr>();
                //    Cv.FindContours(canny,contours,0,1);
                //     CvInvoke.cvFindContours(canny,Dynstorage,ref Dyncontour,8,ContourRetrieval.List,ContourChain.ApproxNone);


                Bitmap pp = BitmapConverter.ToBitmap(canny);
                brush.ImageSource = bi;// ToBitmapImage(pp);

                brush.TileMode      = TileMode.None;
                brush.ViewportUnits = BrushMappingMode.Absolute;
                brush.ViewboxUnits  = BrushMappingMode.Absolute;
                brush.Stretch       = Stretch.None;
                brush.AlignmentX    = AlignmentX.Left;
                brush.AlignmentY    = AlignmentY.Top;
                RotateTransform pr = new RotateTransform();

                //pr.CenterX=100;
                // pr.CenterX=100;
                // brush.Transform = new MatrixTransform(-1, 0, 0, 1.0d, -1.0d, -1.0d);
                brush.Transform = new MatrixTransform(1, 0, 0, -1.0d, 0, 0);

                //  brush.RelativeTransform = pr;
                double largesize = bi.PixelWidth <= bi.PixelHeight ? bi.PixelWidth : bi.PixelHeight;
                brush.Viewport = new Rect(-GlobalVariables.ConvertMetertoUnitLength(74.0), GlobalVariables.ConvertMetertoUnitLength(40.6) - largesize, bi.PixelWidth, bi.PixelHeight);
                // brush.Viewport = new Rect(-GlobalVariables.ConvertMetertoUnitLength(69.8), GlobalVariables.ConvertMetertoUnitLength(40.1)-largesize, bi.PixelWidth, bi.PixelHeight);

                DiffuseMaterial mat      = new DiffuseMaterial(brush);
                GeometryModel3D gModel3D = new GeometryModel3D {
                    Geometry = mesh, Material = mat
                };
                pModelMap.Content = gModel3D;
            }
            //catch
            {
                //    MessageBox.Show("Error in loading Map");
            }
        }
コード例 #2
0
        private void loadinform(String path)
        {
            try
            {
                BitmapImage bi = new BitmapImage(new Uri(TEXT_PATHMAP, UriKind.Absolute));
                GlobalVariables.MAP_WIDTHPIXEL  = bi.PixelWidth;
                GlobalVariables.MAP_HEIGHTPIXEL = bi.PixelHeight;
                double largesize = bi.PixelWidth <= bi.PixelHeight ? bi.PixelWidth : bi.PixelHeight;     // select the small length of image
                //double largesize = 832;
                txt_gridwidth.Text         = "" + largesize;
                txt_gridlength.Text        = "" + largesize;
                txt_gridmajordistance.Text = "" + (largesize / 40.00).ToString("0.000");
                txt_gridminordistance.Text = "" + (largesize / 40.00).ToString("0.000");
                txt_borderX.Text           = "" + GlobalVariables.MAP_WIDTHPIXEL;
                txt_borderY.Text           = "" + GlobalVariables.MAP_HEIGHTPIXEL;

                GlobalVariables.GRIDLINE_WIDTH  = Convert.ToDouble(txt_borderX.Text);
                GlobalVariables.GRIDLINE_LENGTH = Convert.ToDouble(txt_borderY.Text);
                GlobalVariables.MEASUREMENT_UNITASQUARE_LENGTH = largesize / 40;
                GlobalVariables.MEASUREMENT_UNITASQUARE_METER  = Convert.ToDouble(txt_unitMeterPixel.Text) * GlobalVariables.MEASUREMENT_UNITASQUARE_LENGTH;

                txt_mappointX.Text = "" + GlobalVariables.MAP_WIDTHPIXEL;
                txt_mappointY.Text = "" + GlobalVariables.MAP_HEIGHTPIXEL;
                //     txt_asquared.Text = "" + GlobalVariables.MEASUREMENT_UNITASQUARE+" (m)";

                ModelImporter import = new ModelImporter();
                Model3D       device = import.Load(GlobalVariables.getPathRobot3DModel());

                double Sx = device.Bounds.SizeX / 100;   // size in cm  to m
                //MessageBox.Show("size X:" +Sx);
                double Sy = device.Bounds.SizeY / 100;
                double Sz = device.Bounds.SizeZ / 100;
                GlobalVariables.ROBOT_SCALED = GlobalVariables.ConvertMetertoUnitLength(Sx / 100) / Sx;

                richtxt_detailInformation.Document.Blocks.Clear();
                String inform = "Detail information: \n";
                inform += "+Length of a square: " + GlobalVariables.MEASUREMENT_UNITASQUARE_LENGTH + "\n";
                inform += "+Length meter of a squared: " + GlobalVariables.MEASUREMENT_UNITASQUARE_METER + "\n";     /// số ô là 40 ,
                inform += "+ Robot size (m): " + Sx.ToString("0.00") + " // " + Sy.ToString("0.00") + " // " + Sz.ToString("0.00") + "\n";
                inform += "+ Scaled Robot: " + GlobalVariables.ROBOT_SCALED.ToString("0.00");
                richtxt_detailInformation.AppendText(inform);
                TEXT_ROBOT_INFOMATION = inform;
            }
            catch
            {
                MessageBox.Show("Path is wrong");
            }
        }
コード例 #3
0
        public void createpalletobj(ModelVisual3D ppalletlayer)
        {
            ppalletlayer.Children.Clear();
            pPalletlist.Clear();
            CreatePallet pPallet1 = new CreatePallet();

            pPallet1.updatePos(GlobalVariables.ConvertMetertoUnitLength(11.2), GlobalVariables.ConvertMetertoUnitLength(-1.23), 0, 180);
            pPalletlist.Add(pPallet1);
            ppalletlayer.Children.Add(pPallet1.contentlayer);

            CreatePallet pPallet2 = new CreatePallet();

            pPallet2.updatePos(GlobalVariables.ConvertMetertoUnitLength(12.6), GlobalVariables.ConvertMetertoUnitLength(-1.23), 0, 180);
            pPalletlist.Add(pPallet2);
            ppalletlayer.Children.Add(pPallet2.contentlayer);
        }