예제 #1
0
파일: LayerChain.cs 프로젝트: nunb/code
        public static Tree InterpretChain(IEnumerable <LayerWrapper> layers, Tree start)
        {
            Tree.BatchTransform updater = new Tree.BatchTransform(start);
            Tree         tree           = start;
            LayerWrapper currLayer      = null;

            try
            {
                foreach (LayerWrapper wrapper in layers)
                {
                    currLayer = wrapper;
                    InterpretArgs args = new InterpretArgs(tree, updater, wrapper.Intent);

                    wrapper.Layer.Interpret(args);
                    tree = updater.GetUpdatedTree();
                    wrapper.Layer.AfterInterpret(tree);
                }
            }
            catch (Exception e)
            {
                Tree.BatchTransform newupdater = new Tree.BatchTransform(tree);
                LayerException      exception  = new LayerException(currLayer, e);
                newupdater.Tag(tree, "interpretation_exception", exception);
                tree = newupdater.GetUpdatedTree();
            }


            return(tree);
        }
예제 #2
0
        private static Tree InterpretSubchain(List <LayerWrapper> layers, int startInclusive, int endInclusive, Tree tree)
        {
            LayerWrapper currLayer = null;

            try
            {
                for (int i = startInclusive; i <= endInclusive; i++)
                {
                    currLayer = layers[i];
                    Tree.BatchTransform updater = new Tree.BatchTransform(tree);
                    InterpretArgs       args    = new InterpretArgs(tree, updater, currLayer.Intent);
                    currLayer.Layer.Interpret(args);
                    tree = updater.GetUpdatedTree();
                    currLayer.Layer.AfterInterpret(tree);
                }
            }
            catch (Exception e)
            {
                Tree.BatchTransform newupdater = new Tree.BatchTransform(tree);
                LayerException      exception  = new LayerException(currLayer, e);
                newupdater.Tag(tree, "interpretation_exception", exception);
                tree = newupdater.GetUpdatedTree();
            }

            return(tree);
        }
예제 #3
0
        //Some annotations might be updated with an old library and others might be updated with a new one.
        public static void UpdateInvalidatedLayers(List <LayerWrapper> layers)
        {
            //Initialize the intermediate interpretations
            Dictionary <string, InterpretationFromImage> interps = InitializeInterpretations(layers);
            string       configId  = LayerChain.ConfigurationId(layers, -1);
            LayerWrapper currLayer = null;

            //For each layer, re-interpret the captured images for its annotations
            //and let the layer recompute any data for them
            try
            {
                for (int i = 0; i < layers.Count; i++)
                {
                    currLayer = layers[i];

                    //Check if the layer is invalidated
                    string layerConfigId = GetPreviousConfigId(currLayer);
                    if (!configId.StartsWith(layerConfigId))
                    {
                        List <AnnotatedNode> nodes = NodesFromImageAnnotations(layers, i - 1, interps);
                        AnnotationArgs       args  = new AnnotationArgs(nodes, currLayer.Intent);

                        //process those nodes
                        currLayer.Layer.ProcessAnnotations(args);

                        //save the configuration id so we know if this layer becomes invalidated.
                        SetConfigId(layers, i);
                    }
                }
            }
            catch (Exception e)
            {
                throw new LayerException(currLayer, e);
            }
        }
		private static string GetPreviousConfigId(LayerWrapper layer)
		{
			try
			{
				return layer.Intent.GetData("config")["id"].Value<string>();
			}
			catch
			{
				return Guid.NewGuid ().ToString ();
			}
		}
예제 #5
0
        private static void SetConfigId(List <LayerWrapper> layers, int layerIndex)
        {
            LayerWrapper    layer    = layers[layerIndex];
            string          configid = LayerChain.ConfigurationId(layers, layerIndex);
            IRuntimeStorage intent   = layer.Intent;

            JObject jobj = new JObject();

            jobj["id"] = configid;
            intent.PutData("config", jobj);
        }
예제 #6
0
 private static string GetPreviousConfigId(LayerWrapper layer)
 {
     try
     {
         return(layer.Intent.GetData("config")["id"].Value <string>());
     }
     catch
     {
         return(Guid.NewGuid().ToString());
     }
 }
예제 #7
0
        private static List <AnnotatedNode> NodesFromImageAnnotations(List <LayerWrapper> layers,
                                                                      int precedingLayerIndex,
                                                                      Dictionary <string, InterpretationFromImage> interps)
        {
            LayerWrapper currentLayer = layers[precedingLayerIndex + 1];

            List <ImageAnnotation> annotations = new List <ImageAnnotation>();

            IEnumerable <string> layerlibs = currentLayer.Layer.AnnotationLibraries();

            if (layerlibs != null)
            {
                foreach (string lib in layerlibs)
                {
                    annotations.AddRange(AnnotationLibrary.GetAnnotations(lib));
                }
            }

            List <AnnotatedNode> nodesToProcess = new List <AnnotatedNode>();

            //for each one, interpret the observation
            foreach (ImageAnnotation annotation in annotations)
            {
                InterpretationFromImage interp = interps[annotation.ImageId];
                Interpret(layers, precedingLayerIndex, interp);
                Tree root         = interp.interpretation;
                Tree matchingnode = MatchingNode(root, annotation.Region);

                AnnotatedNode annoatednode = new AnnotatedNode(matchingnode, root, annotation.Data, annotation.Region, annotation.ImageId);
                nodesToProcess.Add(annoatednode);
            }

            //MergeNodesWithSameRegion(nodesToProcess);

            return(nodesToProcess);
        }
예제 #8
0
 public LayerException(LayerWrapper layer, Exception exception) : base(exception.Message, exception)
 {
     Layer = layer;
 }
예제 #9
0
파일: LayerException.cs 프로젝트: nunb/code
 public LayerException(LayerWrapper layer, Exception exception) : base(exception.Message, exception)
 {
     Layer = layer;
 }
예제 #10
0
            public LayerWrapper CreateLayerFromSeed(string chainName, LayerInfo info, int layerIndex)
            {

                Layer toAdd = CopyLayer( Seed);
                string buildDate = GetLayerBuildDate(LayerDllLocation);

                try
                {

                    Dictionary<string, object> parameters = info.Parameters;
                    string intentFilename = chainName + "_" + info.Name + "_" + layerIndex;
                    IRuntimeStorage intent = RuntimeStorage.FromCouchDb(intentFilename);
                    parameters.Add("intent", intent);
                    parameters.Add("shared", sharedLayerData);
                    toAdd.Init(parameters);
                    IEnumerable<string> libnames = toAdd.AnnotationLibraries();

                    
                    LayerWrapper wrapper = new LayerWrapper(toAdd, parameters, intent, buildDate);
                    return wrapper;
                }
                catch (IOException e)
                {
                    Console.WriteLine("Could not load layer: " + info.Name);
                    Console.WriteLine("Error Message: " + e.Message);
                    Console.WriteLine("Stack Trace: " + e.StackTrace);
                    return null;
                }

            }