/// <summary> /// Generates a random viewpoint position that satisfies the property to some degree, with more probability where /// satisfaction is higher /// </summary> /// <returns>The random satisfying position.</returns> /// <param name="camera">Camera.</param> public override Vector3 GenerateRandomSatisfyingPosition(CLCameraMan camera) { Vector3 result = new Vector3(); bool found = false; Vector2 minMaxDistance = new Vector2(0.1f, 1000f); // just a placeholder; this method should not be used anymore int maxtries = 0; while (!found && maxtries < 30) { maxtries++; float x = satFunction.GenerateRandomXPoint(); // random angle //Debug.Log (x); //x = 0.0f; // generate random distance float distance = minMaxDistance.x + Random.value * (minMaxDistance.y - minMaxDistance.x); // generate random height float height = camera.ComputeRandomViewpoint(3)[1]; if (orientation == OrientationMode.HORIZONTAL) { result.x = Mathf.Sin(Mathf.Deg2Rad * x) * distance; result.z = Mathf.Cos(Mathf.Deg2Rad * x) * distance; result = targets [0].gameObject.transform.TransformPoint(result); result.y = height; } else // VERTICAL // generate a random theta in cilindrical coordinates { float theta = Random.value * 2 * Mathf.PI; float phi = Mathf.Deg2Rad * x; // convert from spherical to cartesian result.x = Mathf.Sin(phi) * Mathf.Cos(theta) * distance; result.y = Mathf.Sin(phi) * Mathf.Sin(theta) * distance; result.z = Mathf.Cos(phi) * distance; result = targets [0].gameObject.transform.TransformPoint(result); } // if we are in problem bounds, ok - otherwise we throw away the point and generate a new one if (camera.InSearchSpace(new float[] { result.x, result.y, result.z })) { found = true; } } if (!found) { float[] randomCandidate = camera.ComputeRandomViewpoint(3); result = new Vector3(randomCandidate[0], randomCandidate[1], randomCandidate[2]); } return(result); }
/// <summary> /// Generates a random viewpoint position that satisfies the property to some degree, with more probability where /// satisfaction is higher /// </summary> /// <returns>The random satisfying position.</returns> /// <param name="camera">Camera.</param> public override Vector3 GenerateRandomSatisfyingPosition(CLCameraMan camera) { Vector3 result = new Vector3(); bool found = false; int maxtries = 0; while (!found && maxtries < 30) { maxtries++; float distance = GenerateRandomSatisfyingDistance(camera ); // check we are outside bs. we don't want to assign candidates inside bs. if (distance > targets [0].radius) { // generate random direction float inclination = (Mathf.PI) * Random.value; float azimuth = Mathf.PI * 2 * Random.value; result.x = distance * Mathf.Sin(azimuth) * Mathf.Sin(inclination); result.y = distance * Mathf.Cos(inclination); result.z = distance * Mathf.Cos(azimuth) * Mathf.Sin(inclination); result = result + targets [0].boundingBox.center; if (camera.InSearchSpace(new float[] { result.x, result.y, result.z })) { found = true; } } } if (!found) { float[] randomCandidate = camera.ComputeRandomViewpoint(3); result = new Vector3(randomCandidate[0], randomCandidate[1], randomCandidate[2]); } return(result); }
/// <summary> /// Check if candidate is in problem search space /// </summary> /// <returns><c>true</c>, if search space was ined, <c>false</c> otherwise.</returns> /// <param name="evaluator">CLCameraMan evaluator</param> /// <param name="checkGeometry">If set to <c>true</c> check geometry.</param> public bool InSearchSpace(CLCameraMan evaluator) { return(evaluator.InSearchSpace(position)); }
// this method generates a random viewpoint with more probability where // target properties will be satisfied. It assumes we have at least a size // property for the target, plus optional angle and occlusion properties public Vector3 GenerateRandomSatisfyingPosition(CLCameraMan camera, bool considerVisibility = false) { Vector3 result = new Vector3(); bool found = false; int ntries = 0; float yFOV = (camera.cameraDomain.yFOVBounds [0] + camera.cameraDomain.yFOVBounds [1]) / 2; // we allow for 30 tries before giving up while (ntries < 30 && !found) { float distance = 0.0f; float phi = 0.0f; float theta = 0.0f; foreach (CLGroundProperty p in groundProperties) { if (p is CLSizeProperty) { CLSizeProperty sp = (CLSizeProperty)p; // this returns a random area, or width, or height, depending on the type of size // property, with more probability where the satisfaction is higher float randomSize = p.satFunction.GenerateRandomXPoint(); if (randomSize < 0.0001f) { randomSize = 0.0001f; // to avoid computing an infinite distance. } // compute distance from target size distance = ComputeDistanceFromSize(randomSize, sp.sizeType, camera, yFOV); } if (p is CLOrientationProperty) { CLOrientationProperty op = (CLOrientationProperty)p; if (op.orientation == CLOrientationProperty.OrientationMode.HORIZONTAL) { phi = Mathf.Deg2Rad * op.satFunction.GenerateRandomXPoint(); // horizontal random angle } else { theta = Mathf.Deg2Rad * op.satFunction.GenerateRandomXPoint(); // vertical random angle } } } // if we are not inside bs sphere if (distance > radius) { result = ComputeWorldPosFromSphericalCoordinates(distance, phi, theta); if (camera.InSearchSpace(new float[] { result.x, result.y, result.z })) { found = true; } } ntries++; } if (!found) { float[] randomCandidate = camera.cameraDomain.ComputeRandomViewpoint(3); result = new Vector3(randomCandidate [0], randomCandidate [1], randomCandidate [2]); //Debug.Log ("random candidate"); } else { //Debug.Log ("smart candidate in " + ntries + " tries"); } return(result); }