public override Fragment GetItem(int position, Fragment.SavedState fragmentSavedState = null) { var fragmentInfo = FragmentsInfo[position]; var fragmentClass = Class.FromType(fragmentInfo.FragmentType); var fragment = FragmentFactory.Instantiate( fragmentClass.ClassLoader, fragmentClass.Name ); if (!(fragment is IMvxFragmentView mvxFragment)) { return(fragment); } if (mvxFragment.GetType().IsFragmentCacheable(_activityType) && fragmentSavedState != null) { return(fragment); } mvxFragment.ViewModel = GetViewModel(fragmentInfo); fragment.Arguments = GetArguments(fragmentInfo); return(fragment); }
public static void Main() { ICoreFactory coreFactory = new CoreFactory(); IFragmentFactory fragment = new FragmentFactory(); IRepository powerPlantRepository = new PowerPlantRepository(); CommandInterpreter commandInterpreter = new CommandInterpreter(coreFactory, fragment, powerPlantRepository); Engine engine = new Engine(commandInterpreter); engine.Run(); }
public static Object EvaluateXPathFragment( XPathNavigator navigator, XPathExpression expression, String expressionText, String property, FragmentFactory fragmentFactory, XPathResultType resultType) { try { if (Log.IsDebugEnabled) { Log.Debug( "Running XPath '{0}' for property '{1}' against Node XML : {2}", expressionText, property, navigator); } var result = navigator.Evaluate(expression); if (result == null) { return(null); } if (result is XPathNodeIterator) { var nodeIterator = result as XPathNodeIterator; if (nodeIterator.Count == 0) { return(null); } if (nodeIterator.Count == 1) { nodeIterator.MoveNext(); return(fragmentFactory.GetEvent(((IHasXmlNode)nodeIterator.Current).GetNode())); } var events = new List <EventBean>(); while (nodeIterator.MoveNext()) { events.Add(fragmentFactory.GetEvent(((IHasXmlNode)nodeIterator.Current).GetNode())); } return(events.ToArray()); } Log.Warn("Error processing XPath property named '" + property + "' expression result is not of type Node or Nodeset"); return(null); } catch (XPathException e) { throw new PropertyAccessException("Error getting property " + property, e); } }
public void AddFragmentItem(FragmentName _name, GameObject ItemPrefab, Sprite _sprite) { if (ItemChild == null) { ItemChild = Instantiate(ItemPrefab, transform).transform; } ItemChild.GetComponent <Image>().sprite = _sprite; ItemChild.GetComponent <FragmentItem>().ItemFragment = FragmentFactory.GetFragment(_name); isEmpty = false; ItemChild.localPosition = Vector3.zero; }
/// <summary> /// Ctor. /// </summary> /// <param name="getterChain">is the chain of getters to retrieve each nested property</param> /// <param name="fragmentFactory">for creating fragments</param> public DOMNestedPropertyGetter(ICollection <EventPropertyGetter> getterChain, FragmentFactory fragmentFactory) { this._domGetterChain = new DOMPropertyGetter[getterChain.Count]; this._fragmentFactory = fragmentFactory; int count = 0; foreach (EventPropertyGetter getter in getterChain) { _domGetterChain[count++] = (DOMPropertyGetter)getter; } }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// </summary> /// <param name="node">node</param> /// <param name="propertyName">prop name</param> /// <param name="fragmentFactory">fragment factory</param> /// <returns>node</returns> public static object GetValueAsNodeFragment( XmlNode node, string propertyName, FragmentFactory fragmentFactory) { var result = GetValueAsNode(node, propertyName); if (result == null) { return null; } return fragmentFactory.GetEvent(result); }
public static void Main() { IInputReader inputReader = new ConsoleReader(); IOutputWriter outputWriter = new ConsoleWriter(); IInputOutputManager inputOutputManager = new IOManager(inputReader, outputWriter); ICoreIdManager coreIdManager = new CoreIdManager(); ICoreFactory coreFactory = new CoreFactory(); IFragmentFactory fragmentFactory = new FragmentFactory(); IPlantController plantController = new PlantController(coreIdManager, coreFactory, fragmentFactory); IInterpreter commandIntepreter = new CommandInterpreter(plantController); IRunnable engine = new Engine(inputOutputManager, commandIntepreter); engine.Run(); }
/// <summary> /// Ctor. /// </summary> /// <param name="propertyName">is the name of the event property for which this getter gets values</param> /// <param name="expressionText">is the property expression itself</param> /// <param name="xPathExpression">is a compile XPath expression</param> /// <param name="resultType">is the resulting type</param> /// <param name="optionalCastToType">if non-null then the return value of the xpath expression is cast to this value</param> /// <param name="fragmentFactory">for creating fragments, or null in none to be created</param> public XPathPropertyGetter(String propertyName, String expressionText, XPathExpression xPathExpression, XPathResultType resultType, Type optionalCastToType, FragmentFactory fragmentFactory) { _expression = xPathExpression; _expressionText = expressionText; _property = propertyName; _resultType = resultType; _fragmentFactory = fragmentFactory; if ((optionalCastToType != null) && (optionalCastToType.IsArray)) { _isCastToArray = true; if (resultType != XPathResultType.NodeSet) { throw new ArgumentException("Array cast-to types require XPathResultType.NodeSet as the XPath result type"); } optionalCastToType = optionalCastToType.GetElementType(); } else { _isCastToArray = false; } if (optionalCastToType != null) { _simpleTypeParser = SimpleTypeParserFactory.GetParser(optionalCastToType); } else { _simpleTypeParser = null; } if (optionalCastToType == typeof(XmlNode)) { _optionalCastToType = null; } else { _optionalCastToType = optionalCastToType; } }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// </summary> /// <param name="node">node</param> /// <param name="propertyName">prop name</param> /// <param name="fragmentFactory">fragment factory</param> /// <returns>node</returns> public static object GetValueAsNodeFragmentArray( XmlNode node, string propertyName, FragmentFactory fragmentFactory) { var result = GetValueAsNodeArray(node, propertyName); if (result == null || result.Length == 0) { return new EventBean[0]; } var events = new EventBean[result.Length]; var count = 0; for (var i = 0; i < result.Length; i++) { events[count++] = fragmentFactory.GetEvent(result[i]); } return events; }
/// <summary> /// Ctor. /// </summary> /// <param name="propertyName">property name</param> /// <param name="mapKey">key in map</param> /// <param name="fragmentFactory">for creating fragments</param> public DOMMapGetter(String propertyName, String mapKey, FragmentFactory fragmentFactory) { _propertyMap = propertyName; _mapKey = mapKey; _fragmentFactory = fragmentFactory; }
/// <summary> /// Ctor. /// </summary> /// <param name="propertyName">property name</param> /// <param name="index">index</param> /// <param name="fragmentFactory">for creating fragments if required</param> public DOMIndexedGetter(String propertyName, int index, FragmentFactory fragmentFactory) { _propertyName = propertyName; _index = index; _fragmentFactory = fragmentFactory; }
/// <summary> /// Ctor. /// </summary> /// <param name="propertyName">property name</param> /// <param name="fragmentFactory">for creating fragments</param> /// <param name="isArray">if this is an array property</param> public DOMComplexElementGetter(String propertyName, FragmentFactory fragmentFactory, bool isArray) { _propertyName = propertyName; _fragmentFactory = fragmentFactory; _isArray = isArray; }
/// <summary> /// Ctor. /// </summary> /// <param name="getter">property getter returning the parent node</param> /// <param name="index">to get item at</param> /// <param name="fragmentFactory">for creating fragments, or null if not creating fragments</param> public XPathPropertyArrayItemGetter(EventPropertyGetterSPI getter, int index, FragmentFactory fragmentFactory) { _getter = getter; _index = index; _fragmentFactory = fragmentFactory; }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// </summary> /// <param name="node">The node.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="fragmentFactory">The fragment factory.</param> /// <returns></returns> public static object GetValueAsNodeFragmentArray(object node, String propertyName, FragmentFactory fragmentFactory) { var result = GetValueAsNodeArray(node, propertyName); if ((result == null) || (result.Length == 0)) { return(new EventBean[0]); } var events = new EventBean[result.Length]; int count = 0; for (int ii = 0; ii < result.Length; ii++) { var item = result.GetValue(ii); if (item is XContainer container) { events[count++] = fragmentFactory.GetEvent(container); } else if (item is XmlNode xnode) { events[count++] = fragmentFactory.GetEvent(xnode); } else { events[count++] = null; } } return(events); }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// </summary> /// <param name="node">The node.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="fragmentFactory">The fragment factory.</param> /// <returns></returns> public static object GetValueAsNodeFragment(object node, String propertyName, FragmentFactory fragmentFactory) { var result = GetValueAsNode(node, propertyName); if (result is XContainer container) { return(fragmentFactory.GetEvent(container)); } else if (result is XmlNode xnode) { return(fragmentFactory.GetEvent(xnode)); } else { return(null); } }
/// <summary> /// Ctor. /// </summary> /// <param name="getter">property getter returning the parent node</param> /// <param name="index">to get item at</param> /// <param name="fragmentFactory">for creating fragments, or null if not creating fragments</param> public XPathPropertyArrayItemGetter(EventPropertyGetter getter, int index, FragmentFactory fragmentFactory) { this.getter = getter; this.index = index; this.fragmentFactory = fragmentFactory; }
public AttachFragmentCommand(string[] input, List <ICore> repository) : base(input, repository) { this.fragmentFactory = new FragmentFactory(); }
public IEnumerator EncodeFragments(MemoryRef <Binary> binary, TaggedInterval[] intervals, FragmentFactory factory, string fragmentTypeName, Action <ProgressInfo> progressFeedback) { progressFeedback.Invoke(new ProgressInfo() { title = $"Start {fragmentTypeName} fragment encoder", progress = 0.0f }); // // Prologue // int metricIndex = settings.metricIndex; var numFeatures = factory.GetNumFeatures(ref binary.Ref, metricIndex); var numQuantizedFeatures = factory.GetNumQuantizedFeatures(ref binary.Ref, metricIndex); var numNormalizedFeatures = factory.GetNumNormalizedFeatures(ref binary.Ref, metricIndex); var numTransformedFeatures = numFeatures - numQuantizedFeatures - numNormalizedFeatures; numFragments = 0; foreach (var interval in intervals) { numFragments += interval.numFrames; } // // Generate fragments // FragmentArray fragmentArray = FragmentArray.Create(metricIndex, numFragments, numFeatures); int writeIndex = 0; foreach (var interval in intervals) { int segmentIndex = interval.segmentIndex; Assert.IsTrue( interval.firstFrame >= interval.segment.destination.FirstFrame); Assert.IsTrue( interval.onePastLastFrame <= interval.segment.destination.OnePastLastFrame); int relativeFirstFrame = interval.firstFrame - interval.segment.destination.FirstFrame; int numFrames = interval.numFrames; for (int i = 0; i < numFrames; ++i) { int frameIndex = relativeFirstFrame + i; var timeIndex = TimeIndex.Create( segmentIndex, frameIndex); var samplingTime = SamplingTime.Create(timeIndex); fragmentArray.samplingTimes[writeIndex++] = samplingTime; } } Assert.IsTrue(writeIndex == numFragments); progressFeedback.Invoke(new ProgressInfo() { title = $"Create {fragmentTypeName} fragments", progress = 0.0f }); ICreateFragmentsJob createFragmentsJob = factory.PrepareFragmentCreateJob(ref fragmentArray, ref binary.Ref); JobHandle createFragmentsHandle = createFragmentsJob.Schedule(); yield return(null); if (bCancel) { createFragmentsHandle.Complete(); fragmentArray.Dispose(); yield break; } createFragmentsHandle.Complete(); progressFeedback.Invoke(new ProgressInfo() { title = $"Quantize {fragmentTypeName} fragments", progress = 0.0f }); // // Generate feature quantizers // quantizers = new NativeArray <Quantizer>( numQuantizedFeatures, Allocator.Persistent); ComputeQuantizersJob computeQuantizersJob = new ComputeQuantizersJob() { fragmentArray = fragmentArray, quantizers = Quantizers }; JobHandle computeQuantizersHandle = computeQuantizersJob.Schedule(numQuantizedFeatures, 1); computeQuantizersHandle.Complete(); // // Quantize magnitudes and normalize fragments // int numQuantizedValues = numFragments * numQuantizedFeatures; quantizedValues = new NativeArray <byte>( numQuantizedValues, Allocator.Persistent); NormalizeFeaturesJob normalizeFeaturesJob = new NormalizeFeaturesJob() { numQuantizedFeatures = numQuantizedFeatures, quantizers = Quantizers, quantizedValues = new MemoryArray <byte>(QuantizedValues), fragmentArray = fragmentArray }; JobHandle normalizeFeaturesHandle = normalizeFeaturesJob.Schedule(numFragments, 1); normalizeFeaturesHandle.Complete(); // // Generate bounding boxes for feature normalization // boundingBoxes = new NativeArray <BoundingBox>( numTransformedFeatures, Allocator.Persistent); ComputeBoundingBoxesJob computeBoundingBoxesJob = new ComputeBoundingBoxesJob() { fragmentArray = fragmentArray, numTransformedFeatures = numTransformedFeatures, transformedIndex = numFeatures - numTransformedFeatures, boundingBoxes = BoundingBoxes }; JobHandle computeBoundingBoxesHandle = computeBoundingBoxesJob.Schedule(numTransformedFeatures, 1); computeBoundingBoxesHandle.Complete(); // // Normalize fragments // NormalizeFragmentsJob normalizeFragmentsJob = new NormalizeFragmentsJob() { numTransformedFeatures = numTransformedFeatures, transformedIndex = numFeatures - numTransformedFeatures, boundingBoxes = BoundingBoxes, fragmentArray = fragmentArray }; JobHandle normalizeFragmentsHandle = normalizeFragmentsJob.Schedule(numFragments, 1); normalizeFragmentsHandle.Complete(); // // Product Quantization // progressFeedback.Invoke(new ProgressInfo() { title = $"Prepare training {fragmentTypeName} fragments", progress = 0.0f }); yield return(null); if (bCancel) { fragmentArray.Dispose(); yield break; } int numCodes = numFragments * numFeatures; int numCodeWords = numFeatures * Binary.CodeBook.kNumCodeValues; codes = new NativeArray <byte>(numCodes, Allocator.Persistent); codeWords = new NativeArray <float3>(numCodeWords, Allocator.Persistent); var pqs = ProductQuantizer.Settings.Default; pqs.numAttempts = settings.numAttempts; pqs.numIterations = settings.numIterations; pqs.minimumNumberSamples = settings.minimumNumberSamples; pqs.maximumNumberSamples = settings.maximumNumberSamples; using (var pq = new ProductQuantizer(numFeatures * 3, numFeatures, pqs)) { using (ProductQuantizer.TrainingData trainingData = pq.ScheduleTraining(ref fragmentArray)) { float progression = 0.0f; do { progression = trainingData.FrameUpdate(); progressFeedback.Invoke(new ProgressInfo() { title = $"Train {fragmentTypeName} fragments", progress = progression }); yield return(null); if (bCancel) { trainingData.ForceCompleteCurrentBatch(); fragmentArray.Dispose(); yield break; } }while (progression < 1.0f); trainingData.ForceCompleteCurrentBatch(); } progressFeedback.Invoke(new ProgressInfo() { title = $"Compute {fragmentTypeName} codes", progress = 0.0f }); pq.ComputeCodes(ref fragmentArray, Codes); Assert.IsTrue(pq.centroids.Length == numCodeWords * 3); for (int i = 0; i < numCodeWords; ++i) { float x = pq.centroids[i * 3 + 0]; float y = pq.centroids[i * 3 + 1]; float z = pq.centroids[i * 3 + 2]; var centroid = new float3(x, y, z); var words = CodeWords; words[i] = centroid; } } fragmentArray.Dispose(); }
/// <summary> /// Return the xPath corresponding to the given property. The PropertyName String /// may be simple, nested, indexed or mapped. /// </summary> /// <param name="propertyName">is the event property name</param> /// <param name="namespace">is the default namespace</param> /// <param name="schemaModel">is the schema model</param> /// <param name="xPathContext">is the xpath factory instance to use</param> /// <param name="rootElementName">is the name of the root element</param> /// <param name="eventBeanTypedEventFactory">for type lookup and creation</param> /// <param name="xmlEventType">the resolving type</param> /// <param name="isAllowFragment">whether fragmenting is allowed</param> /// <param name="defaultNamespace">default namespace</param> /// <returns> /// xpath expression /// </returns> /// <throws>EPException is there are XPath errors</throws> public static EventPropertyGetterSPI GetXPathResolution( string propertyName, XPathNamespaceContext xPathContext, string rootElementName, string @namespace, SchemaModel schemaModel, EventBeanTypedEventFactory eventBeanTypedEventFactory, BaseXMLEventType xmlEventType, bool isAllowFragment, string defaultNamespace) { if (Log.IsDebugEnabled) { Log.Debug("Determining XPath expression for property '" + propertyName + "'"); } var ctx = new XPathNamespaceContext(); var namespaces = schemaModel.Namespaces; string defaultNamespacePrefix = null; for (var i = 0; i < namespaces.Count; i++) { var namespacePrefix = "n" + i; ctx.AddNamespace(namespacePrefix, namespaces[i]); if (defaultNamespace != null && defaultNamespace == namespaces[i]) { defaultNamespacePrefix = namespacePrefix; } } var property = PropertyParser.ParseAndWalkLaxToSimple(propertyName); var isDynamic = property.IsDynamic; var rootComplexElement = SchemaUtil.FindRootElement(schemaModel, @namespace, rootElementName); var prefix = ctx.LookupPrefix(rootComplexElement.Namespace); if (prefix == null) { prefix = ""; } else { prefix += ':'; } var xPathBuf = new StringBuilder(); xPathBuf.Append('/'); xPathBuf.Append(prefix); if (rootElementName.StartsWith("//")) { xPathBuf.Append(rootElementName.Substring(2)); } else { xPathBuf.Append(rootElementName); } var parentComplexElement = rootComplexElement; Pair <string, XPathResultType> pair = null; if (!(property is NestedProperty)) { pair = MakeProperty(rootComplexElement, property, ctx, true, isDynamic, defaultNamespacePrefix); if (pair == null) { throw new PropertyAccessException("Failed to locate property '" + propertyName + "' in schema"); } xPathBuf.Append(pair.First); } else { var nestedProperty = (NestedProperty)property; var indexLast = nestedProperty.Properties.Count - 1; for (var i = 0; i < indexLast + 1; i++) { var isLast = i == indexLast; var propertyNested = nestedProperty.Properties[i]; pair = MakeProperty( parentComplexElement, propertyNested, ctx, isLast, isDynamic, defaultNamespacePrefix); if (pair == null) { throw new PropertyAccessException( "Failed to locate property '" + propertyName + "' nested property part '" + property.PropertyNameAtomic + "' in schema"); } var text = propertyNested.PropertyNameAtomic; var obj = SchemaUtil.FindPropertyMapping(parentComplexElement, text); if (obj is SchemaElementComplex) { parentComplexElement = (SchemaElementComplex)obj; } xPathBuf.Append(pair.First); } } var xPath = xPathBuf.ToString(); if (ExecutionPathDebugLog.IsDebugEnabled && Log.IsDebugEnabled) { Log.Debug(".parse XPath for property '" + propertyName + "' is expression=" + xPath); } // Compile assembled XPath expression if (Log.IsDebugEnabled) { Log.Debug( "Compiling XPath expression '" + xPath + "' for property '" + propertyName + "' using namespace context :" + ctx); } XPathExpression expr; try { expr = XPathExpression.Compile(xPath, ctx); } catch (XPathException e) { var detail = "Error constructing XPath expression from property expression '" + propertyName + "' expression '" + xPath + "'"; if (e.Message != null) { throw new EPException(detail + " :" + e.Message, e); } throw new EPException(detail, e); } // get type var item = property.GetPropertyTypeSchema(rootComplexElement); if (item == null && !isDynamic) { return(null); } var resultType = isDynamic ? typeof(XmlNode) : SchemaUtil.ToReturnType(item); FragmentFactory fragmentFactory = null; if (isAllowFragment) { fragmentFactory = new FragmentFactoryDOMGetter(eventBeanTypedEventFactory, xmlEventType, propertyName); } return(new XPathPropertyGetter( xmlEventType, propertyName, xPath, expr, pair.Second, resultType, fragmentFactory)); }
IEnumerator BuildFragments() { GenerateCodeBooks(); allocator.Allocate(codeBooks.Count, ref Binary.codeBooks); int codeBookIndex = 0; foreach (var codeBook in codeBooks) { var metricIndex = codeBook.metric.index; var traitIndex = codeBook.traitIndex; MemoryRef <Binary.CodeBook> destination = new MemoryRef <Binary.CodeBook>(ref Binary.codeBooks[codeBookIndex]); destination.Ref.metricIndex = metricIndex; destination.Ref.traitIndex = traitIndex; var numIntervals = codeBook.intervals.Count; allocator.Allocate(numIntervals, ref destination.Ref.intervals); int intervalIndex = 0; foreach (var interval in codeBook.intervals) { destination.Ref.intervals[intervalIndex] = interval.index; intervalIndex++; } Assert.IsTrue(intervalIndex == codeBook.intervals.Count); { FragmentFactory fragmentFactory = PoseFragmentFactory.Create(); using (CodeBook.FragmentEncoder factory = codeBook.CreateEncoder(ref Binary)) { IEnumerator fragmentEncoder = factory.EncodeFragments(binary, codeBook.intervals.ToArray(), fragmentFactory, "pose", progressInfo => progressFeedback?.Invoke(progressInfo)); while (fragmentEncoder.MoveNext()) { yield return(null); if (bCancel) { factory.CancelEncoding(); fragmentEncoder.MoveNext(); // release resources yield break; } } int numFragments = factory.numFragments; Assert.IsTrue(destination.Ref.numFragments == 0); destination.Ref.numFragments = numFragments; var numFeatures = PoseFragment.GetNumFeatures(ref Binary, metricIndex); var numQuantizedFeatures = PoseFragment.GetNumQuantizedFeatures(ref Binary, metricIndex); var numNormalizedFeatures = PoseFragment.GetNumNormalizedFeatures(ref Binary, metricIndex); var numTransformedFeatures = numFeatures - numQuantizedFeatures - numNormalizedFeatures; destination.Ref.poses.numFragments = numFragments; destination.Ref.poses.numFeatures = (short)numFeatures; destination.Ref.poses.numFeaturesQuantized = (short)numQuantizedFeatures; destination.Ref.poses.numFeaturesNormalized = (short)numNormalizedFeatures; destination.Ref.poses.numFeaturesTransformed = (short)numTransformedFeatures; var numCodes = factory.Codes.Length + factory.QuantizedValues.Length; allocator.Allocate(numCodes, ref destination.Ref.poses.codes); int writeIndex = 0; int readIndexQuantized = 0; int readIndex = 0; for (int i = 0; i < numFragments; ++i) { for (int j = 0; j < numQuantizedFeatures; ++j) { var quantizedValue = factory.QuantizedValues[readIndexQuantized++]; destination.Ref.poses.codes[writeIndex++] = quantizedValue; } for (int j = 0; j < numFeatures; ++j) { var code = factory.Codes[readIndex++]; destination.Ref.poses.codes[writeIndex++] = code; } } Assert.IsTrue(readIndexQuantized == factory.QuantizedValues.Length); Assert.IsTrue(readIndex == factory.Codes.Length); Assert.IsTrue(writeIndex == numCodes); var numCodeWords = factory.CodeWords.Length; allocator.Allocate(numCodeWords, ref destination.Ref.poses.centroids); for (int i = 0; i < numCodeWords; ++i) { destination.Ref.poses.centroids[i] = factory.CodeWords[i]; } allocator.Allocate(numTransformedFeatures, ref destination.Ref.poses.boundingBoxes); Assert.IsTrue(numTransformedFeatures == factory.BoundingBoxes.Length); for (int i = 0; i < numTransformedFeatures; ++i) { destination.Ref.poses.boundingBoxes[i].transform = factory.BoundingBoxes[i].transform; destination.Ref.poses.boundingBoxes[i].extent = factory.BoundingBoxes[i].extent; destination.Ref.poses.boundingBoxes[i].inverseDiagonal = factory.BoundingBoxes[i].inverseDiagonal; } allocator.Allocate(numQuantizedFeatures, ref destination.Ref.poses.quantizers); Assert.IsTrue(numQuantizedFeatures == factory.Quantizers.Length); for (int i = 0; i < numQuantizedFeatures; ++i) { destination.Ref.poses.quantizers[i].minimum = factory.Quantizers[i].minimum; destination.Ref.poses.quantizers[i].range = factory.Quantizers[i].range; } } } { FragmentFactory fragmentFactory = TrajectoryFragmentFactory.Create(); using (CodeBook.FragmentEncoder factory = codeBook.CreateEncoder(ref Binary)) { IEnumerator fragmentEncoder = factory.EncodeFragments(binary, codeBook.intervals.ToArray(), fragmentFactory, "trajectory", progressInfo => progressFeedback?.Invoke(progressInfo)); while (fragmentEncoder.MoveNext()) { yield return(null); if (bCancel) { factory.CancelEncoding(); fragmentEncoder.MoveNext(); // release resources yield break; } } int numFragments = factory.numFragments; Assert.IsTrue(destination.Ref.numFragments == numFragments); var numFeatures = TrajectoryFragment.GetNumFeatures(ref Binary, metricIndex); var numQuantizedFeatures = TrajectoryFragment.GetNumQuantizedFeatures(ref Binary, metricIndex); var numNormalizedFeatures = TrajectoryFragment.GetNumNormalizedFeatures(ref Binary, metricIndex); var numTransformedFeatures = numFeatures - numQuantizedFeatures - numNormalizedFeatures; destination.Ref.trajectories.numFragments = numFragments; destination.Ref.trajectories.numFeatures = (short)numFeatures; destination.Ref.trajectories.numFeaturesQuantized = (short)numQuantizedFeatures; destination.Ref.trajectories.numFeaturesNormalized = (short)numNormalizedFeatures; destination.Ref.trajectories.numFeaturesTransformed = (short)numTransformedFeatures; var numCodes = factory.Codes.Length + factory.QuantizedValues.Length; allocator.Allocate(numCodes, ref destination.Ref.trajectories.codes); int writeIndex = 0; int readIndexQuantized = 0; int readIndex = 0; for (int i = 0; i < numFragments; ++i) { for (int j = 0; j < numQuantizedFeatures; ++j) { var quantizedValue = factory.QuantizedValues[readIndexQuantized++]; destination.Ref.trajectories.codes[writeIndex++] = quantizedValue; } for (int j = 0; j < numFeatures; ++j) { var code = factory.Codes[readIndex++]; destination.Ref.trajectories.codes[writeIndex++] = code; } } Assert.IsTrue(readIndexQuantized == factory.QuantizedValues.Length); Assert.IsTrue(readIndex == factory.Codes.Length); Assert.IsTrue(writeIndex == numCodes); var numCodeWords = factory.CodeWords.Length; allocator.Allocate(numCodeWords, ref destination.Ref.trajectories.centroids); for (int i = 0; i < numCodeWords; ++i) { destination.Ref.trajectories.centroids[i] = factory.CodeWords[i]; } allocator.Allocate(numTransformedFeatures, ref destination.Ref.trajectories.boundingBoxes); Assert.IsTrue(numTransformedFeatures == factory.BoundingBoxes.Length); for (int i = 0; i < numTransformedFeatures; ++i) { destination.Ref.trajectories.boundingBoxes[i].transform = factory.BoundingBoxes[i].transform; destination.Ref.trajectories.boundingBoxes[i].extent = factory.BoundingBoxes[i].extent; destination.Ref.trajectories.boundingBoxes[i].inverseDiagonal = factory.BoundingBoxes[i].inverseDiagonal; } allocator.Allocate(numQuantizedFeatures, ref destination.Ref.trajectories.quantizers); Assert.IsTrue(numQuantizedFeatures == factory.Quantizers.Length); for (int i = 0; i < numQuantizedFeatures; ++i) { destination.Ref.trajectories.quantizers[i].minimum = factory.Quantizers[i].minimum; destination.Ref.trajectories.quantizers[i].range = factory.Quantizers[i].range; } } } codeBookIndex++; } Assert.IsTrue(codeBookIndex == codeBooks.Count); }