Example #1
0
 public void Add(FeatureInfo other)
 {
     BoundingBox.Contain(other.BoundingBox);
     Extrusion += other.Extrusion;
     Duration += other.Duration;
     Distance += other.Distance;
     UnweightedCenterOfMass += other.UnweightedCenterOfMass;
 }
Example #2
0
        public AxisAlignedBox2d Bounds()
        {
            AxisAlignedBox2d box = AxisAlignedBox2d.Empty;

            foreach (Element e in vElements)
            {
                box.Contain(e.Bounds());
            }
            return(box);
        }
Example #3
0
        public AxisAlignedBox2d GetBounds()
        {
            if (vertices.Count == 0)
            {
                return(AxisAlignedBox2d.Empty);
            }
            AxisAlignedBox2d box = new AxisAlignedBox2d(vertices[0]);

            for (int i = 1; i < vertices.Count; ++i)
            {
                box.Contain(vertices[i]);
            }
            return(box);
        }
Example #4
0
        public static void CalculateUVs(this DMesh3 dMesh)
        {
            dMesh.EnableVertexUVs(Vector2f.Zero);
            OrthogonalPlaneFit3 orth          = new OrthogonalPlaneFit3(dMesh.Vertices());
            Frame3f             frame         = new Frame3f(orth.Origin, orth.Normal);
            AxisAlignedBox3d    bounds        = dMesh.CachedBounds;
            AxisAlignedBox2d    boundsInFrame = new AxisAlignedBox2d();

            for (int i = 0; i < 8; i++)
            {
                boundsInFrame.Contain(frame.ToPlaneUV((Vector3f)bounds.Corner(i), 3));
            }
            Vector2f min    = (Vector2f)boundsInFrame.Min;
            float    width  = (float)boundsInFrame.Width;
            float    height = (float)boundsInFrame.Height;

            for (int i = 0; i < dMesh.VertexCount; i++)
            {
                Vector2f UV = frame.ToPlaneUV((Vector3f)dMesh.GetVertex(i), 3);
                UV.x = (UV.x - min.x) / width;
                UV.y = (UV.y - min.y) / height;
                dMesh.SetVertexUV(i, UV);
            }
        }
Example #5
0
        /// <summary>
        /// This function is supposed to take a set of spans in a plane and sort them
        /// into regions that can be filled with a polygon. Currently kind of clusters
        /// based on intersecting bboxes. Does not work.
        ///
        /// I think fundamentally it needs to look back at the input mesh, to see what
        /// is connected/not-connected. Or possibly use polygon winding number? Need
        /// to somehow define what the holes are...
        /// </summary>
        List <List <EdgeSpan> > sort_planar_spans(List <EdgeSpan> allspans, Vector3d normal)
        {
            var result    = new List <List <EdgeSpan> >();
            var polyFrame = new Frame3f(Vector3d.Zero, normal);

            int N = allspans.Count;

            var plines = new List <PolyLine2d>();

            foreach (EdgeSpan span in allspans)
            {
                plines.Add(to_polyline(span, polyFrame));
            }

            bool[] bad_poly = new bool[N];
            for (int k = 0; k < N; ++k)
            {
                bad_poly[k] = false;                 // self_intersects(plines[k]);
            }

            bool[] used = new bool[N];
            for (int k = 0; k < N; ++k)
            {
                if (used[k])
                {
                    continue;
                }

                bool             is_bad = bad_poly[k];
                AxisAlignedBox2d bounds = plines[k].Bounds;
                used[k] = true;

                var set = new List <int>()
                {
                    k
                };

                for (int j = k + 1; j < N; ++j)
                {
                    if (used[j])
                    {
                        continue;
                    }

                    AxisAlignedBox2d boundsj = plines[j].Bounds;
                    if (bounds.Intersects(boundsj))
                    {
                        used[j] = true;
                        is_bad  = is_bad || bad_poly[j];
                        bounds.Contain(boundsj);
                        set.Add(j);
                    }
                }

                if (is_bad == false)
                {
                    var span_set = new List <EdgeSpan>();
                    foreach (int idx in set)
                    {
                        span_set.Add(allspans[idx]);
                    }

                    result.Add(span_set);
                }
            }

            return(result);
        }
Example #6
0
        // exports svg w/ different containments of point set (created by slicing mesh)
        public static void containment_demo_svg()
        {
            DMesh3 mesh = TestUtil.LoadTestInputMesh("bunny_solid.obj");

            MeshTransforms.Scale(mesh, 4);

            AxisAlignedBox3d meshBounds = mesh.CachedBounds;
            Vector3d         origin     = meshBounds.Center;

            origin -= 0.2 * meshBounds.Height * Vector3d.AxisY;
            Frame3f      plane = new Frame3f(origin, new Vector3d(1, 3, 0).Normalized);
            MeshPlaneCut cut   = new MeshPlaneCut(mesh, plane.Origin, plane.Z);

            cut.Cut();

            AxisAlignedBox2d polyBounds = AxisAlignedBox2d.Empty;
            List <Polygon2d> polys      = new List <Polygon2d>();

            foreach (EdgeLoop loop in cut.CutLoops)
            {
                Polygon2d poly = new Polygon2d();
                foreach (int vid in loop.Vertices)
                {
                    poly.AppendVertex(mesh.GetVertex(vid).xz);
                }
                poly.Rotate(new Matrix2d(90, true), Vector2d.Zero);
                polys.Add(poly);
                polyBounds.Contain(poly.Bounds);
            }

            SVGWriter svg       = new SVGWriter();
            var       polyStyle = SVGWriter.Style.Outline("red", 1.0f);
            var       contStyle = SVGWriter.Style.Outline("black", 1.0f);

            for (int k = 0; k < 3; ++k)
            {
                double          shift = (k == 2) ? 1.4f : 1.1f;
                Vector2d        tx    = (k - 1) * (polyBounds.Width * shift) * Vector2d.AxisX;
                List <Vector2d> pts   = new List <Vector2d>();
                foreach (Polygon2d poly in polys)
                {
                    var p2 = new Polygon2d(poly).Translate(tx);
                    pts.AddRange(p2.Vertices);
                    svg.AddPolygon(p2, polyStyle);
                }

                if (k == 0)
                {
                    ConvexHull2 hull = new ConvexHull2(pts, 0.001, QueryNumberType.QT_DOUBLE);
                    svg.AddPolygon(hull.GetHullPolygon(), contStyle);
                }
                else if (k == 1)
                {
                    ContMinBox2 contbox = new ContMinBox2(pts, 0.001, QueryNumberType.QT_DOUBLE, false);
                    svg.AddPolygon(new Polygon2d(contbox.MinBox.ComputeVertices()), contStyle);
                }
                else if (k == 2)
                {
                    ContMinCircle2 contcirc = new ContMinCircle2(pts);
                    svg.AddCircle(contcirc.Result, contStyle);
                }
            }


            svg.Write(TestUtil.GetTestOutputPath("contain_demos.svg"));
        }