Ejemplo n.º 1
0
void AgentMover::getAgents(std::vector<Agent>& agentsVector) const
{
    // Accessing shared buffer through OpenGL or else content would go random when acquiring the buffer with OpenCL lateron.

    BuffersMapping mapping = mapBuffers(GL_READ_ONLY);

    std::vector<Agent>::iterator iter;

    size_t i = 0;

    for (iter = agentsVector.begin(); iter != agentsVector.end(); ++iter)
    {
        (*iter).position        = mapping.positions[i];
        (*iter).direction       = mapping.directions[i];
        (*iter).speed           = mapping.speeds[i];
        (*iter).maximumSpeed    = mapping.maximumSpeeds[i];
        (*iter).radius          = mapping.radii[i];
        (*iter).id              = mapping.ids[i];
        (*iter).turnRate        = mapping.turnRates[i];

        i++;
    }

    unmapBuffers();
}
Ejemplo n.º 2
0
NaoCamera::NaoCamera(const char* device, CameraInfo::Camera camera, int width, int height, bool flip,
                     const CameraSettings::CameraSettingsCollection& settings, const Matrix5uc& autoExposureWeightTable) :
  camera(camera),
  WIDTH(width),
  HEIGHT(height)
{
  VERIFY((fd = open(device, O_RDWR | O_NONBLOCK)) != -1);

  mapBuffers();
  queueBuffers();

  setImageFormat();
  setFrameRate(1, 30);

  checkSettingsAvailability();

  specialSettings.horizontalFlip.value = flip ? 1 : 0;
  setControlSetting(specialSettings.horizontalFlip);
  specialSettings.verticalFlip.value = flip ? 1 : 0;
  setControlSetting(specialSettings.verticalFlip);
  setSettings(settings, autoExposureWeightTable);
  writeCameraSettings();
  readCameraSettings();

  startCapturing();
}
Ejemplo n.º 3
0
void AgentMover::setAgents(const std::vector<Agent>& agentsVector)
{
    if (agentsVector.size() != count)
    {
        throw Exception("AgentMover::setAgents: number of agents does not match previously set count");
    }

    // Accessing shared buffer through OpenGL or else content would go random when acquiring the buffer with OpenCL lateron.

    BuffersMapping mapping = mapBuffers(GL_WRITE_ONLY);

    std::vector<Agent>::const_iterator iter;

    size_t i = 0;

    for (iter = agentsVector.begin(); iter != agentsVector.end(); ++iter)
    {
        mapping.positions[i]      = (*iter).position;
        mapping.directions[i]     = (*iter).direction;
        mapping.speeds[i]         = (*iter).speed;
        mapping.maximumSpeeds[i]  = (*iter).maximumSpeed;
        mapping.radii[i]          = (*iter).radius;
        mapping.ids[i]            = (*iter).id;
        mapping.turnRates[i]      = (*iter).turnRate;

        i++;
    }

    unmapBuffers();
}
/* 
 * Setup filterbank internals
 */
bool ChannelizerBase::init()
{
	int i;

	/*
	 * Filterbank coefficients, fft plan, history, and output sample
	 * rate conversion blocks
	 */
	if (!initFilters()) {
		LOG(ERR) << "Failed to initialize channelizing filter";
		return false;
	}

	mResampler = new Resampler(mP, mQ, mFiltLen, mChanM);
	if (!mResampler->init()) {
		LOG(ERR) << "Failed to initialize resampling filter";
		return false;
	}

	history = (struct cxvec **) malloc(sizeof(struct cxvec *) * mChanM);
	for (i = 0; i < mChanM; i++) {
		history[i] =  cxvec_alloc(mFiltLen, 0, NULL, 0);
		cxvec_reset(history[i]);
	}

	if (!initFFT()) {
		LOG(ERR) << "Failed to initialize FFT";
		return false;
	}

	mapBuffers();

	return true;
}
KDvoid CCTextureAtlas::setupVBO ( KDvoid )
{
	if ( m_pBuffersVBO[0] )
	{
		glDeleteBuffers ( 2, &m_pBuffersVBO[0] );
		kdMemset ( m_pBuffersVBO, 0, sizeof ( m_pBuffersVBO ) );
	}

    glGenBuffers ( 2, &m_pBuffersVBO[0] );

    mapBuffers ( );
}
Ejemplo n.º 6
0
// TextureAtlas - Resize
bool TextureAtlas::resizeCapacity(ssize_t newCapacity)
{
    CCASSERT(newCapacity>=0, "capacity >= 0");
    if( newCapacity == _capacity )
    {
        return true;
    }
    auto oldCapactiy = _capacity;
    // update capacity and totolQuads
    _totalQuads = MIN(_totalQuads, newCapacity);
    _capacity = newCapacity;

    V3F_C4B_T2F_Quad* tmpQuads = nullptr;
    GLushort* tmpIndices = nullptr;
    
    // when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return nullptr,
    // so here must judge whether _quads and _indices is nullptr.
    if (_quads == nullptr)
    {
        tmpQuads = (V3F_C4B_T2F_Quad*)malloc( _capacity * sizeof(_quads[0]) );
        if (tmpQuads != nullptr)
        {
            memset(tmpQuads, 0, _capacity * sizeof(_quads[0]) );
        }
    }
    else
    {
        tmpQuads = (V3F_C4B_T2F_Quad*)realloc( _quads, sizeof(_quads[0]) * _capacity );
        if (tmpQuads != nullptr && _capacity > oldCapactiy)
        {
            memset(tmpQuads+oldCapactiy, 0, (_capacity - oldCapactiy)*sizeof(_quads[0]) );
        }
        _quads = nullptr;
    }

    if (_indices == nullptr)
    {    
        tmpIndices = (GLushort*)malloc( _capacity * 6 * sizeof(_indices[0]) );
        if (tmpIndices != nullptr)
        {
            memset( tmpIndices, 0, _capacity * 6 * sizeof(_indices[0]) );
        }
    }
    else
    {
        tmpIndices = (GLushort*)realloc( _indices, sizeof(_indices[0]) * _capacity * 6 );
        if (tmpIndices != nullptr && _capacity > oldCapactiy)
        {
            memset( tmpIndices+oldCapactiy, 0, (_capacity-oldCapactiy) * 6 * sizeof(_indices[0]) );
        }
        _indices = nullptr;
    }

    if( ! ( tmpQuads && tmpIndices) ) {
        CCLOG("cocos2d: TextureAtlas: not enough memory");
        CC_SAFE_FREE(tmpQuads);
        CC_SAFE_FREE(tmpIndices);
        CC_SAFE_FREE(_quads);
        CC_SAFE_FREE(_indices);
        _capacity = _totalQuads = 0;
        return false;
    }

    _quads = tmpQuads;
    _indices = tmpIndices;


    setupIndices();
    mapBuffers();

    _dirty = true;

    return true;
}
Ejemplo n.º 7
0
void TextureAtlas::setupVBO()
{
    glGenBuffers(2, &_buffersVBO[0]);

    mapBuffers();
}
Ejemplo n.º 8
0
void Renderer::setupVBO()
{
    glGenBuffers(2, &_buffersVBO[0]);

    mapBuffers();
}
Ejemplo n.º 9
0
// TextureAtlas - Resize
bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity)
{
    if( newCapacity == m_uCapacity )
    {
        return true;
    }
    unsigned int uOldCapactiy = m_uCapacity; 
    // update capacity and totolQuads
    m_uTotalQuads = MIN(m_uTotalQuads, newCapacity);
    m_uCapacity = newCapacity;

    ccV3F_C4B_T2F_Quad* tmpQuads = NULL;
    GLushort* tmpIndices = NULL;
    
    // when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return NULL,
    // so here must judge whether m_pQuads and m_pIndices is NULL.
    if (m_pQuads == NULL)
    {
        tmpQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(m_pQuads[0]) );
        if (tmpQuads != NULL)
        {
            memset(tmpQuads, 0, m_uCapacity * sizeof(m_pQuads[0]) );
        }
    }
    else
    {
        tmpQuads = (ccV3F_C4B_T2F_Quad*)realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity );
        if (tmpQuads != NULL && m_uCapacity > uOldCapactiy)
        {
            memset(tmpQuads+uOldCapactiy, 0, (m_uCapacity - uOldCapactiy)*sizeof(m_pQuads[0]) );
        }
    }

    if (m_pIndices == NULL)
    {    
        tmpIndices = (GLushort*)malloc( m_uCapacity * 6 * sizeof(m_pIndices[0]) );
        if (tmpIndices != NULL)
        {
            memset( tmpIndices, 0, m_uCapacity * 6 * sizeof(m_pIndices[0]) );
        }
        
    }
    else
    {
        tmpIndices = (GLushort*)realloc( m_pIndices, sizeof(m_pIndices[0]) * m_uCapacity * 6 );
        if (tmpIndices != NULL && m_uCapacity > uOldCapactiy)
        {
            memset( tmpIndices+uOldCapactiy, 0, (m_uCapacity-uOldCapactiy) * 6 * sizeof(m_pIndices[0]) );
        }
    }

    if( ! ( tmpQuads && tmpIndices) ) {
        CCLOG("cocos2d: CCTextureAtlas: not enough memory");
        CC_SAFE_FREE(tmpQuads);
        CC_SAFE_FREE(tmpIndices);
        CC_SAFE_FREE(m_pQuads);
        CC_SAFE_FREE(m_pIndices);
        m_uCapacity = m_uTotalQuads = 0;
        return false;
    }

    m_pQuads = tmpQuads;
    m_pIndices = tmpIndices;


    setupIndices();
    mapBuffers();

    m_bDirty = true;

    return true;
}
// TextureAtlas - Resize
KDbool CCTextureAtlas::resizeCapacity ( KDuint uNewCapacity )
{
	if ( uNewCapacity == m_uCapacity )
	{
		return KD_TRUE;
	}

	KDuint  uOldCapacity = m_uCapacity;

	// update capacity and totolQuads
	m_uTotalQuads = KD_MIN ( m_uTotalQuads, uNewCapacity );
	m_uCapacity = uNewCapacity;

	ccV3F_C4B_T2F_Quad*  pTempQuads   = KD_NULL;
	GLushort*            pTempIndices = KD_NULL;
	
	// when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return NULL,
	// so here must judge whether m_pQuads and m_pIndices is NULL.
	if ( m_pQuads == KD_NULL )
	{
		pTempQuads = (ccV3F_C4B_T2F_Quad*) kdCalloc ( 1, m_uCapacity * sizeof ( m_pQuads[0] ) );
	}
	else
	{
		pTempQuads = (ccV3F_C4B_T2F_Quad*) kdRealloc ( m_pQuads, sizeof ( m_pQuads[0] ) * m_uCapacity );
        if ( pTempQuads != KD_NULL && m_uCapacity > uOldCapacity )
        {
            kdMemset ( pTempQuads + uOldCapacity, 0, ( m_uCapacity - uOldCapacity ) * sizeof ( m_pQuads[0] ) );
        }
	}

	if ( m_pIndices == KD_NULL )
	{
		pTempIndices = (GLushort*) kdCalloc ( 1, m_uCapacity * 6 * sizeof ( m_pIndices[0] ) );
	}
	else
	{
		pTempIndices = (GLushort*) kdRealloc ( m_pIndices, sizeof ( m_pIndices[0] ) * m_uCapacity * 6 );
        if ( pTempIndices != KD_NULL && m_uCapacity > uOldCapacity )
        {
            kdMemset ( pTempIndices + uOldCapacity, 0, ( m_uCapacity - uOldCapacity ) * 6 * sizeof ( m_pIndices[0] ) );
        }
	}

	if ( !( pTempQuads && pTempIndices ) )
	{
		CCLOG ( "XMCocos2D : CCTextureAtlas - not enough memory");
		CC_SAFE_FREE ( pTempQuads );
		CC_SAFE_FREE ( pTempIndices );
		CC_SAFE_FREE ( m_pQuads );
		CC_SAFE_FREE ( m_pIndices );
		m_uCapacity = m_uTotalQuads = 0;
		return KD_FALSE;
	}

	m_pQuads   = pTempQuads;
	m_pIndices = pTempIndices;

	setupIndices ( );
    mapBuffers   ( );

	m_bDirty = KD_TRUE;

	return KD_TRUE;
}
Ejemplo n.º 11
0
bool V4Linux2Camera::initCamera() {

    struct dirent **v4l2_devices;
    int dev_count = scandir ("/dev/", &v4l2_devices, v4lfilter, alphasort);
    if ((dev_count == 0) || (cfg->device<0) || (cfg->device>=dev_count)) return false;

    char v4l2_device[128];
    sprintf(v4l2_device,"/dev/video%d",cfg->device);

    dev_handle = open(v4l2_device, O_RDWR);
    if (dev_handle < 0) return false;

    memset(&v4l2_caps, 0, sizeof(v4l2_capability));
    if (ioctl(dev_handle, VIDIOC_QUERYCAP, &v4l2_caps) < 0) {
        close(dev_handle);
        return false;
    }

    if ((v4l2_caps.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
        close(dev_handle);
        return false;
    }

    if ((v4l2_caps.capabilities & V4L2_CAP_STREAMING) == 0) {
        close(dev_handle);
        return false;
    }

    sprintf(cfg->name, "%s (%s)", v4l2_caps.card, v4l2_caps.driver);

    std::vector<CameraConfig> cfg_list = V4Linux2Camera::getCameraConfigs(cfg->device);
    if (cfg->cam_format==FORMAT_UNKNOWN) cfg->cam_format = cfg_list[0].cam_format;
    setMinMaxConfig(cfg,cfg_list);

    pixelformat=0;
    for (int i=0;;i++) {
        struct v4l2_fmtdesc fmtdesc;
        memset(&fmtdesc, 0, sizeof(v4l2_fmtdesc));
        fmtdesc.index = i;
        fmtdesc.type  = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        if (-1 == ioctl(dev_handle,VIDIOC_ENUM_FMT,&fmtdesc)) break;

        for (int i=FORMAT_MAX;i>0;i--) {
            if (fmtdesc.pixelformat == codec_table[i]) {
                if (cfg->cam_format==i) {
					pixelformat = fmtdesc.pixelformat;
					break;
				}
            }
        }

        if(pixelformat) break;
    }

    if (!pixelformat) {
        printf("%s does not support any valid pixel format\n",v4l2_device);
        close(dev_handle);
        return false;
    }

    cfg->cam_format = FORMAT_UNKNOWN;
    for (int i=FORMAT_MAX;i>0;i--) {
        if (pixelformat == codec_table[i]) {
            cfg->cam_format = i;
            break;
        }
    }

    // try to set the desired format
    memset(&v4l2_form, 0, sizeof(v4l2_format));
    v4l2_form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    v4l2_form.fmt.pix.pixelformat = pixelformat;
    v4l2_form.fmt.pix.width  = cfg->cam_width;
    v4l2_form.fmt.pix.height = cfg->cam_height;

    if (-1 == ioctl (dev_handle, VIDIOC_S_FMT, &v4l2_form)) {
        printf("error setting pixel format: %s\n" , strerror(errno));
        return false;
    }

    // try to set the desired fps
    v4l2_parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    v4l2_parm.parm.capture.timeperframe.numerator = 1;
    v4l2_parm.parm.capture.timeperframe.denominator = int(cfg->cam_fps);

    if(-1 == ioctl (dev_handle, VIDIOC_S_PARM, &v4l2_parm)) {
        printf("error setting fps: %s\n", strerror(errno));
        //return false;
    }

    // use the settings we got from the driver
    pixelformat = v4l2_form.fmt.pix.pixelformat;
    cfg->cam_width = v4l2_form.fmt.pix.width;
    cfg->cam_height = v4l2_form.fmt.pix.height;
    cfg->cam_fps = roundf((v4l2_parm.parm.capture.timeperframe.denominator/(float)v4l2_parm.parm.capture.timeperframe.numerator)*10)/10.0f;

    if ((pixelformat == V4L2_PIX_FMT_MJPEG) || (pixelformat == V4L2_PIX_FMT_JPEG)) _jpegDecompressor = tjInitDecompress();

    if (!requestBuffers()) {
        printf("Error requesting buffers.\n");
        return false;
    }

    if (!mapBuffers()) {
        printf("Unable to mmap buffers.\n");
        return false;
    }

    setupFrame();
    if (cfg->frame) frm_buffer = new unsigned char[cfg->frame_width*cfg->frame_height*cfg->buf_format];
    cam_buffer = new unsigned char[cfg->cam_width*cfg->cam_height*cfg->buf_format];
    buffers_initialized = true;
    return true;
}