private void RemoveUnconnectedParts(ref Cl3DModel p_Model) { if (p_Model.ModelType != "wrl") { throw new Exception("Only WRL models are supported by this method - IV2 Data set"); } List <List <Cl3DModel.Cl3DModelPointIterator> > listOfRegions = new List <List <Cl3DModel.Cl3DModelPointIterator> >(); List <Cl3DModel.Cl3DModelPointIterator> ListToCheck = new List <Cl3DModel.Cl3DModelPointIterator>(); List <Cl3DModel.Cl3DModelPointIterator> newListToCheck = new List <Cl3DModel.Cl3DModelPointIterator>(); Cl3DModel.Cl3DModelPointIterator iter = null; int listNo = 0; while ((iter = findNextUnseenElement(ref p_Model)) != null) { ListToCheck.Add(iter); listOfRegions.Add(new List <Cl3DModel.Cl3DModelPointIterator>()); do { foreach (Cl3DModel.Cl3DModelPointIterator ElementFromListToCheck in ListToCheck) { if (!ElementFromListToCheck.AlreadyVisited) { listOfRegions[listNo].Add(ElementFromListToCheck); ElementFromListToCheck.AlreadyVisited = true; foreach (Cl3DModel.Cl3DModelPointIterator it in ElementFromListToCheck.GetListOfNeighbors()) { if (!it.AlreadyVisited) { newListToCheck.Add(it); } } } } ListToCheck.Clear(); foreach (Cl3DModel.Cl3DModelPointIterator it in newListToCheck) { ListToCheck.Add(it); } newListToCheck.Clear(); } while (ListToCheck.Count != 0); ListToCheck.Clear(); listNo++; } if (listOfRegions.Count <= 1) { return; } int maxCount = listOfRegions[0].Count;; int maxI = 0; for (int i = 1; i < listOfRegions.Count; i++) { if (listOfRegions[i].Count > maxCount) { maxI = i; maxCount = listOfRegions[i].Count; } } for (int i = 0; i < listOfRegions.Count; i++) { if (i == maxI) { continue; } for (int j = 0; j < listOfRegions[i].Count; j++) { p_Model.RemovePointFromModel(listOfRegions[i][j]); } } }
protected override void Algorithm(ref Cl3DModel p_Model) { RemoveUnconnectedParts(ref p_Model); p_Model.ResetVisitedPoints(); List <List <Cl3DModel.Cl3DModelPointIterator> > listOfHoles = new List <List <Cl3DModel.Cl3DModelPointIterator> >(); List <Cl3DModel.Cl3DModelPointIterator> ListToCheck = new List <Cl3DModel.Cl3DModelPointIterator>(); List <Cl3DModel.Cl3DModelPointIterator> newListToCheck = new List <Cl3DModel.Cl3DModelPointIterator>(); Cl3DModel.Cl3DModelPointIterator iter = null; int listNo = 0; while ((iter = GetRandomUnseenPointOfHole(ref p_Model)) != null) { ListToCheck.Add(iter); listOfHoles.Add(new List <Cl3DModel.Cl3DModelPointIterator>()); do { foreach (Cl3DModel.Cl3DModelPointIterator ElementFromListToCheck in ListToCheck) { if (!ElementFromListToCheck.AlreadyVisited && ElementFromListToCheck.GetListOfNeighbors().Count < 8) { listOfHoles[listNo].Add(ElementFromListToCheck); ElementFromListToCheck.AlreadyVisited = true; foreach (Cl3DModel.Cl3DModelPointIterator it in ElementFromListToCheck.GetListOfNeighbors()) { if (!it.AlreadyVisited && it.GetListOfNeighbors().Count < 8) { newListToCheck.Add(it); } } } } ListToCheck.Clear(); foreach (Cl3DModel.Cl3DModelPointIterator it in newListToCheck) { ListToCheck.Add(it); } newListToCheck.Clear(); } while (ListToCheck.Count != 0); ListToCheck.Clear(); listNo++; } //-------------------------------- End of searching holes //-------------------------------- Removing the longest hole - border of the face if (listOfHoles.Count == 0) { return; } int maxCount = listOfHoles[0].Count;; int maxI = 0; for (int i = 1; i < listOfHoles.Count; i++) { if (listOfHoles[i].Count > maxCount) { maxI = i; maxCount = listOfHoles[i].Count; } } listOfHoles.RemoveAt(maxI); //-------------------------------- End of removing the longest hole if (m_bColorIt) { for (int i = 0; i < listOfHoles.Count; i++) { for (int j = 0; j < listOfHoles[i].Count; j++) { listOfHoles[i][j].Color = Color.FromArgb(255, 0, 255);//ClTools.GetColorRGB(((float)i) / listOfHoles.Count, 1); } } } p_Model.ResetVisitedPoints(); //----------------- Fill holes foreach (List <Cl3DModel.Cl3DModelPointIterator> hole in listOfHoles) { double A = 0; double B = 0; double C = 0; double D = 0; double E = 0; double F = 0; List <Cl3DModel.Cl3DModelPointIterator> holeToEstimateSurface = new List <Cl3DModel.Cl3DModelPointIterator>(); foreach (Cl3DModel.Cl3DModelPointIterator it in hole) // we are adding new points to other list becouse all the time its used to aproximate surface { holeToEstimateSurface.Add(it.CopyIterator()); it.AlreadyVisited = true; List <Cl3DModel.Cl3DModelPointIterator> Neighborhood; ClTools.GetNeighborhoodWithGeodesicDistance(out Neighborhood, it, 20); foreach (Cl3DModel.Cl3DModelPointIterator Neighbor in Neighborhood) { if (!Neighbor.AlreadyVisited) { holeToEstimateSurface.Add(Neighbor); Neighbor.AlreadyVisited = true; } } } List <Cl3DModel.Cl3DModelPointIterator> PointsOfHole = new List <Cl3DModel.Cl3DModelPointIterator>(); List <Cl3DModel.Cl3DModelPointIterator> SortedPointsOfHole = new List <Cl3DModel.Cl3DModelPointIterator>(); foreach (Cl3DModel.Cl3DModelPointIterator itOut in hole) { SortedPointsOfHole.Add(itOut.CopyIterator()); foreach (Cl3DModel.Cl3DModelPointIterator itIn in hole) { if (itIn.PointID == itOut.PointID) { continue; } float NewPointX = itOut.X; float NewPointY = itIn.Y; bool exist = false; Cl3DModel.Cl3DModelPointIterator ExistPoint = p_Model.GetIterator(); if (!ExistPoint.IsValid()) { throw new Exception("Iterator in Model isn't valid"); } do { if (Math.Abs(ExistPoint.X - NewPointX) < m_Delta && Math.Abs(ExistPoint.Y - NewPointY) < m_Delta) { exist = true; break; } } while (ExistPoint.MoveToNext()); if (!exist) { if (!ClTools.CountSurfaceCoefficients(holeToEstimateSurface, ref A, ref B, ref C, ref D, ref E, ref F)) { throw new Exception("Cannot calculate surface coefficients"); } float NewPointZ = (float)(A + B * NewPointX + C * NewPointY + D * NewPointX * NewPointX + E * NewPointX * NewPointY + F * NewPointY * NewPointY); Cl3DModel.Cl3DModelPointIterator newPoint = p_Model.AddPointToModel(NewPointX, NewPointY, NewPointZ); holeToEstimateSurface.Add(newPoint.CopyIterator()); PointsOfHole.Add(newPoint.CopyIterator()); SortedPointsOfHole.Add(newPoint.CopyIterator()); if (m_bColorIt) { newPoint.Color = Color.Pink; } } } } foreach (Cl3DModel.Cl3DModelPointIterator iterPoint in PointsOfHole) { SortedPointsOfHole.Sort(new Compare2DDistance(iterPoint)); iterPoint.AddNeighbor(SortedPointsOfHole[1]); iterPoint.AddNeighbor(SortedPointsOfHole[2]); iterPoint.AddNeighbor(SortedPointsOfHole[3]); iterPoint.AddNeighbor(SortedPointsOfHole[4]); iterPoint.AddNeighbor(SortedPointsOfHole[5]); iterPoint.AddNeighbor(SortedPointsOfHole[6]); iterPoint.AddNeighbor(SortedPointsOfHole[7]); iterPoint.AddNeighbor(SortedPointsOfHole[8]); } } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator tmpIter = p_Model.GetIterator(); while (tmpIter.IsValid()) { if (tmpIter.GetListOfNeighbors().Count <= 1) { tmpIter = p_Model.RemovePointFromModel(tmpIter); } else { if (!tmpIter.MoveToNext()) { break; } } } List <List <Cl3DModel.Cl3DModelPointIterator> > listOfRegions = new List <List <Cl3DModel.Cl3DModelPointIterator> >(); List <Cl3DModel.Cl3DModelPointIterator> ListToCheck = new List <Cl3DModel.Cl3DModelPointIterator>(); List <Cl3DModel.Cl3DModelPointIterator> newListToCheck = new List <Cl3DModel.Cl3DModelPointIterator>(); Cl3DModel.Cl3DModelPointIterator iter = null; int listNo = 0; while ((iter = findNextUnseenElement(ref p_Model)) != null) { ListToCheck.Add(iter); listOfRegions.Add(new List <Cl3DModel.Cl3DModelPointIterator>()); do { foreach (Cl3DModel.Cl3DModelPointIterator ElementFromListToCheck in ListToCheck) { if (!ElementFromListToCheck.AlreadyVisited) { listOfRegions[listNo].Add(ElementFromListToCheck); ElementFromListToCheck.AlreadyVisited = true; foreach (Cl3DModel.Cl3DModelPointIterator it in ElementFromListToCheck.GetListOfNeighbors()) { if (!it.AlreadyVisited) { newListToCheck.Add(it); } } } } ListToCheck.Clear(); foreach (Cl3DModel.Cl3DModelPointIterator it in newListToCheck) { ListToCheck.Add(it); } newListToCheck.Clear(); } while (ListToCheck.Count != 0); ListToCheck.Clear(); listNo++; } if (listOfRegions.Count <= 1) { return; } int maxCount = listOfRegions[0].Count;; int maxI = 0; for (int i = 1; i < listOfRegions.Count; i++) { if (listOfRegions[i].Count > maxCount) { maxI = i; maxCount = listOfRegions[i].Count; } } if (m_bColorIt) { for (int i = 0; i < listOfRegions.Count; i++) { if (i == maxI) { continue; } for (int j = 0; j < listOfRegions[i].Count; j++) { listOfRegions[i][j].Color = ClTools.GetColorRGB(((float)i) / listOfRegions.Count, 1); } } } else { for (int i = 0; i < listOfRegions.Count; i++) { if (i == maxI) { continue; } for (int j = 0; j < listOfRegions[i].Count; j++) { p_Model.RemovePointFromModel(listOfRegions[i][j]); } } } }