public static string GenerateMakeCommands(CoG cog, string specName, SpecVars SV, string target) { StringBuilder SB = new StringBuilder(); SB.AppendLine(""); SB.AppendLine("cd " + specName); if (IsUnix()) { SB.AppendLine("make" + target); SB.AppendLine("if [ $? -eq 0 ]; "); SB.AppendLine("then"); SB.AppendLine("echo \"build ok\""); SB.AppendLine("else"); SB.AppendLine("\texit $?"); SB.AppendLine("fi"); } else { SB.AppendLine("nmake" + target); SB.AppendLine("if not %errorlevel%==0 goto :error"); } SB.AppendLine("cd .."); return(SB.ToString()); }
static void Main(string[] args) { try { System.Collections.Hashtable HT = new System.Collections.Hashtable(); HT["Canon Eos 5D Mark II body"] = 2176; HT["Nikon D700 body"] = 1997; HT["Sony DSLR-A900 body"] = 2345; System.Console.WriteLine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); CoG C = new CoG(); C.LoadTemplates( System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\..\\..\\..\\src\\sample_template.txt"); C.EmitTemplate("sample_template", "HT=", HT); C.EmitTemplate("sample_template", "HT=", HT); System.Console.Write(C.GetOutputAndClear()); } catch (Exception E) { System.Console.WriteLine("Exception: " + E.ToString()); } return; }
/// <summary> /// Generates variations of Gaigen 2.5 specifications and Makefiles for the ENGA template. /// <param name="cog">Used for code generation.</param> /// <param name="commands">Used to return the commands to build and run each algebra/test.</param> /// </summary> public static void GenerateENgaVariations(CoG cog, Dictionary <string, List <string> > commands) { int minDim = 1, maxDim = 7; bool groupAlternative = false; string altGmvName = "multivector"; string altScalarName = "scalarClass"; bool varyGmvCode = false; bool varyInline = true; // attempt to be able to compile _huge_ code bool varyCoordStorage = true; List <SpecVars> lowDvars = GetVariations(minDim, maxDim, groupAlternative, altGmvName, altScalarName, varyGmvCode, varyInline, varyCoordStorage); minDim = 8; maxDim = 11; varyInline = false; varyCoordStorage = false; List <SpecVars> highDvars = GetVariations(minDim, maxDim, groupAlternative, altGmvName, altScalarName, varyGmvCode, varyInline, varyCoordStorage); // force runtime code, array storage for all high-D for (int i = 0; i < highDvars.Count; i++) { highDvars[i].GmvCode = G25.GMV_CODE.RUNTIME; highDvars[i].CoordStorage = G25.COORD_STORAGE.VARIABLES; } List <SpecVars> vars = new List <SpecVars>(lowDvars); vars.AddRange(highDvars); vars = Reduce(vars); foreach (SpecVars V in vars) { GenerateFromVar(cog, commands, "eNga_spec", GetMakefileTemplateName(V.OutputLanguage), "e" + V.Dimension + "ga", V); } }
public static void GenerateC3gaVariations(CoG cog, Dictionary <string, List <string> > commands, List <SpecVars> vars) { foreach (SpecVars V in vars) { V.Dimension = 5; GenerateFromVar(cog, commands, "c3ga_spec", GetMakefileTemplateName(V.OutputLanguage), "c3ga", V); } }
public static void GenerateSpecFromVar(CoG cog, string templateName, string specName, string specFilename, SpecVars SV) { // write template to StringBuilder StringBuilder SB = new StringBuilder(); cog.EmitTemplate(SB, templateName, "SV=", SV); // write template to file G25.CG.Shared.Util.WriteFile(specFilename, SB.ToString()); }
public static CoG InitCoG() { CoG cog = new CoG(); cog.AddReference((new SpecVars()).GetType().Assembly.Location); // add reference to this assembly cog.AddReference((new G25.CG.Shared.Util()).GetType().Assembly.Location); // add reference for g25_cg_shared cog.AddReference((new G25.Tuple <string, string>()).GetType().Assembly.Location); // add reference for libg25 cog.LoadTemplates(Properties.Resources.test_suite_templates, "test_suite_templates.txt"); return(cog); }
public static string GenerateDoxygenCommands(CoG cog, string specName, SpecVars SV) { StringBuilder SB = new StringBuilder(); SB.AppendLine(""); SB.AppendLine("cd " + specName); SB.AppendLine("echo \"Running doxygen for " + specName + " \""); SB.AppendLine("doxygen"); SB.AppendLine("cd .."); return(SB.ToString()); }
public static string GenerateFromVar(CoG cog, Dictionary <string, List <string> > commands, string specTemplateName, string makefileTemplateName, string specBaseName, SpecVars SV) { GeneratorCount++; // get name of specification string specName = specBaseName + "_" + SV.GetShortName(); // get full directory name, create directory string dirName = System.IO.Path.Combine(OutputDirectory, specName); try { System.IO.Directory.CreateDirectory(dirName); } catch (Exception) { Console.WriteLine("Warning: this directory is not clean: " + dirName); } // get filename of spec, write it string specFilename = System.IO.Path.Combine(dirName, specName + ".xml"); GenerateSpecFromVar(cog, specTemplateName, specName, specFilename, SV); // get filename of makefile, write it string makefileFilename = System.IO.Path.Combine(dirName, "Makefile"); GenerateMakefileFromVar(cog, makefileTemplateName, specName, makefileFilename, specBaseName, SV); // if myDouble is used, generate it if (SV.FloatTypes.Contains("myDouble")) { string myDoubleFilename = System.IO.Path.Combine(dirName, "my_double.h"); GenerateMyDoubleFromVar(cog, myDoubleFilename, SV); } commands[BUILD_CMD].Add(GenerateMakeCommands(cog, specName, SV, "")); commands[TEST_CMD].Add(GenerateRunCommands(cog, specName, SV)); commands[CLEAN_CMD].Add(GenerateMakeCommands(cog, specName, SV, " clean")); commands[XML_TEST_CMD].Add(GenerateXmlTestCommands(cog, specName, SV)); commands[DOXYGEN_CMD].Add(GenerateDoxygenCommands(cog, specName, SV)); return(specName); }
/// <summary> /// Generates variations of Gaigen 2.5 specifications and Makefiles for the P3GA template. /// <param name="cog">Used for code generation.</param> /// <param name="commands">Used to return the commands to build and run each algebra/test.</param> /// </summary> public static void GenerateP3gaVariations(CoG cog, Dictionary <string, List <string> > commands) { int minDim = 4, maxDim = 4; bool groupAlternative = true; string altGmvName = "multivector"; string altScalarName = "scalarClass"; bool varyGmvCode = true; bool varyInline = true; bool varyCoordStorage = true; List <SpecVars> vars = GetVariations(minDim, maxDim, groupAlternative, altGmvName, altScalarName, varyGmvCode, varyInline, varyCoordStorage); vars = Reduce(vars); GenerateP3gaVariations(cog, commands, vars); }
public static void GenerateMakefileFromVar(CoG cog, string templateName, string specName, string makefileFilename, string algebraName, SpecVars SV) { // write template to StringBuilder StringBuilder SB = new StringBuilder(); cog.EmitTemplate(SB, templateName, "SV=", SV, "SPEC_NAME=", specName, "ALGEBRA_NAME=", algebraName, "WINDOWS=", IsWindows(), "MACOSX=", GetPlatformID() == PlatformID.MacOSX, "LINUX=", GetPlatformID() == PlatformID.Unix ); // write template to file G25.CG.Shared.Util.WriteFile(makefileFilename, SB.ToString()); }
public static void GenerateMyDoubleFromVar(CoG cog, string filename, SpecVars SV) { // get name of template string templateName = "not_set"; if (SV.OutputLanguage == "cpp") { templateName = "myDouble_cpp_header"; } // write template to StringBuilder StringBuilder SB = new StringBuilder(); cog.EmitTemplate(SB, templateName); // write template to file G25.CG.Shared.Util.WriteFile(filename, SB.ToString()); }
/// <summary> /// Generates variations of Gaigen 2.5 specifications and Makefiles for the E3GA template. /// <param name="cog">Used for code generation.</param> /// <param name="commands">Used to return the commands to build and run each algebra/test.</param> /// </summary> public static void GenerateC3gaVariations(CoG cog, Dictionary <string, List <string> > commands) { int minDim = 5, maxDim = 5; bool groupAlternative = true; string altGmvName = "multivector"; string altScalarName = "scalarClass"; bool varyGmvCode = false; // cannot varywhen metric is not diagonal bool varyInline = false; // attempt to be able to compile _huge_ code bool varyCoordStorage = true; List <SpecVars> vars = GetVariations(minDim, maxDim, groupAlternative, altGmvName, altScalarName, varyGmvCode, varyInline, varyCoordStorage); vars = Reduce(vars); foreach (SpecVars V in vars) { V.Dimension = 5; GenerateFromVar(cog, commands, "c3ga_spec", GetMakefileTemplateName(V.OutputLanguage), "c3ga", V); } }
public static void GenerateSampleAlgebras(CoG cog, Dictionary <string, List <string> > commands) { Console.WriteLine("Generating the sample algebras"); ReduceNbTestsBy = 1; Shuffle = false; SpecVars SV = new SpecVars(); SV.HaveGom = true; SV.Inline = true; SV.ShortNameLangOnly = true; List <SpecVars> vars = SV.VaryOutputLanguage(Languages); GenerateE2gaVariations(cog, commands, vars); GenerateE3gaVariations(cog, commands, vars); GenerateP3gaVariations(cog, commands, vars); GenerateC3gaVariations(cog, commands, vars); }
public static string GenerateXmlTestCommands(CoG cog, string specName, SpecVars SV) { StringBuilder SB = new StringBuilder(); string xmlTestdirName = XML_TEST_CMD; string fileListName = "g25_file_list.txt"; SB.AppendLine(""); SB.AppendLine("cd " + specName); SB.AppendLine("g25 -d true -f " + fileListName + " " + specName + ".xml"); SB.AppendLine("mkdir " + xmlTestdirName); SB.AppendLine("g25 -d true -s " + xmlTestdirName + System.IO.Path.DirectorySeparatorChar + specName + ".xml " + specName + ".xml"); SB.AppendLine("cd " + xmlTestdirName); SB.AppendLine("g25 -d true -f " + fileListName + " " + specName + ".xml"); SB.AppendLine("g25_diff " + fileListName + " .." + System.IO.Path.DirectorySeparatorChar + fileListName); if (IsWindows()) { SB.AppendLine("if not %errorlevel%==0 goto :error"); } else { SB.AppendLine("if [ $? -eq 0 ]; "); SB.AppendLine("then"); SB.AppendLine("echo \"XML test ok\""); SB.AppendLine("else"); SB.AppendLine("\texit $?"); SB.AppendLine("fi"); } SB.AppendLine("cd .."); // leave xmlTestdirName SB.AppendLine("cd .."); // leave algebra dir return(SB.ToString()); }
public static string GenerateRunCommands(CoG cog, string specName, SpecVars SV) { StringBuilder SB = new StringBuilder(); SB.AppendLine(""); SB.AppendLine("cd " + specName); SB.AppendLine("echo \"Testing " + specName + " \""); if (IsUnix()) { if (SV.OutputLanguage == G25.XML.XML_JAVA) { SB.AppendLine("sh ./test.sh"); } else if (SV.OutputLanguage == G25.XML.XML_CSHARP) { SB.AppendLine("mono ./test.exe"); } else { SB.AppendLine("./test"); } } else { if (SV.OutputLanguage == G25.XML.XML_JAVA) { SB.AppendLine("call test.bat"); } else { SB.AppendLine("test.exe"); } } SB.AppendLine("cd .."); return(SB.ToString()); }
public static void GenerateVariations(CoG cog, Dictionary <string, List <string> > commands) { if (Algebras.Contains("e2ga")) { GenerateE2gaVariations(cog, commands); } if (Algebras.Contains("e3ga")) { GenerateE3gaVariations(cog, commands); } if (Algebras.Contains("p3ga")) { GenerateP3gaVariations(cog, commands); } if (Algebras.Contains("c3ga")) { GenerateC3gaVariations(cog, commands); } if (Algebras.Contains("enga")) { GenerateENgaVariations(cog, commands); } // todo? if (Algebras.Contains("cnga")) GenerateNdConformalVariations(cog, commands); }
/// <summary> /// Show CoP collected information. /// Called from UserControl load event. /// </summary> public void ShowCharts() { TotalPathLength = 0; PeakVelocity = float.MinValue; double xAnt = _listCoP[0].CX; double yAnt = _listCoP[0].CY; double timeAnt = _listCoP[0].elapsedTime; double initialTime = timeAnt; double distance = 0; double vel = 0; CoP.Clear(); CoP_X.Clear(); CoP_Y.Clear(); MeanCoPX = 0; MeanCoPY = 0; RMSCoP_X = 0; RMSCoP_Y = 0; // Find mean and RMS foreach (DataLog data in _listCoP) { MeanCoPX += data.CX; MeanCoPY += data.CY; RMSCoP_X += (data.CX * data.CX); RMSCoP_Y += (data.CY * data.CY); } MeanCoPX = MeanCoPX / _listCoP.Count; MeanCoPY = MeanCoPY / _listCoP.Count; // Now we can find standard deviation of the serie. RMSCoP_X = Math.Sqrt(RMSCoP_X / _listCoP.Count); RMSCoP_Y = Math.Sqrt(RMSCoP_Y / _listCoP.Count); StdDevCoPX = 0; StdDevCoPY = 0; foreach (DataLog data in _listCoP) { StdDevCoPX += Math.Pow(data.CX - MeanCoPX, 2); StdDevCoPY += Math.Pow(data.CY - MeanCoPY, 2); } StdDevCoPX = Math.Sqrt(StdDevCoPX / (_listCoP.Count - 1)); StdDevCoPY = Math.Sqrt(StdDevCoPY / (_listCoP.Count - 1)); double x, y; foreach (DataLog data in _listCoP) { x = data.CX; y = data.CY; while ((x > (MeanCoPX + (StdDevCoPX * 5))) || (x < (MeanCoPX - (StdDevCoPX * 5)))) { x = (x + MeanCoPX) / 2; } data.CX = (float)x; while ((y > (MeanCoPY + (StdDevCoPY * 5))) || (y < (MeanCoPY - (StdDevCoPY * 5)))) { y = (y + MeanCoPY) / 2; } data.CY = (float)y; if (data.CX < MinCoP_X) { MinCoP_X = data.CX; } if (data.CX > MaxCoP_X) { MaxCoP_X = data.CX; } if (data.CY < MinCoP_Y) { MinCoP_Y = data.CY; } if (data.CY > MaxCoP_Y) { MaxCoP_Y = data.CY; } // Calculate total path length (frame by frame vector position) in (mm) distance = Math.Sqrt(Math.Pow((double)data.CX - xAnt, 2) + Math.Pow((double)data.CY - yAnt, 2)); TotalPathLength += distance; // Calculate instante velocity and check peak velocity. vel = (distance / 1000) / ((data.elapsedTime - timeAnt) / 1000); if (vel > PeakVelocity && !double.IsInfinity(vel)) { PeakVelocity = vel; } xAnt = (double)data.CX; yAnt = (double)data.CY; timeAnt = data.elapsedTime; CoP.Add(new ScatterPoint(data.CX - MeanCoPX, data.CY - MeanCoPY, 0.1)); CoP_X.Add(new ObservablePoint(data.elapsedTime, data.CX - MeanCoPX)); CoP_Y.Add(new ObservablePoint(data.elapsedTime, data.CY - MeanCoPY)); } // Path Length is in centimeters and Time is in milliseconds. Velocity in m/s AvgVelocity = (TotalPathLength / 1000) / ((timeAnt - initialTime) / 1000); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Deals with Center of Mass data. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TotalPathLengthCoG = 0; PeakVelocityCoG = 0; xAnt = _listCoM[0].CX; double zAnt = _listCoM[0].CZ; initialTime = _listCoM[0].elapsedTime; timeAnt = initialTime; CoG.Clear(); CoG_X.Clear(); CoG_Z.Clear(); double meanCoGX = 0; double meanCoGZ = 0; RMSCoM_X = 0; RMSCoM_Z = 0; // finds Min and Max values of Center of Mass. foreach (DataLog data in _listCoM) { if (data.CX < MinCoG_X) { MinCoG_X = data.CX; } if (data.CX > MaxCoG_X) { MaxCoG_X = data.CX; } if (data.CZ < MinCoG_Z) { MinCoG_Z = data.CZ; } if (data.CZ > MaxCoG_Z) { MaxCoG_Z = data.CZ; } meanCoGX += data.CX; meanCoGZ += data.CZ; RMSCoM_X = (data.CX * data.CX); RMSCoM_Z = (data.CZ * data.CZ); } MinCoG_X = MinCoG_X * 1000; MaxCoG_X = MaxCoG_X * 1000; MinCoG_Z = MinCoG_Z * 1000; MaxCoG_Z = MaxCoG_Z * 1000; meanCoGX = (meanCoGX / _listCoM.Count); meanCoGZ = (meanCoGZ / _listCoM.Count); RMSCoM_X = Math.Sqrt(RMSCoM_X / _listCoM.Count); RMSCoM_Z = Math.Sqrt(RMSCoM_Z / _listCoM.Count); foreach (DataLog data in _listCoM) { // Calculate total path length (frame by frame vector position) in (mm) distance = Math.Sqrt(Math.Pow((double)data.CX - xAnt, 2) + Math.Pow((double)(data.CZ - zAnt), 2)); TotalPathLengthCoG += distance; // Calculate instante velocity and check peak velocity. vel = distance / ((data.elapsedTime - timeAnt) / 1000); if (vel > PeakVelocityCoG) { PeakVelocityCoG = vel; } xAnt = (double)data.CX; zAnt = (double)data.CZ; timeAnt = data.elapsedTime; // Kinect provides spatial data in meters, converting to mm CoG.Add(new ObservablePoint((data.CX - meanCoGX) * 1000, (data.CZ - meanCoGZ) * 1000)); CoG_X.Add(new ObservablePoint(data.elapsedTime, (data.CX - meanCoGX) * 1000)); CoG_Z.Add(new ObservablePoint(data.elapsedTime, (data.CZ - meanCoGZ) * 1000)); } // Kinect provides position data in meters. AvgVelocityCoG = TotalPathLengthCoG / ((timeAnt - initialTime) / 1000); TotalPathLengthCoG = TotalPathLengthCoG * 1000; // transform it to mm. meanCoGX = meanCoGX * 1000; meanCoGZ = meanCoGZ * 1000; RMSCoM_X = RMSCoM_X * 1000; RMSCoM_Z = RMSCoM_Z * 1000; AmplitudeCoP_X = Math.Abs(MaxCoP_X - MinCoP_X); AmplitudeCoP_Y = Math.Abs(MaxCoP_Y - MinCoP_Y); AmplitudeCoG_X = Math.Abs(MaxCoG_X - MinCoG_X); AmplitudeCoG_Z = Math.Abs(MaxCoG_Z - MinCoG_Z); }
public static void WriteTopLevelScripts(CoG cog, Dictionary <string, List <string> > commands) { { // build and test List <string> interleavedCommands = InterleaveCommandList(commands[BUILD_CMD], commands[TEST_CMD]); StringBuilder SB = new StringBuilder(); WriteBuildScript(SB, interleavedCommands); string compileScriptFlename = System.IO.Path.Combine(OutputDirectory, "build_and_test." + GetScriptExtension()); G25.CG.Shared.Util.WriteFile(compileScriptFlename, SB.ToString()); } { // build StringBuilder SB = new StringBuilder(); WriteBuildScript(SB, commands[BUILD_CMD]); string compileScriptFlename = System.IO.Path.Combine(OutputDirectory, "build." + GetScriptExtension()); G25.CG.Shared.Util.WriteFile(compileScriptFlename, SB.ToString()); } { // clean StringBuilder SB = new StringBuilder(); if (IsUnix()) { SB.Append("#!/bin/sh\n\n"); } AppendCommands(SB, commands[CLEAN_CMD]); string runScriptFlename = System.IO.Path.Combine(OutputDirectory, "clean." + GetScriptExtension()); G25.CG.Shared.Util.WriteFile(runScriptFlename, SB.ToString()); } { // test StringBuilder SB = new StringBuilder(); if (IsUnix()) { SB.Append("#!/bin/sh\n\n"); } AppendCommands(SB, commands[TEST_CMD]); string runScriptFlename = System.IO.Path.Combine(OutputDirectory, "test." + GetScriptExtension()); G25.CG.Shared.Util.WriteFile(runScriptFlename, SB.ToString()); } { // XML test StringBuilder SB = new StringBuilder(); if (IsUnix()) { SB.Append("#!/bin/sh\n\n"); } WriteXmlTestScript(SB, commands[XML_TEST_CMD]); string runScriptFlename = System.IO.Path.Combine(OutputDirectory, "xml_test." + GetScriptExtension()); G25.CG.Shared.Util.WriteFile(runScriptFlename, SB.ToString()); } { // doxygen StringBuilder SB = new StringBuilder(); if (IsUnix()) { SB.Append("#!/bin/sh\n\n"); } AppendCommands(SB, commands[DOXYGEN_CMD]); //WriteDoxygenScript(SB, commands[]); string runScriptFlename = System.IO.Path.Combine(OutputDirectory, "doxygen." + GetScriptExtension()); G25.CG.Shared.Util.WriteFile(runScriptFlename, SB.ToString()); } }
static void Main(string[] args) { // parse command line List <string> extraArgs = ParseCommandLineOptions(args); if (extraArgs.Count > 0) { Console.WriteLine("Stray arguments detected: " + extraArgs); } // display help if required if (OptionDisplayHelp) { DisplayHelp(); } // set the defaults if the user did not ask for any algebra if (Algebras.Count == 0) { Algebras = new List <string> { "e2ga", "e3ga", "p3ga", "c3ga", "enga" } } ; CoG cog = InitCoG(); try { InitOutputDirectory(OutputDirectory); } catch (Exception ex) { Console.WriteLine("Error initializing the output directory (" + OutputDirectory + "):"); Console.WriteLine(ex.Message); Environment.Exit(-1); } // init command list Dictionary <string, List <string> > commands = new Dictionary <string, List <string> >(); commands[BUILD_CMD] = new List <string>(); commands[CLEAN_CMD] = new List <string>(); commands[TEST_CMD] = new List <string>(); commands[XML_TEST_CMD] = new List <string>(); commands[DOXYGEN_CMD] = new List <string>(); // generate the specifications, collect commands try { if (SampleAlgebras) { GenerateSampleAlgebras(cog, commands); } else { GenerateVariations(cog, commands); } } catch (Exception ex) { Console.WriteLine("Error generating algebra specifications:"); Console.WriteLine(ex.Message); Console.WriteLine("Source: " + ex.Source); Environment.Exit(-1); } // write scripts from commands WriteTopLevelScripts(cog, commands); Console.WriteLine(""); Console.WriteLine("Generated " + GeneratorCount + " test algebras."); }