/// <summary> Initializes a new instance of the <see cref="ShapeLayer"/> class. By default, the spatial reference system is set to "EPSG:4326". </summary> /// <param name="name"> Name of the layer. </param> public ShapeLayer(string name) : base(name) { SpatialReferenceId = "EPSG:4326"; InitializeFactory(CanvasCategory.Content, map => { if (map.Name != "Map") { return(null); } var localOffset = (LocalOffset.X != 0 || LocalOffset.Y != 0) ? GeoTransform.Transform(LocalOffset, SpatialReferenceId, "PTV_MERCATOR") : new Point(0, 0); return(new ShapeCanvas(map, Shapes, SpatialReferenceId, LazyUpdate, true, localOffset)); }); }
private void points_view_FormClosing(object sender, FormClosingEventArgs e) { if (Form1.Image_ID > -1) { Form1 f_main = Application.OpenForms["Form1"] as Form1; f_main.GCP_draw(Form1.gcp_collected[Form1.Image_ID]); f_main.GCP_draw(Form1.gcp_collected[Form1.Image_ID]); } if (formgcp.Form_active == true) { formgcp f_gcp = Application.OpenForms["formgcp"] as formgcp; f_gcp.dzy_main(); } if (GeoTransform.form_active == true) { GeoTransform geo = Application.OpenForms["GeoTransform"] as GeoTransform; geo.image_dzyn(); } }
public float[][] ReadRegionAcrossFiles_MP(int xOffset, int yOffset, int xSize, int ySize) { int nPixPerTile = xSize * ySize; float[][] tileData = new float[m_FileDates.Count][]; ParallelOptions b = new ParallelOptions(); b.MaxDegreeOfParallelism = 6; var keys = m_FileDates.Keys; Parallel.For(0, keys.Count, b, c => { var fDate = keys[c]; var fName = m_FileDates[fDate]; var newshape = GDAL_Operations.GetRasterShape(fName); if (newshape.Item1 != Shape.Item1 || newshape.Item2 != Shape.Item2) { throw new ArgumentException("Raster shapes don't match"); } var newGT = GDAL_Operations.GetGeoTransform(fName); if (!GeoTransform.SequenceEqual(newGT)) { throw new ArgumentException("Raster geotransforms don't match"); } var newNDV = GDAL_Operations.GetNoDataValue(fName); if (newNDV != NoDataValue) { throw new ArgumentException("Raster nodata values don't match"); } var newProj = GDAL_Operations.GetProjection(fName); if (newProj != Projection) { throw new ArgumentException("Raster projections don't match"); } tileData[c] = GDAL_Operations.ReadGDALRasterBandsToFlatArray( fName, xSize, ySize, xOffset, yOffset, 1); }); return(tileData); }
/// <summary> /// Read the values within the specified pixel offsets from the first band of all this TiffCubeReader's rasters, /// returning them as a 1-D array in X,Y,Z order (i.e. leftmost pixel of first row of first file to rightmost /// pixel of last row of last file) /// </summary> /// <param name="xOffset"></param> /// <param name="yOffset"></param> /// <param name="xSize"></param> /// <param name="ySize"></param> /// <returns></returns> public float[] ReadRegionAcrossFiles_Flat(int xOffset, int yOffset, int xSize, int ySize) { // var f = m_FileDates.Values; int nPixPerTile = xSize * ySize; float[] tileData = new float[nPixPerTile * m_FileDates.Count]; int fileNum = 0; foreach (var t in m_FileDates) { int pxStart = nPixPerTile * fileNum; var newshape = GDAL_Operations.GetRasterShape(t.Value); if (newshape.Item1 != Shape.Item1 || newshape.Item2 != Shape.Item2) { throw new ArgumentException("Raster shapes don't match"); } var newGT = GDAL_Operations.GetGeoTransform(t.Value); if (!GeoTransform.SequenceEqual(newGT)) { throw new ArgumentException("Raster geotransforms don't match"); } var newNDV = GDAL_Operations.GetNoDataValue(t.Value); if (newNDV != NoDataValue) { throw new ArgumentException("Raster nodata values don't match"); } var newProj = GDAL_Operations.GetProjection(t.Value); if (newProj != Projection) { throw new ArgumentException("Raster projections don't match"); } var bandarr = GDAL_Operations.ReadGDALRasterBandsToFlatArray( t.Value, xSize, ySize, xOffset, yOffset, 1); Array.Copy(bandarr, 0, tileData, pxStart, bandarr.Length); fileNum += 1; } return(tileData); }
/// <summary> Converts a canvas point to a geographic point. </summary> /// <param name="canvasPoint"> The canvas point. </param> /// <returns> The geographic point. </returns> public Point CanvasToGeo(Point canvasPoint) { return(GeoTransform.PtvMercatorToWGS(CanvasToPtvMercator(canvasPoint))); }
/// <summary> Converts a geographic point to a canvas point. </summary> /// <param name="geoPoint"> The geographic point. </param> /// <returns> The canvas point. </returns> public Point GeoToCanvas(Point geoPoint) { return(PtvMercatorToCanvas(GeoTransform.WGSToPtvMercator(geoPoint))); }
/// <summary> /// Converts a geographic point to a canvas coordinate. /// </summary> /// <param name="geoPoint">The geographic point.</param> /// <param name="spatialReferenceId">The spatial reference identifier.</param> /// <returns> The transformed canvas coordinate. </returns> public Point GeoToCanvas(Point geoPoint, string spatialReferenceId) { return(PtvMercatorToCanvas(GeoTransform.Transform(geoPoint, spatialReferenceId, "PTV_MERCATOR"))); }
public static bool SetOverView(PhotoData data, out int overviewlevel, out int overviewzoom) { Size _imagesize = new Size(data.Width, data.Height); double[] trans = new double[6]; trans[0] = data.Transform1; trans[1] = data.Transform2; trans[2] = data.Transform3; trans[3] = data.Transform4; trans[4] = data.Transform5; trans[5] = data.Transform6; GeoTransform _geoTransform = new GeoTransform(trans); double right = 0, left = 0, top = 0, bottom = 0; double dblW, dblH; dblW = _imagesize.Width; dblH = _imagesize.Height; left = _geoTransform.EnvelopeLeft(dblW, dblH); right = _geoTransform.EnvelopeRight(dblW, dblH); top = _geoTransform.EnvelopeTop(dblW, dblH); bottom = _geoTransform.EnvelopeBottom(dblW, dblH); BoundingBox _envelope = new BoundingBox(left, bottom, right, top); overviewlevel = -1; overviewzoom = 1; int viewcount = 4; int[] scale = new int[viewcount + 1]; int[] scalelevel = new int[viewcount + 1]; scale[0] = 1; scalelevel[0] = -1; for (int i = 1; i <= viewcount; i++) { scale[i] = Convert.ToInt32(Math.Pow(2.0, i + 1)); scalelevel[i] = i - 1; } BoundingBox displayBbox = Map.Envelope; // bounds of section of image to be displayed left = Math.Max(displayBbox.Left, _envelope.Left); top = Math.Min(displayBbox.Top, _envelope.Top); right = Math.Min(displayBbox.Right, _envelope.Right); bottom = Math.Max(displayBbox.Bottom, _envelope.Bottom); if ((displayBbox.Left > _envelope.Right) || (displayBbox.Right < _envelope.Left) || (displayBbox.Top < _envelope.Bottom) || (displayBbox.Bottom > _envelope.Top)) { overviewlevel = scalelevel[1]; overviewzoom = scale[1]; return(false); } for (int i = scale.Length - 1; i >= 0; i--) { BoundingBox trueImageBbox = new BoundingBox(left, bottom, left + (right - left) / scale[i], top); BoundingBox shownImageBbox; EasyMap.Geometries.Point imageTL = new EasyMap.Geometries.Point(), imageBR = new EasyMap.Geometries.Point(); // put display bounds into current projection // if (_transform != null) // { //#if !DotSpatialProjections // _transform.MathTransform.Invert(); // shownImageBbox = GeometryTransform.TransformBox(trueImageBbox, _transform.MathTransform); // _transform.MathTransform.Invert(); //#else // shownImageBbox = GeometryTransform.TransformBox(trueImageBbox, _transform.Source, _transform.Target); //#endif // } // else shownImageBbox = trueImageBbox; // find min/max x and y pixels needed from image imageBR.X = (int) (Math.Max(_geoTransform.GroundToImage(shownImageBbox.TopLeft).X, Math.Max(_geoTransform.GroundToImage(shownImageBbox.TopRight).X, Math.Max(_geoTransform.GroundToImage(shownImageBbox.BottomLeft).X, _geoTransform.GroundToImage(shownImageBbox.BottomRight).X))) + 1); imageBR.Y = (int) (Math.Max(_geoTransform.GroundToImage(shownImageBbox.TopLeft).Y, Math.Max(_geoTransform.GroundToImage(shownImageBbox.TopRight).Y, Math.Max(_geoTransform.GroundToImage(shownImageBbox.BottomLeft).Y, _geoTransform.GroundToImage(shownImageBbox.BottomRight).Y))) + 1); imageTL.X = (int) Math.Min(_geoTransform.GroundToImage(shownImageBbox.TopLeft).X, Math.Min(_geoTransform.GroundToImage(shownImageBbox.TopRight).X, Math.Min(_geoTransform.GroundToImage(shownImageBbox.BottomLeft).X, _geoTransform.GroundToImage(shownImageBbox.BottomRight).X))); imageTL.Y = (int) Math.Min(_geoTransform.GroundToImage(shownImageBbox.TopLeft).Y, Math.Min(_geoTransform.GroundToImage(shownImageBbox.TopRight).Y, Math.Min(_geoTransform.GroundToImage(shownImageBbox.BottomLeft).Y, _geoTransform.GroundToImage(shownImageBbox.BottomRight).Y))); // stay within image if (imageBR.X > _imagesize.Width) { imageBR.X = _imagesize.Width; } if (imageBR.Y > _imagesize.Height) { imageBR.Y = _imagesize.Height; } if (imageTL.Y < 0) { imageTL.Y = 0; } if (imageTL.X < 0) { imageTL.X = 0; } double cx2 = imageBR.X; double cx1 = imageTL.X; int displayImageLength = (int)(imageBR.X - imageTL.X); int displayImageHeight = (int)(imageBR.Y - imageTL.Y); // convert ground coordinates to map coordinates to figure out where to place the bitmap System.Drawing.Point bitmapBR = new System.Drawing.Point((int)Map.WorldToImage(trueImageBbox.BottomRight).X + 1, (int)Map.WorldToImage(trueImageBbox.BottomRight).Y + 1); System.Drawing.Point bitmapTL = new System.Drawing.Point((int)Map.WorldToImage(trueImageBbox.TopLeft).X, (int)Map.WorldToImage(trueImageBbox.TopLeft).Y); int bitmapLength = bitmapBR.X - bitmapTL.X; int bitmapHeight = bitmapBR.Y - bitmapTL.Y; // check to see if image is on its side if (bitmapLength > bitmapHeight && displayImageLength < displayImageHeight) { displayImageLength = bitmapHeight; displayImageHeight = bitmapLength; } else { displayImageLength = bitmapLength; displayImageHeight = bitmapHeight; } double temp = (cx2 - cx1) / (displayImageLength - 1); if (i == 0 && temp < 1) { return(false); } else if (temp >= scale[i]) { overviewzoom = scale[i]; overviewlevel = scalelevel[i]; return(true); } } overviewzoom = scale[0]; overviewlevel = scalelevel[0]; return(true); }
/// <summary> Reads the earthquakes from an xml file and adds a pin element for each to the map. </summary> private void ParseAtomUsingLinq() { System.Xml.Linq.XDocument feedXML = System.Xml.Linq.XDocument.Load("http://earthquake.usgs.gov/earthquakes/catalogs/7day-M2.5.xml"); System.Xml.Linq.XNamespace xmlns = "http://www.w3.org/2005/Atom"; //Atom namespace System.Xml.Linq.XNamespace georssns = "http://www.georss.org/georss"; //GeoRSS Namespace // time to learn some LINQ var posts = (from item in feedXML.Descendants(xmlns + "entry") select new { Title = item.Element(xmlns + "title").Value, Published = DateTime.Parse(item.Element(xmlns + "updated").Value), Url = item.Element(xmlns + "link").Attribute("href").Value, Description = item.Element(xmlns + "summary").Value, Location = CoordinateGeoRssPoint(item.Element(georssns + "point")), //Simple GeoRSS <georss:point>X Y</georss.point> }).ToList(); int i = 0; // order posts by latitude, so they overlap nicely on the map foreach (var post in from post in posts orderby post.Location.Y descending select post) { if (!double.IsNaN(post.Location.X) && !double.IsNaN(post.Location.Y)) { // transform wgs to PTVMercator coordinate var mapPoint = GeoTransform.WGSToPtvMercator(post.Location); // create button and set pin template var pin = new Pin { // a bug in SL throws an obscure exception if children share the same name // http://forums.silverlight.net/forums/t/134299.aspx // the name is needed in XAML for data binding, so just create a unique name at runtime Name = "pin" + (i++), // set render transform for power-law scaling RenderTransform = adjustTransform, // scale around lower right RenderTransformOrigin = new System.Windows.Point(1, 1) }; // set size by magnitude double magnitude = MagnitudeFromTitle(post.Title); pin.Height = magnitude * 10; pin.Width = magnitude * 10; // calculate a value between 0 and 1 and use it for a blend color double relativeDanger = Math.Max(0, Math.Min(1, (magnitude - 2.5) / 4)); pin.Color = Colors.Red; pin.Color = ColorBlend.Danger.GetColor((float)relativeDanger); // set tool tip information ToolTipService.SetToolTip(pin, post.Title); // set position and add to canvas (invert y-ordinate) // set lower right (pin-tip) as position SetLeft(pin, mapPoint.X - pin.Width); SetTop(pin, -(mapPoint.Y + pin.Height)); Children.Add(pin); } } }
public static List <Point3> deNormalizeMesh(ICollection <Vertex> lv, Shell s, GeoTransform t) { MWPoint3D p0 = s.Points[0]; // we choose a point p0 and make sure the origin is part of the plane of the shell //List<MWPoint3D> cPoints = s.Points.Select(p => new MWPoint3D(p.X - p0.X, p.Y - p0.Y, p.Z - p0.Z)).ToList(); //p0 = new MWPoint3D(0, 0, 0); //// we look for 2 points such that p0, p1 and p2 are not aligned //MWPoint3D p1 = cPoints[1]; //MWPoint3D p2 = cPoints[2]; //for (int i = 2; i < cPoints.Count; i++) //{ // p2 = cPoints[i]; // double dp = Math.Abs((p2.X - p0.X) * (p1.X - p0.X) + (p2.Y - p0.Y) * (p1.Y - p0.Y) + (p2.Z - p0.Z) * (p1.Z - p0.Z)); // if (dp < Points.Distance3D(p0, p1) * Points.Distance3D(p0, p2) - 1e-4) // break; //} //// we extract two normal vectors (v,w) defining the plan of the shell and a normal n //MWVector3D v = new MWVector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z); //v = v.Normalised(); //MWVector3D w0 = new MWVector3D(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z); //MWVector3D n = Vectors3D.VectorialProduct(v, w0); //n = n.Normalised(); //MWVector3D w = Vectors3D.VectorialProduct(v, n); //w = w.Normalised(); //List<MWPoint2D> newPts = cPoints.Select(p => //{ // MWVector3D vp = new MWVector3D(p.X, p.Y, p.Z); // double x = Vectors3D.ScalarProduct(vp, v); // double y = Vectors3D.ScalarProduct(vp, w); // return new MWPoint2D(x, y); //}).ToList(); //double x0 = newPts.Min(p => p.X); //double y0 = newPts.Min(p => p.Y); //double x1 = newPts.Max(p => p.X); //double y1 = newPts.Max(p => p.Y); double l = Math.Max(t.Xmax.X - t.Xmin.X, t.Xmax.Y - t.Xmin.Y); // Math.Max(x1 - x0, y1 - y0); // from normalized 2D to non-normalized 2D List <MWPoint2D> dPoints = lv.Select(p => new MWPoint2D(t.Xmin.X + l * p.X, t.Xmin.Y + l * p.Y)).ToList(); if (dPoints.Any(p => double.IsNaN(p.X))) { Console.WriteLine("NaN"); } //Matrix<double> A = Matrix<double>.Build.DenseOfRowArrays(new[] { v.X, v.Y, v.Z }, new[] { w.X, w.Y, w.Z }, new[] { n.X, n.Y, n.Z }); Matrix <double> Ainv = t.P.Inverse(); p0 = t.X0; // s.Points[0]; List <Point3> points3d = dPoints.Select(p => { Vector <double> v2D = Vector <double> .Build.DenseOfArray(new[] { p.X, p.Y, 0.0 }); Vector <double> v3D = Ainv.Multiply(v2D); return(new Point3(p0.X + v3D[0], p0.Y + v3D[1], p0.Z + v3D[2])); }).ToList(); return(points3d); }
/// <summary> /// Normalizes the points coordinates in the plane defined by the shell, and returns the holes and wall segments coordinates /// in this new reference system /// </summary> /// <param name="s"></param> /// <param name="segments"></param> /// <returns></returns> public static (List <Vertex>, GeoTransform) NormalizeShell(Shell s) { MWPoint3D X0 = s.Points[0]; // we choose a point p0 and make sure the origin is part of the plane of the shell List <MWPoint3D> cPoints = s.Points.Select(p => new MWPoint3D(p.X - X0.X, p.Y - X0.Y, p.Z - X0.Z)).ToList(); List <List <MWPoint3D> > cHolesPoints = s.Holes.Select(lp => lp.Select(p => new MWPoint3D(p.X - X0.X, p.Y - X0.Y, p.Z - X0.Z)).ToList()).ToList(); List <List <MWPoint3D> > cSegPoints = s.IncludedSegments.Select(lp => lp.Select(p => new MWPoint3D(p.X - X0.X, p.Y - X0.Y, p.Z - X0.Z)).ToList()).ToList(); MWPoint3D p0 = new MWPoint3D(0, 0, 0); // we look for 2 points such that p0, p1 and p2 are not aligned MWPoint3D p1 = cPoints[1]; MWPoint3D p2 = cPoints[2]; for (int i = 2; i < cPoints.Count; i++) { p2 = cPoints[i]; double dp = Math.Abs((p2.X - p0.X) * (p1.X - p0.X) + (p2.Y - p0.Y) * (p1.Y - p0.Y) + (p2.Z - p0.Z) * (p1.Z - p0.Z)); if (dp < Points.Distance3D(p0, p1) * Points.Distance3D(p0, p2) - 1e-4) { break; } } // we extract two normal vectors defining the plan of the shell MWVector3D v = new MWVector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z); v = v.Normalised(); MWVector3D w0 = new MWVector3D(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z); MWVector3D n = Vectors3D.VectorialProduct(v, w0); n = n.Normalised(); MWVector3D w = Vectors3D.VectorialProduct(v, n); w = w.Normalised(); Matrix <double> P = Matrix <double> .Build.DenseOfRowArrays(new[] { v.X, v.Y, v.Z }, new[] { w.X, w.Y, w.Z }, new[] { n.X, n.Y, n.Z }); List <MWPoint2D> newPts = cPoints.Select(p => { MWVector3D vp = new MWVector3D(p.X, p.Y, p.Z); double x = Vectors3D.ScalarProduct(vp, v); double y = Vectors3D.ScalarProduct(vp, w); double z = Vectors3D.ScalarProduct(vp, n); //Console.WriteLine("z = {0} (should be 0)", z); return(new MWPoint2D(x, y)); }).ToList(); //List<List<MWPoint2D>> newHolesPts = cHolesPoints.Select(lp => lp.Select(p => //{ // MWVector3D vp = new MWVector3D(p.X, p.Y, p.Z); // double x = Vectors3D.ScalarProduct(vp, v); // double y = Vectors3D.ScalarProduct(vp, w); // double z = Vectors3D.ScalarProduct(vp, n); // //Console.WriteLine("z = {0} (should be 0)", z); // return new MWPoint2D(x, y); //}).ToList()).ToList(); //List<List<MWPoint2D>> newSegPts = cSegPoints.Select(lp => lp.Select(p => //{ // MWVector3D vp = new MWVector3D(p.X, p.Y, p.Z); // double x = Vectors3D.ScalarProduct(vp, v); // double y = Vectors3D.ScalarProduct(vp, w); // double z = Vectors3D.ScalarProduct(vp, n); // //Console.WriteLine("z = {0} (should be 0)", z); // return new MWPoint2D(x, y); //}).ToList()).ToList(); if (newPts.Any(p => double.IsNaN(p.X))) { Console.WriteLine("NaN"); } double x0 = newPts.Min(p => p.X); double y0 = newPts.Min(p => p.Y); double x1 = newPts.Max(p => p.X); double y1 = newPts.Max(p => p.Y); double l = Math.Max(x1 - x0, y1 - y0); GeoTransform trans = new GeoTransform() { P = P, X0 = X0, Xmin = new MWPoint2D(x0, y0), Xmax = new MWPoint2D(x1, y1) }; return(newPts.Select(p => new Vertex((p.X - x0) / l, (p.Y - y0) / l)).ToList(), trans ); }
private Mesh3 meshSlab(Shell slab, List <List <MWPoint3D> > walls) { Shell s = slab; double z = s.Points.Min(p => p.Z); List <List <MWPoint3D> > wallSegments = new List <List <MWPoint3D> >(); foreach (var w in walls) { if (Math.Abs(w[0].Z - z) < 1e-5 && Math.Abs(w[1].Z - z) < 1e-5) { wallSegments.Add(w); } } // we reorder the walls according to their center X coordinate then center Y coordinate wallSegments = wallSegments.OrderBy(seg => 0.5 * (seg[0].X + seg[1].X)).ToList(); //wallSegments = wallSegments.OrderBy(seg => 0.5 * (seg[0].Y + seg[1].Y)).ToList(); foreach (var w in wallSegments) { s.IncludedSegments.Add(new List <MWPoint3D>() { new MWPoint3D(w[0].X, w[0].Y, w[0].Z), new MWPoint3D(w[1].X, w[1].Y, w[1].Z) }); } List <MWPoint2D> s2D = s.Points.Select(p => new MWPoint2D(p.X, p.Y)).ToList(); foreach (var b in modelGeo.Beams) { if (Polygons.isInside(s2D, new MWPoint2D(b.Start.X, b.Start.Y))) { if (b.Start.Z == z) { if (!s.IncludedVertices.Contains(b.Start)) { s.IncludedVertices.Add(b.Start); } } else if (b.End.Z == z) { if (!s.IncludedVertices.Contains(b.End)) { s.IncludedVertices.Add(b.End); } } } } // create mesh using Triangle.NET library Polygon pol = new Polygon(); var res = NormalizeShell(s); GeoTransform transform = res.Item2; var holesN = s.Holes.Select(h => ApplyGeoTransform(h, transform)).ToList(); var segN = s.IncludedSegments.Select(seg => ApplyGeoTransform(seg, transform)).ToList(); var cols = ApplyGeoTransform(s.IncludedVertices, transform); pol.Add(new Contour(res.Item1)); // holes are added for (int j = 0; j < s.Holes.Count; j++) { pol.Add(new Contour(holesN[j]), true); } // segments coming from wall meshes are added List <Vertex> addedVertices = new List <Vertex>(); // WARNING : Here are just added the segments with both endpoints new. It might not work every time. // If a problem is encountered, it might be worth adding the points as vertices and not as segments. for (int j = 0; j < segN.Count; j++) { //if (!addedVertices.Contains(new Vertex(segN[j][0].X, segN[j][0].Y)) && !addedVertices.Contains(new Vertex(segN[j][1].X, segN[j][1].Y))) if (!ContainsVertex(addedVertices, segN[j][0]) && !ContainsVertex(addedVertices, segN[j][1])) { pol.Add(new Segment(segN[j][0], segN[j][1]), true); addedVertices.Add(segN[j][0]); addedVertices.Add(segN[j][1]); } //else if (addedVertices.Contains(new Vertex(segN[j][0].X, segN[j][0].Y)) && addedVertices.Contains(new Vertex(segN[j][1].X, segN[j][1].Y))) else if (ContainsVertex(addedVertices, segN[j][0]) && ContainsVertex(addedVertices, segN[j][1])) { //Console.WriteLine("Both endpoints already added..."); } //else if (addedVertices.Contains(new Vertex(segN[j][0].X, segN[j][0].Y))) else if (ContainsVertex(addedVertices, segN[j][0])) { //pol.Add(new Segment(segN[j][0], segN[j][1]), 1); //addedVertices.Add(segN[j][1]); } //else if (addedVertices.Contains(new Vertex(segN[j][1].X, segN[j][1].Y))) else if (ContainsVertex(addedVertices, segN[j][1])) { //pol.Add(new Segment(segN[j][0], segN[j][1]), 0); //addedVertices.Add(segN[j][0]); } } // vertices coming from columns are added cols.ForEach(c => pol.Add(c)); //pol.Add(new Segment(new Vertex(segN[0][0].X, segN[0][0].Y), new Vertex(segN[0][1].X, segN[0][1].Y)), true); //pol.Add(new Segment(new Vertex(segN[2][0].X, segN[2][0].Y), new Vertex(segN[2][1].X, segN[2][1].Y)), true); double maxL = getMaxDim(s); double maxarea = 0.1 / maxL; Configuration config = new Configuration(); QualityOptions qo = new QualityOptions() { MinimumAngle = 15, MaximumArea = maxarea }; //ConstraintOptions co = new ConstraintOptions() //{ // SegmentSplitting = 1 //}; Mesh MyMesh = (new GenericMesher()).Triangulate(pol, qo) as Mesh; List <Point3> meshPts = deNormalizeMesh(MyMesh.Vertices, s, transform); // return(new Mesh3(meshPts, MyMesh.Triangles.Select(t => new Face3(MyMesh.Vertices.ToList().IndexOf(t.GetVertex(0)), MyMesh.Vertices.ToList().IndexOf(t.GetVertex(1)), MyMesh.Vertices.ToList().IndexOf(t.GetVertex(2)))).ToList())); }
private (Mesh3, List <List <MWPoint3D> >) meshWall(Shell wall, List <List <MWPoint3D> > existingPts = null) { // create mesh using Triangle.NET library Shell w = wall.Clone(); // pre addition of points on the contours List <MWPoint3D> refinedPts = new List <MWPoint3D>(); for (int i = 0; i < w.Points.Count; i++) { int k = i == w.Points.Count - 1 ? 0 : i + 1; MWPoint3D p0 = w.Points[i]; MWPoint3D p1 = w.Points[k]; MWVector3D vec = new MWVector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z); vec = vec.Normalised(); double dist = Points.Distance3D(p0, p1); int n = Convert.ToInt32(dist / 0.75) + 1; double inc = dist / n; refinedPts.Add(p0); for (int j = 1; j < n; j++) { MWPoint3D ptAdded = new MWPoint3D(p0.X + j * vec.X * inc, p0.Y + j * vec.Y * inc, p0.Z + j * vec.Z * inc); refinedPts.Add(ptAdded); } } w.Points = refinedPts; if (existingPts != null) { List <MWPoint3D> exPts = existingPts.SelectMany(l => l).ToList(); for (int i = 0; i < exPts.Count; i++) { for (int j = 0; j < w.Points.Count; j++) { int k = j == w.Points.Count - 1 ? 0 : j + 1; if (PointIsOnLine(w.Points[j], w.Points[k], exPts[i])) { w.Points.Insert(k, exPts[i]); j = 0; } } } } Polygon pol = new Polygon(); var res = NormalizeShell(w); var vertices = res.Item1; pol.Add(new Contour(res.Item1)); for (int i = 0; i < vertices.Count; i++) { int k = i == res.Item1.Count - 1 ? 0 : i + 1; if (Math.Sqrt(Math.Pow(vertices[i].X - vertices[k].X, 2) + Math.Pow(vertices[i].Y - vertices[k].Y, 2)) < 0.15) { pol.Add(new Segment(vertices[i], vertices[k]), false); } } GeoTransform transform = res.Item2; double maxL = getMaxDim(w); double maxarea = 0.1 / maxL; Configuration config = new Configuration(); QualityOptions qo = new QualityOptions() { MinimumAngle = 20, MaximumArea = maxarea, }; Mesh MyMesh = (new GenericMesher()).Triangulate(pol, qo) as Mesh; List <Point3> meshPts = deNormalizeMesh(MyMesh.Vertices, wall, transform); // extracting the contour edges for future wall and slab meshing double xmax = MyMesh.Vertices.Max(p => p.X); double xmin = MyMesh.Vertices.Min(p => p.X); double ymax = MyMesh.Vertices.Max(p => p.Y); double ymin = MyMesh.Vertices.Min(p => p.Y); List <List <int> > edgesPtsIdx = MyMesh.Edges.Select(e => new List <int>() { MyMesh.Vertices.ToList().IndexOf(MyMesh.Vertices.Single(p => p.ID == e.P0)), MyMesh.Vertices.ToList().IndexOf(MyMesh.Vertices.Single(p => p.ID == e.P1)) }).ToList(); List <Edge> edges = MyMesh.Edges.ToList(); List <List <MWPoint3D> > TBEdges = new List <List <MWPoint3D> >(); List <Vertex> lv = MyMesh.Vertices.ToList(); for (int i = 0; i < edges.Count; i++) { bool b1 = lv[edgesPtsIdx[i][0]].X == xmin && lv[edgesPtsIdx[i][1]].X == xmin; bool b2 = lv[edgesPtsIdx[i][0]].X == xmax && lv[edgesPtsIdx[i][1]].X == xmax; bool b3 = lv[edgesPtsIdx[i][0]].Y == ymin && lv[edgesPtsIdx[i][1]].Y == ymin; bool b4 = lv[edgesPtsIdx[i][0]].Y == ymax && lv[edgesPtsIdx[i][1]].Y == ymax; if (b1 || b2 || b3 || b4) { TBEdges.Add(new List <MWPoint3D>() { new MWPoint3D(meshPts[edgesPtsIdx[i][0]].X, meshPts[edgesPtsIdx[i][0]].Y, meshPts[edgesPtsIdx[i][0]].Z), new MWPoint3D(meshPts[edgesPtsIdx[i][1]].X, meshPts[edgesPtsIdx[i][1]].Y, meshPts[edgesPtsIdx[i][1]].Z) }); } } return(new Mesh3(meshPts, MyMesh.Triangles.Select(t => new Face3(MyMesh.Vertices.ToList().IndexOf(t.GetVertex(0)), MyMesh.Vertices.ToList().IndexOf(t.GetVertex(1)), MyMesh.Vertices.ToList().IndexOf(t.GetVertex(2)))).ToList()), TBEdges); }
private void button2_Click(object sender, EventArgs e) { //GCP & ICP Collection window formgcp.datatable_back_color = Color.FromName(ımageComboBox8.SelectedItem.ToString()); formgcp.line_select_color = Color.FromName(ımageComboBox9.SelectedItem.ToString()); formgcp.img_select_color = Color.FromName(ımageComboBox11.SelectedItem.ToString()); formgcp.imgbox_backcolor = Color.FromName(ımageComboBox15.SelectedItem.ToString()); formgcp.title_font_name = ımageComboBox7.SelectedItem.ToString(); formgcp.values_font_name = ımageComboBox10.SelectedItem.ToString(); formgcp.title_font_size = (int)numericUpDown7.Value; formgcp.values_font_size = (int)numericUpDown8.Value; formgcp.decimal_points = (int)numericUpDown10.Value; //main windom Form1.select_point_color = Color.FromName(ımageComboBox13.SelectedItem.ToString()); Form1.mouse_icon_color = Color.FromName(ımageComboBox14.SelectedItem.ToString()); //gcp in main windom Form1.gcp_font_name = ımageComboBox1.SelectedItem.ToString(); Form1.gcp_text_size = (float)numericUpDown1.Value; Color clr; clr = Color.FromName(ımageComboBox2.SelectedItem.ToString()); Form1.gcp_text_color = clr; Form1.gcp_line_length = (float)numericUpDown2.Value; Form1.gcp_line_width = (float)numericUpDown3.Value; clr = Color.FromName(ımageComboBox3.SelectedItem.ToString()); Form1.gcp_line_color = clr; Form1.gcp_type_name = checkBox1.Checked; Form1.gcp_id_name = checkBox2.Checked; //icp in main windom Form1.icp_font_name = ımageComboBox4.SelectedItem.ToString(); Form1.icp_text_size = (float)numericUpDown6.Value; clr = Color.FromName(ımageComboBox5.SelectedItem.ToString()); Form1.icp_text_color = clr; Form1.icp_line_length = (float)numericUpDown5.Value; Form1.icp_line_width = (float)numericUpDown4.Value; clr = Color.FromName(ımageComboBox6.SelectedItem.ToString()); Form1.icp_line_color = clr; Form1.icp_type_name = checkBox4.Checked; Form1.icp_id_name = checkBox3.Checked; // view GeoTransform GeoTransform.vektor_back = Color.FromName(ımageComboBox12.SelectedItem.ToString()); GeoTransform.vektor_canves = Color.FromName(ımageComboBox16.SelectedItem.ToString()); GeoTransform.wind_back = Color.FromName(ımageComboBox17.SelectedItem.ToString()); GeoTransform.vektor_color = Color.FromName(ımageComboBox18.SelectedItem.ToString()); GeoTransform.wind_canves = Color.FromName(ımageComboBox19.SelectedItem.ToString()); GeoTransform.wind_color = Color.FromName(ımageComboBox20.SelectedItem.ToString()); GeoTransform.date_back = Color.FromName(ımageComboBox23.SelectedItem.ToString()); GeoTransform.title_font_name = ımageComboBox21.SelectedItem.ToString(); GeoTransform.values_font_name = ımageComboBox24.SelectedItem.ToString(); GeoTransform.title_font_size = (int)numericUpDown11.Value; GeoTransform.values_font_size = (int)numericUpDown9.Value; GeoTransform.decimal_points = (int)numericUpDown12.Value; ////// Form1 f1 = new Form1(); f1.view_save(); formgcp fgcp = new formgcp(); fgcp.view_save(); GeoTransform geo = new GeoTransform(); geo.view_save(); this.Close(); }
/// <inheritdoc/> public Stream GetImageStream(int tileX, int tileY, int zoom) { Rect rect = GeoTransform.TileToPtvMercatorAtZoom(tileX, tileY, zoom); return(GetImageStream(rect.Left, rect.Top, rect.Right, rect.Bottom, 256, 256)); }
private void button2_Click(object sender, EventArgs e) { int i, j; if (Empty_image.active_form == true) { Empty_image empty = Application.OpenForms["Empty_image"] as Empty_image; double[] r = new double[dataGridView1.RowCount]; double[] c = new double[dataGridView1.RowCount]; for (i = 0; i < dataGridView1.RowCount; i++) { r[i] = Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value.ToString()); c[i] = Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value.ToString()); } if (GeoTransform.form_active == false) { Empty_image.emp_Width = Convert.ToInt32(c.Max() + 100); Empty_image.emp_Height = Convert.ToInt32(r.Max() + 100); } else { Empty_image.emp_Width = 1100; Empty_image.emp_Height = 1100; } Visual v = new Visual(); v.open_Image(empty.textBox1.Text, true, true); empty.Close(); } for (i = 0; i < dataGridView1.RowCount; i++) { if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "Control") { Form1.gcp_collected[Form1.Image_ID].Rows.Add("-2"); Form1.gcp_collected[Form1.Image_ID].Rows[Form1.gcp_count][0] = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value); Form1.gcp_collected[Form1.Image_ID].Rows[Form1.gcp_count][1] = dataGridView1.Rows[i].Cells[1].Value; for (j = 2; j < 12; j++) { Form1.gcp_collected[Form1.Image_ID].Rows[Form1.gcp_count][j] = Convert.ToDouble(dataGridView1.Rows[i].Cells[j].Value); } Form1.gcp_count = Form1.gcp_count + 1; } if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "Check") { Form1.icp_collected[Form1.Image_ID].Rows.Add("-2"); Form1.icp_collected[Form1.Image_ID].Rows[Form1.icp_count][0] = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value); Form1.icp_collected[Form1.Image_ID].Rows[Form1.icp_count][1] = dataGridView1.Rows[i].Cells[1].Value; for (j = 2; j < 12; j++) { Form1.icp_collected[Form1.Image_ID].Rows[Form1.icp_count][j] = Convert.ToDouble(dataGridView1.Rows[i].Cells[j].Value); } Form1.icp_count = Form1.icp_count + 1; } } if (GeoTransform.form_active == true) { GeoTransform geo = Application.OpenForms["GeoTransform"] as GeoTransform; geo.scale_control = 1; geo.load_dzyn(); } this.Close(); }