public override void run(Sketch.Sketch sketch, string filename) { FeatureSketch fsketch = FeatureSketch.MakeFeatureSketch(new Sketch.Project(sketch)); Dictionary <Substroke, string> classifications = new Dictionary <Substroke, string>(); foreach (Substroke substroke in sketch.Substrokes) { classifications.Add(substroke, substroke.Classification); } Dictionary <string, Dictionary <FeatureStrokePair, double[]> > pair2values; pair2values = fsketch.GetValuesPairwise(classifications); foreach (KeyValuePair <string, Dictionary <FeatureStrokePair, double[]> > pair in pair2values) { string classification = pair.Key; Dictionary <FeatureStrokePair, double[]> features = pair.Value; Console.WriteLine(classification + ":"); foreach (KeyValuePair <FeatureStrokePair, double[]> pair2 in features) { Substroke stroke1 = pair2.Key.Item1; Substroke stroke2 = pair2.Key.Item2; double[] featureValues = pair2.Value; _resultsPairs.addResult(featureValues); } } }
/// <summary> /// Process a sketch. This runs every recognition step on the sketch in /// the order they were added to this pipeline. This method does nothing /// if no steps have been added. /// </summary> /// <param name="featureSketch">the sketch to process</param> public virtual void process(FeatureSketch featureSketch) { foreach (IRecognitionStep step in _steps) { step.process(featureSketch); } }
/// <summary> /// Process an ordinary sketch by first creating a feature sketch for it. /// This method calls process using the created feature sketch, then /// returns the feature sketch, in case you want to use it. The given /// ordinary sketch is modified in the process. /// </summary> /// <param name="sketch">the ordinary sketch to use</param> /// <returns>the featureSketch used during processing</returns> public FeatureSketch process(Sketch.Sketch sketch) { FeatureSketch featureSketch = FeatureSketch.MakeFeatureSketch(sketch); process(featureSketch); return(featureSketch); }
/// <summary> /// Process an ordinary sketch by first creating a feature sketch for it. /// This method calls process using the created feature sketch, then /// returns the feature sketch, in case you want to use it. The given /// ordinary sketch is modified in the process. /// </summary> /// <param name="project">the sketch project to use</param> /// <returns>the featureSketch used during processing</returns> public FeatureSketch process(Sketch.Project project) { FeatureSketch featureSketch = FeatureSketch.MakeFeatureSketch(project); process(featureSketch); return(featureSketch); }
/// <summary> /// Process an ordinary sketch by first creating a feature sketch for it. /// This method calls process using the created feature sketch, then /// returns the feature sketch, in case you want to use it. The given /// ordinary sketch is modified in the process. /// </summary> /// <param name="sketch">the ordinary sketch to use</param> /// <returns>the featureSketch used during processing</returns> public FeatureSketch process(Sketch.Sketch sketch) { FeatureSketch featureSketch = FeatureSketch.MakeFeatureSketch(new Sketch.Project(sketch)); process(featureSketch); return(featureSketch); }
/// <summary> /// Constructor for StrokeInfoForm /// </summary> /// <param name="strokefeatures"></param> a FeatureStroke /// <param name="sketchFeatures"></param> a FeatureSketch /// <param name="inkStroke"></param> a System.Windows.Controls Stroke /// <param name="substroke"></param> a Sketch Substroke public StrokeInfoWindow(FeatureStroke strokefeatures, FeatureSketch sketchFeatures, Stroke inkStroke, Sketch.Substroke substroke) { InitializeComponent(); inkMovedX = 0; inkMovedY = 0; scale = 2.0f; mInkCanvas.Width = Width / 2 - 20; mInkCanvas.Height = Height - 20; mInkCanvas.StrokeCollected += new InkCanvasStrokeCollectedEventHandler(mInkCanvas_StrokeCollected); mSketchFeatures = sketchFeatures; mStrokeFeatures = strokefeatures; mInkStroke = inkStroke; mSubstroke = substroke; mInkCanvas.Strokes.Add(mInkStroke); Red = Color.FromArgb(255, 255, 0, 0); Green = Color.FromArgb(255, 0, 255, 0); Blue = Color.FromArgb(255, 0, 0, 255); Black = Color.FromArgb(255, 0, 0, 0); mInkCanvas.Strokes[0].DrawingAttributes.Color = Red; populateListView(); }
/// <summary> /// Loads a Sketch into the InkSketch /// </summary> /// <param name="sketch">The sketch to load</param> /// Precondition: The InkSketch is clean (all dictionaries cleared etc) /// Postcondition: The InkSketch has the proper data members public StrokeCollection LoadSketch(Sketch.Sketch sketch) { project.sketch = sketch; featureSketch = FeatureSketch.MakeFeatureSketch(project); setUserSpecified(); return(CreateInkStrokesFromSketch()); }
/// <summary> /// Process a sketch. This runs every recognition step on the sketch in /// the order they were added to this pipeline. This method does nothing /// if no steps have been added. /// </summary> /// <param name="featureSketch">the sketch to process</param> public virtual void process(FeatureSketch featureSketch) { SketchProcessor processor = getProcessor(featureSketch); while (!processor.isFinished()) { processor.executeNextStep(); } }
/// <summary> /// Clears out the internal data structures for loading /// </summary> public void Clear() { mSketch = new Sketch.Sketch(); mFeatureSketch = FeatureSketch.MakeFeatureSketch(mSketch); ink2sketchStr.Clear(); sketchStr2ink.Clear(); substrokeIdMap.Clear(); }
/// <summary> /// Clears out the internal data structures for loading /// </summary> public void Clear() { createEmptySketch(); featureSketch = FeatureSketch.MakeFeatureSketch(project); ink2sketchStr.Clear(); sketchStr2ink.Clear(); substrokeIdMap.Clear(); }
private static List <Shape> GetShapeDerivatives(Shape shape, FeatureSketch fSketch) { List <Shape> derivatives = new List <Shape>(); Dictionary <Substroke, List <SubstrokeDistance> > distances = fSketch.PairwiseFeatureSketch.AllDistances; SortedList <double, Substroke> closest = GetClosestStrokes(shape, distances); return(derivatives); }
/// <summary> /// Classifies using WEKA. /// </summary> public override string classify(Substroke substroke, FeatureSketch featureSketch) { // Get the features for this substroke double[] featureValues = featureSketch.GetValuesSingle(substroke); // classify using Weka string classification = _wekaWrapper.Value.classify(featureValues); return(classification); }
private void menuStrokeInformation_Click(object sender, EventArgs e) { Sketch.Sketch sketch = sketchPanel.Sketch; FeatureSketch sketchFeatures = new FeatureSketch(ref sketch); Microsoft.Ink.Strokes selected = sketchPanel.InkSketch.Ink.Strokes; Microsoft.Ink.Stroke s = selected[selected.Count - 1]; Sketch.Substroke ss = sketchPanel.InkSketch.GetSketchSubstrokeByInkId(s.Id); StrokeInfoForm.strokeInfoForm sif = new StrokeInfoForm.strokeInfoForm(sketchFeatures.GetFeatureStrokeByStrokeGUID(ss.Id), sketchFeatures, s, ss); sif.Show(); }
/// <summary> /// Get an estimate of the probability that the given shape is of the given type /// </summary> /// <param name="shape"></param> /// <param name="type"></param> /// <param name="orientation">[out] the best orientation for the given type</param> /// <returns>the probability</returns> private RecognitionResult RecognizeAsType( SubstrokeCollection substrokes, ShapeType type, FeatureSketch featureSketch) { if (!_identificationResults.ContainsKey(substrokes)) { _identificationResults.Add(substrokes, computeRecognitionProbabilities(substrokes, featureSketch)); } return(_identificationResults[substrokes][type]); }
// Post public override void TranslateT2C(TransCAD.IFeature tFeature) { TransCAD.IStdSolidProtrusionExtrudeFeature proExtrude = (TransCAD.IStdSolidProtrusionExtrudeFeature)tFeature; // 스케치 변환 FeatureSketch SketchManager = new FeatureSketch(PartManager); TransCAD.IFeature profilesketch = PartManager.GetFeatureFromReference(proExtrude.ProfileSketch); SketchManager.TranslateT2C(profilesketch); double sD = proExtrude.StartDepth; TransCAD.StdExtrudeEndType sC = proExtrude.StartCondition; double eD = proExtrude.EndDepth; TransCAD.StdExtrudeEndType eC = proExtrude.EndCondition; bool isFlip = proExtrude.IsFlip; PARTITF.Pad cPad = PartManager.cShapeFactory.AddNewPadFromRef(SketchManager.cReference, sD); cPad.FirstLimit.Dimension.Value = sD; cPad.SecondLimit.Dimension.Value = eD; if (sC == TransCAD.StdExtrudeEndType.Blind) { cPad.FirstLimit.LimitMode = PARTITF.CatLimitMode.catOffsetLimit; } else if (sC == TransCAD.StdExtrudeEndType.ThroughAll) { cPad.FirstLimit.LimitMode = PARTITF.CatLimitMode.catUpToLastLimit; } if (eC == TransCAD.StdExtrudeEndType.Blind) { cPad.SecondLimit.LimitMode = PARTITF.CatLimitMode.catOffsetLimit; } else if (eC == TransCAD.StdExtrudeEndType.ThroughAll) { cPad.SecondLimit.LimitMode = PARTITF.CatLimitMode.catUpToLastLimit; } if (isFlip == false) { cPad.DirectionOrientation = PARTITF.CatPrismOrientation.catRegularOrientation; } else if (isFlip == true) { cPad.DirectionOrientation = PARTITF.CatPrismOrientation.catInverseOrientation; } PartManager.cPart.UpdateObject(cPad); PartManager.ReferenceManager.NameMap.Add(proExtrude.Name, cPad.get_Name()); }
// Pre public override void TranslateC2T(MECMOD.Shape cShape) { PARTITF.Rib cRib = (PARTITF.Rib)cShape; FeatureSketch ProfileSketch = new FeatureSketch(PartManager); ProfileSketch.TranslateC2T(cRib.Sketch); TransCAD.Reference profile = ProfileSketch.tReference; FeatureSketch GuideSketch = new FeatureSketch(PartManager); GuideSketch.TranslateC2T(cRib.CenterCurve); TransCAD.Reference guide = GuideSketch.tReference; PartManager.tFeatures.AddNewSolidProtrusionSweepFeature(cRib.get_Name(), profile, guide); }
// Pre public override void TranslateC2T(MECMOD.Shape cShape) { PARTITF.Groove cGroove = (PARTITF.Groove)cShape; FeatureSketch SketchManager = new FeatureSketch(PartManager); SketchManager.TranslateC2T(cGroove.Sketch); KnowledgewareTypeLib.Angle first = cGroove.FirstAngle; KnowledgewareTypeLib.Angle second = cGroove.SecondAngle; double fA = first.Value; double sA = second.Value; PartManager.tFeatures.AddNewSolidCutRevolveFeature(cGroove.get_Name(), SketchManager.tReference, fA, TransCAD.StdRevolveEndType.StdRevolveEndType_Blind, sA, TransCAD.StdRevolveEndType.StdRevolveEndType_Blind, false); }
/// <summary> /// Constructor for testing (where we pass in an initialized featureSketch) /// </summary> /// <param name="inkCanvas"></param> /// <param name="featureSketch"></param> public InkCanvasSketch(InkCanvas inkCanvas, FeatureSketch featureSketch) { mInkCanvas = inkCanvas; mFeatureSketch = featureSketch; mSketch = featureSketch.Sketch; // Comply with XML format requirements dtGuid = new Guid(dtGuidString); idGuid = new Guid(idGuidString); Sketch.Units = DefaultSketchUnits; // Intialize other fields ink2sketchStr = new Dictionary <String, Guid?>(); sketchStr2ink = new Dictionary <Guid?, String>(); substrokeIdMap = new Dictionary <Guid?, Substroke>(); subscribeToInk(); }
public void process(FeatureSketch featureSketch) { Sketch.Sketch sketch = featureSketch.Sketch; ISketchModification actionToTake; const int MAX_ITERATIONS = 50; int i = 0; while ((actionToTake = _searchMethod.chooseAction(_domain.SketchModifications(sketch), _domain, sketch)) != null) { i++; if (i > MAX_ITERATIONS) { return; } actionToTake.perform(); } }
// Post public override void TranslateT2C(TransCAD.IFeature tFeature) { TransCAD.IStdSolidCutRevolveFeature cutRevolve = (TransCAD.IStdSolidCutRevolveFeature)tFeature; FeatureSketch SketchManager = new FeatureSketch(PartManager); SketchManager.TranslateT2C(PartManager.GetFeatureFromReference(cutRevolve.ProfileSketch)); double sA = cutRevolve.StartAngle; double eA = cutRevolve.EndAngle; PARTITF.Groove cGroove = PartManager.cShapeFactory.AddNewGrooveFromRef(SketchManager.cReference); cGroove.FirstAngle.Value = sA; cGroove.SecondAngle.Value = eA; PartManager.cPart.UpdateObject(cGroove); PartManager.ReferenceManager.NameMap.Add(cutRevolve.Name, cGroove.get_Name()); }
// Post public override void TranslateT2C(TransCAD.IFeature tFeature) { TransCAD.IStdSolidProtrusionRevolveFeature proRevolve = (TransCAD.IStdSolidProtrusionRevolveFeature)tFeature; FeatureSketch SketchManager = new FeatureSketch(PartManager); SketchManager.TranslateT2C(PartManager.GetFeatureFromReference(proRevolve.ProfileSketch)); double sA = proRevolve.StartAngle; double eA = proRevolve.EndAngle; PARTITF.Shaft cShaft = PartManager.cShapeFactory.AddNewShaftFromRef(SketchManager.cReference); cShaft.FirstAngle.Value = sA; cShaft.SecondAngle.Value = eA; PartManager.cPart.UpdateObject(cShaft); PartManager.ReferenceManager.NameMap.Add(proRevolve.Name, cShaft.get_Name()); }
/// <summary> /// Loads a Sketch into the InkSketch /// </summary> /// <param name="sketch">The sketch to load</param> /// Precondition: The InkSketch is clean (all dictionaries cleared etc) /// Postcondition: The InkSketch has the proper data members public StrokeCollection LoadSketch(Sketch.Sketch sketch) { unsubscribeToInk(); foreach (Shape shape in sketch.Shapes) { if (shape.Type != new Domain.ShapeType()) { shape.AlreadyGrouped = true; shape.AlreadyLabeled = true; } } mSketch = sketch; mFeatureSketch = FeatureSketch.MakeFeatureSketch(sketch); subscribeToInk(); return(CreateInkStrokesFromSketch());; }
/// <summary> /// Constructor for testing (where we pass in an initialized featureSketch) /// </summary> /// <param name="inkCanvas"></param> /// <param name="featureSketch"></param> public InkCanvasSketch(InkCanvas inkCanvas, FeatureSketch featureSketch) { this.inkCanvas = inkCanvas; this.featureSketch = featureSketch; // Don't have a circuit yet this.circuit = null; alreadyLoaded = new List <string>(); project = new Sketch.Project(); // Comply with XML format requirements dtGuid = new Guid(dtGuidString); idGuid = new Guid(idGuidString); Sketch.Units = DefaultSketchUnits; // Intialize other fields ink2sketchStr = new Dictionary <String, Guid?>(); sketchStr2ink = new Dictionary <Guid?, String>(); substrokeIdMap = new Dictionary <Guid?, Substroke>(); }
public FeatureSketchStage() { name = "Feature Sketch Stage"; shortname = "fsk"; outputFiletype = ".csv"; Sketch.Sketch sketch = new Sketch.Sketch(); FeatureSketch fsketch = FeatureSketch.MakeFeatureSketch(new Sketch.Project(sketch)); Dictionary <string, bool> featuresSingleEnabled = fsketch.FeatureListSingle; _featuresSingle = Data.Utils.filter(featuresSingleEnabled.Keys, delegate(string s) { return(featuresSingleEnabled[s]); }); Dictionary <string, bool> featuresPairEnabled = fsketch.FeatureListPair; _featuresPair = Data.Utils.filter(featuresPairEnabled.Keys, delegate(string s) { return(featuresPairEnabled[s]); }); _resultsSingle = new Table(_featuresSingle); _resultsPairs = new Table(_featuresPair); }
/// <summary> /// Constructor helper. If both arguments are null, an empty /// instance of this class is created. If Ink or Sketch /// is null, then one object is synchronized to the other /// (e.g. if ink is null, an empty Ink will be created and /// synchronized with Sketch). If neither argument is null, then /// Sketch will be synchronized with Ink. Subscribes to Ink events /// after any synchronization. /// </summary> /// <param name="ink">The Ink with which to (possibly) synchronize</param> /// <param name="sketch">The Sketch with which to (possibly) synchronize</param> protected virtual void init(Microsoft.Ink.Ink ink, FeatureSketch featureSketch) { // Instantiate new Ink and/or Sketch where necessary if (ink == null) { mInk = new Microsoft.Ink.Ink(); } else { mInk = ink; } if (featureSketch == null) { mFeatureSketch = new FeatureSketch(); Sketch.XmlAttrs.Id = System.Guid.NewGuid(); Sketch.XmlAttrs.Units = DefaultSketchUnits; } else { mFeatureSketch = featureSketch; } // Intialize other fields mReadJnt = new ReadJnt(); ink2sketchStr = new Dictionary <int, Guid?>(); sketchStr2ink = new Dictionary <Guid?, int>(); substrokeIdMap = new Dictionary <Guid?, Substroke>(); // Synchronize Ink or Sketch as necessary if (ink == null && featureSketch != null) { LoadFeatureSketch(featureSketch); } else // (ink != null && featureSketch == null) { LoadInk(ink); } subscribeToInk(); }
// Post public override void TranslateT2C(TransCAD.IFeature tFeature) { TransCAD.IStdSolidProtrusionSweepFeature proSweep = (TransCAD.IStdSolidProtrusionSweepFeature)tFeature; FeatureSketch ProfileSketch = new FeatureSketch(PartManager); ProfileSketch.TranslateT2C(PartManager.GetFeatureFromReference(proSweep.ProfileSketch)); INFITF.Reference profile = ProfileSketch.cReference; FeatureSketch GuideSketch = new FeatureSketch(PartManager); GuideSketch.TranslateT2C(PartManager.GetFeatureFromReference(proSweep.GuideCurve)); INFITF.Reference guide = GuideSketch.cReference; PARTITF.Rib cRib = PartManager.cShapeFactory.AddNewRibFromRef(null, null); cRib.SetProfileElement(profile); cRib.CenterCurveElement = guide; PartManager.cPart.UpdateObject(cRib); PartManager.ReferenceManager.NameMap.Add(proSweep.Name, cRib.get_Name()); }
/// <summary> /// Clears the contents of this InkSketch. Deletes /// all Ink and Sketch strokes and maintains /// synchronization between Ink and Sketch. /// </summary> public virtual void Clear() { mFeatureSketch = new FeatureSketch(); Sketch.XmlAttrs.Id = System.Guid.NewGuid(); Sketch.XmlAttrs.Units = DefaultSketchUnits; mInk = new Microsoft.Ink.Ink(); if (ink2sketchStr != null) { ink2sketchStr.Clear(); } if (sketchStr2ink != null) { sketchStr2ink.Clear(); } if (substrokeIdMap != null) { substrokeIdMap.Clear(); } }
/// <summary> /// Adds a Stroke to our internal data structures - the Sketch and FeatureSketch /// </summary> /// Precondition: The InkStroke is not in the InkCanvas's collection of strokes. /// Postcondition: The InkStroke has been added to the InkCanvas, Sketch's list of /// Strokes, Substrokes, and FeatureSketch. /// <param name="inkStroke"></param> public void AddStroke(System.Windows.Ink.Stroke inkStroke) { if (InkCanvas.Strokes.Contains(inkStroke)) { throw new Exception("adding a stroke to the InkCanvasSketch, but it was already there!"); } // Format the stroke inkStroke.AddPropertyData(dtGuid, (ulong)DateTime.Now.ToFileTime()); string strokeId = Guid.NewGuid().ToString(); inkStroke.AddPropertyData(idGuid, strokeId); // Update the dictionaries Sketch.Stroke sketchStroke = new Sketch.Stroke(inkStroke, dtGuid, SAMPLE_RATE); ink2sketchStr.Add(strokeId, sketchStroke.Substrokes[0].XmlAttrs.Id); sketchStr2ink.Add(sketchStroke.Substrokes[0].Id, strokeId); substrokeIdMap.Add(sketchStroke.Substrokes[0].Id, sketchStroke.Substrokes[0]); // Add it to the relevant data structures (InkCanvas last.) FeatureSketch.AddStroke(sketchStroke); InkCanvas.Strokes.Add(inkStroke); }
/// <summary> /// For each type, get an estimate of the probability that the given shape is of the given type /// </summary> /// <param name="cache"></param> /// <param name="shape"></param> /// <param name="types"></param> /// <param name="featureSketch"></param> /// <returns></returns> private Dictionary <ShapeType, RecognitionResult> computeRecognitionProbabilities( SubstrokeCollection substrokes, FeatureSketch featureSketch) { PhantomShape shape = new PhantomShape(); shape.AddSubstrokes(substrokes); Dictionary <ShapeType, RecognitionResult> results = Data.Utils.replaceValues( _gateRecognizer.RecognitionResults(shape, LogicDomain.Gates), r => { return((RecognitionResult)r); }); foreach (ShapeType type in LogicDomain.Types) { if (!results.ContainsKey(type)) { results.Add(type, computeRecognitionProbabilityForTextOrWire(substrokes, type, featureSketch)); } } return(results); }
// Pre public override void TranslateC2T(MECMOD.Shape cShape) { PARTITF.Pad cPad = (PARTITF.Pad)cShape; // 스케치 변환 FeatureSketch SketchManager = new FeatureSketch(PartManager); SketchManager.TranslateC2T(cPad.Sketch); string name = cPad.get_Name(); PARTITF.Limit first = cPad.FirstLimit; PARTITF.Limit second = cPad.SecondLimit; TransCAD.StdExtrudeEndType firstCond = TransCAD.StdExtrudeEndType.Blind; TransCAD.StdExtrudeEndType secondCond = TransCAD.StdExtrudeEndType.Blind; if (first.LimitMode.ToString() == "catUpToLastLimit") { firstCond = TransCAD.StdExtrudeEndType.ThroughAll; } if (second.LimitMode.ToString() == "catUpToLastLimit") { secondCond = TransCAD.StdExtrudeEndType.ThroughAll; } bool isFlip = false; if (cPad.DirectionOrientation == PARTITF.CatPrismOrientation.catInverseOrientation) { isFlip = true; } PartManager.tFeatures.AddNewSolidProtrusionExtrudeFeature(name, SketchManager.tReference, first.Dimension.Value, firstCond, second.Dimension.Value, secondCond, isFlip); }