static public VISIBILTY GetVisibility(Vector4d[] frustumPlanes, Box3d box) { VISIBILTY v0 = GetVisibility(frustumPlanes[0], box); if (v0 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } VISIBILTY v1 = GetVisibility(frustumPlanes[1], box); if (v1 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } VISIBILTY v2 = GetVisibility(frustumPlanes[2], box); if (v2 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } VISIBILTY v3 = GetVisibility(frustumPlanes[3], box); if (v3 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } VISIBILTY v4 = GetVisibility(frustumPlanes[4], box); if (v4 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } if (v0 == VISIBILTY.FULLY && v1 == VISIBILTY.FULLY && v2 == VISIBILTY.FULLY && v3 == VISIBILTY.FULLY && v4 == VISIBILTY.FULLY) { return VISIBILTY.FULLY; } return VISIBILTY.PARTIALLY; }
static VISIBILTY GetVisibility(Vector4d clip, Box3d box) { double x0 = box.xmin * clip.x; double x1 = box.xmax * clip.x; double y0 = box.ymin * clip.y; double y1 = box.ymax * clip.y; double z0 = box.zmin * clip.z + clip.w; double z1 = box.zmax * clip.z + clip.w; double p1 = x0 + y0 + z0; double p2 = x1 + y0 + z0; double p3 = x1 + y1 + z0; double p4 = x0 + y1 + z0; double p5 = x0 + y0 + z1; double p6 = x1 + y0 + z1; double p7 = x1 + y1 + z1; double p8 = x0 + y1 + z1; if(p1 <= 0 && p2 <= 0 && p3 <= 0 && p4 <= 0 && p5 <= 0 && p6 <= 0 && p7 <= 0 && p8 <= 0) { return VISIBILTY.INVISIBLE; } if (p1 > 0 && p2 > 0 && p3 > 0 && p4 > 0 && p5 > 0 && p6 > 0 && p7 > 0 && p8 > 0) { return VISIBILTY.FULLY; } return VISIBILTY.PARTIALLY; }
/** * Returns the visibility of a bounding box in local space, in a view * frustum defined in deformed space. * * param node a TerrainNode. This is node is used to get the camera position * in local and deformed space with TerrainNode::GetLocalCamera and * TerrainNode::GetDeformedCamera, as well as the view frustum planes * in deformed space with TerrainNode::GetDeformedFrustumPlanes. * param localBox a bounding box in local space. * return the visibility of the bounding box in the view frustum. */ public virtual Frustum.VISIBILTY GetVisibility(TerrainNode node, Box3d localBox) { // localBox = deformedBox, so we can compare the deformed frustum with it return Frustum.GetVisibility(node.GetDeformedFrustumPlanes(), localBox); }
/** * Creates a new TerrainQuad. * * param owner the TerrainNode to which the terrain quadtree belongs. * param parent the parent quad of this quad. * param tx the logical x coordinate of this quad. * param ty the logical y coordinate of this quad. * param ox the physical x coordinate of the lower left corner of this quad. * param oy the physical y coordinate of the lower left corner of this quad. * param l the physical size of this quad. * param zmin the minimum %terrain elevation inside this quad. * param zmax the maximum %terrain elevation inside this quad. */ public TerrainQuad(TerrainNode owner, TerrainQuad parent, int tx, int ty, double ox, double oy, double length, float zmin, float zmax) { m_owner = owner; m_parent = parent; m_level = (m_parent == null) ? 0 : m_parent.GetLevel() + 1; m_tx = tx; m_ty = ty; m_ox = ox; m_oy = oy; m_zmax = zmax; m_zmin = zmin; m_length = length; m_localBox = new Box3d(m_ox, m_ox + m_length, m_oy, m_oy + m_length, m_zmin, m_zmax); }
public override Frustum.VISIBILTY GetVisibility(TerrainNode t, Box3d localBox) { Vector3d2[] deformedBox = new Vector3d2[4]; deformedBox[0] = LocalToDeformed(new Vector3d2(localBox.xmin, localBox.ymin, localBox.zmin)); deformedBox[1] = LocalToDeformed(new Vector3d2(localBox.xmax, localBox.ymin, localBox.zmin)); deformedBox[2] = LocalToDeformed(new Vector3d2(localBox.xmax, localBox.ymax, localBox.zmin)); deformedBox[3] = LocalToDeformed(new Vector3d2(localBox.xmin, localBox.ymax, localBox.zmin)); double a = (localBox.zmax + R) / (localBox.zmin + R); double dx = (localBox.xmax - localBox.xmin) / 2 * a; double dy = (localBox.ymax - localBox.ymin) / 2 * a; double dz = localBox.zmax + R; double f = Math.Sqrt(dx * dx + dy * dy + dz * dz) / (localBox.zmin + R); Vector4d[] deformedFrustumPlanes = t.GetDeformedFrustumPlanes(); Frustum.VISIBILTY v0 = GetVisibility(deformedFrustumPlanes[0], deformedBox, f); if (v0 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Frustum.VISIBILTY v1 = GetVisibility(deformedFrustumPlanes[1], deformedBox, f); if (v1 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Frustum.VISIBILTY v2 = GetVisibility(deformedFrustumPlanes[2], deformedBox, f); if (v2 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Frustum.VISIBILTY v3 = GetVisibility(deformedFrustumPlanes[3], deformedBox, f); if (v3 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Frustum.VISIBILTY v4 = GetVisibility(deformedFrustumPlanes[4], deformedBox, f); if (v4 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } Vector3d2 c = t.GetDeformedCameraPos(); double lSq = c.SqrMagnitude(); double rm = R + Math.Min(0.0, localBox.zmin); double rM = R + localBox.zmax; double rmSq = rm * rm; double rMSq = rM * rM; Vector4d farPlane = new Vector4d(c.x, c.y, c.z, Math.Sqrt((lSq - rmSq) * (rMSq - rmSq)) - rmSq); Frustum.VISIBILTY v5 = GetVisibility(farPlane, deformedBox, f); if (v5 == Frustum.VISIBILTY.INVISIBLE) { return Frustum.VISIBILTY.INVISIBLE; } if (v0 == Frustum.VISIBILTY.FULLY && v1 == Frustum.VISIBILTY.FULLY && v2 == Frustum.VISIBILTY.FULLY && v3 == Frustum.VISIBILTY.FULLY && v4 == Frustum.VISIBILTY.FULLY && v5 == Frustum.VISIBILTY.FULLY) { return Frustum.VISIBILTY.FULLY; } return Frustum.VISIBILTY.PARTIALLY; }
/** * Returns the distance in local (i.e., source) space between a point and a * bounding box. * * param localPt a point in local space. * param localBox a bounding box in local space. */ public virtual double GetLocalDist(Vector3d2 localPt, Box3d localBox) { return Math.Max(Math.Abs(localPt.z - localBox.zmax), Math.Max(Math.Min(Math.Abs(localPt.x - localBox.xmin), Math.Abs(localPt.x - localBox.xmax)), Math.Min(Math.Abs(localPt.y - localBox.ymin), Math.Abs(localPt.y - localBox.ymax)))); }
//Returns the bounding box containing this box and the given box. public Box3d Enlarge(Box3d r) { return(new Box3d(System.Math.Min(xmin, r.xmin), System.Math.Max(xmax, r.xmax), System.Math.Min(ymin, r.ymin), System.Math.Max(ymax, r.ymax), System.Math.Min(zmin, r.zmin), System.Math.Max(zmax, r.zmax))); }
//Returns the bounding box containing this box and the given box. public Box3d Enlarge(Box3d r) { return new Box3d( System.Math.Min(xmin, r.xmin), System.Math.Max(xmax, r.xmax), System.Math.Min(ymin, r.ymin), System.Math.Max(ymax, r.ymax), System.Math.Min(zmin, r.zmin), System.Math.Max(zmax, r.zmax)); }
public ParticlesFromBounds(double spacing, Box3d bounds, Box3d exclusion) : base(spacing) { Bounds = bounds; CreateParticles(exclusion); }
/// <summary></summary> public PointFileInfo(string fileName, PointCloudFileFormat format, long fileSizeInBytes, long pointCount, Box3d bounds) { FileName = fileName; Format = format; FileSizeInBytes = fileSizeInBytes; PointCount = pointCount; Bounds = bounds; }
public ParticlesFromBounds(double spacing, Box3d bounds) : base(spacing) { Bounds = bounds; CreateParticles(); }
public bool ObjectIsInsideBox(int objectIndex, Box3d box) { GetTriangle(objectIndex, out V3d p0, out V3d p1, out V3d p2); return(box.Contains(p0) && box.Contains(p1) && box.Contains(p2)); }
public bool ObjectIntersectsBox(int objectIndex, Box3d box) { GetTriangle(objectIndex, out V3d p0, out V3d p1, out V3d p2); return(box.IntersectsTriangle(p0, p1, p2)); }
static Box3d Transform4(Box3d box, M44d trafo) { //if (!box.IsValid) return Box3d.Invalid; //if (box.IsInvalid) return Box3d.Invalid; var t = new V3d(trafo.M03, trafo.M13, trafo.M23); var res = new Box3d(t, t); // unrolled double av, bv; av = trafo.M00 * box.Min.X; bv = trafo.M00 * box.Max.X; if (av < bv) { res.Min.X += av; res.Max.X += bv; } else { res.Min.X += bv; res.Max.X += av; } av = trafo.M01 * box.Min.Y; bv = trafo.M01 * box.Max.Y; if (av < bv) { res.Min.X += av; res.Max.X += bv; } else { res.Min.X += bv; res.Max.X += av; } av = trafo.M02 * box.Min.Z; bv = trafo.M02 * box.Max.Z; if (av < bv) { res.Min.X += av; res.Max.X += bv; } else { res.Min.X += bv; res.Max.X += av; } av = trafo.M10 * box.Min.X; bv = trafo.M10 * box.Max.X; if (av < bv) { res.Min.Y += av; res.Max.Y += bv; } else { res.Min.Y += bv; res.Max.Y += av; } av = trafo.M11 * box.Min.Y; bv = trafo.M11 * box.Max.Y; if (av < bv) { res.Min.Y += av; res.Max.Y += bv; } else { res.Min.Y += bv; res.Max.Y += av; } av = trafo.M12 * box.Min.Z; bv = trafo.M12 * box.Max.Z; if (av < bv) { res.Min.Y += av; res.Max.Y += bv; } else { res.Min.Y += bv; res.Max.Y += av; } av = trafo.M20 * box.Min.X; bv = trafo.M20 * box.Max.X; if (av < bv) { res.Min.Z += av; res.Max.Z += bv; } else { res.Min.Z += bv; res.Max.Z += av; } av = trafo.M21 * box.Min.Y; bv = trafo.M21 * box.Max.Y; if (av < bv) { res.Min.Z += av; res.Max.Z += bv; } else { res.Min.Z += bv; res.Max.Z += av; } av = trafo.M22 * box.Min.Z; bv = trafo.M22 * box.Max.Z; if (av < bv) { res.Min.Z += av; res.Max.Z += bv; } else { res.Min.Z += bv; res.Max.Z += av; } return(res); }
public static void GetDoublev(uint pname, out Box3d data) { m_GetDoublev_9(pname, out data); if(m_debug) CheckError("GetDoublev"); }