private void btnBrowseFile_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "CSV File|*.csv"; openFileDialog1.Title = "Select the VL Results file"; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { using (GenericParserAdapter parser = new GenericParserAdapter(openFileDialog1.FileName)) { DataSet ds = new DataSet(); //Load the data ds = parser.GetDataSet(); dt = ds.Tables[0]; //Format the data foreach (DataColumn dc in dt.Columns) { dc.ColumnName = dt.Rows[0][dc].ToString(); } dt.Rows[0].Delete(); //Display the data dgvResults.DataSource = dt; } } }
// GET: Default public ActionResult Index() { using (GenericParserAdapter parser = new GenericParserAdapter(Server.MapPath("~/data.csv"))) { parser.FirstRowHasHeader = true; Models.ReportGrid grid = new Models.ReportGrid { Data = parser.GetDataSet().Tables[0], Columns = new List <Models.ReportGrid.Column> { new Models.ReportGrid.Column { DataTableName = "Location", FilterType = GridFilterType.Multi, UseFilterOptions = true, Filterable = true }, new Models.ReportGrid.Column { DataTableName = "Copay", FilterType = GridFilterType.Double, Filterable = true } } }; return(View(grid)); } }
public static DataTable GetCrewWorkPanels(string ctfLocation) { DataTable dtResult = new DataTable(); using (GenericParserAdapter parser = new GenericParserAdapter(ctfLocation)) { parser.FirstRowHasHeader = true; var dsResult = parser.GetDataSet(); dtResult = dsResult.Tables[0]; } return(dtResult); }
public static DataTable GetWorkPatterns() { DataTable dtResult = new DataTable(); using (GenericParserAdapter parser = new GenericParserAdapter("C:\\Users\\david.bracken\\OneDrive - TUI\\Documents\\Furlough\\CCMasterRoster.csv")) { parser.FirstRowHasHeader = true; var dsResult = parser.GetDataSet(); dtResult = dsResult.Tables[0]; } return(dtResult); }
private DataSet FlatFileToDataSet(string filePath) { _log.DebugFormat(@"FlatFileToDataSet"); DataSet result = new DataSet(); using (GenericParserAdapter parser = new GenericParserAdapter()) { parser.SetDataSource(filePath); parser.ColumnDelimiter = '\t'; parser.FirstRowHasHeader = true; parser.SkipEmptyRows = false; result = parser.GetDataSet(); } return(result); }
private static void PopulateProfile(Bin[, ,] dProfile, Matrix3D navigationMatrix) { DataTable dataFile = new DataTable(); try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(PATH_TO_BIN_PROFILE)) { System.Data.DataSet dsResult = parser.GetDataSet(); dataFile = dsResult.Tables[0]; } } catch { } for (int i = 1; i < dataFile.Rows.Count; i++) { //lab vale as got form profile index Point3D labBin = new Point3D(); labBin.X = Convert.ToDouble(dataFile.Rows[i][0].ToString()); labBin.Y = Convert.ToDouble(dataFile.Rows[i][1].ToString()); labBin.Z = Convert.ToDouble(dataFile.Rows[i][2].ToString()); //trasfered points Point3D labCoordinate = navigationMatrix.Transform(labBin); //gets the bin to fill up Bin actualBin = GetProfileBin(dProfile, labCoordinate); //bin RGB Value actualBin.binRGB.X = Convert.ToByte(dataFile.Rows[i][9].ToString()); actualBin.binRGB.Y = Convert.ToByte(dataFile.Rows[i][10].ToString()); actualBin.binRGB.Z = Convert.ToByte(dataFile.Rows[i][11].ToString()); //Measure Lab Values actualBin.measuredLAB.X = Convert.ToDouble(dataFile.Rows[i][3].ToString()); actualBin.measuredLAB.Y = Convert.ToDouble(dataFile.Rows[i][4].ToString()); actualBin.measuredLAB.Z = Convert.ToDouble(dataFile.Rows[i][5].ToString()); //measured XYZ Values actualBin.measuredXYZ.X = Convert.ToDouble(dataFile.Rows[i][6].ToString()); actualBin.measuredXYZ.Y = Convert.ToDouble(dataFile.Rows[i][7].ToString()); actualBin.measuredXYZ.Z = Convert.ToDouble(dataFile.Rows[i][8].ToString()); //is empty check actualBin.isEmpty = false; } }
private void Button_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { tbFileName.Text = ofd.FileName; using (GenericParserAdapter parser = new GenericParserAdapter(tbFileName.Text)) { parser.Load("prediction-format.xml"); System.Data.DataSet dsResult = parser.GetDataSet(); DisplayData = dsResult.Tables[0]; PopulateFromAndTo(); } } }
static public DataSet loadTxtToDataset(string path, string name) { // Setup the DataSet DataSet ds = new DataSet(); // Use Generic Txt Parser to load csv to dataset using (GenericParserAdapter parser = new GenericParserAdapter()) { parser.SetDataSource(path); parser.ColumnDelimiter = ','; parser.FirstRowHasHeader = true; parser.TextQualifier = '\"'; ds = parser.GetDataSet(); } ds.Tables[0].TableName = name; return(ds); }
private void LoadAlterationList() { LoadedFromIndex = 0; lstAlterations.Items.Clear(); lstAlterations.Items.Add("New..."); if (File.Exists(_filePath)) { DataSet AlterationFile = new DataSet(); using (GenericParserAdapter parser = new GenericParserAdapter(_filePath)) { parser.ColumnDelimiter = '\t'; parser.FirstRowHasHeader = false; AlterationFile = parser.GetDataSet(); } foreach (DataRow row in AlterationFile.Tables[0].Rows) { lstAlterations.Items.Add(new Alteration(row)); } } }
// Unused for Now, could be useful in teh future static public DataSet loadExcelData() { // Setup the DataSet DataSet ds = new DataSet(); // Use Generic Txt Parser to load source_sphere.csv to a dataset. using (GenericParserAdapter parser = new GenericParserAdapter()) { parser.SetDataSource(Path.Combine(root, @".\data\source_sphere.csv")); parser.ColumnDelimiter = ','; parser.FirstRowHasHeader = true; parser.TextQualifier = '\"'; ds = parser.GetDataSet(); } ds.Tables[0].TableName = "data"; return(ds); }
private void Preview() { GenericParserAdapter parser = null; try { using (parser = new GenericParserAdapter(Filename)) { parser.ColumnDelimiter = Delimiter.ToCharArray()[0]; parser.FirstRowHasHeader = IsFirstRowContainNames; parser.MaxRows = 50; parser.TextQualifier = '\"'; var ds = parser.GetDataSet(); previewGrid.AutoGenerateColumns = true; previewGrid.ItemsSource = ds.Tables[0].DefaultView; System.GC.SuppressFinalize(parser); } } finally { if (parser != null) { GC.SuppressFinalize(parser); } } }
private void AbrirArquivoLaguraFixa() { if (!string.IsNullOrEmpty(labelXMLConfigFile.Text) && labelXMLConfigFile.Text != "Nenhum arquivo selecionado" && !string.IsNullOrEmpty(labelFileName.Text) && labelFileName.Text != "Nenhum arquivo selecionado") { dataGridView1.DataSource = null; dataGridView1.Refresh(); using (GenericParserAdapter parser = new GenericParserAdapter(labelFileName.Text, GetEncodingFromCombo())) { parser.Load(labelXMLConfigFile.Text); dataSet1 = parser.GetDataSet(); VerifyGridNumRowAndSetLabelReg(dataSet1.Tables[0].Rows.Count); dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); dataGridView1.AutoGenerateColumns = true; dataGridView1.DataSource = dataSet1.Tables[0]; dataGridView1.Focus(); } } else { string message = ""; if (!string.IsNullOrEmpty(labelXMLConfigFile.Text) && labelXMLConfigFile.Text != "Nenhum arquivo selecionado") { message += "Selecione o arquivo modelo (XML)\n"; } if (!string.IsNullOrEmpty(labelFileName.Text) && labelFileName.Text != "Nenhum arquivo selecionado") { { message += "Selecione o arquivo texto\n"; } } MessageBox.Show(message); } }
public static TestingStructure[] CorrectColour(System.Drawing.Color rgb, double X, double Y, double Z) { //rgb = System.Drawing.Color.FromArgb(69, 77, 217); //X = 0.0630982813175294; //Y = 0.616476271122916; //Z = 0.667048468232457; //cuda intializer CudafyModule km = CudafyModule.TryDeserialize(); if (km == null || !km.TryVerifyChecksums()) { // km = CudafyTranslator.Cudafy((typeof(ForeGroundStrucuture)), (typeof(BackGroundStrucuture)), typeof(Color)); km = CudafyTranslator.Cudafy((typeof(ProfileStrucuture)), (typeof(ForeGroundStrucuture)), (typeof(BackGroundStrucuture)), (typeof(SampleStructure)), (typeof(TestingStructure)), typeof(quick_corr)); km.TrySerialize(); } CudafyTranslator.GenerateDebug = true; // cuda or emulator GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId); //GPGPU gpu = CudafyHost.GetDevice(eGPUType.Emulator); Console.WriteLine("Running decrease step correction using {0}", gpu.GetDeviceProperties(false).Name); gpu.LoadModule(km); TestingStructure[] distance_CPU = new TestingStructure[1]; // allocate memory on the GPU for the bitmap (same size as ptr) #region DataTable profile = new DataTable(); try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(@"C:\lev\STColorCorrection\Data\PROFILE\p3700.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch (Exception ex) { Console.WriteLine(ex); } #endregion // allocate temp memory, initialize it, copy to constant memory on the GPU // L 0-21 A 0-41 B 0-45 ProfileStrucuture[, ,] profiles_CPU = new ProfileStrucuture[21, 41, 45]; ForeGroundStrucuture[] foregorungRGB_CPU = new ForeGroundStrucuture[1]; BackGroundStrucuture[] BackgroundXYZ_CPU = new BackGroundStrucuture[1]; SampleStructure[,] samples_CPU = new SampleStructure[1, 6]; //profile inicialization #region for (int indexL = 0; indexL < 21; indexL++) { for (int indexA = 0; indexA < 41; indexA++) { for (int indexB = 0; indexB < 45; indexB++) { profiles_CPU[indexL, indexA, indexB].L = indexL; profiles_CPU[indexL, indexA, indexB].A = indexA; profiles_CPU[indexL, indexA, indexB].B = indexB; //profiles_CPU[indexL, indexA, indexB].Given_R = 0; //profiles_CPU[indexL, indexA, indexB].Given_G = 0; //profiles_CPU[indexL, indexA, indexB].Given_B = 0; profiles_CPU[indexL, indexA, indexB].ML = 0; profiles_CPU[indexL, indexA, indexB].MA = 0; profiles_CPU[indexL, indexA, indexB].MB = 0; profiles_CPU[indexL, indexA, indexB].MX = 0; profiles_CPU[indexL, indexA, indexB].MY = 0; profiles_CPU[indexL, indexA, indexB].MZ = 0; profiles_CPU[indexL, indexA, indexB].distance = -1.0; profiles_CPU[indexL, indexA, indexB].weight = -1.0; profiles_CPU[indexL, indexA, indexB].isempty = TRUE; profiles_CPU[indexL, indexA, indexB].isMoreAccurateThanOrigin = FALSE; } } } int lvalue, avalue, bvalue; try { for (int i = 1; i < profile.Rows.Count; i++) { lvalue = Convert.ToInt32(profile.Rows[i][0].ToString()); avalue = Convert.ToInt32(profile.Rows[i][1].ToString()); bvalue = Convert.ToInt32(profile.Rows[i][2].ToString()); lvalue = (int)(lvalue * 0.2); avalue = (int)(avalue * 0.2) + 20; bvalue = (int)(bvalue * 0.2) + 22; profiles_CPU[lvalue, avalue, bvalue].L = lvalue; profiles_CPU[lvalue, avalue, bvalue].A = avalue; profiles_CPU[lvalue, avalue, bvalue].B = bvalue; //profiles_CPU[lvalue, avalue, bvalue].Given_R = (double)Convert.ToByte(profile.Rows[i][9].ToString()); //profiles_CPU[lvalue, avalue, bvalue].Given_G = (double)Convert.ToByte(profile.Rows[i][10].ToString()); //profiles_CPU[lvalue, avalue, bvalue].Given_B = (double)Convert.ToByte(profile.Rows[i][11].ToString()); profiles_CPU[lvalue, avalue, bvalue].ML = (double)Convert.ToDouble(profile.Rows[i][3].ToString()); profiles_CPU[lvalue, avalue, bvalue].MA = (double)Convert.ToDouble(profile.Rows[i][4].ToString()); profiles_CPU[lvalue, avalue, bvalue].MB = (double)Convert.ToDouble(profile.Rows[i][5].ToString()); profiles_CPU[lvalue, avalue, bvalue].MX = (double)Convert.ToDouble(profile.Rows[i][6].ToString()); profiles_CPU[lvalue, avalue, bvalue].MY = (double)Convert.ToDouble(profile.Rows[i][7].ToString()); profiles_CPU[lvalue, avalue, bvalue].MZ = (double)Convert.ToDouble(profile.Rows[i][8].ToString()); profiles_CPU[lvalue, avalue, bvalue].isempty = FALSE; } } catch (Exception ex) { Console.WriteLine(ex); } #endregion //grab the colors ProfileStrucuture[, ,] profile_GPU = gpu.CopyToDevice(profiles_CPU); SampleStructure[,] samples_GPU = gpu.CopyToDevice(samples_CPU); Point3D background = new Point3D(X, Y, Z); //foreground and background image inicialization #region try { for (int i = 0; i < 1; i++) { foregorungRGB_CPU[i].R = rgb.R; foregorungRGB_CPU[i].G = rgb.G; foregorungRGB_CPU[i].B = rgb.B; BackgroundXYZ_CPU[i].X = background.X; BackgroundXYZ_CPU[i].Y = background.Y; BackgroundXYZ_CPU[i].Z = background.Z; } } catch (Exception ex) { Console.WriteLine(ex); } #endregion //begin execution // capture the start time gpu.StartTimer(); ForeGroundStrucuture[] foregorungRGB_GPU = gpu.CopyToDevice(foregorungRGB_CPU); BackGroundStrucuture[] BackgroundXYZ_GPU = gpu.CopyToDevice(BackgroundXYZ_CPU); //out put TestingStructure[] distance_GPU = gpu.Allocate(distance_CPU); // generate a bitmap from our sphere data //Image size: 1024 x 768 //dim3 grids = new dim3(1024 / 16, 768 / 16); //dim3 threads = new dim3(16, 16); dim3 grids = new dim3(1, 1); dim3 threads = new dim3(1, 1); //quick_correct //gpu.Launch(grids, threads, ((Action<GThread, ProfileStrucuture[, ,], ForeGroundStrucuture[], BackGroundStrucuture[], ProfileStrucuture[], SampleStructure[,]>)QuickCorr), profile_GPU, foregorungRGB_GPU, BackgroundXYZ_GPU, distance_GPU, samples_GPU); //quick correct - testing gpu.Launch(grids, threads, ((Action <GThread, ProfileStrucuture[, , ], ForeGroundStrucuture[], BackGroundStrucuture[], TestingStructure[], SampleStructure[, ]>)QuickCorr), profile_GPU, foregorungRGB_GPU, BackgroundXYZ_GPU, distance_GPU, samples_GPU); // copy our bitmap back from the GPU for display gpu.CopyFromDevice(distance_GPU, distance_CPU); // get stop time, and display the timing results double elapsedTime = gpu.StopTimer(); distance_CPU[0].execution_time = elapsedTime; Console.WriteLine("Time to generate: {0} ms", elapsedTime); gpu.Free(foregorungRGB_GPU); gpu.Free(BackgroundXYZ_GPU); gpu.Free(distance_GPU); gpu.FreeAll(); return(distance_CPU); }
static void Main(string[] args) { GenericParserAdapter gpa = new GenericParserAdapter("C:\\project\\DTG\\TMS Reviews\\TMW\\ClientsMissingGC.csv"); //GenericParser gp = new GenericParser("C:\\project\\DTG\\TMS Reviews\\TMW\\NewClients.csv"); gpa.FirstRowHasHeader = true; DataSet dsoriginal = new DataSet(); StreamReader sr; StreamWriter sw; string prefix = "UPDATE CLIENT SET POSLAT = '"; StringBuilder sb = new StringBuilder(); string strLAT = ""; string strLONG = ""; if (System.IO.File.Exists("C:\\project\\DTG\\TMS Reviews\\TMW\\ClientsGEOUpdateScript2.sql")) { sr = new StreamReader("C:\\project\\DTG\\TMS Reviews\\TMW\\ClientsGEOUpdateScript2.sql"); sb.Append(sr.ReadToEnd().ToString()); sr.Close(); } if (System.IO.File.Exists("C:\\project\\DTG\\TMS Reviews\\TMW\\WorkingClients2.xml")) { dsoriginal.ReadXml("C:\\project\\DTG\\TMS Reviews\\TMW\\WorkingClients2.xml"); } else { dsoriginal = gpa.GetDataSet(); dsoriginal.WriteXml("C:\\project\\DTG\\TMS Reviews\\TMW\\WorkingClients2.xml"); } //DataSet ds = new DataSet(); //ds.ReadXml("C:\\project\\DTG\\TMS Reviews\\TMW\\NewClientsShortLat2.xml"); DataRow[] arRows = dsoriginal.Tables[0].Select("POSLAT = '' OR POSLONG = ''"); GeocodingResponse geocode; GeocodingRequest geocodeRequest = new GeocodingRequest(); double degrees; double minutes; double seconds; string strDeg; string strMin; string strSec; double lat; double lng; var geocodingEngine = GoogleMaps.Geocode; foreach (DataRow dr in arRows) { /* * strLAT = dr["POSLAT"].ToString(); * strLONG = dr["POSLONG"].ToString(); * if (strLAT.Substring(0,1) == "N") * { * strLAT = strLAT.Substring(1, strLAT.Length - 1); * if (strLAT.LastIndexOf(".")) * } */ geocodeRequest.Address = dr["ADDRESS_1"] + ", " + dr["CITY"] + ", " + dr["PROVINCE"] + " " + dr["POSTAL_CODE"]; geocode = geocodingEngine.Query(geocodeRequest); if (geocode.Results.Count() > 0) { lat = geocode.Results.First().Geometry.Location.Latitude; degrees = Math.Floor(lat); strDeg = "00" + degrees.ToString(); minutes = Math.Floor((lat - degrees) * 60); strMin = "0" + minutes.ToString(); seconds = Math.Round((((lat - degrees) * 60) - minutes) * 60, 0); strSec = "0" + seconds.ToString(); //dr["POSLAT"] = "N" + strDeg.Substring(Math.Max(0, strDeg.Length - 2)) + strMin.Substring(Math.Max(0, strMin.Length - 2)) + strSec.Substring(Math.Max(0, strSec.Length - 2)); strLAT = strDeg.Substring(strDeg.Length - 3, 3) + strMin.Substring(Math.Max(0, strMin.Length - 2), 2) + strSec.Substring(Math.Max(0, strSec.Length - 2), 2) + "N"; dr["POSLAT"] = strLAT; lng = geocode.Results.First().Geometry.Location.Longitude; degrees = Math.Floor(Math.Abs(lng)); strDeg = "00" + degrees.ToString(); minutes = Math.Floor((Math.Abs(lng) - degrees) * 60); strMin = "0" + minutes.ToString(); seconds = Math.Round((((Math.Abs(lng) - degrees) * 60) - minutes) * 60, 0); strSec = "0" + seconds.ToString(); strLONG = strDeg.Substring(Math.Max(0, strDeg.Length - 3), 3) + strMin.Substring(Math.Max(0, strMin.Length - 2), 2) + strSec.Substring(Math.Max(0, strSec.Length - 2), 2) + "W"; dr["POSLONG"] = strLONG; sb.AppendLine(prefix + strLAT + "',POSLONG='" + strLONG + "' WHERE CLIENT_ID='" + dr["CLIENT_ID"].ToString() + "'@"); } } dsoriginal.WriteXml("C:\\project\\DTG\\TMS Reviews\\TMW\\WorkingClients2.xml"); File.WriteAllText(@"C:\project\DTG\TMS Reviews\TMW\ClientsGEOUpdateScript2.sql", sb.ToString()); }
private void buttonExecute_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(labelXMLConfigFile.Text) && !string.IsNullOrEmpty(labelFileName.Text)) { dataGridView1.DataSource = null; using (GenericParserAdapter parser = new GenericParserAdapter(labelFileName.Text)) { parser.Load(labelXMLConfigFile.Text); dataSet1 = parser.GetDataSet(); int qtdRegistros = dataSet1.Tables[0].Rows.Count; if (qtdRegistros > 1) { labelQtdeRegistros.Text = String.Format("{0:#,##0} Registros", dataSet1.Tables[0].Rows.Count); } else { labelQtdeRegistros.Text = String.Format("{0:#,##0} Registro", dataSet1.Tables[0].Rows.Count); } dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); dataGridView1.AutoGenerateColumns = true; dataGridView1.DataSource = dataSet1.Tables[0]; dataSet1.Tables[0].Columns.Add("Existe", typeof(System.String)); List <String> listCpfFound = new List <String>(); if (!string.IsNullOrEmpty(textBoxConnectioString.Text) && !string.IsNullOrEmpty(textBoxQuery.Text)) { try { //Password=sqluser;User ID=sqluser;Data Source=serverss003;Initial Catalog=COL_COLWEBACEITE;Persist Security Info=True using (var con = new SqlConnection(textBoxConnectioString.Text)) { string filtro = ""; foreach (DataRow row in dataSet1.Tables[0].Rows) { string text = row[2].ToString(); string cpf = text.Substring(0, 3) + "." + text.Substring(3, 3) + "." + text.Substring(6, 3) + "-" + text.Substring(9, 2); text = row[9].ToString(); string data = text.Substring(4, 4) + text.Substring(2, 2) + text.Substring(0, 2); string propCia = row[11].ToString().TrimStart('0'); if (string.IsNullOrEmpty(filtro)) { filtro = string.Format(" (tc.Cgc_cpf = '{0}' and td.Inicio_vigencia = '{1}' and td.Proposta_cia = '{2}')\n", cpf, data, propCia); } else { filtro += string.Format(" or (tc.Cgc_cpf = '{0}' and td.Inicio_vigencia = '{1}' and td.Proposta_cia = '{2}')\n", cpf, data, propCia); } } con.Open(); using (SqlCommand command = new SqlCommand(string.Format(textBoxQuery.Text, filtro), con)) { command.CommandTimeout = 3000; using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { listCpfFound.Add(reader.GetString(0).Replace("-", "").Replace(".", "")); } } } } } catch (Exception ex) { MessageBox.Show("Erro ao acessar o banco de dados: " + ex.Message); } } foreach (DataRow row in dataSet1.Tables[0].Rows) { if (listCpfFound.Where(c => c == row[2].ToString()).Count() > 0) { row["Existe"] = "Sim"; } else { row["Existe"] = "Não"; } } dataGridView1.Focus(); } } }
static void Main(string[] args) { try { CudafyModule km = CudafyModule.TryDeserialize(); if (km == null || !km.TryVerifyChecksums()) { km = CudafyTranslator.Cudafy(); km.TrySerialize(); } CudafyTranslator.GenerateDebug = true; // cuda or emulator GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId); gpu.LoadModule(km); //set up color profile to have a measure LAB lookup working #region Matrix3D navigationMatrix = new Matrix3D(); navigationMatrix.Translate(new Vector3D(0, 100, 110)); navigationMatrix.Scale(new Vector3D((double)1 / 5, (double)1 / 5, (double)1 / 5)); //2- Load the profile in a three dimensional array Bin[, ,] p3700 = new Bin[RANGEL, RANGEA, RANGEB]; for (int l = 0; l < RANGEL; l++) { for (int a = 0; a < RANGEA; a++) { for (int b = 0; b < RANGEB; b++) { p3700[l, a, b] = new Bin(l, a, b); } } } try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(@"C:\lev\STColorCorrection\Data\PROFILE\p3700.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch { } // #region for (int i = 1; i < profile.Rows.Count; i++) { //lab vale as got form profile index Point3D labBin = new Point3D(); labBin.X = Convert.ToDouble(profile.Rows[i][0].ToString()); labBin.Y = Convert.ToDouble(profile.Rows[i][1].ToString()); labBin.Z = Convert.ToDouble(profile.Rows[i][2].ToString()); //trasfered points Point3D labCoordinate = navigationMatrix.Transform(labBin); if (labCoordinate.X == 20 && labCoordinate.Y == 20 && labCoordinate.Z == 22) { Console.WriteLine("empty"); } //gets the bin to fill up Bin actualBin = GetProfileBin(p3700, labCoordinate); //bin RGB Value actualBin.binRGB.X = Convert.ToByte(profile.Rows[i][9].ToString()); actualBin.binRGB.Y = Convert.ToByte(profile.Rows[i][10].ToString()); actualBin.binRGB.Z = Convert.ToByte(profile.Rows[i][11].ToString()); //Measure Lab Values actualBin.measuredLAB.X = Convert.ToDouble(profile.Rows[i][3].ToString()); actualBin.measuredLAB.Y = Convert.ToDouble(profile.Rows[i][4].ToString()); actualBin.measuredLAB.Z = Convert.ToDouble(profile.Rows[i][5].ToString()); //measured XYZ Values actualBin.measuredXYZ.X = Convert.ToDouble(profile.Rows[i][6].ToString()); actualBin.measuredXYZ.Y = Convert.ToDouble(profile.Rows[i][7].ToString()); actualBin.measuredXYZ.Z = Convert.ToDouble(profile.Rows[i][8].ToString()); //is empty check actualBin.isEmpty = false; } #endregion //CVS FILE CREATING AND INICIALIZATION #region //create the CSV file CsvFileWriter output_file_1 = new CsvFileWriter(@"C:\lev\STColorCorrection\Data\CUDA performance analysis\out_file1.csv"); CsvFileWriter output_file_2 = new CsvFileWriter(@"C:\lev\STColorCorrection\Data\CUDA performance analysis\out_file2.csv"); //create the header CsvRow header = new CsvRow(); header.Add("R_fg_in"); header.Add("G_fg_in"); header.Add("B_fg_in"); header.Add("L_fg_in"); header.Add("A_fg_in"); header.Add("B_fg_in"); header.Add("X_bg_in"); header.Add("Y_bg_in"); header.Add("Z_bg_in"); header.Add("BF_Dist"); header.Add("Cuda BF time"); header.Add("QC_Dist"); header.Add("Cuda QC time"); header.Add("Snake_Dist"); header.Add("Cuda Snake time"); header.Add("DecreaseStep_DS"); header.Add("Cuda DS time"); output_file_1.WriteRow(header); header = new CsvRow(); header.Add("R_fg_in"); header.Add("G_fg_in"); header.Add("B_fg_in"); header.Add("L_fg_in"); header.Add("A_fg_in"); header.Add("B_fg_in"); header.Add("X_bg_in"); header.Add("Y_bg_in"); header.Add("Z_bg_in"); header.Add("BF_Dist"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); header.Add("QC_Dist"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); header.Add("Snake_Dist"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); header.Add("DecreaseStep_DS"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); output_file_2.WriteRow(header); //write the header to the CSV file #endregion Random randomGenerater = new Random(); for (int num_colors = 0; num_colors < 500; num_colors++) { //create a new csv row CsvRow new_row_file_1 = new CsvRow(); CsvRow new_row_file_2 = new CsvRow(); //colour selection Byte[] rgb = new Byte[3]; randomGenerater.NextBytes(rgb); System.Drawing.Color foreground = System.Drawing.Color.FromArgb(rgb[0], rgb[1], rgb[2]); Point3D backgroundCIEXYZ = new Point3D(0, 0, 0); backgroundCIEXYZ.X = randomGenerater.NextDouble() * 0.9504; backgroundCIEXYZ.Y = randomGenerater.NextDouble() * 1.0000; backgroundCIEXYZ.Z = randomGenerater.NextDouble() * 1.0888; Point3D background = new Point3D(backgroundCIEXYZ.X, backgroundCIEXYZ.Y, backgroundCIEXYZ.Z); Bin foregroundBin = FindForegroundBin(p3700, navigationMatrix, foreground); PerceptionLib.Color foregroundLAB = new PerceptionLib.Color(); foregroundLAB.LA = foregroundBin.measuredLAB.X; foregroundLAB.A = foregroundBin.measuredLAB.Y; foregroundLAB.B = foregroundBin.measuredLAB.Z; //write the input colors #region new_row_file_1.Add(foreground.R.ToString()); new_row_file_1.Add(foreground.G.ToString()); new_row_file_1.Add(foreground.B.ToString()); new_row_file_1.Add(foregroundLAB.LA.ToString()); new_row_file_1.Add(foregroundLAB.A.ToString()); new_row_file_1.Add(foregroundLAB.B.ToString()); new_row_file_1.Add(background.X.ToString()); new_row_file_1.Add(background.Y.ToString()); new_row_file_1.Add(background.Z.ToString()); new_row_file_2.Add(foreground.R.ToString()); new_row_file_2.Add(foreground.G.ToString()); new_row_file_2.Add(foreground.B.ToString()); new_row_file_2.Add(foregroundLAB.LA.ToString()); new_row_file_2.Add(foregroundLAB.A.ToString()); new_row_file_2.Add(foregroundLAB.B.ToString()); new_row_file_2.Add(background.X.ToString()); new_row_file_2.Add(background.Y.ToString()); new_row_file_2.Add(background.Z.ToString()); #endregion //get the brute force values Color.TestingStructure[] results_brute_force = Color.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_brute_force[0].distance.ToString()); new_row_file_1.Add(results_brute_force[0].execution_time.ToString()); Point3D labBin = new Point3D(); labBin.X = results_brute_force[0].Given_R; labBin.Y = results_brute_force[0].Given_G; labBin.Z = results_brute_force[0].Given_B; Bin actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_brute_force[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); quick_corr.TestingStructure[] results_quick_corr = quick_corr.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_quick_corr[0].distance.ToString()); new_row_file_1.Add(results_quick_corr[0].execution_time.ToString()); labBin = new Point3D(); labBin.X = results_quick_corr[0].Given_R; labBin.Y = results_quick_corr[0].Given_G; labBin.Z = results_quick_corr[0].Given_B; actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_quick_corr[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); snake.TestingStructure[] results_snake = snake.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_snake[0].distance.ToString()); new_row_file_1.Add(results_snake[0].execution_time.ToString()); labBin = new Point3D(); labBin.X = results_snake[0].Given_R; labBin.Y = results_snake[0].Given_G; labBin.Z = results_snake[0].Given_B; actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_snake[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); half_step.TestingStructure[] results_half_step = half_step.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_half_step[0].distance.ToString()); new_row_file_1.Add(results_half_step[0].execution_time.ToString()); labBin = new Point3D(); labBin.X = results_half_step[0].Given_R; labBin.Y = results_half_step[0].Given_G; labBin.Z = results_half_step[0].Given_B; actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_half_step[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); //write the results output_file_1.WriteRow(new_row_file_1); output_file_2.WriteRow(new_row_file_2); } //Color.Execute(); //quick_corr.Execute(); //close the CSV files output_file_1.Close(); output_file_2.Close(); Console.WriteLine("Done!"); } catch (Exception ex) { Console.WriteLine(ex); } theEnd: Console.ReadKey(); }
public static TestOutput CorrectColour(ForeGroundStrucuture[] foregorungRGB_CPU, BackGroundStrucuture[] BackgroundXYZ_CPU) { //rgb = System.Drawing.Color.FromArgb(69, 77, 217); //X = 0.0630982813175294; //Y = 0.616476271122916; //Z = 0.667048468232457; const int image_size = 1024 * 768; //cuda intializer CudafyModule km = CudafyModule.TryDeserialize(); if (km == null || !km.TryVerifyChecksums()) { // km = CudafyTranslator.Cudafy((typeof(ForeGroundStrucuture)), (typeof(BackGroundStrucuture)), typeof(Color)); km = CudafyTranslator.Cudafy((typeof(ProfileStrucuture)), (typeof(ForeGroundStrucuture)), (typeof(BackGroundStrucuture)), (typeof(SampleStructure)), typeof(quick_corr)); km.TrySerialize(); } CudafyTranslator.GenerateDebug = true; // cuda or emulator GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId); //GPGPU gpu = CudafyHost.GetDevice(eGPUType.Emulator); Console.WriteLine("Running quick correction using {0}", gpu.GetDeviceProperties(false).Name); gpu.LoadModule(km); ForeGroundStrucuture[] distance_CPU = new ForeGroundStrucuture[image_size]; // allocate memory on the GPU for the bitmap (same size as ptr) #region DataTable profile = new DataTable(); try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(@"C:\lev\STColorCorrection\Data\PROFILE\p3700.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch (Exception ex) { Console.WriteLine(ex); } #endregion // allocate temp memory, initialize it, copy to constant memory on the GPU // L 0-21 A 0-41 B 0-45 ProfileStrucuture[, ,] profiles_CPU = new ProfileStrucuture[21, 41, 45]; SampleStructure[,] samples_CPU = new SampleStructure[image_size, 6]; FGLookupStructure[, ,] fg_loopup_CPU = new FGLookupStructure[256, 256, 256]; //profile inicialization #region for (int indexL = 0; indexL < 21; indexL++) { for (int indexA = 0; indexA < 41; indexA++) { for (int indexB = 0; indexB < 45; indexB++) { profiles_CPU[indexL, indexA, indexB].L = indexL; profiles_CPU[indexL, indexA, indexB].A = indexA; profiles_CPU[indexL, indexA, indexB].B = indexB; //profiles_CPU[indexL, indexA, indexB].Given_R = 0; //profiles_CPU[indexL, indexA, indexB].Given_G = 0; //profiles_CPU[indexL, indexA, indexB].Given_B = 0; profiles_CPU[indexL, indexA, indexB].ML = 0; profiles_CPU[indexL, indexA, indexB].MA = 0; profiles_CPU[indexL, indexA, indexB].MB = 0; profiles_CPU[indexL, indexA, indexB].MX = 0; profiles_CPU[indexL, indexA, indexB].MY = 0; profiles_CPU[indexL, indexA, indexB].MZ = 0; profiles_CPU[indexL, indexA, indexB].distance = -1.0; profiles_CPU[indexL, indexA, indexB].weight = -1.0; profiles_CPU[indexL, indexA, indexB].isempty = TRUE; profiles_CPU[indexL, indexA, indexB].isMoreAccurateThanOrigin = FALSE; } } } int lvalue, avalue, bvalue; try { for (int i = 1; i < profile.Rows.Count; i++) { lvalue = Convert.ToInt32(profile.Rows[i][0].ToString()); avalue = Convert.ToInt32(profile.Rows[i][1].ToString()); bvalue = Convert.ToInt32(profile.Rows[i][2].ToString()); lvalue = (int)(lvalue * 0.2); avalue = (int)(avalue * 0.2) + 20; bvalue = (int)(bvalue * 0.2) + 22; profiles_CPU[lvalue, avalue, bvalue].L = lvalue; profiles_CPU[lvalue, avalue, bvalue].A = avalue; profiles_CPU[lvalue, avalue, bvalue].B = bvalue; //profiles_CPU[lvalue, avalue, bvalue].Given_R = (byte)Convert.ToByte(profile.Rows[i][9].ToString()); //profiles_CPU[lvalue, avalue, bvalue].Given_G = (byte)Convert.ToByte(profile.Rows[i][10].ToString()); //profiles_CPU[lvalue, avalue, bvalue].Given_B = (byte)Convert.ToByte(profile.Rows[i][11].ToString()); profiles_CPU[lvalue, avalue, bvalue].ML = (double)Convert.ToDouble(profile.Rows[i][3].ToString()); profiles_CPU[lvalue, avalue, bvalue].MA = (double)Convert.ToDouble(profile.Rows[i][4].ToString()); profiles_CPU[lvalue, avalue, bvalue].MB = (double)Convert.ToDouble(profile.Rows[i][5].ToString()); profiles_CPU[lvalue, avalue, bvalue].MX = (double)Convert.ToDouble(profile.Rows[i][6].ToString()); profiles_CPU[lvalue, avalue, bvalue].MY = (double)Convert.ToDouble(profile.Rows[i][7].ToString()); profiles_CPU[lvalue, avalue, bvalue].MZ = (double)Convert.ToDouble(profile.Rows[i][8].ToString()); profiles_CPU[lvalue, avalue, bvalue].isempty = FALSE; } } catch (Exception ex) { Console.WriteLine(ex); } #endregion //fg lookup inicialization #region for (int r = 0; r < 255; r++) { for (int g = 0; g < 255; g++) { for (int b = 0; b < 255; b++) { Point3D foregroundLAB = ToLAB(new ForeGroundStrucuture((byte)r, (byte)g, (byte)b)); int binL = ((int)Math.Round(foregroundLAB.X / 5.0)) * 5; int binA = ((int)Math.Round(foregroundLAB.Y / 5.0)) * 5; int binB = ((int)Math.Round(foregroundLAB.Z / 5.0)) * 5; if (binL > 100) { binL = 100; } if (binA < -86.17385493791946) { binA = -85; } if (binA > 98.2448002875424) { binA = 100; } if (binB < -107.8619171648283) { binB = -110; } if (binB > 94.47705120353054) { binB = 95; } fg_loopup_CPU[r, g, b].L = (int)(binL * 0.2) + 0; fg_loopup_CPU[r, g, b].A = (int)(binA * 0.2) + 20; fg_loopup_CPU[r, g, b].B = (int)(binB * 0.2) + 22; } } } #endregion //grab the colors ProfileStrucuture[, ,] profile_GPU = gpu.CopyToDevice(profiles_CPU); SampleStructure[,] samples_GPU = gpu.CopyToDevice(samples_CPU); FGLookupStructure[, ,] fg_loopup_GPU = gpu.CopyToDevice(fg_loopup_CPU); //begin execution // capture the start time gpu.StartTimer(); ForeGroundStrucuture[] foregorungRGB_GPU = gpu.CopyToDevice(foregorungRGB_CPU); BackGroundStrucuture[] BackgroundXYZ_GPU = gpu.CopyToDevice(BackgroundXYZ_CPU); //out put ForeGroundStrucuture[] distance_GPU = gpu.Allocate(distance_CPU); // generate a bitmap from our sphere data //Image size: 1024 x 768 dim3 grids = new dim3(1024 / 16, 768 / 16); dim3 threads = new dim3(16, 16); //dim3 grids = new dim3(1, 1); //dim3 threads = new dim3(1, 1); //quick_correct //gpu.Launch(grids, threads, ((Action<GThread, ProfileStrucuture[, ,], ForeGroundStrucuture[], BackGroundStrucuture[], ProfileStrucuture[], SampleStructure[,]>)QuickCorr), profile_GPU, foregorungRGB_GPU, BackgroundXYZ_GPU, distance_GPU, samples_GPU); //quick correct - testing //gpu.Launch(grids, threads, ((Action<GThread, ProfileStrucuture[, ,], ForeGroundStrucuture[], BackGroundStrucuture[], ForeGroundStrucuture[], SampleStructure[,]>)QuickCorr), profile_GPU, foregorungRGB_GPU, BackgroundXYZ_GPU, distance_GPU, samples_GPU); gpu.Launch(grids, threads, ((Action <GThread, ProfileStrucuture[, , ], ForeGroundStrucuture[], BackGroundStrucuture[], ForeGroundStrucuture[], SampleStructure[, ], FGLookupStructure[, , ]>)QuickCorr), profile_GPU, foregorungRGB_GPU, BackgroundXYZ_GPU, distance_GPU, samples_GPU, fg_loopup_GPU); // copy our bitmap back from the GPU for display gpu.CopyFromDevice(distance_GPU, distance_CPU); // get stop time, and display the timing results double elapsedTime = gpu.StopTimer(); TestOutput to_return = new TestOutput(); to_return.output_image = distance_CPU; to_return.timeTaken = elapsedTime; Console.WriteLine("Time to generate: {0} ms", elapsedTime); gpu.Free(foregorungRGB_GPU); gpu.Free(BackgroundXYZ_GPU); gpu.Free(distance_GPU); gpu.FreeAll(); return(to_return); }
public static TestOutput CorrectColour(ForeGroundStrucuture[] foregorungRGB_CPU, BackGroundStrucuture[] BackgroundXYZ_CPU) { //set these to constant if you want testing //rgb = System.Drawing.Color.FromArgb(65, 108, 20); //X = 0.613829950099918; //Y = 0.938638756488747; //Z = 1.08019833591292; const int image_size = 960 * 540; //cuda intializer CudafyModule km = CudafyModule.TryDeserialize(); if (km == null || !km.TryVerifyChecksums()) { // km = CudafyTranslator.Cudafy((typeof(ForeGroundStrucuture)), (typeof(BackGroundStrucuture)), typeof(Color)); km = CudafyTranslator.Cudafy(typeof(ProfileStrucuture), typeof(ForeGroundStrucuture), typeof(BackGroundStrucuture), typeof(bf)); km.TrySerialize(); } CudafyTranslator.GenerateDebug = true; // cuda or emulator GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId); //sGPGPU gpu = CudafyHost.GetDevice(eGPUType.Emulator); gpu.LoadModule(km); Console.WriteLine("Running brute force correction using {0}", gpu.GetDeviceProperties(false).Name); ForeGroundStrucuture[] output_image_CPU = new ForeGroundStrucuture[image_size]; // allocate memory on the GPU for the bitmap (same size as ptr) DataTable profile = new DataTable(); try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(@"C:\lev\STColorCorrection\Data\PROFILE\p3700.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch (Exception ex) { Console.WriteLine(ex); } // allocate temp memory, initialize it, copy to constant memory on the GPU // L 0-21 A 0-41 B 0-45 ProfileStrucuture[ , , ] profiles_CPU = new ProfileStrucuture[21, 41, 45]; //ForeGroundStrucuture[] foregorungRGB_CPU = new ForeGroundStrucuture[image_size]; //BackGroundStrucuture[] BackgroundXYZ_CPU = new BackGroundStrucuture[image_size]; for (int indexL = 0; indexL < 21; indexL++) { for (int indexA = 0; indexA < 41; indexA++) { for (int indexB = 0; indexB < 45; indexB++) { profiles_CPU[indexL, indexA, indexB].L = indexL; profiles_CPU[indexL, indexA, indexB].A = indexA; profiles_CPU[indexL, indexA, indexB].B = indexB; profiles_CPU[indexL, indexA, indexB].Given_R = 0; profiles_CPU[indexL, indexA, indexB].Given_G = 0; profiles_CPU[indexL, indexA, indexB].Given_B = 0; profiles_CPU[indexL, indexA, indexB].ML = 0; profiles_CPU[indexL, indexA, indexB].MA = 0; profiles_CPU[indexL, indexA, indexB].MB = 0; profiles_CPU[indexL, indexA, indexB].MX = 0; profiles_CPU[indexL, indexA, indexB].MY = 0; profiles_CPU[indexL, indexA, indexB].MZ = 0; profiles_CPU[indexL, indexA, indexB].isempty = TRUE; profiles_CPU[indexL, indexA, indexB].isMoreAccurateThanOrigin = -1; } } } int lvalue, avalue, bvalue; try { for (int i = 1; i < profile.Rows.Count; i++) { lvalue = Convert.ToInt32(profile.Rows[i][0].ToString()); avalue = Convert.ToInt32(profile.Rows[i][1].ToString()); bvalue = Convert.ToInt32(profile.Rows[i][2].ToString()); lvalue = (int)(lvalue * 0.2); avalue = (int)(avalue * 0.2) + 20; bvalue = (int)(bvalue * 0.2) + 22; profiles_CPU[lvalue, avalue, bvalue].L = lvalue; profiles_CPU[lvalue, avalue, bvalue].A = avalue; profiles_CPU[lvalue, avalue, bvalue].B = bvalue; profiles_CPU[lvalue, avalue, bvalue].Given_R = (byte)Convert.ToByte(profile.Rows[i][9].ToString()); profiles_CPU[lvalue, avalue, bvalue].Given_G = (byte)Convert.ToByte(profile.Rows[i][10].ToString()); profiles_CPU[lvalue, avalue, bvalue].Given_B = (byte)Convert.ToByte(profile.Rows[i][11].ToString()); profiles_CPU[lvalue, avalue, bvalue].ML = (double)Convert.ToDouble(profile.Rows[i][3].ToString()); profiles_CPU[lvalue, avalue, bvalue].MA = (double)Convert.ToDouble(profile.Rows[i][4].ToString()); profiles_CPU[lvalue, avalue, bvalue].MB = (double)Convert.ToDouble(profile.Rows[i][5].ToString()); profiles_CPU[lvalue, avalue, bvalue].MX = (double)Convert.ToDouble(profile.Rows[i][6].ToString()); profiles_CPU[lvalue, avalue, bvalue].MY = (double)Convert.ToDouble(profile.Rows[i][7].ToString()); profiles_CPU[lvalue, avalue, bvalue].MZ = (double)Convert.ToDouble(profile.Rows[i][8].ToString()); profiles_CPU[lvalue, avalue, bvalue].isempty = FALSE; } } catch (Exception ex) { Console.WriteLine(ex); } //foreground and background image inicialization #region //try //{ // for (int i = 0; i < 1; i++) // { // foregorungRGB_CPU[i].R = rgb.R; // foregorungRGB_CPU[i].G = rgb.G; // foregorungRGB_CPU[i].B = rgb.B; // BackgroundXYZ_CPU[i].X = X; // BackgroundXYZ_CPU[i].Y = Y; // BackgroundXYZ_CPU[i].Z = Z; // } //} //catch (Exception ex) //{ Console.WriteLine(ex); } #endregion ProfileStrucuture[, ,] profile_GPU = gpu.CopyToDevice(profiles_CPU); // capture the start time gpu.StartTimer(); ForeGroundStrucuture[] foregorungRGB_GPU = gpu.CopyToDevice(foregorungRGB_CPU); BackGroundStrucuture[] BackgroundXYZ_GPU = gpu.CopyToDevice(BackgroundXYZ_CPU); //out put ForeGroundStrucuture[] distance_GPU = gpu.Allocate(output_image_CPU); // generate a bitmap from our sphere data //Image size: 1024 x 768 //dim3 grids = new dim3(1, 1); //dim3 threads = new dim3(1,1); dim3 grids = new dim3(24, 675); dim3 threads = new dim3(8, 4); gpu.Launch(grids, threads, ((Action <GThread, ProfileStrucuture[, , ], ForeGroundStrucuture[], BackGroundStrucuture[], ForeGroundStrucuture[]>)Bruteforce), profile_GPU, foregorungRGB_GPU, BackgroundXYZ_GPU, distance_GPU); //gpu.Launch(grids, threads, ((Action<GThread, ForeGroundStrucuture[], BackGroundStrucuture[], double[]>)Bruteforce), foregorungRGB_GPU, BackgroundXYZ_GPU, distance_GPU); // copy our bitmap back from the GPU for display gpu.CopyFromDevice(distance_GPU, output_image_CPU); // get stop time, and display the timing results double elapsedTime = gpu.StopTimer(); TestOutput to_return = new TestOutput(); to_return.output_image = output_image_CPU; to_return.timeTaken = elapsedTime; //encapsulte the output image into a class //output_image_CPU[0].execution_time = elapsedTime; Console.WriteLine("Time to generate: {0} ms", elapsedTime); gpu.Free(foregorungRGB_GPU); gpu.Free(BackgroundXYZ_GPU); gpu.Free(distance_GPU); gpu.FreeAll(); return(to_return); }
private void btn_1024x768_Click(object sender, RoutedEventArgs e) { Matrix3D navigationMatrix = new Matrix3D(); navigationMatrix.Translate(new Vector3D(0, 100, 110)); navigationMatrix.Scale(new Vector3D((double)1 / 5, (double)1 / 5, (double)1 / 5)); //2- Load the profile in a three dimensional array Bin[, ,] p3700 = new Bin[RANGEL, RANGEA, RANGEB]; for (int l = 0; l < RANGEL; l++) { for (int a = 0; a < RANGEA; a++) { for (int b = 0; b < RANGEB; b++) { p3700[l, a, b] = new Bin(l, a, b); } } } try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(@"C:\Users\jhincapie\Desktop\Projects\STColorCorrection\Data\PROFILE\p3700.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch { } for (int i = 1; i < profile.Rows.Count; i++) { //lab vale as got form profile index Point3D labBin = new Point3D(); labBin.X = Convert.ToDouble(profile.Rows[i][0].ToString()); labBin.Y = Convert.ToDouble(profile.Rows[i][1].ToString()); labBin.Z = Convert.ToDouble(profile.Rows[i][2].ToString()); //trasfered points Point3D labCoordinate = navigationMatrix.Transform(labBin); //gets the bin to fill up Bin actualBin = GetProfileBin(p3700, labCoordinate); //bin RGB Value actualBin.binRGB.X = Convert.ToByte(profile.Rows[i][9].ToString()); actualBin.binRGB.Y = Convert.ToByte(profile.Rows[i][10].ToString()); actualBin.binRGB.Z = Convert.ToByte(profile.Rows[i][11].ToString()); //Measure Lab Values actualBin.measuredLAB.X = Convert.ToDouble(profile.Rows[i][3].ToString()); actualBin.measuredLAB.Y = Convert.ToDouble(profile.Rows[i][4].ToString()); actualBin.measuredLAB.Z = Convert.ToDouble(profile.Rows[i][5].ToString()); //measured XYZ Values actualBin.measuredXYZ.X = Convert.ToDouble(profile.Rows[i][6].ToString()); actualBin.measuredXYZ.Y = Convert.ToDouble(profile.Rows[i][7].ToString()); actualBin.measuredXYZ.Z = Convert.ToDouble(profile.Rows[i][8].ToString()); //is empty check actualBin.isEmpty = false; } Stopwatch stop2 = new Stopwatch(); stop2.Start(); // to create a random number Random randomGenerater = new Random(); for (int i = 0; i < 1024; i++) { for (int j = 0; j < 768; j++) { Byte[] rgb = new Byte[3]; randomGenerater.NextBytes(rgb); System.Drawing.Color foreground = System.Drawing.Color.FromArgb(rgb[0], rgb[1], rgb[2]); PerceptionLib.CIEXYZ backgroundCIEXYZ = new CIEXYZ(0, 0, 0); backgroundCIEXYZ.X = randomGenerater.NextDouble() * 0.9504; backgroundCIEXYZ.Y = randomGenerater.NextDouble() * 1.0000; backgroundCIEXYZ.Z = randomGenerater.NextDouble() * 1.0888; Point3D background = new Point3D(backgroundCIEXYZ.X, backgroundCIEXYZ.Y, backgroundCIEXYZ.Z); Bin foregroundBin = FindForegroundBin(p3700, navigationMatrix, foreground); PerceptionLib.Color fg = new PerceptionLib.Color(); //fg measured LAB value fg.LA = foregroundBin.measuredLAB.X; fg.A = foregroundBin.measuredLAB.Y; fg.B = foregroundBin.measuredLAB.Z; Bin corretedColorQCHS = QuickCorrection(p3700, navigationMatrix, foreground, background, HalfTheStep); } } stop2.Stop(); Console.WriteLine(stop2.ElapsedMilliseconds); }
private void btn_Start_Click(object sender, RoutedEventArgs e) { Matrix3D navigationMatrix = new Matrix3D(); navigationMatrix.Translate(new Vector3D(0, 100, 110)); navigationMatrix.Scale(new Vector3D((double)1 / 5, (double)1 / 5, (double)1 / 5)); //2- Load the profile in a three dimensional array Bin[, ,] p3700 = new Bin[RANGEL, RANGEA, RANGEB]; for (int l = 0; l < RANGEL; l++) { for (int a = 0; a < RANGEA; a++) { for (int b = 0; b < RANGEB; b++) { p3700[l, a, b] = new Bin(l, a, b); } } } try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(Environment.CurrentDirectory + @"\..\..\..\..\..\Data\PROFILE\IdealProfile.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch { } for (int i = 1; i < profile.Rows.Count; i++) { //lab vale as got form profile index Point3D labBin = new Point3D(); labBin.X = Convert.ToDouble(profile.Rows[i][0].ToString()); labBin.Y = Convert.ToDouble(profile.Rows[i][1].ToString()); labBin.Z = Convert.ToDouble(profile.Rows[i][2].ToString()); //trasfered points Point3D labCoordinate = navigationMatrix.Transform(labBin); //gets the bin to fill up Bin actualBin = GetProfileBin(p3700, labCoordinate); //bin RGB Value actualBin.binRGB.X = Convert.ToByte(profile.Rows[i][9].ToString()); actualBin.binRGB.Y = Convert.ToByte(profile.Rows[i][10].ToString()); actualBin.binRGB.Z = Convert.ToByte(profile.Rows[i][11].ToString()); //Measure Lab Values actualBin.measuredLAB.X = Convert.ToDouble(profile.Rows[i][3].ToString()); actualBin.measuredLAB.Y = Convert.ToDouble(profile.Rows[i][4].ToString()); actualBin.measuredLAB.Z = Convert.ToDouble(profile.Rows[i][5].ToString()); //measured XYZ Values actualBin.measuredXYZ.X = Convert.ToDouble(profile.Rows[i][6].ToString()); actualBin.measuredXYZ.Y = Convert.ToDouble(profile.Rows[i][7].ToString()); actualBin.measuredXYZ.Z = Convert.ToDouble(profile.Rows[i][8].ToString()); //is empty check actualBin.isEmpty = false; } //3- Get the parameters: foreground and background //System.Drawing.Color foreground = System.Drawing.Color.FromArgb(150, 150, 150); //PerceptionLib.CIEXYZ background = new CIEXYZ(0.2146, 0.43125, 0.07595); //RGB: 0 199 0 - greenish ///////////////// //code for comarison //populate template in datagrid PopulateGrid(Environment.CurrentDirectory + @"\..\..\..\..\..\Data\PROFILE\Comparison_Template.txt"); DataTable template = new DataTable(); Dispatcher.Invoke(DispatcherPriority.Render, new Action(() => { dtgrid_corrDisplay.Items.Refresh(); template = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable(); })); // to create a random number Random randomGenerater = new Random(); for (int i = 0; i < 1000; i++) { Byte[] rgb = new Byte[3]; randomGenerater.NextBytes(rgb); System.Drawing.Color foreground = System.Drawing.Color.FromArgb(rgb[0], rgb[1], rgb[2]); PerceptionLib.CIEXYZ backgroundCIEXYZ = new CIEXYZ(0, 0, 0); backgroundCIEXYZ.X = randomGenerater.NextDouble() * 0.9504; backgroundCIEXYZ.Y = randomGenerater.NextDouble() * 1.0000; backgroundCIEXYZ.Z = randomGenerater.NextDouble() * 1.0888; Point3D background = new Point3D(backgroundCIEXYZ.X, backgroundCIEXYZ.Y, backgroundCIEXYZ.Z); try { Bin foregroundBin = FindForegroundBin(p3700, navigationMatrix, foreground); PerceptionLib.Color foregroundLAB = new PerceptionLib.Color(); //fg measured LAB value foregroundLAB.LA = foregroundBin.measuredLAB.X; foregroundLAB.A = foregroundBin.measuredLAB.Y; foregroundLAB.B = foregroundBin.measuredLAB.Z; Stopwatch stop1 = new Stopwatch(); stop1.Start(); Bin corretedColorBF = null; corretedColorBF = BruteForceCorrection(p3700, navigationMatrix, foreground, background); stop1.Stop(); Stopwatch stop2 = new Stopwatch(); stop2.Start(); Bin corretedColorQCHS = QuickCorrection(p3700, navigationMatrix, foreground, background, HalfTheStep); stop2.Stop(); Stopwatch stop3 = new Stopwatch(); stop3.Start(); Bin corretedColorQCD = QuickCorrection(p3700, navigationMatrix, foreground, background, DecreaseTheStep); stop3.Stop(); Stopwatch stop4 = new Stopwatch(); stop4.Start(); Bin corretedColorSC = SnakeCorrection(p3700, navigationMatrix, foreground, background); stop4.Stop(); DataRow newRow = template.NewRow(); newRow["FgR"] = foreground.R.ToString(); newRow["FgG"] = foreground.G.ToString(); newRow["FgB"] = foreground.B.ToString(); newRow["BgX"] = background.X.ToString(); newRow["BgY"] = background.Y.ToString(); newRow["BgZ"] = background.Z.ToString(); newRow["FgL"] = foregroundLAB.LA.ToString(); newRow["FgA"] = foregroundLAB.A.ToString(); newRow["Fg_B"] = foregroundLAB.B.ToString(); newRow["BFL"] = corretedColorBF.binLAB.X.ToString(); newRow["BFA"] = corretedColorBF.binLAB.Y.ToString(); newRow["BFB"] = corretedColorBF.binLAB.Z.ToString(); newRow["BFDis"] = corretedColorBF.distanceLAB.ToString(); newRow["BFTime"] = stop1.ElapsedTicks.ToString(); newRow["QCHSL"] = corretedColorQCHS.binLAB.X.ToString(); newRow["QCHSA"] = corretedColorQCHS.binLAB.Y.ToString(); newRow["QCHSB"] = corretedColorQCHS.binLAB.Z.ToString(); newRow["QCHSCycles"] = corretedColorQCHS.cycles; newRow["QCHSDis"] = corretedColorQCHS.distanceLAB.ToString(); newRow["QCHSOffSet"] = Math.Abs(corretedColorBF.distanceLAB - corretedColorQCHS.distanceLAB); newRow["QCHSTime"] = stop2.ElapsedTicks.ToString(); newRow["QCHSRatio"] = (stop1.ElapsedTicks / stop2.ElapsedTicks).ToString(); newRow["QCDL"] = corretedColorQCD.binLAB.X.ToString(); newRow["QCDA"] = corretedColorQCD.binLAB.Y.ToString(); newRow["QCDB"] = corretedColorQCD.binLAB.Z.ToString(); newRow["QCDCycles"] = corretedColorQCD.cycles; newRow["QCDDis"] = corretedColorQCD.distanceLAB.ToString(); newRow["QCDOffSet"] = Math.Abs(corretedColorBF.distanceLAB - corretedColorQCD.distanceLAB); newRow["QCDTime"] = stop3.ElapsedTicks.ToString(); newRow["QCDRatio"] = (stop1.ElapsedTicks / stop3.ElapsedTicks).ToString(); newRow["SCL"] = corretedColorSC.binLAB.X.ToString(); newRow["SCA"] = corretedColorSC.binLAB.Y.ToString(); newRow["SCB"] = corretedColorSC.binLAB.Z.ToString(); newRow["SCCycles"] = corretedColorSC.cycles; newRow["SCDis"] = corretedColorSC.distanceLAB.ToString(); newRow["SCOffSet"] = Math.Abs(corretedColorBF.distanceLAB - corretedColorSC.distanceLAB); newRow["SCTime"] = stop4.ElapsedTicks.ToString(); newRow["SCRatio"] = (stop1.ElapsedTicks / stop4.ElapsedTicks).ToString(); template.Rows.Add(newRow); } catch { Console.WriteLine(""); } } Dispatcher.Invoke(new Action(() => { dtgrid_corrDisplay.ItemsSource = template.DefaultView; dtgrid_corrDisplay.Items.Refresh(); })); }
static void Main(string[] args) { try { CudafyModule km = CudafyModule.TryDeserialize(); if (km == null || !km.TryVerifyChecksums()) { km = CudafyTranslator.Cudafy(); km.TrySerialize(); } CudafyTranslator.GenerateDebug = true; // cuda or emulator GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId); gpu.LoadModule(km); //set up color profile to have a measure LAB lookup working #region Matrix3D navigationMatrix = new Matrix3D(); navigationMatrix.Translate(new Vector3D(0, 100, 110)); navigationMatrix.Scale(new Vector3D((double)1 / 5, (double)1 / 5, (double)1 / 5)); //2- Load the profile in a three dimensional array Bin[, ,] p3700 = new Bin[RANGEL, RANGEA, RANGEB]; for (int l = 0; l < RANGEL; l++) { for (int a = 0; a < RANGEA; a++) { for (int b = 0; b < RANGEB; b++) { p3700[l, a, b] = new Bin(l, a, b); } } } try { // add the csv bin file using (GenericParserAdapter parser = new GenericParserAdapter(@"C:\lev\STColorCorrection\Data\PROFILE\p3700.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch { } // #region for (int i = 1; i < profile.Rows.Count; i++) { //lab vale as got form profile index Point3D labBin = new Point3D(); labBin.X = Convert.ToDouble(profile.Rows[i][0].ToString()); labBin.Y = Convert.ToDouble(profile.Rows[i][1].ToString()); labBin.Z = Convert.ToDouble(profile.Rows[i][2].ToString()); //trasfered points Point3D labCoordinate = navigationMatrix.Transform(labBin); if (labCoordinate.X == 20 && labCoordinate.Y == 20 && labCoordinate.Z == 22) { Console.WriteLine("empty"); } //gets the bin to fill up Bin actualBin = GetProfileBin(p3700, labCoordinate); //bin RGB Value actualBin.binRGB.X = Convert.ToByte(profile.Rows[i][9].ToString()); actualBin.binRGB.Y = Convert.ToByte(profile.Rows[i][10].ToString()); actualBin.binRGB.Z = Convert.ToByte(profile.Rows[i][11].ToString()); //Measure Lab Values actualBin.measuredLAB.X = Convert.ToDouble(profile.Rows[i][3].ToString()); actualBin.measuredLAB.Y = Convert.ToDouble(profile.Rows[i][4].ToString()); actualBin.measuredLAB.Z = Convert.ToDouble(profile.Rows[i][5].ToString()); //measured XYZ Values actualBin.measuredXYZ.X = Convert.ToDouble(profile.Rows[i][6].ToString()); actualBin.measuredXYZ.Y = Convert.ToDouble(profile.Rows[i][7].ToString()); actualBin.measuredXYZ.Z = Convert.ToDouble(profile.Rows[i][8].ToString()); //is empty check actualBin.isEmpty = false; } #endregion //CVS FILE CREATING AND INICIALIZATION #region //create the CSV file CsvFileWriter output_file_1 = new CsvFileWriter(@"C:\lev\STColorCorrection\Data\CUDA performance analysis\times_file.csv"); //create the header CsvRow header = new CsvRow(); header.Add("Cuda BF time"); header.Add("Cuda QC time"); header.Add("Cuda Snake time"); header.Add("Cuda HF time"); output_file_1.WriteRow(header); #endregion Random randomGenerater = new Random(); for (int num_colors = 0; num_colors < 2; num_colors++) { //create a new csv row CsvRow new_row_file_1 = new CsvRow(); const int image_size = 1024 * 768; bf.ForeGroundStrucuture[] foregorungRGB_BF = new bf.ForeGroundStrucuture[image_size]; bf.BackGroundStrucuture[] BackgroundXYZ_BF = new bf.BackGroundStrucuture[image_size]; quick_corr.ForeGroundStrucuture[] foregorungRGB_QC = new quick_corr.ForeGroundStrucuture[image_size]; quick_corr.BackGroundStrucuture[] BackgroundXYZ_QC = new quick_corr.BackGroundStrucuture[image_size]; snake.ForeGroundStrucuture[] foregorungRGB_SN = new snake.ForeGroundStrucuture[image_size]; snake.BackGroundStrucuture[] BackgroundXYZ_SN = new snake.BackGroundStrucuture[image_size]; reduce_step.ForeGroundStrucuture[] foregorungRGB_RS = new reduce_step.ForeGroundStrucuture[image_size]; reduce_step.BackGroundStrucuture[] BackgroundXYZ_RS = new reduce_step.BackGroundStrucuture[image_size]; for (int i = 0; i < image_size; i++) { //static colour //System.Drawing.Color foreground = System.Drawing.Color.FromArgb(69, 77, 217); //Point3D backgroundCIEXYZ = new Point3D(0.0630982813175294, 0.616476271122916, 0.667048468232457); //dynamic random colour Byte[] rgb = new Byte[3]; randomGenerater.NextBytes(rgb); System.Drawing.Color foreground = System.Drawing.Color.FromArgb(rgb[0], rgb[1], rgb[2]); Point3D backgroundCIEXYZ = new Point3D(0, 0, 0); backgroundCIEXYZ.X = randomGenerater.NextDouble() * 0.9504; backgroundCIEXYZ.Y = randomGenerater.NextDouble() * 1.0000; backgroundCIEXYZ.Z = randomGenerater.NextDouble() * 1.0888; Point3D background = new Point3D(backgroundCIEXYZ.X, backgroundCIEXYZ.Y, backgroundCIEXYZ.Z); foregorungRGB_BF[i].R = foreground.R; foregorungRGB_BF[i].G = foreground.G; foregorungRGB_BF[i].B = foreground.B; BackgroundXYZ_BF[i].X = backgroundCIEXYZ.X; BackgroundXYZ_BF[i].Y = backgroundCIEXYZ.Y; BackgroundXYZ_BF[i].Z = backgroundCIEXYZ.Z; foregorungRGB_QC[i].R = foreground.R; foregorungRGB_QC[i].G = foreground.G; foregorungRGB_QC[i].B = foreground.B; BackgroundXYZ_QC[i].X = backgroundCIEXYZ.X; BackgroundXYZ_QC[i].Y = backgroundCIEXYZ.Y; BackgroundXYZ_QC[i].Z = backgroundCIEXYZ.Z; foregorungRGB_SN[i].R = foreground.R; foregorungRGB_SN[i].G = foreground.G; foregorungRGB_SN[i].B = foreground.B; BackgroundXYZ_SN[i].X = backgroundCIEXYZ.X; BackgroundXYZ_SN[i].Y = backgroundCIEXYZ.Y; BackgroundXYZ_SN[i].Z = backgroundCIEXYZ.Z; foregorungRGB_RS[i].R = foreground.R; foregorungRGB_RS[i].G = foreground.G; foregorungRGB_RS[i].B = foreground.B; BackgroundXYZ_RS[i].X = backgroundCIEXYZ.X; BackgroundXYZ_RS[i].Y = backgroundCIEXYZ.Y; BackgroundXYZ_RS[i].Z = backgroundCIEXYZ.Z; } //write the input colors #region #endregion //prepare a BF specific struct //get the brute force values //bf.TestOutput results_brute_force = bf.CorrectColour(foregorungRGB_BF, BackgroundXYZ_BF); //new_row_file_1.Add(results_brute_force.timeTaken.ToString()); //Console.WriteLine(""); quick_corr.TestOutput results_quick_corr = quick_corr.CorrectColour(foregorungRGB_QC, BackgroundXYZ_QC); new_row_file_1.Add(results_quick_corr.timeTaken.ToString()); //Console.WriteLine(results_quick_corr.timeTaken.ToString()); //snake.TestOutput results_snake_corr = snake.CorrectColour(foregorungRGB_SN, BackgroundXYZ_SN); //new_row_file_1.Add(results_snake_corr.timeTaken.ToString()); //Console.WriteLine(""); //reduce_step.TestOutput results_reduce_step = reduce_step.CorrectColour(foregorungRGB_RS, BackgroundXYZ_RS); //new_row_file_1.Add(results_reduce_step.timeTaken.ToString()); output_file_1.WriteRow(new_row_file_1); } //Color.Execute(); //quick_corr.Execute(); //close the CSV files output_file_1.Close(); Console.WriteLine("Done!"); } catch (Exception ex) { Console.WriteLine(ex); } theEnd: Console.ReadKey(); }