Beispiel #1
0
 public double DistanceFrom(Coordinate3D otherPoint)
 {
     var distanceX = System.Math.Pow(X - otherPoint.X, 2);
     var distanceY = System.Math.Pow(Y - otherPoint.Y, 2);
     var distanceZ = System.Math.Pow(Z - otherPoint.Z, 2);
     return System.Math.Sqrt(distanceX + distanceY + distanceZ);
 }
Beispiel #2
0
        private static IEnumerable<Face> GenerateFaces(Coordinate3D frontBottomLeft, int width, int height, int depth)
        {
            //create corners
            Coordinate3D frontBottomRight = new Coordinate3D(frontBottomLeft.X + width, frontBottomLeft.Y, frontBottomLeft.Z);
            Coordinate3D frontTopLeft = new Coordinate3D(frontBottomLeft.X, frontBottomLeft.Y+height, frontBottomLeft.Z);
            Coordinate3D frontTopRight = new Coordinate3D(frontBottomLeft.X + width, frontBottomLeft.Y + height, frontBottomLeft.Z);

            Coordinate3D backBottomLeft = new Coordinate3D(frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z + depth);
            Coordinate3D backBottomRight = new Coordinate3D(frontBottomLeft.X + width, frontBottomLeft.Y, frontBottomLeft.Z+depth);
            Coordinate3D backTopLeft = new Coordinate3D(frontBottomLeft.X, frontBottomLeft.Y + height, frontBottomLeft.Z+depth);
            Coordinate3D backTopRight = new Coordinate3D(frontBottomLeft.X + width, frontBottomLeft.Y + height, frontBottomLeft.Z+depth);

            List<Face> faces = new List<Face>();

            //faces are drawn in the order specified, therefore they should be drawn back to front but then maybe top down,
            //however if the view point changes then the order of rendering needs to change? how do we cope with this?

            //back
            faces.Add(new Face(new Coordinate3D[] { backBottomLeft, backBottomRight, backTopRight, backTopLeft }) { Brush = Brushes.Beige });
            //right
            faces.Add(new Face(new Coordinate3D[] { frontBottomLeft, frontTopLeft, backTopLeft, backBottomLeft }) { Brush = Brushes.Orange });

            //base
            faces.Add(new Face(new Coordinate3D[] { frontBottomLeft, frontBottomRight, backBottomRight, backBottomLeft }) { Brush = Brushes.Blue });
            //top
            faces.Add(new Face(new Coordinate3D[] { frontTopLeft, frontTopRight, backTopRight, backTopLeft }) { Brush = Brushes.DarkGreen });
            //left
            faces.Add(new Face(new Coordinate3D[] { frontBottomRight, frontTopRight, backTopRight, backBottomRight }) { Brush = Brushes.Bisque });
            //front
            faces.Add(new Face(new Coordinate3D[] { frontBottomLeft, frontBottomRight, frontTopRight, frontTopLeft }) { Brush = Brushes.Azure });

            return faces;
        }
Beispiel #3
0
        public IEnumerable<CodeStadt.Draw.Shapes.IShape> CreateCity(CodeStadt.Core.DrivenMetrics.Reporting.ResultOutput output)
        {
            int preX = 10,preZ = 10;
            List<IShape> shapes = new List<IShape>();

            Random rand = new Random();

            for (int i = 0; i < _numCubeDeep; i++)
            {
                int z = rand.Next(preZ, preZ + _maxDepth/2);
                preX = 10;
                for (int j = 0; j < _numCubeWide; j++)
                {
                    int x = rand.Next(preX, preX + _maxWidth);

                    int width = rand.Next(_minWidth, _maxWidth);
                    int height = rand.Next(_minHeight, _maxHeight);
                    int depth = rand.Next(_minDepth, _maxDepth);

                    Coordinate3D bottomLeft = new Coordinate3D(200, 0, 20);
                    Cube cube = new Cube(bottomLeft, 500, 500, 500);
                    shapes.Add(cube);

                    preX = x+_maxWidth;

                }

                preZ = z+_maxDepth*2;
            }

            return shapes;
        }
Beispiel #4
0
        public Cube(Coordinate3D frontBottomLeft, int width, int height, int depth)
        {
            FrontBottomLeft = frontBottomLeft;
            Width = width;
            Height = height;
            Depth = depth;

            Faces = GenerateFaces(FrontBottomLeft, width, height, depth);
        }
Beispiel #5
0
        protected override void OnClick()
        {
            //Selected voxel layer
            var voxelLayer = MapView.Active.GetSelectedLayers().OfType <VoxelLayer>().FirstOrDefault();

            if (voxelLayer == null)
            {
                voxelLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <VoxelLayer>().FirstOrDefault();
                if (voxelLayer == null)
                {
                    return;
                }
            }

            QueuedTask.Run(() =>
            {
                if (voxelLayer.Visualization != VoxelVisualization.Surface)
                {
                    voxelLayer.SetVisualization(VoxelVisualization.Surface);
                }
                voxelLayer.SetSectionContainerExpanded(true);
                voxelLayer.SetSectionContainerVisibility(true);

                //delete all sections
                foreach (var section in voxelLayer.GetSections())
                {
                    voxelLayer.DeleteSection(section);
                }

                var volume       = voxelLayer.GetVolumeSize();
                var voxel_pos    = new Coordinate3D(0, 0, volume.Item3);
                var voxel_pos_ur = new Coordinate3D(volume.Item1, volume.Item2, volume.Item3);

                //Make the diagonal in voxel space we will be using
                var lineBuilder = new LineBuilder(voxel_pos, voxel_pos_ur, null);
                var diagonal    = PolylineBuilder.CreatePolyline(lineBuilder.ToSegment());

                var num_sections = 12;
                var spacing      = 1 / (double)num_sections;

                //change as needed
                var orientation = 20.0;
                var tilt        = -15.0;
                var normal      = voxelLayer.GetNormal(orientation, tilt);

                for (int s = 0; s < num_sections; s++)
                {
                    Coordinate2D end_pt = new Coordinate2D(0, 0);
                    if (s > 0)
                    {
                        //position each section along the diagonal
                        var segments = new List <Segment>() as ICollection <Segment>;
                        var part     = GeometryEngine.Instance.GetSubCurve3D(
                            diagonal, 0.0, s * spacing, AsRatioOrLength.AsRatio);
                        part.GetAllSegments(ref segments);
                        end_pt = segments.First().EndCoordinate;
                    }

                    voxelLayer.CreateSection(new SectionDefinition()
                    {
                        Name          = $"Diagonal {s + 1}",
                        VoxelPosition = new Coordinate3D(end_pt.X, end_pt.Y, volume.Item3),
                        Normal        = normal,
                        IsVisible     = true
                    });
                }
            });
        }
Beispiel #6
0
 internal static Coordinate3D DebugCoord(int idx, Coordinate3D coord)
 {
     // System.Diagnostics.Debug.WriteLine($@"Pnt: {idx} {coord.X} {coord.Y} {coord.Z} ");
     return(coord);
 }
Beispiel #7
0
        public void RotateRight_ShouldRotateCoordinateToTheRight(Coordinate3D center, Coordinate3D position,
                                                                 Coordinate3D expectedRotation)
        {
            var rotation = Coordinate3D.RotateRight(center, position);

            Assert.That(rotation, Is.EqualTo(expectedRotation));
        }
Beispiel #8
0
        public void ToString_ShouldSerializeToString()
        {
            var coordinate3D = new Coordinate3D(1, -2, 1);

            Assert.That(coordinate3D.ToString(), Is.EqualTo("(1, -2, 1)"));
        }
Beispiel #9
0
		/// <summary>
		/// Implementation of reading a csv which is specific to the way this sample
		/// is implemented. Your mileage may vary. Change to suit your purposes as
		/// needed.
		/// </summary>
		private void Open()
		{
			var lstDoubleFields = new List<int>();
			var lstLongFields = new List<int>();
			var lstDateFields = new List<int>();
			//Read in the CSV
			TextFieldParser parser = new TextFieldParser(_path);
			parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
			parser.SetDelimiters(",");
			parser.HasFieldsEnclosedInQuotes = true;

			//Initialize our data table
			_table = new DataTable();
			//dataTable.PrimaryKey = new DataColumn("OBJECTID", typeof(long));
			var oid = new DataColumn("OBJECTID", typeof(Int32))
			{
				AutoIncrement = true,
				AutoIncrementSeed = 1
			};
			_table.Columns.Add(oid);
			_table.PrimaryKey = new DataColumn[] { oid };

			//First line must be the column headings
			var fieldIdx = 0;
			foreach (var field in parser.ReadFields())
			{
				var field_name = field.Replace(' ', '_').ToUpper();
				if (field_name.Length == 1 || field_name.StartsWith("POINT_"))
				{
					// field name is X or Y
					_table.Columns.Add(new DataColumn(field_name, typeof(double)));
					lstDoubleFields.Add(fieldIdx);
				}
				else if (field_name.StartsWith ("LONG_"))
				{
					_table.Columns.Add(new DataColumn(field_name, typeof(long)));
					lstLongFields.Add(fieldIdx);
				}
				else if (field_name.StartsWith ("DATE_"))
				{
					_table.Columns.Add(new DataColumn(field_name, typeof(DateTime)));
					lstDateFields.Add(fieldIdx);
				}
				else _table.Columns.Add(new DataColumn(field_name, typeof(string)));
				fieldIdx++;
			}

			//For spatial data...
			//Domain to verify coordinates (2D)
			var sr_extent = new RBush.Envelope(
				minX: _sr.Domain.XMin,
				minY: _sr.Domain.YMin,
				maxX: _sr.Domain.XMax,
				maxY: _sr.Domain.YMax
			);

			//default to the Spatial Reference domain
			_extent = sr_extent;

			bool hasSpatialData = false;
			bool haveDeterminedSpatialData = false;

			//The first two fields are assumed to be the X and Y coordinates of a point
			//otherwise the file is treated as a table and not a feature class
			//The third field (if there is one) is checked for Z.
			while (!parser.EndOfData)
			{
				var values = parser.ReadFields();

				if (!haveDeterminedSpatialData)
				{
					if (values.Count() >= 2)
					{
						double test = 0;
						if (Double.TryParse(values[0], out test))
						{
							hasSpatialData = Double.TryParse(values[1], out test);
							if (hasSpatialData)
							{
								//add a shape column
								_table.Columns.Add(new DataColumn("SHAPE", typeof(System.Byte[])));
								//do we have a Z?
								double z = 0;
								_hasZ = false;
								if (values.Count() >= 3)
								{
									_hasZ = Double.TryParse(values[2], out z);
								}
							}
						}
					}
					haveDeterminedSpatialData = true;
				}

				//load the datatable
				var row = _table.NewRow();
				for (int c = 0; c < values.Length; c++)
				{
					//TODO Deal with nulls!!
					// check double types 
					if (lstDoubleFields.Contains(c))
					{
						row[c + 1] = System.DBNull.Value;
						// field value is double
						if (Double.TryParse(values[c], out double dValue))
						{
							row[c + 1] = dValue;//Column "0" is our objectid
						}
					}
					else if (lstLongFields.Contains(c))
					{
						row[c + 1] = System.DBNull.Value;
						// field value is long
						if (int.TryParse(values[c], out int iValue))
						{
							row[c + 1] = iValue;//Column "0" is our objectid
						}
					}
					else if (lstDateFields.Contains(c))
					{
						row[c + 1] = System.DBNull.Value;
						// field value is datetime
						if (DateTime.TryParse(values[c], out DateTime dateValue))
						{
							row[c + 1] = dateValue;//Column "0" is our objectid
						}
					}
					else
					{
						row[c + 1] = values[c] ?? "";//Column "0" is our objectid
					}
				}

				if (hasSpatialData)
				{
					double x = 0, y = 0, z = 0;
					//TODO Deal with nulls!
					Double.TryParse(values[0], out x);
					Double.TryParse(values[1], out y);

					//do we have a Z?
					if (_hasZ)
					{
						//TODO Deal with nulls!
						Double.TryParse(values[2], out z);
					}

					//ensure the coordinate is within bounds
					var coord = new Coordinate3D(x, y, z);
					if (!sr_extent.Contains2D(coord))
						throw new ArcGIS.Core.Data.GeodatabaseFeatureException(
							"The feature falls outside the defined spatial reference");

					//store it
					row["SHAPE"] = coord.ToMapPoint().ToEsriShape();

					//add it to the index
					var rbushCoord = new RBushCoord3D(coord, (int)row["OBJECTID"]);
					_rtree.Insert(rbushCoord);

					//update max and min for use in the extent
					if (_rtree.Count == 1)
					{
						//first record
						_extent = rbushCoord.Envelope;
					}
					else
					{
						_extent = rbushCoord.Envelope.Union2D(_extent);
					}
				}
				_table.Rows.Add(row);
			}
		}
Beispiel #10
0
 // Reflect <point> in the YZ plane
 public static void ReflectYZ(Coordinate3D point)
 {
     point.X = -point.X;
 }
Beispiel #11
0
 // Reflect <point> in the XZ plane
 public static void ReflectXZ(Coordinate3D point)
 {
     point.Y = -point.Y;
 }
Beispiel #12
0
 // Reflect <point> in the XY plane
 public static void ReflectXY(Coordinate3D point)
 {
     point.Z = -point.Z;
 }
        public static Tuple <List <ICoordinate>, List <bool> > RandomizeCoordinatesAndSave(int numcoords, ConfigParams Config, bool save = true)
        {
            List <ICoordinate> coordinates = new List <ICoordinate>();
            List <bool>        labels      = new List <bool>();
            bool instance_created          = false;

            while (!instance_created)
            {
                if ((Config.ActionList & Actions.Instance_Uniform) != 0)
                {
                    for (var i = 0; i < numcoords; i++)
                    {
                        if (StaticConfigParams.RandomInstanceType == typeof(Coordinate))
                        {
                            coordinates.Add(Coordinate.MakeRandom());
                        }
                        else if (StaticConfigParams.RandomInstanceType == typeof(Coordinate3D))
                        {
                            coordinates.Add(Coordinate3D.MakeRandom());
                        }
                        labels.Add(StaticConfigParams.rnd.NextDouble() > StaticConfigParams.CONST_NEGATIVELABELRATE);
                    }
                }
                if ((Config.ActionList & Actions.Instance_PlantedSingleEnrichment) != 0)
                {
                    for (var i = 0; i < numcoords; i++)
                    {
                        if (StaticConfigParams.RandomInstanceType == typeof(Coordinate))
                        {
                            coordinates.Add(Coordinate.MakeRandom());
                        }
                        else if (StaticConfigParams.RandomInstanceType == typeof(Coordinate3D))
                        {
                            coordinates.Add(Coordinate3D.MakeRandom());
                        }
                    }
                    ICoordinate pivotCoord = null;
                    if (StaticConfigParams.RandomInstanceType == typeof(Coordinate))
                    {
                        pivotCoord = Coordinate.MakeRandom();
                    }
                    else if (StaticConfigParams.RandomInstanceType == typeof(Coordinate3D))
                    {
                        pivotCoord = Coordinate3D.MakeRandom();
                    }

                    var prPos = (int)Math.Round((1.0 - StaticConfigParams.CONST_NEGATIVELABELRATE) * numcoords);
                    mHGJumper.Initialize(prPos, numcoords - prPos);
                    coordinates = coordinates.OrderBy(t => t.EuclideanDistance(pivotCoord)).ToList();
                    labels      = mHGJumper.SampleSignificantEnrichmentVector(1e-3).ToList();
                    Console.WriteLine($"Instantiated sample with p={mHGJumper.minimumHypergeometric(labels.ToArray()).Item1:e} around pivot {pivotCoord.ToString()}");
                    mHGJumper.optHGT = 0.05;
                }
                instance_created = labels.Any();
            }
            if (save)
            {
                Generics.SaveToCSV(coordinates.Zip(labels, (a, b) => a.ToString() + "," + Convert.ToDouble(b)),
                                   $@"coords_{StaticConfigParams.filenamesuffix}.csv");
            }
            return(new Tuple <List <ICoordinate>, List <bool> >(coordinates, labels));
        }
Beispiel #14
0
 public void CopyFrom(Coordinate3D <T> coordinate)
 {
     X = coordinate.X;
     Y = coordinate.Y;
     Z = coordinate.Z;
 }