public static LineOfSightArea LoadFromStream(ref Stream stream)
        {
            var area = new LineOfSightArea();

            BinaryReader br = new BinaryReader(stream);
            int size = Marshal.SizeOf(typeof(Header));

            byte[] buffer = new byte[size];
            br.Read(buffer, 0, size);

            var header = Functions.ByteArrayToStructure<Header>(buffer);

            size = Marshal.SizeOf(typeof(Vertex));

            for (int i = 0; i < header.vertexCount; i++)
            {
                buffer = new byte[size];
                br.Read(buffer, 0, size);
                var vertex = Functions.ByteArrayToStructure<Vertex>(buffer);

                //don't add the last one... as it's value needs to tbe the same as the first vertex
                if (i != header.vertexCount - 1)
                {
                    area.Vertices.Add(new Point3D(vertex.x, vertex.y, vertex.z));
                }
            }
            area._maxZ = header.maxZ;
            area._minZ = header.minZ;
            area._version = header.version;

            return area;
        }
        public static LineOfSightArea LoadFileBinary(string file)
        {
            var los = new LineOfSightArea();

            FileStream fs = new FileStream(file.ToLower(), FileMode.Open);

            Stream s = fs;
            var header = los.ReadHeader(ref s);
            //p.ReadNodes(ref s, header);
            fs.Close();

            return los;
        }
        public void ShowArea(LineOfSightArea area)
        {
            Model3DGroup group = Model as Model3DGroup;
            group.Children.Clear();

            if (area != null)
            {
                CreateArea(area);
                _activeArea = area;
            }

            //if (area == null)
            //{
            //    //UpdateAll();
            //    return;
            //}
            //else
            //{
            //    Model3DGroup group = Model as Model3DGroup;
            //    group.Children.Clear();
            //    CreateArea(area);
            //    _activeArea = area;
            //}
        }
        public static LineOfSightArea LoadFileXml(string file)
        {
            var los = new LineOfSightArea();

            return los;
        }
 public void RemoveArea(LineOfSightArea area)
 {
     Areas.Remove(area);
 }
 public void AddArea(LineOfSightArea area)
 {
     this.Areas.Add(area);
 }
        private void CreateArea(LineOfSightArea area)
        {
            Model3DGroup group = Model as Model3DGroup;

            Model3DCollection collection = new Model3DCollection();
            try
            {
                if (_mapping[area] != null)
                {
                    foreach (Model3D model in _mapping[area])
                    {
                        group.Children.Remove(model);
                    }
                }
            }
            catch (KeyNotFoundException)
            {
                //nothing needs to be done
            }

            foreach (var vertex in area.Vertices)
            {
                MeshBuilder builder = new MeshBuilder();
                Point3D p1 = new Point3D(vertex.X, vertex.Y, area.MaxZ);
                Point3D p2 = new Point3D(vertex.X, vertex.Y, area.MinZ);

                //if (Clipping != null && !Clipping.DrawPoint(p)) continue;

                builder.AddBox(p1, 4, 4, 4);
                builder.AddBox(p2, 4, 4, 4);
                builder.AddPipe(p1, p2, 1.5, 1.5, 50);

                GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Yellow);
                collection.Add(box);

                builder = new MeshBuilder();

                Point3D next;
                if (vertex == area.Vertices.Last())
                {
                    next = area.Vertices[0];
                }
                else
                {
                    next = area.Vertices.ElementAt(area.Vertices.IndexOf(vertex) + 1);
                }
                Point3D n1 = new Point3D(next.X, next.Y, area.MaxZ);
                Point3D n2 = new Point3D(next.X, next.Y, area.MinZ);

                //builder.AddPipe(p1, p2);
                builder.AddPipe(p1, n1, 0.5, 0.5, 50);
                builder.AddPipe(p2, n2, 0.5, 0.5, 50);
                collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.Yellow));

            }

            _mapping[area] = collection;
            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }