Exemplo n.º 1
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            if (MeshSource == null)
            {
                throw new Exception("GenerateClosedMeshOp: must set valid MeshSource to compute!");
            }

            try {
                DMesh3 meshIn = new DMesh3(MeshSource.GetDMeshUnsafe());
                MergeCoincidentEdges merge = new MergeCoincidentEdges(meshIn)
                {
                    OnlyUniquePairs = this.OnlyUniquePairs,
                    MergeDistance   = this.MergeTolerance
                };
                if (merge.Apply() == false)
                {
                    throw new Exception("merge.Apply() returned false");
                }

                ResultMesh = meshIn;

                base.complete_update();
            } catch (Exception e) {
                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }
Exemplo n.º 2
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            Vector3d cache_start   = start_point;
            Vector3d cache_end     = end_point;
            bool     cache_through = through_hole;
            double   cache_depth   = hole_depth;

            if (MeshSource == null)
            {
                throw new Exception("GenerateClosedMeshOp: must set valid MeshSource to compute!");
            }

            int try_count = 0;
            int max_tries = 0;

try_again:

            try {
                Vector3d dir = (cache_end - cache_start).Normalized;
                if (dir.IsNormalized == false)
                {
                    throw new Exception("Invalid direction");
                }

                if (through_hole)
                {
                    ResultMesh = compute_through_hole(cache_start, cache_end, tolerance);
                }
                else
                {
                    ResultMesh = compute_partial_hole(cache_start, cache_start + cache_depth * dir, tolerance);
                }


                base.complete_update();
            } catch (Exception e) {
                if (try_count < max_tries)
                {
                    try_count++;
                    goto try_again;
                }

                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }
Exemplo n.º 3
0
        public virtual void Update()
        {
            base.begin_update();

            if (MeshSource == null)
            {
                throw new Exception("MeshScaleOp: must set valid MeshSource to compute!");
            }

            DMesh3 mesh = (CopyInput) ? new DMesh3(MeshSource.GetDMeshUnsafe()) : MeshSource.ExtractDMesh();

            if (ScaleFactor == 1.0)
            {
                ScaledMesh = mesh;
                base.complete_update();
                return;
            }

            gParallel.ForEach(mesh.VertexIndices(), (vid) => {
                Vector3d v = mesh.GetVertex(vid);
                v         -= scale_origin;
                v         *= scale_factor;
                v         += scale_origin;
                mesh.SetVertex(vid, v);
            });

            ScaledMesh = mesh;
            base.complete_update();
        }
Exemplo n.º 4
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            if (MeshSource == null)
            {
                throw new Exception("MeshShellOp: must set valid MeshSource to compute!");
            }

            try {
                ResultMesh = null;

                DMesh3 meshIn = MeshSource.GetDMeshUnsafe();
                input_spatial = MeshSource.GetSpatial() as DMeshAABBTree3;
                if (meshIn.ShapeTimestamp != input_mesh_cache_timestamp)
                {
                    cached_is_closed = meshIn.IsClosed();
                    MeshQueries.EdgeLengthStats(meshIn, out input_mesh_edge_stats.x, out input_mesh_edge_stats.y, out input_mesh_edge_stats.z);
                    if (input_spatial == null)
                    {
                        input_spatial = new DMeshAABBTree3(meshIn, false);
                    }
                    input_mesh_cache_timestamp = meshIn.ShapeTimestamp;
                }

                if (shell_type == ShellTypes.DistanceField)
                {
                    compute_shell_distancefield();
                }
                else
                {
                    compute_shell_extrude();
                }

                if (ResultMesh.TriangleCount == 0)
                {
                    ResultMesh = base.make_failure_output(null);
                }

                base.complete_update();
            } catch (Exception e) {
                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }
Exemplo n.º 5
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            if (MeshSource == null)
            {
                throw new Exception("RemoveHiddenFacesOp: must set valid MeshSource to compute!");
            }

            try {
                DMesh3 meshIn = MeshSource.GetDMeshUnsafe();
                if (cachedSpatial == null || spatial_cache_timstamp != meshIn.ShapeTimestamp)
                {
                    cachedSpatial = new DMeshAABBTreePro(meshIn, true);
                    cachedSpatial.FastWindingNumber(Vector3d.Zero);
                    spatial_cache_timstamp = meshIn.ShapeTimestamp;
                }
                DMesh3 editMesh = new DMesh3(meshIn);

                RemoveOccludedTriangles remove = new RemoveOccludedTriangles(editMesh, cachedSpatial)
                {
                    InsideMode = (RemoveOccludedTriangles.CalculationMode)(int) inside_mode,
                    PerVertex  = all_hidden_vertices
                };
                remove.Progress = new ProgressCancel(is_invalidated);

                if (remove.Apply() == false)
                {
                    ResultMesh     = null;
                    RemovedTris    = null;
                    RemovedSubmesh = null;
                }
                else
                {
                    ResultMesh     = editMesh;
                    RemovedTris    = remove.RemovedT;
                    RemovedSubmesh = new DSubmesh3(MeshSource.GetDMeshUnsafe(), RemovedTris);
                }

                base.complete_update();
            } catch (Exception e) {
                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }
Exemplo n.º 6
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            if (MeshSource == null)
            {
                throw new Exception("GenerateBlockSupportsOp: must set valid MeshSource to compute!");
            }

            try {
                ResultMesh = null;

                DMesh3 mesh = MeshSource.GetDMeshUnsafe();

                BlockSupportGenerator supportgen = new BlockSupportGenerator(mesh, GridCellSize);
                supportgen.OverhangAngleDeg   = this.overhang_angle;
                supportgen.ForceMinY          = (float)this.min_y;
                supportgen.SubtractMesh       = this.subtract_input;
                supportgen.SubtractMeshOffset = this.SubtractOffsetDistance;
                supportgen.Generate();

                if (is_invalidated())
                {
                    goto skip_to_end;
                }

                ResultMesh = supportgen.SupportMesh;
                Reducer reducer = new Reducer(ResultMesh);
                reducer.Progress = new ProgressCancel(is_invalidated);
                reducer.ReduceToEdgeLength(GridCellSize / 2);

skip_to_end:
                if (is_invalidated())
                {
                    ResultMesh = null;
                }
                base.complete_update();
            } catch (Exception e) {
                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }
Exemplo n.º 7
0
        DMeshAABBTree3 get_cached_spatial()
        {
            if (MeshSource.HasSpatial)
            {
                if (MeshSource.GetSpatial() is DMeshAABBTree3)
                {
                    return(MeshSource.GetSpatial() as DMeshAABBTree3);
                }
            }
            DMesh3 mesh = MeshSource.GetDMeshUnsafe();

            if (internal_spatial != null && spatial_timestamp == mesh.ShapeTimestamp)
            {
                return(internal_spatial);
            }
            internal_spatial  = new DMeshAABBTree3(mesh, true);
            spatial_timestamp = mesh.ShapeTimestamp;
            return(internal_spatial);
        }
Exemplo n.º 8
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            if (MeshSource == null)
            {
                throw new Exception("RemeshOp: must set valid MeshSource to compute!");
            }

            try {
                ResultMesh = update_standard();

                base.complete_update();
            } catch (Exception e) {
                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }
Exemplo n.º 9
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            if (MeshSource == null)
            {
                throw new Exception("GenerateClosedMeshOp: must set valid MeshSource to compute!");
            }

            try {
                ResultMesh = null;

                DMesh3 meshIn = MeshSource.GetDMeshUnsafe();
                input_spatial = MeshSource.GetSpatial() as DMeshAABBTree3;
                if (meshIn.ShapeTimestamp != input_mesh_cache_timestamp)
                {
                    cached_is_closed = meshIn.IsClosed();
                    MeshQueries.EdgeLengthStats(meshIn, out input_mesh_edge_stats.x, out input_mesh_edge_stats.y, out input_mesh_edge_stats.z);
                    if (input_spatial == null)
                    {
                        input_spatial = new DMeshAABBTree3(meshIn, false);
                    }
                    input_mesh_cache_timestamp = meshIn.ShapeTimestamp;
                }

                if (closing_type == ClosingTypes.LevelSet)
                {
                    update_level_set();
                }
                else if (closing_type == ClosingTypes.WindingNumberGrid)
                {
                    if (cached_is_closed)
                    {
                        update_winding();
                    }
                    else
                    {
                        update_winding_fast();
                    }
                }
                else
                {
                    update_winding_exact();
                }

                base.complete_update();
            } catch (Exception e) {
                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }
Exemplo n.º 10
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            Vector3d cache_normal     = PlaneNormal;
            Vector3d cache_origin     = PlaneOrigin;
            bool     cache_fill_holes = FillHoles;
            double   cache_tolerance  = Tolerance;
            bool     cache_min_fill   = MinimalFill;
            double   cache_fill_len   = (MinimalFill) ? double.MaxValue : FillEdgeLength;
            bool     cache_both       = ReturnBothSides;

            if (reverse_normal)
            {
                cache_normal = -cache_normal;
            }

            if (MeshSource == null)
            {
                throw new Exception("GenerateClosedMeshOp: must set valid MeshSource to compute!");
            }

            int try_count = 0;
            int max_tries = (cache_min_fill) ? 0 : 3;

try_again:

            ResultMesh          = null;
            OtherSideResultMesh = null;

            try {
                bool fill_errors;
                ResultMesh = compute_cut(cache_origin, cache_normal, cache_tolerance, cache_fill_holes, cache_fill_len, out fill_errors);

                bool fill_errors_otherside = false;
                if (cache_both)
                {
                    OtherSideResultMesh = compute_cut(cache_origin, -cache_normal, cache_tolerance, cache_fill_holes, cache_fill_len, out fill_errors_otherside);
                }
                else
                {
                    OtherSideResultMesh = null;
                }

                if (fill_errors || fill_errors_otherside)
                {
                    throw new Exception("fill_errors");
                    //ResultMesh = base.make_failure_output(ResultMesh, false);
                }

                base.complete_update();
            } catch (Exception e) {
                if (try_count < max_tries)
                {
                    cache_fill_len *= 2;
                    try_count++;
                    goto try_again;
                }
                else if (try_count == max_tries)
                {
                    cache_fill_len = double.MaxValue;
                    try_count++;
                    goto try_again;
                }

                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }
Exemplo n.º 11
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            if (MeshSource == null)
            {
                throw new Exception("CombineMeshesOp: must set valid MeshSource to compute!");
            }

            ResultMesh = null;

            try {
                DMesh3 meshIn = new DMesh3(MeshSource.GetDMeshUnsafe());

                if (orient_nested_shells)
                {
                    MeshConnectedComponents comp = new MeshConnectedComponents(meshIn);
                    comp.FindConnectedT();
                    DSubmesh3Set subMeshes = new DSubmesh3Set(meshIn, comp);

                    List <DMesh3> curMeshes = new List <DMesh3>();
                    foreach (var submesh in subMeshes)
                    {
                        curMeshes.Add(submesh.SubMesh);
                    }

                    MeshSpatialSort sort = new MeshSpatialSort();
                    foreach (var mesh in curMeshes)
                    {
                        sort.AddMesh(mesh, mesh);
                    }
                    sort.Sort();

                    ResultMesh = new DMesh3();
                    MeshEditor editor = new MeshEditor(ResultMesh);
                    foreach (var solid in sort.Solids)
                    {
                        DMesh3 outer = solid.Outer.Mesh;
                        if (!is_outward_oriented(outer))
                        {
                            outer.ReverseOrientation();
                        }
                        editor.AppendMesh(outer, ResultMesh.AllocateTriangleGroup());

                        foreach (var hole in solid.Cavities)
                        {
                            if (hole.Mesh.CachedIsClosed && is_outward_oriented(hole.Mesh) == true)
                            {
                                hole.Mesh.ReverseOrientation();
                            }
                            editor.AppendMesh(hole.Mesh, ResultMesh.AllocateTriangleGroup());
                        }
                    }
                }
                else
                {
                    ResultMesh = meshIn;
                }

                base.complete_update();
            } catch (Exception e) {
                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }