public List <Particle> Update(IValueFastIn field, int sx, int sy) { List <Particle> alive = new List <Particle>(); if (this.particles.Count > 0) { LinkedListNode <Particle> current = this.particles.First; while (current != null) { bool err = false; try { int cellx = GetIndexX(current.Value.PositionX, sx); int celly = GetIndexY(current.Value.PositionY, sy); int cell = celly * sx + cellx; double dblvx, dblvy; field.GetValue2D(cell, out dblvx, out dblvy); if (current.Value.Update(this.dtage, this.dtvelocity, dblvx, dblvy)) { LinkedListNode <Particle> next = current.Next; current.List.Remove(current); current = next; } else { alive.Add(current.Value); current = current.Next; } } catch { LinkedListNode <Particle> next = current.Next; current.List.Remove(current); current = next; } } } return(alive); }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { double width; FPinWidth.GetValue(0, out width); double height; FPinHeight.GetValue(0, out height); // if something changed, recreate Trafo if (FInputGridFrom.PinIsChanged || FInputGridTo.PinIsChanged || width != FWidth || height != FHeight) { // prepare GridTransformer FTrafo = new GridTransformer(); int i, j; Point2D p1, p2, p3; FWidth = (int)width; FHeight = (int)height; // check Input ranges FBufSize = (int)height * (int)width * 2; if (FInputGridFrom.SliceCount != FBufSize || FInputGridTo.SliceCount != FBufSize) { return; } // loop through points and create triangles for (i = 0; i < FHeight - 1; ++i) { for (j = 0; j < FWidth - 1; ++j) { int index = j + i * FWidth; // upper triangle FInputGridFrom.GetValue2D(index, out p1.x, out p1.y); FInputGridFrom.GetValue2D(index + 1, out p2.x, out p2.y); FInputGridFrom.GetValue2D(index + FWidth, out p3.x, out p3.y); Triangle triFrom1 = new Triangle(p1, p2, p3); FInputGridTo.GetValue2D(index, out p1.x, out p1.y); FInputGridTo.GetValue2D(index + 1, out p2.x, out p2.y); FInputGridTo.GetValue2D(index + FWidth, out p3.x, out p3.y); Triangle triTo1 = new Triangle(p1, p2, p3); FTrafo.Insert(triFrom1, triTo1); // lower triangle FInputGridFrom.GetValue2D(index + 1, out p1.x, out p1.y); FInputGridFrom.GetValue2D(index + FWidth, out p2.x, out p2.y); FInputGridFrom.GetValue2D(index + FWidth + 1, out p3.x, out p3.y); Triangle triFrom2 = new Triangle(p1, p2, p3); FInputGridTo.GetValue2D(index + 1, out p1.x, out p1.y); FInputGridTo.GetValue2D(index + FWidth, out p2.x, out p2.y); FInputGridTo.GetValue2D(index + FWidth + 1, out p3.x, out p3.y); Triangle triTo2 = new Triangle(p1, p2, p3); FTrafo.Insert(triFrom2, triTo2); } } } /////////////////////////////////////////////////////// // do transformation // prepare data int sliceCount = FInputPoints.SliceCount; Point2D pIn, pOut; List <Point2D> pList = new List <Point2D>(); int[] hitter; hitter = new int[sliceCount / 2]; int number = (sliceCount / 2); // loop throug input points and calc Transformation for (int i = 0; i < sliceCount / 2; ++i) { FInputPoints.GetValue2D(i, out pIn.x, out pIn.y); if (FTrafo.Transform(pIn, out pOut)) // inside ? { pList.Add(pOut); hitter[i] = 1; } else { hitter[i] = 0; } } // set final slicecount FOutputPoints.SliceCount = pList.Count * 2; FOutputHit.SliceCount = number; // set output for (int i = 0; i < pList.Count; ++i) { FOutputPoints.SetValue2D(i, pList[i].x, pList[i].y); FOutputHit.SetValue(i, hitter[i]); } for (int i = 0; i < number; ++i) { FOutputHit.SetValue(i, hitter[i]); } }