//---------------------------------------------------------------------------- public static void CalculateGeodesicDistanceFromSourcePointToAllPoints(Cl3DModel.Cl3DModelPointIterator p_BasicPoint, string p_SepcificPointNameToWhichDistanceWillBeCalculated) { Cl3DModel.Cl3DModelPointIterator iter = p_BasicPoint.GetManagedModel().GetIterator(); do { if (iter.IsSpecificValueCalculated(p_SepcificPointNameToWhichDistanceWillBeCalculated)) iter.RemoveSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated); } while (iter.MoveToNext()); p_BasicPoint.AlreadyVisited = true; List<Cl3DModel.Cl3DModelPointIterator> ListToCheck = null; List<Cl3DModel.Cl3DModelPointIterator> NewListToCheck = new List<Cl3DModel.Cl3DModelPointIterator>(); NewListToCheck.Add(p_BasicPoint); p_BasicPoint.AddSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, 0.0f); do { ListToCheck = NewListToCheck; NewListToCheck = new List<Cl3DModel.Cl3DModelPointIterator>(); for (int i = 0; i < ListToCheck.Count; i++) { Cl3DModel.Cl3DModelPointIterator currentPoint = ListToCheck[i]; List<Cl3DModel.Cl3DModelPointIterator> Neighbors = currentPoint.GetListOfNeighbors(); foreach (Cl3DModel.Cl3DModelPointIterator point in Neighbors) { float CurrentDistance = currentPoint - point; double OldDistance = 0; if (!currentPoint.GetSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, out OldDistance)) throw new Exception("Cannot get specific value: " + p_SepcificPointNameToWhichDistanceWillBeCalculated.ToString()); if (point.IsSpecificValueCalculated(p_SepcificPointNameToWhichDistanceWillBeCalculated))// if point was already visited, check if we dont have sometimes shorter path to it { double SavedPointDistance = 0; if (!point.GetSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, out SavedPointDistance)) throw new Exception("Cannot get specific value: " + p_SepcificPointNameToWhichDistanceWillBeCalculated.ToString()); if (SavedPointDistance > OldDistance + CurrentDistance) // check if we maybe have shorter path to this point { point.AddSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, OldDistance + CurrentDistance); point.AddSpecificValue("Path", currentPoint.PointID); NewListToCheck.Add(point); } } else { //can be corrected because we have right now possibility to save distance in the point not different list point.AddSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, OldDistance + CurrentDistance); point.AddSpecificValue("Path", currentPoint.PointID); NewListToCheck.Add(point); } } } } while (NewListToCheck.Count != 0); p_BasicPoint.GetManagedModel().ResetVisitedPoints(); }
public static void CalculateGeodesicDistanceFromSourcePointToAllPointsWithMovement(Cl3DModel.Cl3DModelPointIterator p_BasicPoint, string p_SepcificPointNameToWhichDistanceWillBeCalculated, Dictionary<uint, uint> movement) { List<Cl3DModel.Cl3DModelPointIterator> ListToCheck = null; List<Cl3DModel.Cl3DModelPointIterator> NewListToCheck = new List<Cl3DModel.Cl3DModelPointIterator>(); NewListToCheck.Add(p_BasicPoint); p_BasicPoint.AddSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, 0.0f); do { ListToCheck = NewListToCheck; NewListToCheck = new List<Cl3DModel.Cl3DModelPointIterator>(); for (int i = 0; i < ListToCheck.Count; i++) { Cl3DModel.Cl3DModelPointIterator currentPoint = ListToCheck[i]; if (movement != null) { uint testID; if (movement.TryGetValue(currentPoint.PointID, out testID)) { double value = currentPoint.GetSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated); uint OldId = currentPoint.PointID; if (!currentPoint.MoveToPoint(testID)) throw new Exception("Cannot move a point in to the point with no: " + testID.ToString()); currentPoint.AddSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, value); currentPoint.AddSpecificValue("Path", OldId); } } List<Cl3DModel.Cl3DModelPointIterator> Neighbors = currentPoint.GetListOfNeighbors(); foreach (Cl3DModel.Cl3DModelPointIterator point in Neighbors) { float CurrentDistance = currentPoint - point; double OldDistance = 0; if (!currentPoint.GetSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, out OldDistance)) throw new Exception("Cannot get specific value: " + p_SepcificPointNameToWhichDistanceWillBeCalculated.ToString()); double SavedPointDistance = 0; if (point.GetSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, out SavedPointDistance)) { if (SavedPointDistance > OldDistance + CurrentDistance) // check if we maybe have shorter path to this point { point.AddSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, OldDistance + CurrentDistance); point.AddSpecificValue("Path", currentPoint.PointID); NewListToCheck.Add(point); } } else { //can be corrected because we have right now possibility to save distance in the point not different list point.AddSpecificValue(p_SepcificPointNameToWhichDistanceWillBeCalculated, OldDistance + CurrentDistance); point.AddSpecificValue("Path", currentPoint.PointID); NewListToCheck.Add(point); } } } } while (NewListToCheck.Count != 0); p_BasicPoint.GetManagedModel().ResetVisitedPoints(); }
private void CalculateGeodesicDistancesFromPoint(string DistanceName, Cl3DModel.Cl3DModelPointIterator p_BasicPoint, Cl3DModel p_Model) { List<Cl3DModel.Cl3DModelPointIterator> ListToCheck = null; List<Cl3DModel.Cl3DModelPointIterator> NewListToCheck = new List<Cl3DModel.Cl3DModelPointIterator>(); NewListToCheck.Add(p_BasicPoint); p_BasicPoint.AddSpecificValue(DistanceName, 0.0f); Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); do { ListToCheck = NewListToCheck; NewListToCheck = new List<Cl3DModel.Cl3DModelPointIterator>(); foreach (Cl3DModel.Cl3DModelPointIterator PointToCheck in ListToCheck) { double PointToCheckDistance = 0; if (!PointToCheck.GetSpecificValue(DistanceName, out PointToCheckDistance)) throw new Exception("Cannot get distance value"); PointToCheck.AlreadyVisited = true; List<Cl3DModel.Cl3DModelPointIterator> Neighbors = PointToCheck.GetListOfNeighbors(); foreach (Cl3DModel.Cl3DModelPointIterator NeighboorPoint in Neighbors) { double CurrentDistance = PointToCheck - NeighboorPoint; double newDistance = PointToCheckDistance + CurrentDistance; double NeighborOldDistance = 0; if (NeighboorPoint.GetSpecificValue(DistanceName, out NeighborOldDistance))// if point was already visited, check if we dont have sometimes shorter path to it { if (NeighborOldDistance > newDistance) NeighboorPoint.AddSpecificValue(DistanceName, newDistance); } else { NeighboorPoint.AddSpecificValue(DistanceName, newDistance); } if (!NeighboorPoint.AlreadyVisited) { NeighboorPoint.AlreadyVisited = true; NewListToCheck.Add(NeighboorPoint); } } } } while (NewListToCheck.Count != 0); iter = p_Model.GetIterator(); do { iter.AlreadyVisited = false; } while (iter.MoveToNext()); }