public void Swap(int a, int b) { CompressedPhoton ab = store[a]; store[a] = store[b]; store[b] = ab; }
public void Store(CompressedPhoton a) { bBoxMax = new PhotonVector3(a.Position.X < bBoxMax.X ? bBoxMax.X : a.Position.X, a.Position.Y < bBoxMax.Y ? bBoxMax.Y : a.Position.Y, a.Position.Z < bBoxMax.Z ? bBoxMax.Z : a.Position.Z); bBoxMin = new PhotonVector3(a.Position.X > bBoxMin.X ? bBoxMin.X : a.Position.X, a.Position.Y > bBoxMin.Y ? bBoxMin.Y : a.Position.Y, a.Position.Z > bBoxMin.Z ? bBoxMin.Z : a.Position.Z); //store.Add(a); AddPhoton(a); }
public void Store(Photon photon) { CompressedPhoton a = new CompressedPhoton(); if (photon.position != PhotonVector3.Empty) { a.position[0] = photon.position[0]; a.position[1] = photon.position[1]; a.position[2] = photon.position[2]; for (int x = 0; x < 3; x++) { a.Power[x] = photon.Power[x]; } int theta = (int)(Math.Acos(photon.Direction[2]) * (256 / Math.PI)); if (theta > 255) { a.Theta = 255; } else { a.Theta = (byte)theta; } int phi = (int)(Math.Atan2(photon.Direction[1], photon.Direction[0]) * (256 / Math.PI)); if (phi > 255) { a.Phi = 255; } else { a.Phi = (byte)phi; } a.Direction = (Vector3)photon.Direction; for (int x = 0; x < 3; x++) { a.Power[x] = photon.Power[x]; } bBoxMax = new PhotonVector3(a.Position.X < bBoxMax.X ? bBoxMax.X : a.Position.X, a.Position.Y < bBoxMax.Y ? bBoxMax.Y : a.Position.Y, a.Position.Z < bBoxMax.Z ? bBoxMax.Z : a.Position.Z); bBoxMin = new PhotonVector3(a.Position.X > bBoxMin.X ? bBoxMin.X : a.Position.X, a.Position.Y > bBoxMin.Y ? bBoxMin.Y : a.Position.Y, a.Position.Z > bBoxMin.Z ? bBoxMin.Z : a.Position.Z); //a.LightmapIndex = photon.LightmapIndex; //a.MaterialIndex = photon.MaterialIndex; if (a == null) { System.Diagnostics.Debugger.Break(); } //this.store.Add(a); AddPhoton(a); } else { System.Diagnostics.Debugger.Break(); } }
private void AddPhoton(CompressedPhoton photon) { if (storeIndex >= store.Length) { Array.Resize(ref store, store.Length + ResizeStep); } store[storeIndex++] = photon; }
public static void DownHeap(CompressedPhoton[] a, int v, int n, int axis) { int w = 2 * v + 1; // first descendant of v if (a[v] == null) { a[v] = new CompressedPhoton(); a[v].Position = new PhotonVector3(float.MaxValue, float.MaxValue, float.MaxValue); } while (w < n) { if (a[w] == null) { a[w] = new CompressedPhoton(); a[w].Position = new PhotonVector3(float.MaxValue, float.MaxValue, float.MaxValue); } if (w + 1 < n) // is there a second descendant? { if (a[w + 1] == null) { a[w + 1] = new CompressedPhoton(); a[w + 1].position = new PhotonVector3(float.MaxValue, float.MaxValue, float.MaxValue); } if (a[w + 1].position[axis] > a[w].position[axis]) { w++; } } // w is the descendant of v with maximum label if (a[v].position[axis] >= a[w].position[axis]) { return; // v has heap property } // otherwise exchange(a, v, w); // exchange labels of v and w v = w; // continue w = 2 * v + 1; } }
public Node <CompressedPhoton> LoadNodeFromStream(BinaryReader br) { int axis = br.ReadInt32(); if (axis == -1) { return(null); } if ((axis < 0) || (axis > 2)) { throw new IndexOutOfRangeException(); } CompressedPhoton phot = CompressedPhoton.FromStream(br); Node <CompressedPhoton> node = new Node <CompressedPhoton>(phot); AddPhoton(phot); node.Left = LoadNodeFromStream(br); node.Right = LoadNodeFromStream(br); return(node); }
public void AddIfClosest(CompressedPhoton photon, float dist2) { int insertPos = 0; for (; insertPos < index; insertPos++) { if (dist2 < list[insertPos].dist2) { break; // we've found the location this one should be at. } } if (insertPos == index) { if (index < list.Length) { list[index++] = new RetrievedPhoton(photon, dist2); } return; } if (index == list.Length) { return; // the list is fully populated. } int end = index + 1; // start one slot to the right of the last record. // if we can't start there, start at the second to the last entry, overwriting the last one. if (end >= list.Length) { end = list.Length - 1; } index = end + 1; for (int l = end - 1; l >= insertPos; l--) { list[l + 1] = list[l]; } list[insertPos] = new RetrievedPhoton(photon, dist2); }
public void LoadStoreFromStream(BinaryReader br) { string id = new string(br.ReadChars(4)); if (id != "STOR") { return; } int count = br.ReadInt32(); if (count < 0) { return; } store = new CompressedPhoton[count]; storeIndex = 0; for (int x = 0; x < count; x++) { AddPhoton(CompressedPhoton.FromStream(br)); } }
public RetrievedPhoton(CompressedPhoton phtn, float dist) { photonPtr = phtn; dist2 = dist; }
public CompressedPhoton[] SortPhotons(List <CompressedPhoton> photons, Vector3 point, int maxCount) { WrapperPhoton[] array = new WrapperPhoton[(maxCount < photons.Count) ? maxCount : photons.Count]; PhotonVector3 photonPoint = point.ToPhotonVector(); int end = 0; for (int x = 0; x < photons.Count; x++) { float dist = (photons[x].position - photonPoint).ToVector3().LengthSq(); if (end == maxCount) { // insert int y; for (y = 0; y < end; y++) { if (array[y].dist2 > dist) { break; } } if (y >= end) { continue; } WrapperPhoton tempA, tempB; tempB = new WrapperPhoton(); tempB.p = photons[x]; tempB.dist2 = dist; for (y++; y < end; y++) { tempA = array[y]; array[y] = tempB; tempB = tempA; } } else if (end == 0) { array[end] = new WrapperPhoton(); array[end].dist2 = dist; array[end].p = photons[x]; end++; } else { int y; for (y = 0; y < end; y++) { if (array[y].dist2 > dist) { break; } } if (y >= end) { if (end != maxCount) { array[end] = new WrapperPhoton(); array[end].dist2 = dist; array[end].p = photons[x]; end++; } continue; } WrapperPhoton tempA, tempB; tempB = new WrapperPhoton(); tempB.p = photons[x]; tempB.dist2 = dist; for (y++; y < end; y++) { tempA = array[y]; array[y] = tempB; tempB = tempA; } if (end != maxCount) { array[end] = tempB; end++; } } } CompressedPhoton[] result = new CompressedPhoton[end]; for (int x = 0; x < end; x++) { result[x] = array[x].p; } array = null; //photons.Clear(); return(result); }