コード例 #1
0
ファイル: Matching.cpp プロジェクト: shadowphoenix/gemrb
Targets *GetAllActors(Scriptable *Sender, int ga_flags)
{
	Map *map = Sender->GetCurrentArea();

	int i = map->GetActorCount(true);
	Targets *tgts = new Targets();
	while (i--) {
		Actor *ac = map->GetActor(i,true);
		int dist = Distance(Sender->Pos, ac->Pos);
		tgts->AddTarget((Scriptable *) ac, dist, ga_flags);
	}
	return tgts;
}
コード例 #2
0
  svn_revnum_t
  Client::commit(const Targets & targets,
                 const char * message,
                 bool recurse,
                 bool keep_locks) throw(ClientException)
  {
    Pool pool;

    m_context->setLogMessage(message);

    svn_client_commit_info_t *commit_info = NULL;

    svn_error_t * error =
      svn_client_commit2(&commit_info,
                         targets.array(pool),
                         recurse,
                         keep_locks,
                         *m_context,
                         pool);
    if (error != NULL)
      throw ClientException(error);

    if (commit_info && SVN_IS_VALID_REVNUM(commit_info->revision))
      return commit_info->revision;

    return -1;
  }
コード例 #3
0
  std::vector<svn_revnum_t>
  Client::update(const Targets & targets,
                 const Revision & revision,
                 bool recurse,
                 bool ignore_externals) throw(ClientException)
  {
    Pool pool;
    apr_array_header_t * result_revs;

    svn_error_t * error =
      svn_client_update2(&result_revs,
                         const_cast<apr_array_header_t*>(targets.array(pool)),
                         revision.revision(),
                         recurse,
                         ignore_externals,
                         *m_context,
                         pool);
    if (error != NULL)
      throw ClientException(error);

    std::vector<svn_revnum_t> revnums;
    int i;
    for (i = 0; i < result_revs->nelts; i++)
    {
      svn_revnum_t revnum=
        APR_ARRAY_IDX(result_revs, i, svn_revnum_t);

      revnums.push_back(revnum);
    }

    return revnums;
  }
コード例 #4
0
ファイル: Matching.cpp プロジェクト: AlanWasTaken/gemrb
int GetObjectCount(Scriptable* Sender, Object* oC)
{
	if (!oC) {
		return 0;
	}
	// EvaluateObject will return [PC]
	// GetAllObjects will also return Myself (evaluates object filters)
	// i believe we need the latter here
	Targets* tgts = GetAllObjects(Sender->GetCurrentArea(), Sender, oC, 0);
	int count = 0; // silly fallback to avoid potential crashes
	if (tgts) {
		count = tgts->Count();
		delete tgts;
	}
	return count;
}
コード例 #5
0
ファイル: Matching.cpp プロジェクト: AlanWasTaken/gemrb
Targets *GetAllActors(Scriptable *Sender, int ga_flags)
{
	Map *map = Sender->GetCurrentArea();

	int i = map->GetActorCount(true);
	Targets *tgts = new Targets();
	//make sure that Sender is always first in the list, even if there
	//are other (e.g. dead) targets at the same location
	tgts->AddTarget(Sender, 0, ga_flags);
	while (i--) {
		Actor *ac = map->GetActor(i,true);
		if (ac != Sender) {
			int dist = Distance(Sender->Pos, ac->Pos);
			tgts->AddTarget(ac, dist, ga_flags);
		}
	}
	return tgts;
}
コード例 #6
0
ファイル: Matching.cpp プロジェクト: AlanWasTaken/gemrb
Scriptable* GetActorFromObject(Scriptable* Sender, Object* oC, int ga_flags)
{
	Scriptable *aC = NULL;

	Game *game = core->GetGame();
	Targets *tgts = GetAllObjects(Sender->GetCurrentArea(), Sender, oC, ga_flags);
	if (tgts) {
		//now this could return other than actor objects
		aC = tgts->GetTarget(0,-1);
		delete tgts;
		if (aC || !oC || oC->objectFields[0]!=-1) {
			return aC;
		}

		//global actors are always found by object ID!
		return game->GetGlobalActorByGlobalID(oC->objectFields[1]);
	}

	if (!oC) {
		return NULL;
	}

	if (oC->objectName[0]) {
		// if you ActionOverride a global actor, they might not have a map :(
		// TODO: don't allow this to happen?
		if (Sender->GetCurrentArea()) {
			aC = GetActorObject(Sender->GetCurrentArea()->GetTileMap(), oC->objectName );
			if (aC) {
				return aC;
			}
		}

		//global actors are always found by scripting name!
		aC = game->FindPC(oC->objectName);
		if (aC) {
			return aC;
		}
		aC = game->FindNPC(oC->objectName);
		if (aC) {
			return aC;
		}
	}
	return NULL;
}
コード例 #7
0
ファイル: Matching.cpp プロジェクト: AlanWasTaken/gemrb
//TODO:
//check numcreaturesatmylevel(myself, 1)
//when the actor is alone
//it should (obviously) return true if the trigger
//evaluates object filters
//also check numcreaturesgtmylevel(myself,0) with
//actor having at high level
int GetObjectLevelCount(Scriptable* Sender, Object* oC)
{
	if (!oC) {
		return 0;
	}
	// EvaluateObject will return [PC]
	// GetAllObjects will also return Myself (evaluates object filters)
	// i believe we need the latter here
	Targets* tgts = GetAllObjects(Sender->GetCurrentArea(), Sender, oC, 0);
	int count = 0;
	if (tgts) {
		targetlist::iterator m;
		const targettype *tt = tgts->GetFirstTarget(m, ST_ACTOR);
		while (tt) {
			count += ((Actor *) tt->actor)->GetXPLevel(true);
			tt = tgts->GetNextTarget(m, ST_ACTOR);
		}
	}
	delete tgts;
	return count;
}
コード例 #8
0
  void
  Client::unlock(const Targets & targets, bool force) throw(ClientException)
  {
    Pool pool;

    svn_error_t * error =
      svn_client_unlock(const_cast<apr_array_header_t*>(targets.array(pool)),
                        force,
                        *m_context,
                        pool);
    if (error != NULL)
      throw ClientException(error);
  }
コード例 #9
0
  void
  Client::mkdir(const Targets & targets) throw(ClientException)
  {
    Pool pool;

    svn_client_commit_info_t *commit_info = NULL;
    svn_error_t * error =
      svn_client_mkdir(&commit_info,
                       const_cast<apr_array_header_t*>
                       (targets.array(pool)),
                       *m_context, pool);

    if (error != NULL)
      throw ClientException(error);
  }
コード例 #10
0
  void
  Client::revert(const Targets & targets,
                 bool recurse) throw(ClientException)
  {
    Pool pool;

    svn_error_t * error =
      svn_client_revert((targets.array(pool)),
                        recurse,
                        *m_context,
                        pool);

    if (error != NULL)
      throw ClientException(error);
  }
コード例 #11
0
  void
  Client::remove(const Targets & targets,
                 bool force) throw(ClientException)
  {
    Pool pool;
    svn_client_commit_info_t *commit_info = NULL;

    svn_error_t * error =
      svn_client_delete(&commit_info,
                        const_cast<apr_array_header_t*>(targets.array(pool)),
                        force,
                        *m_context,
                        pool);
    if (error != NULL)
      throw ClientException(error);
  }
FaceDetector_Surf::DetectedFace FaceDetector_Surf::recognize(const cv::Mat &in, cv::Rect roi, const Targets& targets, const TrackedFaces &lastlyTrackedFaces) {


    cv::Point center;
    center.x = roi.x + roi.width/2;
    center.y = roi.y + roi.height/2;

	for(size_t i = 0; i < lastlyTrackedFaces.size(); ++i){
        std::cout << "tracking" << std::endl;
		const TrackedFace* trackedFace = &lastlyTrackedFaces.at(i);
        cv::Point previousCenter;
        previousCenter.x = trackedFace->rect.x + trackedFace->rect.width/2;
        previousCenter.y = trackedFace->rect.y + trackedFace->rect.height/2;

        if(abs(center.x - previousCenter.x) <= 50 && abs(center.y - previousCenter.y) <= 50){
            std::cout << "tracked" << std::endl;
            DetectedFace detectedFace;
            detectedFace.isRecognized = true;
            detectedFace.target = trackedFace->target;
            detectedFace.index = trackedFace->index;
            _availableFlags.at(detectedFace.index) = false;
            return detectedFace;
        }
    }


    Score bestMatch;
    cv::Mat face = in(roi).clone();

    for(size_t i = 0; i < targets.size(); ++i){
        std::cout << "surf[" << i << "]" << std::endl;
        if(!_availableFlags.at(i)) continue;
        std::cout << "available" << std::endl;

        const Target* target =  &targets.at(i);
        cv::Mat model = target->picture;


        // Match the two images
        std::vector<cv::DMatch> matches;
        std::vector<cv::KeyPoint> keypoints1, keypoints2;
        rmatcher.match(model, face ,matches, keypoints1, keypoints2);


        // draw the matches
        /*cv::Mat imageMatches;
        cv::drawMatches(model,keypoints1,          // 1st image and its keypoints
                        face,keypoints2,            // 2nd image and its keypoints
                        matches,                    // the matches
                        imageMatches,               // the image produced
                        cv::Scalar(255,255,255));   // color of the lines*/

        if(matches.size() > bestMatch.first){
            bestMatch = Score(matches.size(), i);
        }
    }

    DetectedFace detectedFace;
    detectedFace.isRecognized = bestMatch.first > 13;
    if(detectedFace.isRecognized){
        detectedFace.target = targets.at(bestMatch.second);
        detectedFace.index = bestMatch.second;
        _availableFlags.at(detectedFace.index) = false;
    }
    else{
        Target target;
        target.picture = face;
        target.name = "Inconnu";
        detectedFace.target = target;
    }

    return detectedFace;
}
コード例 #13
0
ファイル: Matching.cpp プロジェクト: AlanWasTaken/gemrb
bool MatchActor(Scriptable *Sender, ieDword actorID, Object* oC)
{
	if (!Sender) {
		return false;
	}
	Actor *ac = Sender->GetCurrentArea()->GetActorByGlobalID(actorID);
	if (!ac) {
		return false;
	}

	// [0]/[ANYONE] can match all actors
	if (!oC) {
		return true;
	}

	bool filtered = false;

	// name matching
	if (oC->objectName[0]) {
		if (strnicmp(ac->GetScriptName(), oC->objectName, 32) != 0) {
			return false;
		}
		filtered = true;
	}

	// IDS targeting
	// (if we already matched by name, we don't do this)
	// TODO: check distance? area? visibility?
	if (!filtered && !DoObjectIDSCheck(oC, ac, &filtered)) return false;

	// globalID hack should never get here
	assert(oC->objectFilters[0] != -1);

	// object filters
	if (oC->objectFilters[0]) {
		// object filters insist on having a stupid targets list,
		// so we waste a lot of time here
		Targets *tgts = new Targets();
		int ga_flags = 0; // TODO: correct?

		// handle already-filtered vs not-yet-filtered cases
		// e.g. LastTalkedToBy(Myself) vs LastTalkedToBy
		if (filtered) tgts->AddTarget(ac, 0, ga_flags);

		tgts = DoObjectFiltering(Sender, tgts, oC, ga_flags);
		if (!tgts) return false;

		// and sometimes object filters are lazy and not only don't filter
		// what we give them, they clear it and return a list :(
		// so we have to search the whole list..
		bool ret = false;
		targetlist::iterator m;
		const targettype *tt = tgts->GetFirstTarget(m, ST_ACTOR);
		while (tt) {
			Actor *actor = (Actor *) tt->actor;
			if (actor->GetGlobalID() == actorID) {
				ret = true;
				break;
			}
			tt = tgts->GetNextTarget(m, ST_ACTOR);
		}
		delete tgts;
		if (!ret) return false;
	}
	return true;
}
コード例 #14
0
ファイル: Matching.cpp プロジェクト: AlanWasTaken/gemrb
/* returns actors that match the [x.y.z] expression */
static Targets* EvaluateObject(Map *map, Scriptable* Sender, Object* oC, int ga_flags)
{
	// if you ActionOverride a global actor, they might not have a map :(
	// TODO: don't allow this to happen?
	if (!map) {
		return NULL;
	}

	if (oC->objectName[0]) {
		//We want the object by its name...
		Scriptable* aC = map->GetActor( oC->objectName, ga_flags );

		/*if (!aC && (ga_flags&GA_GLOBAL) ) {
			aC = FindActorNearby(oC->objectName, map, ga_flags );
		}*/

		//This order is the same as in GetActorObject
		//TODO:merge them
		if (!aC) {
			aC = map->GetTileMap()->GetDoor(oC->objectName);
		}
		if (!aC) {
			aC = map->GetTileMap()->GetContainer(oC->objectName);
		}
		if (!aC) {
			aC = map->GetTileMap()->GetInfoPoint(oC->objectName);
		}

		//return here because object name/IDS targeting are mutually exclusive
		return ReturnScriptableAsTarget(aC);
	}

	if (oC->objectFields[0]==-1) {
		// this is an internal hack, allowing us to pass actor ids around as objects
		Actor* aC = map->GetActorByGlobalID( (ieDword) oC->objectFields[1] );
		if (aC) {
			if (!aC->ValidTarget(ga_flags)) {
				return NULL;
			}
			return ReturnScriptableAsTarget(aC);
		}
		Door *door = map->GetDoorByGlobalID( (ieDword) oC->objectFields[1]);
		if (door) {
			return ReturnScriptableAsTarget(door);
		}

		Container* cont = map->GetContainerByGlobalID((ieDword) oC->objectFields[1]);
		if (cont) {
			return ReturnScriptableAsTarget(cont);
		}

		InfoPoint* trap = map->GetInfoPointByGlobalID((ieDword) oC->objectFields[1]);
		if (trap) {
			return ReturnScriptableAsTarget(trap);
		}

		return NULL;
	}

	Targets *tgts = NULL;

	//we need to get a subset of actors from the large array
	//if this gets slow, we will need some index tables
	int i = map->GetActorCount(true);
	while (i--) {
		Actor *ac = map->GetActor(i, true);
		if (!ac) continue; // is this check really needed?
		// don't return Sender in IDS targeting!
		if (ac == Sender) continue;
		bool filtered = false;
		if (DoObjectIDSCheck(oC, ac, &filtered)) {
			// this is needed so eg. Range trigger gets a good object
			// HACK: our parsing of Attack([0]) is broken
			if (!filtered) {
				// if no filters were applied..
				assert(!tgts);
				return NULL;
			}
			int dist;
			if (DoObjectChecks(map, Sender, ac, dist, (ga_flags & GA_DETECT) != 0)) {
				if (!tgts) tgts = new Targets();
				tgts->AddTarget((Scriptable *) ac, dist, ga_flags);
			}
		}
	}

	return tgts;
}
コード例 #15
0
ファイル: targets.cpp プロジェクト: aka2006/RapidSVN
 Targets::Targets(const Targets & targets)
 {
   m_targets = targets.targets();
 }
コード例 #16
0
ファイル: udp2udp.cpp プロジェクト: boris-r-v/STD
int main( int argc, char** argv ){
	
//	ipxComm* ipx = new ipxComm( ipxPort ,false);	
	if(argc<3){
		std::cerr<<" no one targets !"<<std::endl;
		return 1;
	}
	int	inUdpPort=14310;
	char * ip = cip;
	inUdpPort = atoi(argv[1]);
	
	std::cout<<" udp to udp translator. udp port listen "<<inUdpPort<<std::endl;	
	
	//sockaddr_in	sa_out;
	//sa_out.sin_family = AF_INET;
	//sa_out.sin_addr.s_addr = inet_addr( ip );
	//sa_out.sin_port = htons( outUdpPort);

	int size = argc-2;
	Targets targets;
	std::string ipStr;
	int ipPort=0;
	for( int i = 2 ; i < argc ;i++ ){
		parseIp( std::string(argv[i]),ipStr,ipPort );
		sockaddr_in	sa_out;
		sa_out.sin_family = AF_INET;
		sa_out.sin_addr.s_addr = inet_addr( ipStr.c_str() );
		sa_out.sin_port = htons( ipPort );
		targets.push_back(sa_out);
		std::cout<<"target "<<ipStr<<":"<<ipPort<<" added "<<std::endl;
	}
 
	int sockOut = socket( PF_INET, SOCK_DGRAM , 0 );
	int sockIn = socket( PF_INET, SOCK_DGRAM , 0 );
	int flag = 1;
	
	sockaddr_in	sa_in;
	sa_in.sin_family = AF_INET;
	sa_in.sin_addr.s_addr = INADDR_ANY;
	sa_in.sin_port = htons( inUdpPort );
	if(!bind(sockIn,(sockaddr*)&sa_in,sizeof(sa_in))){
		std::cout<<" socket binded on port "<<inUdpPort<<std::endl;
	}

	unsigned char* pack = new unsigned char[packSize];
	unsigned char* udpPack = new unsigned char[packSize];
	Net::InfoPackHeader* iph = (Net::InfoPackHeader*)udpPack;
	if(!setsockopt(sockOut,SOL_SOCKET,SO_BROADCAST,&flag,sizeof(flag))){
		std::cout<<"Start work "<<std::endl;
		Targets::iterator start = targets.begin();
		Targets::iterator end = targets.end();
		while(1){		
			if( unsigned  recsize = recv(sockIn,pack,packSize,0)){
				while( start != end ){
					if( sendto(sockOut,pack,recsize,MSG_NOSIGNAL,(sockaddr*)(&(*start)),sizeof(sockaddr_in)) <0 ){
						std::cout<<"can`t send to "<<(*start).sin_port<<std::endl; 
					}else{
						std::cout<<"packsize "<<recsize<<" send to "<<inet_ntoa((*start).sin_addr)<<":"<<ntohs( (*start).sin_port )<<std::endl; 	
					}	
					++start;
				}	
				start = targets.begin();
				std::cout<<std::endl;
			
			}
		}	
	}
	
	return 0;
}
void FaceDetector_Surf::process(const cv::Mat &in, cv::Mat &out) {
    this->_allTargetsLock.lock();
	Targets targets = this->_allTargets;
	this->_trackedFacesLock.lock();
	TrackedFaces lastlyTrackedFaces = this->_trackedFaces;
	this->_trackedFacesLock.unlock();
	this->_allTargetsLock.unlock();

    _availableFlags.clear();
    _availableFlags.resize(targets.size(), true);

    // Create a new image based on the input image
	//out = in.clone();

	//invert x axis (1 for x axis)
	cv::Mat temp;
	cv::flip(in,temp,1);
	out = temp.clone();

    // There can be more than one face in an image
    std::vector<cv::Rect> faces;

    // Detect the objects and store them in the sequence
	this->_classifier.detectMultiScale(temp, faces, 1.2, 3, CV_HAAR_DO_CANNY_PRUNING, cv::Size(25, 25));

    // Loop the number of faces found.
    for( size_t i = 0; i < faces.size(); ++i )  {
        // Draw the rectangle in the input image
        cv::rectangle( out, faces.at(i), cv::Scalar(255,0,0), 3, 8, 0);
    }

    cv::Point point;
    point.x = 20;
    point.y = 20;

    std::ostringstream faces_;
    faces_ << "Number of Faces : " << faces.size();

    cv::putText(out, faces_.str(), point, cv::FONT_HERSHEY_COMPLEX_SMALL, 0.8, cv::Scalar(255,0,0), 1, CV_AA);

    DetectedFaces detectedFaces;
    TrackedFaces trackedFaces;
    for (const cv::Rect& face : faces){

		DetectedFace detectedFace = recognize(temp, face, targets, lastlyTrackedFaces);

        detectedFaces.push_back(detectedFace);
        if(detectedFace.isRecognized){
            cv::Point label;
            label.x = face.tl().x + face.width/2 - detectedFace.target.name.size()*10/2;
            label.y = face.br().y + 15;
            cv::putText(out, detectedFace.target.name, label, cv::FONT_HERSHEY_COMPLEX_SMALL, 0.8, cv::Scalar(255,0,0), 1, CV_AA);

            TrackedFace trackedFace;
            trackedFace.rect = face;
            trackedFace.target = detectedFace.target;
            trackedFace.index = detectedFace.index;

            trackedFaces.push_back(trackedFace);
        }
    }

    this->_currentFacesLock.lock();
    this->_currentFaces = detectedFaces;
    this->_currentFacesLock.unlock();
	this->_trackedFacesLock.lock();
	this->_trackedFaces = trackedFaces;
	for(size_t ind : this->_removedDuringProcessing){
		size_t j = 0;
		for(size_t i = 0; i < this->_trackedFaces.size(); ++i){
			if(this->_trackedFaces.at(i-j).index == ind){
				this->_trackedFaces.erase(this->_trackedFaces.begin()+i-j);
				++j;
			}
		}
	}
	this->_removedDuringProcessing.clear();
	this->_trackedFacesLock.unlock();


    return;
}