public static Contour TraceContour( int a_iStartingPixelIndex, NeighborDirection a_eStartingDirection, int a_iContourLabel, BinarizedImage a_rBinarizedImage, int[ ] a_rLabelMap ) { int iPixelIndexTrace; NeighborDirection eDirectionNext = a_eStartingDirection; FindNextPoint( a_iStartingPixelIndex, a_eStartingDirection, a_rBinarizedImage, a_rLabelMap, out iPixelIndexTrace, out eDirectionNext ); Contour oContour = new Contour( a_iContourLabel ); oContour.AddFirst( a_rBinarizedImage.PixelIndex2Coords( iPixelIndexTrace ) ); int iPreviousPixelIndex = a_iStartingPixelIndex; int iCurrentPixelIndex = iPixelIndexTrace; bool bDone = ( a_iStartingPixelIndex == iPixelIndexTrace ); // Choose a bias factor // The bias factor points to exterior if tracing an outer contour // The bias factor points to interior if tracing an inner contour float fOrthoBiasFactor; if( a_eStartingDirection == NeighborDirection.DirectionUpRight ) // inner contour { fOrthoBiasFactor = -0.2f; } else // outer contour { fOrthoBiasFactor = 0.2f; } while( bDone == false ) { a_rLabelMap[ iCurrentPixelIndex ] = a_iContourLabel; NeighborDirection eDirectionSearch = (NeighborDirection) ( ( (int) eDirectionNext + 6 ) % 8 ); int iNextPixelIndex; FindNextPoint( iCurrentPixelIndex, eDirectionSearch, a_rBinarizedImage, a_rLabelMap, out iNextPixelIndex, out eDirectionNext ); iPreviousPixelIndex = iCurrentPixelIndex; iCurrentPixelIndex = iNextPixelIndex; bDone = ( iPreviousPixelIndex == a_iStartingPixelIndex && iCurrentPixelIndex == iPixelIndexTrace ); if( bDone == false ) { // Apply some bias to inner and outer contours to avoid them overlap // Use the orthogonal vector to direction NeighborDirection eOrthoBiasDirection = (NeighborDirection) ( ( (int) eDirectionNext + 6 ) % 8 ); // == direction - 2 % 8 but easier to compute (always positive) Vector2 f2Bias = fOrthoBiasFactor * BinarizedImage.GetDirectionVector( eOrthoBiasDirection ); // Add bias to pixel pos Vector2 f2BiasedPos = f2Bias + a_rBinarizedImage.PixelIndex2Coords( iNextPixelIndex ); // Add biased pos to contour oContour.AddFirst( f2BiasedPos ); } } return oContour; }
public static void FindNextPoint( int a_iStartingPixelIndex, NeighborDirection a_eStartingDirection, BinarizedImage a_rBinarizedImage, int[ ] a_rLabelMap, out int a_iNextPixelIndex, out NeighborDirection a_eNextDirection ) { a_eNextDirection = a_eStartingDirection; // Search in all directions except initial direction (=> 7) for( int iSearchIteration = 0; iSearchIteration < 7; ++iSearchIteration ) { a_iNextPixelIndex = a_rBinarizedImage.GetNeighborPixelIndex( a_iStartingPixelIndex, a_eNextDirection ); if( a_rBinarizedImage[ a_iNextPixelIndex ] == false ) // Background pixel, mark it as visited { a_rLabelMap[ a_iNextPixelIndex ] = -1; // mark as visited a_eNextDirection = (NeighborDirection) ( ( (int) a_eNextDirection + 1 ) % 8 ); // Next direction... } else // Non background pixel { return; } } a_iNextPixelIndex = a_iStartingPixelIndex; // return starting index }
private IEnumerable <ChessBoxPosition> getEnemiesToRemoveByDirection(ChessBoxState actualPlayer, ChessBoxPosition position, NeighborDirection direction) { var enemyPlayer = getEnemyPlayer(actualPlayer); foreach (var enemy in getNeighborsByPlayer(enemyPlayer, position, direction)) { if (enemy.IsCorner && getNeighborsByPlayer(actualPlayer, enemy).Count() == 1 || getNeighborsByPlayer(actualPlayer, enemy, direction).Count() == 1) { yield return(enemy); } } }
public void SetNeighbor(GameNode new_neighbor, NeighborDirection direction) { neighbors[(int)direction] = new_neighbor; new_neighbor.GetNeighbors()[(int)AntiDirection(direction)] = this; }
public int GetNeighborPixelIndex( int a_iPixelIndex, NeighborDirection a_eDirection ) { int iDirectionValue = (int) a_eDirection; return a_iPixelIndex + ms_iDirectionDeltas[ iDirectionValue, 0 ] + ms_iDirectionDeltas[ iDirectionValue, 1 ] * ( this.PaddedWidth ); }
public Tile GetNeighbor(NeighborDirection direction) { return(neighbor[(int)direction]); }
public TileMapGraphNode GetNeighbor(NeighborDirection direction) { return(neighbors[(int)direction]); }
public void updateWindowsFlushWithEdgeInNeighborDirection(byte[] surfaceHeightsAtEdge, NeighborDirection ndir) { // ndir is neighb's relation to us // so want the windows on the opposite edge Direction dir = NeighborDirectionUtils.DirecionFourForNeighborDirection(NeighborDirectionUtils.oppositeNeighborDirection(ndir)); Axis axis = DirectionUtil.AxisForDirection(dir); if (axis == Axis.X) { updateWindowsAlongXEdge(surfaceHeightsAtEdge, DirectionUtil.IsPosDirection(dir)); return; } updateWindowsAlongZEdge(surfaceHeightsAtEdge, DirectionUtil.IsPosDirection(dir)); }
public static NeighborDirection Opposite(NeighborDirection nd) { return((NeighborDirection)(((int)nd + ((int)nd % 2 == 0 ? 1 : 5)) % 6)); }
public int GetNeighborPixelIndex(int a_iPixelIndex, NeighborDirection a_eDirection) { int iDirectionValue = (int)a_eDirection; return(a_iPixelIndex + ms_iDirectionDeltas[iDirectionValue, 0] + ms_iDirectionDeltas[iDirectionValue, 1] * (this.PaddedWidth)); }
public static Vector2 GetDirectionVector(NeighborDirection a_eDirection) { int iDirectionValue = (int)a_eDirection; return(new Vector2(ms_iDirectionDeltas[iDirectionValue, 0], ms_iDirectionDeltas[iDirectionValue, 1])); }
public static void FindNextPoint(int a_iStartingPixelIndex, NeighborDirection a_eStartingDirection, BinarizedImage a_rBinarizedImage, int[] a_rLabelMap, out int a_iNextPixelIndex, out NeighborDirection a_eNextDirection) { a_eNextDirection = a_eStartingDirection; // Search in all directions except initial direction (=> 7) for (int iSearchIteration = 0; iSearchIteration < 7; ++iSearchIteration) { a_iNextPixelIndex = a_rBinarizedImage.GetNeighborPixelIndex(a_iStartingPixelIndex, a_eNextDirection); if (a_rBinarizedImage[a_iNextPixelIndex] == false) // Background pixel, mark it as visited { a_rLabelMap[a_iNextPixelIndex] = -1; // mark as visited a_eNextDirection = (NeighborDirection)(((int)a_eNextDirection + 1) % 8); // Next direction... } else // Non background pixel { return; } } a_iNextPixelIndex = a_iStartingPixelIndex; // return starting index }
private void ReLinkChild(byte childIndex, NeighborDirection direction) { Children[childIndex].SetNeighbor(direction, Neighbors[(int)direction].Node, Neighbors[(int)direction].Direction); }
public void SetNeighbor(NeighborDirection direction, PatchTree tree, NeighborDirection directionFromThere) { if (tree.HasChildren) { //the other node has children, which means this node was in coarse resolution, //so find correct child to link to... //need to find which two of the 4 children //of the other node that links to the parent of this node or to this node itself //then, decide which of the two children is closer to this node //and update the correct (nearest) child to link to this node PatchTree correctNode = null; float dist = 0; byte neighDirection = 0; //for each child of that node... for (byte i = 0; i < 4; i++) { var child = tree.Children[i]; //for each direction of that child of that node... for (byte j = 0; j < 4; j++) { //check if that child links from that direction to our parent if (child.Neighbors[j].Node.Equals(Parent)) { if (correctNode == null) { //as there is no best correct child yet, //temporarily selects that child as the correct correctNode = child; neighDirection = j; dist = VectorHelper.QuickDistance(child.Middle, Middle); break; } else { //check if this child is closer than //the currently selected as the closer child if (VectorHelper.QuickDistance(child.Middle, Middle) < dist) { correctNode = child; neighDirection = j; //as we can have only two childs //pointing to our own parent, and the other child has been scanned already, //we can safely bail out of the outer loop and stop searching i = 4; break; } } } else if (child.Neighbors[j].Node == this) { //that child relinked to this node first //which means both nodes are at same level //so just get it and bail out correctNode = child; neighDirection = j; //link back to that node Neighbors[(int)direction].Node = correctNode; Neighbors[(int)direction].Direction = (NeighborDirection)neighDirection; //update edges of this node NeedsReedge = true; //bail out return; } } } if (correctNode != null) { //link to that node Neighbors[(int)direction].Node = correctNode; Neighbors[(int)direction].Direction = (NeighborDirection)neighDirection; //link that node back to this node correctNode.Neighbors[neighDirection].Node = this; correctNode.Neighbors[neighDirection].Direction = direction; //update edges and gaps NeedsReedge = true; correctNode.NeedsReedge = true; //the other node was discarding resolution //because this node was at coarse level //now that both are at same level, //lets force the other node to use full mesh at the edge that links to this node correctNode.GapFixMask |= (byte)(1 << neighDirection); correctNode.Neighbors[neighDirection].isFixed = false; } } else { //the other node has no children... //so, the other node is at a coarse level //or at same level (a brother node); //link directly to that node Neighbors[(int)direction].Node = tree; Neighbors[(int)direction].Direction = directionFromThere; Neighbors[(int)direction].Node.NeedsReedge = true; //only this node needs to update edges and fix gaps NeedsReedge = true; GapFixMask |= (byte)(1 << (int)direction); Neighbors[(int)direction].isFixed = false; //the other node stays linked to the node it is already linked to. } }
private IEnumerable <ChessBoxPosition> getNeighborsByPlayer(ChessBoxState player, ChessBoxPosition position, NeighborDirection direction = NeighborDirection.All) { return(from ChessBoxPosition neighborPosition in position.GetNeighbors(direction) where desk.GetState(neighborPosition) == player select neighborPosition); }
public T Get(NeighborDirection nd) { return(this[center + CubeNeighbors6.Relative(nd)]); }
public void Set(NeighborDirection nd, T item) { this[center + CubeNeighbors6.Relative(nd)] = item; }
public static IntVector3 SnapToFace(IntVector3 p, IntVector3 size, NeighborDirection nd) { var zeroOut = RelativeMask(nd) * p; return(zeroOut + (size - 1) * Relative(nd) * Positive(nd)); }
public void SetNeighbor(TileMapGraphNode neighbor, NeighborDirection direction) { neighbors[(int)direction] = neighbor; }
public IntVector3 Get(NeighborDirection nd) { return(this[(int)nd]); }
public bool HasNeighbor(NeighborDirection direction) { return(neighbor[(int)direction] != null); }
public ChunkGenData Get(NeighborDirection nd) { return(neighbors[nd]); }
public static Vector2 GetDirectionVector( NeighborDirection a_eDirection ) { int iDirectionValue = (int) a_eDirection; return new Vector2( ms_iDirectionDeltas[ iDirectionValue, 0 ], ms_iDirectionDeltas[ iDirectionValue, 1 ] ); }
public void AddIgnoreDirection(NeighborDirection nd) { ignorableDirections.Add(nd); }
//////////////////////////////////////////// public BoardTile GetNeighbor(NeighborDirection which) { //return null for no neighbors if(tileNeighbors.Count < 4) { return null; } //Order is : North, East, South, West return tileNeighbors[(int)which]; }
public bool Contains(NeighborDirection nd) { return(storage.ContainsKey(center + CubeNeighbors6.Relative(nd))); }
public override bool Move(NeighborDirection dire) { return(false); }
public T Get(NeighborDirection nd) { return(this[nd]); }
public GameNode GetNeighbor(NeighborDirection direction) { return(neighbors[(int)direction]); }
public void Set(NeighborDirection nd, T item) { this[nd] = item; }