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(); } }
public override void Read(Cl3DModel p_mModel3D, string p_sFilePath) { try { using (FileStream fs = File.OpenRead(p_sFilePath)) { BinaryReader ReaderBinary = new BinaryReader(fs); while (true) { try { short number = ReaderBinary.ReadInt16(); for (short i = 0; i < number; i++) { short X = ReaderBinary.ReadInt16(); short Y = ReaderBinary.ReadInt16(); short Z = ReaderBinary.ReadInt16(); p_mModel3D.AddPointToModel((float)X/10.0f, (float)Y/10.0f, (float)-Z/10.0f); } } catch (System.IO.EndOfStreamException) { break; } } fs.Close(); } } catch (Exception e) { p_mModel3D.ResetModel(); throw e; } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator leftLipsCorner = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftCornerOfLips); Cl3DModel.Cl3DModelPointIterator rightLipsCorner = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightCornerOfLips); Cl3DModel.Cl3DModelPointIterator UpperLip = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.UpperLip); Cl3DModel.Cl3DModelPointIterator BottomLip = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.BottomLip); Edge[] edges = new Edge[3]; 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); edges[0] = new Edge((int)leftLipsCorner.RangeImageX - OffsetX, (int)leftLipsCorner.RangeImageY - OffsetY, (int)UpperLip.RangeImageX - OffsetX, (int)UpperLip.RangeImageY - OffsetY); edges[1] = new Edge((int)UpperLip.RangeImageX - OffsetX, (int)UpperLip.RangeImageY - OffsetY, (int)BottomLip.RangeImageX - OffsetX, (int)BottomLip.RangeImageY - OffsetY); edges[2] = new Edge((int)BottomLip.RangeImageX - OffsetX, (int)BottomLip.RangeImageY - OffsetY, (int)leftLipsCorner.RangeImageX - OffsetX, (int)leftLipsCorner.RangeImageY - OffsetY); RemoveTriangle(edges); edges[0] = new Edge((int)UpperLip.RangeImageX - OffsetX, (int)UpperLip.RangeImageY - OffsetY, (int)rightLipsCorner.RangeImageX - OffsetX, (int)rightLipsCorner.RangeImageY - OffsetY); edges[1] = new Edge((int)rightLipsCorner.RangeImageX - OffsetX, (int)rightLipsCorner.RangeImageY - OffsetY, (int)BottomLip.RangeImageX - OffsetX, (int)BottomLip.RangeImageY - OffsetY); edges[2] = new Edge((int)BottomLip.RangeImageX - OffsetX, (int)BottomLip.RangeImageY - OffsetY, (int)UpperLip.RangeImageX - OffsetX, (int)UpperLip.RangeImageY - OffsetY); RemoveTriangle(edges); }
public override void Read(Cl3DModel p_mModel3D, string p_sFilePath) { try { using (StreamReader FileStream = File.OpenText(p_sFilePath)) { string line = ""; while ((line = FileStream.ReadLine()) != null) { if(line.Length == 0) continue; if(line[0] == '#') continue; string[] splitted = line.Split(' '); if(splitted[0].Equals("v")) { float X = float.Parse(splitted[1].Replace('.',',')); float Y = float.Parse(splitted[2].Replace('.', ',')); float Z = float.Parse(splitted[3].Replace('.', ',')); p_mModel3D.AddPointToModel(X, Y, Z); } else if(splitted[0].Equals("f")) { if (splitted.Length != 4) throw new Exception("Wrong number of vertexes in the face"); int vertex1 = int.Parse(splitted[1]); int vertex2 = int.Parse(splitted[2]); int vertex3 = int.Parse(splitted[3]); Cl3DModel.Cl3DModelPointIterator iter = p_mModel3D.GetIterator(); Cl3DModel.Cl3DModelPointIterator iter2 = p_mModel3D.GetIterator(); if (!iter.MoveToPoint((uint)--vertex1)) throw new Exception("Cannot find the point with ID: " + vertex1.ToString()); if (!iter2.MoveToPoint((uint)--vertex2)) throw new Exception("Cannot find the point with ID: " + vertex2.ToString()); iter.AddNeighbor(iter2.CopyIterator()); if (!iter2.MoveToPoint((uint)--vertex3)) throw new Exception("Cannot find the point with ID: " + vertex3.ToString()); iter.AddNeighbor(iter2.CopyIterator()); } } } } catch (Exception) { p_mModel3D.ResetModel(); throw; } }
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); }
// public override void SetProperitis(string p_sProperity, string p_sValue) // { // } // public override List<KeyValuePair<string, string>> GetProperitis() // { // } protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); do { iter.X = iter.U; iter.Y = iter.V; iter.Z = 0; } while (iter.MoveToNext()); }
protected override void Algorithm(ref Cl3DModel p_Model) { string fileName = ClTools.ExtractOryginalFileNameFRGC(p_Model.ModelFileName); string expression = ""; if (!ClTools.ClExpressionFRGC.GetExpression(fileName, out expression)) throw new Exception("Cannot find Expression for file " + p_Model.ModelFilePath); p_Model.ModelExpression = expression; ClInformationSender.SendInformation("Model has expression: " + p_Model.ModelExpression, ClInformationSender.eInformationType.eDebugText); }
protected override void Algorithm(ref Cl3DModel p_Model) { string name = p_Model.ModelFilePath + ".locked"; if (File.Exists(name)) throw new Exception("File has been already used by different appication"); using (TextWriter tw = new StreamWriter(name, false)) { tw.WriteLine("@----------------------------------------\n@ 3DModelsPreprocessing\n@ Przemyslaw Szeptycki LIRIS 2009\n@ FILE USED TO LOCK MODEL\n@----------------------------------------\n@ File generated: " + DateTime.Now.ToString()); tw.Close(); } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); do { if (iter.NormalVector != null) { iter.Color = Color.FromArgb((int)Math.Abs((iter.NormalVector[0]) * 255), (int)Math.Abs((iter.NormalVector[1]) * 255), (int)Math.Abs((iter.NormalVector[2]) * 255)); } } while (iter.MoveToNext()); }
protected override void Algorithm(ref Cl3DModel p_Model) { string name = ""; if (p_Model.ModelType.Equals("bnt")) { name = p_Model.ModelFileFolder + p_Model.ModelFileName + ".png"; } else throw new Exception("Method does not supprt this kind of files"); Bitmap Texture = new Bitmap(name); Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); if (!iter.IsValid()) throw new Exception("Model iterator not Valid"); int MinX; int MaxX; int MinY; int MaxY; MinX = iter.RangeImageX; MaxX = iter.RangeImageX; MinY = iter.RangeImageY; MaxY = iter.RangeImageY; do { if (MinX > iter.RangeImageX) MinX = iter.RangeImageX; if (MaxX < iter.RangeImageX) MaxX = iter.RangeImageX; if (MinY > iter.RangeImageY) MinY = iter.RangeImageY; if (MaxY < iter.RangeImageY) MaxY = iter.RangeImageY; } while (iter.MoveToNext()); iter = p_Model.GetIterator(); do { float x = ((float)iter.RangeImageX-MinX)/(MaxX-MinX+1); float y = ((float)iter.RangeImageY-MinY)/(MaxY-MinY+1); iter.Color = Texture.GetPixel( (int)(x *Texture.Width) ,(int)(y*Texture.Height)); iter.AddSpecificValue("Texture", iter.Color.ToArgb()); } while (iter.MoveToNext()); }
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); } }
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; }
public virtual void ReadModel(Cl3DModel p_mModel3D, string p_sFilePath) { if (m_sReaderFileExtension.Equals(p_mModel3D.ModelType)) { try { Read(p_mModel3D, p_sFilePath); } catch (Exception) { p_mModel3D.ResetModel(); throw; } } else throw new ArgumentException("Extension of file doesn't fit to reader object"); }
public float InterpolateCubic(int p_iHoleBegin, int p_iHoleEnd, int p_iRow, Cl3DModel.Cl3DModelPointIterator[,] p_map, float p_fProcent, int p_Height, int p_Width) { float beforeBeginHoleVal = p_map[p_iHoleBegin, p_iRow].Z; float afterBeginHoleVal = p_map[p_iHoleEnd, p_iRow].Z; if (p_iHoleBegin > 2) if (p_map[p_iHoleBegin - 1, p_iRow] != null) beforeBeginHoleVal = p_map[p_iHoleBegin - 1, p_iRow].Z; if (p_iHoleEnd < p_Width - 1) if (p_map[p_iHoleEnd + 1, p_iRow] != null) afterBeginHoleVal = p_map[p_iHoleEnd + 1, p_iRow].Z; return CubicInterpolate(beforeBeginHoleVal, p_map[p_iHoleBegin, p_iRow].Z, p_map[p_iHoleEnd, p_iRow].Z, afterBeginHoleVal, p_fProcent); }
public static void ResetFasade() { m_sProcessedModel = null; m_bIsRunning = false; m_lAlgorithmsList = null; m_lFilesList.Clear(); m_sTestDirectory = @"c:\"; if (m_sProcessingThread != null) { if (m_sProcessingThread.IsAlive) m_sProcessingThread.Abort(); while (m_sProcessingThread.ThreadState != ThreadState.AbortRequested && m_sProcessingThread.ThreadState != ThreadState.Stopped) { } m_sProcessingThread = null; ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStopProcessing); } }
protected override void Algorithm(ref Cl3DModel p_Model) { string name = p_Model.ModelFileFolder + p_Model.ModelFileName + m_sFilePostFix+ ".crr"; List<KeyValuePair<string,Cl3DModel.Cl3DModelPointIterator>> specPoints = p_Model.GetAllSpecificPoints(); using (TextWriter tw = new StreamWriter(name, false)) { tw.WriteLine("@----------------------------------------"); tw.WriteLine("@ Przemyslaw Szeptycki LIRIS 2008"); tw.WriteLine("@ Automatic Model Specific Points Coordinates"); tw.WriteLine("@ Model name: " + p_Model.ModelFileName); tw.WriteLine("@----------------------------------------"); foreach(KeyValuePair<string,Cl3DModel.Cl3DModelPointIterator> point in specPoints) { string line = point.Key + " X: " + point.Value.X.ToString(System.Globalization.CultureInfo.InvariantCulture) + " Y: " + point.Value.Y.ToString(System.Globalization.CultureInfo.InvariantCulture) + " Z: " + point.Value.Z.ToString(System.Globalization.CultureInfo.InvariantCulture); tw.WriteLine(line); } tw.Close(); } }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); float maxX = iter.X; float minX = iter.X; float maxY = iter.Y; float minY = iter.Y; float maxZ = iter.Z; float minZ = iter.Z; do { if (maxX < iter.X) maxX = iter.X; if (maxY < iter.Y) maxY = iter.Y; if (maxZ < iter.Z) maxZ = iter.Z; if (minX > iter.X) minX = iter.X; if (minY > iter.Y) minY = iter.Y; if (minZ > iter.Z) minZ = iter.Z; } while (iter.MoveToNext()); iter = p_Model.GetIterator(); do { int R = (int)(((iter.X - minX) / (maxX - minX)) * 255); int G = (int)(((iter.Y - minY) / (maxY - minY)) * 255); int B = (int)(((iter.Z - minZ) / (maxZ - minZ)) * 255); iter.Color = Color.FromArgb(R, G, B); } while (iter.MoveToNext()); }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator ManualNoseTip = p_Model.GetSpecificPoint("NoseTip"); Cl3DModel.Cl3DModelPointIterator ManualLeftEyeCorner = p_Model.GetSpecificPoint("LeftEyeRightCorner"); Cl3DModel.Cl3DModelPointIterator ManualRightEyeCorner = p_Model.GetSpecificPoint("RightEyeLeftCorner"); Cl3DModel.Cl3DModelPointIterator NoseTip = p_Model.GetSpecificPoint("AutomaticNoseTip"); Cl3DModel.Cl3DModelPointIterator LeftEyeRightCorner = p_Model.GetSpecificPoint("AutomaticLeftEyeRightCorner"); Cl3DModel.Cl3DModelPointIterator RightEyeLeftCorner = p_Model.GetSpecificPoint("AutomaticRightEyeLeftCorner"); float NoseDistance = ManualNoseTip - NoseTip; float RightEyeDistance = ManualRightEyeCorner - RightEyeLeftCorner; float LeftEyeDistance = ManualLeftEyeCorner - LeftEyeRightCorner; TotalModels++; if (NoseDistance > 20 || RightEyeDistance > 20 || LeftEyeDistance > 20) { TextWriter rr = new StreamWriter("d:\\Incorrect.txt", true); rr.WriteLine(p_Model.ModelFilePath + " " + NoseDistance.ToString() + " " + RightEyeDistance.ToString() + " " + LeftEyeDistance.ToString()); rr.Close(); } Dictionary<int, int[]> Dict = null; if(!Precision.TryGetValue("NoseTip", out Dict)) { Dict = new Dictionary<int, int[]>(); Precision.Add("NoseTip", Dict); } int[] outVal = null; if (!Dict.TryGetValue((int)NoseDistance, out outVal)) { outVal = new int[1]; Dict.Add((int)NoseDistance, outVal); } outVal[0]++; if (!Precision.TryGetValue("LeftEye", out Dict)) { Dict = new Dictionary<int, int[]>(); Precision.Add("LeftEye", Dict); } if (!Dict.TryGetValue((int)LeftEyeDistance, out outVal)) { outVal = new int[1]; Dict.Add((int)LeftEyeDistance, outVal); } outVal[0]++; if (!Precision.TryGetValue("RightEye", out Dict)) { Dict = new Dictionary<int, int[]>(); Precision.Add("RightEye", Dict); } if (!Dict.TryGetValue((int)RightEyeDistance, out outVal)) { outVal = new int[1]; Dict.Add((int)RightEyeDistance, outVal); } outVal[0]++; TextWriter tw = new StreamWriter("d:\\PointsPrecision.txt", false); foreach(KeyValuePair<string, Dictionary<int, int[]>> prc in Precision) { tw.WriteLine(prc.Key); string Line1 = ""; string Line2 = ""; foreach (KeyValuePair<int, int[]> dd in prc.Value) { Line1 += " " + dd.Key.ToString(); Line2 += " " + dd.Value[0].ToString(); } tw.WriteLine(Line1); tw.WriteLine(Line2); } tw.Close(); }
protected abstract void Algorithm(ref Cl3DModel p_Model);
public virtual void MakeAlgorithm(ref Cl3DModel p_Model) { if (p_Model == null) throw new Exception("NULL model"); ClInformationSender.SendInformation("-> In progress: " + m_sAlgorithmName +" for: " +p_Model.ModelFileName, ClInformationSender.eInformationType.eTextInternal); p_Model.ResetVisitedPoints(); DateTime start = DateTime.Now; m_AlgorithmTime = TimeSpan.Zero; Algorithm(ref p_Model); DateTime stop = DateTime.Now; m_AlgorithmTime = (stop - start); p_Model.IsModelChanged = true; ClInformationSender.SendInformation("-] Finished: " + m_sAlgorithmName + " for: " + p_Model.ModelFileName+" [time: " + m_AlgorithmTime.TotalSeconds + " sec.]", ClInformationSender.eInformationType.eTextInternal); string fullAlgorithmAdditionalData = GetAlgorithmFullPath() + "\n"; foreach (KeyValuePair<string, string> prop in GetProperitis()) fullAlgorithmAdditionalData += "\t" + prop.Key + " -> " + prop.Value + "\n"; p_Model.AddDoneProcessingAlgorithm(fullAlgorithmAdditionalData); }
public virtual void MakeAlgorithm(Cl3DModel p_Model) { MakeAlgorithm(ref p_Model); }
protected override void Algorithm(ref Cl3DModel p_Model) { string name = p_Model.ModelFileName; if(m_CharsToSubstract != 0) name = name.Substring(0, name.Length - m_CharsToSubstract); if (!IDS) { string fileName = p_Model.ModelFileFolder + name + m_sFilePostFix + ".pts"; Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); using (StreamReader FileStream = File.OpenText(fileName)) { string line = ""; while ((line = FileStream.ReadLine()) != null) { if (line.Length == 0) continue; if (line[0].Equals('@')) continue; string[] splited = line.Split(' '); Cl3DModel.eSpecificPoints type = Cl3DModel.eSpecificPoints.LeftEyeRightCorner; if (splited[0].Equals("LeftEyeRightCorner")) type = Cl3DModel.eSpecificPoints.LeftEyeRightCorner; else if (splited[0].Equals("RightEyeLeftCorner")) type = Cl3DModel.eSpecificPoints.RightEyeLeftCorner; else if (splited[0].Equals("NoseTip")) type = Cl3DModel.eSpecificPoints.NoseTip; else continue; uint ID = UInt32.Parse(splited[1]); if (!iter.MoveToPoint(ID)) throw new Exception("Cannot find point with ID: " + splited[1]); p_Model.AddSpecificPoint(type, iter); } } } else { string fileName = p_Model.ModelFileFolder + name + m_sFilePostFix + ".ptsID"; Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); using (StreamReader FileStream = File.OpenText(fileName)) { string line = ""; int count = 0; uint NoOfPoints = 0; bool ReadHeader = false; while ((line = FileStream.ReadLine()) != null) { if (!ReadHeader) { NoOfPoints = UInt32.Parse(line); if (NoOfPoints != 3) throw new Exception("Method ready to read 3 points"); ReadHeader = true; } else { uint id = UInt32.Parse(line); iter.MoveToPoint(id); if (count == 0) p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip, iter); if (count == 1) p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner, iter); if (count == 2) p_Model.AddSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner, iter); count++; } } } } }
void SaveModel(Cl3DModel p_Model) { string name = p_Model.ModelFileFolder + paramFileName+".tmp"; Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); using (TextWriter tw = new StreamWriter(name, false)) { 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) + " " + iter.PointID.ToString(System.Globalization.CultureInfo.InvariantCulture); tw.WriteLine(line); MapVertexNo.Add(iter.PointID, vertexNO++); } 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) { SaveModel(p_Model); string ParameterString = "\"" + p_Model.ModelFileFolder+paramFileName + ".tmp\" " + "0"; if(m_bAreaWeight) { ParameterString = "\"" + p_Model.ModelFileFolder + paramFileName + ".tmp\" " + "1"; } ProcessStartInfo proces = new ProcessStartInfo(m_sRunApplication, ParameterString); proces.WindowStyle = ProcessWindowStyle.Minimized; Process ConformalProcess = System.Diagnostics.Process.Start(proces); ConformalProcess.WaitForExit(); string FileName = p_Model.ModelFileFolder + paramFileName + "_AreaWeight.UV"; if(m_bAreaWeight) { FileName = p_Model.ModelFileFolder + paramFileName + "_NoAreaWeight.UV"; } if (!File.Exists(FileName)) { throw new Exception("Something goes wrong with calculation of UV parametrization for the file:" + p_Model.ModelFileName); } using (StreamReader FileStream = File.OpenText(FileName)) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); string line = ""; while ((line = FileStream.ReadLine()) != null) { if (line.Length == 0) continue; // UV verID=41496 U=0.0854425 V=0.224188 char[] delimiters = new char[] { ' ', '=' }; string[] parts = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); uint ID = UInt32.Parse(parts[2], System.Globalization.CultureInfo.InvariantCulture); float U = Single.Parse(parts[4], System.Globalization.CultureInfo.InvariantCulture); float V = Single.Parse(parts[6], System.Globalization.CultureInfo.InvariantCulture); if (!iter.MoveToPoint(ID)) throw new Exception("Cannot move iterator to the position: " + ID.ToString()); iter.U = U; iter.V = V; } FileStream.Close(); } File.Delete(FileName); File.Delete(p_Model.ModelFileFolder + paramFileName + ".tmp"); }
protected override void Algorithm(ref Cl3DModel p_Model) { Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); Cl3DModel.Cl3DModelPointIterator max = iter.CopyIterator(); float distanceMax = 0; do { float distance = (float)Math.Sqrt(Math.Pow(iter.U, 2) + Math.Pow(iter.V, 2)); if (distanceMax < distance) distanceMax = distance; } while (iter.MoveToNext()); iter = p_Model.GetIterator(); do { iter.U = (iter.U / distanceMax) * m_RadiousOfConformalMap; iter.V = (iter.V / distanceMax) * m_RadiousOfConformalMap; } while (iter.MoveToNext()); Cl3DModel.Cl3DModelPointIterator LeftEye = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner); Cl3DModel.Cl3DModelPointIterator RightEye = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner); Cl3DModel.Cl3DModelPointIterator NoseTip = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip); Cl3DModel.Cl3DModelPointIterator tmp; if (LeftEye.X > RightEye.X) { tmp = LeftEye.CopyIterator(); RightEye = LeftEye.CopyIterator(); LeftEye = tmp.CopyIterator(); } double EyesDistance = Math.Sqrt(Math.Pow(LeftEye.U - RightEye.U,2) + Math.Pow(LeftEye.V - RightEye.V,2)); double NoseLeftEyeDistance = Math.Sqrt(Math.Pow(LeftEye.U - NoseTip.U, 2) + Math.Pow(LeftEye.V - NoseTip.V, 2)); double NoseRightEyeDistance = Math.Sqrt(Math.Pow(NoseTip.U - RightEye.U, 2) + Math.Pow(NoseTip.V - RightEye.V, 2)); double AverageNoseTipEyeDistance = (NoseLeftEyeDistance + NoseRightEyeDistance) / 2; Matrix GenModel = new Matrix(2, 3); GenModel[0, 0] = 0; GenModel[1, 0] = 0; // nose GenModel[0, 1] = (EyesDistance / 2); GenModel[1, 1] = AverageNoseTipEyeDistance; // left eye GenModel[0, 2] = -(EyesDistance / 2); GenModel[1, 2] = AverageNoseTipEyeDistance; // right eye Matrix Model = new Matrix(2, 3); Model[0, 0] = NoseTip.U; Model[1, 0] = NoseTip.V; // nose Model[0, 1] = LeftEye.U; Model[1, 1] = LeftEye.V; // left eye Model[0, 2] = RightEye.U; Model[1, 2] = RightEye.V; // right eye Matrix rotationMatrix = null; Matrix translationMatrix = null; ClTools.CalculateRotationAndTranslation(GenModel, Model, out rotationMatrix, out translationMatrix); Iridium.Numerics.LinearAlgebra.Matrix q = new Iridium.Numerics.LinearAlgebra.Matrix(2, 1); iter = p_Model.GetIterator(); do { q[0, 0] = iter.U; q[1, 0] = iter.V; Iridium.Numerics.LinearAlgebra.Matrix NewQ = rotationMatrix * q +translationMatrix; iter.U = (float)NewQ[0, 0]; iter.V = (float)NewQ[1, 0]; } while (iter.MoveToNext()); float U = NoseTip.U; float V = NoseTip.V; iter = p_Model.GetIterator(); do { iter.U -= U; iter.V -= V; } while (iter.MoveToNext()); if (centerConformalMaps) { float middleU = 0; float middleV = 0; iter = p_Model.GetIterator(); do { middleU += iter.U; middleV += iter.V; } while (iter.MoveToNext()); middleU /= p_Model.ModelPointsCount; middleV /= p_Model.ModelPointsCount; iter = p_Model.GetIterator(); do { iter.U -= middleU; iter.V -= middleV; } while (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) { Cl3DModel.Cl3DModelPointIterator NoseTip = null; if (!p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip.ToString(), ref NoseTip)) throw new Exception("Cannot get Nose Tip"); List<Cl3DModel.Cl3DModelPointIterator> Neighborhood = null; ClTools.GetNeighborhoodWithGeodesicDistance(out Neighborhood, NoseTip, m_NeighborhoodSize); foreach (Cl3DModel.Cl3DModelPointIterator point in Neighborhood) point.Color = Color.Red; }
private static void RunAlgorithmsForFolder() { if (m_bIsRunning) return; m_bIsRunning = true; ClFileLogger FileLogger = new ClFileLogger(m_sTestDirectory + "log.txt", false); if (m_bLogging) { ClInformationSender.RegisterReceiver(FileLogger, ClInformationSender.eInformationType.eDebugText); ClInformationSender.RegisterReceiver(FileLogger, ClInformationSender.eInformationType.eTextExternal); ClInformationSender.RegisterReceiver(FileLogger, ClInformationSender.eInformationType.eTextInternal); ClInformationSender.RegisterReceiver(FileLogger, ClInformationSender.eInformationType.eError); } try { ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStartProcessing); int current = 1; int howMany = m_lFilesList.Count; ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStartProcessing); string fullAlgorithmAdditionalData = ""; foreach (IFaceAlgorithm alg in m_lAlgorithmsList) { fullAlgorithmAdditionalData += "\n- " + alg.GetAlgorithmFullPath(); fullAlgorithmAdditionalData += "\n"; foreach (KeyValuePair<string, string> prop in alg.GetProperitis()) fullAlgorithmAdditionalData += "\t" + prop.Key + " -> " + prop.Value + "\n"; } fullAlgorithmAdditionalData += "\n------------------------------"; ClInformationSender.SendInformation(fullAlgorithmAdditionalData, ClInformationSender.eInformationType.eDebugText); TimeSpan mean = TimeSpan.Zero; foreach (String file in m_lFilesList) { DateTime start = DateTime.Now; ClInformationSender.SendInformation(((current * 100) / howMany).ToString(), ClInformationSender.eInformationType.eProgress); try { Cl3DModel newModel = new Cl3DModel(); newModel.LoadModel(file); foreach (IFaceAlgorithm alg in m_lAlgorithmsList) { alg.MakeAlgorithm(ref newModel); } } catch (ThreadAbortException) { ClInformationSender.SendInformation("Processing Interrupted", ClInformationSender.eInformationType.eTextInternal); break; } catch (Exception ex) { ClInformationSender.SendInformation("ERROR:\n(" + file + ")\n" + ex.ToString(), ClInformationSender.eInformationType.eDebugText); } DateTime stop = DateTime.Now; mean += (stop - start); double MeanTotalHours = mean.TotalHours; double MeanTotalMin = mean.TotalMinutes; int TotalTimeHours = (int)((MeanTotalHours / current) * (howMany - current)); int TotalTimeMin = (int)((MeanTotalMin / current) * (howMany - current)); TotalTimeMin = TotalTimeMin - (TotalTimeHours * 60); ClInformationSender.SendInformation("Time Remaining: " + TotalTimeHours.ToString() + "h" + TotalTimeMin.ToString("00")+"min [" + current.ToString() + "/" + howMany.ToString()+"]", ClInformationSender.eInformationType.eTextExternal); current++; } } catch (Exception e) { ClInformationSender.SendInformation("ERROR:\n" + e.ToString(), ClInformationSender.eInformationType.eError); } m_bIsRunning = false; ClInformationSender.SendInformation(null, ClInformationSender.eInformationType.eStopProcessing); ClInformationSender.UnRegisterReceiver(FileLogger, ClInformationSender.eInformationType.eDebugText); ClInformationSender.UnRegisterReceiver(FileLogger, ClInformationSender.eInformationType.eTextExternal); ClInformationSender.UnRegisterReceiver(FileLogger, ClInformationSender.eInformationType.eTextInternal); ClInformationSender.UnRegisterReceiver(FileLogger, ClInformationSender.eInformationType.eError); }
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()); } }
public static void RunAlgorithms(Cl3DModel p_mModel3D, List<IFaceAlgorithm> p_lListOfAlgorithms) { if (m_bIsRunning) throw new Exception("The previous processing is still running ..."); m_lAlgorithmsList = p_lListOfAlgorithms; if (p_mModel3D != null && p_lListOfAlgorithms != null) { m_sProcessedModel = p_mModel3D; m_sProcessingThread = new Thread(RunAlgorithmsForModel); m_sProcessingThread.Priority = ThreadPriority.Highest; m_sProcessingThread.Start(); } }