/// Primary Constructor
/// @param position Zero-based index of the position within the system where the chord text is anchored
/// @param chordName Chord name represented in the chord text
ChordText::ChordText(wxUint32 position, const ChordName& chordName) :
    m_position((wxByte)position), m_chordName(chordName)
{
    //------Last Checked------//
    // - Jan 3, 2005
    wxASSERT(IsValidPosition(position));
}
RecordFrame* RecordIterator::FindNextRecord(RecordFrame* record) const {
  if (record == NULL) {
    return (RecordFrame*)region_start;
  }

  if(record == (RecordFrame*)RegionEnd()) {
    return record;
  }

  record_frame_t* peek = (record_frame_t*)record->getEndOfRecord();

  while((char*)peek < RegionEnd() && *peek == 0)
    peek++;

  ASSERT_TRUE((char*)peek <= RegionEnd());

  record = (RecordFrame*)peek;

  if(peek != (record_frame_t*)RegionEnd()) {
    ASSERT_TRUE(IsValidPosition(record));
    ASSERT_TRUE(record->isValid());
  }

  return record;
}
Esempio n. 3
0
wxPoint wxTextAreaBase::PositionToCoords(long pos) const
{
    wxCHECK_MSG( IsValidPosition(pos), wxDefaultPosition,
                 wxS("Position argument out of range.") );

    return DoPositionToCoords(pos);
}
Esempio n. 4
0
bool CSafebox::Add(DWORD dwPos, LPITEM pkItem)
{
	if (!IsValidPosition(dwPos))
	{
		sys_err("SAFEBOX: item on wrong position at %d (size of grid = %d)", dwPos, m_pkGrid->GetSize());
		return false;
	}

	pkItem->SetWindow(m_bWindowMode);
	pkItem->SetCell(m_pkChrOwner, dwPos);
	pkItem->Save(); // 강제로 Save를 불러줘야 한다.
	ITEM_MANAGER::instance().FlushDelayedSave(pkItem);

	m_pkGrid->Put(dwPos, 1, pkItem->GetSize());
	m_pkItems[dwPos] = pkItem;

	TPacketGCItemSet pack;

	pack.header	= m_bWindowMode == SAFEBOX ? HEADER_GC_SAFEBOX_SET : HEADER_GC_MALL_SET;
	pack.Cell	= TItemPos(m_bWindowMode, dwPos);
	pack.vnum	= pkItem->GetVnum();
	pack.count	= pkItem->GetCount();
	pack.flags	= pkItem->GetFlag();
	pack.anti_flags	= pkItem->GetAntiFlag();
	thecore_memcpy(pack.alSockets, pkItem->GetSockets(), sizeof(pack.alSockets));
	thecore_memcpy(pack.aAttr, pkItem->GetAttributes(), sizeof(pack.aAttr));

	m_pkChrOwner->GetDesc()->Packet(&pack, sizeof(pack));
	sys_log(1, "SAFEBOX: ADD %s %s count %d", m_pkChrOwner->GetName(), pkItem->GetName(), pkItem->GetCount());
	return true;
}
Esempio n. 5
0
/// Primary Constructor
/// @param position Zero-based index of the position within the system where the
/// barline is anchored
/// @param symbolType Type of symbol to add (see symbolTypes enum for values)
/// @param activeSymbol Symbol that must be active for the symbol to be
/// triggered (see activeSymbols enum for values)
/// @param repeatNumber Repeat number that must be active for the symbol to be
/// triggered (0 = none)
Direction::Direction(wxUint32 position, wxByte symbolType, wxByte activeSymbol,
    wxByte repeatNumber) : m_position(position)
{
    //------Last Checked------//
    // - Jan 11, 2005
    wxASSERT(IsValidPosition(position));
    AddSymbol(symbolType, activeSymbol, repeatNumber);   
}
Esempio n. 6
0
/// Primary Constructor
/// @param system Zero-based index of the system where the system symbol is
/// anchored
/// @param position Zero-based index of the position within the system where the
/// system symbol is anchored
/// @param data Data used by the symbol (the data format is dependant upon the
/// derived class)
SystemSymbol::SystemSymbol(wxUint32 system, wxUint32 position, wxUint32 data) :
    m_system(DEFAULT_SYSTEM), m_position(DEFAULT_POSITION), m_data(data)
{
    //------Last Checked------//
    // - Jan 13, 2005
    wxASSERT(IsValidSystem(system));
    wxASSERT(IsValidPosition(position));
    SetSystem(system);
    SetPosition(position);    
}
/*
 *	Try to set the head and tail of ship. if that Points are incorrect, do nothing and return false.
 *
 */
bool Ship::SetPosition(const Point& head, const Point& tail)
{
	if (IsValidPosition(head, tail))
	{
		m_HeadPos = head;
		m_TailPos = tail;
		return true;
	}
	else return false;
}
RecordFrame* RecordIterator::FindPreviousRecord(RecordFrame* record) const {
  if (record == NULL || record == region_start) {
    return NULL;
  }

  record_frame_t* peek = (record_frame_t*)record - 1;
  ASSERT_TRUE(IsValidPosition((RecordFrame*)peek));

  while((char*)peek > region_start && *peek == 0)
    peek--;

  if(peek == region_start) 
    return NULL;

  RecordFrame* end = (RecordFrame*)peek;
  record = end->getStartHeader();
  
  ASSERT_TRUE(IsValidPosition(record));
  ASSERT_TRUE(record->isValid());
  return record;
}
/// Primary Constructor
/// @param position Zero-based index within the system where the rhythm slash is anchored
/// @param durationType Duration type to set (1 = whole, 2 = half, 4 = quarter, 8 = 8th, 16 = 16th, 32 = 32nd, 64 = 64th)
/// @param dotCount Number of duration dots to set
RhythmSlash::RhythmSlash(wxUint32 position, wxByte durationType, wxByte dotCount) :
    m_position(position), m_beaming(DEFAULT_BEAMING), m_data(DEFAULT_DATA)
{
    //------Last Checked------//
    // - Jan 7, 2005
    wxASSERT(IsValidPosition(position));
    
    SetDurationType(durationType);    
    if (dotCount == 1)
        SetDotted();
    else if (dotCount == 2)
        SetDoubleDotted();
}
Esempio n. 10
0
/// Primary Constructor
/// @param system Zero-based index of the system where the guitar in is anchored
/// @param staff Zero-based inded of the staff within the system where the
/// guitar in is anchored
/// @param position Zero-based index of the position within the system where the
/// guitar in is anchored
/// @param staffGuitars A bit map representing the guitars to set on the staff
/// (bit 1 = guitar 0, bit 2 = guitar 1, etc.)
/// @param rhythmSlashGuitars A bit map representing the guitars to set for the
/// rhythm slashes (bit 1 = guitar 0, bit 2 = guitar 1, etc.)
GuitarIn::GuitarIn(wxUint32 system, wxUint32 staff, wxUint32 position,
    wxByte staffGuitars, wxByte rhythmSlashGuitars) :
    m_system(DEFAULT_SYSTEM), m_staff(DEFAULT_STAFF),
    m_position(DEFAULT_POSITION), m_data(DEFAULT_DATA)
{
    //------Last Checked------//
    // - Jan 25, 2005
    wxASSERT(IsValidSystem(system));
    wxASSERT(IsValidStaff(staff));
    wxASSERT(IsValidPosition(position));
    SetSystem(system);
    SetStaff(staff);
    SetPosition(position);
    SetStaffGuitars(staffGuitars);
    SetRhythmSlashGuitars(rhythmSlashGuitars);
}
Esempio n. 11
0
//가지고 있는 배들을 자동으로 배치하는 함수
void Player::SetupShips()
{
    Position setPos;
    MyDirection direction = UP;
    
    //먼저 배들을 초기화 한다. 
    //for문이 2개 따로 있는 이유는 전부 초기화를 시키지 않으면,
    //초기화 하지 않은 배들에 앞서 배치해야되는 배들이 영향을 받기 때문이다.
    for( auto shipIter : m_MyShipList )
    {
        shipIter->ShipInit();
    }

    for( auto shipIter : m_MyShipList )
    {
        do
        {
            FindBestSetupPos( &setPos , &direction , shipIter->GetMaxHP() );
        } while( !IsValidPosition( setPos , shipIter->GetMaxHP() , direction ) );
        shipIter->PlaceShip( setPos , direction );
    }
    m_EnemyBoard->InitBoard();
}
Buffer RecordIterator::AsData() const {
  ASSERT_TRUE(IsValidPosition(current));
  return Buffer(current->getPayload(), current->getPayloadSize());
}
Esempio n. 13
0
vnl_vector_fixed<double,3> MLBSTrackingFilter<  ShOrder, NumImageFeatures >::GetNewDirection(itk::Point<double, 3> &pos, vnl_vector_fixed<double, 3>& olddir)
{
    if (m_DemoMode)
    {
        m_SamplingPointset->Clear();
        m_AlternativePointset->Clear();
    }
    vnl_vector_fixed<double,3> direction; direction.fill(0);

    ItkUcharImgType::IndexType idx;
    m_StoppingRegions->TransformPhysicalPointToIndex(pos, idx);
    if (m_StoppingRegions->GetLargestPossibleRegion().IsInside(idx) && m_StoppingRegions->GetPixel(idx)>0)
        return direction;

    if (m_MaskImage.IsNotNull() && ((m_MaskImage->GetLargestPossibleRegion().IsInside(idx) && m_MaskImage->GetPixel(idx)<=0) || !m_MaskImage->GetLargestPossibleRegion().IsInside(idx)) )
        return direction;

    if (olddir.magnitude()>0)
        olddir.normalize();

    int candidates = 0; // number of directions with probability > 0
    double w = 0;       // weight of the direction predicted at each sampling point
    if (IsValidPosition(pos))
    {
        direction = m_ForestHandler.Classify(pos, candidates, olddir, m_AngularThreshold, w, m_MaskImage); // get direction proposal at current streamline position
        direction *= w;  // HERE WE ARE WEIGHTING AGAIN EVEN THOUGH THE OUTPUT DIRECTIONS ARE ALREADY WEIGHTED!!! THE EFFECT OF THIS HAS YET TO BE EVALUATED.
    }

    itk::OrientationDistributionFunction< double, 50 >  probeVecs;
    itk::Point<double, 3> sample_pos;
    int alternatives = 1;
    for (int i=0; i<m_NumberOfSamples; i++)
    {
        vnl_vector_fixed<double,3> d;

        if (m_RandomSampling)
        {
            d[0] = GetRandDouble();
            d[1] = GetRandDouble();
            d[2] = GetRandDouble();
            d.normalize();
            d *= GetRandDouble(0,m_SamplingDistance);
        }
        else
        {
            d = probeVecs.GetDirection(i)*m_SamplingDistance;
        }

        sample_pos[0] = pos[0] + d[0];
        sample_pos[1] = pos[1] + d[1];
        sample_pos[2] = pos[2] + d[2];
        if(m_DemoMode)
            m_SamplingPointset->InsertPoint(i, sample_pos);

        candidates = 0;
        vnl_vector_fixed<double,3> tempDir; tempDir.fill(0.0);
        if (IsValidPosition(sample_pos))
            tempDir = m_ForestHandler.Classify(sample_pos, candidates, olddir, m_AngularThreshold, w, m_MaskImage); // sample neighborhood
        if (candidates>0 && tempDir.magnitude()>0.001)
        {
            direction += tempDir*w;
        }
        else if (m_AvoidStop && candidates==0 && olddir.magnitude()>0) // out of white matter
        {
            double dot = dot_product(d, olddir);
            if (dot >= 0.0) // in front of plane defined by pos and olddir
                d = -d + 2*dot*olddir; // reflect
            else
                d = -d; // invert

            // look a bit further into the other direction
            sample_pos[0] = pos[0] + d[0];
            sample_pos[1] = pos[1] + d[1];
            sample_pos[2] = pos[2] + d[2];
            if(m_DemoMode)
                m_AlternativePointset->InsertPoint(alternatives, sample_pos);
            alternatives++;
            candidates = 0;
            vnl_vector_fixed<double,3> tempDir; tempDir.fill(0.0);
            if (IsValidPosition(sample_pos))
                tempDir = m_ForestHandler.Classify(sample_pos, candidates, olddir, m_AngularThreshold, w, m_MaskImage); // sample neighborhood

            if (candidates>0 && tempDir.magnitude()>0.001)  // are we back in the white matter?
            {
                direction += d;         // go into the direction of the white matter
                direction += tempDir*w;  // go into the direction of the white matter direction at this location
            }
        }
    }

    if (direction.magnitude()>0.001)
    {
        direction.normalize();
        olddir[0] = direction[0];
        olddir[1] = direction[1];
        olddir[2] = direction[2];
    }
    else
        direction.fill(0);

    return direction;
}
Esempio n. 14
0
void MLBSTrackingFilter<  ShOrder, NumImageFeatures >::ThreadedGenerateData(const InputImageRegionType &regionForThread, ThreadIdType threadId)
{
    m_Mutex.Lock();
    m_Threads++;
    m_Mutex.Unlock();
    typedef ImageRegionConstIterator< ItkUcharImgType >     MaskIteratorType;
    MaskIteratorType    sit(m_SeedImage, regionForThread );
    MaskIteratorType    mit(m_MaskImage, regionForThread );

    sit.GoToBegin();
    mit.GoToBegin();
    itk::Point<double> worldPos;
    while( !sit.IsAtEnd() )
    {
        if (sit.Value()==0 || mit.Value()==0)
        {
            ++sit;
            ++mit;
            continue;
        }

        for (int s=0; s<m_SeedsPerVoxel; s++)
        {
            FiberType fib;
            double tractLength = 0;
            typename FeatureImageType::IndexType index = sit.GetIndex();
            itk::ContinuousIndex<double, 3> start;
            unsigned int counter = 0;

            if (m_SeedsPerVoxel>1)
            {
                start[0] = index[0]+GetRandDouble(-0.5, 0.5);
                start[1] = index[1]+GetRandDouble(-0.5, 0.5);
                start[2] = index[2]+GetRandDouble(-0.5, 0.5);
            }
            else
            {
                start[0] = index[0];
                start[1] = index[1];
                start[2] = index[2];
            }

            // get staring position
            m_SeedImage->TransformContinuousIndexToPhysicalPoint( start, worldPos );

            // get starting direction
            int candidates = 0;
            double prob = 0;
            vnl_vector_fixed<double,3> dirOld; dirOld.fill(0.0);
            vnl_vector_fixed<double,3> dir; dir.fill(0.0);
            if (IsValidPosition(worldPos))
                dir = m_ForestHandler.Classify(worldPos, candidates, dirOld, 0, prob, m_MaskImage);
            if (dir.magnitude()<0.0001)
                continue;

            // forward tracking
            tractLength = FollowStreamline(worldPos, dir, &fib, 0, false);
            fib.push_front(worldPos);

            if (m_RemoveWmEndFibers)
            {
                itk::Point<double> check = fib.back();
                dirOld.fill(0.0);
                vnl_vector_fixed<double,3> check2 = GetNewDirection(check, dirOld);
                if (check2.magnitude()>0.001)
                {
                    MITK_INFO << "Detected WM ending. Discarding fiber.";
                    continue;
                }
            }

            // backward tracking
            tractLength = FollowStreamline(worldPos, -dir, &fib, tractLength, true);
            counter = fib.size();

            if (m_RemoveWmEndFibers)
            {
                itk::Point<double> check = fib.front();
                dirOld.fill(0.0);
                vnl_vector_fixed<double,3> check2 = GetNewDirection(check, dirOld);
                if (check2.magnitude()>0.001)
                {
                    MITK_INFO << "Detected WM ending. Discarding fiber.";
                    continue;
                }
            }

            if (tractLength<m_MinTractLength || counter<2)
                continue;

            m_Mutex.Lock();
            m_Tractogram.push_back(fib);
            m_Mutex.Unlock();

            if (m_AbortTracking)
                break;
        }
        if (m_AbortTracking)
            break;
        ++sit;
        ++mit;
    }
    m_Threads--;
    std::cout << "Thread " << threadId << " finished tracking" << std::endl;
}
double MLBSTrackingFilter< NumImageFeatures >::FollowStreamline(ThreadIdType threadId, itk::Point<double, 3> pos, vnl_vector_fixed<double,3> dir, FiberType* fib, double tractLength, bool front)
{
    vnl_vector_fixed<double,3> dirOld = dir;
    dirOld = dir;

    for (int step=0; step< m_MaxLength/2; step++)
    {
        while (m_PauseTracking){}
        if (m_DemoMode)
        {
            m_Mutex.Lock();
            m_BuildFibersReady++;
            m_Tractogram.push_back(*fib);
            BuildFibers(true);
            m_Stop = true;
            m_Mutex.Unlock();
            while (m_Stop){}
        }

        // get new position
        CalculateNewPosition(pos, dir);

        // is new position inside of image and mask
        if (!IsValidPosition(pos) || m_AbortTracking)   // if not end streamline
        {
            return tractLength;
        }
        else    // if yes, add new point to streamline
        {
            tractLength +=  m_StepSize;
            if (front)
                fib->push_front(pos);
            else
                fib->push_back(pos);

            if (m_AposterioriCurvCheck)
            {
                int curv = CheckCurvature(fib, front);  // TODO: Move into classification ???
                if (curv>0)
                {
                    tractLength -= m_StepSize*curv;
                    while (curv>0)
                    {
                        if (front)
                            fib->pop_front();
                        else
                            fib->pop_back();
                        curv--;
                    }
                    return tractLength;
                }
            }

            if (tractLength>m_MaxTractLength)
                return tractLength;
        }

        dir = GetNewDirection(pos, dirOld);

        if (dir.magnitude()<0.0001)
            return tractLength;
    }
    return tractLength;
}
void* RecordIterator::operator * ()  const {
  ASSERT_TRUE(IsValidPosition(current));
  return current->getPayload();
}
Esempio n. 17
0
int CreatePossibleMove(BYTE position[GRID_NUM][GRID_NUM], int nPly, int Type)
{
	//此函数前19行代码特别讲解
	int i_min = 19, i_max = 0, j_min = 19, j_max = 0;
	for (int ii = 0; ii<19; ii++)
	{
		for (int jj = 0; jj<19; jj++)
		{
			if (position[ii][jj] != NOSTONE)
			{
				if (ii<i_min) i_min = ii;
				if (ii>i_max) i_max = ii;
				if (jj<j_min) j_min = jj;
				if (jj>j_max) j_max = jj;
			}
		}
	}
	i_min -= 2, i_max += 3, j_min -= 2, j_max += 3;
	if (i_min <= 0)  i_min = 0;
	if (i_max >= 19) i_max = 19;
	if (j_min <= 0)  j_min = 0;
	if (j_max >= 19) j_max = 19;


	//前面代码特别讲解
	//以下是生成所有走法及他们的价值
	int		i1, j1, i2, j2;
	m_nMoveCount = 0;
	for (i1 = i_min; i1 < i_max; i1++)
	for (j1 = j_min; j1 < j_max; j1++)
	{
		if (position[i1][j1] == (BYTE)NOSTONE)//第一步棋
		{
			int i = (j1 + 1) / j_max, j = (j1 + 1) % j_max;
			i2 = i1 + i;
			j2 = j;
			for (; i2 < i_max; i2++, j2 = j_min)
			for (; j2 < j_max; j2++)
			{

				if (position[i2][j2] == (BYTE)NOSTONE)//第二步棋
				{
					BOOL a1 = IsValidPosition(position, i1, j1);
					position[i1][j1] = Type;
					BOOL a2 = IsValidPosition(position, i2, j2);
					position[i1][j1] = NOSTONE;
					BOOL b1 = IsValidPosition(position, i2, j2);
					position[i2][j2] = Type;
					BOOL b2 = IsValidPosition(position, i1, j1);
					position[i2][j2] = NOSTONE;

					if (a1 + a2 != 2 && b1 + b2 != 2)
						continue;
					m_MoveList[nPly][m_nMoveCount].StonePos1.x = j1;
					m_MoveList[nPly][m_nMoveCount].StonePos1.y = i1;
					m_MoveList[nPly][m_nMoveCount].StonePos2.x = j2;
					m_MoveList[nPly][m_nMoveCount].StonePos2.y = i2;

					position[i1][j1] = Type;//在棋盘上放第一步棋子
					position[i2][j2] = Type;//在棋盘上放第二步棋子

					//下面一条语句是获得此走法的价值
					m_MoveList[nPly][m_nMoveCount].Score = m_pEvel->Eveluate(position, Type);

					if (m_MoveList[nPly][m_nMoveCount].Score == 100000)
					{//若此走法价值为100000,则说明此走法实现六子连珠,即游戏结束
						//很显然,此走法是最优走法,将其付给走法链的第一个元素,然后return
						m_MoveList[nPly][0].StonePos1.x = j1;
						m_MoveList[nPly][0].StonePos1.y = i1;
						m_MoveList[nPly][0].StonePos2.x = j2;
						m_MoveList[nPly][0].StonePos2.y = i2;
						m_MoveList[nPly][0].Score = 100000;
						position[i1][j1] = NOSTONE;//撤销刚下在棋盘上的第一步棋子
						position[i2][j2] = NOSTONE;//撤销刚下在棋盘上的第二步棋子
						return 1;
					}
					position[i1][j1] = NOSTONE;//撤销刚下在棋盘上的第一步棋子
					position[i2][j2] = NOSTONE;//撤销刚下在棋盘上的第二步棋子
					m_nMoveCount++;
				}
			}
		}
	}
	//下面三条语句对所有走法的价值经过从大到小的排序,显然m_MoveList[2][0]是最优走法,不用理解,知道干啥就行

	HistoryHeuristic->MergeSort(m_MoveList[nPly], m_nMoveCount, 0);
	return m_nMoveCount;
}
Esempio n. 18
0
#include "coding/multilang_utf8_string.hpp"

#include "base/assert.hpp"

namespace search
{
void SearchParams::SetPosition(double lat, double lon)
{
  m_lat = lat;
  m_lon = lon;
  m_validPos = true;
}

m2::PointD SearchParams::GetPositionMercator() const
{
  ASSERT(IsValidPosition(), ());
  return MercatorBounds::FromLatLon(m_lat, m_lon);
}

ms::LatLon SearchParams::GetPositionLatLon() const
{
  ASSERT(IsValidPosition(), ());
  return ms::LatLon(m_lat, m_lon);
}

bool SearchParams::IsEqualCommon(SearchParams const & rhs) const
{
  return m_query == rhs.m_query && m_inputLocale == rhs.m_inputLocale &&
         m_validPos == rhs.m_validPos && m_mode == rhs.m_mode;
}
RecordFrame* RecordIterator::GetRecord() const {
  ASSERT_TRUE(IsValidPosition(current));
  return current;
}