public IActionResult Post(SceneDto scene) { // TODO: input sanitize e.g. // best to accumulate errors and return a not ok with violations if (scene?.LightSource?.Position == null || scene?.LightSource?.Intensity == null) { throw new ArgumentOutOfRangeException(nameof(scene.LightSource)); } if (scene?.Camera?.From == null || scene?.Camera?.To == null || scene?.Camera?.Up == null) { throw new ArgumentOutOfRangeException(nameof(scene.Camera)); } var renderSceneCommand = GetRenderSceneCommand(scene); _taskQueue.QueueBackgroundWorkItem(async token => { if (token.IsCancellationRequested) { return; } await _mediator.Send(renderSceneCommand, token); }); return(Ok(new CreateSceneResponse { CorrelationId = renderSceneCommand.CorrelationId, PollUrl = this.Url.Action(nameof(Get), this.ControllerContext.ActionDescriptor.ControllerName, new { id = renderSceneCommand.CorrelationId }, this.Request.Scheme), Message = "Scene submitted to renderer. When the image is ready, it can be fetched at the 'pollUrl' included. Depending on complexity, images can take quite some time to render." })); }
private RenderSceneCommand GetRenderSceneCommand(SceneDto scene) { var correlationId = Guid.NewGuid(); var fileInfo = GetSceneBitmapFileInfo(correlationId); var command = new RenderSceneCommand { Scene = scene, CorrelationId = correlationId, FilePath = fileInfo.PhysicalPath }; return(command); }
private SceneDto BuildScene(string scenePath) { var scene = new SceneDto(); scene.Id = GetMetadataStringValue(scenePath, "LANDSAT_SCENE_ID"); scene.Name = GetMetadataStringValue(scenePath, "LANDSAT_PRODUCT_ID"); scene.Path = scenePath; scene.Metadata = Directory.GetFiles(scenePath).FirstOrDefault(x => Path.GetFileNameWithoutExtension(x).EndsWith("MTL")); scene.Cloudity = GetMetadataStringValue(scenePath, "CLOUD_COVER"); scene.TimeStamp = DateTime.Parse(GetMetadataStringValue(scenePath, "DATE_ACQUIRED")); //scene.Time = TimeSpan.Parse(GetMetadataStringValue(scenePath, "SCENE_CENTER_TIME")); scene.Image = Path.Combine(scenePath, "preview.jpg"); for (int i = 0; i < _points.Count; i++) { var point = _points[i]; var area = BuildArea(scenePath, i + 1, point.X, point.Y, point.OFFSET); scene.Areas.Add(area); } return(scene); }
public static SceneDto GetSphereCentralWithPlanesExample() { // Templates var defaultSphere = Sphere.CreateDefaultInstance(); var defaultMaterial = Material.CreateDefaultInstance(); var white = Color.White; // Copying ReRenderSphereCentralWithPlanes code using serializable DTOs. // Planes var floor = new ShapeDto { Type = ShapeDto.ShapeType.Plane, Material = new MaterialDto { Color = new ColorDto { A = Material.DefaultColorA, R = 1F, G = 0.9F, B = 0.9F }, Specular = 0F, Ambient = defaultMaterial.Ambient, Diffuse = defaultMaterial.Diffuse, Shininess = defaultMaterial.Shininess } }; var left_wall = new ShapeDto { Type = ShapeDto.ShapeType.Plane, Material = floor.Material, Transformations = new List <TransformDto> { new TransformDto { TransformType = TransformDto.TransformationType.RotateX, RotationRadians = MathF.PI / 2 }, new TransformDto { TransformType = TransformDto.TransformationType.RotateY, RotationRadians = -MathF.PI / 4 }, new TransformDto { TransformType = TransformDto.TransformationType.Translate, VectorTransformation = new VectorDto { X = 0F, Y = 0F, Z = 5F } } } }; var right_wall = new ShapeDto { Type = ShapeDto.ShapeType.Plane, Material = floor.Material, Transformations = new List <TransformDto> { new TransformDto { TransformType = TransformDto.TransformationType.RotateX, RotationRadians = MathF.PI / 2 }, new TransformDto { TransformType = TransformDto.TransformationType.RotateY, RotationRadians = MathF.PI / 4 }, new TransformDto { TransformType = TransformDto.TransformationType.Translate, VectorTransformation = new VectorDto { X = 0F, Y = 0F, Z = 5F } } } }; // Spheres var middle = new ShapeDto { Type = ShapeDto.ShapeType.Sphere, Material = new MaterialDto { Color = new ColorDto { A = Material.DefaultColorA, R = 0.1F, G = 1F, B = 0.5F }, Diffuse = 0.7F, Specular = 0.3F, Ambient = defaultMaterial.Ambient, Shininess = defaultMaterial.Shininess }, Transformations = new List <TransformDto> { new TransformDto { TransformType = TransformDto.TransformationType.Translate, VectorTransformation = new VectorDto { X = -0.5F, Y = 1F, Z = 0.5F } } } }; var right = new ShapeDto { Type = ShapeDto.ShapeType.Sphere, Material = new MaterialDto { Color = new ColorDto { A = Material.DefaultColorA, R = 0.5F, G = 1F, B = 0.1F }, Diffuse = 0.7F, Specular = 0.3F, Ambient = defaultMaterial.Ambient, Shininess = defaultMaterial.Shininess }, Transformations = new List <TransformDto> { new TransformDto { TransformType = TransformDto.TransformationType.Scale, VectorTransformation = new VectorDto { X = 0.5F, Y = 0.5F, Z = 0.5F } }, new TransformDto { TransformType = TransformDto.TransformationType.Translate, VectorTransformation = new VectorDto { X = 1.5F, Y = 0.5F, Z = -0.5F } } } }; var left = new ShapeDto { Type = ShapeDto.ShapeType.Sphere, Material = new MaterialDto { Color = new ColorDto { A = Material.DefaultColorA, R = 1F, G = 0.8F, B = 0.1F }, Diffuse = 0.7F, Specular = 0.3F, Ambient = defaultMaterial.Ambient, Shininess = defaultMaterial.Shininess }, Transformations = new List <TransformDto> { new TransformDto { TransformType = TransformDto.TransformationType.Scale, VectorTransformation = new VectorDto { X = 0.33F, Y = 0.33F, Z = 0.33F } }, new TransformDto { TransformType = TransformDto.TransformationType.Translate, VectorTransformation = new VectorDto { X = -1.5F, Y = 0.33F, Z = -0.75F } } } }; // Scene - pull together shapes into root serializable object // Use low res until happy, then crank up. Takes a lot of clock cycles! #pragma warning disable CS0219 // Variable is assigned but its value is never used int high = 1000; int medium = 500; int low = 250; int res = medium; #pragma warning restore CS0219 // Variable is assigned but its value is never used var scene = new SceneDto { Shapes = new List <ShapeDto> { floor, left_wall, right_wall, left, middle, right }, LightSource = new LightDto { Position = new VectorDto { X = -10F, Y = 10F, Z = -10F }, Intensity = new ColorDto { A = white.ScA, R = white.ScR, G = white.ScG, B = white.ScB } }, Camera = new CameraDto { HSize = res, VSize = res / 2, FieldOfView = MathF.PI / 3, From = new VectorDto { X = 0F, Y = 1.5F, Z = -5F }, To = new VectorDto { X = 0F, Y = 1F, Z = 0F }, Up = new VectorDto { X = 0F, Y = 1F, Z = 0F } } }; return(scene); }