Пример #1
0
bool repo::core::RepoBoundingBox::operator==(const RepoBoundingBox& other) const
{
    return this->getMin() == other.getMin() &&
            this->getMax() == other.getMax();
}
Пример #2
0
//------------------------------------------------------------------------------
std::string repo::core::RepoNodeMesh::hash(
    const std::vector<aiVector3t<float> >& originalVertices,
    const RepoBoundingBox& boundingBox,
    double hashDensity)
{
//    std::cerr << std::endl;
//    std::cerr << "Mesh" << std::endl;
    std::vector<hash_type> vertexHashes;


    std::set<aiVector3t<float> > verticesSet(originalVertices.begin(), originalVertices.end());
    std::vector<aiVector3t<float> > vertices(verticesSet.begin(), verticesSet.end());


//    std::sort(vertices.begin(), vertices.end(), RepoaiVertexComparator());
//    auto uniqueEnd = std::unique(vertices.begin(), vertices.end(), RepoaiVertexComparator());
//    vertices.erase(uniqueEnd, vertices.end());

    vertexHashes.resize(vertices.size());

    const aiVector3t<float> &min = boundingBox.getMin();
    const aiVector3t<float> &max = boundingBox.getMax();

    float stride_x = (max.x - min.x);
    float stride_y = (max.y - min.y);
    float stride_z = (max.z - min.z);

    for(int v_idx = 0; v_idx < vertices.size(); v_idx++)
    {
        double norm_x = (vertices.at(v_idx).x - min.x) / stride_x;
        double norm_y = (vertices.at(v_idx).y - min.y) / stride_y;
        double norm_z = (vertices.at(v_idx).z - min.z) / stride_z;

        hash_type x_coord = (hash_type)round(hashDensity * norm_x);
        hash_type y_coord = (hash_type)round(hashDensity * norm_y);
        hash_type z_coord = (hash_type)round(hashDensity * norm_z);

        hash_type vertexIndex = x_coord
                                + (hash_type)round(hashDensity * y_coord)
                                + (hash_type)round(hashDensity * hashDensity * z_coord);

        vertexHashes[v_idx] = vertexIndex;

//        if (vertices.size() < 100)
//            std::cerr << "[ " << norm_x << ", " << norm_y << ", " << norm_z << " ]";
    }

//    std::cerr << std::endl;

    std::sort(vertexHashes.begin(), vertexHashes.end());
//    std::unique(vertexHashes.begin(), vertexHashes.end());

//    for(auto v : vertexHashes)
//    {
//        std::cerr << v << " ";
//    }
//    std::cerr << std::endl;

    size_t bufSize = vertexHashes.size() * sizeof(hash_type) + sizeof(float) * 3;
    char *buf = new char[bufSize];

    memcpy(buf, (char *)(&vertexHashes[0]), vertexHashes.size() * sizeof(hash_type));
    unsigned int idx = vertexHashes.size() * sizeof(hash_type);

    /*
    stride_x = (float)(floor((double)stride_x * 10000.0) / 10000.0);
    stride_y = (float)(floor((double)stride_y * 10000.0) / 10000.0);
    stride_z = (float)(floor((double)stride_z * 10000.0) / 10000.0);
    */

    stride_x = fround(stride_x, 3);
    stride_y = fround(stride_y, 3);
    stride_z = fround(stride_z, 3);

    *((float *)(buf + idx)) = stride_x;
    *((float *)(buf + idx + sizeof(float))) = stride_y;
    *((float *)(buf + idx + 2 * sizeof(float))) = stride_z;

//    std::cerr << stride_x << " " << stride_y << " " << stride_z << " " << sha256(std::string(buf, bufSize)) << std::endl;

    return sha256(std::string(buf, bufSize));
}