public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } EdgeDescription objCasted = (EdgeDescription)obj; return (objCasted.VertexConstraints1 == this.VertexConstraints1 && objCasted.VertexConstraints2 == this.VertexConstraints2 && objCasted.EdgeConstraints == this.EdgeConstraints); }
public EdgeDescription RotateEdge(EdgeDescription edge, int rotations) { // Update position; Vector3 newPos = edge.position; int w = topEdges.Count - 1; int h = leftEdges.Count - 1; for (int i = 0; i < rotations; i++) { newPos = new Vector3(newPos.z, 0, (i % 2 == 0 ? w : h) - newPos.x); } // Update direction. Direction newDir = (Chunk.Direction)(((int)edge.dir + rotations) % 4); var r = new EdgeDescription(newPos, newDir, edge.type); return(r); }
public int RotationsNeeded(EdgeDescription exit) { return RotationsNeeded(exit.dir); }
public EdgeDescription RotateEdge(EdgeDescription edge, int rotations) { // Update position; Vector3 newPos = edge.position; int w = topEdges.Count - 1; int h = leftEdges.Count - 1; for(int i = 0; i < rotations; i++) newPos = new Vector3(newPos.z, 0, (i % 2 == 0 ? w : h) - newPos.x); // Update direction. Direction newDir = (Chunk.Direction)(((int)edge.dir + rotations) % 4); var r = new EdgeDescription(newPos, newDir, edge.type); return r; }
public int RotationsNeeded(EdgeDescription exit) { return(RotationsNeeded(exit.dir)); }
public void CalculateShapeTerms(ShapeModel model, ShapeConstraints constraintsSet, Image2D<ObjectBackgroundTerm> result) { if (model == null) throw new ArgumentNullException("model"); if (constraintsSet == null) throw new ArgumentNullException("constraintsSet"); if (result == null) throw new ArgumentNullException("result"); if (model.Structure != constraintsSet.ShapeStructure) throw new ArgumentException("Shape model and shape constraints correspond to different shape structures."); if (model != this.shapeModel || result.Rectangle.Size != this.imageSize) this.SetTarget(model, result.Rectangle.Size); for (int x = 0; x < imageSize.Width; ++x) for (int y = 0; y < imageSize.Height; ++y) result[x, y] = new ObjectBackgroundTerm(Double.PositiveInfinity, 0); for (int edgeIndex = 0; edgeIndex < this.shapeModel.Structure.Edges.Count; ++edgeIndex) { ShapeEdge edge = this.shapeModel.Structure.Edges[edgeIndex]; VertexConstraints vertexConstraints1 = constraintsSet.VertexConstraints[edge.Index1]; VertexConstraints vertexConstraints2 = constraintsSet.VertexConstraints[edge.Index2]; EdgeConstraints edgeConstraints = constraintsSet.EdgeConstraints[edgeIndex]; Image2D<ObjectBackgroundTerm> edgeTerms; EdgeDescription edgeDescription = new EdgeDescription( vertexConstraints1, vertexConstraints2, edgeConstraints); if (!this.cachedEdgeTerms.TryGetValue(edgeDescription, out edgeTerms)) { edgeTerms = this.AllocateImage(); this.cachedEdgeTerms.Add(edgeDescription, edgeTerms); Polygon convexHull = constraintsSet.GetConvexHullForVertexPair(edge.Index1, edge.Index2); Parallel.For( 0, imageSize.Width, x => { for (int y = 0; y < imageSize.Height; ++y) { Vector pointAsVec = new Vector(x, y); double minDistanceSqr, maxDistanceSqr; MinMaxDistanceForEdge( pointAsVec, convexHull, vertexConstraints1, vertexConstraints2, out minDistanceSqr, out maxDistanceSqr); edgeTerms[x, y] = new ObjectBackgroundTerm( this.shapeModel.CalculateObjectPenaltyForEdge( minDistanceSqr, edgeConstraints.MaxWidth), this.shapeModel.CalculateBackgroundPenaltyForEdge( maxDistanceSqr, edgeConstraints.MinWidth)); } }); } for (int x = 0; x < imageSize.Width; ++x) for (int y = 0; y < imageSize.Height; ++y) result[x, y] = new ObjectBackgroundTerm( Math.Min(result[x, y].ObjectTerm, edgeTerms[x, y].ObjectTerm), Math.Max(result[x, y].BackgroundTerm, edgeTerms[x, y].BackgroundTerm)); } }
public void CalculateShapeTerms(ShapeModel model, ShapeConstraints constraintsSet, Image2D <ObjectBackgroundTerm> result) { if (model == null) { throw new ArgumentNullException("model"); } if (constraintsSet == null) { throw new ArgumentNullException("constraintsSet"); } if (result == null) { throw new ArgumentNullException("result"); } if (model.Structure != constraintsSet.ShapeStructure) { throw new ArgumentException("Shape model and shape constraints correspond to different shape structures."); } if (model != this.shapeModel || result.Rectangle.Size != this.imageSize) { this.SetTarget(model, result.Rectangle.Size); } for (int x = 0; x < imageSize.Width; ++x) { for (int y = 0; y < imageSize.Height; ++y) { result[x, y] = new ObjectBackgroundTerm(Double.PositiveInfinity, 0); } } for (int edgeIndex = 0; edgeIndex < this.shapeModel.Structure.Edges.Count; ++edgeIndex) { ShapeEdge edge = this.shapeModel.Structure.Edges[edgeIndex]; VertexConstraints vertexConstraints1 = constraintsSet.VertexConstraints[edge.Index1]; VertexConstraints vertexConstraints2 = constraintsSet.VertexConstraints[edge.Index2]; EdgeConstraints edgeConstraints = constraintsSet.EdgeConstraints[edgeIndex]; Image2D <ObjectBackgroundTerm> edgeTerms; EdgeDescription edgeDescription = new EdgeDescription( vertexConstraints1, vertexConstraints2, edgeConstraints); if (!this.cachedEdgeTerms.TryGetValue(edgeDescription, out edgeTerms)) { edgeTerms = this.AllocateImage(); this.cachedEdgeTerms.Add(edgeDescription, edgeTerms); Polygon convexHull = constraintsSet.GetConvexHullForVertexPair(edge.Index1, edge.Index2); Parallel.For( 0, imageSize.Width, x => { for (int y = 0; y < imageSize.Height; ++y) { Vector pointAsVec = new Vector(x, y); double minDistanceSqr, maxDistanceSqr; MinMaxDistanceForEdge( pointAsVec, convexHull, vertexConstraints1, vertexConstraints2, out minDistanceSqr, out maxDistanceSqr); edgeTerms[x, y] = new ObjectBackgroundTerm( this.shapeModel.CalculateObjectPenaltyForEdge( minDistanceSqr, edgeConstraints.MaxWidth), this.shapeModel.CalculateBackgroundPenaltyForEdge( maxDistanceSqr, edgeConstraints.MinWidth)); } }); } for (int x = 0; x < imageSize.Width; ++x) { for (int y = 0; y < imageSize.Height; ++y) { result[x, y] = new ObjectBackgroundTerm( Math.Min(result[x, y].ObjectTerm, edgeTerms[x, y].ObjectTerm), Math.Max(result[x, y].BackgroundTerm, edgeTerms[x, y].BackgroundTerm)); } } } }