Esempio n. 1
0
        public PointCloudTileSourceEnumeratorChunk(PointCloudTile tile, BufferInstance buffer)
        {
            m_tile = tile;

            m_buffer         = buffer;
            m_pointSizeBytes = m_tile.TileSet.TileSource.PointSizeBytes;

            m_dataPtr    = buffer.DataPtr;
            m_dataEndPtr = m_dataPtr + m_tile.StorageSize;
        }
        public PointCloudTileSourceEnumeratorChunk(PointCloudTile tile, BufferInstance buffer)
        {
            m_tile = tile;

            m_buffer = buffer;
            m_pointSizeBytes = m_tile.TileSet.TileSource.PointSizeBytes;

            m_dataPtr = buffer.DataPtr;
            m_dataEndPtr = m_dataPtr + m_tile.StorageSize;
        }
Esempio n. 3
0
        public void LoadTile(PointCloudTile tile, byte[] inputBuffer, int index)
        {
            if (tile == null)
            {
                throw new ArgumentNullException("tile");
            }

            Open();

            tile.ReadTile(m_inputStream, inputBuffer, index);
        }
Esempio n. 4
0
        public int Decompress(PointCloudTile tile, byte[] compressedBuffer, int count, byte[] uncompressedBuffer)
        {
            MemoryStream uncompressedStream = new MemoryStream(uncompressedBuffer);
            MemoryStream compressedStream = new MemoryStream(compressedBuffer, 0, count, false);

            using (SevenZipExtractor extractor = new SevenZipExtractor(compressedStream))
            {
                extractor.ExtractFile(0, uncompressedStream);
            }

            return (int)uncompressedStream.Position;
        }
Esempio n. 5
0
		public int Decompress(PointCloudTile tile, byte[] compressedBuffer, int count, byte[] uncompressedBuffer)
		{
			MemoryStream compressedStream = new MemoryStream(compressedBuffer, 0, count, false);

			int uncompressedBytes = 0;
			using (ZipInputStream zipStream = new ZipInputStream(compressedStream, true))
			{
				zipStream.GetNextEntry();
				uncompressedBytes = zipStream.Read(uncompressedBuffer, 0, uncompressedBuffer.Length);
			}

			return uncompressedBytes;
		}
Esempio n. 6
0
		public int Compress(PointCloudTile tile, byte[] uncompressedBuffer, int count, byte[] compressedBuffer)
		{
			MemorableMemoryStream compressedStream = new MemorableMemoryStream(compressedBuffer);

			using (ZipOutputStream zipStream = new ZipOutputStream(compressedStream, true))
			{
				zipStream.CompressionMethod = Ionic.Zip.CompressionMethod.Deflate;
				zipStream.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;

				zipStream.PutNextEntry("a");
				zipStream.Write(uncompressedBuffer, 0, count);
			}

			return (int)compressedStream.MaxPosition;
		}
Esempio n. 7
0
        public int Compress(PointCloudTile tile, byte[] uncompressedBuffer, int count, byte[] compressedBuffer)
        {
            SevenZipCompressor compressor = new SevenZipCompressor
            {
                CompressionMethod = SevenZip.CompressionMethod.Lzma2,
                CompressionLevel = CompressionLevel.Fast
            };

            MemoryStream uncompressedStream = new MemoryStream(uncompressedBuffer, 0, count, false);

            // custom stream is required because the position is always 32 instead of the end of the stream
            MemorableMemoryStream compressedStream = new MemorableMemoryStream(compressedBuffer);

            compressor.CompressStream(uncompressedStream, compressedStream);

            return (int)compressedStream.MaxPosition;
        }
Esempio n. 8
0
        public bool MoveNext()
        {
            // check for cancel
            if (m_current != null && m_process != null && !m_process.Update(m_current))
            {
                return(false);
            }

            if (m_tileEnumerator.MoveNext())
            {
                PointCloudTile tile = m_tileEnumerator.Current;
                tile.ReadTile(m_stream, m_buffer.Data);

                m_current = new PointCloudTileSourceEnumeratorChunk(tile, m_buffer);

                return(true);
            }
            return(false);
        }
Esempio n. 9
0
        public unsafe void LoadTileGrid(PointCloudTile tile, BufferInstance inputBuffer, Grid <float> grid, Grid <int> quantizedGrid)
        {
            Open();

            var quantizedExtent = tile.QuantizedExtent;

            double cellSizeX = (double)quantizedExtent.RangeX / grid.SizeX;
            double cellSizeY = (double)quantizedExtent.RangeY / grid.SizeY;

#warning Why did I do FillVal it this way?
            //grid.FillVal = -1.0f;
            grid.Reset();
            quantizedGrid.Reset();

            byte *inputBufferPtr = inputBuffer.DataPtr;

            int bytesRead = tile.ReadTile(m_inputStream, inputBuffer.Data);

            byte *pb    = inputBufferPtr;
            byte *pbEnd = inputBufferPtr + tile.StorageSize;
            while (pb < pbEnd)
            {
                var p = (SQuantizedPoint3D *)pb;
                pb += PointSizeBytes;

                var pixelX = (int)(((*p).X - quantizedExtent.MinX) / cellSizeX);
                var pixelY = (int)(((*p).Y - quantizedExtent.MinY) / cellSizeY);

                // max val for now, apparently
                if ((*p).Z > quantizedGrid.Data[pixelY, pixelX])
                {
                    quantizedGrid.Data[pixelY, pixelX] = (*p).Z;
                }
            }

            quantizedGrid.CorrectMaxOverflow();
            quantizedGrid.CopyToUnquantized(grid, Quantization, Extent);
        }
Esempio n. 10
0
        public void LoadTile(PointCloudTile tile, byte[] inputBuffer, int index)
        {
            if (tile == null)
                throw new ArgumentNullException("tile");

            Open();

            tile.ReadTile(m_inputStream, inputBuffer, index);
        }
        public static unsafe System.Windows.Media.Media3D.MeshGeometry3D LoadTilePointMesh(PointCloudTile tile, byte[] inputBuffer, double pointSize, int thinByFactor)
        {
            /*LoadTile(tile, inputBuffer);

            Extent3D distributionExtent = tile.Extent;
            Extent3D centeringExtent = Extent;
            Point3D centerOfMass = CenterOfMass;

            double xShift = -centeringExtent.MidpointX;
            double yShift = -centeringExtent.MidpointY;
            double zShift = -centerOfMass.Z;

            double halfPointSize = pointSize / 2;

            int thinnedTilePointCount = tile.PointCount / thinByFactor;

            // these values need to be changed from 4,6 to 8,36 if I test it out
            System.Windows.Media.Media3D.Point3DCollection positions = new System.Windows.Media.Media3D.Point3DCollection(thinnedTilePointCount * 4);
            System.Windows.Media.Media3D.Vector3DCollection normals = new System.Windows.Media.Media3D.Vector3DCollection(positions.Count);
            System.Windows.Media.Int32Collection indices = new System.Windows.Media.Int32Collection(tile.PointCount * 6);

            fixed (byte* inputBufferPtr = inputBuffer)
            {
                UQuantizedPoint3D* p = (UQuantizedPoint3D*)inputBufferPtr;

                for (int i = 0; i < tile.PointCount; i++)
                {
                    if (!(i % thinByFactor == 0))
                        continue;

                    // slow!
                    Point3D point = Quantization.Convert(p[i]);
                    double xC = point.X + xShift;
                    double yC = point.Y + yShift;
                    double zC = point.Z + zShift;

                    int currentStartIndex = positions.Count;

                    foreach (double y in new double[] { yC - halfPointSize, yC + halfPointSize })
                    {
                        foreach (double x in new double[] { xC - halfPointSize, xC + halfPointSize })
                        {
                            positions.Add(new System.Windows.Media.Media3D.Point3D(x, y, zC));
                            normals.Add(new System.Windows.Media.Media3D.Vector3D(0, 0, 1));
                        }
                    }

                    indices.Add(currentStartIndex + 0);
                    indices.Add(currentStartIndex + 1);
                    indices.Add(currentStartIndex + 3);

                    indices.Add(currentStartIndex + 0);
                    indices.Add(currentStartIndex + 3);
                    indices.Add(currentStartIndex + 2);
                }
            }

            System.Windows.Media.Media3D.MeshGeometry3D geometry = new System.Windows.Media.Media3D.MeshGeometry3D();
            geometry.Positions = positions;
            geometry.TriangleIndices = indices;
            geometry.Normals = normals;

            return geometry;*/

            return null;
        }
        public static unsafe System.Windows.Media.Media3D.MeshGeometry3D LoadTileMeshDelaunayIncremental(PointCloudTile tile, byte[] inputBuffer)
        {
            //Open();

            //Extent3D extent = tile.Extent;

            //DelaunayPoint[] pointsToTriangulate = new DelaunayPoint[tile.PointCount];

            //fixed (byte* inputBufferPtr = inputBuffer)
            //{
            //    UQuantizedPoint3D* p = (UQuantizedPoint3D*)inputBufferPtr;

            //    int bytesRead = tile.ReadTile(m_inputStream, inputBuffer);

            //    for (int i = 0; i < tile.PointCount; i++)
            //    {
            //        Point3D point = Quantization.Convert(p[i]);

            //        pointsToTriangulate[i] = new DelaunayPoint(
            //            (float)point.X,
            //            (float)point.Y,
            //            (float)point.Z,
            //            i);
            //    }
            //}

            //Delaunay2DIncremental triangulator = new Delaunay2DIncremental();
            //triangulator.Initialize(extent, pointsToTriangulate.Length);

            //foreach (DelaunayPoint point in pointsToTriangulate)
            //{
            //    if (triangulator.Locate(point))
            //        triangulator.UpdateTriangle(point);
            //}

            //List<int> mesh = triangulator.FlushTriangles();

            //System.Windows.Media.Media3D.Point3DCollection points = new System.Windows.Media.Media3D.Point3DCollection(pointsToTriangulate.Length);
            //for (int i = 0; i < pointsToTriangulate.Length; i++)
            //    points.Add(new System.Windows.Media.Media3D.Point3D(
            //        pointsToTriangulate[i].X - Extent.MidpointX,
            //        pointsToTriangulate[i].Y - Extent.MidpointY,
            //        pointsToTriangulate[i].Z - Extent.MidpointZ));

            //System.Windows.Media.Int32Collection triangles = new System.Windows.Media.Int32Collection(mesh.Reverse<int>());

            //System.Windows.Media.Media3D.MeshGeometry3D meshGeometry = new System.Windows.Media.Media3D.MeshGeometry3D();
            //meshGeometry.Positions = points;
            //meshGeometry.TriangleIndices = triangles;

            //return meshGeometry;

            return null;
        }
Esempio n. 13
0
 public PointCloudTileTreeNodeLeaf(PointCloudTile tile)
 {
     m_tile = tile;
 }
Esempio n. 14
0
        private void UpdateCurrentTile(PointCloudTile tile)
        {
            foreach (System.Windows.Shapes.Rectangle rect in m_loadedTiles.Values)
            {
                rect.Stroke = System.Windows.Media.Brushes.DarkGray;
            }

            if (tile == null)
                return;

            var tilesToLoad = new List<PointCloudTile>();
            //int pointsToLoad = 0;

            int radius = 4;

            int xMin = Math.Max(0, tile.Col - radius);
            int xMax = Math.Min(tile.Col + radius + 1, CurrentTileSource.TileSet.Cols);
            int yMin = Math.Max(0, tile.Row - radius);
            int yMax = Math.Min(tile.Row + radius + 1, CurrentTileSource.TileSet.Rows);
            for (int x = xMin; x < xMax; x++)
            {
                for (int y = yMin; y < yMax; y++)
                {
                    PointCloudTile currentTile = CurrentTileSource.TileSet.GetTile(y, x);

                    if (currentTile != null)
                    {
                        if (!m_loadedTiles.ContainsKey(currentTile))
                        {
                            tilesToLoad.Add(currentTile);
                            //pointsToLoad += currentTile.PointCount;

                            System.Windows.Shapes.Rectangle rect = CreateTileRectangle(currentTile, previewImage, previewImageGrid);
                            m_loadedTiles.Add(currentTile, rect);

                            previewImageGraphicsGrid.Children.Add(rect);
                        }
                        else
                        {
                            System.Windows.Shapes.Rectangle rect = m_loadedTiles[currentTile];
                            if (tile.Equals(currentTile))
                                rect.Stroke = System.Windows.Media.Brushes.Red;
                            else
                                rect.Stroke = System.Windows.Media.Brushes.Blue;
                        }
                    }
                }
            }

            PointCloudTile[] loadedTiles = m_loadedTiles.Keys.ToArray();
            SortByDistanceFromTile(loadedTiles, tile);
            Array.Reverse(loadedTiles);

            // drop loaded tiles that are the farthest from the center
            int totalAllowedPoints = MAX_BUFFER_SIZE_BYTES / CurrentTileSource.PointSizeBytes;
            int loadedPoints = loadedTiles.Sum(t => t.PointCount);

            int potentialTotalPoints = loadedPoints;// +pointsToLoad;

            if (potentialTotalPoints > totalAllowedPoints)
            {
                int pointsToDrop = potentialTotalPoints - totalAllowedPoints;
                int i = 0;
                while(pointsToDrop > 0 && i < loadedTiles.Length)
                {
                    PointCloudTile currentTile = loadedTiles[i];
                    System.Windows.Shapes.Rectangle rect = m_loadedTiles[currentTile];
                    m_loadedTiles.Remove(currentTile);
                    m_loadedTileBuffers.Remove(currentTile);

                    // I don't know why I need to do this, but I can occasionally get a duplicate add below if I don't
                    tilesToLoad.Remove(currentTile);

                    previewImageGraphicsGrid.Children.Remove(rect);
                    pointsToDrop -= currentTile.PointCount;
                    ++i;
                }
            }

            var tilesToLoadOrdered = CurrentTileSource.TileSet.GetTileReadOrder(tilesToLoad);
            foreach (PointCloudTile currentTile in tilesToLoadOrdered)
            {
                // this will cause fragmentation problems, but it's just for demonstration
                byte[] inputBuffer = new byte[currentTile.PointCount * CurrentTileSource.PointSizeBytes];
                CurrentTileSource.LoadTile(currentTile, inputBuffer);
                m_loadedTileBuffers.Add(currentTile, inputBuffer);
            }
        }
Esempio n. 15
0
        private void UpdateCurrentTile(PointCloudTile tile)
        {
            if (tile == null)
                return;

            List<PointCloudTile> tilesToLoad = new List<PointCloudTile>();
            int pointsToLoad = 0;

            Model3DGroup emptyModelGroup = new Model3DGroup();
            emptyModelGroup.Freeze();

            bool isDirty = false;

            int radius = 2;

            int xMin = Math.Max(0, tile.Col - radius);
            int xMax = Math.Min(tile.Col + radius + 1, CurrentTileSource.TileSet.Cols);
            int yMin = Math.Max(0, tile.Row - radius);
            int yMax = Math.Min(tile.Row + radius + 1, CurrentTileSource.TileSet.Rows);
            for (int x = xMin; x < xMax; x++)
            {
                for (int y = yMin; y < yMax; y++)
                {
                    PointCloudTile currentTile = CurrentTileSource.TileSet.GetTile(y, x);

                    if (currentTile != null)
                    {
                        if (!m_loadedTiles.ContainsKey(currentTile))
                        {
                            tilesToLoad.Add(currentTile);
                            pointsToLoad += currentTile.PointCount;

                            isDirty = true;
                        }
                    }
                }
            }

            PointCloudTile[] loadedTiles = m_loadedTiles.Keys.ToArray();
            SortByDistanceFromTile(loadedTiles, tile);
            Array.Reverse(loadedTiles);

            // drop loaded tiles that are the farthest from the center
            int totalAllowedPoints = MAX_BUFFER_SIZE_BYTES / CurrentTileSource.PointSizeBytes;
            int loadedPoints = loadedTiles.Sum(t => t.PointCount);

            int potentialTotalPoints = loadedPoints + pointsToLoad;

            Dictionary<PointCloudTile, TileInfo3D> alteredTiles = new Dictionary<PointCloudTile, TileInfo3D>();

            if (potentialTotalPoints > totalAllowedPoints)
            {
                int pointsToDrop = potentialTotalPoints - totalAllowedPoints;
                int i = 0;
                while (pointsToDrop > 0)
                {
                    PointCloudTile currentTile = loadedTiles[i];
                    TileInfo3D tileInfo = m_tileInfo[currentTile];
                    GeometryModel3D model = m_loadedTiles[currentTile];

                    m_meshTileMap.Remove(model);
                    m_loadedTiles.Remove(currentTile);
                    //m_loadedTileBuffers.Remove(currentTile);

                    // replace high-res tile with low-res geometry
                    int modelIndex = tileInfo.Tile.ValidIndex;
                    m_tileModelCollection[modelIndex] = tileInfo.LowResGeometry;
                    // clear stitching
                    m_stitchingModelCollection[modelIndex] = emptyModelGroup;
                    tileInfo.ClearGeometry();

                    alteredTiles.Add(currentTile, tileInfo);

                    pointsToDrop -= currentTile.PointCount;
                    ++i;
                }
            }

            Jacere.Core.Geometry.Point3D centerOfMass = CurrentTileSource.CenterOfMass;

            PointCloudTile[] tilesToLoadArray = tilesToLoad.ToArray();
            #warning sort so that disk reads are in order? or make a tile cache
            SortByDistanceFromTile(tilesToLoadArray, tile);
            foreach (PointCloudTile currentTile in tilesToLoadArray)
            {
                TileInfo3D tileInfo = m_tileInfo[currentTile];
                CurrentTileSource.LoadTileGrid(currentTile, m_buffer, m_gridHighRes, m_quantizedGridHighRes);
                if (ENABLE_HEIGHT_EXAGGERATION)
                    m_gridHighRes.Multiply(m_heightExaggerationFactor, (float)centerOfMass.Z);

                Jacere.Core.Geometry.Extent3D tileExtent = currentTile.Extent;
                MeshGeometry3D mesh = CurrentTileSource.GenerateMesh(m_gridHighRes, tileExtent);

                DiffuseMaterial material = new DiffuseMaterial();
                if (USE_HIGH_RES_TEXTURE)
                {
                    material.Brush = m_overviewTextureBrush;
                    mesh.TextureCoordinates = MeshUtils.GeneratePlanarTextureCoordinates(mesh, m_overallCenteredExtent, MathUtils.ZAxis);
                }
                else
                {
                    material.Brush = m_solidBrush;
                }

                material.Freeze();
                GeometryModel3D geometryModel = new GeometryModel3D(mesh, material);
                geometryModel.Freeze();

                // replace low-res tile with high-res geometry
                int modelIndex = tileInfo.Tile.ValidIndex;
                m_tileModelCollection[modelIndex] = geometryModel;
                // clear stitching
                m_stitchingModelCollection[modelIndex] = emptyModelGroup;
                tileInfo.UpdateGeometry(geometryModel, m_gridHighRes);

                alteredTiles.Add(currentTile, tileInfo);

                m_meshTileMap.Add(geometryModel, currentTile);
                m_loadedTiles.Add(currentTile, geometryModel);
                //m_loadedTileBuffers.Add(currentTile, inputBuffer);
            }

            // in the future, I could have a list of which tiles need to be checked for stitching updates

            // go through the stitching groups and replace any empty ones with the appropriate stitching
            if (ENABLE_STITCHING && isDirty)
            {
                PointCloudTile[] alteredTileArray = alteredTiles.Keys.ToArray();
                foreach (PointCloudTile currentTile in alteredTileArray)
                {
                    // this amount of clearing is excessive.  I only want to clear one of the edges

                    if (currentTile.Col < CurrentTileSource.TileSet.Cols - 1)
                    {
                        PointCloudTile adjacentTile = CurrentTileSource.TileSet.GetTile(currentTile.Row, currentTile.Col + 1);
                        if (adjacentTile != null && m_tileInfo.ContainsKey(adjacentTile))
                        {
                            TileInfo3D adjacentTileInfo = m_tileInfo[adjacentTile];
                            if (!alteredTiles.ContainsKey(adjacentTile))
                                alteredTiles.Add(adjacentTile, adjacentTileInfo);

                            m_stitchingModelCollection[adjacentTileInfo.Tile.ValidIndex] = emptyModelGroup;
                            adjacentTileInfo.UpdateStitching(null, null, TileStitchingEdge.Left);
                        }
                    }

                    if (currentTile.Row < CurrentTileSource.TileSet.Rows - 1)
                    {
                        PointCloudTile adjacentTile = CurrentTileSource.TileSet.GetTile(currentTile.Row + 1, currentTile.Col);
                        if (adjacentTile != null && m_tileInfo.ContainsKey(adjacentTile))
                        {
                            TileInfo3D adjacentTileInfo = m_tileInfo[adjacentTile];
                            if (!alteredTiles.ContainsKey(adjacentTile))
                                alteredTiles.Add(adjacentTile, adjacentTileInfo);

                            m_stitchingModelCollection[adjacentTileInfo.Tile.ValidIndex] = emptyModelGroup;
                            adjacentTileInfo.UpdateStitching(null, null, TileStitchingEdge.Top);
                        }
                    }

                    if (currentTile.Col < CurrentTileSource.TileSet.Cols - 1 && currentTile.Row < CurrentTileSource.TileSet.Rows - 1)
                    {
                        PointCloudTile adjacentTile = CurrentTileSource.TileSet.GetTile(currentTile.Row + 1, currentTile.Col + 1);
                        if (adjacentTile != null && m_tileInfo.ContainsKey(adjacentTile))
                        {
                            TileInfo3D adjacentTileInfo = m_tileInfo[adjacentTile];
                            if (!alteredTiles.ContainsKey(adjacentTile))
                                alteredTiles.Add(adjacentTile, adjacentTileInfo);

                            m_stitchingModelCollection[adjacentTileInfo.Tile.ValidIndex] = emptyModelGroup;
                            adjacentTileInfo.UpdateStitching(null, null, TileStitchingEdge.TopLeft);
                        }
                    }
                }

                foreach (KeyValuePair<PointCloudTile, TileInfo3D> kvp in alteredTiles)
                {
                    int i = kvp.Value.Tile.ValidIndex;
                    Model3DGroup stitchingGroup = m_stitchingModelCollection[i] as Model3DGroup;
                    if (stitchingGroup.Children.Count == 0)
                    {
                        GeometryModel3D geometryModel = m_tileModelCollection[i] as GeometryModel3D;
                        Model3DGroup newStitchingGroup = GenerateTileStitching(CurrentTileSource, kvp.Value);
                        if (newStitchingGroup.Children.Count > 0)
                            m_stitchingModelCollection[i] = newStitchingGroup;
                    }
                }

                //for (int i = 0; i < m_stitchingModelCollection.Count; i++)
                //{
                //    Model3DGroup stitchingGroup = m_stitchingModelCollection[i] as Model3DGroup;
                //    // this is an incorrect condition, but it won't be apparent until I get multi-res stitching
                //    if (stitchingGroup.Children.Count < 3)
                //    {
                //        GeometryModel3D geometryModel = m_tileModelCollection[i] as GeometryModel3D;
                //        PointCloudTile currentTile = m_meshTileMap[geometryModel];
                //        TileInfo3D currentTileInfo = m_tileInfo[currentTile];
                //        Model3DGroup newStitchingGroup = GenerateTileStitching(CurrentTileSource, currentTileInfo);
                //        if (newStitchingGroup.Children.Count > 0)
                //            m_stitchingModelCollection[i] = newStitchingGroup;
                //    }
                //}
            }
        }
Esempio n. 16
0
 public int ReadLowResTile(PointCloudTile tile, byte[] buffer, int position)
 {
     // todo: get lowres points
     return(0);
 }
Esempio n. 17
0
        public static unsafe System.Windows.Media.Media3D.MeshGeometry3D LoadTilePointMesh(PointCloudTile tile, byte[] inputBuffer, double pointSize, int thinByFactor)
        {
            /*LoadTile(tile, inputBuffer);
             *
             * Extent3D distributionExtent = tile.Extent;
             * Extent3D centeringExtent = Extent;
             * Point3D centerOfMass = CenterOfMass;
             *
             * double xShift = -centeringExtent.MidpointX;
             * double yShift = -centeringExtent.MidpointY;
             * double zShift = -centerOfMass.Z;
             *
             * double halfPointSize = pointSize / 2;
             *
             * int thinnedTilePointCount = tile.PointCount / thinByFactor;
             *
             * // these values need to be changed from 4,6 to 8,36 if I test it out
             * System.Windows.Media.Media3D.Point3DCollection positions = new System.Windows.Media.Media3D.Point3DCollection(thinnedTilePointCount * 4);
             * System.Windows.Media.Media3D.Vector3DCollection normals = new System.Windows.Media.Media3D.Vector3DCollection(positions.Count);
             * System.Windows.Media.Int32Collection indices = new System.Windows.Media.Int32Collection(tile.PointCount * 6);
             *
             * fixed (byte* inputBufferPtr = inputBuffer)
             * {
             *      UQuantizedPoint3D* p = (UQuantizedPoint3D*)inputBufferPtr;
             *
             *      for (int i = 0; i < tile.PointCount; i++)
             *      {
             *              if (!(i % thinByFactor == 0))
             *                      continue;
             *
             *              // slow!
             *              Point3D point = Quantization.Convert(p[i]);
             *              double xC = point.X + xShift;
             *              double yC = point.Y + yShift;
             *              double zC = point.Z + zShift;
             *
             *              int currentStartIndex = positions.Count;
             *
             *              foreach (double y in new double[] { yC - halfPointSize, yC + halfPointSize })
             *              {
             *                      foreach (double x in new double[] { xC - halfPointSize, xC + halfPointSize })
             *                      {
             *                              positions.Add(new System.Windows.Media.Media3D.Point3D(x, y, zC));
             *                              normals.Add(new System.Windows.Media.Media3D.Vector3D(0, 0, 1));
             *                      }
             *              }
             *
             *              indices.Add(currentStartIndex + 0);
             *              indices.Add(currentStartIndex + 1);
             *              indices.Add(currentStartIndex + 3);
             *
             *              indices.Add(currentStartIndex + 0);
             *              indices.Add(currentStartIndex + 3);
             *              indices.Add(currentStartIndex + 2);
             *      }
             * }
             *
             * System.Windows.Media.Media3D.MeshGeometry3D geometry = new System.Windows.Media.Media3D.MeshGeometry3D();
             * geometry.Positions = positions;
             * geometry.TriangleIndices = indices;
             * geometry.Normals = normals;
             *
             * return geometry;*/

            return(null);
        }
Esempio n. 18
0
        public static unsafe System.Windows.Media.Media3D.MeshGeometry3D LoadTileMeshDelaunayIncremental(PointCloudTile tile, byte[] inputBuffer)
        {
            //Open();

            //Extent3D extent = tile.Extent;

            //DelaunayPoint[] pointsToTriangulate = new DelaunayPoint[tile.PointCount];

            //fixed (byte* inputBufferPtr = inputBuffer)
            //{
            //    UQuantizedPoint3D* p = (UQuantizedPoint3D*)inputBufferPtr;

            //    int bytesRead = tile.ReadTile(m_inputStream, inputBuffer);

            //    for (int i = 0; i < tile.PointCount; i++)
            //    {
            //        Point3D point = Quantization.Convert(p[i]);

            //        pointsToTriangulate[i] = new DelaunayPoint(
            //            (float)point.X,
            //            (float)point.Y,
            //            (float)point.Z,
            //            i);
            //    }
            //}

            //Delaunay2DIncremental triangulator = new Delaunay2DIncremental();
            //triangulator.Initialize(extent, pointsToTriangulate.Length);

            //foreach (DelaunayPoint point in pointsToTriangulate)
            //{
            //    if (triangulator.Locate(point))
            //        triangulator.UpdateTriangle(point);
            //}

            //List<int> mesh = triangulator.FlushTriangles();

            //System.Windows.Media.Media3D.Point3DCollection points = new System.Windows.Media.Media3D.Point3DCollection(pointsToTriangulate.Length);
            //for (int i = 0; i < pointsToTriangulate.Length; i++)
            //    points.Add(new System.Windows.Media.Media3D.Point3D(
            //        pointsToTriangulate[i].X - Extent.MidpointX,
            //        pointsToTriangulate[i].Y - Extent.MidpointY,
            //        pointsToTriangulate[i].Z - Extent.MidpointZ));

            //System.Windows.Media.Int32Collection triangles = new System.Windows.Media.Int32Collection(mesh.Reverse<int>());

            //System.Windows.Media.Media3D.MeshGeometry3D meshGeometry = new System.Windows.Media.Media3D.MeshGeometry3D();
            //meshGeometry.Positions = points;
            //meshGeometry.TriangleIndices = triangles;

            //return meshGeometry;

            return(null);
        }
Esempio n. 19
0
        public unsafe void LoadTileGrid(PointCloudTile tile, BufferInstance inputBuffer, Grid<float> grid, Grid<int> quantizedGrid)
        {
            Open();

            var quantizedExtent = tile.QuantizedExtent;

            double cellSizeX = (double)quantizedExtent.RangeX / grid.SizeX;
            double cellSizeY = (double)quantizedExtent.RangeY / grid.SizeY;

            #warning Why did I do FillVal it this way?
            //grid.FillVal = -1.0f;
            grid.Reset();
            quantizedGrid.Reset();

            byte* inputBufferPtr = inputBuffer.DataPtr;

            int bytesRead = tile.ReadTile(m_inputStream, inputBuffer.Data);

            byte* pb = inputBufferPtr;
            byte* pbEnd = inputBufferPtr + tile.StorageSize;
            while (pb < pbEnd)
            {
                var p = (SQuantizedPoint3D*)pb;
                pb += PointSizeBytes;

                var pixelX = (int)(((*p).X - quantizedExtent.MinX) / cellSizeX);
                var pixelY = (int)(((*p).Y - quantizedExtent.MinY) / cellSizeY);

                // max val for now, apparently
                if ((*p).Z > quantizedGrid.Data[pixelY, pixelX])
                    quantizedGrid.Data[pixelY, pixelX] = (*p).Z;
            }

            quantizedGrid.CorrectMaxOverflow();
            quantizedGrid.CopyToUnquantized(grid, Quantization, Extent);
        }
Esempio n. 20
0
        private void SortByDistanceFromTile(PointCloudTile[] tiles, PointCloudTile centerTile)
        {
            float[] distanceToCenter2 = new float[tiles.Length];
            for (int i = 0; i < tiles.Length; i++)
            {
                distanceToCenter2[i] = (float)(Math.Pow(tiles[i].Col - centerTile.Col, 2) + Math.Pow(tiles[i].Row - centerTile.Row, 2));
            }

            Array.Sort(distanceToCenter2, tiles);
        }
Esempio n. 21
0
 public int ReadLowResTile(PointCloudTile tile, byte[] buffer, int position)
 {
     // todo: get lowres points
     return 0;
 }
Esempio n. 22
0
        public TileInfo3D(PointCloudTile tile, GeometryModel3D lowResGeometry, Grid<float> lowResGrid)
        {
            Tile = tile;

            LowResGeometry = lowResGeometry;
            LowResGrid = lowResGrid;

            m_currentGeometry = LowResGeometry;
            m_currentGrid = LowResGrid;

            m_stitchingHasChanged = false;

            m_stitchingGeometry = new GeometryModel3D[3];
            m_stitchingGrid = new Grid<float>[3];
        }
Esempio n. 23
0
        private System.Windows.Shapes.Rectangle CreateTileRectangle(PointCloudTile tile, FrameworkElement image, Panel grid)
        {
            double containerWidth = image.ActualWidth;
            double containerHeight = image.ActualHeight;

            double imageLocationX = (grid.ActualWidth - containerWidth) / 2;
            double imageLocationY = (grid.ActualHeight - containerHeight) / 2;

            double tileRatioX = (double)tile.Col / (CurrentTileSource.TileSet.Cols);
            double tileRatioY = 1 - ((double)(tile.Row + 1) / (CurrentTileSource.TileSet.Rows));

            double tileLocationX = imageLocationX + tileRatioX * containerWidth;
            double tileLocationY = imageLocationY + tileRatioY * containerHeight;

            double tileRatioWidth = 1.0 / (CurrentTileSource.TileSet.Cols);
            double tileRatioHeight = 1.0 / (CurrentTileSource.TileSet.Rows);

            System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();

            rect.StrokeThickness = 1;
            rect.Stroke = System.Windows.Media.Brushes.Green;

            rect.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            rect.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            rect.Width = tileRatioWidth * containerWidth;
            rect.Height = tileRatioHeight * containerHeight;

            rect.Margin = new Thickness(tileLocationX, tileLocationY, 0, 0);

            return rect;
        }