void IBufferConsumer.Consume(IRawData buffer) { m_deserilizer.Init(buffer.Buffer); try { var data = m_dataUnpacker.Unpack<IEntryData>(m_deserilizer); if (m_hasNewDefinisions) { TryDequeuPendingItems(); } if (data != null) { if (m_currentPendingIndex != 0) { m_pendingUnpackedObjects.Enqueue(new Tuple<int, IEntryData>(m_currentPendingIndex, data)); m_currentPendingIndex++; } else { m_consumer.Consume(data); } } } catch (UnkownPackageException unkownPackageException) { m_pendingDefinitonQueue.Enqueue(new Tuple<int, int, IRawData>(m_currentPendingIndex, unkownPackageException.PackageId, new CloneRawData(buffer.Buffer, buffer.Length))); m_currentPendingIndex++; } catch (CacheStringNotFoundException cacheStringNotFoundException) { m_pendingDefinitonQueue.Enqueue(new Tuple<int, int, IRawData>(m_currentPendingIndex,cacheStringNotFoundException.Id, new CloneRawData(buffer.Buffer, buffer.Length))); m_currentPendingIndex++; } }
/** * <summary>Applies smooting</summary> * <param name="aRef">Latest raw data</param> * <param name="aAlfa">Alfa</param> * <param name="aTimestamp">New timestamp</param> */ public void shift(IRawData aRef, double aAlfa, ulong aTimestamp) { timestamp = aTimestamp; x = (float)((aRef.x + aAlfa * x) / (1.0 + aAlfa)); y = (float)((aRef.y + aAlfa * y) / (1.0 + aAlfa)); z = (float)Math.Sqrt(1 - x * x - y * y); }
public ActionResult RawData(string id, string piServer, string SegmentDelimiter) { piServer = string.IsNullOrEmpty(piServer) ? Constant.PIPServer : piServer; ViewBag.Message = Constant.RawData; IRawData irawdata = DataAccess.CreateRawData(piServer); string Rslt = irawdata.Get(id, Constant.ContentTypeUTF8).Content; try { if (!string.IsNullOrEmpty(SegmentDelimiter)) { Rslt = Rslt.Replace(SegmentDelimiter, "\r\n"); } } catch (System.Xml.XmlException) { if (!string.IsNullOrEmpty(SegmentDelimiter)) { Rslt = Rslt.Replace(SegmentDelimiter, "\r\n"); } } ViewData["RsltRawdata"] = Rslt; return(View()); }
private List <Point> InnerBFSTraversalInit(Point startPoint, IRawData data) { List <Point> result = new List <Point>(); Queue <Point> toVisit = new Queue <Point>(); Point currentPoint = startPoint; while (true) { result.Add(currentPoint); foreach (Point neighbourPoint in GetNotEmptyNotVisitedNeighbours(currentPoint, data, result, toVisit)) { toVisit.Enqueue(neighbourPoint); } if (toVisit.Count == 0) { break; } currentPoint = toVisit.Dequeue(); } return(result); }
public IEnumerable <IRawData> DifferShape(IRawData data) { List <IRawData> rawShapes = new List <IRawData>(); IRawData currentData = data; data.Save(Environment.CurrentDirectory + "/Output/source"); while (true) { Point firstPoint = FindFirstShape(currentData); if (firstPoint.Equals(INVALID_POINT)) { break; } IEnumerable <(int x, int y)> points = InnerBFSTraversalInit(firstPoint, data).Select(P => (P.X, P.Y)); //int left = points.Min(P => P.x); //int top = points.Min(P => P.y); //int right = points.Max(P => P.x); //int bot = points.Max(P => P.y); rawShapes.Add(currentData.GetCropped(points)); rawShapes.Last().Save(Environment.CurrentDirectory + $"/Output/{firstPoint.X}_{firstPoint.Y}"); currentData.Erase(points); } return(rawShapes); }
protected (int x, int y) FindNext(bool[,] visited, IRawData data) { for (int i = 0; i < data.Height; i++) { if (!visited[i, 0] && !data.IsEmpty(0, i)) { return(0, i); } else if (!visited[i, data.Width - 1] && !data.IsEmpty(data.Width - 1, i)) { return(data.Width - 1, i); } } for (int i = 0; i < data.Width; i++) { if (!visited[0, i] && !data.IsEmpty(i, 0)) { return(i, 0); } else if (!visited[data.Height - 1, i] && !data.IsEmpty(i, data.Height - 1)) { return(i, data.Height - 1); } } return(-1, -1); }
private List <Point> GetNotEmptyNotVisitedNeighbours(Point point, IRawData data, List <Point> visited, Queue <Point> toVisit) { List <Point> notEmptyNotVisitedNeighbours = new List <Point>(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i == 0 && j == 0) { continue; } Point pointShifted = new Point(point.X + j, point.Y + i); if (pointShifted.X < 0 || pointShifted.X >= data.Width || pointShifted.Y < 0 || pointShifted.Y >= data.Height) { continue; } if (data.IsEmpty(pointShifted.X, pointShifted.Y) || visited.Contains(pointShifted) || toVisit.Contains(pointShifted)) { bool x = data.IsEmpty(pointShifted.X, pointShifted.Y); continue; } notEmptyNotVisitedNeighbours.Add(pointShifted); } } return(notEmptyNotVisitedNeighbours); }
/** * <summary>Copies values from another data</summary> * <param name="aRef">Reference to copy from</param> */ public static RawVector copyFrom(IRawData aRef) { RawVector r = (RawVector)aRef; if (r == null) { throw new ArgumentException("Cannot copy from the instance of another type"); } return(new RawVector(r.timestamp, new Vector3(r.x, r.y, r.z))); }
private Point FindFirstShape(IRawData data) { for (int i = 0; i < data.Height; i++) { for (int j = 0; j < data.Width; j++) { if (!data.IsEmpty(j, i)) { return(new Point(j, i)); } } } return(new Point(-1, -1)); }
public void WriteData(IRawData buffer) { if (m_streamProvider.ShouldArchive(m_stream.Length, buffer.Length, buffer.DateTime)) { m_stream.Close(); m_stream.Dispose(); m_streamProvider.Archive(); m_stream = m_streamProvider.GetStream(); m_onNewfileCreated.Invoke(this,m_stream); } m_stream.Write(BitConverter.GetBytes(buffer.Length),0,sizeof(int)); m_stream.Write(buffer.Buffer, 0, buffer.Length); }
public static int Scope(this IRawData rawShape) { int count = 0; for (int i = 0; i < rawShape.Height; i++) { for (int j = 0; j < rawShape.Width; j++) { if (!rawShape.IsEmpty(j, i)) { count++; } } } return(count); }
public static int Perimeter(this IRawData rawShape) { int count = 0; for (int i = 0; i < rawShape.Height; i++) { for (int j = 0; j < rawShape.Width; j++) { if (!rawShape.IsEmpty(j, i) && (j == 0 || i == 0 || j == rawShape.Width - 1 || i == rawShape.Height - 1 || rawShape.IsEmpty(j - 1, i) || rawShape.IsEmpty(j + 1, i) || rawShape.IsEmpty(j, i - 1) || rawShape.IsEmpty(j, i + 1))) { count++; } } } return(count); }
protected List <List <(int x, int y)> > GetAllCountures(IRawData data) { bool[,] visited = new bool[data.Height, data.Width]; (int x, int y)startPoint = FindNext(visited, data); List <List <(int x, int y)> > ways = new List <List <(int x, int y)> >(); while (!startPoint.Equals((-1, -1))) { List <(int x, int y)> way = new List <(int x, int y)>(); ProcessPerimeter(startPoint.x, startPoint.y, data, visited, way, new Queue <(int x, int y)>()); way.RemoveAll(P => P.x != 0 && P.x != data.Width - 1 && P.y != 0 && P.y != data.Height - 1); ways.Add(way); startPoint = FindNext(visited, data); } return(ways); }
public ActionResult Test(string id, string optradio) { optradio = (string.IsNullOrEmpty(optradio)) ? Constant.PIQServer : optradio; ViewBag.Message = "Your function test page."; //IFactory ifactory = DataAccess.CreateRawData(optradio); IRawData irawdata = DataAccess.CreateRawData(optradio); //string Rslt = irawdata.Get().Content; RawData r = irawdata.Get(id, Constant.ContentTypeUTF8); string newurl = r.Url; string Rslt = r.Get(); ViewBag.newUrl = newurl; ViewData["RsltRawdata"] = Rslt; ViewBag.piServer = optradio; return(View()); }
public bool sendMessage(PUBTYPE cmd) { if (type == NetworkType.SUB) { return(false); } if (publisher == null) { return(false); } try { if (typeof(PUBTYPE) == typeof(IRawData)) { Msg msg = new Msg(); IRawData d = (IRawData)(cmd); msg.InitGC(d.Data, d.Data.Length); Console.WriteLine(d.Data.Length); publisher.Send(ref msg, false); } else { //cmd is a command and we serialize it System.IO.MemoryStream ms = new System.IO.MemoryStream(); Serializer.Serialize <PUBTYPE>(ms, cmd); Msg msg = new Msg(); msg.InitGC(ms.ToArray(), (int)ms.Length); publisher.Send(ref msg, false); } } catch (Exception e) { string msg = e.Message; return(false); } return(true); }
public IRawData SetItem(IRawData value, uint id) { value.Id = id; value.Title = $"title {id}"; value.Created = DateTime.Now; value.Note = $"{value.Created:G}"; value.Amount = (id % 2) * 14; value.Max = 360; value.Min = (id % 4) * 5; value.Average = (id % 3) * 2; value.Exp = (id % 6) * 11; var code = 41; code = code * 59 + value.Title.GetHashCode(); code = code * 59 + value.Note.GetHashCode(); value.Info = code.ToString(); return(value); }
public override IShape RecognizeShape(IRawData shape) { double triangleScope = shape.Scope(); double wrapperScope = shape.Width * shape.Height; Triangle result = new Triangle(shape.X, shape.Y, shape.Width, shape.Height, triangleScope); if (Math.Abs(0.5 - triangleScope / wrapperScope) < MAX_DEVIATION) { return(result); } List <List <(int x, int y)> > ways = GetAllCountures(shape); bool isRectTriangle = ways.Count == 1 && Math.Abs(1 - (double)ways.First().Count / (shape.Width + shape.Height)) <= MAX_DEVIATION; bool twoSidesTouchTriangle = ways.Count == 2 && (ways.First().Count <= PIN_MAX || ways.Last().Count <= PIN_MAX); bool threePinsTriangle = ways.Count == 3 && ways.All(W => W.Count <= PIN_MAX); return(isRectTriangle || twoSidesTouchTriangle || threePinsTriangle ? result : null); }
public override IShape RecognizeShape(IRawData shape) { double shapeScope = shape.Scope(); Rect result = new Rect(shape.X, shape.Y, shape.Width, shape.Height, shapeScope); double wrapperScope = shape.Width * shape.Height; if (Math.Abs(1 - shapeScope / wrapperScope) <= MAX_DEVIATION) { return(result); } List <List <(int x, int y)> > ways = GetAllCountures(shape); if (ways.Count == 4 && ways.All(W => W.Count < PIN_MAX)) { return(result); } return(null); }
public abstract IShape RecognizeShape(IRawData shape);
protected void ProcessPerimeter(int x, int y, IRawData data, bool[,] visited, List <(int x, int y)> way, Queue <(int x, int y)> toVisit)
private static void PrintRawData(IRawData value, int indent) { Print($"IRawData:{{ RVA: {(uint)value.RVA:X8} FileOffset: {(uint)value.FileOffset:X8} Length: {value.Length:X8} }}", indent); }
internal ItemData(Language lang, IRawData data) { _Data = data; _Lang = lang; _Name = null; }
public override IShape RecognizeShape(IRawData shape) => Math.Abs(1 - (Math.PI / 4.0) / ((double)shape.Scope() / (shape.Width * shape.Height))) <= MAX_DEVIATION ? new Circle(shape.X, shape.Y, shape.Width / 2) : null;
public void Consume(IRawData buffer) { m_buffer = buffer; }
/** * <summary>Copies values from another data</summary> * <param name="aRef">Reference to copy from</param> */ public static RawPoint copyFrom(IRawData aRef) { return(new RawPoint(aRef.timestamp, aRef.x, aRef.y)); }
public void Consume(IRawData buffer) { }