예제 #1
0
        /**
         * Instructs this state's Filter to process its input.
         *
         * @param env
         *      Runtime processing environment
         */
        public override FilterStateResult traverse(FilterEnv in_env)
        {
            FilterStateResult result = new FilterStateResult();

            // clone a new environment:
            current_env = in_env.advance();

            FeatureList output = filter.process(in_features, current_env);

            FilterState next = getNextState();

            if (next != null)
            {
                if (output.Count > 0)
                {
                    if (next is FeatureFilterState)
                    {
                        FeatureFilterState state = (FeatureFilterState)next;
                        state.push(output);
                    }
                    else if (next is FragmentFilterState)
                    {
                        FragmentFilterState state = (FragmentFilterState)next;
                        state.push(output);
                    }
                    else if (next is NodeFilterState)
                    {
                        NodeFilterState state = (NodeFilterState)next;
                        state.push(output);
                    }
                    else if (next is CollectionFilterState)
                    {
                        CollectionFilterState state = (CollectionFilterState)next;
                        state.push(output);
                    }

                    result = next.traverse(current_env);
                }
                else
                {
                    result.set(FilterStateResult.Status.STATUS_NODATA, filter);
                }
            }

            // clean up
            in_features.Clear();

            return(result);
        }
        public override FilterStateResult signalCheckpoint()
        {
#if TODO
            FilterStateResult result;

            FilterState next = getNextState();
            if (next != null)
            {
                int metering = filter.getMetering();

                if (next is FeatureFilterState)
                {
                    if (features.Count > 0)
                    {
                        FeatureGroups feature_groups;
                        foreach (Feature i in features)
                        {
                            feature_groups[filter.assign(i, current_env)].Add(i);
                        }

                        FeatureFilterState state = (FeatureFilterState)next;
                        result = meterGroups(filter, feature_groups, state, metering, current_env);
                    }
                    else
                    {
                        result.set(FilterStateResult.Status.STATUS_NODATA, filter);
                    }
                }
                else if (next is FragmentFilterState)
                {
                    FragmentFilterState state = (FragmentFilterState)next;
                    if (features.Count > 0)
                    {
                        FeatureGroups groups;
                        foreach (Feature i in features)
                        {
                            groups[filter.assign(i, current_env)].Add(i);
                        }
                        result = meterGroups(filter, groups, state, metering, current_env);
                    }
                    else if (fragments.Count > 0)
                    {
                        FragmentGroups groups;
                        foreach (Fragment i in fragments)
                        {
                            groups[filter.assign(i, current_env)].Add(i);
                        }
                        result = meterGroups(filter, groups, state, metering, current_env);
                    }
                    else
                    {
                        result.set(FilterStateResult.Status.STATUS_NODATA, filter);
                    }
                }
                else if (next is NodeFilterState)
                {
                    NodeFilterState state = (NodeFilterState)next;
                    if (features.Count > 0)
                    {
                        FeatureGroups feature_groups;
                        foreach (Feature i in features)
                        {
                            feature_groups[filter.assign(i, current_env)].Add(i);
                        }
                        result = meterGroups(filter, feature_groups, state, metering, current_env);
                    }
                    else if (fragments.Count > 0)
                    {
                        FragmentGroups groups;
                        foreach (Fragment i in fragments)
                        {
                            groups[filter.assign(i, current_env)].Add(i);
                        }
                        result = meterGroups(filter, groups, state, metering, current_env);
                    }
                    else if (nodes.Count > 0)
                    {
                        NodeGroups groups;
                        foreach (AttributedNode i in nodes)
                        {
                            groups[filter.assign(i, current_env)].Add(i);
                        }
                        result = meterGroups(filter, groups, state, metering, current_env);
                    }
                    else
                    {
                        result.set(FilterStateResult.Status.STATUS_NODATA, filter);
                    }
                }
                else if (next is CollectionFilterState)
                {
                    CollectionFilterState state = (CollectionFilterState)next;
                    if (features.Count > 0)
                    {
                        FeatureGroups feature_groups;
                        foreach (Feature i in features)
                        {
                            feature_groups[filter.assign(i, current_env)].Add(i);
                        }
                        result = meterGroups(filter, feature_groups, state, metering, current_env);
                    }
                    else if (fragments.Count > 0)
                    {
                        FragmentGroups groups;
                        foreach (Fragment i in fragments)
                        {
                            groups[filter.assign(i, current_env)].Add(i);
                        }
                        result = meterGroups(filter, groups, state, metering, current_env);
                    }
                    else if (nodes.Count > 0)
                    {
                        NodeGroups groups;
                        foreach (AttributedNode i in nodes)
                        {
                            groups[filter.assign(i, current_env)].Add(i);
                        }
                        result = meterGroups(filter, groups, state, metering, current_env);
                    }
                    else
                    {
                        result.set(FilterStateResult.Status.STATUS_NODATA, filter);
                    }
                }

                if (result.isOK())
                {
                    result = next.signalCheckpoint();
                }
            }

            // clean up the input:
            features.Clear();
            fragments.Clear();
            nodes.Clear();

            current_env = null;

            return(result);
#endif
            throw new NotImplementedException();
        }
예제 #3
0
        /**
         * Runs the graph to generate a scene graph.
         *
         * Executes the graph by passing features to the first filter in the
         * chain. That filter will process the data, pass the results along to
         * the next filter, and so on until completion.
         *
         * @param cursor
         *      Source cursor for features to process
         * @param env
         *      Contextual compilation environment
         * @param output
         *      Group node that, upon success, contains resulting nodes of compiled scene
         *      as its children
         * @return
         *      A structure describing the result of the compilation.
         */
        public FilterGraphResult computeNodes(FeatureCursor cursor, FilterEnv env, osg.Group output)
        {
            FilterStateResult state_result;

            output = null;

            NodeFilterState output_state;

            // first build a new state chain corresponding to our filter prototype chain.
            FilterState first = null;

            foreach (Filter i in filter_prototypes)
            {
                FilterState next_state = i.newState();
                if (first == null)
                {
                    first = next_state;
                }
                else
                {
                    first.appendState(next_state);
                }

                if (next_state is NodeFilterState)
                {
                    output_state = (NodeFilterState)next_state;
                }
            }

            // now traverse the states.
            if (first != null)
            {
                int         count = 0;
                osg.Timer_t start = osg.Timer.instance().tick();

                env.setOutputSRS(env.getInputSRS());

                if (first is FeatureFilterState)
                {
                    FeatureFilterState state = (FeatureFilterState)first;
                    while (state_result.isOK() && cursor.hasNext())
                    {
                        state.push(wind(cursor.next()));
                        state_result = state.traverse(env);
                        count++;
                    }
                    if (state_result.isOK())
                    {
                        state_result = state.signalCheckpoint();
                    }
                }
                else if (first is FragmentFilterState)
                {
                    FragmentFilterState state = (FragmentFilterState)first;
                    while (state_result.isOK() && cursor.hasNext())
                    {
                        state.push(wind(cursor.next()));
                        state_result = state.traverse(env);
                        count++;
                    }
                    if (state_result.isOK())
                    {
                        state_result = state.signalCheckpoint();
                    }
                }
                else if (first is CollectionFilterState)
                {
                    CollectionFilterState state = (CollectionFilterState)first;
                    while (state_result.isOK() && cursor.hasNext())
                    {
                        state.push(wind(cursor.next()));
                        state_result = state.traverse(env);
                        count++;
                    }
                    if (state_result.isOK())
                    {
                        state_result = state.signalCheckpoint();
                    }
                }

                osg.Timer_t end = osg.Timer.instance().tick();

                double dur = osg.Timer.instance().delta_s(start, end);
                //osgGIS.notify( osg.ALWAYS ) << std.endl << "Time = " << dur << " s; Per Feature Avg = " << (dur/(double)count) << " s" << std.endl;
            }
            else
            {
                state_result.set(FilterStateResult.Status.STATUS_NODATA);
            }

            if (output_state != null && state_result.hasData())
            {
                output = new osg.Group();
                foreach (AttributedNode i in output_state.getOutput())
                {
                    output.addChild(i.getNode());
                }
            }

            if (state_result.isOK())
            {
                return(FilterGraphResult.ok(output_state.getLastKnownFilterEnv()));
            }
            else
            {
                return(FilterGraphResult.error("Filter graph failed to compute any nodes"));
            }
        }