Exemplo n.º 1
0
void BVNDFProcessor::computeDirac(){
    int nbFacet = m_geom->getNbFacet();
    m_dirac = new int[nbFacet];
    m_bnormals = new bool[m_nbNormal];
    for(int i = 0; i < m_nbNormal; ++i)
        m_bnormals[i] = false;

    void * tree = kd_create(3);
    struct kdres *presults;

    // Creation of a KdTree of all the normals
    for (int i = 0; i < m_nbNormal; ++i){
        void * data = malloc(sizeof(i));
        memcpy(data, &i, sizeof(i));
        kd_insert3f((kdtree*)tree,
                            m_normals[i].x,
                            m_normals[i].y,
                            m_normals[i].z,
                            data);
        int temp;
        memcpy(&temp, data, sizeof(temp));
        //std::cout << temp << std::endl;
    }

    // For each facet we find its closest normal
    for (int i = 0; i < nbFacet; ++i){
        glm::vec3 normal = m_geom->getNormal(i);
        presults = kd_nearest3f((kdtree*) tree, normal.x, normal.y, normal.z);
        int * data;
        data = (int*)kd_res_item(presults, NULL);
        int normalId;
        memcpy(&normalId, data, sizeof(normalId));
        // Test
            int closest = getClosestNormal(normal);
        // Test
        m_dirac[i] = normalId;
        m_bnormals[normalId] = true;
    }

    m_corres = new int[m_nbNormal];
    int currId = 0;
    for (int i = 0; i < m_nbNormal; ++i){
        if (m_bnormals[i]){
            m_corres[i] = currId;
            currId++;
        }
        else{
            m_corres[i] = -1;
        }
    }
    m_nbNonZeroNormals = currId;
    m_diracInitialized = true;
}
Exemplo n.º 2
0
 void PhotonMap::AddPhoton(kdtree *map, const Vector &pos, Photon *photon)
 {
     _ASSERT(photon);
     _ASSERT(map);
     EnterCriticalSection(lpcs);
     kd_insert3f(map, pos.x, pos.y, pos.z, photon);
     photons.push_back(photon);
     if ( map == causticsMap ) causticsCount++;
     else if ( map == indirectMap ) indirectCount++;
     else if ( map == volumeMap ) volumeCount++;
     LeaveCriticalSection(lpcs);
 }