TEST(OsgViewElementRenderTest, StereoView)
{
	std::shared_ptr<Runtime> runtime = std::make_shared<Runtime>();
	std::shared_ptr<OsgManager> manager = std::make_shared<OsgManager>();

	runtime->addManager(manager);
	runtime->addManager(std::make_shared<SurgSim::Framework::BehaviorManager>());

	std::shared_ptr<Scene> scene = runtime->getScene();

	/// Add a graphics component to the scene
	std::shared_ptr<OsgViewElement> viewElement = std::make_shared<OsgViewElement>("view");

	auto boxElement = std::make_shared<SurgSim::Framework::BasicSceneElement>("box");

	RigidTransform3d pose =
		makeRigidTransform(Vector3d(1.0, 1.0, 1.0), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 1.0, 0.0));
	viewElement->setPose(pose);
	scene->addSceneElement(viewElement);

	auto box = std::make_shared<OsgBoxRepresentation>("box");
	box->setSizeXYZ(0.1, 0.1, 0.2);
	boxElement->addComponent(box);

	RigidTransform3d from =
		makeRigidTransform(Vector3d(0.2, 0.0, 0.0), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 1.0, 0.0));
	RigidTransform3d to =
		makeRigidTransform(Vector3d(-0.2, 0.0, 0.0), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 1.0, 0.0));
	auto interpolator = std::make_shared<SurgSim::Blocks::PoseInterpolator>("interpolator");

	interpolator->setDuration(2.0);
	interpolator->setStartingPose(from);
	interpolator->setEndingPose(to);
	interpolator->setPingPong(true);
	interpolator->setTarget(boxElement);

	boxElement->addComponent(interpolator);

	scene->addSceneElement(boxElement);

	auto osgView = std::static_pointer_cast<OsgView>(viewElement->getView());
	osgView->setStereoMode(View::STEREO_MODE_HORIZONTAL_SPLIT);
	osgView->setDisplayType(View::DISPLAY_TYPE_MONITOR);
	osgView->setEyeSeparation(0.06);
	osgView->setScreenWidth(0.486918);
	osgView->setScreenHeight(0.273812);
	osgView->setScreenDistance(1.0);


	runtime->start();
	boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
	runtime->stop();
}
Beispiel #2
0
OculusView::OculusView(const std::string& name) : OsgView(name)
{
	SURGSIM_ADD_SERIALIZABLE_PROPERTY(OculusView, std::shared_ptr<SurgSim::Framework::Component>, InputComponent,
									  getInputComponent, setInputComponent);

	// Default Settings of Oculus DK2
	setFullScreen(true);
	setDisplayType(View::DISPLAY_TYPE_HMD);
	setStereoMode(View::STEREO_MODE_HORIZONTAL_SPLIT);
	setScreenWidth(0.0631);
	setScreenHeight(0.071);
	setEyeSeparation(0.06);
	setScreenDistance(0.10);
	setTargetScreen(1); // Assume Oculus HMD has ID '1'.

	std::array<int, 2> dimensions = {1920, 1080};
	setDimensions(dimensions);
}
void bimWorld::CameraManipulator::switchMatrixManipulator(ManipulatorType emanip)
{
	auto viewer = m_host->_ViewerData()->ModelViewer();
	auto sceneRoot = m_host->_ViewerData()->getSceneRoot();
	auto modelRoot = m_host->_ViewerData()->getModelRoot();
	if (!viewer || !sceneRoot || !modelRoot)
	{
		return;
	}
	m_host->_RenderingThreads()->setIsExternalRendering(true);
	auto manip = viewer->getCameraManipulator();
	osg::Vec3d eye, center, up;
	auto matrix = manip->getMatrix();
	manip->getHomePosition(eye, center, up);
	switch (emanip)
	{
	case ManipulatorType::Default:
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT0,
			osg::StateAttribute::ON);
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT1,
			osg::StateAttribute::ON);
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT2,
			osg::StateAttribute::OFF);
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT3,
			osg::StateAttribute::OFF);
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT4,
			osg::StateAttribute::OFF);
		((BIMCameraManipulator*)m_d.get())->setPosition(eye, center, up, matrix);

		////                BIMCameraManipulator* mat = (BIMCameraManipulator*)(m_d.get());
		//                 ((BIMCameraManipulator*)m_d.get())->beginSetCameraMatrix();
		//                ((BIMCameraM-anipulator*)m_d.get())->setByMatrix(matrix);
		//               ((BIMCameraManipulator*)m_d.get())->endSetCameraMatrix();
		viewer->setCameraManipulator(((BIMCameraManipulator*)m_d.get()), false);
		break;
	case ManipulatorType::Person:
	{
		auto oldManip = static_cast<BIMCameraManipulator*>(manip);
		if (!oldManip)
			break;
		auto rotation = oldManip->getRotation();
		auto dist = oldManip->getDistance();
		auto personManip = static_cast<PersonManipulator*>(m_p.get());
		if (!personManip)
			break;
		personManip->setScreenRotation(rotation);
		personManip->setScreenDistance(dist);
		personManip->setPosition(eye, center, up, matrix);
		viewer->setCameraManipulator(personManip, false);
		break;
	}
	case ManipulatorType::FirstPerson:
	{
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT0,
			osg::StateAttribute::OFF);
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT1,
			osg::StateAttribute::OFF);
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT2,
			osg::StateAttribute::ON);
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT3,
			osg::StateAttribute::ON);
		sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHT4,
			osg::StateAttribute::ON);

		osgGA::CameraManipulator* first = new BIMFirstPersonManipulator(m_host);
		viewer->setCameraManipulator(first, true);

		first->setHomePosition(modelRoot->getBound().center(), osg::Vec3(0, 0, 0), up);
		viewer->home();
		break;
	}
	}
	m_host->_RenderingThreads()->setIsExternalRendering(false);

	return;

	//		osgGA::KeySwitchMatrixManipulator *switchmanipulator = dynamic_cast<osgGA::KeySwitchMatrixManipulator*>(m_mViewer->getCameraManipulator());
	//
	//		//m_ptrKeySwitchMatrixManipulator=new osgGA::KeySwitchMatrixManipulator;
	//		//m_ptrKeySwitchMatrixManipulator->addMatrixManipulator(1,"deflaut",createCameraManipulator());
	//		//m_ptrKeySwitchMatrixManipulator->addMatrixManipulator(2,"person",createPersonManipulator());
	//		switchmanipulator->selectMatrixManipulator((int)emanip);
	//		if (emanip == deflaut)
	//		{
	//			BIMCameraManipulator* manipulator = dynamic_cast<BIMCameraManipulator*>(switchmanipulator->getCurrentMatrixManipulator());
	//
	//			zoomTo(m_modelRoot);
	//			//if (manipulator)
	//			//{
	//			//	manipulator->setupFrameRateController(m_modelRoot.get());
	//			//	manipulator->setModelRoot(m_modelRoot);
	//			//}
	//		}
	//		else if (emanip == person)
	//		{
	//			PersonManipulator* manipulator = dynamic_cast<PersonManipulator*>(switchmanipulator->getCurrentMatrixManipulator());
	//			zoomTo(m_modelRoot);
	//			//if (manipulator)
	//			//{
	//			//	manipulator->setupFrameRateController(m_modelRoot.get());
	//			//	manipulator->setModelRoot(m_modelRoot);
	//			//}
	//		}

	m_host->_RenderingThreads()->updateSeveralTimes(1);
}