コード例 #1
0
        /// <summary>
        /// Builds shaded relief.
        /// </summary>
        /// <param name="surfacePoints">A 3D-coordinates defining source</param>
        /// <param name="lightX">An X component of the light vector</param>
        /// <param name="lightY">A Y component of the light vector</param>
        /// <param name="lightZ">A Z component of the light vector</param>
        /// <param name="zFactor">A value at which to multiply z-values for luminosity calculation</param>
        /// <param name="luminosityLevelNumber">A number of resoluted luminosity levels</param>
        /// <returns>An array containing lightened polygons</returns>
        public LightenedPolygon[] BuildShadedRelief(IEnumerable <Coordinate3D> surfacePoints,
                                                    double lightX,
                                                    double lightY,
                                                    double lightZ,
                                                    double zFactor,
                                                    int luminosityLevelNumber)
        {
            List <ICoordinate> coords = new List <ICoordinate>();

            foreach (Coordinate3D c in surfacePoints)
            {
                coords.Add(c);
            }

            VoronoiBuilder     vb          = new VoronoiBuilder();
            VoronoiTesselation tesselation = vb.Build(coords, true);

            return(BuildShadedRelief(tesselation.Triangles, lightX, lightY, lightZ, zFactor, luminosityLevelNumber));
        }
コード例 #2
0
        private Polyline[] buildIsolinesInternal(IEnumerable<Coordinate3D> surfacePoints, double[] zLevels, List<Triangle> triangles)
        {
            Polyline[] result = new Polyline[zLevels.Length];
            if (zLevels.Length > 0)
            {
                double minZ = zLevels.Min();
                double maxZ = zLevels.Max();
                double surfaceMin = surfacePoints.Min(coord => coord.Z);
                double surfaceMax = surfacePoints.Max(coord => coord.Z);

                if (surfaceMin > maxZ || surfaceMax < minZ)
                    return result;

                List<ICoordinate> coords = new List<ICoordinate>();
                surfacePoints.ToList().ForEach(coord => coords.Add(coord));

                // build tesselation
                VoronoiBuilder vb = new VoronoiBuilder();
                VoronoiTesselation tesselation = vb.Build(coords, true);
                tesselation.Triangles.ToList().ForEach(t => triangles.Add(t));

                vb = null;
                tesselation = null;

                Comparison<Triangle> comparision = delegate(Triangle t1, Triangle t2)
                {
                    if (t1 == t2)
                        return 0;

                    double z11 = ((Coordinate3D)t1.Cell1.DataPoint).Z;
                    double z12 = ((Coordinate3D)t1.Cell2.DataPoint).Z;
                    double z13 = ((Coordinate3D)t1.Cell3.DataPoint).Z;

                    double z21 = ((Coordinate3D)t2.Cell1.DataPoint).Z;
                    double z22 = ((Coordinate3D)t2.Cell2.DataPoint).Z;
                    double z23 = ((Coordinate3D)t2.Cell3.DataPoint).Z;

                    double z1 = Math.Min(Math.Min(z11, z12), z13);
                    double z2 = Math.Min(Math.Min(z21, z22), z23);

                    if (z1 < z2) return -1;
                    if (z1 > z2) return 1;
                    return 0;
                };

                // sort triangles by minimal z-value
                triangles.Sort(comparision);

                for (int i = 0; i < zLevels.Length; i++)
                {
                    if (zLevels[i] < surfaceMin)
                    {
                        result[i] = new Polyline();
                        continue;
                    }

                    result[i] = getIsoline(triangles, zLevels[i]);
                }
            }

            return result;
        }
コード例 #3
0
        private Polyline[] buildIsolinesInternal(IEnumerable <Coordinate3D> surfacePoints, double[] zLevels, List <Triangle> triangles)
        {
            Polyline[] result = new Polyline[zLevels.Length];
            if (zLevels.Length > 0)
            {
                double minZ       = zLevels.Min();
                double maxZ       = zLevels.Max();
                double surfaceMin = surfacePoints.Min(coord => coord.Z);
                double surfaceMax = surfacePoints.Max(coord => coord.Z);

                if (surfaceMin > maxZ || surfaceMax < minZ)
                {
                    return(result);
                }

                List <ICoordinate> coords = new List <ICoordinate>();
                surfacePoints.ToList().ForEach(coord => coords.Add(coord));

                // build tesselation
                VoronoiBuilder     vb          = new VoronoiBuilder();
                VoronoiTesselation tesselation = vb.Build(coords, true);
                tesselation.Triangles.ToList().ForEach(t => triangles.Add(t));

                vb          = null;
                tesselation = null;

                Comparison <Triangle> comparision = delegate(Triangle t1, Triangle t2)
                {
                    if (t1 == t2)
                    {
                        return(0);
                    }

                    double z11 = ((Coordinate3D)t1.Cell1.DataPoint).Z;
                    double z12 = ((Coordinate3D)t1.Cell2.DataPoint).Z;
                    double z13 = ((Coordinate3D)t1.Cell3.DataPoint).Z;

                    double z21 = ((Coordinate3D)t2.Cell1.DataPoint).Z;
                    double z22 = ((Coordinate3D)t2.Cell2.DataPoint).Z;
                    double z23 = ((Coordinate3D)t2.Cell3.DataPoint).Z;

                    double z1 = Math.Min(Math.Min(z11, z12), z13);
                    double z2 = Math.Min(Math.Min(z21, z22), z23);

                    if (z1 < z2)
                    {
                        return(-1);
                    }
                    if (z1 > z2)
                    {
                        return(1);
                    }
                    return(0);
                };

                // sort triangles by minimal z-value
                triangles.Sort(comparision);

                for (int i = 0; i < zLevels.Length; i++)
                {
                    if (zLevels[i] < surfaceMin)
                    {
                        result[i] = new Polyline();
                        continue;
                    }

                    result[i] = getIsoline(triangles, zLevels[i]);
                }
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Builds shaded relief.
        /// </summary>
        /// <param name="surfacePoints">A 3D-coordinates defining source</param>
        /// <param name="lightX">An X component of the light vector</param>
        /// <param name="lightY">A Y component of the light vector</param>
        /// <param name="lightZ">A Z component of the light vector</param>
        /// <param name="zFactor">A value at which to multiply z-values for luminosity calculation</param>
        /// <param name="luminosityLevelNumber">A number of resoluted luminosity levels</param>
        /// <returns>An array containing lightened polygons</returns>
        public LightenedPolygon[] BuildShadedRelief(IEnumerable<Coordinate3D> surfacePoints,
            double lightX,
            double lightY,
            double lightZ,
            double zFactor,
            int luminosityLevelNumber)
        {
            List<ICoordinate> coords = new List<ICoordinate>();
            foreach(Coordinate3D c in surfacePoints)
                coords.Add(c);

            VoronoiBuilder vb = new VoronoiBuilder();
            VoronoiTesselation tesselation = vb.Build(coords, true);

            return BuildShadedRelief(tesselation.Triangles, lightX, lightY, lightZ, zFactor, luminosityLevelNumber);
        }