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
    }
예제 #3
0
        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);
                }
            }
        }
예제 #4
0
 public void SetNeighbor(GameNode new_neighbor, NeighborDirection direction)
 {
     neighbors[(int)direction] = new_neighbor;
     new_neighbor.GetNeighbors()[(int)AntiDirection(direction)] = this;
 }
예제 #5
0
	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 );
	}
예제 #6
0
파일: Tile.cs 프로젝트: KLD/Mahatha
 public Tile GetNeighbor(NeighborDirection direction)
 {
     return(neighbor[(int)direction]);
 }
예제 #7
0
 public TileMapGraphNode GetNeighbor(NeighborDirection direction)
 {
     return(neighbors[(int)direction]);
 }
예제 #8
0
    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));
    }
예제 #9
0
 public static NeighborDirection Opposite(NeighborDirection nd)
 {
     return((NeighborDirection)(((int)nd + ((int)nd % 2 == 0 ? 1 : 5)) % 6));
 }
예제 #10
0
    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));
    }
예제 #11
0
    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
    }
예제 #13
0
 private void ReLinkChild(byte childIndex, NeighborDirection direction)
 {
     Children[childIndex].SetNeighbor(direction, Neighbors[(int)direction].Node, Neighbors[(int)direction].Direction);
 }
예제 #14
0
    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.
        }
    }
예제 #15
0
 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);
 }
예제 #16
0
 public T Get(NeighborDirection nd)
 {
     return(this[center + CubeNeighbors6.Relative(nd)]);
 }
예제 #17
0
 public void Set(NeighborDirection nd, T item)
 {
     this[center + CubeNeighbors6.Relative(nd)] = item;
 }
예제 #18
0
        public static IntVector3 SnapToFace(IntVector3 p, IntVector3 size, NeighborDirection nd)
        {
            var zeroOut = RelativeMask(nd) * p;

            return(zeroOut + (size - 1) * Relative(nd) * Positive(nd));
        }
예제 #19
0
 public void SetNeighbor(TileMapGraphNode neighbor, NeighborDirection direction)
 {
     neighbors[(int)direction] = neighbor;
 }
예제 #20
0
 public IntVector3 Get(NeighborDirection nd)
 {
     return(this[(int)nd]);
 }
예제 #21
0
파일: Tile.cs 프로젝트: KLD/Mahatha
 public bool HasNeighbor(NeighborDirection direction)
 {
     return(neighbor[(int)direction] != null);
 }
예제 #22
0
 public ChunkGenData Get(NeighborDirection nd)
 {
     return(neighbors[nd]);
 }
예제 #23
0
	public static Vector2 GetDirectionVector( NeighborDirection a_eDirection )
	{
		int iDirectionValue = (int) a_eDirection;
		return new Vector2( ms_iDirectionDeltas[ iDirectionValue, 0 ], ms_iDirectionDeltas[ iDirectionValue, 1 ] );
	}
예제 #24
0
 public void AddIgnoreDirection(NeighborDirection nd)
 {
     ignorableDirections.Add(nd);
 }
예제 #25
0
    ////////////////////////////////////////////
    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];
    }
예제 #26
0
 public bool Contains(NeighborDirection nd)
 {
     return(storage.ContainsKey(center + CubeNeighbors6.Relative(nd)));
 }
예제 #27
0
 public override bool Move(NeighborDirection dire)
 {
     return(false);
 }
예제 #28
0
 public T Get(NeighborDirection nd)
 {
     return(this[nd]);
 }
예제 #29
0
 public GameNode GetNeighbor(NeighborDirection direction)
 {
     return(neighbors[(int)direction]);
 }
예제 #30
0
 public void Set(NeighborDirection nd, T item)
 {
     this[nd] = item;
 }