Esempio n. 1
0
MotionSequence* MoCapManager::stopRecording()
{
    if (!_recording)
    {
        return nullptr;
    }
    // enable synchronizing again
    theSensorManager.setSynchronizing(true);
    _recording = false;
    _filters[_currentFilter]->setRecording(false);
    MotionSequence* sequence = new MotionSequence(_filters[_currentFilter]->getSequence());
    // TODO(JK#4#): set recorded MotionSequence details (name, frameTime, numFrames etc in appropriate function eg in the filter)
    sequence->setName("recording");
    // TODO(JK#5#2017-03-01): maybe do not add the recorded sequence to the animation manager (at least not here)
    theAnimationManager.addProjectSequence(sequence);
    return sequence;
}
Esempio n. 2
0
MotionSequence* Blender::blend(MOTION_BLEND_SPEC& spec)
{
	MotionSequence* result = new MotionSequence;
	unsigned short i, j, frame;

	result->setNumFrames(spec.num_frames);
	result->setFrameRate(120);
	for (i=0; i<spec.channel_specs.size(); i++)
	{
		result->addChannel(spec.channel_specs[i].channel);
	}
	result->adjustStorage();

	// FIXIT! result need to resize its Array2D once all channels are defined.

	for (i=0; i<spec.channel_specs.size(); i++)
	{
		CHANNEL_BLEND_SPEC cblend = spec.channel_specs[i];
		{
			// FIXIT! This needs to account for each channels frame rate

			// compute time warp for each input channel
			float warp[MAX_INPUT_CHANNELS];
			short result_frame_range = cblend.end_frame - cblend.start_frame;
			for (j=0; j<cblend.inputs.size(); j++)
			{
				// warp from target time back to source time
				warp[j] = (cblend.inputs[j].end_frame-cblend.inputs[j].start_frame)
					/ float(result_frame_range);
			}
			
			for (frame=cblend.start_frame; frame<cblend.end_frame; frame++)
			{
				float value = 0.0f;
				for (j=0; j<cblend.inputs.size(); j++)
				{
					// FIXIT! need to interpolate
					long cframe = short((frame-cblend.start_frame) * warp[j])
						+ cblend.inputs[j].start_frame;
					if (cframe >= cblend.inputs[j].ms->numFrames())
						cframe = cblend.inputs[j].ms->numFrames()-1;
					value += cblend.inputs[j].blend_weight *
						cblend.inputs[j].ms->getValue(cblend.channel, cframe);
				}
				result->setValue(cblend.channel, frame, value);
			}
		}
	}

	return result;
}
void MotionGraphController::readInMotionSequences(MotionDataSpecification& motion_data_specs)
{
	for (unsigned short i = 0; i<motion_data_specs.size(); i++)
	{
		string current_file = motion_data_specs.getBvhFilename(i);
		cout << "MotionGraphController reading " << current_file << endl;
		logout << "MotionGraphController reading "  << current_file << endl;

		char* BVH_filename = NULL;
		string character_BVH2(current_file);
		try
		{
			BVH_filename = data_manager.findFile(character_BVH2.c_str());
			if (BVH_filename == NULL)
			{
				stringstream ss;
				ss << "MotionGraphController::readInMotionSequences: Unable to find character BVH file <" << character_BVH2 << ">. Aborting load.";
				logout << ss.str() << endl;
				throw AppException(ss.str().c_str());
			}
			pair<Skeleton*, MotionSequence*> read_result;
			try
			{
				read_result = data_manager.readBVH(BVH_filename);
			}
			catch (const DataManagementException& dme)
			{
				stringstream ss;
				ss << "MotionGraphController::readInMotionSequences: Aborting due to DataManager expection: " << dme.msg;
				logout << ss.str();
				throw AppException(ss.str().c_str());
			}

			// throw away the skeleton
			delete read_result.first;
			MotionSequence * ms = read_result.second;

			string seqID = motion_data_specs.getSeqID(i);
			char* tmp = new char[strlen(seqID.c_str())+1];
			strcpy(tmp, seqID.c_str());
			ms->setId(tmp);
			delete [] tmp;

			//scale the character position in the motion sequence
			ms->scaleChannel(CHANNEL_ID(0, CT_TX), character_size_scale);
			ms->scaleChannel(CHANNEL_ID(0, CT_TY), character_size_scale);
			ms->scaleChannel(CHANNEL_ID(0, CT_TZ), character_size_scale);

			motion_sequence_map.insert(pair<string, MotionSequence*>(seqID, ms));
		}
		catch (BasicException& e)
		{
			stringstream ss;
			ss << "MotionGraphController::readInMotionSequences: Aborting due to BasicException: " << e.msg;
			logout << ss.str();
			throw AppException(ss.str().c_str());
		}
	}
	logout << "the number of motion sequences is : " << motion_sequence_map.size() << endl;
	logout << "... MotionGraphController::readInMotionSequences finished" << endl;
}
Esempio n. 4
0
void MotionGraphController::readInMotionSequences()
{
	cout << "reading motion Sequences" << endl;
	namespace fs = ::boost::filesystem;

	fs::path p(BVH_MOTION_FILE_PATHMOTIONS);
	if (!exists(p))    // does p actually exist?
		cout << "doesn't exist" << endl;
	fs::directory_iterator end_itr;

	// cycle through the directory
	for (fs::directory_iterator itr(p); itr != end_itr; ++itr)
	{
		// If it's not a directory, list it. If you want to list directories too, just remove this check.
		if (is_regular_file(itr->path())) {
			// assign current file name to current_file and echo it out to the console.
			string current_file = itr->path().string();
			current_file = itr->path().filename().string();

			cout << current_file << endl;

			DataManager dataman;
			dataman.addFileSearchPath(BVH_MOTION_FILE_PATHMOTIONS);
			char* BVH_filename = NULL;
			string character_BVH2(current_file);
			try
			{
				BVH_filename = dataman.findFile(character_BVH2.c_str());
				if (BVH_filename == NULL)
				{
					logout << "AnimationControl::loadCharacters: Unable to find character BVH file <" << character_BVH2 << ">. Aborting load." << endl;
					throw BasicException("ABORT");
				}
				pair<Skeleton*, MotionSequence*> read_result;
				try
				{
					read_result = data_manager.readBVH(BVH_filename);
				}
				catch (const DataManagementException& dme)
				{
					logout << "AnimationControl::loadCharacters: Unable to load character data files. Aborting load." << endl;
					logout << "   Failure due to " << dme.msg << endl;
					throw BasicException("ABORT");
				}

				Skeleton* skel = read_result.first;
				MotionSequence * ms = read_result.second;
				
				std::string x = current_file;
				char *y = new char[x.length() + 1];
				std::strcpy(y, x.c_str());
				//set the ID aka filename
				ms->setId(y);
				delete[] y;

				//scale each motion sequence once
				ms->scaleChannel(CHANNEL_ID(0, CT_TX), character_size_scale);
				ms->scaleChannel(CHANNEL_ID(0, CT_TY), character_size_scale);
				ms->scaleChannel(CHANNEL_ID(0, CT_TZ), character_size_scale);

				MotionSequenceContainer test;
				test.MS = ms;
				test.SeqID = current_file;
				MsVector.push_back(test);
				cout << "done loading:  "<<current_file << MsVector.size() << endl;
			}
			catch (BasicException& e) { cout << e.msg << endl; }
		}
	}
	cout << "the size of the vector is : " << MsVector.size() << endl;
}
Esempio n. 5
0
MotionGraphController::MotionGraphController(MotionGraph &input)
{
	g = input;
	//Connector(g.allFrames.at(0), g.allFrames.at(1));
	cout << "initializing Motion Graph Controller \n Reading all frames to test first \n then Checking for neighbors \n" << endl;
	// pretty much tests to see if all frames are readable in the graph;
	readAllFrames();
	//read in the motion sequences
	readInMotionSequences();
	//read all the ids in the vector of MsVNames
	readAllSequenceIDs();

	/* test code*/
	status.FrameNumber = 0;
	status.SeqID = "swing5.bvh";
	status.isTransitioning = true;
	status.TransitionToSeqId = "swing5.bvh";
	MotionSequence *MS;
	MotionSequence *MS2;
	MotionSequence *MS3;
	MotionSequence *MS4;
	MS = returnMotionSequenceContainerFromID(status.SeqID).MS;
	status.FrameNumberTransition = MS->numFrames();
	status.FrameNumberTransitionTo = 0;



	//temp vertex target list
	/*
	MotionGraphController::vertexTargets temp;
	temp.SeqID = "swing5.bvh";
	temp.SeqID2 = "swing6.bvh";
	temp.FrameNumber = MS->numFrames();
	temp.FrameNumber2 = 0;
	path.push_back(temp);
	//second transition
	MS2 = returnMotionSequenceContainerFromID("swing6.bvh").MS;
	temp.SeqID = "swing6.bvh";
	temp.SeqID2 = "swing5.bvh";
	temp.FrameNumber = MS2->numFrames();
	temp.FrameNumber2 = 0;
	path.push_back(temp);

	MS3 = returnMotionSequenceContainerFromID("swing5.bvh").MS;
	temp.SeqID = "swing5.bvh";
	temp.SeqID2 = "swing7.bvh";
	temp.FrameNumber = MS3->numFrames();
	temp.FrameNumber2 = 0;
	path.push_back(temp);

	MS4 = returnMotionSequenceContainerFromID("swing7.bvh").MS;
	temp.SeqID = "swing7.bvh";
	temp.SeqID2 = "swing8.bvh";
	temp.FrameNumber = MS4->numFrames();
	temp.FrameNumber2 = 0;
	path.push_back(temp);

	MS4 = returnMotionSequenceContainerFromID("swing8.bvh").MS;
	temp.SeqID = "swing8.bvh";
	temp.SeqID2 = "swing9.bvh";
	temp.FrameNumber = MS4->numFrames();
	temp.FrameNumber2 = 0;
	path.push_back(temp);

	MS4 = returnMotionSequenceContainerFromID("swing9.bvh").MS;
	temp.SeqID = "swing9.bvh";
	temp.SeqID2 = "swing10.bvh";
	temp.FrameNumber = MS4->numFrames();
	temp.FrameNumber2 = 0;
	path.push_back(temp);

	MS4 = returnMotionSequenceContainerFromID("swing10.bvh").MS;
	temp.SeqID = "swing10.bvh";
	temp.SeqID2 = "swing11.bvh";
	temp.FrameNumber = MS4->numFrames();
	temp.FrameNumber2 = 0;
	path.push_back(temp);
	

	printStatus();
	cout << "update status" << endl;
	iterateStatus();
	pathBackup = path;
	*/
	//set the current_vertex 
	// only use once the names of the files MS match up with the names of the motion graph verticies 
	//CurrentVertex = FindVertex(status.SeqID, status.FrameNumber); 
	//cout << "just for testing" << endl;
}