- gesturerecognizer_demo.zip
- GestureRecognizer_demo
- gesturerecognizer_src.zip
- GestureRecognizer_src
- cmgblade_src.zip
- MouseGesture
- cmgblade_demo.zip
- Gestures
- ArrowLeft.mgf
- ArrowLeftNET.mgn
- ArrowLeftTS.mgt
- ArrowRight.mgf
- ArrowRightNET.mgn
- ArrowRightTS.mgt
- Circle.mgf
- CircleNET.mgn
- CircleTS.mgt
- DownLeftLine.mgf
- DownLeftLineNET.mgn
- DownLeftLineTS.mgt
- DownRightLine.mgf
- DownRightLineNET.mgn
- DownRightLineTS.mgt
- DownUp.mgf
- DownUpNET.mgn
- DownUpTS.mgt
- Esse.mgf
- EsseNET.mgn
- EsseTS.mgt
- HourGlass.mgf
- HourGlassNET.mgn
- HourGlassTS.mgt
- LeftSquare.mgf
- LeftSquareNET.mgn
- LeftSquareTS.mgt
- LineDown.mgf
- LineDownNET.mgn
- LineDownTS.mgt
- LineLeft.mgf
- LineLeftNET.mgn
- LineLeftTS.mgt
- LineRight.mgf
- LineRightNET.mgn
- LineRightTS.mgt
- LineUp.mgf
- LineUpNET.mgn
- LineUpTS.mgt
- LLeft.mgf
- LLeftNET.mgn
- LLeftTS.mgt
- LRight.mgf
- LRightNET.mgn
- LRightTS.mgt
- Omega.mgf
- OmegaNET.mgn
- OmegaTS.mgt
- RightSquare.mgf
- RightSquareNET.mgn
- RightSquareTS.mgt
- UpDown.mgf
- UpDownNET.mgn
- UpDownTS.mgt
- UpLeftLine.mgf
- UpLeftLineNET.mgn
- UpLeftLineTS.mgt
- UpRightLine.mgf
- UpRightLineNET.mgn
- UpRightLineTS.mgt
- Whirl.mgf
- WhirlNET.mgn
- WhirlTS.mgt
- MouseGesture.exe
- mousegesturesrc.zip
|
using System;
using System.Drawing;
using System.Collections;
using System.Drawing.Drawing2D;
namespace MouseGesture
{
#region GestureRegularization abstract class
//The class contains useful functions to manipolate points
public abstract class GestureRegularization
{
#region ReduceGesturePoints static function
//Remove points from an array points
public static int ReduceGesturePoints(ArrayList Points)
{
//Compute poitns to remove
int ExcessivePoints=Points.Count-MainBoard.GestureMaximumPoints;
for(int i=0; i<ExcessivePoints; i++)
{
//Compute min segment in arraylist, returning the index of its
//first point
int index=GestureRegularization.GetFirstIndexMinSegment(Points);
//Add mid point of min segment
GestureRegularization.AddMidPoint(Points,index);
//Remove points which identified min segment
GestureRegularization.RemovePoint(Points,index+2);
GestureRegularization.RemovePoint(Points,index);
}
//Return numbers of points removed
return ExcessivePoints;
}
#endregion
#region ExpandGesturePoints static function
//Add points to points arraylist
public static int ExpandGesturePoints(ArrayList Points)
{
//Compute missing points
int GapPoints=MainBoard.GestureMaximumPoints-Points.Count;
for(int i=0; i<GapPoints; i++)
{
//Compute max segment, returning index of its first point
int index=GestureRegularization.GetFirstIndexMaxSegment(Points);
//Add max segment mid poitn to arraylist
GestureRegularization.AddMidPoint(Points,index);
}
//Returns added points number
return GapPoints;
}
#endregion
#region GetFirstIndexMinSegment static function
//Get min segment among points
public static int GetFirstIndexMinSegment(ArrayList Points)
{
double[] Lenghts=new double[Points.Count-1];
//Get segments lengths
Lenghts=GestureRegularization.GetSegmentsLenghts(Points);
//Get min segment, storing index
int ret=0;
for(int i=1; i<Lenghts.Length; i++)
{
if(Lenghts[ret]>Lenghts[i])
ret=i;
}
//Returns min segment first point
return ret;
}
#endregion
#region GetFirstIndexMaxSegment static function
//Get max segment among points
public static int GetFirstIndexMaxSegment(ArrayList Points)
{
double[] Lenghts=new double[Points.Count-1];
//Get segments lengths
Lenghts=GestureRegularization.GetSegmentsLenghts(Points);
//Get max segment, storing index
int ret=0;
for(int i=1; i<Lenghts.Length; i++)
{
if(Lenghts[ret]<Lenghts[i])
ret=i;
}
//Returns max segment first point
return ret;
}
#endregion
#region RemovePoint static function
//Remove point from points arraylist
public static void RemovePoint(ArrayList Points,int Index)
{
//It would be a good idea to check Points length... anyway, since
//in this program gesture re composed by more than 3 points, everything is fine...
//There could be a better way :P
if(Index==0) //If index is start, then removes next one
Points.RemoveAt(1);
else if(Index==Points.Count-1) //If index is the last, remove the earlier
Points.RemoveAt(Points.Count-2);
else
Points.RemoveAt(Index);
}
#endregion
#region AddMidPoint static function
//Adds mid point between to points
public static void AddMidPoint(ArrayList Points,int Index)
{
//First mid point can't be the last, so there is no problem using Index+1
//Get mid point between Index point and Index+1 point
PointF MidPoint=GestureRegularization.GetMidPoint(((PointF)Points[Index]),((PointF)Points[Index+1]));
//Insert new point
Points.Insert(Index+1,MidPoint);
}
#endregion
#region GetSegmentsLenghts static function
//Get lengths of every segment
public static double[] GetSegmentsLenghts(ArrayList Points)
{
double[] vect=new double[Points.Count-1];
//For each couple, compute segment length
for(int i=0; i<Points.Count-1; i++)
vect[i]=GestureRegularization.GetSegmentLength(((PointF)Points[i]),((PointF)Points[i+1]));
return vect;
}
#endregion
#region GetSegmentLength static function
//Get Segment length between 2 points
public static double GetSegmentLength(PointF pointA, PointF pointB)
{
//length=sqrt((x0-x1)^2+(y0-y1)^2)
double DX2=(pointA.X-pointB.X)*(pointA.X-pointB.X);
double DY2=(pointA.Y-pointB.Y)*(pointA.Y-pointB.Y);
return Math.Sqrt(DX2+DY2);
}
#endregion
#region GetMidPoint static function
//Get mid point between 2 ponts
public static PointF GetMidPoint(PointF pointA, PointF pointB)
{
float x=((pointA.X+pointB.X)/2);
float y=((pointA.Y+pointB.Y)/2);
return new PointF(x,y);
}
#endregion
#region GetMaxDeltaX static function
//This function gets max delta-x among all points
public static double GetMaxDeltaX(ArrayList Points)
{
double ret=0;
for(int i=0; i<Points.Count-1; i++)
{
//Get x excursion between 2 consecutive points
double Length=((PointF)Points[i]).X-((PointF)Points[i+1]).X;
//Gets length positive value
Length=(Length>0)?(Length):(-Length);
//Check is this length is best than last one
if(Length>ret)
ret=Length;
}
//Return max delta x
return ret;
}
#endregion
#region GetMaxDeltaY static function
//This function gets max delta-y among all points
public static double GetMaxDeltaY(ArrayList Points)
{
double ret=0;
for(int i=0; i<Points.Count-1; i++)
{
//Get y excursion between 2 consecutive points
double Length=((PointF)Points[i]).Y-((PointF)Points[i+1]).Y;
//Gets length positive value
Length=(Length>0)?(Length):(-Length);
//Check is this length is best than last one
if(Length>ret)
ret=Length;
}
//Return max delta y
return ret;
}
#endregion
}
#endregion
}
|
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.
I got my Computer Science (Engineering) Master's Degree at the Siena University (Italy), but I'm from Rieti (a small town next to Rome).
My hobbies are RPG, MMORGP, programming and 3D graphics.
At the moment I'm employed at Apex s.r.l. (Modena, Italy) as a senior software developer, working for a WPF/WCF project in Rome.