예제 #1
0
파일: glutwidget.cpp 프로젝트: Kurispy/city
/*
 Initializes opengl states
 */
void glutWidget::initOpenGL()
{
    glewExperimental = GL_TRUE; 
    GLenum err = glewInit();                             //initialize GLEW - this enables us to use extensions
    if(err != GLEW_OK)
    {
        std::cout << "ERROR: Loading GLEW failed." << std::endl;
        exit(-1);
    }
    checkExtensions();
    glClearColor(1, 1, 1, 0);   //default "empty"/background color is set to white
    
    glEnable(GL_DEPTH_TEST);
    
    CBitmap skybox("skybox.bmp");               //read bitmap image
    glGenTextures(1, &m_texture);               //allocate 1 texture
    glUniform1i(skybox_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, skybox_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, skybox.GetWidth(), skybox.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, skybox.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);        //specify texture coordinate treatment
    
    glBindTexture(GL_TEXTURE_2D, 0);
    
    CBitmap streets("streets.bmp");               //read bitmap image
    glGenTextures(1, &street_texture);          //allocate 1 texture
    glUniform1i(street_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, street_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, streets.GetWidth(), streets.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, streets.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);        //specify texture coordinate treatment


    glBindTexture(GL_TEXTURE_2D, 0);    //bind default texture to be active
    
    CBitmap car("car.bmp");               //read bitmap image
    glGenTextures(1, &car_texture);          //allocate 1 texture
    glUniform1i(car_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, car_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, car.GetWidth(), car.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, car.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);        //specify texture coordinate treatment
    
    glBindTexture(GL_TEXTURE_2D, 0);    //bind default texture to be active
    
    CBitmap structure("structure.bmp");               //read bitmap image
    glGenTextures(1, &structure_texture);          //allocate 1 texture
    glUniform1i(structure_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, structure_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, structure.GetWidth(), structure.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, structure.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);        //specify texture coordinate treatment


    glBindTexture(GL_TEXTURE_2D, 0);    //bind default texture to be active
    
    CBitmap wall("wall.bmp");               //read bitmap image
    glGenTextures(1, &wall_texture);          //allocate 1 texture
    glUniform1i(wall_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, wall_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wall.GetWidth(), wall.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, wall.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);        //specify texture coordinate treatment


    glBindTexture(GL_TEXTURE_2D, 0);    //bind default texture to be active
    
    makeShaders();          //load data of fragment and vertex programs/shaders - compile shaders
    
    glMatrixMode(GL_PROJECTION);       
    glLoadIdentity();                                             //initializes projection matrix with identity
    gluPerspective(60,(float)m_width/(float)m_height,0.1,1000);  //set up projection mode (field of view, aspect ratio, near and far clipping plane)
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();                       //initializes modelview matrix with identity
    
    glEnable(GL_CULL_FACE);

}
예제 #2
0
// static
void StreetsMatcher::FindStreets(BaseContext const & ctx, FeaturesFilter const & filter,
                                 QueryParams const & params, vector<Prediction> & predictions)
{
  for (size_t startToken = 0; startToken < ctx.m_numTokens; ++startToken)
  {
    if (ctx.m_usedTokens[startToken])
      continue;

    // Here we try to match as many tokens as possible while
    // intersection is a non-empty bit vector of streets. Single
    // tokens that are synonyms to streets are ignored.  Moreover,
    // each time a token that looks like a beginning of a house number
    // is met, we try to use current intersection of tokens as a
    // street layer and try to match BUILDINGs or POIs.
    CBV streets(ctx.m_streets);

    CBV all;
    all.SetFull();

    size_t curToken = startToken;

    // This variable is used for prevention of duplicate calls to
    // CreateStreetsLayerAndMatchLowerLayers() with the same
    // arguments.
    size_t lastToken = startToken;

    // When true, no bit vectors were intersected with |streets| at all.
    bool emptyIntersection = true;

    // When true, |streets| is in the incomplete state and can't be
    // used for creation of street layers.
    bool incomplete = false;

    auto emit = [&]()
    {
      if (!streets.IsEmpty() && !emptyIntersection && !incomplete && lastToken != curToken)
      {
        CBV fs(streets);
        CBV fa(all);

        ASSERT(!fs.IsFull(), ());
        ASSERT(!fa.IsFull(), ());

        if (filter.NeedToFilter(fs))
          fs = filter.Filter(fs);

        if (fs.IsEmpty())
          return;

        if (filter.NeedToFilter(fa))
          fa = filter.Filter(fa).Union(fs);

        predictions.emplace_back();
        auto & prediction = predictions.back();

        prediction.m_startToken = startToken;
        prediction.m_endToken = curToken;

        ASSERT_NOT_EQUAL(fs.PopCount(), 0, ());
        ASSERT_LESS_OR_EQUAL(fs.PopCount(), fa.PopCount(), ());
        prediction.m_prob = static_cast<double>(fs.PopCount()) / static_cast<double>(fa.PopCount());

        prediction.m_features = move(fs);
        prediction.m_hash = prediction.m_features.Hash();
      }
    };

    StreetTokensFilter filter([&](strings::UniString const & /* token */, size_t tag)
                              {
                                auto buffer = streets.Intersect(ctx.m_features[tag]);
                                if (tag < curToken)
                                {
                                  // This is the case for delayed
                                  // street synonym.  Therefore,
                                  // |streets| is temporarily in the
                                  // incomplete state.
                                  streets = buffer;
                                  all = all.Intersect(ctx.m_features[tag]);
                                  emptyIntersection = false;

                                  incomplete = true;
                                  return;
                                }
                                ASSERT_EQUAL(tag, curToken, ());

                                // |streets| will become empty after
                                // the intersection. Therefore we need
                                // to create streets layer right now.
                                if (buffer.IsEmpty())
                                  emit();

                                streets = buffer;
                                all = all.Intersect(ctx.m_features[tag]);
                                emptyIntersection = false;
                                incomplete = false;
                              });