private static void EdgesLeadToDesiredFaceCatFinder(FaceWithScores face, PrimitiveSurfaceType p, List <List <int> > faceRules) { // This function takes a face and a possible category and returns // edges which lead to that category // We need to define some rules. for example, if the p is F, with // combination of F F SE, then return edges of F and F. //eltc = [faceRules[4][i],faceRules[5][i],faceRules[6][i]]; var edges = new List <Edge>(); var com = face.CatToCom[p]; var edgesFD = new Edge[3]; ///////////////////////////////////////////////////////////////////// // Checking the equality of 2 arrays: com and comb foreach (var comb in face.ComToEdge.Keys) { var counter = 0; var list = new List <int>(); for (var m = 0; m < 3; m++) { for (var n = 0; n < 3; n++) { if (!list.Contains(n)) { if (com[m] == comb[n]) { counter++; list.Add(n); break; } } } } bool equals = counter == 3; if (@equals) { for (int i = 0; i < 3; i++) { edgesFD[i] = face.ComToEdge[comb][i]; } } } ///////////////////////////////////////////////////////////////////// for (var i = 0; i < faceRules[0].Count; i++) { var arrayOfRule = new[] { faceRules[0][i], faceRules[1][i], faceRules[2][i] }; /*var q = from a in com * join b in arrayOfRule on a equals b * select a; * bool equals = com.Length == arrayOfRule.Length && q.Count() == com.Length;*/ // Checking the equality of 2 arrays:com and arrayOfRules var counter = 0; var list = new List <int>(); for (var m = 0; m < 3; m++) { for (var n = 0; n < 3; n++) { if (!list.Contains(n)) { if (com[m] == arrayOfRule[n]) { counter++; list.Add(n); break; } } } } bool equals = counter == 3; arrayOfRule.OrderBy(n => n).ToArray(); if (@equals) { var EdgesLead = new[] { faceRules[4][i], faceRules[5][i], faceRules[6][i] }; var SortedEL = EdgesLead.OrderBy(n => n).ToArray(); for (var t = 0; t < 3; t++) //foreach (var EL in SortedEL.Where(a => a != 1000)) { if (SortedEL[t] == 1000) { continue; } //var index = Array.IndexOf(SortedEL, EL); edges.Add(edgesFD[t]); } break; //return edges; } } face.CatToELDC.Add(p, edges); //return null; }
private static List <PlanningSurface> groupFacesIntoPlanningSurfaces(FaceWithScores seedFace, List <FaceWithScores> allFacesWithScores) { // candidatePatches are where we store successful surfaces that start on the stackOfPotentialPrimitives // they are collected here and returned to the main classification method var candidatePatches = new List <PlanningSurface>(); // the outer depthfirst search builds stackOfPotentialPatches, which acts as seeds to the inner DFS. // While on this stack, all surfaces ONLY have one face - which is the start to // the inner DFS. Once an inner DFS ends, its successful result is added to candidatePatches. var stackOfPotentialPatches = new Stack <PlanningSurface>(); // put possible start states on the stack starting with the seedface. But don't start with faces that // are too small or have not //if (seedFace.Face.Area < Parameters.Classifier_MinAreaForStartFace || seedFace.CatToCom.Count == 0) // return new List<PlanningSurface>(); foreach (var faceCat in seedFace.FaceCat.Keys) { stackOfPotentialPatches.Push(new PlanningSurface(faceCat, seedFace)); } while (stackOfPotentialPatches.Any()) { var primitive = stackOfPotentialPatches.Pop(); var type = primitive.SurfaceType; if (AlreadySearchedPrimitive(primitive, candidatePatches)) { continue; } // start new depth first search on this primitive var innerStack = new Stack <FaceWithScores>(); innerStack.Push(primitive.Faces[0]); while (innerStack.Any()) { var openBranchFace = innerStack.Pop(); foreach (var eachEdge in openBranchFace.CatToELDC[type]) { var child = (eachEdge.OwnedFace == openBranchFace.Face) ? allFacesWithScores.First(f => f.Face == eachEdge.OtherFace) : allFacesWithScores.First(f => f.Face == eachEdge.OwnedFace); if (primitive.Faces.Contains(child)) { continue; } if (child.FaceCat == null) { continue; // you've moved onto a dense or bad face } if (!child.CatToCom.ContainsKey(type)) { continue; } if (child.FaceCat.ContainsKey(type)) { child.CatToCom.Remove(type); primitive.Add(child); innerStack.Push(child); } // else foreach (var surfaceType in child.FaceCat.Keys .Where(surfaceType => !stackOfPotentialPatches.Any(p => p.SurfaceType == surfaceType && p.Faces[0] == child))) { stackOfPotentialPatches.Push(new PlanningSurface(surfaceType, child)); } } } candidatePatches.Add(primitive); } Debug.WriteLine("new patches: " + candidatePatches.Count + " -- comprised of #faces: " + candidatePatches.SelectMany(cp => cp.Faces).Distinct().Count()); return(candidatePatches); }
private static void FaceFuzzyClassification(FaceWithScores eachFace, List <EdgeWithScores> allEdgeWithScores) { var c = 0; List <Dictionary <int, double> > t = eachFace.Face.Edges.Select(e => allEdgeWithScores.First(ews => ews.Edge == e).CatProb).ToList(); eachFace.FaceCat = new Dictionary <PrimitiveSurfaceType, double>(); eachFace.CatToCom = new Dictionary <PrimitiveSurfaceType, int[]>(); eachFace.ComToEdge = new Dictionary <int[], Edge[]>(); if (t[0] != null) { for (var i = 0; i < t[0].Count; i++) { if (t[1] == null) { break; } for (var j = 0; j < t[1].Count; j++) { if (t[2] == null) { break; } for (var k = 0; k < t[2].Count; k++) { var combination = new[] { t[0].ToList()[i].Key, t[1].ToList()[j].Key, t[2].ToList()[k].Key }; var a = new double[3]; a[0] = t[0].ToList()[i].Value; a[1] = t[1].ToList()[j].Value; a[2] = t[2].ToList()[k].Value; double totProb = 1; var co = 0; foreach (var ar in a.Where(p => p != 1)) { totProb = totProb * (1 - ar); co++; } if (co == 0) { totProb = 1; } else { totProb = 1 - totProb; } //var totProb = 1-((1-t[0].ToList()[i].Value) * (1-t[1].ToList()[j].Value) * (1-t[2].ToList()[k].Value)); //var combAndEdge = new Dictionary<int[], EdgeWithScores[]>(); //CanCom.Add(combination, totProb); var edges = new[] { eachFace.Face.Edges[0], eachFace.Face.Edges[1], eachFace.Face.Edges[2] }; //combAndEdge.Add(combination.OrderBy(n=>n).ToArray(),edges); var faceCat = FaceClassifier(combination, faceRules); if (!eachFace.FaceCat.ContainsKey(faceCat)) { eachFace.FaceCat.Add(faceCat, totProb); eachFace.CatToCom.Add(faceCat, combination.OrderBy(n => n).ToArray()); eachFace.ComToEdge.Add(combination, edges); eachFace.ComToEdge = sortingComToEdgeDic(eachFace.ComToEdge); //eachFace.ComEdge.Add(faceCat, combAndEdge); } else { if (!(eachFace.FaceCat[faceCat] < totProb)) { continue; } eachFace.FaceCat[faceCat] = totProb; eachFace.ComToEdge.Remove(eachFace.CatToCom[faceCat]); eachFace.CatToCom[faceCat] = combination.OrderBy(n => n).ToArray(); eachFace.ComToEdge.Add(combination, edges); eachFace.ComToEdge = sortingComToEdgeDic(eachFace.ComToEdge); //eachFace.ComEdge[faceCat] = combAndEdge; } } } } } }