예제 #1
0
 public static Scene GenerateSceneFromPointCloud(IPointCloud pointCloud)
 {
     return(new Scene(new List <Mesh>()
     {
         GenerateMeshFromPointCloud(pointCloud)
     }, pointCloud.Source));
 }
        public static Polygon Create(IPointCloud pointCloud, double searchRange, int kNearestCount)
        {
            var result = new Polygon();

              var currPoint = pointCloud.QuadTree.GetLowestYPoint();
              result.Points.Add(currPoint);

              //Uno a sinistra così può calcolare l'angolo in modo uniforme
              var prevPoint = new DblPoint2(currPoint.x - 1, currPoint.y);

              while (true)
              {
            var nextPoint = GetNextPoint(pointCloud, result, prevPoint, currPoint, result.Points.Count < 3 ? result.Points : result.Points.Skip(1),
                                     searchRange, kNearestCount);
            if (nextPoint == result.Points[0])
              break;

            result.Points.Add(nextPoint);

            prevPoint = currPoint;
            currPoint = nextPoint;
              }

              return result;
        }
예제 #3
0
 private static Mesh GenerateMeshFromPointCloud(IPointCloud pointCloud)
 {
     return(new Mesh(
                pointCloud.Source,
                pointCloud.Vertices.Select(v => v.Point).ToList(),
                pointCloud.Vertices.Select(v => v.Normal).ToList(),
                pointCloud.Vertices.Select(v => v.Color.ToCustomColor()).ToList()));
 }
예제 #4
0
        public static OctreeModel ToOctree(this IPointCloud pointCloud, int maxLevel)
        {
            var         box  = pointCloud.CalulateAABB();
            var         size = Math.Abs(box.HalfSize.ToArray().Max() * 2.0);
            IOctreeNode node = new OctreeNode(box.Center, size, 0, NodeType.Empty);

            return(new OctreeModel(pointCloud.Points.Aggregate(node, (current, point) => current.Intersect(point.In, maxLevel))));
        }
예제 #5
0
        public static OctreeModel ToOctreeParallel(this IPointCloud pointCloud, int maxLevel)
        {
            //unsure if this will work
            var         box  = pointCloud.CalulateAABB();
            var         size = Math.Abs(box.HalfSize.ToArray().Max() * 2.0);
            IOctreeNode node = new OctreeNode(box.Center, size, 0, NodeType.Empty);

            return(new OctreeModel(pointCloud.Points.AsParallel().WithDegreeOfParallelism(8).Aggregate(node, (current, point) => current.Intersect(point.In, maxLevel))));
        }
        private static DblPoint2 GetNextPoint(IPointCloud pointCloud, Polygon partialResult, DblPoint2 prevPoint, DblPoint2 currPoint, IEnumerable<DblPoint2> excludedPoints,
                                          double searchRange, int kNearestCount)
        {
            while (true)
              {
            var kNearest = new List<DblPoint2>();
            var actualkNearestCount = kNearestCount;
            while (true)
            {
              pointCloud.QuadTree.GetPointsInsideCircle(currPoint, 1000000.0, kNearest);

              kNearest.RemoveAll((x) => excludedPoints.Contains(x));

              if (kNearest.Count < actualkNearestCount && kNearest.Count != (pointCloud.Points.Count() - excludedPoints.Count()))
              {
            actualkNearestCount++;
            kNearest.Clear();
              }
              else if (kNearest.Count > 3)
              {
            kNearest = (from k in kNearest
                        orderby (k - currPoint).Length2 ascending
                        select k).Take(actualkNearestCount).ToList();
            break;
              }
              else
            break;
            }

            var kNearestOrderedByAngle = (from k in kNearest
                                      orderby (prevPoint - currPoint).CWAngleTo(k - currPoint) descending
                                      select k).ToList();

            //Rimuovi tutti quelli che intersecano il poligono corrente
            var kNearestOrderedByAngleNotIntersecting = (from k in kNearestOrderedByAngle
                                                     where !IntersectAnyPolygonEdgeExceptLast(partialResult, currPoint, k)
                                                     select k).ToList();

            if (kNearestOrderedByAngleNotIntersecting.Count > 0)
              return kNearestOrderedByAngleNotIntersecting.First();
              }
        }
예제 #7
0
        public static IAABB CalulateAABB(this IPointCloud pointCloud)
        {
            var agg = pointCloud.Points.Aggregate(new
            {
                MinX = Double.PositiveInfinity,
                MinY = Double.PositiveInfinity,
                MinZ = Double.PositiveInfinity,
                MaxX = Double.NegativeInfinity,
                MaxY = Double.NegativeInfinity,
                MaxZ = Double.NegativeInfinity,
            }, (a, p) => new
            {
                MinX = Math.Min(a.MinX, p.Position.X),
                MinY = Math.Min(a.MinY, p.Position.Y),
                MinZ = Math.Min(a.MinZ, p.Position.Z),
                MaxX = Math.Max(a.MaxX, p.Position.X),
                MaxY = Math.Max(a.MaxY, p.Position.Y),
                MaxZ = Math.Max(a.MaxZ, p.Position.Z),
            });
            var min = new Vect3(agg.MinX, agg.MinY, agg.MinZ);
            var max = new Vect3(agg.MaxX, agg.MaxY, agg.MaxZ);

            return(new AABB((max + min) * 0.5f, (max - min) * 0.5f));
        }
        public virtual Task WritePointCloudToFileAsync(IAssetImporterExporter assetImporterExporter, IPointCloud pointCloud, string filePath)
        {
            var scene = PointCloudToSceneAdapter.GenerateSceneFromPointCloud(pointCloud);

            return(assetImporterExporter.ExportFileAsync(scene, filePath, true));
        }