Exemplo n.º 1
0
void Vizzer::init(ApplicationData &app)
{
    m_meshes.resize(20);

    //const FloatType radius, const ml::vec3<FloatType>& pos, const size_t stacks /*= 10*/, const size_t slices /*= 10*/, const ml::vec4<FloatType>& color
    for (int i = 0; i < 20; i++)
    {
        const vec3f pos = vec3f(util::randomUniform(-1.0f, 1.0f), util::randomUniform(-1.0f, 1.0f), util::randomUniform(-1.0f, 1.0f));
        const vec4f color = vec4f(util::randomUniform(0.5f, 1.0f), util::randomUniform(0.5f, 1.0f), util::randomUniform(0.5f, 1.0f), 1.0f);
        m_meshes[i].load(app.graphics, TriMeshf(Shapesf::sphere(util::randomUniform(0.1f, 0.2f), pos, 10, 10, color)));
    }
	
    const string shaderDir = "../../frameworkD3D11/shaders/";
    m_vsColor.load(app.graphics, shaderDir + "test.shader");
    m_psColor.load(app.graphics, shaderDir + "test.shader");

    m_constants.init(app.graphics);

    vec3f eye(1.0f, 1.0f, 4.5f);
    vec3f worldUp(0.0f, 0.0f, 1.0f);
    m_camera = Cameraf(-eye, worldUp, vec3f::origin, 60.0f, (float)app.window.getWidth() / app.window.getHeight(), 0.01f, 1000.0f, true);

    m_font.init(app.graphics, "Calibri");

    m_world = mat4f::identity();

}
Exemplo n.º 2
0
Cameraf SynthRenderer::randomCamera(const Scene &s)
{
    const float randomLookVariance = 0.2f;
    const float targetBBoxExpansion = 1.5f;

    const OBB3f objectOBB = s.objects[s.mainObjectIndex].worldBBox;
    
    bbox3f targetBBox;
    targetBBox.include(bbox3f(objectOBB));

    const auto r = [&](float a, float b) { return (float)ml::util::randomUniform(a, b); };
    const auto rA = [&]() { return (float)r(0.0f, 1.0f); };
    const auto rB = [&]() { return (float)r(-1.0f, 1.0f); };

    const vec3f lookAt = objectOBB.getCenter() +
                         vec3f(rB(), rB(), rB()) * randomLookVariance;

    vec3f eye;

    eye.x = r(targetBBox.getMin().x - targetBBoxExpansion, targetBBox.getMax().x + targetBBoxExpansion);
    eye.y = r(targetBBox.getMin().y - targetBBoxExpansion, targetBBox.getMax().y + targetBBoxExpansion);
    eye.z = r(0.5f, 2.0f);

    return Cameraf(eye, lookAt - eye, vec3f::eZ, constants::fieldOfView, 1.0f, 0.01f, 100.0f);
}
Exemplo n.º 3
0
void Vizzer::init(ApplicationData &app)
{
    assets.init(app.graphics);

    vec3f eye(0.5f, 0.2f, 0.5f);
    vec3f worldUp(0.0f, 1.0f, 0.0f);
    camera = Cameraf(-eye, eye, worldUp, 60.0f, (float)app.window.getWidth() / app.window.getHeight(), 0.01f, 10000.0f);
    camera = Cameraf("-0.774448 1.24485 -1.35404 0.999848 1.80444e-009 -0.0174517 0.0152652 -0.484706 0.874544 -0.00845866 -0.874677 -0.484632 0 1 0 60 1.25 0.01 10000");
    //-0.774448 1.24485 -1.35404 0.999848 1.80444e-009 -0.0174517 0.0152652 -0.484706 0.874544 -0.00845866 -0.874677 -0.484632 0 1 0 60 1.25 0.01 10000
    font.init(app.graphics, "Calibri");

    state.bundler.loadSensorFile(constants::dataDir + "/sensors/sample.sensor");
    state.bundler.computeKeypoints();
    state.bundler.addCorrespondences(1);
    state.bundler.addCorrespondences(2);
    state.bundler.addCorrespondences(4);
    state.bundler.addCorrespondences(6);
    state.bundler.addCorrespondences(12);
    state.bundler.addCorrespondences(20);
    state.bundler.addCorrespondences(30);
    state.bundler.addCorrespondences(40);
    state.bundler.addCorrespondences(60);
    state.bundler.addCorrespondences(80);
    state.bundler.addCorrespondences(100);
    
    state.bundler.solve();
    
    state.bundler.thresholdCorrespondences(0.01);

    state.bundler.solve();

    //state.bundler.thresholdCorrespondences(0.005);

    //state.bundler.solve();

    state.bundler.saveKeypointCloud(constants::debugDir + "result.ply");
    state.bundler.saveResidualDistribution(constants::debugDir + "residuals.csv");

    state.frameCloudsSmall.resize(state.bundler.frames.size());
    state.frameCloudsBig.resize(state.bundler.frames.size());

    for (auto &frame : iterate(state.bundler.frames))
    {
        vector<TriMeshf> meshesSmall, meshesBig;

        auto makeColoredBox = [](const vec3f &center, const vec4f &color, float radius) {
            TriMeshf result = ml::Shapesf::box(radius, radius, radius);
            result.transform(mat4f::translation(center));
            result.setColor(color);
            return result;
        };

        const int stride = 5;
        for (auto &p : frame.value.depthImage)
        {
            vec2i coord((int)p.x, (int)p.y);
            const vec3f framePos = frame.value.localPos(coord);
            if (!framePos.isValid() || p.x % stride != 0 || p.y % stride != 0)
                continue;

            meshesSmall.push_back(makeColoredBox(frame.value.frameToWorld * framePos, vec4f(frame.value.colorImage(coord)) / 255.0f, 0.002f));
            meshesBig.push_back(makeColoredBox(frame.value.frameToWorld * framePos, vec4f(frame.value.colorImage(coord)) / 255.0f, 0.005f));
        }

        state.frameCloudsSmall[frame.index] = D3D11TriMesh(app.graphics, Shapesf::unifyMeshes(meshesSmall));
        state.frameCloudsBig[frame.index] = D3D11TriMesh(app.graphics, Shapesf::unifyMeshes(meshesBig));
    }

    state.selectedCamera = 0;
}