// // On-Demand hypergraph construction. // public Hypergraph.Hypergraph<Region, SimpleRegionEquation> ConstructHypergraph() { Queue<Region> worklist = new Queue<Region>(); List<ShapeRegion> shapeRegions = new List<ShapeRegion>(); // Add all the shapes to the worklist. foreach(Figure fig in figures) { ShapeRegion r = new ShapeRegion(fig); shapeRegions.Add(r); worklist.Enqueue(r); } // // Deconstruct non-atomic regions, construct atomic regions. // while(worklist.Any()) { Region currRegion = worklist.Dequeue(); if (!currRegion.IsAtomic()) RegionDecomposition(currRegion, shapeRegions, worklist); if (currRegion.IsAtomic()) RegionComposition(currRegion, shapeRegions, worklist); } graph.DebugDumpClauses(); Debug.WriteLine(graph.ToString()); return graph; }
// // Create the actual equation and continue processing recursively. // private void ProcessShape(Region currOuterRegion, TreeNode<Figure> currShape, List<TreeNode<Figure>> currHierarchyRoots, ComplexRegionEquation currEquation, double currArea, KnownMeasurementsAggregator known) { // Acquire the sub-shape. Figure currentFigure = currShape.GetData(); // See what regions compose the subshape. ShapeRegion childShapeRegion = new ShapeRegion(currentFigure); // Make a copy of the current outer regions Region regionCopy = new Region(currOuterRegion); // Remove all regions from the outer region; if successful, recur on the new outer shape. if (regionCopy.Remove(childShapeRegion.atoms)) { // Update the equation: copy and modify ComplexRegionEquation eqCopy = new ComplexRegionEquation(currEquation); eqCopy.AppendSubtraction(childShapeRegion); // Compute new area double currAreaCopy = currArea; if (currAreaCopy > 0) { double currShapeArea = currentFigure.GetArea(known); currAreaCopy = currShapeArea < 0 ? -1 : currAreaCopy - currShapeArea; } // Recur. SolveHelper(regionCopy, currHierarchyRoots, eqCopy, currAreaCopy, known); } }
// // 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); } } }
private void PreprocessAtomAreas(KnownMeasurementsAggregator known) { // // Preprocess any of the shape atoms to see if the area is computable. // for (int a = 0; a < figureAtoms.Count; a++) { ShapeAtomicRegion shapeAtom = figureAtoms[a] as ShapeAtomicRegion; if (shapeAtom != null) { double area = shapeAtom.GetArea(known); if (area > 0) { ShapeRegion atomRegion = new ShapeRegion(shapeAtom.shape); 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 = new IndexList(a); // Add this solution to the database. solutions.AddSolution(agg); } } } }
//public ShapeRegion(List<Atomizer.AtomicRegion> ats) : base(ats) //{ //} public ShapeRegion(ShapeRegion that) : base(that.atoms) { this.shape = that.shape; }