public static Slice[] ProcessSlices(string dicomfilepath) { string[] dicomfilenames = Directory.GetFiles(dicomfilepath, "*.IMA"); int numSlices = dicomfilenames.Length; Slice[] slices = new Slice[numSlices]; float max = -1; float min = 99999; for (int i = 0; i < numSlices; i++) { string filename = dicomfilenames[i]; slices[i] = new Slice(filename); SliceInfo info = slices[i].sliceInfo; if (info.LargestImagePixelValue > max) { max = info.LargestImagePixelValue; } if (info.SmallestImagePixelValue < min) { min = info.SmallestImagePixelValue; } // Del dataen på max før den settes inn i tekstur // alternativet er å dele på 2^dicombitdepth, men det ville blitt 4096 i dette tilfelle } Array.Sort(slices); return(slices); }
private void HandleSlice(List <BoxCollider> colliders, int targetCount) { if (colliders.Count <= 0 || colliders.Count / 2 < targetCount) { sliceInfo = SliceInfo.Miss; return; } Debug.Log(colliders.Count / 2 + " Objects cut"); sliceInfo = SliceInfo.Geki; for (int i = 0; i < colliders.Count; i += 2) { var volume1 = colliders[i].bounds.size.x * colliders[i].bounds.size.y * colliders[i].bounds.size.z; var volume2 = colliders[i + 1].bounds.size.x * colliders[i + 1].bounds.size.y * colliders[i + 1].bounds.size.z; var result = volume1 > volume2 ? volume1 / volume2 : volume2 / volume1; if (result > 1.0f + CleanCutThreshold) { Debug.Log("Bad cut, result difference: " + result); sliceInfo = SliceInfo.Katsu; } else { Debug.Log("Clean cut, result difference: " + result); //sliceInfo = SliceInfo.Geki; } } }
private IEnumerator CompleteAnimationAndChangeZoneAndScene(Animator anim, SliceInfo sliceInfo) { yield return(new WaitForSeconds(anim.GetCurrentAnimatorStateInfo(0).length)); UpdateScoreText(); ChangeZoneAndScene(sliceInfo); }
public static void getSlices(string dicomfilepath, int _numSlices, out Slice[] _slices, out float min, out float max) { string[] dicomfilenames; dicomfilenames = Directory.GetFiles(dicomfilepath, "*.IMA"); if (dicomfilenames.Length < 1) { dicomfilenames = Directory.GetFiles(dicomfilepath, "*.ima"); } _numSlices = dicomfilenames.Length; _slices = new Slice[_numSlices]; max = -1; min = 99999; for (int i = 0; i < _numSlices; i++) { string filename = dicomfilenames[i]; _slices[i] = new Slice(filename); _slices[i].getPixels(); SliceInfo sinfo = _slices[i].sliceInfo; if (sinfo.LargestImagePixelValue > max) { max = sinfo.LargestImagePixelValue; } if (sinfo.SmallestImagePixelValue < min) { min = sinfo.SmallestImagePixelValue; } // Hvis largest og smallest ikke fins i dicomfilen så bruk 0 og 2^BitsStored istedet som konservative grenser } Array.Sort(_slices); SliceInfo info = _slices[0].sliceInfo; }
private void AddStripe(int left, int right) { SliceInfo a = Slices[left]; SliceInfo b = Slices[right % TotalSlices]; int lenA = a.VerticesCount; int lenB = b.VerticesCount; int aVerticesOffset = a.FirstVertex; int bVerticesOffset = b.FirstVertex; int aTextureOffset = AddTextureVertices(left, lenA); int bTextureOffset = AddTextureVertices(right, lenB); float max = Math.Max(lenA, lenB); float accA = 0, accB = 0; float stepA = lenA / max, stepB = lenB / max; int indA = 0, indB = 0; int vertexA = aVerticesOffset, vertexB = bVerticesOffset; int textureA = aTextureOffset, textureB = bTextureOffset; List <FaceInfo> faces = new List <FaceInfo>(); while (indA + 1 < lenA || indB + 1 < lenB) { accA += stepA; accB += stepB; if (indA + 1 < lenA && accA >= 1) { accA--; indA++; int newVertex = aVerticesOffset + indA; int newTexture = aTextureOffset + indA; faces.Add(new FaceInfo(new [] { new VertexInfo(vertexA, textureA), new VertexInfo(vertexB, textureB), new VertexInfo(newVertex, newTexture) })); vertexA = newVertex; textureA = newTexture; } if (indB + 1 < lenB && accB >= 1) { accB--; indB++; int newVertex = bVerticesOffset + indB; int newTexture = bTextureOffset + indB; faces.Add(new FaceInfo(new[] { new VertexInfo(vertexA, textureA), new VertexInfo(vertexB, textureB), new VertexInfo(newVertex, newTexture) })); vertexB = newVertex; textureB = newTexture; } } Stripes.Add(faces.ToArray()); }
public static void Slice(SliceInfo sliceInfo, Vector3 start, Vector3 direction, float punch = 1.0f) { SpriteSlicer slicer = sliceInfo.gameObject.AddComponent <SpriteSlicer>(); slicer.sliceInfo = sliceInfo; Transform t = sliceInfo.transform; slicer.start = t.InverseTransformPoint(start); slicer.direction = t.InverseTransformDirection(direction); slicer.punch = punch; }
public async Task <Download <SliceInfo> > DownloadBlockStorageSliceInfo(ChainType chainType, int chainId, uint chainIndex) { try { var data = await DownloadBinary($"dynamic/{GetChainTypeName(chainType)}/{chainId}/{chainIndex}/block/slice/info/result.data"); using (var unpacker = new Unpacker(data)) { var sliceInfo = new SliceInfo(unpacker); return(new Download <SliceInfo>(sliceInfo)); } } catch (Exception exception) { return(Download <SliceInfo> .HandleException(exception)); } }
private void ChangeZoneAndScene(SliceInfo sliceInfo) { if (sliceInfo == SliceInfo.Miss) { gameOverPanel.SetActive(true); finalScoreText.text = "Final score: " + data.Score.ToString(); Time.timeScale = 0.0f; data.CurrentLevel = 0; data.Timer = 0.0f; data.Score = 0; Settings.GlobalTimeScale = 1.0f; waitingForContinue = true; return; } currentZone++; if (currentZone >= PlayerSpawnPositions.Count) { //Go to next scene or loop back to first and increase global timescale var nLevels = Settings.nScenes; //+1 since menu is 0 data.CurrentLevel++; //Loop levels and speedup on loop if (data.CurrentLevel >= nLevels) { //Speedup Settings.GlobalTimeScale += LevelLoopTimeSpeedupFactor; //Go back to first level (scene) data.CurrentLevel = 0; Time.timeScale = 1.0f + Settings.GlobalTimeScale; } SceneManager.LoadScene(data.CurrentLevel + 1); } else { //TODO better transition SliceHandlerZones[currentZone - 1].SetActive(false); SliceHandlerZones[currentZone].SetActive(true); PlayerRef.transform.position = PlayerSpawnPositions[currentZone].transform.position; } }
private void SliceInHalf(SliceInfo slice) { float diffX = slice.End.x - slice.Start.x; float slope = (slice.End.y - slice.Start.y) / (diffX == 0.0f ? 0.001f : diffX); SliceableObject half = Instantiate(this.gameObject).GetComponent <SliceableObject>(); Sprite halfSprite = half.GetComponent <SpriteRenderer>().sprite; Sprite thisSprite = this.GetComponent <SpriteRenderer>().sprite; Texture2D halfTex = (Texture2D)Instantiate(halfSprite.texture); Texture2D thisTex = (Texture2D)Instantiate(thisSprite.texture); int w = halfTex.width; int h = halfTex.height; Color[] halfPixels = halfTex.GetPixels(); Color[] thisPixels = thisTex.GetPixels(); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { if (y - (h / 2) > slope * (x - (w / 2))) { halfPixels[x + y * w] = new Color(0, 0, 0, 0); } else { thisPixels[x + y * w] = new Color(0, 0, 0, 0); } } } halfTex.SetPixels(halfPixels); thisTex.SetPixels(thisPixels); thisTex.Apply(); halfTex.Apply(); half.GetComponent <SpriteRenderer>().sprite = Sprite.Create(halfTex, halfSprite.rect, new Vector2(0.5f, 0.5f)); this.GetComponent <SpriteRenderer>().sprite = Sprite.Create(thisTex, thisSprite.rect, new Vector2(0.5f, 0.5f)); half.GetComponent <Rigidbody2D>().gravityScale = 1.0f; this.GetComponent <Rigidbody2D>().gravityScale = 1.0f; }
public static List <SliceInfo> SliceAll(Vector3 from, Vector3 to, float punch = 1.0f) { List <SliceInfo> hits = new List <SliceInfo>(); Vector3 direction = to - from; foreach (RaycastHit2D hit in Physics2D.LinecastAll(from, to, ~0)) { SliceInfo info = hit.collider.GetComponent <SliceInfo>(); if (info && info.enabled) { hits.Add(info); Slice(info, from, direction, punch); info.DoSlice(); } } return(hits); }
Slice[] processSlices(string dicomfilepath) { string[] dicomfilenames = Directory.GetFiles(dicomfilepath, "*.IMA"); _numSlices = dicomfilenames.Length; Slice[] slices = new Slice[_numSlices]; float max = -1; float min = 99999; for (int i = 0; i < _numSlices; i++) { string filename = dicomfilenames[i]; slices[i] = new Slice(filename); SliceInfo info = slices[i].sliceInfo; if (info.LargestImagePixelValue > max) { max = info.LargestImagePixelValue; } if (info.SmallestImagePixelValue < min) { min = info.SmallestImagePixelValue; } // Del dataen på max før den settes inn i tekstur // alternativet er å dele på 2^dicombitdepth, men det ville blitt 4096 i dette tilfelle } print("Number of slices read:" + _numSlices); print("Max intensity in all slices:" + max); print("Min intensity in all slices:" + min); _minIntensity = (int)min; _maxIntensity = (int)max; //_iso = 0; Array.Sort(slices); return(slices); }
private void LoadDicomData() { if (!_dicomSetLoaded) { Slice.initDicom(); //relative path : string dicomfilepath = Application.dataPath + @"/../dicomdata/"; // Application.dataPath is in the assets folder, but these files are "managed", so we go one level up if (AddPaddingToDicom) { _numSlices = _numSlices = Slice.getnumslices(dicomfilepath) + 2; } else { _numSlices = _numSlices = Slice.getnumslices(dicomfilepath); } _slices = new Slice[_numSlices]; float min = 0; float max = 0; Slice.getSlices(dicomfilepath, _numSlices, out _slices, out min, out max); _info = _slices[0].sliceInfo; _minIntensity = (int)min; _maxIntensity = (int)max; _xdim = _info.Rows; _ydim = _info.Columns; _zdim = _numSlices; print("Number of slices read:" + _numSlices); } else { print("Dicom set already loaded."); } }
public GameObject[] SplitBlock(GameObject blockObject, float offset, bool isHorizontal, Vector3 center) { Block originalBlock = blockObject.GetComponent <Block>(); float slicedSide = isHorizontal ? originalBlock.SideA : originalBlock.SideB; //slice axis of block center, need for correct new blocks position float centerAxis = isHorizontal ? center.x : center.z; SliceInfo sliceInfo = CalculaterNewSlicedParams(offset, slicedSide, centerAxis); Vector3 oldBlockPos = blockObject.transform.position; Vector3 newBlockPos = blockObject.transform.position; Vector3 newBlockSize = new Vector3(originalBlock.SideA, originalBlock.Height, originalBlock.SideB); if (isHorizontal) { originalBlock.SideA = sliceInfo.leftPartLength; oldBlockPos.x = sliceInfo.rightPartPos; newBlockPos.x = sliceInfo.leftPartPos; newBlockSize.x = sliceInfo.rightPartLength; } else { originalBlock.SideB = sliceInfo.leftPartLength; oldBlockPos.z = sliceInfo.rightPartPos; newBlockPos.z = sliceInfo.leftPartPos; newBlockSize.z = sliceInfo.rightPartLength; } //create new block GameObject newBlockObject = CreateBlock(newBlockSize, originalBlock.Color); newBlockObject.name = blockObject.name + "_part"; //set positions blockObject.transform.position = oldBlockPos; newBlockObject.transform.position = newBlockPos; return(new GameObject[] { blockObject, newBlockObject }); }
public SlicedData(SliceInfo[] slices) { this.slices = slices; }
public void copyFrom(SliceInfo info) { this.slicePrefab = info.slicePrefab; this.insideSprite = info.insideSprite; }
public Slice(string filename) { dicomFile = DicomFile.Open(filename); sliceInfo = new SliceInfo(dicomFile); slicePixels = null; // slicePixels remains empty until loadPixels() is called }