示例#1
0
void FubiRecorder::recordNextSkeletonFrame(const FubiHand& hand)
{
	const Fubi::FingerTrackingData* data = (const Fubi::FingerTrackingData*)(m_useFilteredData
		? hand.currentFilteredTrackingData()
		: hand.currentTrackingData());

	int leftFingerCount = (hand.getHandType() == SkeletonJoint::LEFT_HAND) ? data->fingerCount :- 1;
	int rightFingerCount = (hand.getHandType() == SkeletonJoint::RIGHT_HAND) ? data->fingerCount : -1;

	recordNextSkeletonFrame(data, leftFingerCount, rightFingerCount);
}
void FubiRecorder::recordNextSkeletonFrame(const FubiHand& hand)
{
	if (m_isRecording && (hand.currentTrackingData()->timeStamp - m_lastTimeStamp) > Math::Epsilon)
	{
		const FubiHand::FingerTrackingData* data = m_useFilteredData
			? hand.currentFilteredTrackingData()
			: hand.currentTrackingData();

		m_lastTimeStamp = data->timeStamp;

		xml_document<> doc;
		// Create base node
		xml_node<>* frameNode = doc.allocate_node(node_element, "Frame");
		doc.append_node(frameNode);
		// With time attribute		
		xml_attribute<>* attr = doc.allocate_attribute("time", doc.allocate_string(numToString(m_lastTimeStamp - m_recordingStart, 6).c_str()));
		frameNode->append_attribute(attr);
		// And frame id		
		attr = doc.allocate_attribute("frameID", doc.allocate_string(numToString(m_currentFrameID++, 0).c_str()));
		frameNode->append_attribute(attr);

		// Create all sub nodes for the frame
		xml_node<>* jointPositions = doc.allocate_node(node_element, "JointPositions");
		frameNode->append_node(jointPositions);
		xml_node<>* jointOrientations = doc.allocate_node(node_element, "JointOrientations");
		frameNode->append_node(jointOrientations);

		// Now fill them with the joint data
		for (int i = 0; i < SkeletonHandJoint::NUM_JOINTS; ++i)
		{
			xml_node<>* joint = doc.allocate_node(node_element, "Joint");
			joint->append_attribute(doc.allocate_attribute("name", getHandJointName((SkeletonHandJoint::Joint)i)));
			const Vec3f* pos = &(data->jointPositions[i].m_position);
			joint->append_attribute(doc.allocate_attribute("x", doc.allocate_string(numToString(pos->x, 0).c_str())));
			joint->append_attribute(doc.allocate_attribute("y", doc.allocate_string(numToString(pos->y, 0).c_str())));
			joint->append_attribute(doc.allocate_attribute("z", doc.allocate_string(numToString(pos->z, 0).c_str())));
			joint->append_attribute(doc.allocate_attribute("confidence", doc.allocate_string(numToString(data->jointPositions[i].m_confidence, 0).c_str())));
			jointPositions->append_node(joint);

			joint = doc.allocate_node(node_element, "Joint");
			joint->append_attribute(doc.allocate_attribute("name", getHandJointName((SkeletonHandJoint::Joint)i)));
			const Vec3f* rot = &(data->jointOrientations[i].m_orientation.getRot());
			joint->append_attribute(doc.allocate_attribute("x", doc.allocate_string(numToString(rot->x, 2).c_str())));
			joint->append_attribute(doc.allocate_attribute("y", doc.allocate_string(numToString(rot->y, 2).c_str())));
			joint->append_attribute(doc.allocate_attribute("z", doc.allocate_string(numToString(rot->z, 2).c_str())));
			joint->append_attribute(doc.allocate_attribute("confidence", doc.allocate_string(numToString(data->jointOrientations[i].m_confidence, 0).c_str())));
			jointOrientations->append_node(joint);
		}
		
		if (data->fingerCount > -1)
		{
			xml_node<>* fingercounts = doc.allocate_node(node_element, "FingerCounts");
			frameNode->append_node(fingercounts);
			fingercounts->append_attribute(doc.allocate_attribute((hand.getHandType()==SkeletonJoint::LEFT_HAND) ? "left" : "right", doc.allocate_string(numToString(data->fingerCount, 0).c_str())));
		}

		// Write the frame node to the file
		// Call the internal print_node directly to start at a different indent level
		internal::print_node(std::ostream_iterator<char>(m_file), frameNode, 0, 1);
		if (m_file.fail())
		{
			Fubi_logErr("Error writing skeleton data to file: %s \n", m_fileName.c_str());
			stopRecording();
		}
	}
}