// loads cells from the given file public void loadCellsFromFile(string path) { // clear all of the previous cells so the new ones can be loaded if (cells != null) { foreach (GameObject cell in cells) { Destroy(cell); } } var xmlParser = new XmlParser(); var matParser = new MatParser(); try{ // string path = EditorUtility.OpenFilePanel("Select XML or MAT File", "", ""); string physicellCellsPath; if (!path.Contains(".xml") && !path.Contains(".XML")) { if (path.Contains(".mat") || path.Contains(".MAT")) { physicellCellsPath = path; // just used the default variables variableNames = new string[32] { "ID", "position", "position", "position", "total_volume", "cell_type", "cycle_model", "current_phase", "elapsed_time_in_phase", "nuclear_volume", "cytopasmic_volume", "fluid_fraction", "calcified_fraction", "orientation", "orientation", "orientation", "polarity", "migration_speed", "motility_vector", "motility_vector", "motility_vector", "migration_bias", "motility_bias_direction", "motility_bias_direction", "motility_bias_direction", "persistence_time", "motility_reserved", "oncoprotein", "elastic_coefficient", "kill_rate", "attachment_lifetime", "attachment_rate" }; } else { throw new System.Exception("wrong file type, wanted XML or MAT"); } } else { xmlParser.parseXML(path); // use the MAT file referenced in the XML file physicellCellsPath = xmlParser.getPhysicellCellsPath(); // use the variables specified by the XML file variableNames = xmlParser.getVariableNames(); } // parser.GetComponent<MatParser>().parseMat("Assets/Parsing Test Data/output00003696_cells_physicell.mat"); // invoke the parse function in our MatParser matParser.parseMat(physicellCellsPath); // once the pare function has been invoked, we can access that matData float[,] data = matParser.getData(); cells = new GameObject[greatestID(data) + 1]; Vector3 origin = OriginObj.transform.position; // initialize all of the modification zones foreach (GameObject modZone in modificationZones) { modZone.GetComponent <Modifier>().init(); } float[] cellDataCol; int numCells = data.GetLength(1); for (int i = 0; i < numCells; i++) { // get the current col of data cellDataCol = getDataColumn(data, i); // initialize each cell and place it in the scene and in cell array try{ Vector3 pos = new Vector3(cellDataCol[1] + origin.x, cellDataCol[2] + origin.y, cellDataCol[3] + origin.z); // occasionally, cells are given an infinite for one of their coordinates, so we just ignore those cases if (pos.x > 100000 || pos.y > 100000 || pos.z > 100000) { continue; } // create the cell GameObject g = Instantiate(cellPrefab, pos, Quaternion.identity); float radius = (float)(Math.Pow(cellDataCol[4] / ((4f / 3f) * Math.PI), 1f / 3f)); g.transform.localScale = new Vector3(radius, radius, radius); // place the cell in our cells array cells[(int)cellDataCol[0]] = g; // give the cell a random color (just for fun) // g.GetComponent<Renderer>().material.SetColor("_Color", new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f))); // place the cell in the correct position in the scene and give it the appropriate variable names g.GetComponent <CellData>().init(pos, variableNames); // instantiate CellData variable dictionary int variableIndex = 0; foreach (string variableName in variableNames) { g.GetComponent <CellData>().addDataPoint(variableName, cellDataCol[variableIndex]); variableIndex++; } // apply all modification zones foreach (GameObject modZone in modificationZones) { // if the cell is inside of modZone, apply modZone's modify function to it if (modZone.GetComponent <Collider>().bounds.Contains(g.GetComponent <CellData>().getRealPosition())) { modZone.GetComponent <Modifier>().modify(g); } } } catch (Exception e) { Debug.Log("Exception " + e + " at cell id: " + cellDataCol[0]); } } } catch (Exception fe) { Debug.Log(fe); } }
public static ArrayList parse(string fileName, ref ArrayList fileContent) { ArrayList textureTricks = new ArrayList(); TextureTrick tt; ArrayList textureTrickData = null; int textureTrickStartIndex = -1, textureTrickEndIndex = -1; string textureTrickName = ""; bool isTextureTrick = false; bool createTextureTrick = false; int endCount = 0; int maxEndCount = 0; int i = 0; foreach (object obj in fileContent) { System.Windows.Forms.Application.DoEvents(); string line = (string)obj; line = common.COH_IO.removeExtraSpaceBetweenWords(((string)obj).Replace("\t", " ")).Trim(); if (line.ToLower().StartsWith("Texture ".ToLower()) && !MatParser.isMatTrick(fileContent, i)) //!line.ToLower().StartsWith("Texture X_".ToLower())) { textureTrickName = line.Replace("//", "#").Replace("Texture ", "").Replace("texture ", "").Split('#')[0].Replace(".tga", "").Replace(".TGA", "").Replace(".Txt", "").Replace(".txt", ""); textureTrickStartIndex = i; isTextureTrick = true; createTextureTrick = false; textureTrickData = new ArrayList(); } if (isTextureTrick) { string dataObj = (string)obj; if (dataObj.ToLower().Contains("Texture_Name".ToLower())) { dataObj = common.COH_IO.fixInnerCamelCase((string)obj, "Texture_Name").Replace("Texture_Name.tga", "none").Replace("Texture_Name", "none"); } textureTrickData.Add(dataObj); if (line.ToLower().StartsWith("End".ToLower())) { endCount++; } if (endCount > maxEndCount || i == (fileContent.Count - 1)) { isTextureTrick = false; textureTrickEndIndex = i; createTextureTrick = true; } if (createTextureTrick) { tt = new TextureTrick(textureTrickStartIndex, textureTrickEndIndex, textureTrickData, fileName, textureTrickName); textureTricks.Add(tt); endCount = 0; maxEndCount = 0; } } i++; } return(textureTricks); }
public matBlockForm(string file_name, ref RichTextBox rtBx, ref ArrayList file_content, System.Collections.Generic.Dictionary <string, string> tga_files_dictionary) { finishedLoading = true; common.WatingIconAnim wia = new COH_CostumeUpdater.common.WatingIconAnim(); wia.Show(); Application.DoEvents(); this.Cursor = Cursors.WaitCursor; selectdMatBtn = null; rTextBox = rtBx; bumpMap2Indx = -1; updateMatListComboBx = true; fileName = file_name; System.Windows.Forms.Application.DoEvents(); InitializeComponent(); System.Windows.Forms.Application.DoEvents(); matListCmboBx.Items.Clear(); fileContent = (ArrayList)file_content.Clone(); tgaFilesDictionary = tga_files_dictionary; if (matTricksList != null) { matTricksList.Clear(); } System.Windows.Forms.Application.DoEvents(); matTricksList = MatParser.parse(file_name, ref fileContent); foreach (object obj in matTricksList) { System.Windows.Forms.Application.DoEvents(); MatTrick mt = (MatTrick)obj; if (!mt.deleted) { buildMatBtn(mt.name, mt); } } if (matListCmboBx.Items.Count > 0) { System.Windows.Forms.Application.DoEvents(); System.Windows.Forms.Application.DoEvents(); buildMatProperties(); matListCmboBx.SelectedItem = matListCmboBx.Items[0]; matListCmboBx_SelectionChangeCommitted(matListCmboBx, new EventArgs()); } else { string fName = System.IO.Path.GetFileName(fileName); string warning = string.Format("\"{0}\" is not a Material Trick File.\r\nIt dose not contain (Texture X_...End) block.\r\n", fName); //MessageBox.Show(warning); rTextBox.SelectionColor = Color.Red; rTextBox.SelectedText += warning; dupMatBtn.Enabled = false; deleteMatBtn.Enabled = false; renameMatBtn.Enabled = false; } System.Windows.Forms.Application.DoEvents(); wia.Close(); wia.Dispose(); this.Cursor = Cursors.Arrow; }