private void AddAssociationArrow(StylusPoint firstPoint, StylusPoint lastPoint) { Point pointOnStroke = GetPointForArrow(new Coordinates(firstPoint.ToPoint()), new Coordinates(lastPoint.ToPoint()), 10); Point actualArrowPoint1 = rotatePointAroundPoint(pointOnStroke, firstPoint.ToPoint(), 45); Point actualArrowPoint2 = rotatePointAroundPoint(pointOnStroke, firstPoint.ToPoint(), -45); StylusPoints.Add(new StylusPoint(actualArrowPoint1.X, actualArrowPoint1.Y)); StylusPoints.Add(StylusPoints[0]); StylusPoints.Add(new StylusPoint(actualArrowPoint2.X, actualArrowPoint2.Y)); StylusPoints.Add(StylusPoints[0]); }
//private void StudentInkCanvas_SpeedCheckedEvent(object sender, StudentInkCanvas.SpeedCheckedEventArgs e) //{ // IsSpeedChecked = e.state; //} #endregion #region overrides protected override void OnStylusDown(RawStylusInput rawStylusInput) { base.OnStylusDown(rawStylusInput); Stroke tempStroke = new Stroke(rawStylusInput.GetStylusPoints()); //if the styluspoints is not empty if (tempStroke.StylusPoints.Count >= 0) { //get the stroke thats the animation is running on ExpertStroke = ExpertStrokeCollection[StudentStrokeCount]; //set the first point of the stroke as the expert reference point ExpertStylusPoint = ExpertStroke.StylusPoints.First(); if (tempStroke.HitTest(ExpertStylusPoint.ToPoint(), HitThreshold)) { foreach (StylusPoint sp in tempStroke.StylusPoints) { hitChangedPoints.Add(sp.ToPoint()); } StrokeColor = Color.FromArgb(255, 0, 255, 0); } else { StrokeColor = Color.FromArgb(255, 255, 0, 0); } } }
private void MoveDotAndRobotToStylusPoint(StylusPoint stylusPt) { var pt = stylusPt.ToPoint(); if (dot.Visibility == Visibility.Visible) { dotTranslateTransform.X = pt.X - (inkCanvas.ActualWidth / 2); dotTranslateTransform.Y = pt.Y - (inkCanvas.ActualHeight / 2); } //TODO :: handle case where drawDimensionSize is less than the inkCanvas.Strokes size // Apply the scalingFactor to the point that the robot will draw. // FOR TESTING if (!isShowingDrawZone) { // get the scaleFactor between the (inkSize + (drawDimensionSize - inkSize)) // and the actual inkSize. // TODO :: establish a new origin to be the Top Left of the Draw Rectangle double scaleFactorX = (drawZoneRect.Width / (inkCanvas.ActualWidth)); double scaleFactorY = (drawZoneRect.Height / (inkCanvas.ActualHeight)); pt.X = (pt.X * scaleFactorX) + drawZoneRect.Left; pt.Y = (pt.Y * scaleFactorY) + drawZoneRect.Top; } // Send the point to the robot too. // Leave the arm in its current down state. RobotArm.Move(pt); }
private void MoveDotAndRobotToStylusPoint(StylusPoint stylusPt) { var pt = stylusPt.ToPoint(); if (dot.Visibility == Visibility.Visible) { dotTranslateTransform.X = pt.X - (inkCanvas.ActualWidth / 2); dotTranslateTransform.Y = pt.Y - (inkCanvas.ActualHeight / 2); } // Send the point to the robot too. RobotArm.Move(pt); }
protected Point GetTheRightBottomPoint() { if (StylusPoints == null) { throw new ArgumentNullException("StylusPoints"); } StylusPoint tmpPoint = new StylusPoint(0, 0); foreach (StylusPoint point in StylusPoints) { if ((point.X > tmpPoint.X) || (point.Y > tmpPoint.Y)) { tmpPoint = point; } } return(tmpPoint.ToPoint()); }
protected Point GetTheLeftTopPoint() { if (StylusPoints == null) { throw new ArgumentNullException("StylusPoints"); } StylusPoint tmpPoint = new StylusPoint(double.MaxValue, double.MaxValue); foreach (StylusPoint point in StylusPoints) { if ((point.X < tmpPoint.X) || (point.Y < tmpPoint.Y)) { tmpPoint = point; } } return(tmpPoint.ToPoint()); }
// resample the stroke into point set with constant inter-distance private void ResampleStrokes(int pass) { // initial the variable m_resampleTime = new double[500]; m_numS = 0; m_meanTime = 0; // init number of raw points between two resampled points int numBetween = 0; // compute the diagonal of the stroke's bounding box Rect bound = m_stroke.GetBounds(); double diag = GetDistance(bound.TopLeft, bound.BottomRight); // set the distance between resampled poits to be 1/40 of the diagonal m_cellDist = diag / 40; // resample the points double m_length = 0; int preIndex = 0; // pass 0: the first resampled points is the start point of the stroke if (pass == 0) { m_resamplePoints.Add(m_stroke.StylusPoints[0].ToPoint()); m_resampleTime[m_numS] = 0; m_numS++; } // compute other resampled points for (int i = 1; i < m_numP; i++) { numBetween++; // compute the distance between ajacent two raw points in the stroke double dist = GetDistance(m_stroke.StylusPoints[i - 1].ToPoint(), m_stroke.StylusPoints[i].ToPoint()); // check the distance between the last resampled point and the visiting raw points if (m_length + dist >= m_cellDist || (pass == 1 && m_numS == 0 && m_length + dist >= m_cellDist / 2.0)) { // add a new point to the resampled points Point newPoint = new Point(); StylusPoint preP = m_stroke.StylusPoints[i - 1]; StylusPoint curP = m_stroke.StylusPoints[i]; // compute the position of the new resampled point if (pass == 1 && m_numS == 0) { // first shifted resampled point newPoint.X = preP.X + ((m_cellDist / 2.0 - m_length) / dist) * (curP.X - preP.X); newPoint.Y = preP.Y + ((m_cellDist / 2.0 - m_length) / dist) * (curP.Y - preP.Y); } else { // other resampled points newPoint.X = preP.X + ((m_cellDist - m_length) / dist) * (curP.X - preP.X); newPoint.Y = preP.Y + ((m_cellDist - m_length) / dist) * (curP.Y - preP.Y); } m_resamplePoints.Add(newPoint); // compute the distance from the new resampled point to the raw point i m_length = GetDistance(newPoint, curP.ToPoint()); // compute time for each resampled point m_resampleTime[m_numS] = m_time[i] - m_time[preIndex]; if (m_resampleTime[m_numS] < 0) { m_resampleTime[m_numS] = 0; } // compute the mean time of the resampled points m_meanTime += m_resampleTime[m_numS]; // add extra resampled points between newPoint and raw point i preIndex = i; numBetween = 0; m_numS++; // make sure m_length is less than m_cellDist while (m_length > m_cellDist) { // find all possible resampled point befor i newPoint.X += (m_cellDist / dist) * (curP.X - preP.X); newPoint.Y += (m_cellDist / dist) * (curP.Y - preP.Y); m_resamplePoints.Add(newPoint); m_length -= m_cellDist; // compute time for each resampled point m_resampleTime[m_numS] = m_time[i] - m_time[i - 1]; if (m_resampleTime[m_numS] < 0) { m_resampleTime[m_numS] = 0; } // compute the mean time of the resampled points m_meanTime += m_resampleTime[m_numS]; m_numS++; } } else { // get the last resampled point m_length += dist; if ((m_length > m_cellDist) && (i == m_numP - 1)) { m_resamplePoints.Add(m_stroke.StylusPoints[i].ToPoint()); m_resampleTime[m_numS] = m_time[i] - m_time[preIndex]; m_numS++; } } } // compute mean time of resampled point m_meanTime /= m_numS; }
protected override void OnStylusMoveProcessed(object callbackData, bool targetVerified) { // Check that the element actually receive the OnStylusUp input. if (targetVerified) { //Debug.WriteLine("StudentDynamicRendrer/StudentStrokeCount : " + StudentStrokeCount); StylusPointCollection spc = callbackData as StylusPointCollection; //pass the points into a stroke to find the neartest stroke Stroke tempStroke = new Stroke(spc); //if the expert stroke is loaded if (IsExpertStrokeLoaded == true) { //get the expert strokes collection that are overlapping with the current ink stroke //StrokeCollection tempStrokeCollection = SelectBoundingStrokeCollection(tempStroke, ExpertStrokeCollection); //if the tempstrokecollection returns empty exit the method. //if (tempStrokeCollection.Count > 0) //{ //get the stylusPoint and the stroke over lapping the pen point from the tempStrokeCollection //Stroke ExpertStroke = ExpertStrokeCollection[StudentStrokeCount]; //set the first point of the stroke as the //ExpertStylusPoint = ExpertStroke.StylusPoints.First(); //ExpertStylusPoint = SelectNearestExpertPoint(tempStroke, tempStrokeCollection, out ExpertStroke); //raise the event that the nearest expert point is selected //NearestExpertStylusPointCalculatedEventArgs args = new NearestExpertStylusPointCalculatedEventArgs(); //args.styluspoint = ExpertStylusPoint; //args.stroke = ExpertStroke; //OnNearestExpertStylusPointCalculated(args); //if StrokeFeedback is requested if (IsStrokeChecked == true) { if (tempStroke.HitTest(ExpertStylusPoint.ToPoint(), HitThreshold)) { foreach (StylusPoint sp in tempStroke.StylusPoints) { hitChangedPoints.Add(sp.ToPoint()); } StrokeColor = Color.FromArgb(255, 0, 255, 0); } else { StrokeColor = Color.FromArgb(255, 255, 0, 0); } } //If Pressure is checked change the color of the Stroke if (IsPressureChecked == true) { List <float> pressureFactorList = new List <float>(); foreach (StylusPoint s in tempStroke.StylusPoints) { pressureFactorList.Add(s.PressureFactor); } float StudentPressureFactor = pressureFactorList.Average(); //multiplier to darken or lighen the PreviousColor float ExpertPressureFactor = ExpertStylusPoint.PressureFactor; //if pressure is higher produce darker color by passing negetive number float ColorWeight = ExpertPressureFactor - StudentPressureFactor; StrokeColor = ChangeColorBrightness(StrokeColor, ColorWeight); } //} } } }