Exemple #1
0
    public static TraceGroup ToTraceGroup(this Ink ink)
    {
      var traceGroup = new TraceGroup();
      foreach(var stroke in ink.Strokes)
      {
        var trace = new Trace();
        foreach(var point in stroke.GetPoints())
        {
          var penPoint = new PenPoint {X = point.X, Y = point.Y};
          trace.Points.Add(penPoint);
        }
        traceGroup.Traces.Add(trace);
      }

      return traceGroup;
    }
Exemple #2
0
    public Trace ResampleTrace(Trace inTrace, int resamplePoints)
    {
      var outTrace = new Trace();
      var xSum = 0f;
      var ySum = 0f;
      var x = 0f;
      var y = 0f;
      var numTracePoints = inTrace.Points.Count;

      var xDiff = 0f;
      var yDiff = 0f;
      var pointDistance = 0f;
      var unitLength = 0f;
      var distanceVec = new List<float>();
      var balanceDistance = 0f;  //	distance between the last resampled point and
                                //	the next raw sample point
      var measuredDistance = 0f;

      var m1 = 0f;
      var m2 = 0f;
      var ptIndex = 0;
      var currentPointIndex = 0;

      var xVec = inTrace.ChannelX;
      var yVec = inTrace.ChannelY;

      var xTemp = 0f;
      var yTemp = 0f;

      if(resamplePoints==1)
      {
        xSum = inTrace.GetSumX();
        ySum = inTrace.GetSumY();

        x = xSum/numTracePoints;
        y = ySum/numTracePoints;
        var penPoint = new PenPoint {X = x, Y = y};
        outTrace.Points.Add(penPoint);
      }else
      {
        for(var i=0;i<(numTracePoints-1);++i)
        {
          xDiff = inTrace.ChannelX[i] - inTrace.ChannelX[i + 1];
          yDiff = inTrace.ChannelY[i] - inTrace.ChannelY[i + 1];
          pointDistance = (float) Math.Sqrt(xDiff*xDiff + yDiff*yDiff);
          unitLength += pointDistance;
          distanceVec.Add(pointDistance);
        }

        unitLength /= (resamplePoints - 1);

        x = inTrace.ChannelX[0];
        y = inTrace.ChannelY[0];

        outTrace.Points.Add(new PenPoint{X=x, Y=y});

        for(var i=1; i<(resamplePoints-1); ++i)
        {
          measuredDistance = balanceDistance;

          while(measuredDistance<unitLength)
          {
            measuredDistance += distanceVec[ptIndex++];

            if (ptIndex == 1) currentPointIndex = 1;
            else currentPointIndex++;

          }

          if (ptIndex < 1) ptIndex = 1;

          m2 = measuredDistance - unitLength;
          m1 = distanceVec[ptIndex - 1] - m2;

          if(Math.Abs(m1+m2)>_eps)
          {
            xTemp = (m1*xVec[currentPointIndex] + m2*xVec[currentPointIndex - 1])/(m1 + m2);
            yTemp = (m1*yVec[currentPointIndex] + m2*yVec[currentPointIndex - 1])/(m1 + m2);
          }else
          {
            xTemp = xVec[currentPointIndex];
            yTemp = yVec[currentPointIndex];
          }

          outTrace.Points.Add(new PenPoint{X=xTemp, Y=yTemp});

          balanceDistance = m2;
        }

        x = xVec[xVec.Count - 1]; //adding x of last point
        y = yVec[yVec.Count - 1]; //adding y of last point

        outTrace.Points.Add(new PenPoint{X=x, Y=y});
      }

      return outTrace;
    }