Ejemplo n.º 1
0
bool
VisionPerceptor::StaticAxisPercept(boost::shared_ptr<PredicateList> predList)
{
    Predicate& predicate = predList->AddPredicate();
    predicate.name       = mPredicateName;
    predicate.parameter.Clear();

    TTeamIndex  ti       = mAgentState->GetTeamIndex();
    salt::Vector3f myPos = mTransformParent->GetWorldTransform().Pos();

    TObjectList visibleObjects;
    SetupVisibleObjects(visibleObjects);

    for (std::list<ObjectData>::iterator i = visibleObjects.begin();
         i != visibleObjects.end(); ++i)
    {
        ObjectData& od = (*i);

        od.mRelPos = SoccerBase::FlipView(od.mRelPos, ti);
        if (mAddNoise)
            {
                od.mRelPos += mError;
            }

        if (
            (od.mRelPos.Length() <= 0.1) ||
            (CheckOcclusion(myPos,od))
            )
        {
            // object is occluded or too close
            continue;
        }

        // theta is the angle in the X-Y (horizontal) plane
        od.mTheta = salt::gRadToDeg(salt::gArcTan2(od.mRelPos[1], od.mRelPos[0]));

        // latitude
        od.mPhi = 90.0 - salt::gRadToDeg(salt::gArcCos(od.mRelPos[2]/od.mDist));

        // make some noise
        ApplyNoise(od);

        // generate a sense entry
        AddSense(predicate,od);
    }

    if (mSenseMyPos)
    {
        Vector3f sensedMyPos = SoccerBase::FlipView(myPos, ti);

        ParameterList& element = predicate.parameter.AddList();
        element.AddValue(std::string("mypos"));
        element.AddValue(sensedMyPos[0]);
        element.AddValue(sensedMyPos[1]);
        element.AddValue(sensedMyPos[2]);
    }

    return true;
}
Ejemplo n.º 2
0
bool CLiteObjectMgr::RemoveObjectFromList(TObjectList &aList, GameBaseLite *pObject)
{
	TObjectList::iterator iObj = std::find(aList.begin(), aList.end(), pObject);
	if (iObj == aList.end())
		return false;
	*iObj = 0;
	return true;
}
Ejemplo n.º 3
0
void
VisionPerceptor::SetupVisibleObjects(TObjectList& visibleObjects)
{
    TLeafList objectList;
    mActiveScene->ListChildrenSupportingClass<ObjectState>(objectList, true);

    salt::Vector3f myPos = mTransformParent->GetWorldTransform().Pos();

    for (TLeafList::iterator i = objectList.begin();
         i != objectList.end(); ++i)
        {
            ObjectData od;
            od.mObj = static_pointer_cast<ObjectState>(*i);

            if (od.mObj.get() == 0)
                {
                    GetLog()->Error() << "Error: (VisionPerceptor) skipped: "
                                      << (*i)->GetName() << "\n";
                    continue; // this should never happen
                }

            boost::shared_ptr<Transform> j = od.mObj->GetTransformParent();

            if (j.get() == 0)
                {
                    continue; // this should never happen
                }

            od.mRelPos = j->GetWorldTransform().Pos() - myPos;
            od.mDist   = od.mRelPos.Length();

            visibleObjects.push_back(od);
        }
}
Ejemplo n.º 4
0
void CLiteObjectMgr::RemoveObjectList(TObjectList &aList)
{
	// Remove the objects in the engine
	TObjectList::iterator iCurObj = aList.begin();
	for (; iCurObj != aList.end(); ++iCurObj)
	{
		if (*iCurObj)
		{
			GameBaseLite *pObj = *iCurObj;
			// Clear out the entry in the list so we don't think we have it any more
			*iCurObj = 0;
			g_pLTServer->RemoveObject(pObj->GetClass(), pObj);
		}
	}
	// Forget...
	aList.swap(TObjectList());
}
Ejemplo n.º 5
0
void CLiteObjectMgr::CleanList(TObjectList &aList)
{
	// Clear nulls from the end of the list
	while (!aList.empty() && (aList.back() == 0))
		aList.pop_back();

	// Swap empties to the end of the list and get rid of them
	TObjectList::iterator iCurObj = aList.begin();
	while (iCurObj != aList.end())
	{
		if (!*iCurObj)
		{
			*iCurObj = aList.back();
			aList.pop_back();
		}
		else
			++iCurObj;
	}
}
Ejemplo n.º 6
0
bool
VisionPerceptor::DynamicAxisPercept(boost::shared_ptr<PredicateList> predList)
{
    Predicate& predicate = predList->AddPredicate();
    predicate.name       = mPredicateName;
    predicate.parameter.Clear();

	// get the transformation matrix describing the current orientation
    const Matrix& mat = mTransformParent->GetWorldTransform();

    TObjectList visibleObjects;
    SetupVisibleObjects(visibleObjects);

    for (std::list<ObjectData>::iterator i = visibleObjects.begin();
         i != visibleObjects.end(); ++i)
    {
        ObjectData& od = (*i);

        if (mAddNoise)
            {
                od.mRelPos += mError;
            }

        if (od.mRelPos.Length() <= 0.1)
        {
            // object is too close
            continue;
        }

		// determine position relative to the local reference frame
        Vector3f localRelPos = mat.InverseRotate(od.mRelPos);
        
        
        // theta is the angle in horizontal plane, with fwAngle as 0 degree
        od.mTheta = gNormalizeDeg (gRadToDeg(gNormalizeRad(
                              gArcTan2(localRelPos[1],localRelPos[0])
                              )) -90 );

        // latitude with fwPhi as 0 degreee
        od.mPhi = gRadToDeg(gNormalizeRad(
							gArcTan2( localRelPos[2], Vector2f(localRelPos[0], localRelPos[1]).Length())
                            ));

        // make some noise
        ApplyNoise(od);

        // generate a sense entry
        AddSense(predicate,od);
    }

    if (mSenseMyPos)
    {
        TTeamIndex  ti          = mAgentState->GetTeamIndex();
        salt::Vector3f myPos = mTransformParent->GetWorldTransform().Pos();
        Vector3f sensedMyPos = SoccerBase::FlipView(myPos, ti);

        ParameterList& element = predicate.parameter.AddList();
        element.AddValue(std::string("mypos"));
        element.AddValue(sensedMyPos[0]);
        element.AddValue(sensedMyPos[1]);
        element.AddValue(sensedMyPos[2]);
    }

    return true;
}
Ejemplo n.º 7
0
bool CLiteObjectMgr::IsObjectInList(TObjectList &aList, GameBaseLite *pObject)
{
	return std::find(aList.begin(), aList.end(), pObject) != aList.end();
}
void
RestrictedVisionPerceptor::AddSense(Predicate& predicate,
                                    boost::shared_ptr<BaseNode> node,
                                    TObjectList& objectList) const
{
    if (objectList.empty())
    {
        return;
    }

    boost::shared_ptr<AgentAspect> agent_aspect =
        dynamic_pointer_cast<AgentAspect>(node);
    if (agent_aspect != 0)
    {
        boost::shared_ptr<AgentAspect> aspect =
            agent_aspect->FindParentSupportingClass<AgentAspect>().lock();
        if (aspect != 0)
        {
            agent_aspect = aspect;
        }

        boost::shared_ptr<AgentState> agent_state = static_pointer_cast<AgentState>
            (agent_aspect->GetChildOfClass("AgentState",true));
        if (agent_state.get() == 0 ||
            (agent_state->GetPerceptName(ObjectState::PT_Player).empty())
           )
        {
            return;
        }

        ParameterList& element = predicate.parameter.AddList();
        element.AddValue(std::string("P"));

        ParameterList player;
        player.AddValue(std::string("team"));
        player.AddValue
            (std::string
                (agent_state->GetPerceptName(ObjectState::PT_Player)
                )
            );
        element.AddValue(player);

        if (! agent_state->GetID().empty())
        {
            ParameterList id;
            id.AddValue(std::string("id"));
            id.AddValue(agent_state->GetID());
            element.AddValue(id);
        }

        for (TObjectList::iterator j = objectList.begin();
            j != objectList.end(); ++j)
        {
            ObjectData& od = (*j);

            if (!od.mObj->GetID().empty())
            {
                ParameterList id;
                id.AddValue(od.mObj->GetID());

                ParameterList position;
                position.AddValue(std::string("pol"));
                position.AddValue(od.mDist);
                position.AddValue(od.mTheta);
                position.AddValue(od.mPhi);
                id.AddValue(position);

                element.AddValue(id);
            }
        }
    }
    else
    {
        for (TObjectList::iterator j = objectList.begin();
            j != objectList.end(); ++j)
        {
            ObjectData& od = (*j);
            ParameterList& element = predicate.parameter.AddList();
            element.AddValue(od.mObj->GetPerceptName());

            ParameterList& position = element.AddList();
            position.AddValue(std::string("pol"));
            position.AddValue(od.mDist);
            position.AddValue(od.mTheta);
            position.AddValue(od.mPhi);
        }
    }
}
Ejemplo n.º 9
0
void __fastcall TForm1::Button1Click(TObject *Sender)
{

//1.图像数组
       Byte *data ;  // data[] 处理一行数据
       this->Image2->Picture->Bitmap->PixelFormat = pf8bit ;
       Graphics::TBitmap * bitmap = this->Image2->Picture->Bitmap ;
//2.计算差值
        DynamicArray< DynamicArray <int> > h ;
        TObjectList  *positionXY = new TObjectList(true);
        TObjectList  *map  = new TObjectList(true);
        h.Length = height;
        for(int i = 0 ; i < height ; i++)
        {
        	h[i].Length = width /2 ;
                data = static_cast<Byte *> (this->Image2->Picture->Bitmap->ScanLine[i]) ;

        	for(int j = 0 ; j < width /2 ; j++)
                {
	                //compute the difference                
                      h[i][j] = data[2*j] - data[2*j+1]  ;
                      //averate
                      int average = (data[2*j] + data[2*j+1]) /2 ;
                      //judge Expandable
//3.把差值分类 统计可以差值的位置
                      if( ( h[i][j] < 2*(255-average) )&&( h[i][j] > -2*(255-average)) && ( h[i][j] < 2*average+1 )&& ( h[i][j] > -(2*average+1) ) )
                      {
                      	   TPoint *p = new TPoint;
                           p->x = i ;
                           p->y = j ; //map the pair(a,b) a{x,y}
                          
//4.嵌入数据

			   if( embedCount <= embedSize )
                           {
                           //expand difference

                                
                           	if(    embeddata.operator [](embedCount) == '1')
                                {
                      			h[i][j] = 2*h[i][j]+ 1 ;
                                }
                                embedCount++ ;
                           //recaculate x y
                           data[2*j] = average + (h[i][j]+1)/2 ;
                           data[2*j+1] = average - h[i][j]/2 ;     
                            map->Add((TObject *)p);
                            TPoint *pair = new TPoint(data[2*j],data[2*j+1]);
                            positionXY->Add((TObject *)pair);

                           }
                           else
                           {
//5.存储map
			    if(this->SaveDialog1->Execute())
                            {

                                //保存map
                            	AnsiString FileName = this->SaveDialog1->FileName;
                                int handle = FileCreate(FileName);                              
                                for(int a = 0 ; a < map->Count ; a++)
                                {
                                     TPoint * p = (TPoint *)map->Items[a] ;
                                     FileWrite(handle,p,sizeof(TPoint));                                     

                                }
                                FileClose(handle);
                                this->Image2->Canvas->Draw(0,0,bitmap) ;
                                //保存h[i][j];
                                AnsiString strH = "";
                                for(int a = 0 ;  a <= i ; a++)
                                {
                                	for(int b = 0 ; b <= j ; b++)
                                        {
                                           strH +=AnsiString(h[a][b])+";";
                                        }


                                }
                                 AnsiString dirFileName = ExtractFilePath(FileName) +"difference.txt";
                                 int difHandle = FileCreate(dirFileName);
                                 FileWrite(difHandle,strH.c_str(),strH.Length());
                                 FileClose(difHandle);
                                //保存修改坐标值
                                AnsiString valueFileName = ExtractFilePath(FileName) + "value.txt" ;
                                int valueHandle =  FileCreate(valueFileName);
                                AnsiString pairStr = "" ;
                                for(int x = 0 ;  x < positionXY->Count ; x++)
                                {

                                	TPoint *pair = (TPoint *)positionXY->Items[x] ;
                                         pairStr += AnsiString(pair->x) + "," + AnsiString(pair->y) + ";" ;
                                }
                                FileWrite(valueHandle,pairStr.c_str(),pairStr.Length());
                                FileClose(valueHandle) ;
                                return ;
                            }

                              
                           }

                      }
                }
        }



//6. 清理
delete map ;	
        





}