|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
namespace UPImage.FileFormat
{
public class UPPenTrajectory
{
int iComponentID;
String keyname;
List<String> penTrajectory;
List<Point> points;
Point top;
Point bottom;
public Point Top
{
get
{
return top;
}
}
public Point Bottom
{
get
{
return bottom;
}
}
/// <summary>
///
/// </summary>
public int ComponentID
{
get
{
return iComponentID;
}
}
public List<String> PenTrajectory
{
get
{
return penTrajectory;
}
}
public List<Point> Points
{
get
{
return points;
}
}
public String Keyname
{
get
{
return keyname;
}
}
public int MaxDegreeOfParallelism
{
get
{
return _maxDegreeOfParallelism;
}
set
{
if (value == _maxDegreeOfParallelism)
return;
if ((value == 0) || (value > Environment.ProcessorCount))
_maxDegreeOfParallelism = -1;
else
_maxDegreeOfParallelism = value;
ParallelOption.MaxDegreeOfParallelism = _maxDegreeOfParallelism;
}
}
public ParallelOptions ParallelOption { get; private set; }
private int _maxDegreeOfParallelism = Environment.ProcessorCount;
public UPPenTrajectory(Point t, Point bt)
{
iComponentID = -1;
penTrajectory = new List<string>();
points = new List<Point>();
top = t;
bottom = bt;
keyname = "";
ParallelOption = new ParallelOptions();
ParallelOption.TaskScheduler = null;
_maxDegreeOfParallelism = Environment.ProcessorCount;
ParallelOption.MaxDegreeOfParallelism = _maxDegreeOfParallelism;
}
public void SetPenTrajectory(int id, UPKEYWORD kw)
{
try
{
if (kw.keyName == UPImage.Common.UpCommonLib.keyPenDown||kw.keyName == UPImage.Common.UpCommonLib.keyPenUp)
{
//get pen trajectory
if (kw.content_list.Count > 1)
{
iComponentID = id;
foreach(var s in kw.content_list)
{
if (UPImage.Common.UpCommonLib.SubStringSearch(null, s, UPImage.Common.UpCommonLib.keyPenDown) || UPImage.Common.UpCommonLib.SubStringSearch(null, s, UPImage.Common.UpCommonLib.keyPenUp))
{
keyname = kw.keyName;
}
else
{
String st = s.Trim();
// Convert X Y parameters to point
List<String> slist = new List<string>();
lock (this)
{
penTrajectory.Add(st);
UPImage.Common.UpCommonLib.GetWordsFromString(null, st, out slist);
}
if (slist.Count >= 2)
{
Point newpoint = new Point();
newpoint.X = Convert.ToInt32(slist[0]);
newpoint.Y = Convert.ToInt32(slist[1]);
lock (this)
{
points.Add(newpoint);
}
//set location and size of unipen's rectangle
if (bottom.IsEmpty && top.IsEmpty)
{
top = newpoint;
bottom = newpoint;
}
else
{
if (newpoint.X < top.X)
{
top.X = newpoint.X;
}
else
if (newpoint.X > bottom.X)
{
bottom.X = newpoint.X;
}
if (newpoint.Y < top.Y)
{
top.Y = newpoint.Y;
}
else
if (newpoint.Y > bottom.Y)
{
bottom.Y = newpoint.Y;
}
}
}
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public void SetPenTrajectory(int id, UPKEYWORD kw, int beginPoint, int endPoint)
{
try
{
if (kw.keyName == UPImage.Common.UpCommonLib.keyPenDown || kw.keyName == UPImage.Common.UpCommonLib.keyPenUp)
{
//get pen trajectory
if (kw.content_list.Count > 1)
{
iComponentID = id;
int index = 0;
foreach(var s in kw.content_list)
{
if (UPImage.Common.UpCommonLib.SubStringSearch(null, s, UPImage.Common.UpCommonLib.keyPenDown) || UPImage.Common.UpCommonLib.SubStringSearch(null, s, UPImage.Common.UpCommonLib.keyPenUp))
{
keyname = kw.keyName;
}
else
{
if (index < beginPoint)
{
index++;
}
else
if (index >= beginPoint && index <= endPoint)
{
String st = s.Trim();
List<String> slist = new List<string>();
lock (this)
{
penTrajectory.Add(st);
// Convert X Y parameters to point
UPImage.Common.UpCommonLib.GetWordsFromString(null, st, out slist);
}
if (slist.Count >= 2)
{
Point newpoint = new Point();
newpoint.X = Convert.ToInt32(slist[0]);
newpoint.Y = Convert.ToInt32(slist[1]);
lock (this)
{
points.Add(newpoint);
}
//set location and size of unipen's rectangle
if (bottom.IsEmpty && top.IsEmpty)
{
top = newpoint;
bottom = newpoint;
}
else
{
if (newpoint.X <= top.X)
{
top.X = newpoint.X;
}
else if (newpoint.X >= bottom.X)
{
bottom.X = newpoint.X;
}
if (newpoint.Y <= top.Y)
{
top.Y = newpoint.Y;
}
else if (newpoint.Y >= bottom.Y)
{
bottom.Y = newpoint.Y;
}
}
}
index++;
}
else
if (index > endPoint)
{
break;
}
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
/// <summary>
/// --------------------------------------------------------------------------------
/// </summary>
public class UPUnipen
{
int iStartBoxID;
int iUnipen; //Unipen id in databox
String hierachy;
String label;
List<UPPenTrajectory> penTrajectories;
Point top;
Point bottom;
UPSEGMENT segment;
public UPSEGMENT Segment
{
get
{
return segment;
}
}
public int StartBoxID
{
get
{
return iStartBoxID;
}
}
public int UnipenID
{
get
{
return iUnipen;
}
}
public String Hierachy
{
get
{
return hierachy;
}
}
public String Label
{
get
{
return label;
}
}
public Point Top
{
get
{
return top;
}
}
public Point Bottom
{
get
{
return bottom;
}
}
public List<UPPenTrajectory> PenTrajectories
{
get
{
return penTrajectories;
}
}
/// <summary>
/// ----------------------------------------------------------------------------------------
/// </summary>
public UPUnipen()
{
label = "";
hierachy = "";
iStartBoxID = -1;
iUnipen = -1;
segment = new UPSEGMENT();
penTrajectories = new List<UPPenTrajectory>();
top = Point.Empty;
bottom = Point.Empty;
}
public void InitUPUnipen(UPKEYWORD kw, UPSEGMENT sm, int dbID, int unpID)
{
penTrajectories = new List<UPPenTrajectory>(sm.ComponentValues.Count);
segment = sm;
hierachy = sm.Hierachy;
label = sm.Label;
iStartBoxID = dbID;
iUnipen = unpID;
segment = sm;
}
public void AddPenTrajectory(UPKEYWORD kw, ComponentInfo cv)
{
if (kw.content_list.Count > 1)
{
UPPenTrajectory upt = new UPPenTrajectory(top, bottom);
int beginpoint = cv.startpoint;
int endpoint;
if (cv.endpoint == -1)
{
endpoint = (kw.content_list.Count - 1) - 1; // do not count keyname
}
else
{
endpoint=cv.endpoint;
}
//check if the first pen trajectory has begin point !=0
upt.SetPenTrajectory(cv.ComponentID, kw, beginpoint, endpoint);
//update location and size
top = upt.Top;
bottom = upt.Bottom;
penTrajectories.Add(upt);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.