Beispiel #1
0
        public static ComponentProblem Add(ref ComponentProblems problems, BrepEdge edge, BrepTrim trim, string problem, ComponentProblemTypes type, object data = null)
        {
            var componentReal = new ComponentIndex(ComponentIndexType.BrepEdge, edge.EdgeIndex);
            var componentGUI  = new ComponentIndex(ComponentIndexType.BrepEdge, trim.TrimIndex);

            return(Add(ref problems, componentReal, componentGUI, problem, type, data));
        }
Beispiel #2
0
        public static ComponentProblem Add(ref ComponentProblems problems, Mesh mesh, string problem, ComponentProblemTypes type, object data = null)
        {
            //var componentReal = new ComponentIndex(ComponentIndexType.MeshFace, 0);

            var componentReal = mesh != null?mesh.ComponentIndex() : new ComponentIndex(ComponentIndexType.MeshFace, 0);

            return(Add(ref problems, componentReal, componentReal, problem, type, data));
        }
Beispiel #3
0
        private static ComponentProblem Add(ref ComponentProblems problems, ComponentIndex componentReal, ComponentIndex componentGUI, string problem, ComponentProblemTypes type, object data = null)
        {
            if (problems == null)
            {
                problems = new ComponentProblems();
            }
            var res = problems.AddProblem(componentReal, componentGUI, problem, type, data);

            return(res);
        }
Beispiel #4
0
        public ComponentProblems Select(Func <ComponentProblem, bool> filter)
        {
            var ps = Problems.Where(filter).ToList();

            if (ps.Count == 0)
            {
                return(null);
            }
            var res = new ComponentProblems();

            res.Problems.AddRange(ps);
            return(res);
        }
Beispiel #5
0
 public static void AddRange(ref ComponentProblems problems, ComponentProblems newProblems)
 {
     if (newProblems == null)
     {
         return;
     }
     if (problems == null)
     {
         problems = new ComponentProblems();
     }
     problems.Problems.AddRange(newProblems.Problems);
     problems.IsProblemsSorted = false;
     problems.fixWhat          = null;
 }
Beispiel #6
0
        public static ComponentProblem Add(ref ComponentProblems problems, BrepVertex vertex, string problem, ComponentProblemTypes type, object data = null)
        {
            var componentReal = new ComponentIndex(ComponentIndexType.BrepVertex, vertex.VertexIndex);

            return(Add(ref problems, componentReal, componentReal, problem, type, data));
        }
Beispiel #7
0
 public static ComponentProblem Add(ref ComponentProblems problems, string problem, ComponentProblemTypes type, object data = null)
 {
     return(Add(ref problems, ComponentIndex.Unset, ComponentIndex.Unset, problem, type, data));
 }
Beispiel #8
0
        public FixWhat(ComponentProblems problems = null)
        {
            Problems = problems ?? new ComponentProblems();

            foreach (var p in Problems.Problems)
            {
                // some problems cannot be fixed, but to norify user they must be present in GUI
                if (p.IsFixable.HasValue && !p.IsFixable.Value)
                {
                    HasNotFixableProblem = true;
                    if (!String.IsNullOrEmpty(FixableFailReasons))
                    {
                        FixableFailReasons += "; ";
                    }
                    FixableFailReasons += p.FixableFailReason;
                    continue;
                }

                bool found = true;
                switch (p.Type)
                {
                //
                //Vertex
                //
                case ComponentProblemTypes.VertexFarFromEdges:
                    VertexRebuild = true;
                    break;
                //case ComponentProblemTypes.VertexFarFromTrims:
                //    is filtered out in method 'ComponentProblemFinder.PostProcess_VertexFarFromTrims
                //    this issue is transformed into FaceRebuildUV or eliminated
                //    break;

                //
                //Face
                //
                case ComponentProblemTypes.FaceDomainLengthIsVerySmall:
                    FaceDomainSet01 = true;
                    break;

                case ComponentProblemTypes.FaceRebuildUV:
                    FaceRebuildUV = true;
                    break;

                case ComponentProblemTypes.FaceRedundantSeam:
                    FaceRedundantSeam = true;
                    break;

                case ComponentProblemTypes.FaceRedundantSingularity:
                    FaceRedundantSingularity = true;
                    break;

                case ComponentProblemTypes.FaceHasKinks:
                    FaceRebuildSurface = true;
                    break;

                //
                //Trim
                //
                case ComponentProblemTypes.TrimInvalidIsoStatus:
                    TrimFixSingularity = true;
                    break;

                case ComponentProblemTypes.TrimDoubleIsoStatuses:
                    TrimFixDoubleSingularity = true;
                    break;

                case ComponentProblemTypes.TrimEndBeginMismatch:
                    TrimEndBeginMismatch = true;
                    break;

                case ComponentProblemTypes.TrimUVOutOfFaceDomain:
                    TrimUVOutOfDomain = true;
                    break;

                case ComponentProblemTypes.TrimControlPointsNotCorrectInSeam:
                    TrimFixSeamControlPoints = true;
                    break;

                case ComponentProblemTypes.TrimControlPointsNotCorrectInSingularity:
                    TrimFixSingularity = true;
                    break;

                case ComponentProblemTypes.TrimControlPointsCanBeSimplified:
                    TrimSimplifyControlPoints = true;
                    break;

                case ComponentProblemTypes.TrimZigZagControlpoints:
                    TrimZigZag = true;
                    break;

                //
                // Edge
                //
                case ComponentProblemTypes.EdgeStartAndEndVertexesSame:
                    VertexRebuild = true;
                    break;

                case ComponentProblemTypes.EdgeIsClosedButNoUniquInLoop:
                case ComponentProblemTypes.EdgeIsClosedButEndAndStartPointsAreFar:
                    RemoveClosed = true;
                    break;

                case ComponentProblemTypes.EdgeVerySmall:
                    // problem is not fixable - it comes from ComponentProblemFinder which dont know about topology, but this problem can be solved only knowing topology
                    found = false;
                    break;

                case ComponentProblemTypes.EdgeVerySmallUnatached:
                    // problem is fixable - it comes from GeomFaceProblemFinder which already know about topology
                    EdgeRemoveSmallUnatached = true;
                    break;

                case ComponentProblemTypes.EdgeInvalidDomainLength:
                    EdgeRecreateFromTrim = true;
                    break;

                case ComponentProblemTypes.EdgeCrossIntersection:
                    EdgeRecreateFromTrim = true;
                    break;

                case ComponentProblemTypes.EdgeHasKinks:
                    EdgeRemoveKinks = true;
                    break;

                case ComponentProblemTypes.EdgeZigZagControlpoints:
                    EdgeRemoveZigZags = true;
                    break;

                case ComponentProblemTypes.EdgeControlPointsCanBeSimplified:
                    EdgeSimplifyControlPoints = true;
                    break;

                case ComponentProblemTypes.EdgeNeedJoin:
                    EdgeNeedJoin = true;
                    break;

                default:
                    found = false;
                    break;
                }

                if (found)
                {
                    HasFixableProblem = true;
                }
                else
                {
                    HasNotFixableProblem = true;
                    FixableFailReasons   = Shared.AUTOFIX_NOT_IMPLEMENTED;
                }
            }

            // one of these options must be disabled - lets give priority to Edges - they usually more correct
            if (EdgeRecreateFromTrim && TrimRecreateFromEdge)
            {
                EdgeRecreateFromTrim = false;
                TrimRecreateFromEdge = true;
            }
        }
Beispiel #9
0
 public void Close()
 {
     Problems = null;
 }
        public static void Find(ref ComponentProblems res, Mesh mesh, int maxAllowedDisjointMeshCount = 0)
        {
            //
            // Empty mesh
            //
            if (mesh == null || mesh.Faces.Count == 0)
            {
                var problem = "Mesh is empty";
                ComponentProblems.Add(ref res, mesh, problem, ComponentProblemTypes.MeshIsEmpty);
            }

            if (mesh == null)
            {
                return;
            }


            if (mesh.DisjointMeshCount > maxAllowedDisjointMeshCount)
            {
                var problem = "Found {0} disjoint mesh faces"._Format(mesh.DisjointMeshCount);
                ComponentProblems.Add(ref res, mesh, problem, ComponentProblemTypes.MeshHasDisjoints);
            }


            //
            // Invalid mesh
            //
            string invalidLog;

            if (mesh.Faces.Count != 0 && // this is already checked in ComponentProblemTypes.MeshIsEmpty
                !mesh.IsValidWithLog(out invalidLog))
            {
                var problem = "Mesh is invalid: {0}"._Format(invalidLog);
                ComponentProblems.Add(ref res, mesh, problem, ComponentProblemTypes.MeshIsEmpty);
            }

            //
            // Invalid faces
            //
            var vertexesCount     = mesh.Vertices.Count;
            var invalidFacesCount = 0;

            foreach (var f in mesh.Faces)
            {
                if (!f.IsValid(vertexesCount) ||
                    (!f.IsTriangle && !f.IsQuad) ||
                    (f.IsTriangle && f.IsQuad))
                {
                    invalidFacesCount++;
                    continue;
                }

                var count = 0;
                if (f.IsTriangle)
                {
                    count = 3;
                }
                else if (f.IsQuad)
                {
                    count = 4;
                }
                for (int i = 0; i < count; i++)
                {
                    var vertexIndex = f[i];
                    if (vertexIndex < 0 || vertexIndex >= vertexesCount)
                    {
                        invalidFacesCount++;
                        continue;
                    }
                }
            }
            if (invalidFacesCount > 0)
            {
                var problem = "Mesh has {0} invalid faces."._Format(invalidFacesCount);
                ComponentProblems.Add(ref res, mesh, problem, ComponentProblemTypes.MeshHasInvalidFaces);
            }


            //
            // Unattached vertices
            //
            var vertexesUsed            = GetVertexesUsed(mesh);
            var unattachedVerticesCount = vertexesUsed.Count(o => !o);

            if (unattachedVerticesCount > 0)
            {
                var problem = "Mesh has {0} unattached vertices."._Format(unattachedVerticesCount);
                ComponentProblems.Add(ref res, mesh, problem, ComponentProblemTypes.MeshHasUnattachedVertices);
            }

            //
            // Flipped faces
            //
            //TODO: implement
        }