예제 #1
0
        protected override async Task _init()
        {
            RecordSet layer = _layer as RecordSet;

            symbology = layer.Properties.Units;
            Datasource ds = await Datasource.LoadAsync(layer.Source);

            features = new List <DMesh3>();
            for (int i = 0; i < ds.meshes.Length; i++)
            {
                DMesh3 mesh = await ds.GetMeshAsync(i);

                mesh.RemoveMetadata("properties");
                mesh.AttachMetadata("properties", new Dictionary <string, object> {
                    { "Name", ds.meshes[i] }
                });
                if (layer.ContainsKey("Crs") && layer.Crs != null)
                {
                    mesh.RemoveMetadata("CRS");
                    mesh.AttachMetadata("CRS", layer.Crs);
                }
                ;
                features.Add(mesh);
            }
            return;
        }
예제 #2
0
        /// <summary>
        /// Craate a new compact DMesh3 with all of the ViRGiS metadata copied across
        /// </summary>
        /// <param name="dMesh">Source DMesh3</param>
        /// <returns>DMesh3</returns>
        public static DMesh3 Compactify(this DMesh3 dMesh)
        {
            DMesh3 mesh = new DMesh3(dMesh);

            //mesh.CompactCopy(dMesh);

            if (dMesh.HasMetadata)
            {
                string crs = dMesh.FindMetadata("CRS") as string;
                if (crs != null)
                {
                    mesh.AttachMetadata("CRS", crs);
                }
            }
            return(mesh);
        }
예제 #3
0
        protected Task <int> Load()
        {
            TaskCompletionSource <int> tcs1 = new TaskCompletionSource <int>();
            Task <int> t1 = tcs1.Task;

            t1.ConfigureAwait(false);

            // Start a background task that will complete tcs1.Task
            Task.Factory.StartNew(() => {
                RecordSet layer      = _layer as RecordSet;
                string ex            = Path.GetExtension(layer.Source).ToLower();
                string sourcetype    = null;
                Datasource ds        = null;
                string proj          = null;
                double scalingFactor = 0;
                string headerString;
                features = new List <DMesh3>();

                // Determine the DAL to be used to load the data.
                // GDAL data is loaded throu PDAL to get a mesh - but the pipeline is radically different
                //
                if (".2dm .nc .dat .adf .out .grb .hdf .slf .sww .xdmf .xmdf .tin".Contains(ex))
                {
                    sourcetype = "mdal";
                }
                else if (".bpf .json .e57 .mat .txt .las .nitf .npy .csd .pcd .ply .pts .qi .rxp .rdbx .sbet .slpk .bin .xyz ".Contains(ex) || new Regex(@"\.m\d\d").IsMatch(ex))
                {
                    sourcetype = "pdal";
                }
                else
                {
                    sourcetype = "gdal";
                }

                //Loading through PDAL
                if (sourcetype != "mdal")
                {
                    List <object> pipe = new List <object>();

                    // Set up the pipline for GDAL data
                    // Get the metadata thjrough GDAL first
                    if (sourcetype == "gdal")
                    {
                        Dataset raster = Gdal.Open(layer.Source, Access.GA_ReadOnly);
                        int numBands   = raster.RasterCount;
                        if (numBands <= 0)
                        {
                            throw new NotSupportedException($" No Data in file {layer.Source}");
                        }
                        proj = raster.GetProjection();

                        //Make the header string from the number of bands - assume band-1 is elevation
                        headerString = "Z";
                        for (int i = 1; i < numBands; i++)
                        {
                            headerString += $",M{i}";
                        }

                        pipe.Add(new {
                            type     = "readers.gdal",
                            filename = layer.Source,
                            header   = headerString
                        });

                        //get the null value and filter out null data
                        Band band1 = raster.GetRasterBand(1);
                        double noDataValue;
                        int hasval;
                        band1.GetNoDataValue(out noDataValue, out hasval);
                        if (hasval == 1)
                        {
                            if (noDataValue < 0)
                            {
                                pipe.Add(new {
                                    type   = "filters.range",
                                    limits = $"Z[{noDataValue + 1}:]"
                                });
                            }
                            else
                            {
                                pipe.Add(new {
                                    type   = "filters.range",
                                    limits = $"Z[:{noDataValue - 1}]"
                                });
                            }
                        }

                        // Get the size and pixel size of the raster
                        // if the raster has more than 40,000 data points, using poisson sampling to down size
                        long datapoints = raster.RasterXSize * raster.RasterYSize;
                        if (datapoints > 40000)
                        {
                            try {
                                double[] geoTransform = new double[6];
                                raster.GetGeoTransform(geoTransform);
                                if (geoTransform == null && geoTransform[1] == 0)
                                {
                                    throw new Exception();
                                }
                                scalingFactor = Math.Sqrt(datapoints / 40000d * geoTransform[1]);
                            } catch {
                                scalingFactor = Math.Sqrt(datapoints / 40000d);
                            };

                            pipe.Add(new {
                                type   = "filters.sample",
                                radius = scalingFactor
                            });
                        }
                        band1.FlushCache();
                        band1.Dispose();
                        raster.FlushCache();
                        raster.Dispose();
                        // special treatment for .xyz files that are not handled well by the defaults
                    }
                    else if (ex == ".xyz")
                    {
                        pipe.Add(new {
                            type     = "readers.text",
                            filename = layer.Source,
                        });
                    }

                    // for PDAL data - use the default reader
                    else
                    {
                        pipe.Add(layer.Source);
                    }

                    // if there is a filter definituion in the RecordSet, add that
                    if (layer.Properties.Filter != null)
                    {
                        foreach (Dictionary <string, object> item in layer.Properties.Filter)
                        {
                            pipe.Add(item);
                        }
                    }

                    // if there is a Color Interpolation definition in the RecordSet, add that
                    if (layer.Properties.ColorInterp != null)
                    {
                        Dictionary <string, object> ci = new Dictionary <string, object>(layer.Properties.ColorInterp);
                        ci.Add("type", "filters.colorinterp");
                        ci["dimension"] = "Z";
                        pipe.Add(ci);
                    }

                    // create a Mesh using Delaunay traingulation
                    pipe.Add(new {
                        type = "filters.delaunay"
                    });

                    // serialize the pipeline to json
                    string json = JsonConvert.SerializeObject(new {
                        pipeline = pipe.ToArray()
                    });

                    Debug.Log(json);

                    // create and run the piplene
                    Pipeline pipeline = new Pipeline(json);
                    long pointCount   = pipeline.Execute();
                    using (PointViewIterator views = pipeline.Views) {
                        views.Reset();
                        while (views.HasNext())
                        {
                            PointView view = views.Next;
                            if (view != null)
                            {
                                DMesh3 mesh = view.getMesh();
                                mesh.RemoveMetadata("properties");
                                // set the CRS based on what is known
                                if (proj != null)
                                {
                                    mesh.RemoveMetadata("CRS");
                                    mesh.AttachMetadata("CRS", proj);
                                }
                                if (layer.ContainsKey("Crs") && layer.Crs != null)
                                {
                                    mesh.RemoveMetadata("CRS");
                                    mesh.AttachMetadata("CRS", layer.Crs);
                                }
                                ;
                                features.Add(mesh);
                            }
                        }
                    }
                    pipeline.Dispose();
                }
                else
                {
                    // for MDAL files - load the mesh directly
                    ds = Datasource.Load(layer.Source);

                    for (int i = 0; i < ds.meshes.Length; i++)
                    {
                        DMesh3 mesh = ds.GetMesh(i);
                        mesh.RemoveMetadata("properties");
                        mesh.AttachMetadata("properties", new Dictionary <string, object> {
                            { "Name", ds.meshes[i] }
                        });
                        // set the CRS based on what is known
                        if (proj != null)
                        {
                            mesh.RemoveMetadata("CRS");
                            mesh.AttachMetadata("CRS", proj);
                        }
                        if (layer.ContainsKey("Crs") && layer.Crs != null)
                        {
                            mesh.RemoveMetadata("CRS");
                            mesh.AttachMetadata("CRS", layer.Crs);
                        }
                        ;
                        features.Add(mesh);
                    }
                }
                tcs1.SetResult(1);
            });
            return(t1);
        }
예제 #4
0
        protected virtual void compute_shell_extrude()
        {
            DMesh3 mesh = new DMesh3(MeshSource.GetDMeshUnsafe());

            MeshNormals.QuickCompute(mesh);

            if (shell_direction == ShellDirections.Symmetric)
            {
                double thickness = shell_thickness * 0.5;

                DMesh3          outerMesh    = new DMesh3(mesh);
                MeshExtrudeMesh outerExtrude = new MeshExtrudeMesh(outerMesh);
                outerExtrude.ExtrudedPositionF = (v, n, vid) => {
                    return(v + thickness * (Vector3d)n);
                };
                if (outerExtrude.Extrude() == false)
                {
                    throw new Exception("MeshShellOp.compute_shell_extrude: outer Extrude() returned false!");
                }
                MeshEditor.RemoveTriangles(outerMesh, outerExtrude.InitialTriangles);

                MeshExtrudeMesh innerExtrude = new MeshExtrudeMesh(mesh);
                innerExtrude.IsPositiveOffset  = false;
                innerExtrude.ExtrudedPositionF = (v, n, vid) => {
                    return(v - thickness * (Vector3d)n);
                };
                if (innerExtrude.Extrude() == false)
                {
                    throw new Exception("MeshShellOp.compute_shell_extrude: inner Extrude() returned false!");
                }
                MeshEditor.RemoveTriangles(mesh, innerExtrude.InitialTriangles);

                MeshEditor.Append(mesh, outerMesh);

                if (cached_is_closed == false)
                {
                    // cheating!
                    MergeCoincidentEdges merge = new MergeCoincidentEdges(mesh);
                    merge.Apply();
                }
            }
            else
            {
                double thickness = (shell_direction == ShellDirections.Outer) ?
                                   shell_thickness : -shell_thickness;

                MeshExtrudeMesh extrude = new MeshExtrudeMesh(mesh);
                extrude.IsPositiveOffset = (shell_direction == ShellDirections.Outer);

                extrude.ExtrudedPositionF = (v, n, vid) => {
                    return(v + thickness * (Vector3d)n);
                };

                if (extrude.Extrude() == false)
                {
                    throw new Exception("MeshShellOp.compute_shell_extrude: Extrude() returned false!");
                }

                if (shell_surface_only && cached_is_closed)
                {
                    MeshEditor.RemoveTriangles(mesh, extrude.InitialTriangles);
                    if (shell_direction == ShellDirections.Inner)
                    {
                        mesh.ReverseOrientation();
                    }
                    if (shell_direction == ShellDirections.Inner || shell_direction == ShellDirections.Outer)
                    {
                        mesh.AttachMetadata("is_partial", new object());
                    }
                }
            }

            if (is_invalidated())
            {
                return;
            }

            ResultMesh = mesh;
        }
예제 #5
0
 public static void TagAsFailureMesh(DMesh3 mesh)
 {
     mesh.AttachMetadata("DMESHOP_FAILURE_MESH", new object());
 }
예제 #6
0
        protected VirgisFeature _drawFeature(Geometry tin, Feature feature = null)
        {
            //Create the GameObjects
            GameObject dataTIN = Instantiate(MeshPrefab, transform);

            EditableMesh mesh = dataTIN.GetComponent <EditableMesh>();

            if (feature != null)
            {
                mesh.feature = feature;
            }

            List <Geometry> trigeos  = new List <Geometry>();
            List <Vector3d> trivects = new List <Vector3d>();
            List <int>      tris     = new List <int>();

            for (int i = 0; i < tin.GetGeometryCount(); i++)
            {
                trigeos.Add(tin.GetGeometryRef(i));
            }

            HashSet <Vector3d> vertexhash = new HashSet <Vector3d>();

            for (int i = 0; i < trigeos.Count; i++)
            {
                Geometry tri        = trigeos[i];
                Geometry linearring = tri.GetGeometryRef(0);
                for (int j = 0; j < 3; j++)
                {
                    double[] argout = new double[3];
                    linearring.GetPoint(j, argout);
                    Vector3d vertex = new Vector3d(argout);
                    vertexhash.Add(vertex);
                    trivects.Add(vertex);
                }
                tri.Dispose();
                linearring.Dispose();
            }

            List <Vector3d> vertexes = vertexhash.ToList();

            foreach (Vector3d vertex in trivects)
            {
                tris.Add(vertexes.IndexOf(vertex));
            }

            DMesh3 dmesh = DMesh3Builder.Build <Vector3d, int, int>(vertexes, tris);
            string crs;

            tin.GetSpatialReference().ExportToWkt(out crs, null);
            dmesh.AttachMetadata("CRS", crs);

            mesh.Draw(dmesh, bodyMain, WireframeMaterial, true);

            //if (symbology.ContainsKey("body") && symbology["body"].ContainsKey("Label") && symbology["body"].Label != null && (feature?.ContainsKey(symbology["body"].Label) ?? false)) {
            //    //Set the label
            //    GameObject labelObject = Instantiate(LabelPrefab, dataPoly.transform, false);
            //    labelObject.transform.Translate(dataPoly.transform.TransformVector(Vector3.up) * symbology["point"].Transform.Scale.magnitude, Space.Self);
            //    Text labelText = labelObject.GetComponentInChildren<Text>();
            //    labelText.text = (string) feature.Get(symbology["body"].Label);
            //}

            return(mesh);
        }