protected override void Algorithm(ref Cl3DModel p_Model) { try { if (!File.Exists(m_sPath)) throw new Exception("External file does not exist, the path is incorrect: " + m_sPath); ClSaveToMFileNew algSave = new ClSaveToMFileNew(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2"); algSave.MakeAlgorithm(p_Model); Process proc = new Process(); proc.StartInfo.FileName = m_sPath; proc.StartInfo.Arguments = "-harmonic_map \"" + p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2\" \"" + p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m\""; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.Start(); if (!proc.WaitForExit(10000)) { proc.Kill(); File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2"); } ClInformationSender.SendInformation("Parametrization calculated", ClInformationSender.eInformationType.eDebugText); Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); using (StreamReader FileStream = File.OpenText(p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m")) { string line = ""; while ((line = FileStream.ReadLine()) != null) { if (!line.Contains("Vertex")) continue; int index = line.LastIndexOf("uv=") + 3; string substring = line.Substring(index); string[] subsubs = substring.Substring(substring.IndexOf('(') + 1, substring.LastIndexOf(')') - substring.IndexOf('(') - 1).Split(' '); float U = float.Parse(subsubs[0], System.Globalization.CultureInfo.InvariantCulture); float V = float.Parse(subsubs[1], System.Globalization.CultureInfo.InvariantCulture); uint ID = uint.Parse(line.Split(' ')[1]); if (!iter.MoveToPoint(ID - 1)) throw new Exception("Cannot localize point with number: " + ID.ToString()); iter.U = U; iter.V = V; } } File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2"); if(removeOutput) File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m"); } catch (Exception) { File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2"); File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m"); throw; } }
protected override void Algorithm(ref Cl3DModel p_Model) { try { if (!File.Exists(m_sPath)) { throw new Exception("External file does not exist, the path is incorrect: " + m_sPath); } ClSaveToMFileNew algSave = new ClSaveToMFileNew(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2"); algSave.MakeAlgorithm(p_Model); Process proc = new Process(); proc.StartInfo.FileName = m_sPath; proc.StartInfo.Arguments = "-harmonic_map \"" + p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2\" \"" + p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m\""; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.Start(); if (!proc.WaitForExit(10000)) { proc.Kill(); File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2"); } ClInformationSender.SendInformation("Parametrization calculated", ClInformationSender.eInformationType.eDebugText); Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator(); using (StreamReader FileStream = File.OpenText(p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m")) { string line = ""; while ((line = FileStream.ReadLine()) != null) { if (!line.Contains("Vertex")) { continue; } int index = line.LastIndexOf("uv=") + 3; string substring = line.Substring(index); string[] subsubs = substring.Substring(substring.IndexOf('(') + 1, substring.LastIndexOf(')') - substring.IndexOf('(') - 1).Split(' '); float U = float.Parse(subsubs[0], System.Globalization.CultureInfo.InvariantCulture); float V = float.Parse(subsubs[1], System.Globalization.CultureInfo.InvariantCulture); uint ID = uint.Parse(line.Split(' ')[1]); if (!iter.MoveToPoint(ID - 1)) { throw new Exception("Cannot localize point with number: " + ID.ToString()); } iter.U = U; iter.V = V; } } File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2"); if (removeOutput) { File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m"); } } catch (Exception) { File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + ".m2"); File.Delete(p_Model.ModelFileFolder + p_Model.ModelFileName + "OUT.m"); throw; } }