Пример #1
0
        /** Function for adding a node to the graph.
         * \param node: Smart pointer to the node to add.
         */
        void     addNode( CNodePtr node )
        {
            m_nodes.push_back(node);

            bool nodeTypeAlreadyInserted = false;

            for ( size_t i = 0; i < m_nodeTypes.size(); i++ )
                if ( m_nodeTypes[i]->getID() == node->getType()->getID() )
                {
                    nodeTypeAlreadyInserted = true;
                    break;
                }

            if ( !nodeTypeAlreadyInserted )
                m_nodeTypes.push_back(node->getType());
        }
Пример #2
0
        /** Function for computing the potentials of the nodes and the edges in
         * the graph.
         */
        void computePotentials()
        {
            // Method steps:
            //  1. Compute node potentials
            //  2. Compute edge potentials

            //
            //  1. Node potentials
            //

            std::vector<CNodePtr>::iterator it;

            //cout << "NODE POTENTIALS" << endl;

            for ( it = m_nodes.begin(); it != m_nodes.end(); it++ )
            {
                CNodePtr nodePtr = *it;

                if ( !nodePtr->finalPotentials() )
                {
                    // Get the node type
                    //size_t type = nodePtr->getType()->getID();

                    // Compute the node potentials according to the node type and its
                    // extracted features

                    Eigen::VectorXd potentials = nodePtr->getType()->computePotentials( nodePtr->getFeatures() );

                    // Apply the node class multipliers
                    potentials = potentials.cwiseProduct( nodePtr->getClassMultipliers() );

                    /*Eigen::VectorXd fixed = nodePtr->getFixed();

                    potentials = potentials.cwiseProduct( fixed );*/

                    nodePtr->setPotentials( potentials );
                }

            }

            //
            //  2. Edge potentials
            //

            std::vector<CEdgePtr>::iterator it2;

            //cout << "EDGE POTENTIALS" << endl;

            for ( it2 = m_edges.begin(); it2 != m_edges.end(); it2++ )
            {
                CEdgePtr edgePtr = *it2;

                Eigen::MatrixXd potentials
                        = edgePtr->getType()->computePotentials( edgePtr->getFeatures() );

                edgePtr->setPotentials ( potentials );
            }

        }
Пример #3
0
        /** Set the type of a node. This method is consistent with the internal
          * vector for storing the different types of the nodes within this graph.
          * If the function setType of a node is used instead this method,
          * this vector could became inconsistent.
          * /param nodePtr node to change.
          * /param nodeTypePtr node type to set.
          */
        void setNodeType( CNodePtr nodePtr, CNodeTypePtr nodeTypePtr)
        {
            size_t previousNodeTypeID = nodePtr->getType()->getID();
            nodePtr->setType( nodeTypePtr );
            size_t nodeTypeID = nodeTypePtr->getID();

            // Check if other nodes have the same nodeType, and delete that type if not.

            bool nodeTypeStillInUse = false;

            for ( size_t i = 0; i < m_nodes.size(); i++ )
                if ( m_nodes[i]->getType()->getID() == previousNodeTypeID )
                {
                    nodeTypeStillInUse = true;
                    break;
                }

            if ( !nodeTypeStillInUse )
            {
                std::vector<CNodeTypePtr>::iterator it;

                for ( it = m_nodeTypes.begin(); it != m_nodeTypes.end(); it++ )
                {
                    CNodeTypePtr nodeTypePtrAux = *it;

                    if ( nodeTypePtrAux->getID() == previousNodeTypeID )
                    {
                        m_nodeTypes.erase( it );
                        break;
                    }
                }
            }

            // Check if the node type already exists

            bool nodeTypeAlreadyInserted = false;

            for ( size_t i = 0; i < m_nodeTypes.size(); i++ )
                if ( m_nodeTypes[i]->getID() == nodeTypeID )
                {
                    nodeTypeAlreadyInserted = true;
                    break;
                }

            if ( !nodeTypeAlreadyInserted )
                m_nodeTypes.push_back(nodeTypePtr);

        }