コード例 #1
0
        //internal Shpe wrapper;

        private void SelectPart(object sender, System.EventArgs e)
        {
            if (lbpart.Tag != null)
            {
                return;
            }
            if (lbpart.SelectedIndex < 0)
            {
                return;
            }

            try
            {
                lbpart.Tag = true;
                ShapePart item = (ShapePart)lbpart.Items[lbpart.SelectedIndex];
                tbparttype.Text = item.Subset;
                tbpartdsc.Text  = item.FileName;

                string s = "";
                foreach (byte b in item.Data)
                {
                    s += Helper.HexString(b) + " ";
                }
                tbpartdata.Text = s;
            }
            catch (Exception) {}
            finally
            {
                lbpart.Tag = null;
            }
        }
コード例 #2
0
ファイル: Polygon.cs プロジェクト: ygqiang/czml-writer
        private void WritePacket(int index)
        {
            ShapePart part = simplifiedRings[index];

            using (PacketCesiumWriter packetWriter = m_document.CesiumStreamWriter.OpenPacket(m_document.CesiumOutputStream))
            {
                packetWriter.WriteId(Guid.NewGuid().ToString());

                using (PolygonCesiumWriter polygonWriter = packetWriter.OpenPolygonProperty())
                {
                    using (MaterialCesiumWriter materialWriter = polygonWriter.OpenMaterialProperty())
                    {
                        using (SolidColorMaterialCesiumWriter colorWriter = materialWriter.OpenSolidColorProperty())
                        {
                            colorWriter.WriteColorProperty(m_color);
                        }
                    }
                }

                using (PositionListCesiumWriter positionWriter = packetWriter.OpenVertexPositionsProperty())
                {
                    PolygonShape        polygon   = (PolygonShape)m_shape;
                    List <Cartographic> positions = new List <Cartographic>();
                    for (int i = 0; i < part.Count; i++)
                    {
                        positions.Add(part[i]);
                    }
                    positionWriter.WriteCartographicRadians(positions);
                }
            }
        }
コード例 #3
0
ファイル: PolygonZShape.cs プロジェクト: qjw2bqn/czml-writer
        public PolygonZShape(
            int recordNumber,
            StringDictionary metadata,
            CartographicExtent extent,
            int[] parts,
            Rectangular[] positions,
            double minimumZ,
            double maximumZ,
            double[] zValues,
            double minimumMeasure,
            double maximumMeasure,
            double[] measures,
            ShapeType shapeType = ShapeType.PolygonZ
            )
            : base(recordNumber, metadata, extent, parts, positions, minimumMeasure, maximumMeasure, measures, shapeType)
        {
            _minimumZ = minimumZ;
            _maximumZ = maximumZ;

            for (int i = 0; i < parts.Length; ++i)
            {
                int count = ((i == parts.Length - 1) ?
                    positions.Length : parts[i + 1]) - parts[i];

                _parts[i] = new ShapePart(positions, zValues, measures, parts[i], count);
            }
        }
コード例 #4
0
        private void ChangedPart(object sender, System.EventArgs e)
        {
            if (lbpart.Tag != null)
            {
                return;
            }
            if (lbpart.SelectedIndex < 0)
            {
                return;
            }

            try
            {
                lbpart.Tag = true;
                ShapePart item = (ShapePart)lbpart.Items[lbpart.SelectedIndex];
                item.Subset   = tbparttype.Text;
                item.FileName = tbpartdsc.Text;

                string[] tokens = tbpartdata.Text.Trim().Split(" ".ToCharArray());
                byte[]   data   = new byte[tokens.Length];
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = Convert.ToByte(tokens[i]);
                }
                item.Data = data;

                lbpart.Items[lbpart.SelectedIndex] = item;
            }
            catch (Exception) {}
            finally
            {
                lbpart.Tag = null;
            }
        }
コード例 #5
0
        private static void PolylineCapacities(Shapefile shapefile, out int positionsCount, out int indicesCount)
        {
            int numberOfPositions = 0;
            int numberOfIndices   = 0;

            foreach (Shape shape in shapefile)
            {
                if (shape.ShapeType != ShapeType.Polyline)
                {
                    throw new NotSupportedException("The type of an individual shape does not match the Shapefile type.");
                }

                PolylineShape polylineShape = (PolylineShape)shape;

                for (int j = 0; j < polylineShape.Count; ++j)
                {
                    ShapePart part = polylineShape[j];

                    numberOfPositions += part.Count;
                    numberOfIndices   += (part.Count - 1) * 2;
                }
            }

            positionsCount = numberOfPositions;
            indicesCount   = numberOfIndices;
        }
コード例 #6
0
ファイル: Polyline.cs プロジェクト: qjw2bqn/czml-writer
        /// <summary>
        /// Writes the polyline to its <see cref="CzmlDocument"/>.
        /// </summary>
        public override void Write()
        {
            PolylineShape polyline = (PolylineShape)m_shape;

            for (int i = 0; i < polyline.Count; i++)
            {
                ShapePart part = polyline[i];
                using (PacketCesiumWriter packetWriter = m_document.CesiumStreamWriter.OpenPacket(m_document.CesiumOutputStream))
                {
                    packetWriter.WriteId(Guid.NewGuid().ToString());
                    using (PolylineCesiumWriter polylineWriter = packetWriter.OpenPolylineProperty())
                    {
                        using (var materialWriter = polylineWriter.OpenMaterialProperty())
                            using (var colorWriter = materialWriter.OpenSolidColorProperty())
                            {
                                colorWriter.WriteColorProperty(m_color);
                            }

                        List <Cartographic> positions = new List <Cartographic>();
                        for (int x = 0; x < part.Count; x++)
                        {
                            positions.Add(part[x]);
                        }
                        polylineWriter.WritePositionsPropertyCartographicRadians(positions);
                    }
                }
            }
        }
コード例 #7
0
ファイル: MultiPatch.cs プロジェクト: ygqiang/czml-writer
        /// <summary>
        /// Writes the MultiPatch shape to its <see cref="CzmlDocument"/> as a series of polygon packets.
        /// </summary>
        public override void Write()
        {
            MultiPatchShape multipatch = (MultiPatchShape)m_shape;
            List <Polygon>  polygons   = new List <Polygon>();

            StringDictionary metadata = new StringDictionary();
            var fields = multipatch.GetMetadataFields();

            foreach (String field in fields)
            {
                metadata.Add(field, multipatch.GetMetadataValue(field));
            }

            for (int i = 0; i < multipatch.Count; i++)
            {
                List <ShapePart> polygonParts = new List <ShapePart>();
                PolygonShape     temp;

                switch (multipatch.GetPartType(i))
                {
                case MultiPatchPartType.TriangleFan:
                case MultiPatchPartType.TriangleStrip:
                    for (int j = 2; j < multipatch[i].Count; j++)
                    {
                        int            firstIndex = (multipatch.GetPartType(i) == MultiPatchPartType.TriangleFan) ? 0 : j - 2;
                        Cartographic[] vertices   = new Cartographic[] { multipatch[i][firstIndex], multipatch[i][j - 1], multipatch[i][j] };
                        ShapePart      triangle   = new ShapePart(vertices, 0, vertices.Length);
                        PolygonShape   p          = new PolygonShape(multipatch.RecordNumber, metadata, multipatch.Extent, new ShapePart[] { triangle });
                        (new Polygon(p, m_document, m_color)).Write();
                    }
                    break;

                case MultiPatchPartType.Ring:
                    while (i < multipatch.Count && multipatch.GetPartType(i) == MultiPatchPartType.Ring)
                    {
                        temp = new PolygonShape(multipatch.RecordNumber, metadata, multipatch.Extent, new ShapePart[] { multipatch[i] });
                        (new Polygon(temp, m_document, m_color)).Write();
                        i++;
                    }
                    i--;
                    break;

                case MultiPatchPartType.OuterRing:
                case MultiPatchPartType.FirstRing:
                    polygonParts.Add(multipatch[i]);
                    MultiPatchPartType comparisonType = (multipatch.GetPartType(i) == MultiPatchPartType.OuterRing) ? MultiPatchPartType.InnerRing : MultiPatchPartType.Ring;
                    while (++i < multipatch.Count && multipatch.GetPartType(i) == comparisonType)
                    {
                        polygonParts.Add(multipatch[i]);
                    }
                    temp = new PolygonShape(multipatch.RecordNumber, metadata, multipatch.Extent, polygonParts.ToArray());
                    (new Polygon(temp, m_document, m_color)).Write();
                    i--;
                    break;
                }
            }
        }
コード例 #8
0
ファイル: MultiPatch.cs プロジェクト: qjw2bqn/czml-writer
        /// <summary>
        /// Writes the MultiPatch shape to its <see cref="CzmlDocument"/> as a series of polygon packets.
        /// </summary>
        public override void Write()
        {
            MultiPatchShape multipatch = (MultiPatchShape)m_shape;
            List<Polygon> polygons = new List<Polygon>();

            StringDictionary metadata = new StringDictionary();
            var fields = multipatch.GetMetadataFields();
            foreach (String field in fields)
            {
                metadata.Add(field, multipatch.GetMetadataValue(field));
            }

            for (int i = 0; i < multipatch.Count; i++)
            {
                List<ShapePart> polygonParts = new List<ShapePart>();
                PolygonShape temp;

                switch (multipatch.GetPartType(i))
                {
                    case MultiPatchPartType.TriangleFan:
                    case MultiPatchPartType.TriangleStrip:
                        for (int j = 2; j < multipatch[i].Count; j++)
                        {
                            int firstIndex = (multipatch.GetPartType(i) == MultiPatchPartType.TriangleFan) ? 0 : j - 2;
                            Cartographic[] vertices = new Cartographic[] { multipatch[i][firstIndex], multipatch[i][j - 1], multipatch[i][j] };
                            ShapePart triangle = new ShapePart(vertices, 0, vertices.Length);
                            PolygonShape p = new PolygonShape(multipatch.RecordNumber, metadata, multipatch.Extent, new ShapePart[] { triangle });
                            (new Polygon(p, m_document, m_color)).Write();
                        }
                        break;

                    case MultiPatchPartType.Ring:
                        while (i < multipatch.Count && multipatch.GetPartType(i) == MultiPatchPartType.Ring)
                        {
                            temp = new PolygonShape(multipatch.RecordNumber, metadata, multipatch.Extent, new ShapePart[] { multipatch[i] });
                            (new Polygon(temp, m_document, m_color)).Write();
                            i++;
                        }
                        i--;
                        break;

                    case MultiPatchPartType.OuterRing:
                    case MultiPatchPartType.FirstRing:
                        polygonParts.Add(multipatch[i]);
                        MultiPatchPartType comparisonType = (multipatch.GetPartType(i) == MultiPatchPartType.OuterRing) ? MultiPatchPartType.InnerRing : MultiPatchPartType.Ring;
                        while (++i < multipatch.Count && multipatch.GetPartType(i) == comparisonType)
                        {
                            polygonParts.Add(multipatch[i]);
                        }
                        temp = new PolygonShape(multipatch.RecordNumber, metadata, multipatch.Extent, polygonParts.ToArray());
                        (new Polygon(temp, m_document, m_color)).Write();
                        i--;
                        break;
                }
            }
        }
コード例 #9
0
        private void UpdateLists()
        {
            try
            {
                SimPe.Plugin.Shape shape = (SimPe.Plugin.Shape) this.Tag;

                ShapePart[] parts = new ShapePart[lbpart.Items.Count];
                for (int i = 0; i < parts.Length; i++)
                {
                    parts[i] = (ShapePart)lbpart.Items[i];
                }
                shape.Parts = parts;
            }
            catch (Exception) {}
        }
コード例 #10
0
        private void linkLabel8_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                //Shpe wrp = (Shpe)wrapper;
                SimPe.Plugin.Shape shape = (SimPe.Plugin.Shape) this.Tag;

                ShapePart val = new ShapePart();
                val.Subset   = tbparttype.Text;
                val.FileName = tbpartdsc.Text;
                val.Data     = Helper.SetLength(Helper.HexListToBytes(tbpartdata.Text), 9);

                lbpart.Items.Add(val);
                UpdateLists();
            }
            catch (Exception) {}
        }
コード例 #11
0
        public MultiPatchShape(
            int recordNumber,
            StringDictionary metadata,
            CartographicExtent extent,
            int[] parts,
            MultiPatchPartType[] partTypes,
            Rectangular[] positions,
            double minimumZ,
            double maximumZ,
            double[] zValues,
            double minimumMeasure,
            double maximumMeasure,
            double[] measures,
            ShapeType shapeType = ShapeType.MultiPatch)
            : base(recordNumber, metadata, shapeType)
        {
            _extent = new CartographicExtent(
               extent.WestLongitude * Constants.RadiansPerDegree,
               extent.SouthLatitude * Constants.RadiansPerDegree,
               extent.EastLongitude * Constants.RadiansPerDegree,
               extent.NorthLatitude * Constants.RadiansPerDegree);

            _minimumZ = minimumZ;
            _maximumZ = maximumZ;
            _minimumMeasure = minimumMeasure;
            _maximumMeasure = maximumMeasure;
            _measures = (double[])measures.Clone();

            for (int i = 0; i < positions.Length; i++)
            {
                positions[i] = new Rectangular(positions[i].X * Constants.RadiansPerDegree, positions[i].Y * Constants.RadiansPerDegree);
            }

            _parts = new ShapePart[parts.Length];
            for (int i = 0; i < parts.Length; ++i)
            {
                int count = ((i == parts.Length - 1) ?
                    positions.Length : parts[i + 1]) - parts[i];

                _parts[i] = new ShapePart(positions, zValues, parts[i], count);
            }

            _partTypes = (MultiPatchPartType[])partTypes.Clone();
        }
コード例 #12
0
        /// <summary>
        /// Regenerates all the Mesh/Lod Numbers for the ShapeParts
        /// based on the index offsets and other information.
        ///
        /// Kind of computationally expensive, so this is only done once
        /// and then cached in the shape parts themselves.
        /// </summary>
        public void AssignMeshAndLodNumbers(List <List <int> > indexOffsets)
        {
            // For every shape...
            foreach (ShapeInfo shape in this.ShapeInfoList)
            {
                string shapeName = shape.Name;

                // And every LoD in that shape...
                for (int lodNum = 0; lodNum < indexOffsets.Count; lodNum++)
                {
                    ShapeLodInfo lod        = shape.ShapeLods[lodNum];
                    List <int>   lodOffsets = indexOffsets[lodNum];

                    short            count  = lod.PartCount;
                    ushort           offset = lod.PartOffset;
                    List <ShapePart> parts  = new List <ShapePart>(count);

                    // And every part in that LoD...
                    for (int i = offset; i < offset + count; i++)
                    {
                        ShapePart part = this.ShapeParts[i];

                        // Assign its LoD level
                        part.LodLevel = lodNum;

                        // Assign its parent Shape name.
                        part.ShapeName = shapeName;

                        // And see which of our mesh offsets matches it.
                        for (int meshNum = 0; meshNum < indexOffsets[lodNum].Count; meshNum++)
                        {
                            if (indexOffsets[lodNum][meshNum] == part.MeshIndexOffset)
                            {
                                part.MeshNumber = meshNum;
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
ファイル: Polyline.cs プロジェクト: slojo404/czml-writer
 /// <summary>
 /// Writes a new polyline packet for each part of the shape.
 /// </summary>
 /// <param name="part">The <see cref="ShapePart"/> of the <see cref="PolylineShape"/> to write</param>
 private void WritePacket(ShapePart part)
 {
     using (PacketCesiumWriter packetWriter = m_document.CesiumStreamWriter.OpenPacket(m_document.CesiumOutputStream))
     {
         packetWriter.WriteId(Guid.NewGuid().ToString());
         using (PositionListCesiumWriter position = packetWriter.OpenVertexPositionsProperty())
         {
             PolylineShape polyline = (PolylineShape)m_shape;
             List<Cartographic> positions = new List<Cartographic>();
             for (int i = 0; i < part.Count; i++)
             {
                 positions.Add(part[i]);
             }
             position.WriteCartographicRadians(positions);
         }
         using (PolylineCesiumWriter polylineWriter = packetWriter.OpenPolylineProperty())
         {
             polylineWriter.WriteColorProperty(m_color);
         }
     }
 }
コード例 #14
0
ファイル: Polyline.cs プロジェクト: ygqiang/czml-writer
 /// <summary>
 /// Writes a new polyline packet for each part of the shape.
 /// </summary>
 /// <param name="part">The <see cref="ShapePart"/> of the <see cref="PolylineShape"/> to write</param>
 private void WritePacket(ShapePart part)
 {
     using (PacketCesiumWriter packetWriter = m_document.CesiumStreamWriter.OpenPacket(m_document.CesiumOutputStream))
     {
         packetWriter.WriteId(Guid.NewGuid().ToString());
         using (PositionListCesiumWriter position = packetWriter.OpenVertexPositionsProperty())
         {
             PolylineShape       polyline  = (PolylineShape)m_shape;
             List <Cartographic> positions = new List <Cartographic>();
             for (int i = 0; i < part.Count; i++)
             {
                 positions.Add(part[i]);
             }
             position.WriteCartographicRadians(positions);
         }
         using (PolylineCesiumWriter polylineWriter = packetWriter.OpenPolylineProperty())
         {
             polylineWriter.WriteColorProperty(m_color);
         }
     }
 }
コード例 #15
0
        public PolylineShapefile(
            Shapefile shapefile,
            Context context,
            Ellipsoid globeShape,
            ShapefileAppearance appearance)
        {
            Verify.ThrowIfNull(shapefile);
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(globeShape);
            Verify.ThrowIfNull(appearance);

            _polyline = new OutlinedPolylineTexture();

            int positionsCount = 0;
            int indicesCount   = 0;

            PolylineCapacities(shapefile, out positionsCount, out indicesCount);

            VertexAttributeDoubleVector3 positionAttribute     = new VertexAttributeDoubleVector3("position", positionsCount);
            VertexAttributeRGBA          colorAttribute        = new VertexAttributeRGBA("color", positionsCount);
            VertexAttributeRGBA          outlineColorAttribute = new VertexAttributeRGBA("outlineColor", positionsCount);
            IndicesUnsignedInt           indices = new IndicesUnsignedInt(indicesCount);

            foreach (Shape shape in shapefile)
            {
                if (shape.ShapeType != ShapeType.Polyline)
                {
                    throw new NotSupportedException("The type of an individual shape does not match the Shapefile type.");
                }

                PolylineShape polylineShape = (PolylineShape)shape;

                for (int j = 0; j < polylineShape.Count; ++j)
                {
                    ShapePart part = polylineShape[j];

                    for (int i = 0; i < part.Count; ++i)
                    {
                        Vector2D point = part[i];

                        positionAttribute.Values.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y))));
                        colorAttribute.AddColor(appearance.PolylineColor);
                        outlineColorAttribute.AddColor(appearance.PolylineOutlineColor);

                        if (i != 0)
                        {
                            indices.Values.Add((uint)positionAttribute.Values.Count - 2);
                            indices.Values.Add((uint)positionAttribute.Values.Count - 1);
                        }
                    }
                }
            }

            Mesh mesh = new Mesh();

            mesh.PrimitiveType = PrimitiveType.Lines;
            mesh.Attributes.Add(positionAttribute);
            mesh.Attributes.Add(colorAttribute);
            mesh.Attributes.Add(outlineColorAttribute);
            mesh.Indices = indices;
            _polyline.Set(context, mesh);
            _polyline.Width        = appearance.PolylineWidth;
            _polyline.OutlineWidth = appearance.PolylineOutlineWidth;
        }
コード例 #16
0
 /// <summary>
 /// Retrieves the shape data for a given part.
 /// </summary>
 public List <ShapeDataEntry> GetShapeData(ShapePart part)
 {
     ShapeDataEntry[] data = new ShapeDataEntry[part.IndexCount];
     this.ShapeDataList.CopyTo(part.ShapeDataOffset, data, 0, part.IndexCount);
     return(data.ToList());
 }
コード例 #17
0
        public PolygonShapefile(
            Shapefile shapefile,
            Context context,
            Ellipsoid globeShape,
            ShapefileAppearance appearance)
        {
            Verify.ThrowIfNull(shapefile);
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(globeShape);

            _polyline = new OutlinedPolylineTexture();
            _polygons = new List <Polygon>();

            VertexAttributeDoubleVector3 positionAttribute     = new VertexAttributeDoubleVector3("position");
            VertexAttributeRGBA          colorAttribute        = new VertexAttributeRGBA("color");
            VertexAttributeRGBA          outlineColorAttribute = new VertexAttributeRGBA("outlineColor");
            IndicesUnsignedInt           indices = new IndicesUnsignedInt();

            Random           r         = new Random(3);
            IList <Vector3D> positions = new List <Vector3D>();

            foreach (Shape shape in shapefile)
            {
                if (shape.ShapeType != ShapeType.Polygon)
                {
                    throw new NotSupportedException("The type of an individual shape does not match the Shapefile type.");
                }

                PolygonShape polygonShape = (PolygonShape)shape;

                for (int j = 0; j < polygonShape.Count; ++j)
                {
                    Color color = Color.FromArgb(127, r.Next(256), r.Next(256), r.Next(256));

                    positions.Clear();

                    ShapePart part = polygonShape[j];

                    for (int i = 0; i < part.Count; ++i)
                    {
                        Vector2D point = part[i];

                        positions.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y))));

                        //
                        // For polyline
                        //
                        positionAttribute.Values.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y))));
                        colorAttribute.AddColor(color);
                        outlineColorAttribute.AddColor(Color.Black);

                        if (i != 0)
                        {
                            indices.Values.Add((uint)positionAttribute.Values.Count - 2);
                            indices.Values.Add((uint)positionAttribute.Values.Count - 1);
                        }
                    }

                    try
                    {
                        Polygon p = new Polygon(context, globeShape, positions);
                        p.Color = color;
                        _polygons.Add(p);
                    }
                    catch (ArgumentOutOfRangeException) // Not enough positions after cleaning
                    {
                    }
                }
            }

            Mesh mesh = new Mesh();

            mesh.PrimitiveType = PrimitiveType.Lines;
            mesh.Attributes.Add(positionAttribute);
            mesh.Attributes.Add(colorAttribute);
            mesh.Attributes.Add(outlineColorAttribute);
            mesh.Indices = indices;
            _polyline.Set(context, mesh);
        }