Example #1
0
        //
        // Recur through all of the shapes to pre-calculate their areas.
        //
        private void PreprocessShapeHierarchyAreas(KnownMeasurementsAggregator known, List <Figure> allFigures)
        {
            foreach (Figure theFigure in allFigures)
            {
                // Acquire the indices of the shape.
                IndexList figIndices = IndexList.AcquireAtomicRegionIndices(figureAtoms, theFigure.atoms);
                figureIndexMap[figIndices] = theFigure;

                double area = theFigure.GetArea(known);

                if (area > 0)
                {
                    ShapeRegion atomRegion = new ShapeRegion(theFigure);

                    SolutionAgg agg = new SolutionAgg();

                    // The equation is the identity equation.
                    agg.solEq       = new ComplexRegionEquation(atomRegion, atomRegion);
                    agg.solType     = SolutionAgg.SolutionType.COMPUTABLE;
                    agg.solArea     = area;
                    agg.atomIndices = IndexList.AcquireAtomicRegionIndices(figureAtoms, theFigure.atoms);

                    // Add this solution to the database.
                    solutions.AddSolution(agg);
                }
            }
        }
Example #2
0
        //
        // Acquire a single solution equation and area value.
        //
        public SolutionAgg GetSolutionAgg(List <Atomizer.AtomicRegion> figureAtoms, List <Atomizer.AtomicRegion> desiredRegions)
        {
            IndexList indices = IndexList.AcquireAtomicRegionIndices(figureAtoms, desiredRegions);

            SolutionAgg solutionAgg = null;

            if (!solutions.TryGetValue(indices, out solutionAgg))
            {
                throw new ArgumentException("Could not find a solution in the database.");
            }

            return(solutionAgg);
        }
Example #3
0
        //
        // Acquire a single solution equation and area value.
        //
        public KeyValuePair <ComplexRegionEquation, double> GetSolution(List <Atomizer.AtomicRegion> figureAtoms, List <Atomizer.AtomicRegion> desiredRegions)
        {
            IndexList indices = IndexList.AcquireAtomicRegionIndices(figureAtoms, desiredRegions);

            SolutionAgg solutionAgg = null;

            if (!solutions.TryGetValue(indices, out solutionAgg))
            {
                throw new ArgumentException("Could not find a solution in the database.");
            }

            return(new KeyValuePair <ComplexRegionEquation, double>(solutionAgg.solEq, solutionAgg.solArea));
        }
Example #4
0
        //
        // Given a shape that owns the atomic region, recur through the resulting atomic region
        //
        // From
        //
        public void SolveHelper(Region currOuterRegion, List <TreeNode <Figure> > currHierarchyRoots,
                                ComplexRegionEquation currEquation, double currArea, KnownMeasurementsAggregator known)
        {
            IndexList currOuterRegionIndices = IndexList.AcquireAtomicRegionIndices(figureAtoms, currOuterRegion.atoms);

            // There is no outer region
            if (currOuterRegionIndices.IsEmpty())
            {
                return;
            }

            //
            // We have reached this point by subtracting shapes, therefore, we have an equation.
            //
            SolutionAgg agg = new SolutionAgg();

            agg.solEq = new ComplexRegionEquation(currEquation);
            agg.solEq.SetTarget(currOuterRegion);
            agg.solType     = currArea < 0 ? SolutionAgg.SolutionType.INCOMPUTABLE : SolutionAgg.SolutionType.COMPUTABLE;
            agg.solArea     = currArea;
            agg.atomIndices = currOuterRegionIndices;

            //
            // Add this solution to the database.
            //
            solutions.AddSolution(agg);

            // Was this equation solving for a single atomic region? If so, leave.
            if (currOuterRegion.IsAtomic())
            {
                return;
            }

            //
            // Recursively explore EACH sub-shape root inside of the outer region.
            //
            foreach (TreeNode <Figure> shapeNode in currHierarchyRoots)
            {
                // A list omitting this shape
                List <TreeNode <Figure> > updatedHierarchy = new List <TreeNode <Figure> >(currHierarchyRoots);
                updatedHierarchy.Remove(shapeNode);

                // Process this shape
                ProcessShape(currOuterRegion, shapeNode, updatedHierarchy, currEquation, currArea, known);

                // Process the children
                ProcessChildrenShapes(currOuterRegion, shapeNode, updatedHierarchy, currEquation, currArea, known);
            }
        }