protected void TestCase_GetAssociatedEntries_ManagerWithThreeOverlappingEntriesThatMatchAMsg( bool Entry1Override, bool Entry2Override, bool Entry3Override, bool Entry1Matches, bool Entry2Matches, bool Entry3Matches) { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry1 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 16, 0, 127); mappingEntry1.OverrideDuplicates = Entry1Override; IMappingEntry mappingEntry2 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 4, 5, 10, 20); mappingEntry2.OverrideDuplicates = Entry2Override; IMappingEntry mappingEntry3 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 5, 5, 15, 15); mappingEntry3.OverrideDuplicates = Entry3Override; int id1 = mappingMgr.AddMappingEntry(mappingEntry1); int id2 = mappingMgr.AddMappingEntry(mappingEntry2); int id3 = mappingMgr.AddMappingEntry(mappingEntry3); MssMsg msg = Factory_MssMsg_InitializedValues( DEFAULT_MSG_TYPE, /*matches all entries*/ 5, /*matches all*/ 15, /*matches all*/ 100 /*doesn't need to match anything*/); var matchingEntries = mappingMgr.GetCopiesOfMappingEntriesForMsg(msg); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id1) == Entry1Matches); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id2) == Entry2Matches); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id3) == Entry3Matches); }
public void GetAssociatedEntries_MsgMatchesFirstTwoEntriesAndOverrideDuplicatesIsTrueForTheThirdEntry_FirstTwoEntriesAreReturned() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry1 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 16, 0, 127); IMappingEntry mappingEntry2 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 8, 0, 64); IMappingEntry mappingEntry3 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 7, 16, 60, 127); mappingEntry3.OverrideDuplicates = true; int id1 = mappingMgr.AddMappingEntry(mappingEntry1); int id2 = mappingMgr.AddMappingEntry(mappingEntry2); int id3 = mappingMgr.AddMappingEntry(mappingEntry3); MssMsg msg = Factory_MssMsg_InitializedValues( DEFAULT_MSG_TYPE, /*matches all*/ 7, /*matches all*/ 10, /*only matches entries 1 and 2*/ 100 /*doesn't need to match anything*/); var matchingEntries = mappingMgr.GetCopiesOfMappingEntriesForMsg(msg); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id1)); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id2)); Assert.IsFalse(matchingEntries.Any(entry => entry.Id == id3)); }
public void AddMappingEntry_SingleEntry_SuccessfullyAdded() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry = Factory_IMappingEntry_Basic(); int newId = mappingMgr.AddMappingEntry(mappingEntry); Assert.AreEqual(mappingEntry.Id, mappingMgr.GetCopyOfMappingEntryById(newId).Value.Id); }
public void AddMappingEntry_SingleEntry_AddsExactlyOneEntry() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry = Factory_IMappingEntry_Basic(); mappingMgr.AddMappingEntry(mappingEntry); Assert.AreEqual(1, mappingMgr.GetNumEntries()); }
public void RemoveMappingEntry_ManagerHasOneEntry_ExistingEntryIsRemoved() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry = Factory_IMappingEntry_Basic(); mappingMgr.AddMappingEntry(mappingEntry); mappingMgr.RemoveMappingEntry(0); Assert.AreEqual(0, mappingMgr.GetNumEntries()); }
public void Init(MssMsg mssMsg, List <MssParamInfo> variableParamInfoList, IMappingEntry mappingEntry) { IStaticMssMsgInfo inMsgInfo = Factory_StaticMssMsgInfo.Create(mssMsg.Type); double relativeData1 = (double)mssMsg.Data1 / (double)(inMsgInfo.MaxData1Value - inMsgInfo.MinData1Value); double relativeData2 = (double)mssMsg.Data2 / (double)(inMsgInfo.MaxData2Value - inMsgInfo.MinData2Value); double relativeData3 = (double)mssMsg.Data3 / (double)(inMsgInfo.MaxData3Value - inMsgInfo.MinData3Value); this.Init(relativeData1, relativeData2, relativeData3, variableParamInfoList, mappingEntry); }
//Can be called multiple times. public void Init(double relData1, double relData2, double relData3, List <MssParamInfo> variableParamInfoList, IMappingEntry mappingEntry) { this.VariableParamInfoList = variableParamInfoList; this.TransformParamInfoList = mappingEntry.CurveShapeInfo.ParamInfoList; this.PrimaryInputSource = mappingEntry.PrimaryInputSource; this.RelData1 = relData1; this.RelData2 = relData2; this.RelData3 = relData3; this.CurveEquations = mappingEntry.CurveShapeInfo.CurveEquations; this.PointEquations = mappingEntry.CurveShapeInfo.PointEquations; }
public void ProcessMssMsg_MapsOutsideOfRange_NoMsgsAreReturned() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOn, 1, 10, 64); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mapsNoteOffToSameMsg = Factory_IMappingEntry( MssMsgType.NoteOn, 1, 1, 10, 10, MssMsgType.NoteOn, 1, 1, 10, 10); matchingEntries.Add(mapsNoteOffToSameMsg); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, true); }
public void MoveEntryUp_MoveBottomEntryUpInManagerThatHasTwoEntries_EntriesAreSwapped() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry1 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 1, 0, 0); IMappingEntry mappingEntry2 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 2, 2, 3, 3); mappingMgr.AddMappingEntry(mappingEntry1); mappingMgr.AddMappingEntry(mappingEntry2); mappingMgr.MoveEntryUp(1); List <IMappingEntry> mappingEntryList = mappingMgr.GetCopyOfMappingEntryList(); Assert.AreEqual(mappingEntry2.Id, mappingEntryList[0].Id); Assert.AreEqual(mappingEntry1.Id, mappingEntryList[1].Id); }
public void GetAssociatedEntries_MsgMatchesOneEntry_TheAssociatedEntryIsReturned() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 3, 0, 10); int newId = mappingMgr.AddMappingEntry(mappingEntry); MssMsg msg = Factory_MssMsg_InitializedValues( DEFAULT_MSG_TYPE, /*same as type in manager*/ 2, /*between 1 and 3*/ 5, /*between 0 and 10*/ 100 /*doesn't need to match anything*/); var matchingEntries = mappingMgr.GetCopiesOfMappingEntriesForMsg(msg); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == newId)); }
public void ProcessMssMsg_MapsToRangeOfSameSize_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.PolyAftertouch, 16, 64, 100); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.PolyAftertouch, 15, 16, 60, 70, MssMsgType.PolyAftertouch, 1, 2, 50, 60); matchingEntries.Add(mappingEntry); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.PolyAftertouch, 2, 54, 100)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void ProcessMssMsg_MapsTypeData1AndData2_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOff, 1, 64, 0); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.NoteOff, 1, 1, 64, 64, MssMsgType.CC, 2, 2, 100, 100); matchingEntries.Add(mappingEntry); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.CC, 2, 100, 0)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void ProcessMssMsg_MapsToSameMsg_MsgIsUnaffected() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOff, 1, 64, 0); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mapsNoteOffToSameMsg = Factory_IMappingEntry( MssMsgType.NoteOff, 1, 1, 64, 64, MssMsgType.NoteOff, 1, 1, 64, 64); matchingEntries.Add(mapsNoteOffToSameMsg); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add((MssMsg)inputMsg.Clone()); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void ProcessMssMsg_MapsCCToPitchbend_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.CC, 1, 10, 127); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.CC, 1, 1, 10, 10, MssMsgType.PitchBend, 1, 1, 10, 10); matchingEntries.Add(mappingEntry); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.PitchBend, 1, 10, 16383)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void ProcessMssMsg_MapsToRangeOfDifferentSize_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOn, 2, 10, 100); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.NoteOn, 1, 3, 9, 10, MssMsgType.NoteOn, 1, 5, 0, 127); matchingEntries.Add(mappingEntry); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.NoteOn, 3, 127, 100)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
/// <summary> /// Initializes this MappingDlg. Init() must be called for this MappingDlg to work correctly. /// </summary> /// <param name="mappingEntry"> MappingEntry instance to use for the mappingEntry member variable.</param> /// <param name="useMappingEntryForDefaultValues"> /// If true, use the data in <paramref name="mappingEntry"/> to populate the entry fields. /// </param> public void Init(IMappingEntry mappingEntry, bool useMappingEntryForDefaultValues, Factory_MssMsgRangeEntryMetadata msgMetadataFactory, IFactory_MssMsgInfo msgInfoFactory, IDryMssEventOutputPort dryEventOut) { this.mappingEntry = mappingEntry; this.UseMappingEntryForDefaultValues = useMappingEntryForDefaultValues; this.MsgMetadataFactory = msgMetadataFactory; this.MsgInfoFactory = msgInfoFactory; this.dryEventOut = dryEventOut; this.dryEventOut.DryMssEventRecieved += new DryMssEventRecievedEventHandler(dryMssEventOutputPort_DryMssEventRecieved); if (useMappingEntryForDefaultValues == true) { //Initializes inMsgMetadata and outMsgMetadata this.inTypeCombo.Text = MssMsg.MssMsgTypeNames[(int)this.mappingEntry.InMssMsgRange.MsgType]; this.outTypeCombo.Text = MssMsg.MssMsgTypeNames[(int)this.mappingEntry.OutMssMsgRange.MsgType]; this.inMsgMetadata.UseExistingMsgRange(mappingEntry.InMssMsgRange); this.outMsgMetadata.UseExistingMsgRange(mappingEntry.OutMssMsgRange); //This could be disabled if we are editing a mapping with an input type like Parameter. If //this is disabled then we don't want to check it off because that will make it impossible //to edit the output fields. if (this.outSameAsInCheckBox.Enabled) { this.outSameAsInCheckBox.Checked = (this.mappingEntry.InMssMsgRange.Equals(this.mappingEntry.OutMssMsgRange)); } } else { //Initializes inMsgMetadata and outMsgMetadata this.inTypeCombo.SelectedIndex = 0; this.mappingEntry.CurveShapeInfo = new CurveShapeInfo(); this.mappingEntry.CurveShapeInfo.InitWithDefaultValues(); this.outSameAsInCheckBox.Checked = true; } }
public void MoveEntryUp_MoveThirdEntryUpInManagerThatHasFourEntries_OnlyMiddleTwoEntriesAreSwapped() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry1 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 1, 0, 0); IMappingEntry mappingEntry2 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 2, 2, 0, 0); IMappingEntry mappingEntry3 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 3, 3, 0, 0); IMappingEntry mappingEntry4 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 4, 4, 0, 0); mappingMgr.AddMappingEntry(mappingEntry1); mappingMgr.AddMappingEntry(mappingEntry2); mappingMgr.AddMappingEntry(mappingEntry3); mappingMgr.AddMappingEntry(mappingEntry4); mappingMgr.MoveEntryUp(2); List <IMappingEntry> mappingEntryList = mappingMgr.GetCopyOfMappingEntryList(); Assert.AreEqual(mappingEntry1.Id, mappingEntryList[0].Id); Assert.AreEqual(mappingEntry3.Id, mappingEntryList[1].Id); Assert.AreEqual(mappingEntry2.Id, mappingEntryList[2].Id); Assert.AreEqual(mappingEntry4.Id, mappingEntryList[3].Id); }
public void GetAssociatedEntries_MsgOnlyMatchesPartsOfEntriesInMgr_TheEnumerationReturnedIsEmpty() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry1 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 1, 3, 127); IMappingEntry mappingEntry2 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 2, 16, 2, 2); IMappingEntry mappingEntry3 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(SECONDARY_MSG_TYPE, 1, 1, 2, 2); mappingMgr.AddMappingEntry(mappingEntry1); mappingMgr.AddMappingEntry(mappingEntry2); mappingMgr.AddMappingEntry(mappingEntry3); MssMsg msg = Factory_MssMsg_InitializedValues( DEFAULT_MSG_TYPE, /*matches entries 1 and 2*/ 1, /*matches entries 1 and 3*/ 2, /*matches entries 2 and 3*/ 100 /*doesn't need to match anything*/); var matchingEntries = mappingMgr.GetCopiesOfMappingEntriesForMsg(msg); Assert.IsEmpty(matchingEntries.ToList()); }
public void ProcessMssMsg_MultipleMappings_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOn, 1, 64, 100); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.NoteOn, 1, 1, 64, 64, MssMsgType.NoteOn, 2, 2, 65, 65); matchingEntries.Add(mappingEntry); IMappingEntry mappingEntry2 = Factory_IMappingEntry( MssMsgType.NoteOn, 1, 1, 64, 64, MssMsgType.CC, 3, 3, 66, 66); matchingEntries.Add(mappingEntry2); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.NoteOn, 2, 65, 100)); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.CC, 3, 66, 100)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void Init(MssMsg mssMsg, List<MssParamInfo> variableParamInfoList, IMappingEntry mappingEntry) { IStaticMssMsgInfo inMsgInfo = Factory_StaticMssMsgInfo.Create(mssMsg.Type); double relativeData1 = (double)mssMsg.Data1 / (double)(inMsgInfo.MaxData1Value - inMsgInfo.MinData1Value); double relativeData2 = (double)mssMsg.Data2 / (double)(inMsgInfo.MaxData2Value - inMsgInfo.MinData2Value); double relativeData3 = (double)mssMsg.Data3 / (double)(inMsgInfo.MaxData3Value - inMsgInfo.MinData3Value); this.Init(relativeData1, relativeData2, relativeData3, variableParamInfoList, mappingEntry); }
//Can be called multiple times. public void Init(double relData1, double relData2, double relData3, List<MssParamInfo> variableParamInfoList, IMappingEntry mappingEntry) { this.VariableParamInfoList = variableParamInfoList; this.TransformParamInfoList = mappingEntry.CurveShapeInfo.ParamInfoList; this.PrimaryInputSource = mappingEntry.PrimaryInputSource; this.RelData1 = relData1; this.RelData2 = relData2; this.RelData3 = relData3; this.CurveEquations = mappingEntry.CurveShapeInfo.CurveEquations; this.PointEquations = mappingEntry.CurveShapeInfo.PointEquations; }
/// <summary> /// Evaluates the equations for the given mappingEntry. All control point equations will /// be evaluated and returned pointList. Curve equations will be evaluated at equally spaced /// sample points and the return values will be returned in curveYValues. This function is /// used by the GUI to create the graph representing the transformation on a mapping. /// </summary> /// <param name="xDistanceBetweenPoints"> /// The maximum horizontal distance between any two points. /// </param> /// <param name="variableParamInfoList"> /// A list of cloned variable parameter info for each variable parameter. /// </param> /// <param name="mappingEntry"> /// The mapping entry to evaluate equations for. /// </param> /// <param name="controlPointList"> /// The evaluated control points are returned in this list /// </param> /// <param name="curvePointsByCurveList"> /// This will contain the evaluated list of XyPoints for each curve. /// </param> /// <param name="erroneousControlPointIndexSet"> /// empty if all points had valid equations. Otherwise the index of at least one point with an invalid equation. /// </param> /// <param name="erroneousCurveIndexSet"> /// -1 if there is an invalid control point or if all curve equations are valid. Otherwise /// the index of the first curve with an invalid equation. /// </param> /// <returns> /// true if all equations could be evaluated and false otherwise. The out parameters are only /// garunteed to be valid if the return value is true. /// </returns> public bool SampleExpressionWithDefaultInputValues( double xDistanceBetweenPoints, List<MssParamInfo> variableParamInfoList, IMappingEntry mappingEntry, out List<XyPoint<double>> controlPointList, out List<List<XyPoint<double>>> curvePointsByCurveList, out HashSet<int> erroneousControlPointIndexSet, out HashSet<int> erroneousCurveIndexSet ) { Logger.HighVolume(23, String.Format("Sampling Expression - xGap: {0}, variableParamInfo: {1}", xDistanceBetweenPoints, EnumerableUtils.ToString(variableParamInfoList))); erroneousControlPointIndexSet = new HashSet<int>(); erroneousCurveIndexSet = new HashSet<int>(); //Initialize this list from an array so that elements can be set directly in parallel. curvePointsByCurveList = new List<List<XyPoint<double>>>(new List<XyPoint<double>>[mappingEntry.CurveShapeInfo.CurveEquations.Count]); EvaluationCurveJob evalJob = new EvaluationCurveJob(); var controlPointValuesStatus = CalculateControlPointValues( variableParamInfoList, mappingEntry.CurveShapeInfo.ParamInfoList, mappingEntry.CurveShapeInfo.PointEquations, ref erroneousControlPointIndexSet); controlPointList = controlPointValuesStatus.Value; //Need to make a second version of these variable as out parameters cannot be used in Parallel.For loops. List<XyPoint<double>> controlPointList2 = controlPointList; List<List<XyPoint<double>>> curvePointsByCurveList2 = curvePointsByCurveList; HashSet<int> erroneousCurveIndexSet2 = erroneousCurveIndexSet; if (controlPointValuesStatus.IsValid == false) { return false; } int numCurves = mappingEntry.CurveShapeInfo.CurveEquations.Count; bool noErrorsEncountered = true; Parallel.For(0, numCurves, (curveIndex, loopState) => { double curveStartXVal = 0; double curveEndXVal = 1; if (curveIndex > 0) { curveStartXVal = controlPointList2[curveIndex - 1].X; } if (curveIndex < numCurves - 1) { curveEndXVal = controlPointList2[curveIndex].X; } int numPointsInCurve = (int)((curveEndXVal - curveStartXVal) / xDistanceBetweenPoints) + 1; Logger.HighVolume(24, string.Format("Sampling curve {0}. Points in curve: {1}", curveIndex, numPointsInCurve)); if (numPointsInCurve == 0) { return; } List<XyPoint<double>> curCurvePoints = new List<XyPoint<double>>(new XyPoint<double>[numPointsInCurve]); curvePointsByCurveList2[curveIndex] = curCurvePoints; //Evaluates the first point in the curve before createing threads to evaluate the //rest of the points. If evaluating each point is going to throw an exception then //this will improve performance by letting the code exit early. var firstEvalStatus = evaluateCurveAtXVal(curveStartXVal, curveIndex, mappingEntry, variableParamInfoList, controlPointList2); if (firstEvalStatus.IsValid == false) { lock (erroneousCurveIndexSet2) { Logger.HighVolume(25, string.Format("Sampling exiting early as first eval status for curve {0} was invalid", curveIndex)); erroneousCurveIndexSet2.Add(curveIndex); noErrorsEncountered = false; loopState.Stop(); return; } } curCurvePoints[0] = firstEvalStatus.Value; Parallel.For(1, numPointsInCurve, pointIndex => { //Calling loopState.Stop() does not immedateally stop all threads so that they //exit without doing any more processing. if (loopState.ShouldExitCurrentIteration) { return; } double curXVal = curveStartXVal + (pointIndex * xDistanceBetweenPoints); var evalStatus = evaluateCurveAtXVal(curXVal, curveIndex, mappingEntry, variableParamInfoList, controlPointList2); if (evalStatus.IsValid == false) { lock (erroneousCurveIndexSet2) { Logger.HighVolume(25, string.Format("Sampling exiting. point {0} for curve {1} was invalid.", pointIndex, curveIndex)); erroneousCurveIndexSet2.Add(curveIndex); noErrorsEncountered = false; loopState.Stop(); return; } } curCurvePoints[pointIndex] = evalStatus.Value; }); }); return noErrorsEncountered; }
protected ReturnStatus<XyPoint<double>> evaluateCurveAtXVal(double inputXVal, int curveIndex, IMappingEntry mappingEntry, List<MssParamInfo> variableParamInfoList, List<XyPoint<double>> controlPointList) { //For each sample point data1 data2 and data3 will be set to the X value of the //sample point. double relData1 = inputXVal; double relData2 = inputXVal; double relData3 = inputXVal; IStaticMssMsgInfo inMsgInfo = Factory_StaticMssMsgInfo.Create(mappingEntry.InMssMsgRange.MsgType); //If curXVal is outside of the relative input range for data 1 then set //relData1 to NaN double max = (double)inMsgInfo.MaxData1Value; double min = (double)inMsgInfo.MinData1Value; double bottom = (double)mappingEntry.InMssMsgRange.Data1RangeBottom; double top = (double)mappingEntry.InMssMsgRange.Data1RangeTop; if (inputXVal < ((bottom - min) / (max - min + 1)) || inputXVal > ((top - min) / (max - min + 1))) { relData1 = double.NaN; } //If curXVal is outside of the relative input range for data 2 then set relData2 //to NaN max = (double)inMsgInfo.MaxData2Value; min = (double)inMsgInfo.MinData2Value; bottom = (double)mappingEntry.InMssMsgRange.Data2RangeBottom; top = (double)mappingEntry.InMssMsgRange.Data2RangeTop; if (inputXVal < ((bottom - min) / (max - min + 1)) || inputXVal > ((top - min) / (max - min + 1))) { relData2 = double.NaN; } var evalInput = new EvaluationCurveInput(); evalInput.Init( relData1, relData2, relData3, variableParamInfoList, mappingEntry); var evalJob = new EvaluationCurveJob(); var returnedExpression = CreateExpressionFromString(mappingEntry.CurveShapeInfo.CurveEquations[curveIndex], EvalType.Curve); if (returnedExpression.IsValid == false) { return new ReturnStatus<XyPoint<double>>(); } evalJob.Configure(evalInput, controlPointList, returnedExpression.Value); evalJob.Execute(); if (evalJob.OutputIsValid) { var curPoint = new XyPoint<double>(inputXVal, evalJob.OutputVal); return new ReturnStatus<XyPoint<double>>(curPoint); } else { return new ReturnStatus<XyPoint<double>>(); } }
/// <summary> /// Evaluates the equations for the given mappingEntry. All control point equations will /// be evaluated and returned pointList. Curve equations will be evaluated at equally spaced /// sample points and the return values will be returned in curveYValues. This function is /// used by the GUI to create the graph representing the transformation on a mapping. /// </summary> /// <param name="xDistanceBetweenPoints"> /// The maximum horizontal distance between any two points. /// </param> /// <param name="variableParamInfoList"> /// A list of cloned variable parameter info for each variable parameter. /// </param> /// <param name="mappingEntry"> /// The mapping entry to evaluate equations for. /// </param> /// <param name="controlPointList"> /// The evaluated control points are returned in this list /// </param> /// <param name="curvePointsByCurveList"> /// This will contain the evaluated list of XyPoints for each curve. /// </param> /// <param name="erroneousControlPointIndexSet"> /// empty if all points had valid equations. Otherwise the index of at least one point with an invalid equation. /// </param> /// <param name="erroneousCurveIndexSet"> /// -1 if there is an invalid control point or if all curve equations are valid. Otherwise /// the index of the first curve with an invalid equation. /// </param> /// <returns> /// true if all equations could be evaluated and false otherwise. The out parameters are only /// garunteed to be valid if the return value is true. /// </returns> public bool SampleExpressionWithDefaultInputValues( double xDistanceBetweenPoints, List <MssParamInfo> variableParamInfoList, IMappingEntry mappingEntry, out List <XyPoint <double> > controlPointList, out List <List <XyPoint <double> > > curvePointsByCurveList, out HashSet <int> erroneousControlPointIndexSet, out HashSet <int> erroneousCurveIndexSet ) { Logger.HighVolume(23, String.Format("Sampling Expression - xGap: {0}, variableParamInfo: {1}", xDistanceBetweenPoints, EnumerableUtils.ToString(variableParamInfoList))); erroneousControlPointIndexSet = new HashSet <int>(); erroneousCurveIndexSet = new HashSet <int>(); //Initialize this list from an array so that elements can be set directly in parallel. curvePointsByCurveList = new List <List <XyPoint <double> > >(new List <XyPoint <double> > [mappingEntry.CurveShapeInfo.CurveEquations.Count]); EvaluationCurveJob evalJob = new EvaluationCurveJob(); var controlPointValuesStatus = CalculateControlPointValues( variableParamInfoList, mappingEntry.CurveShapeInfo.ParamInfoList, mappingEntry.CurveShapeInfo.PointEquations, ref erroneousControlPointIndexSet); controlPointList = controlPointValuesStatus.Value; //Need to make a second version of these variable as out parameters cannot be used in Parallel.For loops. List <XyPoint <double> > controlPointList2 = controlPointList; List <List <XyPoint <double> > > curvePointsByCurveList2 = curvePointsByCurveList; HashSet <int> erroneousCurveIndexSet2 = erroneousCurveIndexSet; if (controlPointValuesStatus.IsValid == false) { return(false); } int numCurves = mappingEntry.CurveShapeInfo.CurveEquations.Count; bool noErrorsEncountered = true; Parallel.For(0, numCurves, (curveIndex, loopState) => { double curveStartXVal = 0; double curveEndXVal = 1; if (curveIndex > 0) { curveStartXVal = controlPointList2[curveIndex - 1].X; } if (curveIndex < numCurves - 1) { curveEndXVal = controlPointList2[curveIndex].X; } int numPointsInCurve = (int)((curveEndXVal - curveStartXVal) / xDistanceBetweenPoints) + 1; Logger.HighVolume(24, string.Format("Sampling curve {0}. Points in curve: {1}", curveIndex, numPointsInCurve)); if (numPointsInCurve == 0) { return; } List <XyPoint <double> > curCurvePoints = new List <XyPoint <double> >(new XyPoint <double> [numPointsInCurve]); curvePointsByCurveList2[curveIndex] = curCurvePoints; //Evaluates the first point in the curve before createing threads to evaluate the //rest of the points. If evaluating each point is going to throw an exception then //this will improve performance by letting the code exit early. var firstEvalStatus = evaluateCurveAtXVal(curveStartXVal, curveIndex, mappingEntry, variableParamInfoList, controlPointList2); if (firstEvalStatus.IsValid == false) { lock (erroneousCurveIndexSet2) { Logger.HighVolume(25, string.Format("Sampling exiting early as first eval status for curve {0} was invalid", curveIndex)); erroneousCurveIndexSet2.Add(curveIndex); noErrorsEncountered = false; loopState.Stop(); return; } } curCurvePoints[0] = firstEvalStatus.Value; Parallel.For(1, numPointsInCurve, pointIndex => { //Calling loopState.Stop() does not immedateally stop all threads so that they //exit without doing any more processing. if (loopState.ShouldExitCurrentIteration) { return; } double curXVal = curveStartXVal + (pointIndex * xDistanceBetweenPoints); var evalStatus = evaluateCurveAtXVal(curXVal, curveIndex, mappingEntry, variableParamInfoList, controlPointList2); if (evalStatus.IsValid == false) { lock (erroneousCurveIndexSet2) { Logger.HighVolume(25, string.Format("Sampling exiting. point {0} for curve {1} was invalid.", pointIndex, curveIndex)); erroneousCurveIndexSet2.Add(curveIndex); noErrorsEncountered = false; loopState.Stop(); return; } } curCurvePoints[pointIndex] = evalStatus.Value; }); }); return(noErrorsEncountered); }
protected ReturnStatus <XyPoint <double> > evaluateCurveAtXVal(double inputXVal, int curveIndex, IMappingEntry mappingEntry, List <MssParamInfo> variableParamInfoList, List <XyPoint <double> > controlPointList) { //For each sample point data1 data2 and data3 will be set to the X value of the //sample point. double relData1 = inputXVal; double relData2 = inputXVal; double relData3 = inputXVal; IStaticMssMsgInfo inMsgInfo = Factory_StaticMssMsgInfo.Create(mappingEntry.InMssMsgRange.MsgType); //If curXVal is outside of the relative input range for data 1 then set //relData1 to NaN double max = (double)inMsgInfo.MaxData1Value; double min = (double)inMsgInfo.MinData1Value; double bottom = (double)mappingEntry.InMssMsgRange.Data1RangeBottom; double top = (double)mappingEntry.InMssMsgRange.Data1RangeTop; if (inputXVal < ((bottom - min) / (max - min + 1)) || inputXVal > ((top - min) / (max - min + 1))) { relData1 = double.NaN; } //If curXVal is outside of the relative input range for data 2 then set relData2 //to NaN max = (double)inMsgInfo.MaxData2Value; min = (double)inMsgInfo.MinData2Value; bottom = (double)mappingEntry.InMssMsgRange.Data2RangeBottom; top = (double)mappingEntry.InMssMsgRange.Data2RangeTop; if (inputXVal < ((bottom - min) / (max - min + 1)) || inputXVal > ((top - min) / (max - min + 1))) { relData2 = double.NaN; } var evalInput = new EvaluationCurveInput(); evalInput.Init( relData1, relData2, relData3, variableParamInfoList, mappingEntry); var evalJob = new EvaluationCurveJob(); var returnedExpression = CreateExpressionFromString(mappingEntry.CurveShapeInfo.CurveEquations[curveIndex], EvalType.Curve); if (returnedExpression.IsValid == false) { return(new ReturnStatus <XyPoint <double> >()); } evalJob.Configure(evalInput, controlPointList, returnedExpression.Value); evalJob.Execute(); if (evalJob.OutputIsValid) { var curPoint = new XyPoint <double>(inputXVal, evalJob.OutputVal); return(new ReturnStatus <XyPoint <double> >(curPoint)); } else { return(new ReturnStatus <XyPoint <double> >()); } }