示例#1
0
文件: VRRect.cpp 项目: MinVR/MinVR
void VRRect::write(VRDataIndex& index, std::string name) const {
	index.addData(name + "/xOffset", m_xOffset);
	index.addData(name + "/yOffset", m_yOffset);
	index.addData(name + "/width", m_width);
	index.addData(name + "/height", m_height);
	index.addData(name + "/usePercent", m_usePercent);
}
示例#2
0
void VRVRPNButtonDevice::sendEvent(int buttonNumber, bool down)
{
    VRDataIndex di;
	std::string name = getEventName(buttonNumber);
	if (down) {
        name = name + "_Down";
		di.addData(name + "/id", buttonNumber);
	    _pendingEvents.push(di.serialize(name));
	}
	else {
        name = name + "_Up";
		di.addData(name + "/id", buttonNumber);
	    _pendingEvents.push(di.serialize(name));
	}
}
示例#3
0
int TestQueueArray() {

  std::string testString = "<VRDataQueue num=\"2\"><VRDataQueueItem timeStamp=\"1454671331220377\"><atestarray type=\"intarray\" separator=\"@\">0@1@2@3@4@5@6@7@8@9@10@11@12@13@14@15@16@17@18@19@20@21@22@23@24@25@26@27@28@29@30@31@32@33@34@35@36@37@38@39@40@41@42@43@44@45@46@47@48@49@50@51@52@53@54@55@56@57@58@59@60@61@62@63@64@65@66@67@68@69@70@71@72@73@74@75@76@77@78@79@80@81@82@83@84@85@86@87@88@89@90@91@92@93@94@95@96@97@98@99</atestarray></VRDataQueueItem><VRDataQueueItem timeStamp=\"1454671331220395\"><d0 type=\"doublearray\">1.200000,2.300000,3.400000,4.500000,5.600000</d0></VRDataQueueItem></VRDataQueue>";

  testString = removeTimeStamps(testString);
  
  VRDataIndex *n = setupQIndex();
  VRDataQueue *q = new VRDataQueue;
  
  std::vector<int>e;

  for (int i = 0; i < 100; i++) {
    e.push_back(i);
  }

  n->addData("/george/atestarray", e);
  n->getDatum("/george/atestarray")->setAttributeValue("separator", "@");
  
  q->push(n->serialize("atestarray", "/george/"));
  q->push(n->serialize("/donna/d0"));
  
  std::string output = removeTimeStamps(q->serialize());
  
  //std::cout << "test:" << testString << std::endl;
  //std::cout << "outp:" << output << std::endl;
  
  // Test that the new queue is the same as the test string.
  int out = output.compare(testString);
  delete n;
  delete q;
  
  return out;
}
/**
The tracker reports the transformation that would transform stuff
in tracker space to device space (that is, to the space relative to
the origin of the tracking device).  First we change the units on
the translation part of this since we usually work in feet and most
tracking systems report mesurements in some metric system.  Then we
have a transformation in feet relative to the device.  We multiply
by a transformation that transforms stuff in device space to IS3D
room space.  You can think of this as what rotation, then
translation would move the origin of RoomSpace to the origin of
tracking device.  This is the deviceToRoom coordinate frame.
*/
void VRVRPNTrackerDevice::processEvent(const VRMatrix4 &vrpnEvent, int sensorNum)
{

    if ((_ignoreZeroes) && (vrpnEvent.getColumn(3) == VRVector3(0,0,0))) {
    	return;
	}
	_newReportFlag = true;

	// first, adjust units of trackerToDevice.  after this, everything
	// is in RoomSpace units (typically feet for VRG3D).
	VRMatrix4 trackerToDevice = vrpnEvent;

	// convert a left handed coordinate system to a right handed one
	// not sure if this actually works..
	if (_convertLHtoRH) {
		/*** This is code from syzygy..
		CoordinateFrame switchMat(Matrix3(1,0,0, 0,0,1, 0,-1,0), Vector3::zero());
		CoordinateFrame transMat(switchMat.inverse() * vrpnEvent.translation);
		CoordinateFrame rotMat(vrpnEvent.rotation, Vector3::zero());
		trackerToDevice = transMat * switchMat.inverse() * rotMat * switchMat;
		***/

		// This code is based on the article "Conversion of Left-Handed
		// Coordinates to Right-Handed Coordinates" by David Eberly,
		// available online:
		// http://www.geometrictools.com/Documentation/LeftHandedToRightHanded.pdf
		trackerToDevice[3][2] = -trackerToDevice[3][2];

		trackerToDevice[2][0] = -trackerToDevice[2][0];
		trackerToDevice[2][1] = -trackerToDevice[2][1];
		trackerToDevice[0][2] = -trackerToDevice[0][2];
		trackerToDevice[1][2] = -trackerToDevice[1][2];
	}

	trackerToDevice[3][0] *= _trackerUnitsToRoomUnitsScale;
	trackerToDevice[3][1] *= _trackerUnitsToRoomUnitsScale;
	trackerToDevice[3][2] *= _trackerUnitsToRoomUnitsScale;

	VRMatrix4 eventRoom = _finalOffset[sensorNum] * _deviceToRoom * trackerToDevice * _propToTracker[sensorNum];

	if ((_printSensor0) && (sensorNum == 0)) {
        VRVector3 translation = eventRoom.getColumn(3);
		std::cout << translation << std::endl;
	}

	VRDataIndex di;
    std::string name = getEventName(sensorNum) + "_Move";
	di.addData(name + "/Transform", eventRoom);
    _pendingEvents.push(di.serialize(name));
}
示例#5
0
int TestQueueUnpack() {

  std::string testString;

  // Create an index and a queue.
  VRDataIndex *n = setupQIndex();
  VRDataQueue *q = new VRDataQueue;
  
  std::vector<int>e;

  for (int i = 0; i < 100; i++) {
    e.push_back(i);
  }

  // Add an array to the index.
  n->addData("/george/atestarray", e);

  // Get the serialized version of an index object.
  testString = n->serialize("/george");

  // Put that object into the queue.
  q->push(n->serialize("/george"));
  
  VRDataIndex* index = new VRDataIndex;

  // Unpack the serialized object.
  index->addSerializedValue( q->getSerializedObject(), "/" );

  // Unpack it into a different index.
  std::string output = index->serialize("/george");

  // Does it match?
  int out = testString.compare(output);

  delete n;
  delete q;
  delete index;

  return out;
}
示例#6
0
int main() {
  VRDataIndex *index = new VRDataIndex;

  // Create a container object called cora, with two member objects.
  index->addData("/cora/nora", 4);
  index->addData("/cora/flora", "gosh and golly");

  // Create another container called homer, with two members.
  index->addData("/homer/bart", 3.4);
  index->addData("/homer/lisa", 5.2);

  // Show the index structure.
  std::cout << "Index Structure" << std::endl;
  std::cout << index->printStructure();

  VRDataQueue *queue = new VRDataQueue;

  // Push cora onto the queue.
  queue->push(index->serialize("cora", "/"));

  // Change the values of cora's members.
  index->addData("/cora/nora", 7);
  index->addData("/cora/flora", "are you sure?");

  VRIntArray ia;
  ia.push_back(1);
  ia.push_back(2);
  ia.push_back(3);
  index->addData("/cora/ia", ia);

  VRDoubleArray da;
  da.push_back(1.2);
  da.push_back(3.4);
  da.push_back(5.6);
  index->addData("/cora/da", da);

  VRStringArray sa;
  sa.push_back("hello");
  sa.push_back("good-bye");
  index->addData("/cora/sa", sa);
  
  std::cout << "Index Structure after changing /cora" << std::endl;
  std::cout << index->printStructure();

  // Push the new cora onto the queue.
  queue->push(index->serialize("cora", "/"));

  // Push homer onto the queue.
  queue->push(index->serialize("homer", "/"));

  // Show the queue.
  std::cout << "Queue" << std::endl;
  std::cout << queue->printQueue();

  std::cout << std::endl;
  std::cout << "serialized queue: " << queue->serialize() << std::endl;
  std::string queueData = queue->serialize();
  
  // Pretend we are in a remote program, having received event data
  // over the net.  It comes in as some kind of string data called
  // queueData.
  VRDataQueue *newQueue = new VRDataQueue(queueData);

  // Here's the index we'll populate with the new data.
  VRDataIndex *remoteIndex = new VRDataIndex;
  
  // While there is something in the queue, unpack it into the index,
  // and examine it.
  while (newQueue->notEmpty()) {

    // Unpack the items from the queue.
    std::string p =
      remoteIndex->addSerializedValue( newQueue->getSerializedObject() );

    std::cout << std::endl << "examining the data..." << std::endl;
    std::cout << "The object named " << p << " is a " <<
      remoteIndex->getTypeString(p) << "." << std::endl;
    if (remoteIndex->getType(p) == VRCORETYPE_CONTAINER) {
      VRContainer lp = remoteIndex->getValue(p);

      std::cout << "... it contains these" << std::endl;

      for (VRContainer::iterator it = lp.begin(); it != lp.end(); it++) {
        std::cout << "  " << *it << " (" << remoteIndex->getTypeString(*it) << ")" << std::endl;
      }
    }
    
    // Print out the entire index.
    std::cout << "Remote Index Structure" << std::endl;
    std::cout << remoteIndex->printStructure();

    // Perform arithmetic with some data from the index.
    int r = remoteIndex->getValue("/cora/nora");
    std::cout << " ... sum of /cora/nora and seven = " << 7 + r << std::endl;

    // Get the next item from the queue.
    newQueue->pop();

  }
}
示例#7
0
// This is pretty much the same function as setupIndex() in
// indextest.cpp, but has its name changed to avoid link conflicts in
// the construction of test_runner.
VRDataIndex* setupQIndex() {

  VRDataIndex *n = new VRDataIndex;
  
  VRInt a = 4;
  VRDouble b = 3.1415926;
  
  n->addData("/george/a0", a);
  n->addData("/george/a1", a + 1);
  n->addData("/george/a2", a + 2);
  n->addData("/george/a3", a + 3);
  n->addData("/george/a4", a + 4);
  n->addData("/george/a5", a + 5);
  n->addData("/george/a6", a + 6);
  n->addData("/george/a7", a + 7);
  n->addData("/george/a8", a + 8);
  n->addData("/george/a9", a + 9);

  n->addData("/martha/b0", b);
  n->addData("/martha/b1", b * 1);
  n->addData("/martha/b2", b * 2);
  n->addData("/martha/b3", b * 3);
  n->addData("/martha/b4", b * 4);
  n->addData("/martha/b5", b * 5);
  n->addData("/martha/b6", b * 6);
  n->addData("/martha/b7", b * 7);
  n->addData("/martha/b8", b * 8);
  n->addData("/martha/b9", b * 9);

  VRString c = "abigail";
  n->addData("/john/c0", c + "0");
  n->addData("/john/c1", c + "1");
  n->addData("/john/c2", c + "2");
  n->addData("/john/c3", c + "3");
  n->addData("/john/c4", c + "4");
  n->addData("/john/c5", c + "5");
  n->addData("/john/c6", c + "6");
  n->addData("/john/c7", c + "7");
  n->addData("/john/c8", c + "8");
  n->addData("/john/c9", c + "9");

  std::vector<double>d;
  d.push_back(1.2);
  d.push_back(2.3);
  d.push_back(3.4);
  d.push_back(4.5);
  d.push_back(5.6);

  n->addData("/donna/d0", d);
  
  // This file is specified using the WORKING_DIRECTORY option in the
  // ctest framework.  See the CMakeLists.txt file in this directory,
  // and look for the add_test command.
  n->processXMLFile("test.xml", "/");
  
  return n;
}