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();
}
Exemple #2
0
/** Called when asyn clients call pasynInt32->write().
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Value to write. */
asynStatus drvQuadEM::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
    int function = pasynUser->reason;
    int status = asynSuccess;
    int channel;
    const char *paramName;
    const char* functionName = "writeInt32";

    getAddress(pasynUser, &channel);
    
    /* Set the parameter in the parameter library. */
    status |= setIntegerParam(channel, function, value);
    
    /* Fetch the parameter string name for possible use in debugging */
    getParamName(function, &paramName);

    if (function == P_Acquire) {
        if (value) {
            epicsRingBytesFlush(ringBuffer_);
            ringCount_ = 0;
        }
        status |= setAcquire(value);
    } 
    else if (function == P_AcquireMode) {
        if (value != QEAcquireModeContinuous) {
            status |= setAcquire(0);
            setIntegerParam(P_Acquire, 0);
        } 
        status |= setAcquireMode(value);
        status |= readStatus();
    }
    else if (function == P_BiasState) {
        status |= setBiasState(value);
        status |= readStatus();
    }
    else if (function == P_BiasInterlock) {
        status |= setBiasInterlock(value);
        status |= readStatus();
    }
    else if (function == P_NumChannels) {
        status |= setNumChannels(value);
        status |= readStatus();
    }
    else if (function == P_NumAcquire) {
        status |= setNumAcquire(value);
        status |= readStatus();
    }
    else if (function == P_PingPong) {
        status |= setPingPong(value);
        status |= readStatus();
    }
    else if (function == P_Range) {
        status |= setRange(value);
        status |= readStatus();
    }
    else if (function == P_ReadData) {
        status |= doDataCallbacks();
    }
    else if (function == P_Resolution) {
        status |= setResolution(value);
        status |= readStatus();
    }
    else if (function == P_TriggerMode) {
        status |= setTriggerMode(value);
        status |= readStatus();
    }
    else if (function == P_ValuesPerRead) {
        valuesPerRead_ = value;
        status |= setValuesPerRead(value);
        status |= readStatus();
    }
    else if (function == P_ReadFormat) {
        status |= setReadFormat(value);
        status |= readStatus();
    }
    else if (function == P_ReadStatus) {
        // We don't do this if we are acquiring, too disruptive
        if (!acquiring_) {
            status |= readStatus();
        }
    }
    else if (function == P_Reset) {
        status |= reset();
        status |= readStatus();
    }
    else {
        /* All other parameters just get set in parameter list, no need to
         * act on them here */
    }
    
    /* Do callbacks so higher layers see any changes */
    status |= (asynStatus) callParamCallbacks();
    
    if (status) 
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d, name=%s, value=%d", 
                  driverName, functionName, status, function, paramName, value);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, name=%s, value=%d\n", 
              driverName, functionName, function, paramName, value);
    return (asynStatus)status;
}
Exemple #3
0
/** Constructor for the drvAPS_EM class.
  * Calls the constructor for the drvQuadEM base class.
  * \param[in] portName The name of the asyn port driver to be created.
  * \param[in] baseAddr A24 base address of the VME card
  * \param[in] fiberChannel Address [0-3] of the fiber channel connected to the electrometer
  * \param[in] unidigName Name of asynPort for the Ip-Unidig driver if it is being used to generate interrupts
  * \param[in] unidigChan Channel number [0-23] of the Ip-Unidig connected to the APS_EM pulse output, if Ip-Unidig is being used.
  * \param[in] unidigDrvInfo  The drvInfo field for the data callback of the ipUnidig driver. 
  *            If not specified then asynUser->reason=0 is used.
  * \param[in] ringBufferSize The number of samples to hold in the input ring buffer.
  *            This should be large enough to hold all the samples between reads of the
  *            device, e.g. 1 ms SampleTime and 1 second read rate = 1000 samples.
  *            If 0 then default of 2048 is used.
  */
drvAPS_EM::drvAPS_EM(const char *portName, unsigned short *baseAddr, int fiberChannel,
                     const char *unidigName, int unidigChan, char *unidigDrvInfo, int ringBufferSize)
   : drvQuadEM(portName, 0, ringBufferSize),
    unidigChan_(unidigChan),
    pUInt32DigitalPvt_(NULL),
    pUInt32RegistrarPvt_(NULL)
{
    asynInterface *pasynInterface;
    asynDrvUser *pdrvUser;
    unsigned long probeVal;
    epicsUInt32 mask;
    asynStatus status;
    static const char *functionName = "drvAPS_EM";
    
    readingsAveraged_ = 0;

    if ((unidigName != 0) && (strlen(unidigName) != 0) && (strcmp(unidigName, "0") != 0)) {
        /* Create asynUser */
        pUInt32DAsynUser_ = pasynManager->createAsynUser(0, 0);

        /* Connect to device */
        status = pasynManager->connectDevice(pUInt32DAsynUser_, 
                                             unidigName, unidigChan_);
        if (status != asynSuccess) {
            errlogPrintf("initQuadEM: connectDevice failed for ipUnidig\n");
            goto error;
        }

        /* Get the asynUInt32DigitalCallback interface */
        pasynInterface = pasynManager->findInterface(pUInt32DAsynUser_, 
                                                   asynUInt32DigitalType, 1);
        if (!pasynInterface) {
            errlogPrintf("%s:%s:, find asynUInt32Digital interface failed\n", driverName, functionName);
            goto error;
        }
        pUInt32Digital_ = (asynUInt32Digital *)pasynInterface->pinterface;
        pUInt32DigitalPvt_ = pasynInterface->drvPvt;
        
        /* If the drvInfo is specified then call drvUserCreate, else assume asynUser->reason=0 */
        if (unidigDrvInfo) {
            pasynInterface = pasynManager->findInterface(pUInt32DAsynUser_, 
                                                         asynDrvUserType, 1);
            if (!pasynInterface) {
                errlogPrintf("%s:%s:, find asynDrvUser interface failed\n", driverName, functionName);
            goto error;
            }
            pdrvUser = (asynDrvUser *)pasynInterface->pinterface;
            status = pdrvUser->create(pasynInterface->drvPvt, pUInt32DAsynUser_, unidigDrvInfo, NULL, 0);
            if (status != asynSuccess) {
                errlogPrintf("%s:%s: drvUser->create failed for ipUnidig\n", driverName, functionName);
                goto error;
            }
        } else {
            pUInt32DAsynUser_->reason = 0;
        }
    }
 
    if ((fiberChannel >= 4) || (fiberChannel < 0)) {
        errlogPrintf("%s:%s:: Invalid channel # %d \n", driverName, functionName, fiberChannel);
        goto error;
    }

    if (baseAddr >= (unsigned short *)MAX_A24_ADDRESS) {
        errlogPrintf("%s:%s:: Invalid Module Address %p \n", driverName, functionName, baseAddr);
        goto error;
    }

    /* The channel # goes in bits 5 and 6 */
    baseAddr = (unsigned short *)((int)baseAddr | ((fiberChannel << 5) & 0x60));
    if (devRegisterAddress("APS_EM", atVMEA24, (int)baseAddr, 16, 
                           (volatile void**)&baseAddress_) != 0) {
        baseAddress_ = NULL;
        errlogPrintf("%s:%s: A24 Address map failed\n", driverName, functionName);
        goto error;
    }

    if (devReadProbe(4, (char *)baseAddress_, (char *)&probeVal) != 0 ) {
        errlogPrintf("%s:%s:: devReadProbe failed for address %p\n", 
                     driverName, functionName, baseAddress_);
        baseAddress_ = NULL;
        goto error;
    }

    if (pUInt32DigitalPvt_ == NULL) {
        if (epicsThreadCreate("APS_EMPoller",
                              epicsThreadPriorityMedium,
                              epicsThreadGetStackSize(epicsThreadStackMedium),
                              (EPICSTHREADFUNC)pollerThreadC,
                              this) == NULL) {
            errlogPrintf("%s:%s: quadEMPoller epicsThreadCreate failure\n", driverName, functionName);
        goto error;
        }
    }
    else {
        /* Make sure interrupts are enabled on the falling edge of the 
         * quadEM output pulse */
        pUInt32Digital_->getInterrupt(pUInt32DigitalPvt_, 
                                     pUInt32DAsynUser_, &mask,
                                     interruptOnOneToZero);
        mask |= 1 << unidigChan_;
        pUInt32Digital_->setInterrupt(pUInt32DigitalPvt_, 
                                    pUInt32DAsynUser_, mask,
                                    interruptOnOneToZero);
    }
    
    /* Set the model */
    setIntegerParam(P_Model, QE_ModelAPS_EM);
    
    /* Set the range, ping-pong and integration time to reasonable defaults */
    setRange(0);
    setPingPong(0);
    setIntegrationTime(0.001); 

    /* Send the initial settings to the board to get it talking to the 
     * electometer. These settings will be overridden by the database values 
     * when the database initializes */
    reset();
    
    /* Calling readStatus() will compute the sampleTime, which must be done before iocInit
     * or fast feedback won't work. */
    readStatus();
    
    error:
    return;
}