public static IEnumerator FindTrianglesCoroutine(ResultsCallback callback, float maxSecondsPerFrame, OrientedBoundingBox obb, Vector3[] meshVerts, int[] triangleIndices, Transform meshTransform) { float t0 = Time.realtimeSinceStartup; int[] indices = triangleIndices; int expectedNumIntersecting = Math.Max(1, indices.Length / 10); // assume 10% will intersect List <int> intersectingTriangles = new List <int>(expectedNumIntersecting); Vector3 boxcenter = Vector3.zero; // OBB is symmetric about its center point Vector3 boxhalfsize = obb.Extents; // Gross test using AABB Bounds aabb = ComputeAABB(obb); if (!aabb.Intersects(meshTransform.gameObject.GetComponent <Renderer>().bounds)) { callback(intersectingTriangles); yield break; } // Rotate the mesh into OBB-local space so we can perform axis-aligned // testing (because the OBB then becomes an AABB in its local space). Vector3[] verts = new Vector3[meshVerts.Length]; for (int i = 0; i < meshVerts.Length; i++) { // Transform mesh: 1) mesh local -> world, 2) world -> OBB local Vector3 worldVertex = meshTransform.TransformPoint(meshVerts[i]); verts[i] = TransformWorldToOBB(worldVertex, obb);// obb.transform.InverseTransformPoint(worldVertex); if (Time.realtimeSinceStartup - t0 >= maxSecondsPerFrame) { yield return(null); t0 = Time.realtimeSinceStartup; } } // Test each triangle in the mesh for (int i = 0; i < indices.Length; i += 3) { int i0 = indices[i + 0]; int i1 = indices[i + 1]; int i2 = indices[i + 2]; if (TriangleBoxTest(boxcenter, boxhalfsize, verts[i0], verts[i1], verts[i2])) { intersectingTriangles.Add(i0); intersectingTriangles.Add(i1); intersectingTriangles.Add(i2); } if (Time.realtimeSinceStartup - t0 >= maxSecondsPerFrame) { yield return(null); t0 = Time.realtimeSinceStartup; } } // Pass result to caller callback(intersectingTriangles); }
public void populateTable(ResultContainer results) { if (results != null) { //it will be null if the user cancelled the operation prematurely. if (this.totalwords.InvokeRequired) { // It's on a different thread, so use Invoke. ResultsCallback d = new ResultsCallback(ResultsDisplay); this.Invoke(d, new object[] { results }); } else { // It's on the same thread, no need for Invoke Dictionary<String, int> frequencies = results.Frequencies; int wordcount = results.Wordcount; //Related information totalwords.Text = "Total Word Count: " + wordcount; uniquewords.Text = "Unique Word Count: " + frequencies.Count; var ordered_results = from k in frequencies.Keys orderby frequencies[k] descending select k; double previous_frequency = 0; foreach (string key in ordered_results) { double word_frequency = (frequencies[key] / (double)wordcount) * 100; if (word_frequency == previous_frequency) { //Don't display the same percentage over and over again. Just for the first time it appears. resultsbox.Items.Add(key + "\t [" + frequencies[key] + "]"); } else { resultsbox.Items.Add(key + "\t [" + frequencies[key] + ", " + word_frequency.ToString("#0.00") + "%]"); previous_frequency = word_frequency; } } progressBar.Visible = false; progressBar.Value = 0; calcLabel.Visible = false; totalwords.Visible = true; uniquewords.Visible = true; resultsbox.Visible = true; recalculatebutton.Text = "Re-calculate"; calculating = false; } } }
public void populateTable(ResultContainer results) { if (results != null) { //it will be null if the user cancelled the operation prematurely. if (this.totalwords.InvokeRequired) { // It's on a different thread, so use Invoke. ResultsCallback d = new ResultsCallback(ResultsDisplay); this.Invoke(d, new object[] { results }); } else { // It's on the same thread, no need for Invoke Dictionary <String, int> frequencies = results.Frequencies; int wordcount = results.Wordcount; //Related information totalwords.Text = "Total Word Count: " + wordcount; uniquewords.Text = "Unique Word Count: " + frequencies.Count; var ordered_results = from k in frequencies.Keys orderby frequencies[k] descending select k; double previous_frequency = 0; foreach (string key in ordered_results) { double word_frequency = (frequencies[key] / (double)wordcount) * 100; if (word_frequency == previous_frequency) { //Don't display the same percentage over and over again. Just for the first time it appears. resultsbox.Items.Add(key + "\t [" + frequencies[key] + "]"); } else { resultsbox.Items.Add(key + "\t [" + frequencies[key] + ", " + word_frequency.ToString("#0.00") + "%]"); previous_frequency = word_frequency; } } progressBar.Visible = false; progressBar.Value = 0; calcLabel.Visible = false; totalwords.Visible = true; uniquewords.Visible = true; resultsbox.Visible = true; recalculatebutton.Text = "Re-calculate"; calculating = false; } } }
public static bool Request(Method method, string uri, string parameters, ResultsCallback callback) { requestParameters = parameters; // Used in post callback requestCallback = callback; // Used in response callback try { if (!App.networkService.IsNetworkAvailable()) return false; // if (requestInProgress) return false; // requestInProgress = true; HttpWebRequest httpReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(uri)); httpReq.CookieContainer = cookieJar; httpReq.Accept = "application/json"; if (Method.Post == method) { httpReq.Method = "POST"; // Asynchronously get stream for post data httpReq.BeginGetRequestStream(new AsyncCallback(PostCallback), httpReq); } else { httpReq.Method = "GET"; // Todo: Do we need to set if it's a GET? } } catch (WebException e) { System.Diagnostics.Debug.WriteLine("Exception Message " + e.Message); System.Diagnostics.Debug.WriteLine("Exception Data " + e.Data); requestInProgress = false; return false; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception Message " + e.Message); System.Diagnostics.Debug.WriteLine("Exception Data " + e.Data); requestInProgress = false; return false; } System.Diagnostics.Debug.WriteLine("Request completed: " + callback.ToString()); return true; }
////This method will invoke the search and add the resuls to the ClaimSearchRow collection binded to the view. public virtual void GetResults(SearchRequest request, ResultsCallback callback) { this._searchService.InvokeSearch(this._appModel.UserProfile.Culture, this._appModel.UserProfile.LanguageId, CLAIMS_SEARCH_SP_NAME, this.BuildSearchCriteria(request), (searchData) => { ObservableCollection<ISearchRow> nameRows = searchData.SearchResultRowList.Transform<SearchResultRow, ISearchRow>((row) => { GeniusX.AXA.FrontendModules.Claims.Search.Model.AXAClaimSearchRow riskRow = new GeniusX.AXA.FrontendModules.Claims.Search.Model.AXAClaimSearchRow(row); riskRow.ViewUniqueId = this._searchTypeName + "Preview"; return riskRow; }); callback(new DefaultSearchResult(request.RecordIndex, searchData.TotalRecords, nameRows)); }); }