Ejemplo n.º 1
0
void TRWS::initializeAlg()
{
    assert(m_type != NONE);

    int i;

    // determine type
    if (m_type == L1 && m_nLabels == 2)
	{
	    m_type = BINARY;
	}

    // allocate messages
    int messageNum = (m_type == BINARY) ? 4*m_nPixels : 4*m_nPixels*m_nLabels;
    m_messageArraySizeInBytes = messageNum*sizeof(REAL);
    m_messages = new REAL[messageNum];
    memset(m_messages, 0, messageNum*sizeof(REAL));

    if (m_type == BINARY)
	{
	    assert(m_DBinary == NULL && m_horzWeightsBinary == NULL && m_horzWeightsBinary == NULL);
	    m_DBinary = new CostVal[m_nPixels];
	    m_horzWeightsBinary = new CostVal[m_nPixels];
	    m_vertWeightsBinary = new CostVal[m_nPixels];

	    if ( m_dataType == ARRAY)
		{
		    for (i=0; i<m_nPixels; i++)
			{
			    m_DBinary[i] = m_D[2*i+1] - m_D[2*i];
			}
		}
	    else
		{
		    for (i=0; i<m_nPixels; i++)
			{
			    m_DBinary[i] = m_dataFn(i,1) - m_dataFn(i,0);
			}
		}

	    assert(m_V[0] == 0 && m_V[1] == m_V[2] && m_V[3] == 0);
	    for (i=0; i<m_nPixels; i++)
		{
		    m_horzWeightsBinary[i] = (m_varWeights) ? m_V[1]*m_horzWeights[i] : m_V[1];
		    m_vertWeightsBinary[i] = (m_varWeights) ? m_V[1]*m_vertWeights[i] : m_V[1];
		}
	}
}
Ejemplo n.º 2
0
void MaxProdBP::setData(DataCostFn dcost)
{
  m_dataFn = dcost;
  int i;
  int j;
  m_ExpData = new FloatType[m_nPixels * m_nLabels];
  // MEMORY LEAK? where does this ever get deleted??
  if(!m_ExpData)
  {
    exit(0);
  }
  
  
  m_exp_scale = 1;//FLOATTYPE(cmax)*4.0;
  FloatType *cData = m_ExpData;
  for ( i= 0; i < m_nPixels; i++)
  {
    nodeArray[i].localEv = cData;
    for( j = 0; j < m_nLabels; j++)
    {
      *cData = (float)m_dataFn(i,j);
      cData++;
    }
  }
}
Ejemplo n.º 3
0
/*===========================================================================
 * FUNCTION   : flushNodes
 *
 * DESCRIPTION: flush only specific nodes, depending on
 *              the given matching function.
 *
 * PARAMETERS :
 *   @match   : matching function
 *
 * RETURN     : None
 *==========================================================================*/
void QCameraQueue::flushNodes(match_fn_data match, void *match_data){
    camera_q_node* node = NULL;
    struct cam_list *head = NULL;
    struct cam_list *pos = NULL;

    if ( NULL == match ) {
        return;
    }

    pthread_mutex_lock(&m_lock);
    if (m_active) {
        head = &m_head.list;
        pos = head->next;

        while(pos != head) {
            node = member_of(pos, camera_q_node, list);
            pos = pos->next;
            if ( match(node->data, m_userData, match_data) ) {
                cam_list_del_node(&node->list);
                m_size--;

                if (NULL != node->data) {
                    if (m_dataFn) {
                        m_dataFn(node->data, m_userData);
                    }
                    free(node->data);
                }
                free(node);
            }
        }
    }
    pthread_mutex_unlock(&m_lock);
}
Ejemplo n.º 4
0
/*===========================================================================
 * FUNCTION   : flush
 *
 * DESCRIPTION: flush all nodes from the queue, queue will be empty after this
 *              operation.
 *
 * PARAMETERS : None
 *
 * RETURN     : None
 *==========================================================================*/
void QCameraQueue::flush(){
    camera_q_node* node = NULL;
    struct cam_list *head = NULL;
    struct cam_list *pos = NULL;

    pthread_mutex_lock(&m_lock);
    if (m_active) {
        head = &m_head.list;
        pos = head->next;

        while(pos != head) {
            node = member_of(pos, camera_q_node, list);
            pos = pos->next;
            cam_list_del_node(&node->list);
            m_size--;

            if (NULL != node->data) {
                if (m_dataFn) {
                    m_dataFn(node->data, m_userData);
                }
                free(node->data);
            }
            free(node);

        }
        m_size = 0;
        m_active = false;
    }
    pthread_mutex_unlock(&m_lock);
}
Ejemplo n.º 5
0
void TRWS::setData(DataCostFn dcost)
{
    int i, k;

    m_dataFn = dcost;
    CostVal* ptr;
    m_D = new CostVal[m_nPixels*m_nLabels];

    for (ptr=m_D, i=0; i<m_nPixels; i++)
	for (k=0; k<m_nLabels; k++, ptr++)
	    {
		*ptr = m_dataFn(i,k);
	    }
    m_needToFreeD = true;
}
Ejemplo n.º 6
0
MRF::EnergyVal MaxProdBP::dataEnergy()
{
    EnergyVal eng = (EnergyVal) 0;

    
    if ( m_dataType == ARRAY) 
    {
        for ( int i = 0; i < m_nPixels; i++ )
            eng = eng + m_D(i,m_answer[i]);
    }
    else
    {
        for ( int i = 0; i < m_nPixels; i++ )
            eng = eng + m_dataFn(i,m_answer[i]);
    }
    return(eng);

}