示例#1
0
void SaveService::_scheduleSave( const std::shared_ptr<RenderResponse>& response ){
    m_renderCount++;
    m_images[response->getLayerName()] = response;
    if ( m_renderCount != m_redrawCount ) {
        return;
    }

    m_view->resetLayers();

    //We want the selected index to be the last one in the stack.
    int dataCount = m_layers.size();
    int stackIndex = 0;
    for ( int i = 0; i < dataCount; i++ ){
        int dIndex = ( m_selectIndex + i + 1) % dataCount;
        m_layers[dIndex]->disconnect( this );
        if ( m_layers[dIndex]->_isVisible() ){
            QString layerId = m_layers[dIndex]->_getLayerId();
            if ( m_images.contains( layerId ) ){
                QImage image = m_images[layerId]->getImage();
                Carta::Lib::VectorGraphics::VGList graphicsList = m_images[layerId]->getVectorGraphics();
                m_view->setRasterLayer( stackIndex, image );
                m_view->setVectorGraphicsLayer( stackIndex, graphicsList );
                stackIndex++;
            }
        }
    }
    for ( int i = 0; i < dataCount; i++ ){
           m_layers[i]->_renderDone();
       }
    m_view->paintLayers();
    QImage image = m_view->getImage();
    _saveImage( image );
}
示例#2
0
void GraphComparator::drawCostDistance(shared_ptr<OsmMap> map, vector<Coordinate>& c,
                                       QString output)
{
  _updateBounds();
  // make a copy of the map so we can manipulate it.
  map.reset(new OsmMap(map));

  for (size_t i = 0; i < c.size(); i++)
  {
    cout << c[i].x << " " << c[i].y << endl;
    c[i] = _findNearestPointOnFeature(map, c[i]);
    cout << c[i].x << " " << c[i].y << endl;
    // find the nearest feature
    long wId = map->getIndex().findNearestWay(c[i]);
    shared_ptr<Way> w = map->getWay(wId);

    // split way at c
    WayLocation wl = LocationOfPoint::locate(map, w, c[i]);
    vector< shared_ptr<Way> > v = WaySplitter::split(map, w, wl);
    wl = LocationOfPoint::locate(map, v[0], c[i]);
    assert(wl.isNode() == true);
  }

  // populate graph
  shared_ptr<DirectedGraph> graph(new DirectedGraph());
  graph->deriveEdges(map);

  LOG_WARN("Running cost");
  ShortestPath sp(graph);

  for (size_t i = 0; i < c.size(); i++)
  {
    long wId = map->getIndex().findNearestWay(c[i]);
    shared_ptr<Way> w = map->getWay(wId);

    WayLocation wl = LocationOfPoint::locate(map, w, c[i]);

    // set cost at c to zero.
    long sourceId = w->getNodeId(wl.getSegmentIndex());
    sp.setNodeCost(sourceId, 0.0);
  }

  // calculate cost
  sp.calculateCost();
  LOG_WARN("Cost done");

  cv::Mat mat = _paintGraph(map, *graph, sp);

  _saveImage(mat, output, -1.0, false);
  _saveImage(mat, output.replace(".png", "2.png"), -1.0, true);

  shared_ptr<OGRSpatialReference> srs(new OGRSpatialReference());
  srs->importFromEPSG(900913);

  Coordinate c1 = MapProjector::project(Coordinate(_projectedBounds.MinX, _projectedBounds.MinY), map->getProjection(), srs);
  cout << "coord " << c1.x << ", " << c1.y << endl;

  Coordinate c2 = MapProjector::project(Coordinate(_projectedBounds.MaxX, _projectedBounds.MaxY), map->getProjection(), srs);
  cout << "coord2 " << c2.x << ", " << c2.y << endl;

  printf("POSITION_Y=%f\n", (c1.y + c2.y) / 2.0);
  //cout << "POSITION_Y=" << (c1.y + c2.y) / 2.0 << endl;
  printf("POSITION_X=%f\n", (c1.x + c2.x) / 2.0);
  //cout << "POSITION_X=" << (c1.x + c2.x) / 2.0 << endl;
  cout << "M12=0.0" << endl;
  cout << "M11=1.0" << endl;
  cout << "M10=0.0" << endl;
  cout << "M02=0.0" << endl;
  cout << "INITIAL_SCALE=" << (c2.x - c1.x) / (double)_width * 100.0 << endl;
  cout << "M01=0.0" << endl;
  cout << "M00=1.0" << endl;

  // paint graph onto raster
  //_exportGraphImage(map, *graph, sp, output);
}
示例#3
0
double GraphComparator::compareMaps()
{
  _updateBounds();
  double diffScoreSum = 0.0;

  vector<double> scores;
  int same = 0;
  // sampled standard deviation
  _s = -1;
  // 1.645 for 90% confidence, 1.96 for 95% confidence, and 2.58 for 99% confidence.
  // please update the header file comments if you change this value.
  double zalpha = 1.645;
  _ci = -1;

  // do this a bunch of times
  for (int i = 0; i < _iterations && same < 4; i++)
  {
    // generate a random source point
    _r.x = Random::generateUniform() * (_projectedBounds.MaxX - _projectedBounds.MinX) +
          _projectedBounds.MinX;
    _r.y = Random::generateUniform() * (_projectedBounds.MaxY - _projectedBounds.MinY) +
          _projectedBounds.MinY;

    shared_ptr<OsmMap> referenceMap;
    // pick one map as the reference map
    if (Random::coinToss())
    {
      referenceMap = _mapP1;
    }
    else
    {
      referenceMap = _mapP2;
    }

    _maxGraphCost = 0.0;

    // find the random source point's nearest point on a feature in one of the maps
    _r = _findNearestPointOnFeature(referenceMap, _r);

    // generate a cost distance raster for each map
    cv::Mat image1 = _calculateCostDistance(_mapP1, _r);
    cv::Mat image2 = _calculateCostDistance(_mapP2, _r);

    // take the difference of the two rasters and normalize
    double error = _calculateError(image1, image2);

    if (_debugImages)
    {
      cv::Mat diff(cvSize(_width, _height), CV_32FC1);

      const float* image1Data = image1.ptr<float>(0);
      const float* image2Data = image2.ptr<float>(0);
      float* diffData = diff.ptr<float>(0);
      size_t size = (image1.dataend - image1.datastart) / sizeof(float);
      for (size_t j = 0; j < size; j++)
      {
        diffData[j] = fabs(image1Data[j] - image2Data[j]);
      }

      QDir().mkpath("test-output/route-image");
      QString s1 = QString("test-output/route-image/route-%1-a.png").arg(i, 3, 10, QChar('0'));
      QString s2 = QString("test-output/route-image/route-%1-b.png").arg(i, 3, 10, QChar('0'));
      QString sdiff = QString("test-output/route-image/route-%1-diff.png").arg(i, 3, 10, QChar('0'));
      _saveImage(image1, s1, _maxGraphCost * 3);
      _saveImage(image2, s2, _maxGraphCost * 3);
      _saveImage(diff, sdiff, _maxGraphCost * 3);
    }

    image1.release();
    image2.release();

    // keep a running tally of the differences.
    diffScoreSum += error;

    scores.push_back(1 - error);
    sort(scores.begin(), scores.end());
    _median = scores[scores.size() / 2];
    _mean = 1 - (diffScoreSum / (i + 1));

    if (scores.size() > 1)
    {
      double v = 0;
      for (size_t i = 0; i < scores.size(); i++)
      {
        v += (scores[i] - _mean) * (scores[i] - _mean);
      }
      _s = sqrt(v / (scores.size() - 1));

      _ci = zalpha * _s / sqrt(scores.size());
    }


    if (Log::getInstance().isInfoEnabled())
    {
      cout << i << " / " << _iterations << " mean: " << _mean << "   \r";
      cout.flush();
    }
    //qDebug() << _median << 1 - error << _mean << "+/-" << _ci << "sd: " << _s;
  }

  if (Log::getInstance().isInfoEnabled())
  {
    cout << "                                   \r";
  }

  return _mean;
}
示例#4
0
void Channel::_testDepthAssemble()
{
    //----- setup constant data
    const eq::Images& images = _frame.getImages();
    eq::Image* image  = images[ 0 ];
    LBASSERT( image );

    eq::Config* config = getConfig();
    const eq::PixelViewport& pvp    = getPixelViewport();
    const eq::Vector2i offset( pvp.x, pvp.y );

    ConfigEvent event = _createConfigEvent();
    event.area.x() = pvp.w;

    lunchbox::Clock clock;
    eq::Window::ObjectManager* glObjects = getObjectManager();
    const GLEWContext* glewContext = glewGetContext();

    //----- test depth-based assembly algorithms
    for( unsigned i = 0; i < NUM_IMAGES; ++i )
    {
        image = images[ i ];
        LBASSERT( image );
        image->setPixelViewport( pvp );
    }

    event.area.y() = pvp.h;

    for( unsigned i = 0; i < NUM_IMAGES; ++i )
    {
        _draw( i );

        // fill depth & color image
        image = images[ i ];

        LBCHECK( image->allocDownloader( eq::Frame::BUFFER_COLOR, 
                                         EQ_COMPRESSOR_TRANSFER_RGBA_TO_BGRA, 
                                         glewContext ));

        LBCHECK( image->allocDownloader( eq::Frame::BUFFER_DEPTH, 
                             EQ_COMPRESSOR_TRANSFER_DEPTH_TO_DEPTH_UNSIGNED_INT,
                                         glewContext ));

        image->clearPixelData( eq::Frame::BUFFER_COLOR );
        image->clearPixelData( eq::Frame::BUFFER_DEPTH );

        image->startReadback( eq::Frame::BUFFER_COLOR | eq::Frame::BUFFER_DEPTH,
                              pvp, eq::Zoom::NONE, glObjects );
        image->finishReadback( eq::Zoom::NONE, glObjects->glewGetContext( ));

        if( i == NUM_IMAGES-1 )
            _saveImage( image,"EQ_COMPRESSOR_DATATYPE_DEPTH_UNSIGNED_INT",
                              "depthAssemble" );

        // benchmark
        eq::Compositor::ImageOp op;
        op.channel = this;
        op.buffers = eq::Frame::BUFFER_COLOR | eq::Frame::BUFFER_DEPTH;
        op.offset  = offset;

        // fixed-function
        event.data.type = ConfigEvent::ASSEMBLE;
        snprintf( event.formatType, 32, "depth, GL1.1, %d images", i+1 ); 

        clock.reset();
        for( unsigned j = 0; j <= i; ++j )
            eq::Compositor::assembleImageDB_FF( images[j], op );

        event.msec = clock.getTimef();
        config->sendEvent( event );

        // GLSL
        if( GLEW_VERSION_2_0 )
        {
            snprintf( event.formatType, 32, "depth, GLSL,  %d images", i+1 ); 

            clock.reset();
            for( unsigned j = 0; j <= i; ++j )
                eq::Compositor::assembleImageDB_GLSL( images[j], op );
            event.msec = clock.getTimef();
            config->sendEvent( event );
        }

        // CPU
        snprintf( event.formatType, 32, "depth, CPU,   %d images", i+1 ); 

        std::vector< eq::Frame* > frames;
        frames.push_back( &_frame );

        clock.reset();
        eq::Compositor::assembleFramesCPU( frames, this );
        event.msec = clock.getTimef();
        config->sendEvent( event );
    }
}
示例#5
0
void Channel::_testTiledOperations()
{
    //----- setup constant data
    const eq::Images& images = _frame.getImages();
    LBASSERT( images[0] );

    eq::Config* config = getConfig();
    const eq::PixelViewport& pvp    = getPixelViewport();
    const eq::Vector2i     offset( pvp.x, pvp.y );

    ConfigEvent event = _createConfigEvent();
    event.area.x() = pvp.w;

    lunchbox::Clock clock;
    eq::Window::ObjectManager* glObjects = getObjectManager();
    const GLEWContext* glewContext = glewGetContext();

    //----- test tiled assembly algorithms
    eq::PixelViewport subPVP = pvp;
    subPVP.h /= NUM_IMAGES;

    for( unsigned i = 0; i < NUM_IMAGES; ++i )
    {
        LBASSERT( images[ i ] );
        images[ i ]->setPixelViewport( subPVP );
    }

    for( unsigned tiles = 0; tiles < NUM_IMAGES; ++tiles )
    {
        _draw( 0 );

        event.area.y() = subPVP.h * (tiles+1);

        //---- readback of 'tiles' depth images
        event.data.type = ConfigEvent::READBACK;
        snprintf( event.formatType, 32, "%d depth tiles", tiles+1 ); 

        event.msec = 0;
        for( unsigned j = 0; j <= tiles; ++j )
        {
            subPVP.y = pvp.y + j * subPVP.h;
            eq::Image* image = images[ j ];
            LBCHECK( image->allocDownloader( eq::Frame::BUFFER_DEPTH, 
                             EQ_COMPRESSOR_TRANSFER_DEPTH_TO_DEPTH_UNSIGNED_INT,
                                             glewContext ));
            image->clearPixelData( eq::Frame::BUFFER_DEPTH );

            clock.reset();
            image->startReadback( eq::Frame::BUFFER_DEPTH, subPVP,
                                  eq::Zoom::NONE, glObjects );
            image->finishReadback( eq::Zoom::NONE, glObjects->glewGetContext( ));
            event.msec += clock.getTimef();
            
        }

        config->sendEvent( event );

        if( tiles == NUM_IMAGES-1 )
            for( unsigned j = 0; j <= tiles; ++j )
                _saveImage( images[j],
                            "EQ_COMPRESSOR_DATATYPE_DEPTH_UNSIGNED_INT",
                            "tiles" );

        //---- readback of 'tiles' color images
        event.data.type = ConfigEvent::READBACK;
        snprintf( event.formatType, 32, "%d color tiles", tiles+1 );

        event.msec = 0;
        for( unsigned j = 0; j <= tiles; ++j )
        {
            subPVP.y = pvp.y + j * subPVP.h;
            eq::Image* image = images[ j ];

            LBCHECK( image->allocDownloader( eq::Frame::BUFFER_COLOR, 
                                            EQ_COMPRESSOR_TRANSFER_RGBA_TO_BGRA,
                                              glewContext ));
            image->clearPixelData( eq::Frame::BUFFER_COLOR );

            clock.reset();
            image->startReadback( eq::Frame::BUFFER_COLOR, subPVP,
                                  eq::Zoom::NONE, glObjects );
            image->finishReadback( eq::Zoom::NONE, glObjects->glewGetContext( ));
            event.msec += clock.getTimef();
        }
        config->sendEvent( event );

        if( tiles == NUM_IMAGES-1 )
            for( unsigned j = 0; j <= tiles; ++j )
                _saveImage( images[j],"EQ_COMPRESSOR_DATATYPE_BGRA","tiles" );

        //---- benchmark assembly operations
        subPVP.y = pvp.y + tiles * subPVP.h;

        eq::Compositor::ImageOp op;
        op.channel = this;
        op.buffers = eq::Frame::BUFFER_COLOR | eq::Frame::BUFFER_DEPTH;
        op.offset  = offset;

        // fixed-function
        event.data.type = ConfigEvent::ASSEMBLE;
        snprintf( event.formatType, 32, "tiles, GL1.1, %d images", tiles+1 ); 

        clock.reset();
        for( unsigned j = 0; j <= tiles; ++j )
            eq::Compositor::assembleImage( images[j], op );

        event.msec = clock.getTimef();
        config->sendEvent( event );

        // CPU
        snprintf( event.formatType, 32, "tiles, CPU,   %d images", tiles+1 ); 

        std::vector< eq::Frame* > frames;
        frames.push_back( &_frame );

        clock.reset();
        eq::Compositor::assembleFramesCPU( frames, this );
        event.msec = clock.getTimef();
        config->sendEvent( event );
    }
}
示例#6
0
void Channel::_testDepthAssemble()
{
    glGetError(); // reset

    //----- setup constant data
    const eq::Images& images = _frame.getImages();
    eq::Image* image  = images[ 0 ];
    LBASSERT( image );

    const eq::PixelViewport& pvp    = getPixelViewport();
    const eq::Vector2i offset( pvp.x, pvp.y );

    eq::Vector2i area;
    area.x() = pvp.w;

    lunchbox::Clock clock;
    eq::util::ObjectManager& glObjects = getObjectManager();
    const GLEWContext* glewContext = glewGetContext();

    //----- test depth-based assembly algorithms
    for( unsigned i = 0; i < NUM_IMAGES; ++i )
    {
        image = images[ i ];
        LBASSERT( image );
        image->setPixelViewport( pvp );
    }

    area.y() = pvp.h;

    for( uint64_t i = 0; i < NUM_IMAGES; ++i )
    {
        _draw( co::uint128_t( i ) );

        // fill depth & color image
        image = images[ i ];

        LBCHECK( image->allocDownloader( eq::Frame::BUFFER_COLOR,
                                         EQ_COMPRESSOR_TRANSFER_RGBA_TO_BGRA,
                                         glewContext ));

        LBCHECK( image->allocDownloader( eq::Frame::BUFFER_DEPTH,
                             EQ_COMPRESSOR_TRANSFER_DEPTH_TO_DEPTH_UNSIGNED_INT,
                                         glewContext ));

        image->clearPixelData( eq::Frame::BUFFER_COLOR );
        image->clearPixelData( eq::Frame::BUFFER_DEPTH );

        image->startReadback( eq::Frame::BUFFER_COLOR | eq::Frame::BUFFER_DEPTH,
                              pvp, eq::Zoom::NONE, glObjects );
        image->finishReadback( glObjects.glewGetContext( ));
        LBASSERT( image->hasPixelData( eq::Frame::BUFFER_COLOR ));
        LBASSERT( image->hasPixelData( eq::Frame::BUFFER_DEPTH ));

        if( i == NUM_IMAGES-1 )
            _saveImage( image,"EQ_COMPRESSOR_DATATYPE_DEPTH_UNSIGNED_INT",
                              "depthAssemble" );

        // benchmark
        eq::Compositor::ImageOp op;
        op.channel = this;
        op.buffers = eq::Frame::BUFFER_COLOR | eq::Frame::BUFFER_DEPTH;
        op.offset  = offset;

        // fixed-function
        std::stringstream formatType;
        formatType << "depth, GL1.1, " << i+1 << " images";

        clock.reset();
        for( unsigned j = 0; j <= i; ++j )
            eq::Compositor::assembleImageDB_FF( images[j], op );

        float msec = clock.getTimef();
        _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );

        // GLSL
        if( GLEW_VERSION_2_0 )
        {
            formatType.str("");
            formatType << "depth, GLSL,  " << i+1 << " images";

            clock.reset();
            for( unsigned j = 0; j <= i; ++j )
                eq::Compositor::assembleImageDB_GLSL( images[j], op );
            msec = clock.getTimef();
            _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
        }

        // CPU
        formatType.str("");
        formatType << "depth, CPU,   " << i+1 << " images";

        std::vector< eq::Frame* > frames;
        frames.push_back( &_frame );

        clock.reset();
        eq::Compositor::assembleFramesCPU( frames, this );
        msec = clock.getTimef();
        _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
    }
}
示例#7
0
void Channel::_testTiledOperations()
{
    glGetError(); // reset

    //----- setup constant data
    const eq::Images& images = _frame.getImages();
    LBASSERT( images[0] );

    const eq::PixelViewport& pvp    = getPixelViewport();
    const eq::Vector2i     offset( pvp.x, pvp.y );

    eq::Vector2i area;
    area.x() = pvp.w;

    lunchbox::Clock clock;
    eq::util::ObjectManager& glObjects = getObjectManager();
    const GLEWContext* glewContext = glewGetContext();

    //----- test tiled assembly algorithms
    eq::PixelViewport subPVP = pvp;
    subPVP.h /= NUM_IMAGES;

    for( unsigned i = 0; i < NUM_IMAGES; ++i )
    {
        LBASSERT( images[ i ] );
        images[ i ]->setPixelViewport( subPVP );
    }

    for( unsigned tiles = 0; tiles < NUM_IMAGES; ++tiles )
    {
        EQ_GL_CALL( _draw( co::uint128_t( )));
        area.y() = subPVP.h * (tiles+1);

        //---- readback of 'tiles' depth images
        std::stringstream formatType;
        formatType << tiles+1 << " depth tiles";

        float msec = 0;
        for( unsigned j = 0; j <= tiles; ++j )
        {
            subPVP.y = pvp.y + j * subPVP.h;
            eq::Image* image = images[ j ];
            LBCHECK( image->allocDownloader( eq::Frame::BUFFER_DEPTH,
                             EQ_COMPRESSOR_TRANSFER_DEPTH_TO_DEPTH_UNSIGNED_INT,
                                             glewContext ));
            image->clearPixelData( eq::Frame::BUFFER_DEPTH );

            clock.reset();
            image->startReadback( eq::Frame::BUFFER_DEPTH, subPVP,
                                  eq::Zoom::NONE, glObjects );
            image->finishReadback( glObjects.glewGetContext( ));
            msec += clock.getTimef();
        }

        _sendEvent( READBACK, msec, area, formatType.str(), 0, 0 );

        if( tiles == NUM_IMAGES-1 )
            for( unsigned j = 0; j <= tiles; ++j )
                _saveImage( images[j],
                            "EQ_COMPRESSOR_DATATYPE_DEPTH_UNSIGNED_INT",
                            "tiles" );

        //---- readback of 'tiles' color images
        formatType.str("");
        formatType << tiles+1 << " color tiles";

        msec = 0;
        for( unsigned j = 0; j <= tiles; ++j )
        {
            subPVP.y = pvp.y + j * subPVP.h;
            eq::Image* image = images[ j ];

            LBCHECK( image->allocDownloader( eq::Frame::BUFFER_COLOR,
                                            EQ_COMPRESSOR_TRANSFER_RGBA_TO_BGRA,
                                              glewContext ));
            image->clearPixelData( eq::Frame::BUFFER_COLOR );

            clock.reset();
            image->startReadback( eq::Frame::BUFFER_COLOR, subPVP,
                                  eq::Zoom::NONE, glObjects );
            image->finishReadback( glObjects.glewGetContext( ));
            msec += clock.getTimef();
        }
        _sendEvent( READBACK, msec, area, formatType.str(), 0, 0 );

        if( tiles == NUM_IMAGES-1 )
            for( unsigned j = 0; j <= tiles; ++j )
                _saveImage( images[j],"EQ_COMPRESSOR_DATATYPE_BGRA","tiles" );

        //---- benchmark assembly operations
        subPVP.y = pvp.y + tiles * subPVP.h;

        eq::Compositor::ImageOp op;
        op.channel = this;
        op.buffers = eq::Frame::BUFFER_COLOR | eq::Frame::BUFFER_DEPTH;
        op.offset  = offset;

        // fixed-function
        formatType.str("");
        formatType << "tiles, GL1.1, " << tiles+1 << " images";

        clock.reset();
        for( unsigned j = 0; j <= tiles; ++j )
            eq::Compositor::assembleImage( images[j], op );

        msec = clock.getTimef();
        _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );

        // CPU
        formatType.str("");
        formatType << "tiles, CPU,   " << tiles+1 << " images";

        std::vector< eq::Frame* > frames;
        frames.push_back( &_frame );

        clock.reset();
        eq::Compositor::assembleFramesCPU( frames, this );
        msec = clock.getTimef();
        _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
    }
}