protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (iter.IsValid()) { do { List <float> points = new List <float>(); List <Cl3DModel.Cl3DModelPointIterator> Neighbors = iter.GetListOfNeighbors(); foreach (Cl3DModel.Cl3DModelPointIterator neighbor in Neighbors) { points.Add(neighbor.Z); } points.Add(iter.Z); points.Sort(); float result = 0; if (points.Count % 2 == 0)// even { int first = (int)(points.Count / 2); result = (points[first - 1] + points[first]) / 2; } else // odd { int element = (int)(points.Count / 2); result = points[element]; } if (m_bDecision) { float diff = Math.Abs(iter.Z - result); if (diff >= m_SpikeThreshold) { iter = p_Model.RemovePointFromModel(iter); } else if (!iter.MoveToNext()) { break; } } else { iter.Z = result; if (!iter.MoveToNext()) { break; } } } while (iter.IsValid()); } }
protected override void Algorithm(ref Cl3DModel p_Model) { string name = p_Model.ModelFileFolder + p_Model.ModelFileName + ".curv"; Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { throw new Exception("Iterator in the model is not valid"); } using (TextWriter tw = new StreamWriter(name, false)) { tw.WriteLine("@----------------------------------------"); tw.WriteLine("@ Przemyslaw Szeptycki LIRIS 2008"); tw.WriteLine("@ Face model curvatures"); tw.WriteLine("@ Model name: " + p_Model.ModelFileName); tw.WriteLine("@----------------------------------------"); tw.WriteLine("@ (PointID) X Y Z"); tw.WriteLine("@ \tCurvatureName: value"); do { List <String> SpecValList = iter.GetListOfSpecificValues(); string line = "(" + iter.PointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + ")" + iter.X.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.Y.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.Z.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; foreach (String SPV in SpecValList) { double val; iter.GetSpecificValue(SPV, out val); line += "\t" + SPV + ": " + val.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; } tw.WriteLine(line); } while (iter.MoveToNext()); tw.Close(); } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (iter.IsValid()) { do { double H; double K; double ShapeIndex; if (!iter.GetSpecificValue("Gaussian_25", out K)) { continue; } if (!iter.GetSpecificValue("Mean_25", out H)) { continue; } if (H < 0 && K > m_ThresholdK) // Nose { iter.Color = Color.Green; } }while (iter.MoveToNext()); } }
private float CalculateWholeModelArea(Cl3DModel p_Model) { float Area = 0; List <ClTools.ClTriangle> Triangles = null; Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (iter.IsValid()) { do { ClTools.GetListOfTriangles(out Triangles, iter); foreach (ClTools.ClTriangle triangle in Triangles) { if (triangle.AlreadyVisited) { continue; } Area += ClTools.CalculateTriangleArea(triangle); triangle.AlreadyVisited = true; } } while (iter.MoveToNext()); } return(Area); }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); while (iter.IsValid()) { List <Cl3DModel.Cl3DModelPointIterator> neighboors = iter.GetListOfNeighbors(); foreach (Cl3DModel.Cl3DModelPointIterator neighbor1Ring in neighboors) { bool founded = false; foreach (Cl3DModel.Cl3DModelPointIterator neighbor2Ring in neighbor1Ring.GetListOfNeighbors()) { foreach (Cl3DModel.Cl3DModelPointIterator neighbor3Ring in neighbor2Ring.GetListOfNeighbors()) { if (neighbor3Ring.PointID == iter.PointID) { founded = true; break; } } } if (!founded) { iter.RemoveNeighbor(neighbor1Ring); } } if (!iter.MoveToNext()) { break; } } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator NoseTip = null; if (!p_Model.GetSpecificPoint(m_NoseTipName, ref NoseTip)) { throw new Exception("Cannot find specific point NoseTip"); } Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); while (iter.IsValid()) { bool isOk = false; if (ClTools.IsItInsideSphere(iter.X, iter.Y, iter.Z, NoseTip.X, NoseTip.Y, NoseTip.Z + m_fBottomSphereNoseTipZoffset, m_fBottomSphereRadious)) { if (ClTools.IsItInsideSphere(iter.X, iter.Y, iter.Z, NoseTip.X, NoseTip.Y, NoseTip.Z + m_fUpperSphereNoseTipZoffset, m_fUpperSphereRadious)) { isOk = true; } } if (!isOk) { iter = p_Model.RemovePointFromModel(iter); } else { if (!iter.MoveToNext()) { break; } } } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator nose = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip.ToString()); ClTools.CalculateGeodesicDistanceFromSourcePointToAllPoints(nose, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip.ToString()); Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); do { double distance = 0; if (iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip, out distance)) { if (distance > m_fDistence) { iter = p_Model.RemovePointFromModel(iter); } else { if (!iter.MoveToNext()) { break; } } } else { iter = p_Model.RemovePointFromModel(iter); } }while(iter.IsValid()); }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator NoseTip = null; if (!p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip, ref NoseTip)) { throw new Exception("Cannot find specific point NoseTip"); } Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); while (iter.IsValid()) { bool isOk = false; if (iter.Z < NoseTip.X && iter.Z > NoseTip.Z - m_fPlaneDistanceZ) { isOk = true; } if (!isOk) { iter = p_Model.RemovePointFromModel(iter); } else { if (!iter.MoveToNext()) { break; } } } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel ConformalModel = new Cl3DModel(); ConformalModel.LoadModel(p_Model.ModelFileFolder + ConformalMapFolder + "\\" + p_Model.ModelFileName + ".m_Out.pos.m"); Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); List <ClTools.ClTriangle> Triangles = null; float ModelArea = CalculateWholeModelArea(p_Model); float ConformalMapArea = CalculateWholeModelArea(ConformalModel); if (iter.IsValid()) { do { float area3D = 0; ClTools.GetListOfTriangles(out Triangles, iter); // if (Triangles.Count != 6) // continue; foreach (ClTools.ClTriangle triangle in Triangles) { area3D += ClTools.CalculateTriangleArea(triangle); } area3D /= Triangles.Count; iter.AddSpecificValue("ConnectedTrianglesArea", area3D); Cl3DModel.Cl3DModelPointIterator ConformalIter = ConformalModel.GetIterator(); if (!ConformalIter.MoveToPoint(iter.PointID)) { continue;//throw new Exception("Cannot find on conformal model point with no: " + iter.PointID.ToString()); } float area2D = 0; ClTools.GetListOfTriangles(out Triangles, ConformalIter); foreach (ClTools.ClTriangle triangle in Triangles) { area2D += ClTools.CalculateTriangleArea(triangle); } area2D /= Triangles.Count; float ConformalFactor = (area3D / ModelArea) / (area2D / ConformalMapArea); ConformalIter.AddSpecificValue("ConformalFactor", ConformalFactor); } while (iter.MoveToNext()); } p_Model = ConformalModel; }
protected override void Algorithm(ref Cl3DModel p_Model) { string name = p_Model.ModelFileFolder + p_Model.ModelFileName + m_sFilePostFix; if (m_bBinaryMode) { p_Model.SaveModel(name); } else { name += ".model"; Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { throw new Exception("Iterator in the model is not valid"); } using (TextWriter tw = new StreamWriter(name, false)) { tw.WriteLine("@----------------------------------------"); tw.WriteLine("@ Przemyslaw Szeptycki LIRIS 2008"); tw.WriteLine("@ Face model"); tw.WriteLine("@ Model name: " + p_Model.ModelFileName); tw.WriteLine("@----------------------------------------"); tw.WriteLine("@ PointID X Y Z (TextureX TextureY) (Neighbors PointID)"); do { string line = iter.PointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.X.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.Y.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.Z.ToString(System.Globalization.CultureInfo.InvariantCulture) + " ( " + iter.RangeImageX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.RangeImageY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " ) ( "; List <Cl3DModel.Cl3DModelPointIterator> neighbors = iter.GetListOfNeighbors(); foreach (Cl3DModel.Cl3DModelPointIterator neighbor in neighbors) { line += neighbor.PointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " "; } line += ")"; tw.WriteLine(line); } while (iter.MoveToNext()); int nop = p_Model.GetAllSpecificPoints().Count; if (nop != 0) { tw.WriteLine("Landmark points (ptID): " + nop.ToString()); foreach (KeyValuePair <string, Cl3DModel.Cl3DModelPointIterator> specificPoint in p_Model.GetAllSpecificPoints()) { tw.WriteLine(specificPoint.Key + " " + specificPoint.Value.PointID.ToString()); } } tw.Close(); } } }
protected override void Algorithm(ref Cl3DModel p_Model) { string name = p_Model.ModelFileName; string FileName = p_Model.ModelFileFolder + name + ".gav"; string line = ""; List <ClTools.MainPoint3D> points = new List <ClTools.MainPoint3D>(); using (StreamReader FileStream = File.OpenText(FileName)) { while ((line = FileStream.ReadLine()) != null) { string[] coordinates = line.Split('\t'); if (coordinates[0].Contains("@")) { continue; } if (coordinates.Length != 4) { throw new Exception("Incorrect format, less than 3 coordinates for a landmark (landmekName x y z)"); } points.Add(new ClTools.MainPoint3D(Single.Parse(coordinates[1].Split(' ')[1], System.Globalization.CultureInfo.InvariantCulture), Single.Parse(coordinates[2].Split(' ')[1], System.Globalization.CultureInfo.InvariantCulture), Single.Parse(coordinates[3].Split(' ')[1], System.Globalization.CultureInfo.InvariantCulture), coordinates[0])); } } Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { throw new Exception("Iterator in the model is not valid!"); } do { foreach (ClTools.MainPoint3D pts in points) { pts.CheckClosest(iter); } } while (iter.MoveToNext()); foreach (ClTools.MainPoint3D pts in points) { p_Model.AddSpecificPoint(pts.Name, pts.ClosestPoint); } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator RightEye = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner.ToString()); Cl3DModel.Cl3DModelPointIterator LeftEye = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner.ToString()); Cl3DModel.Cl3DModelPointIterator[,] Map = null; int Width, Height, Xoffset, Yoffset; ClTools.CreateGridBasedOnRangeValues(p_Model, out Map, out Width, out Height, out Xoffset, out Yoffset); int RightEyeX = RightEye.RangeImageX - Xoffset; int RightEyeY = RightEye.RangeImageY - Yoffset; int LeftEyeX = LeftEye.RangeImageX - Xoffset; int LeftEyeY = LeftEye.RangeImageY - Yoffset; int MiddleX = (RightEyeX + LeftEyeX) / 2; int MiddleY = (RightEyeY + LeftEyeY) / 2; Cl3DModel.Cl3DModelPointIterator MiddlePoint = Map[MiddleX, MiddleY]; p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.UnspecifiedPoint, MiddlePoint); List <Cl3DModel.Cl3DModelPointIterator> Neighborhood = null; ClTools.GetNeighborhoodWithGeodesicDistance(out Neighborhood, MiddlePoint, m_fEyesPartRadious); foreach (Cl3DModel.Cl3DModelPointIterator point in Neighborhood) { point.AlreadyVisited = true; } MiddlePoint.AlreadyVisited = true; Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); do { if (!iter.IsValid()) { break; } if (!iter.AlreadyVisited) { iter = p_Model.RemovePointFromModel(iter); } else if (!iter.MoveToNext()) { break; } } while (true); }
private Cl3DModel.Cl3DModelPointIterator GetRandomUnseenPointOfHole(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { return(null); } do { if (iter.GetListOfNeighbors().Count < 8 && !iter.AlreadyVisited) { return(iter); } } while (iter.MoveToNext()); return(null); }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); while (iter.IsValid()) { iter.X = iter.X * m_fScale; iter.Y = iter.Y * m_fScale; iter.Z = iter.Z * m_fScale; if (!iter.MoveToNext()) { break; } } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator maxIter = p_Model.GetIterator(); Cl3DModel.Cl3DModelPointIterator iter = maxIter.CopyIterator(); while (iter.MoveToNext()) { if (maxIter.Z < iter.Z) { maxIter = iter.CopyIterator(); } } if (maxIter.IsValid()) { p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip.ToString(), maxIter); } }
private Cl3DModel.Cl3DModelPointIterator findNextUnseenElement(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (iter.IsValid()) { while (iter.AlreadyVisited) { if (!iter.MoveToNext()) { return(null); } } return(iter); } else { return(null); } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); while (iter.IsValid()) { float X = iter.X; float Y = iter.Y; float Z = iter.Z; iter.X = X - m_fMoveX; iter.Y = Y - m_fMoveY; iter.Z = Z - m_fMoveZ; if (!iter.MoveToNext()) { break; } } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (m_bRandomX) { Random random = new Random(); m_fAngleX = (int)random.Next(-45, 45); } if (m_bRandomY) { Random random = new Random(); m_fAngleY = (int)random.Next(-90, 90); } if (m_bRandomZ) { Random random = new Random(); m_fAngleZ = (int)random.Next(-30, 30); } ClInformationSender.SendInformation("ROTATIONS: X: " + m_fAngleX + " Y: " + m_fAngleY + " Z: " + m_fAngleZ, ClInformationSender.eInformationType.eDebugText); while (iter.IsValid()) { float X = iter.X; float Y = iter.Y; float Z = iter.Z; ClTools.RotateXDirection(X, Y, Z, m_fAngleX * (float)(Math.PI / 180), out X, out Y, out Z); ClTools.RotateYDirection(X, Y, Z, m_fAngleY * (float)(Math.PI / 180), out X, out Y, out Z); ClTools.RotateZDirection(X, Y, Z, m_fAngleZ * (float)(Math.PI / 180), out X, out Y, out Z); iter.X = X; iter.Y = Y; iter.Z = Z; if (!iter.MoveToNext()) { break; } } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); do { double value = 0; if (!iter.GetSpecificValue(m_SpecificValue, out value)) { iter.MoveToNext(); continue; } if (value > m_ThresholdValue) { iter = p_Model.RemovePointFromModel(iter); } else { iter.MoveToNext(); } } while (iter.IsValid()); }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { return; } List <Cl3DModel.Cl3DModelPointIterator> ListOfNosePoints = new List <Cl3DModel.Cl3DModelPointIterator>(); List <Cl3DModel.Cl3DModelPointIterator> ListOfEyesPoints = new List <Cl3DModel.Cl3DModelPointIterator>(); string gausString = "Gaussian_" + m_iNeighborhoodSize.ToString(); string meanString = "Mean_" + m_iNeighborhoodSize.ToString(); do { double H = 0; double K = 0; if (!iter.GetSpecificValue(gausString, out K)) { continue; } if (!iter.GetSpecificValue(meanString, out H)) { continue; } if (H < 0 && K > m_NoseThresholdK) // Nose { ListOfNosePoints.Add(iter.CopyIterator()); } else if (H > 0 && K > m_EyesThresholdK) // Eyes { ListOfEyesPoints.Add(iter.CopyIterator()); } }while (iter.MoveToNext()); List <List <Cl3DModel.Cl3DModelPointIterator> > NoseRegions = null; List <List <Cl3DModel.Cl3DModelPointIterator> > EyesRegions = null; // NOSE DivideToTheRegions(ListOfNosePoints, out NoseRegions); // EYES DivideToTheRegions(ListOfEyesPoints, out EyesRegions); // COLOR IT /*for (int i = 0; i < NoseRegions.Count; i++) * { * foreach (Cl3DModel.Cl3DModelPointIterator point in NoseRegions[i]) * point.Color = ClTools.GetColorRGB((float)i / (NoseRegions.Count + EyesRegions.Count), 1); * } * for (int i = 0; i < EyesRegions.Count; i++) * { * foreach (Cl3DModel.Cl3DModelPointIterator point in EyesRegions[i]) * point.Color = ClTools.GetColorRGB((float)(i + NoseRegions.Count) / (EyesRegions.Count + NoseRegions.Count), 1); * } */ // ----------------- NOSE // remove smallest regions leave only 3 biggest one List <Cl3DModel.Cl3DModelPointIterator> NoseTipsPoints = new List <Cl3DModel.Cl3DModelPointIterator>(); if (NoseRegions.Count > m_iMaxCountOfNoseRegions) { NoseRegions.Sort(new ClCompareCount()); for (int i = NoseRegions.Count - 1; i >= m_iMaxCountOfNoseRegions; i--) { NoseRegions.RemoveAt(i); } } //----------- NOSE searching for one point in each region for (int i = 0; i < NoseRegions.Count; i++) { double MaxKVal = 0; Cl3DModel.Cl3DModelPointIterator MaxPoint = null; foreach (Cl3DModel.Cl3DModelPointIterator point in NoseRegions[i]) { double K; if (!point.GetSpecificValue(gausString, out K)) { continue; } if (MaxPoint == null) { MaxPoint = point; MaxKVal = K; continue; } if (MaxKVal < K) { MaxKVal = K; MaxPoint = point; } } NoseTipsPoints.Add(MaxPoint); } // --------------- EYES // remove smallest regions leave only 5 biggest one List <Cl3DModel.Cl3DModelPointIterator> EyesPoints = new List <Cl3DModel.Cl3DModelPointIterator>(); if (EyesRegions.Count > m_iMaxCountOfEyeRegions) { EyesRegions.Sort(new ClCompareCount()); for (int i = EyesRegions.Count - 1; i >= m_iMaxCountOfEyeRegions; i--) { EyesRegions.RemoveAt(i); } } //--------------------------- EYES searching for one point in each region for (int i = 0; i < EyesRegions.Count; i++) { double MaxKval = 0; Cl3DModel.Cl3DModelPointIterator MinPoint = null; foreach (Cl3DModel.Cl3DModelPointIterator point in EyesRegions[i]) { double val; if (!point.GetSpecificValue(gausString, out val)) { continue; } if (MinPoint == null) { MinPoint = point; MaxKval = val; continue; } if (MaxKval < val) { MaxKval = val; MinPoint = point; } } EyesPoints.Add(MinPoint); } //------------- Looking for three face points ------------------------------ Iridium.Numerics.LinearAlgebra.Matrix Model = new Iridium.Numerics.LinearAlgebra.Matrix(3, 3); Iridium.Numerics.LinearAlgebra.Matrix ModelGen = new Iridium.Numerics.LinearAlgebra.Matrix(3, 3); // Generic model Vector GenericNoseTip = new Vector(new double[] { 0, 0, 0 }); Vector GenericLeftEye = new Vector(new double[] { -21f, 40.5f, -41.5f }); Vector GenericRightEye = new Vector(new double[] { 21f, 40.5f, -41.5f }); Vector GenLeftCornerOfLeftEye = new Vector(new double[] { -44f, 40f, -44f }); Vector GenRightCornerOfRightEye = new Vector(new double[] { 44f, 40f, -44f }); Vector GenLeftCornerOfNose = new Vector(new double[] { -20f, -2f, -31f }); Vector GenRightCornerOfNose = new Vector(new double[] { 20f, -2f, -31f }); Vector GenLeftCornerOfLips = new Vector(new double[] { -28f, -32f, -34f }); Vector GenRightCornerOfLips = new Vector(new double[] { 28f, -32f, -34f }); Vector MeanGenericModel = new Vector(new double[] { (GenericNoseTip[0] + GenericLeftEye[0] + GenericRightEye[0]) / 3, (GenericNoseTip[1] + GenericLeftEye[1] + GenericRightEye[1]) / 3, (GenericNoseTip[2] + GenericLeftEye[2] + GenericRightEye[2]) / 3 }); // Centered generic model (generic model - mean) ModelGen[0, 0] = (GenericNoseTip[0] - MeanGenericModel[0]); ModelGen[1, 0] = (GenericNoseTip[1] - MeanGenericModel[1]); ModelGen[2, 0] = (GenericNoseTip[2] - MeanGenericModel[2]); ModelGen[0, 1] = (GenericLeftEye[0] - MeanGenericModel[0]); ModelGen[1, 1] = (GenericLeftEye[1] - MeanGenericModel[1]); ModelGen[2, 1] = (GenericLeftEye[2] - MeanGenericModel[2]); ModelGen[0, 2] = (GenericRightEye[0] - MeanGenericModel[0]); ModelGen[1, 2] = (GenericRightEye[1] - MeanGenericModel[1]); ModelGen[2, 2] = (GenericRightEye[2] - MeanGenericModel[2]); ModelGen.Transpose(); List <KeyValuePair <float, List <Cl3DModel.Cl3DModelPointIterator> > > deltaOfDistanceBetweenModelAndPoints = new List <KeyValuePair <float, List <Cl3DModel.Cl3DModelPointIterator> > >(); for (int iEye = 0; iEye < EyesPoints.Count - 1; iEye++) { for (int jEye = iEye + 1; jEye < EyesPoints.Count; jEye++) { for (int iNose = 0; iNose < NoseTipsPoints.Count; iNose++) { Cl3DModel.Cl3DModelPointIterator eyeLeft = EyesPoints[iEye]; Cl3DModel.Cl3DModelPointIterator eyeRight = EyesPoints[jEye]; Cl3DModel.Cl3DModelPointIterator noseTip = NoseTipsPoints[iNose]; if (eyeLeft.Y < noseTip.Y || eyeRight.Y < noseTip.Y) { continue; } for (int c = 0; c < 2; c++) { if (c == 1) { eyeLeft = EyesPoints[jEye]; // zmiana oczu nie wiemy ktore punkty to oczy prawdziwe sa eyeRight = EyesPoints[iEye]; } float MeanValX = (noseTip.X + eyeLeft.X + eyeRight.X) / 3.0f; float MeanValY = (noseTip.Y + eyeLeft.Y + eyeRight.Y) / 3.0f; float MeanValZ = (noseTip.Z + eyeLeft.Z + eyeRight.Z) / 3.0f; Model[0, 0] = (noseTip.X - MeanValX); Model[1, 0] = (noseTip.Y - MeanValY); Model[2, 0] = (noseTip.Z - MeanValZ); Model[0, 1] = (eyeLeft.X - MeanValX); Model[1, 1] = (eyeLeft.Y - MeanValY); Model[2, 1] = (eyeLeft.Z - MeanValZ); Model[0, 2] = (eyeRight.X - MeanValX); Model[1, 2] = (eyeRight.Y - MeanValY); Model[2, 2] = (eyeRight.Z - MeanValZ); //----------------- Finding best rotation and translation SVD algorithm Iridium.Numerics.LinearAlgebra.Matrix Covariance = Model * ModelGen; Iridium.Numerics.LinearAlgebra.SingularValueDecomposition SVD = new Iridium.Numerics.LinearAlgebra.SingularValueDecomposition(Covariance); Iridium.Numerics.LinearAlgebra.Matrix U = SVD.LeftSingularVectors; Iridium.Numerics.LinearAlgebra.Matrix V = SVD.RightSingularVectors; Iridium.Numerics.LinearAlgebra.Matrix s = new Iridium.Numerics.LinearAlgebra.Matrix(3, 1.0); if (Covariance.Rank() < 2) { throw new Exception("Cannot allign generic model (cov rank is less than 2)"); } if (Covariance.Rank() == 2) // m-1 where m is dimension space (3D) { double detU = Math.Round(U.Determinant()); double detV = Math.Round(V.Determinant()); double detC = Covariance.Determinant(); if ((int)detU * (int)detV == 1) { s[2, 2] = 1; } else if ((int)detU * (int)detV == -1) { s[2, 2] = -1; } else { throw new Exception("Determinant of U and V are not in conditions"); } } else { if (Covariance.Determinant() < 0) { s[2, 2] = -1; } } V.Transpose(); Iridium.Numerics.LinearAlgebra.Matrix Roatation = U * s * V; Iridium.Numerics.LinearAlgebra.Matrix MeanValOfGenModelMatrix = new Iridium.Numerics.LinearAlgebra.Matrix(3, 1); MeanValOfGenModelMatrix[0, 0] = MeanGenericModel[0]; MeanValOfGenModelMatrix[1, 0] = MeanGenericModel[1]; MeanValOfGenModelMatrix[2, 0] = MeanGenericModel[2]; Iridium.Numerics.LinearAlgebra.Matrix MeanValOfModelMatrix = new Iridium.Numerics.LinearAlgebra.Matrix(3, 1); MeanValOfModelMatrix[0, 0] = MeanValX; MeanValOfModelMatrix[1, 0] = MeanValY; MeanValOfModelMatrix[2, 0] = MeanValZ; Iridium.Numerics.LinearAlgebra.Matrix Translation = MeanValOfModelMatrix - Roatation * MeanValOfGenModelMatrix; //--------------------------- End now we have translation and rotation float GenericModelDistance = 0;; Iridium.Numerics.LinearAlgebra.Matrix q = new Iridium.Numerics.LinearAlgebra.Matrix(3, 1); q[0, 0] = GenericNoseTip[0]; q[1, 0] = GenericNoseTip[1]; q[2, 0] = GenericNoseTip[2]; Iridium.Numerics.LinearAlgebra.Matrix NewQ = Roatation * q + Translation; GenericModelDistance += (float)Math.Sqrt(Math.Pow(noseTip.X - NewQ[0, 0], 2) + Math.Pow(noseTip.Y - NewQ[1, 0], 2) + Math.Pow(noseTip.Z - NewQ[2, 0], 2)); //--------- // Cl3DModel.Cl3DModelPointIterator it1 = p_Model.AddPointToModel((float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0]); //it1.AddNeighbor(noseTip); // it1.Color = Color.Green; //--------- q[0, 0] = GenericLeftEye[0]; q[1, 0] = GenericLeftEye[1]; q[2, 0] = GenericLeftEye[2]; NewQ = Roatation * q + Translation; GenericModelDistance += (float)Math.Sqrt(Math.Pow(eyeLeft.X - NewQ[0, 0], 2) + Math.Pow(eyeLeft.Y - NewQ[1, 0], 2) + Math.Pow(eyeLeft.Z - NewQ[2, 0], 2)); //--------- // Cl3DModel.Cl3DModelPointIterator it2 = p_Model.AddPointToModel((float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0]); //it2.AddNeighbor(eyeLeft); // it2.Color = Color.White; //--------- q[0, 0] = GenericRightEye[0]; q[1, 0] = GenericRightEye[1]; q[2, 0] = GenericRightEye[2]; NewQ = Roatation * q + Translation; GenericModelDistance += (float)Math.Sqrt(Math.Pow(eyeRight.X - NewQ[0, 0], 2) + Math.Pow(eyeRight.Y - NewQ[1, 0], 2) + Math.Pow(eyeRight.Z - NewQ[2, 0], 2)); //--------- // Cl3DModel.Cl3DModelPointIterator it3 = p_Model.AddPointToModel((float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0]); //it3.AddNeighbor(eyeRight); // it3.Color = Color.Orange; // it1.AddNeighbor(it2); // it1.AddNeighbor(it3); // it2.AddNeighbor(it3); //--------- // ---------- Rest of generic model to find closest points and count distance; q[0, 0] = GenLeftCornerOfLeftEye[0]; q[1, 0] = GenLeftCornerOfLeftEye[1]; q[2, 0] = GenLeftCornerOfLeftEye[2]; NewQ = Roatation * q + Translation; Cl3DModel.Cl3DModelPointIterator closestPoint = null; float MinDistance; ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance); GenericModelDistance += MinDistance; q[0, 0] = GenRightCornerOfRightEye[0]; q[1, 0] = GenRightCornerOfRightEye[1]; q[2, 0] = GenRightCornerOfRightEye[2]; NewQ = Roatation * q + Translation; ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance); GenericModelDistance += MinDistance; q[0, 0] = GenLeftCornerOfNose[0]; q[1, 0] = GenLeftCornerOfNose[1]; q[2, 0] = GenLeftCornerOfNose[2]; NewQ = Roatation * q + Translation; ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance); GenericModelDistance += MinDistance; q[0, 0] = GenRightCornerOfNose[0]; q[1, 0] = GenRightCornerOfNose[1]; q[2, 0] = GenRightCornerOfNose[2]; NewQ = Roatation * q + Translation; ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance); GenericModelDistance += MinDistance; q[0, 0] = GenLeftCornerOfLips[0]; q[1, 0] = GenLeftCornerOfLips[1]; q[2, 0] = GenLeftCornerOfLips[2]; NewQ = Roatation * q + Translation; ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance); GenericModelDistance += MinDistance; q[0, 0] = GenRightCornerOfLips[0]; q[1, 0] = GenRightCornerOfLips[1]; q[2, 0] = GenRightCornerOfLips[2]; NewQ = Roatation * q + Translation; ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance); GenericModelDistance += MinDistance; // ---------- ClInformationSender.SendInformation("One of distances between generic model and face before thresholding: " + GenericModelDistance.ToString(System.Globalization.CultureInfo.InvariantCulture), ClInformationSender.eInformationType.eDebugText); if (GenericModelDistance > m_fDistanceMinValueFromGenModel) { continue; } // Check if between eyes and nose there is other region (it should be not) /*bool isBetweenNoseRegion = false; * foreach (Cl3DModel.Cl3DModelPointIterator noseTmp in NoseTipsPoints) * { * if (noseTmp.PointID == noseTip.PointID) * continue; * * if (noseTmp.X > eyeLeft.X && noseTmp.X < eyeRight.X && noseTmp.Y > noseTip.Y && (noseTip.Y < eyeLeft.Y || noseTip.Y < eyeRight.Y)) * isBetweenNoseRegion = true; * } * if (isBetweenNoseRegion) * continue; */ List <Cl3DModel.Cl3DModelPointIterator> list = new List <Cl3DModel.Cl3DModelPointIterator>(); list.Add(noseTip); list.Add(eyeLeft); list.Add(eyeRight); KeyValuePair <float, List <Cl3DModel.Cl3DModelPointIterator> > KeyVal = new KeyValuePair <float, List <Cl3DModel.Cl3DModelPointIterator> >(GenericModelDistance, list); deltaOfDistanceBetweenModelAndPoints.Add(KeyVal); } } } } if (deltaOfDistanceBetweenModelAndPoints.Count == 0) { throw new Exception("Cannot find nose and eyes points"); } float min = deltaOfDistanceBetweenModelAndPoints[0].Key; int no = 0; for (int i = 1; i < deltaOfDistanceBetweenModelAndPoints.Count; i++) { if (deltaOfDistanceBetweenModelAndPoints[i].Key < min) { min = deltaOfDistanceBetweenModelAndPoints[i].Key; no = i; } } ClInformationSender.SendInformation("Correct MIN distance between generic model and face: " + min.ToString(System.Globalization.CultureInfo.InvariantCulture), ClInformationSender.eInformationType.eDebugText); p_Model.AddSpecificPoint(NameOfNoseTip, deltaOfDistanceBetweenModelAndPoints[no].Value[0]); p_Model.AddSpecificPoint(NameLeftEyeRightCorner, deltaOfDistanceBetweenModelAndPoints[no].Value[1]); p_Model.AddSpecificPoint(NameRightEyeLeftCorner, deltaOfDistanceBetweenModelAndPoints[no].Value[2]); }
protected override void Algorithm(ref Cl3DModel p_Model) { // if (p_Model.ModelType != "abs") // throw new Exception("Saveing to .obj files works only for ABS files"); string name = p_Model.ModelFileFolder + p_Model.ModelFileName + ".obj"; Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { throw new Exception("Iterator in the model is not valid"); } using (TextWriter tw = new StreamWriter(name, false)) { tw.WriteLine("#----------------------------------------"); tw.WriteLine("# Przemyslaw Szeptycki LIRIS 2009"); tw.WriteLine("# Object Face model"); tw.WriteLine("# Model name: " + p_Model.ModelFileName); tw.WriteLine("# [email protected]"); tw.WriteLine("#----------------------------------------"); uint vertexNO = 1; Dictionary <uint, uint> MapVertexNo = new Dictionary <uint, uint>(); do { string line = "v " + iter.X.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.Y.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.Z.ToString(System.Globalization.CultureInfo.InvariantCulture); MapVertexNo.Add(iter.PointID, vertexNO++); tw.WriteLine(line); } while (iter.MoveToNext()); // --- create faces iter = p_Model.GetIterator(); do { iter.AlreadyVisited = true; List <Cl3DModel.Cl3DModelPointIterator> neighbors = iter.GetListOfNeighbors(); uint MainPointID; if (!MapVertexNo.TryGetValue(iter.PointID, out MainPointID)) { throw new Exception("Cannot find point ID in the ID dictionary: " + iter.PointID); } uint point1 = 0; uint point2 = 0; uint point3 = 0; foreach (Cl3DModel.Cl3DModelPointIterator point in neighbors) { //if (point.AlreadyVisited) // continue; if (point.RangeImageY == iter.RangeImageY && point.RangeImageX > iter.RangeImageX) // first point { if (!MapVertexNo.TryGetValue(point.PointID, out point1)) { throw new Exception("Cannot find point ID in the ID dictionary: " + iter.PointID); } } if (point.RangeImageY > iter.RangeImageY && point.RangeImageX > iter.RangeImageX) // second point { if (!MapVertexNo.TryGetValue(point.PointID, out point2)) { throw new Exception("Cannot find point ID in the ID dictionary: " + iter.PointID); } } if (point.RangeImageY > iter.RangeImageY && point.RangeImageX == iter.RangeImageX) // third point { if (!MapVertexNo.TryGetValue(point.PointID, out point3)) { throw new Exception("Cannot find point ID in the ID dictionary: " + iter.PointID); } } } string line = ""; if (point1 != 0 && point2 != 0) { line += "f " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point2.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point1.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; if (point3 != 0) { line += "f " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point3.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point2.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; } } else if (point1 != 0 && point3 != 0) { line += "f " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point3.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point1.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; } else if (point2 != 0 && point3 != 0) { line += "f " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point3.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point2.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; } tw.Write(line); } while (iter.MoveToNext()); tw.Close(); } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); uint current = 0; string NeighborhoodSize = m_fNeighborhoodSize.ToString(); if (m_bFirstNeighbor) { NeighborhoodSize = "1Neighb"; } string ShapeIndexString = "ShapeIndex_" + NeighborhoodSize; if (iter.IsValid()) { do { double A = 0; double B = 0; double C = 0; double D = 0; double E = 0; double F = 0; double H = 0; double K = 0; double k1 = 0; double k2 = 0; double ShapeIndex = 0; double CurvednessIndex = 0; List <Cl3DModel.Cl3DModelPointIterator> ListOfneighborhood; double dx; double dy; double dxy; double dxx; double dyy; //------------------------- Neighborhood Custom -------------------------------------------------- if (!iter.IsSpecificValueCalculated(ShapeIndexString) || m_bRecalculateCurvature) { if (!m_bFirstNeighbor) { ClTools.GetNeighborhoodWithGeodesicDistance(out ListOfneighborhood, iter, m_fNeighborhoodSize); } else { ListOfneighborhood = iter.GetListOfNeighbors(); } if (m_bNeighborhoodRotation) { Matrix Rotation = ClTools.CalculateRotationMatrix(iter.NormalVector, new Vector(new double[] { iter.NormalVector[0], iter.NormalVector[1], 1 })); List <ClTools.MainPoint3D> Neighbors = new List <ClTools.MainPoint3D>(); foreach (Cl3DModel.Cl3DModelPointIterator Neighb in ListOfneighborhood) { Matrix after = Rotation * Neighb; Neighbors.Add(new ClTools.MainPoint3D((float)after[0, 0], (float)after[1, 0], (float)after[2, 0], "")); } if (!ClTools.CountSurfaceCoefficients(Neighbors, ref A, ref B, ref C, ref D, ref E, ref F)) { iter.RemoveSpecificValue("Gaussian_" + NeighborhoodSize); iter.RemoveSpecificValue("Mean_" + NeighborhoodSize); iter.RemoveSpecificValue("K1_" + NeighborhoodSize); iter.RemoveSpecificValue("K2_" + NeighborhoodSize); iter.RemoveSpecificValue("ShapeIndex_" + NeighborhoodSize); iter.RemoveSpecificValue("CurvednessIndex_" + NeighborhoodSize); continue; } } else { if (!ClTools.CountSurfaceCoefficients(ListOfneighborhood, ref A, ref B, ref C, ref D, ref E, ref F)) { iter.RemoveSpecificValue("Gaussian_" + NeighborhoodSize); iter.RemoveSpecificValue("Mean_" + NeighborhoodSize); iter.RemoveSpecificValue("K1_" + NeighborhoodSize); iter.RemoveSpecificValue("K2_" + NeighborhoodSize); iter.RemoveSpecificValue("ShapeIndex_" + NeighborhoodSize); iter.RemoveSpecificValue("CurvednessIndex_" + NeighborhoodSize); continue; } } dx = B + 2 * D * iter.X + E * iter.Y; dy = C + E * iter.X + 2 * F * iter.Y; dxy = E; dxx = 2 * D; dyy = 2 * F; //Mean H = ((((1 + Math.Pow(dy, 2)) * dxx) - (2 * dx * dy * dxy) + ((1 + Math.Pow(dx, 2)) * dyy)) / (2 * Math.Pow((1 + Math.Pow(dx, 2) + Math.Pow(dy, 2)), 3.0d / 2.0d))); //Gaussian K = (((dxx * dyy) - Math.Pow(dxy, 2)) / Math.Pow((1 + Math.Pow(dx, 2) + Math.Pow(dy, 2)), 2)); k1 = H + Math.Sqrt(Math.Pow(H, 2) - K); k2 = H - Math.Sqrt(Math.Pow(H, 2) - K); ShapeIndex = 0.5d - (1 / Math.PI) * Math.Atan((k1 + k2) / (k1 - k2)); CurvednessIndex = Math.Sqrt(Math.Pow(k1, 2) + Math.Pow(k2, 2)) / 2; iter.AddSpecificValue("Gaussian_" + NeighborhoodSize, K); iter.AddSpecificValue("Mean_" + NeighborhoodSize, H); iter.AddSpecificValue("K1_" + NeighborhoodSize, k1); iter.AddSpecificValue("K2_" + NeighborhoodSize, k2); iter.AddSpecificValue("ShapeIndex_" + NeighborhoodSize, ShapeIndex); iter.AddSpecificValue("CurvednessIndex_" + NeighborhoodSize, CurvednessIndex); } ClInformationSender.SendInformation((current * 100 / p_Model.ModelPointsCount).ToString(System.Globalization.CultureInfo.InvariantCulture), ClInformationSender.eInformationType.eProgress); current++; } while (iter.MoveToNext()); } }
protected override void Algorithm(ref Cl3DModel p_Model) { MarkHighCurvEdges(ref p_Model); p_Model.ResetVisitedPoints(); //-------------------------------- Cropping Cl3DModel.Cl3DModelPointIterator NoseTip = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip); Cl3DModel.Cl3DModelPointIterator LeftEye = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner); Cl3DModel.Cl3DModelPointIterator RightEye = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner); float distanceBetweenEyes = LeftEye - RightEye; float ossfest = distanceBetweenEyes * 0.4f; //20% of distance between eyes will be taken as a stripe down to search for the mouth hole Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); Dictionary <uint, Cl3DModel.Cl3DModelPointIterator> pointsToRemove = new Dictionary <uint, Cl3DModel.Cl3DModelPointIterator>(); do { if (iter.X > LeftEye.X + ossfest && iter.X < RightEye.X - ossfest && iter.Y < NoseTip.Y - 20 && iter.Y > NoseTip.Y - 43) { // iter.Color = Color.LightBlue; if (iter.IsSpecificValueCalculated("ToRemove_HighCurvature")) { pointsToRemove.Add(iter.PointID, iter.CopyIterator()); } } } while (iter.MoveToNext()); List <List <Cl3DModel.Cl3DModelPointIterator> > ListOfRegions = new List <List <Cl3DModel.Cl3DModelPointIterator> >(); while (pointsToRemove.Count != 0) { Cl3DModel.Cl3DModelPointIterator test = new List <Cl3DModel.Cl3DModelPointIterator>(pointsToRemove.Values)[0]; pointsToRemove.Remove(test.PointID); bool toRemove = false; List <Cl3DModel.Cl3DModelPointIterator> CurrentList = new List <Cl3DModel.Cl3DModelPointIterator>(); ListOfRegions.Add(CurrentList); List <Cl3DModel.Cl3DModelPointIterator> ToCheck = new List <Cl3DModel.Cl3DModelPointIterator>(); ToCheck.Add(test); test.AlreadyVisited = true; do { List <Cl3DModel.Cl3DModelPointIterator> NewToCheck = new List <Cl3DModel.Cl3DModelPointIterator>(); foreach (Cl3DModel.Cl3DModelPointIterator pt in ToCheck) { CurrentList.Add(pt.CopyIterator()); foreach (Cl3DModel.Cl3DModelPointIterator ptNb in pt.GetListOfNeighbors()) { if (ptNb.IsSpecificValueCalculated("ToRemove_HighCurvature") && ptNb.AlreadyVisited == false) { ptNb.AlreadyVisited = true; NewToCheck.Add(ptNb.CopyIterator()); pointsToRemove.Remove(ptNb.PointID); List <Cl3DModel.Cl3DModelPointIterator> Neighbors = ptNb.GetListOfNeighbors(); // if (Neighbors.Count < 8) // that means the points from marked region went to the end of the model very rare happens that the open mouth region is the externatl region // toRemove = true; } } } ToCheck = NewToCheck; NewToCheck = new List <Cl3DModel.Cl3DModelPointIterator>(); } while (ToCheck.Count != 0); if (toRemove) { ListOfRegions.Remove(CurrentList); } } List <Cl3DModel.Cl3DModelPointIterator> BiggestRegion = null; int SizeOfTheBiggest = int.MinValue; for (int i = 0; i < ListOfRegions.Count; i++) { if (ListOfRegions[i].Count > SizeOfTheBiggest) { SizeOfTheBiggest = ListOfRegions[i].Count; BiggestRegion = ListOfRegions[i]; } } //------------------- Creating image of localized mouth part /* int NoseX = NoseTip.RangeImageX; * int NoseY = NoseTip.RangeImageY; * //BiggestRegion * int[,] FMap = null; * if (!FaceMaps.TryGetValue(p_Model.m_sExpression, out FMap)) * { * FMap = new int[200, 200]; * FaceMaps.Add(p_Model.m_sExpression, FMap); * } * Cl3DModel.Cl3DModelPointIterator its = p_Model.GetIterator(); * do * { * int currX = its.RangeImageX; * int currY = its.RangeImageY; * * * int x = currX - NoseX + 100; * int y = currY - NoseY + 100; * * FMap[x, y]++; * } while (its.MoveToNext()); * * int MaxF = int.MinValue; * for (int i = 0; i < 200; i++) * for(int j=0; j< 200; j++) * if (FMap[i, j] > MaxF) * MaxF = FMap[i, j]; * * * //- * int[,] FRem = null; * if (!RemovedMaps.TryGetValue(p_Model.m_sExpression, out FRem)) * { * FRem = new int[200, 200]; * RemovedMaps.Add(p_Model.m_sExpression, FRem); * } * * if (BiggestRegion != null) * { * foreach (Cl3DModel.Cl3DModelPointIterator pp in BiggestRegion) * { * int currX = pp.RangeImageX; * int currY = pp.RangeImageY; * * * int x = currX - NoseX + 100; * int y = currY - NoseY + 100; * * FRem[x, y]++; * } * } * * FRem[NoseTip.RangeImageX - NoseX + 100, NoseTip.RangeImageY - NoseY + 100]++; * // FRem[LeftEye.RangeImageX - NoseX + 100, LeftEye.RangeImageY - NoseY + 100]++; * // FRem[RightEye.RangeImageX - NoseX + 100, RightEye.RangeImageY - NoseY + 100]++; * * * int MaxR = int.MinValue; * for (int i = 0; i < 200; i++) * for (int j = 0; j < 200; j++) * if (FRem[i, j] > MaxR) * MaxR = FRem[i, j]; * * * * * * * * * * Bitmap map = new Bitmap(200, 200); * for (int i = 0; i < 200; i++) * { * for (int j = 0; j < 200; j++) * { * map.SetPixel(i, j, ClTools.GetColorGray(((float)FMap[i, j]) / MaxF, 1.0f)); * if(FRem[i, j] != 0) * map.SetPixel(i, j, ClTools.GetColorGray( 1 - ((float)FRem[i, j]) / MaxR, 1.0f)); * } * } * map.Save("d:\\" + p_Model.m_sExpression + ".bmp"); * return; */ //------------------------------------------------------------ /* TextWriter tw = new StreamWriter("d:\\MouthSizeBosphorus2.txt", false); * * * int ssize = 0; * if (BiggestRegion != null) * ssize = BiggestRegion.Count; * * int[] OldSize; * if(!mouthSize.TryGetValue(p_Model.m_sExpression, out OldSize)) * { * OldSize = new int[2]; * mouthSize.Add(p_Model.m_sExpression, OldSize); * } * OldSize[0] += ssize; * OldSize[1]++; * * foreach(KeyValuePair<string, int[]> val in mouthSize) * tw.WriteLine(val.Key+" "+ val.Value[0].ToString()+ " " + val.Value[1].ToString()); * * tw.Close(); * * return; */ //---------------------------------------------------------------- //---------------------- NO mouth REGION LOCALIZED if (BiggestRegion == null) { ClInformationSender.SendInformation("No mouth localized, normal Geodesic distance calculation", ClInformationSender.eInformationType.eDebugText); if (m_bRemoveRegions) // still there can be vertexes with high curvature (edges between hair and the face) { Cl3DModel.Cl3DModelPointIterator remover = p_Model.GetIterator(); while (remover.IsValid()) { if (remover.IsSpecificValueCalculated("ToRemove_HighCurvature")) { remover = p_Model.RemovePointFromModel(remover); } else { remover.MoveToNext(); } } } ClTools.CalculateGeodesicDistanceFromSourcePointToAllPoints(NoseTip, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip.ToString()); if (!m_bCrop) { return; } iter = p_Model.GetIterator(); while (iter.IsValid()) { if (!iter.IsSpecificValueCalculated(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip)) { iter = p_Model.RemovePointFromModel(iter); } else { double distance = iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip); if (distance > m_fDistence) { iter = p_Model.RemovePointFromModel(iter); } else { iter.MoveToNext(); } } } return; } //------------------------- Mouth REGION LOCALiZED p_Model.ResetVisitedPoints(); List <Cl3DModel.Cl3DModelPointIterator> BorderOfTheBigestRegion = new List <Cl3DModel.Cl3DModelPointIterator>(); foreach (Cl3DModel.Cl3DModelPointIterator pts in BiggestRegion) { if (m_bMarkRegion) { pts.Color = Color.Red; } List <Cl3DModel.Cl3DModelPointIterator> neighb = pts.GetListOfNeighbors(); foreach (Cl3DModel.Cl3DModelPointIterator ppt in neighb) { if (!ppt.AlreadyVisited && !ppt.IsSpecificValueCalculated("ToRemove_HighCurvature")) { BorderOfTheBigestRegion.Add(ppt); ppt.AlreadyVisited = true; } } } if (m_bRemoveRegions) // After we have border of the mouth region we can remove them { Cl3DModel.Cl3DModelPointIterator remover = p_Model.GetIterator(); while (remover.IsValid()) { if (remover.IsSpecificValueCalculated("ToRemove_HighCurvature")) { remover = p_Model.RemovePointFromModel(remover); } else { remover.MoveToNext(); } } } Cl3DModel.Cl3DModelPointIterator MaxLeft = BorderOfTheBigestRegion[0]; Cl3DModel.Cl3DModelPointIterator MaxRight = BorderOfTheBigestRegion[0]; foreach (Cl3DModel.Cl3DModelPointIterator pt in BorderOfTheBigestRegion) { if (pt.X < MaxLeft.X) { MaxLeft = pt; } if (pt.X > MaxRight.X) { MaxRight = pt; } } int size = (int)Math.Abs(MaxLeft.X - MaxRight.X) + 1; List <Cl3DModel.Cl3DModelPointIterator>[] histogram = new List <Cl3DModel.Cl3DModelPointIterator> [size]; foreach (Cl3DModel.Cl3DModelPointIterator pt in BorderOfTheBigestRegion) { int pos = (int)(pt.X - MaxLeft.X); if (histogram[pos] == null) { histogram[pos] = new List <Cl3DModel.Cl3DModelPointIterator>(); } histogram[pos].Add(pt); } Dictionary <uint, uint> movingPoints = new Dictionary <uint, uint>(); for (int i = 0; i < size; i++) { if (histogram[i] != null && histogram[i].Count != 0) { //Color cl = ClTools.GetColorRGB(((float)i) / size, 1.0f); Cl3DModel.Cl3DModelPointIterator UpperPoint = histogram[i][0]; Cl3DModel.Cl3DModelPointIterator LowerPoint = histogram[i][0]; foreach (Cl3DModel.Cl3DModelPointIterator pts in histogram[i]) { // pts.Color = cl; if (UpperPoint.Y < pts.Y) { UpperPoint = pts; } if (LowerPoint.Y > pts.Y) { LowerPoint = pts; } } //UpperPoint from this one if (UpperPoint.PointID != LowerPoint.PointID) { float distance = Math.Min(LowerPoint - MaxLeft, LowerPoint - MaxRight); List <Cl3DModel.Cl3DModelPointIterator> neighborhood = null; ClTools.GetNeighborhoodWithGeodesicDistance(out neighborhood, LowerPoint, distance); Cl3DModel.Cl3DModelPointIterator ClosestPoint = LowerPoint; float MinDistance = LowerPoint - UpperPoint; foreach (Cl3DModel.Cl3DModelPointIterator ptNeighb in neighborhood) { // ptNeighb.Color = Color.Pink; float newDistance = ptNeighb - UpperPoint; if (newDistance < MinDistance) { MinDistance = newDistance; ClosestPoint = ptNeighb; } } Color cl = ClTools.GetColorRGB(((float)i) / size, 1.0f); // ClosestPoint.Color = cl; // UpperPoint.Color = cl; movingPoints.Add(UpperPoint.PointID, ClosestPoint.PointID); } } } //-------------------------------- Calculation of the geodesic using movement points p_Model.ResetVisitedPoints(); ClTools.CalculateGeodesicDistanceFromSourcePointToAllPointsWithMovement(NoseTip, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip.ToString(), movingPoints); if (!m_bCrop) { return; } iter = p_Model.GetIterator(); while (iter.IsValid()) { if (!iter.IsSpecificValueCalculated(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip)) { iter = p_Model.RemovePointFromModel(iter); } else { double distance = iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip); if (distance > m_fDistence) { iter = p_Model.RemovePointFromModel(iter); } else { iter.MoveToNext(); } } } }
protected override void Algorithm(ref Cl3DModel p_Model) { CORFile landmarkFile = ReadCORFile(p_Model.ModelFileFolder + p_Model.ModelFileName + ".cor"); //search for the closest point from the model to the read landmark Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { throw new Exception("Iterator in the model is not valid!"); } Cl3DModel.Cl3DModelPointIterator SavedNoseTip = iter.CopyIterator(); float NoseTipDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.NoseTip.X - SavedNoseTip.X, 2) + Math.Pow(landmarkFile.NoseTip.Y - SavedNoseTip.Y, 2) + Math.Pow(landmarkFile.NoseTip.Z - SavedNoseTip.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedLeftEyeRightCorner = iter.CopyIterator(); float LeftEyeRightCornerDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftEyeRightCorner.X - SavedLeftEyeRightCorner.X, 2) + Math.Pow(landmarkFile.LeftEyeRightCorner.Y - SavedLeftEyeRightCorner.Y, 2) + Math.Pow(landmarkFile.LeftEyeRightCorner.Z - SavedLeftEyeRightCorner.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedRightEyeLeftCorner = iter.CopyIterator(); float RightEyeLeftCornerDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightEyeLeftCorner.X - SavedRightEyeLeftCorner.X, 2) + Math.Pow(landmarkFile.RightEyeLeftCorner.Y - SavedRightEyeLeftCorner.Y, 2) + Math.Pow(landmarkFile.RightEyeLeftCorner.Z - SavedRightEyeLeftCorner.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedRightEyeRightCorner = iter.CopyIterator(); float RightEyeRightCornerDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightEyeRightCorner.X - SavedRightEyeRightCorner.X, 2) + Math.Pow(landmarkFile.RightEyeRightCorner.Y - SavedRightEyeRightCorner.Y, 2) + Math.Pow(landmarkFile.RightEyeRightCorner.Z - SavedRightEyeRightCorner.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedLeftEyeLeftCorner = iter.CopyIterator(); float LeftEyeLeftCornerDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftEyeLeftCorner.X - SavedLeftEyeLeftCorner.X, 2) + Math.Pow(landmarkFile.LeftEyeLeftCorner.Y - SavedLeftEyeLeftCorner.Y, 2) + Math.Pow(landmarkFile.LeftEyeLeftCorner.Z - SavedLeftEyeLeftCorner.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedLeftCornerOfNose = iter.CopyIterator(); float LeftCornerOfNoseDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftCornerOfNose.X - SavedLeftCornerOfNose.X, 2) + Math.Pow(landmarkFile.LeftCornerOfNose.Y - SavedLeftCornerOfNose.Y, 2) + Math.Pow(landmarkFile.LeftCornerOfNose.Z - SavedLeftCornerOfNose.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedRightCornerOfNose = iter.CopyIterator(); float RightCornerOfNoseDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightCornerOfNose.X - SavedRightCornerOfNose.X, 2) + Math.Pow(landmarkFile.RightCornerOfNose.Y - SavedRightCornerOfNose.Y, 2) + Math.Pow(landmarkFile.RightCornerOfNose.Z - SavedRightCornerOfNose.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedLeftCornerOfLips = iter.CopyIterator(); float LeftCornerOfLipsDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftCornerOfLips.X - SavedLeftCornerOfLips.X, 2) + Math.Pow(landmarkFile.LeftCornerOfLips.Y - SavedLeftCornerOfLips.Y, 2) + Math.Pow(landmarkFile.LeftCornerOfLips.Z - SavedLeftCornerOfLips.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedRightCornerOfLips = iter.CopyIterator(); float RightCornerOfLipsDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightCornerOfLips.X - SavedRightCornerOfLips.X, 2) + Math.Pow(landmarkFile.RightCornerOfLips.Y - SavedRightCornerOfLips.Y, 2) + Math.Pow(landmarkFile.RightCornerOfLips.Z - SavedRightCornerOfLips.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedUpperLip = iter.CopyIterator(); float UpperLipDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.UpperLip.X - SavedUpperLip.X, 2) + Math.Pow(landmarkFile.UpperLip.Y - SavedUpperLip.Y, 2) + Math.Pow(landmarkFile.UpperLip.Z - SavedUpperLip.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedBottomLip = iter.CopyIterator(); float BottomLipDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.BottomLip.X - SavedBottomLip.X, 2) + Math.Pow(landmarkFile.BottomLip.Y - SavedBottomLip.Y, 2) + Math.Pow(landmarkFile.BottomLip.Z - SavedBottomLip.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedLeftEyeUpperEyelid = iter.CopyIterator(); float LeftEyeUpperEyelidDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftEyeUpperEyelid.X - SavedLeftEyeUpperEyelid.X, 2) + Math.Pow(landmarkFile.LeftEyeUpperEyelid.Y - SavedLeftEyeUpperEyelid.Y, 2) + Math.Pow(landmarkFile.LeftEyeUpperEyelid.Z - SavedLeftEyeUpperEyelid.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedLeftEyeBottomEyelid = iter.CopyIterator(); float LeftEyeBottomEyelidDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftEyeBottomEyelid.X - SavedLeftEyeBottomEyelid.X, 2) + Math.Pow(landmarkFile.LeftEyeBottomEyelid.Y - SavedLeftEyeBottomEyelid.Y, 2) + Math.Pow(landmarkFile.LeftEyeBottomEyelid.Z - SavedLeftEyeBottomEyelid.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedRightEyeUpperEyelid = iter.CopyIterator(); float RightEyeUpperEyelidDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightEyeUpperEyelid.X - SavedRightEyeUpperEyelid.X, 2) + Math.Pow(landmarkFile.RightEyeUpperEyelid.Y - SavedRightEyeUpperEyelid.Y, 2) + Math.Pow(landmarkFile.RightEyeUpperEyelid.Z - SavedRightEyeUpperEyelid.Z, 2)); Cl3DModel.Cl3DModelPointIterator SavedRightEyeBottomEyelid = iter.CopyIterator(); float RightEyeBottomEyelidDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightEyeBottomEyelid.X - SavedRightEyeBottomEyelid.X, 2) + Math.Pow(landmarkFile.RightEyeBottomEyelid.Y - SavedRightEyeBottomEyelid.Y, 2) + Math.Pow(landmarkFile.RightEyeBottomEyelid.Z - SavedRightEyeBottomEyelid.Z, 2)); do { float NewNoseTipDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.NoseTip.X - iter.X, 2) + Math.Pow(landmarkFile.NoseTip.Y - iter.Y, 2) + Math.Pow(landmarkFile.NoseTip.Z - iter.Z, 2)); float NewLeftEyeRightCornerDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftEyeRightCorner.X - iter.X, 2) + Math.Pow(landmarkFile.LeftEyeRightCorner.Y - iter.Y, 2) + Math.Pow(landmarkFile.LeftEyeRightCorner.Z - iter.Z, 2)); float NewRightEyeLeftCornerDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightEyeLeftCorner.X - iter.X, 2) + Math.Pow(landmarkFile.RightEyeLeftCorner.Y - iter.Y, 2) + Math.Pow(landmarkFile.RightEyeLeftCorner.Z - iter.Z, 2)); float NewLeftEyeLeftCornerDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftEyeLeftCorner.X - iter.X, 2) + Math.Pow(landmarkFile.LeftEyeLeftCorner.Y - iter.Y, 2) + Math.Pow(landmarkFile.LeftEyeLeftCorner.Z - iter.Z, 2)); float NewRightEyeRightCornerDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightEyeRightCorner.X - iter.X, 2) + Math.Pow(landmarkFile.RightEyeRightCorner.Y - iter.Y, 2) + Math.Pow(landmarkFile.RightEyeRightCorner.Z - iter.Z, 2)); float NewLeftCornerOfNoseDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftCornerOfNose.X - iter.X, 2) + Math.Pow(landmarkFile.LeftCornerOfNose.Y - iter.Y, 2) + Math.Pow(landmarkFile.LeftCornerOfNose.Z - iter.Z, 2)); float NewRightCornerOfNoseDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightCornerOfNose.X - iter.X, 2) + Math.Pow(landmarkFile.RightCornerOfNose.Y - iter.Y, 2) + Math.Pow(landmarkFile.RightCornerOfNose.Z - iter.Z, 2)); float NewLeftCornerOfLipsDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftCornerOfLips.X - iter.X, 2) + Math.Pow(landmarkFile.LeftCornerOfLips.Y - iter.Y, 2) + Math.Pow(landmarkFile.LeftCornerOfLips.Z - iter.Z, 2)); float NewRightCornerOfLipsDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightCornerOfLips.X - iter.X, 2) + Math.Pow(landmarkFile.RightCornerOfLips.Y - iter.Y, 2) + Math.Pow(landmarkFile.RightCornerOfLips.Z - iter.Z, 2)); float NewUpperLipDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.UpperLip.X - iter.X, 2) + Math.Pow(landmarkFile.UpperLip.Y - iter.Y, 2) + Math.Pow(landmarkFile.UpperLip.Z - iter.Z, 2)); float NewBottomLipDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.BottomLip.X - iter.X, 2) + Math.Pow(landmarkFile.BottomLip.Y - iter.Y, 2) + Math.Pow(landmarkFile.BottomLip.Z - iter.Z, 2)); float NewLeftEyeUpperEyelidDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftEyeUpperEyelid.X - iter.X, 2) + Math.Pow(landmarkFile.LeftEyeUpperEyelid.Y - iter.Y, 2) + Math.Pow(landmarkFile.LeftEyeUpperEyelid.Z - iter.Z, 2)); float NewLeftEyeBottomEyelidDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.LeftEyeBottomEyelid.X - iter.X, 2) + Math.Pow(landmarkFile.LeftEyeBottomEyelid.Y - iter.Y, 2) + Math.Pow(landmarkFile.LeftEyeBottomEyelid.Z - iter.Z, 2)); float NewRightEyeUpperEyelidDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightEyeUpperEyelid.X - iter.X, 2) + Math.Pow(landmarkFile.RightEyeUpperEyelid.Y - iter.Y, 2) + Math.Pow(landmarkFile.RightEyeUpperEyelid.Z - iter.Z, 2)); float NewRightEyeBottomEyelidDistance = (float)Math.Sqrt(Math.Pow(landmarkFile.RightEyeBottomEyelid.X - iter.X, 2) + Math.Pow(landmarkFile.RightEyeBottomEyelid.Y - iter.Y, 2) + Math.Pow(landmarkFile.RightEyeBottomEyelid.Z - iter.Z, 2)); if (NewNoseTipDistance < NoseTipDistance) { NoseTipDistance = NewNoseTipDistance; SavedNoseTip = iter.CopyIterator(); } if (NewLeftEyeRightCornerDistance < LeftEyeRightCornerDistance) { LeftEyeRightCornerDistance = NewLeftEyeRightCornerDistance; SavedLeftEyeRightCorner = iter.CopyIterator(); } if (NewRightEyeLeftCornerDistance < RightEyeLeftCornerDistance) { RightEyeLeftCornerDistance = NewRightEyeLeftCornerDistance; SavedRightEyeLeftCorner = iter.CopyIterator(); } if (NewRightEyeRightCornerDistance < RightEyeRightCornerDistance) { RightEyeRightCornerDistance = NewRightEyeRightCornerDistance; SavedRightEyeRightCorner = iter.CopyIterator(); } if (NewLeftEyeLeftCornerDistance < LeftEyeLeftCornerDistance) { LeftEyeLeftCornerDistance = NewLeftEyeLeftCornerDistance; SavedLeftEyeLeftCorner = iter.CopyIterator(); } if (NewLeftCornerOfNoseDistance < LeftCornerOfNoseDistance) { LeftCornerOfNoseDistance = NewLeftCornerOfNoseDistance; SavedLeftCornerOfNose = iter.CopyIterator(); } if (NewRightCornerOfNoseDistance < RightCornerOfNoseDistance) { RightCornerOfNoseDistance = NewRightCornerOfNoseDistance; SavedRightCornerOfNose = iter.CopyIterator(); } if (NewLeftCornerOfLipsDistance < LeftCornerOfLipsDistance) { LeftCornerOfLipsDistance = NewLeftCornerOfLipsDistance; SavedLeftCornerOfLips = iter.CopyIterator(); } if (NewRightCornerOfLipsDistance < RightCornerOfLipsDistance) { RightCornerOfLipsDistance = NewRightCornerOfLipsDistance; SavedRightCornerOfLips = iter.CopyIterator(); } if (NewUpperLipDistance < UpperLipDistance) { UpperLipDistance = NewUpperLipDistance; SavedUpperLip = iter.CopyIterator(); } if (NewBottomLipDistance < BottomLipDistance) { BottomLipDistance = NewBottomLipDistance; SavedBottomLip = iter.CopyIterator(); } if (NewLeftEyeUpperEyelidDistance < LeftEyeUpperEyelidDistance) { LeftEyeUpperEyelidDistance = NewLeftEyeUpperEyelidDistance; SavedLeftEyeUpperEyelid = iter.CopyIterator(); } if (NewLeftEyeBottomEyelidDistance < LeftEyeBottomEyelidDistance) { LeftEyeBottomEyelidDistance = NewLeftEyeBottomEyelidDistance; SavedLeftEyeBottomEyelid = iter.CopyIterator(); } if (NewRightEyeUpperEyelidDistance < RightEyeUpperEyelidDistance) { RightEyeUpperEyelidDistance = NewRightEyeUpperEyelidDistance; SavedRightEyeUpperEyelid = iter.CopyIterator(); } if (NewRightEyeBottomEyelidDistance < RightEyeBottomEyelidDistance) { RightEyeBottomEyelidDistance = NewRightEyeBottomEyelidDistance; SavedRightEyeBottomEyelid = iter.CopyIterator(); } } while (iter.MoveToNext()); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip, SavedNoseTip); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner, SavedRightEyeLeftCorner); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner, SavedLeftEyeRightCorner); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeLeftCorner, SavedLeftEyeLeftCorner); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeRightCorner, SavedRightEyeRightCorner); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.LeftCornerOfNose, SavedLeftCornerOfNose); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.RightCornerOfNose, SavedRightCornerOfNose); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.LeftCornerOfLips, SavedLeftCornerOfLips); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.RightCornerOfLips, SavedRightCornerOfLips); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.UpperLip, SavedUpperLip); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.BottomLip, SavedBottomLip); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeUpperEyelid, SavedLeftEyeUpperEyelid); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeBottomEyelid, SavedLeftEyeBottomEyelid); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeUpperEyelid, SavedRightEyeUpperEyelid); p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeBottomEyelid, SavedRightEyeBottomEyelid); }
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[,] Map; int width = 0; int height = 0; int offsetX = 0; int offsetY = 0; ClTools.CreateGridBasedOnRangeValues(p_Model, out Map, out width, out height, out offsetX, out offsetY); double SumOfKernelMatrix = 0; double[,] Mask = GetGaussianMatrix(MaskSize, 2.0f, out SumOfKernelMatrix); int pointsFromCenter = (MaskSize / 2); for (int centX = 0; centX < width; centX++) { for (int centY = 0; centY < height; centY++) { if (Map[centX, centY] == null) { continue; } int XBeginning = centX - pointsFromCenter; int YBeginning = centY - pointsFromCenter; double value = 0; bool didBreak = false; for (int xi = 0; xi < MaskSize; xi++) { for (int yi = 0; yi < MaskSize; yi++) { if (XBeginning + xi >= 0 && XBeginning + xi < width && YBeginning + yi >= 0 && YBeginning + yi < height && Map[XBeginning + xi, YBeginning + yi] != null) { value += Mask[xi, yi] * Map[XBeginning + xi, YBeginning + yi].Z; } else { Map[centX, centY].AlreadyVisited = true; // Map[centX, centY].Color = Color.Red; didBreak = true; break; } } if (didBreak) { break; } } if (!didBreak) { Map[centX, centY].Z = (float)(value / SumOfKernelMatrix); } } } Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); do { if (iter.AlreadyVisited) { iter = p_Model.RemovePointFromModel(iter); } else { iter.MoveToNext(); } } while (iter.IsValid()); }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (iter.IsValid()) { do { double H; double K; if (!iter.GetSpecificValue("Gaussian_" + NeighborhoodSize, out K)) { continue; } if (!iter.GetSpecificValue("Mean_" + NeighborhoodSize, out H)) { continue; } if (H < 0 && K < 0) // Saddle ridge { iter.Color = Color.FromArgb(0, 0, 255); //Blue; } else if (H == 0 && K < 0) // Minimal Surface { iter.Color = Color.Orange; } else if (H > 0 && K < 0) // Saddle Valley { iter.Color = Color.FromArgb(255, 255, 0); //Yellow; } else if (H < 0 && K == 0) // Ridge, Cylindrical convex (wypukłość) { iter.Color = Color.FromArgb(0, 255, 255); //SkyBlue; } else if (H == 0 && K == 0) // Plane { iter.Color = Color.FromArgb(255, 255, 255); } else if (H > 0 && K == 0) // Valley, Cylindrical concave (wklęsłość) { iter.Color = Color.FromArgb(255, 0, 255); //Pink; } else if (H < 0 && K > 0) // Peak, Elliptical convex (wypukłość) { iter.Color = Color.FromArgb(0, 255, 0); //Green; } else if (H == 0 && K > 0) // !!! Impossible { iter.Color = Color.Black; } else if (H > 0 && K > 0) // Pit, Elliptical concave (wklęsłość) { iter.Color = Color.FromArgb(255, 0, 0); //Red; } else { iter.Color = Color.White; } }while (iter.MoveToNext()); } }
protected override void Algorithm(ref Cl3DModel p_Model) { if (m_sFileName.Length == 0) { m_sFileName = p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2"; } Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { throw new Exception("Iterator in the model is not valid"); } using (TextWriter tw = new StreamWriter(m_sFileName, false)) { Cl3DModel.Cl3DModelPointIterator NoseTip = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip); tw.WriteLine("CenterVertex " + (NoseTip.PointID + 1).ToString()); do { uint ID = iter.PointID + 1; double geodesicDistance = 0; if (!iter.GetSpecificValue("GeodesicDistanceToNoseTip", out geodesicDistance)) { geodesicDistance = 100; } int R = 0; R = (R << 8) + (int)iter.Color.R; int G = 0; G = (G << 8) + (int)iter.Color.G; int B = 0; B = (B << 8) + (int)iter.Color.B; string line = "Vertex " + ID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.X.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.Y.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + iter.Z.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + geodesicDistance.ToString(System.Globalization.CultureInfo.InvariantCulture) + " {rgb=(" + ((float)R / 255.0f).ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + ((float)G / 255.0f).ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + ((float)B / 255.0f).ToString(System.Globalization.CultureInfo.InvariantCulture) + ")}"; tw.WriteLine(line); } while (iter.MoveToNext()); // --- create faces iter = p_Model.GetIterator(); uint FaceNO = 1; do { iter.AlreadyVisited = true; List <Cl3DModel.Cl3DModelPointIterator> neighbors = iter.GetListOfNeighbors(); uint MainPointID = iter.PointID + 1; uint point1 = 0; bool point1Founded = false; uint point2 = 0; bool point2Founded = false; uint point3 = 0; bool point3Founded = false; uint point4Exc = 0; bool point4ExcFounded = false; uint point5Exc = 0; bool point5ExcFounded = false; uint point6Exc = 0; bool point6ExcFounded = false; foreach (Cl3DModel.Cl3DModelPointIterator point in neighbors) { if (point.RangeImageY == iter.RangeImageY && point.RangeImageX > iter.RangeImageX) // first point { point1 = point.PointID + 1; point1Founded = true; } if (point.RangeImageY > iter.RangeImageY && point.RangeImageX > iter.RangeImageX) // second point { point2 = point.PointID + 1; point2Founded = true; } if (point.RangeImageY > iter.RangeImageY && point.RangeImageX == iter.RangeImageX) // third point { point3 = point.PointID + 1; point3Founded = true; } if (point.RangeImageY < iter.RangeImageY && point.RangeImageX > iter.RangeImageX) // second point { point4Exc = point.PointID + 1; point4ExcFounded = true; } if (point.RangeImageY > iter.RangeImageY && point.RangeImageX < iter.RangeImageX) // second point { point5Exc = point.PointID + 1; point5ExcFounded = true; } if (point.RangeImageY < iter.RangeImageY && point.RangeImageX == iter.RangeImageX) // second point { point6Exc = point.PointID + 1; point6ExcFounded = true; } } string line = ""; if (point1Founded && point2Founded) { line += "Face " + FaceNO.ToString() + " " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point2.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point1.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; FaceNO++; if (point3Founded) { line += "Face " + FaceNO.ToString() + " " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point3.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point2.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; FaceNO++; } if (!point6ExcFounded && point4ExcFounded) { line += "Face " + FaceNO.ToString() + " " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point1.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point4Exc.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; FaceNO++; } } else if (point1Founded && point3Founded) { line += "Face " + FaceNO.ToString() + " " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point3.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point1.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; FaceNO++; } else if (point2Founded && point3Founded) { line += "Face " + FaceNO.ToString() + " " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point3.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + point2.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; FaceNO++; } /*else if (point1Founded && !point2Founded && !point3Founded && point4ExcFounded) * { * line += "Face " + FaceNO.ToString() + " " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + * point4Exc.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + * point1.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; * FaceNO++; * * } */ /*else if (!point1Founded && !point2Founded && point3Founded && point5ExcFounded) * { * line += "Face " + FaceNO.ToString() + " " + MainPointID.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + * point3.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + * point5Exc.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\n"; * FaceNO++; * * } */ tw.Write(line); } while (iter.MoveToNext()); tw.Close(); } }
protected override void Algorithm(ref Cl3DModel p_Model) { string FileName = p_Model.ModelFileFolder + p_Model.ModelFileName + ".lm3"; string line = ""; bool bName = false; string Name = ""; ClTools.MainPoint3D point = null; List <ClTools.MainPoint3D> points = new List <ClTools.MainPoint3D>(); using (StreamReader FileStream = File.OpenText(FileName)) { while ((line = FileStream.ReadLine()) != null) { if (line.Contains("#") || line.Length == 0) { continue; } if (line.Contains("landmarks")) { bName = true; continue; } if (bName) { Name = line; bName = false; } else { string[] coordinates = line.Split(' '); if (coordinates.Length != 3) { throw new Exception("Incorrect format, less than 3 coordinates for a landmark"); } points.Add(new ClTools.MainPoint3D(Single.Parse(coordinates[0], System.Globalization.CultureInfo.InvariantCulture), Single.Parse(coordinates[1], System.Globalization.CultureInfo.InvariantCulture), Single.Parse(coordinates[2], System.Globalization.CultureInfo.InvariantCulture), Name)); bName = true; } } } Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { throw new Exception("Iterator in the model is not valid!"); } do { foreach (ClTools.MainPoint3D pts in points) { pts.CheckClosest(iter); } } while (iter.MoveToNext()); foreach (ClTools.MainPoint3D pts in points) { p_Model.AddSpecificPoint(pts.Name, pts.ClosestPoint); } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) { throw new Exception("Iter is not valid"); } if (m_ResetColor) { do { iter.Color = Color.White; } while (iter.MoveToNext()); return; } if (!m_bMinMaxPreset) { bool firstTime = true; do { double Value; if (m_RangeColor) { Value = iter.Z; } else if (!iter.GetSpecificValue(m_SpecificValue, out Value)) { continue; } if (firstTime) { m_dMaxValue = Value; m_dMinValue = Value; firstTime = false; continue; } if (Value > m_dMaxValue) { m_dMaxValue = Value; } if (Value < m_dMinValue) { m_dMinValue = Value; } } while (iter.MoveToNext()); } if (m_SpecificValue.Contains("ShapeIndex") && !m_RangeColor) { m_dMinValue = 0; m_dMaxValue = 1; } if (m_bMaxMinFromNoseAndEyes) { Cl3DModel.Cl3DModelPointIterator NoseTip = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip); List <Cl3DModel.Cl3DModelPointIterator> NeighborhoodNose = null; ClTools.GetNeighborhoodWithGeodesicDistance(out NeighborhoodNose, NoseTip, 10f); if (m_sMinValuePointName.Equals("Nose")) { m_dMinValue = NoseTip.GetSpecificValue(m_SpecificValue); foreach (Cl3DModel.Cl3DModelPointIterator nb in NeighborhoodNose) { double currVal = nb.GetSpecificValue(m_SpecificValue); if (currVal < m_dMinValue) { m_dMinValue = currVal; } } } else if (m_sMaxValuePointName.Equals("Nose")) { m_dMaxValue = NoseTip.GetSpecificValue(m_SpecificValue); foreach (Cl3DModel.Cl3DModelPointIterator nb in NeighborhoodNose) { double currVal = nb.GetSpecificValue(m_SpecificValue); if (currVal > m_dMaxValue) { m_dMaxValue = currVal; } } } NeighborhoodNose = null; Cl3DModel.Cl3DModelPointIterator Eye1 = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner); Cl3DModel.Cl3DModelPointIterator Eye2 = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner); List <Cl3DModel.Cl3DModelPointIterator> NeighborhoodEye1 = null; List <Cl3DModel.Cl3DModelPointIterator> NeighborhoodEye2 = null; ClTools.GetNeighborhoodWithGeodesicDistance(out NeighborhoodEye1, Eye1, 10f); ClTools.GetNeighborhoodWithGeodesicDistance(out NeighborhoodEye2, Eye2, 10f); NeighborhoodEye1.Add(Eye2); foreach (Cl3DModel.Cl3DModelPointIterator ne in NeighborhoodEye2) { NeighborhoodEye1.Add(ne); } if (m_sMinValuePointName.Equals("Eye")) { m_dMinValue = Eye1.GetSpecificValue(m_SpecificValue); foreach (Cl3DModel.Cl3DModelPointIterator nb in NeighborhoodEye1) { double currVal = nb.GetSpecificValue(m_SpecificValue); if (currVal < m_dMinValue) { m_dMinValue = currVal; } } } else if (m_sMaxValuePointName.Equals("Eye")) { m_dMaxValue = Eye1.GetSpecificValue(m_SpecificValue); foreach (Cl3DModel.Cl3DModelPointIterator nb in NeighborhoodEye1) { double currVal = nb.GetSpecificValue(m_SpecificValue); if (currVal > m_dMaxValue) { m_dMaxValue = currVal; } } } } iter = p_Model.GetIterator(); do { double Value; if (m_RangeColor) { Value = iter.Z; } else if (!iter.GetSpecificValue(m_SpecificValue, out Value)) { continue; } double divide = 1; if (m_dMaxValue != m_dMinValue) { divide = (m_dMaxValue - m_dMinValue); } if (m_Color == ColorType.RGB) { iter.Color = ClTools.GetColorRGB((float)((Value - m_dMinValue) / divide), 1.0f); } else if (m_Color == ColorType.Gray) { iter.Color = ClTools.GetColorGray((float)((Value - m_dMinValue) / divide), 1.0f); } else if (m_Color == ColorType.R) { Color PartialColor = ClTools.GetColorRGB((float)((Value - m_dMinValue) / divide), 1.0f); int R = 0; R = (R << 8) + (int)PartialColor.R; int G = 0; G = (G << 8) + (int)PartialColor.G; int B = 0; B = (B << 8) + (int)PartialColor.B; Color newColor = Color.FromArgb((R + G + B) / 3, iter.Color.G, iter.Color.B); iter.Color = newColor; } else if (m_Color == ColorType.G) { Color PartialColor = ClTools.GetColorRGB((float)((Value - m_dMinValue) / divide), 1.0f); int R = 0; R = (R << 8) + (int)PartialColor.R; int G = 0; G = (G << 8) + (int)PartialColor.G; int B = 0; B = (B << 8) + (int)PartialColor.B; Color newColor = Color.FromArgb(iter.Color.R, (R + G + B) / 3, iter.Color.B); iter.Color = newColor; } else if (m_Color == ColorType.B) { Color PartialColor = ClTools.GetColorRGB((float)((Value - m_dMinValue) / divide), 1.0f); int R = 0; R = (R << 8) + (int)PartialColor.R; int G = 0; G = (G << 8) + (int)PartialColor.G; int B = 0; B = (B << 8) + (int)PartialColor.B; Color newColor = Color.FromArgb(iter.Color.R, iter.Color.G, (R + G + B) / 3); iter.Color = newColor; } } while (iter.MoveToNext()); ClInformationSender.SendInformation(m_SpecificValue.ToString() + " Max: " + m_dMaxValue.ToString() + " Min: " + m_dMinValue.ToString(), ClInformationSender.eInformationType.eColorMapChanged); }