private void Subdivide() { Vector3 oppositeBound = bound1 - bound0; Vector3 offset; // Creating the sub-cubes. for (int i = 0; i < 8; i++) { offset = GetOffset(bound0, oppositeBound, i); children[i] = new AtomTree(bound0 + offset, split + offset); } // Sending the atoms (and corresponding types) to the correct sub-cubes. int childIndex; for (int i = 0; i < MAX_ATOMS; i++) { childIndex = GetChildIndex(positions[i]); children[childIndex].AddAtomToLeaf(positions[i], types[i], colors[i]); } // Now this cube is not a leaf anymore, but a node. // It must be cleared, and no more atoms should be added to it. positions.Clear(); types.Clear(); colors.Clear(); isLeaf = false; }
private AtomTree GetOptimalChild(Vector3 pos) { AtomTree optimal = null; float minDist = float.MaxValue; float dist; foreach (AtomTree child in children) { if (!child.IsEmpty()) { dist = Vector3.SqrMagnitude(child.split - pos); //dist = Vector3.Distance(child.split, pos); if (dist < minDist) { minDist = dist; optimal = child; } } } return(optimal); }
public void SubGetClosestAtomColor(Vector3 pos) { Debug.Log("isLeaf " + isLeaf); Debug.Log("Taille colors " + colors.Count); Debug.Log("Positions " + positions.Count); if (isLeaf) { float dist; for (int i = 0; i < positions.Count; i++) { dist = Vector3.SqrMagnitude(pos - positions[i]); if (dist < candidateDist) { candidateDist = dist; candidateCol = colors[i]; // candidatePos = positions[i]; } } } return; // If the function has not returned yet, then this is a node, not a leaf. // So we just find the correct sub-cube for the recursive call. int childIndex = GetChildIndex(pos); AtomTree optChild = children[childIndex]; if (optChild.isLeaf) { foreach (AtomTree child in children) { child.SubGetClosestAtomColor(pos); } } else { optChild.SubGetClosestAtomColor(pos); } }
public void InitTree() { surfaceObjs = GameObject.FindGameObjectsWithTag("SurfaceManager"); Debug.Log("Init tree"); bTime = Time.realtimeSinceStartup; atomTree = AtomTree.Build(); /* * List<AtomModel> atomModels = MoleculeModel.atomsTypelist; * List<float[]> atomLocations = MoleculeModel.atomsLocationlist; * * locations = new List<Vector3>(); * types = new List<string>(); * * for(int i=0; i<atomModels.Count; i++) { * string type = atomModels[i].type; * Vector3 pos = new Vector3(atomLocations[i][0], atomLocations[i][1], atomLocations[i][2]); * * locations.Add(pos); * types.Add(type); * } */ }
public void BuildTree(string input, AtomTree expectedTree) { var resultTree = _atomTreeBuilder.Build(input); resultTree.ShouldBe(expectedTree); }
public static AtomTree Build() { //List<string> typeList = new List<string>(); //List<Vector3> posList = new List<Vector3>(); AtomTree atomTree = new AtomTree(MoleculeModel.MinValue, MoleculeModel.MaxValue); List <AtomModel> atomModels = MoleculeModel.atomsTypelist; List <string> atomChain = MoleculeModel.atomsChainList; List <float[]> atomLocations = MoleculeModel.atomsLocationlist; List <string> atomResname = MoleculeModel.atomsResnamelist; List <float> BfactorList = MoleculeModel.BFactorList; List <int> atomsNumberList = MoleculeModel.atomsNumberList; int nbres = 0; string type; System.Diagnostics.Debug.Assert(atomModels.Count == atomLocations.Count); //System.Diagnostics.Debug.Assert(atomChain.Count == atomLocations.Count); for (int i = 0; i < atomModels.Count; i++) { //for(int i=0; i<atomChain.Count; i++) { //string type = atomModels[i].type; if (UI.UIData.surfColChain && !UI.UIData.surfColHydroKD) { if (i > 0 && atomResname[i] != atomResname[i - 1]) { nbres++; } if (i > 0 && atomChain[i] != atomChain[i - 1]) { nbres = 1; } // Coloration by domains (only for GLIC) if (nbres > 182 && UI.UIData.isGLIC) { type = atomChain[i] + "L"; } else { type = atomChain[i]; } } else if ((UI.UIData.surfColHydroKD || UI.UIData.surfColPChim || UI.UIData.surfColHydroEng || UI.UIData.surfColHydroEis || UI.UIData.surfColHydroWO) && !UI.UIData.surfColChain) { type = atomResname[i]; } else if (UI.UIData.surfColBF) { type = BfactorList[i].ToString(); } else if (UI.UIData.spread_tree) // For Spreading when camera near the structure { type = atomsNumberList[i].ToString(); } else { type = atomModels[i].type; } Vector3 pos = new Vector3(atomLocations[i][0], atomLocations[i][1], atomLocations[i][2]); //typeList.Add(type); //posList.Add(pos); Color col = MoleculeModel.atomsColorList[i]; atomTree.AddAtom(pos, type, col); } return(atomTree); }