public static AABB surrounding_box(AABB box0, AABB box1) { Vec3 small = new Vec3(XMath.Min(box0.min.x, box1.min.x), XMath.Min(box0.min.y, box1.min.y), XMath.Min(box0.min.z, box1.min.z)); Vec3 big = new Vec3(XMath.Max(box0.max.x, box1.max.x), XMath.Max(box0.max.y, box1.max.y), XMath.Max(box0.max.z, box1.max.z)); return(new AABB(small, big)); }
// https://developer.download.nvidia.com/cg/atan2.html public static float Atan2(float y, float x) { float t0, t1, t3, t4; t3 = XMath.Abs(x); t1 = XMath.Abs(y); t0 = XMath.Max(t3, t1); t1 = XMath.Min(t3, t1); t3 = 1f / t0; t3 = t1 * t3; t4 = t3 * t3; t0 = -0.013480470f; t0 = t0 * t4 + 0.057477314f; t0 = t0 * t4 - 0.121239071f; t0 = t0 * t4 + 0.195635925f; t0 = t0 * t4 - 0.332994597f; t0 = t0 * t4 + 0.999995630f; t3 = t0 * t3; t3 = (XMath.Abs(y) > XMath.Abs(x)) ? 1.570796327f - t3 : t3; t3 = (x < 0) ? 3.141592654f - t3 : t3; t3 = (y < 0) ? -t3 : t3; return(t3); }
public void CopyFrom( AcceleratorStream stream, T[][][] source, Index3 sourceOffset, Index3 targetOffset, Index3 extent) { if (extent.X < 0 || extent.Y < 0 || extent.Z < 0 || extent.X > source.Length) { throw new ArgumentOutOfRangeException(nameof(extent)); } if (sourceOffset.X < 0 || sourceOffset.Y < 0 || sourceOffset.Z < 0 || sourceOffset.X >= extent.X || sourceOffset.Y >= extent.Y || sourceOffset.Z >= extent.Z) { throw new ArgumentOutOfRangeException(nameof(sourceOffset)); } var tempBuffer = new T[extent.Size]; for (int i = 0; i < extent.X; ++i) { var subData = source[i + sourceOffset.X]; if (subData == null) { continue; } for (int j = 0; j < extent.Y; ++j) { var subSubData = subData[j + sourceOffset.Y]; if (subSubData == null) { continue; } // Skip entries that are out of bounds for (int k = 0, e = XMath.Min(subSubData.Length, extent.Z); k < e; ++k) { var targetIdx = new Index3(i, j, k).ComputeLinearIndex(extent); tempBuffer[targetIdx] = subSubData[k + sourceOffset.Z]; } } } buffer.CopyFrom( stream, tempBuffer, 0, targetOffset, extent.Size); }
public static void CorrelationMap(Index2 index, ArrayView3D <float> result, ArrayView3D <byte> bufIn) { if (index.X == bufIn.Width - 1 || index.X == 0 || index.Y == bufIn.Height - 1 || index.Y == 0) { result[index.X, index.Y, 0] = 1.0f; result[index.X, index.Y, 1] = 1.0f; result[index.X, index.Y, 2] = 1.0f; return; } var corrX = (float)XMath.Abs(Kernels.PearsonCorrelation(bufIn, new Index2(index.X - 1, index.Y), new Index2(index.X + 1, index.Y))); var corrY = (float)XMath.Abs(Kernels.PearsonCorrelation(bufIn, new Index2(index.X, index.Y - 1), new Index2(index.X, index.Y + 1))); result[index.X, index.Y, 0] = ((1.0f - corrX)); result[index.X, index.Y, 1] = (XMath.Sqrt(XMath.Pow(1.0f - corrX, 2) + XMath.Pow(1.0f - corrY, 2))); result[index.X, index.Y, 2] = ((1.0f - XMath.Min(corrX, corrY))); }
public bool hit(Ray ray, float tMin, float tMax) { float minV = (min.x - ray.a.x) / ray.b.x; float maxV = (max.x - ray.a.x) / ray.b.x; float t1 = XMath.Max(minV, maxV); float t0 = XMath.Min(minV, maxV); tMin = XMath.Max(t0, tMin); tMax = XMath.Min(t1, tMax); if (tMax <= tMin) { return(false); } minV = (min.y - ray.a.y) / ray.b.y; maxV = (max.y - ray.a.y) / ray.b.y; t1 = XMath.Max(minV, maxV); t0 = XMath.Min(minV, maxV); tMin = XMath.Max(t0, tMin); tMax = XMath.Min(t1, tMax); if (tMax <= tMin) { return(false); } minV = (min.z - ray.a.z) / ray.b.z; maxV = (max.z - ray.a.z) / ray.b.z; t1 = XMath.Max(minV, maxV); t0 = XMath.Min(minV, maxV); tMin = XMath.Max(t0, tMin); tMax = XMath.Min(t1, tMax); if (tMax <= tMin) { return(false); } return(true); }
public static void BuildCorrelationMap(Index2 index, ArrayView2D <double> result, ArrayView2D <double> bufIn1, ArrayView2D <double> bufIn2, ArrayView2D <double> bufIn3, ArrayView2D <double> bufIn4) { result[index] = XMath.Min(XMath.Min(XMath.Min(bufIn1[index], bufIn2[index]), bufIn3[index]), bufIn4[index]); }