예제 #1
0
파일: graph.hpp 프로젝트: SkTim/saedb
 vertex_type& vertex(vertex_id_type vid){
     if (!v_valid_[vid]) {
         sae::io::VertexIteratorPtr v = graph->Vertices();
         v->MoveTo(vid);
         std::string s = v->Data();
         vertices_[vid] = vertex_type(std::move(v));
         v_valid_[vid] = 1;
     }
     return vertices_[vid];
 }
예제 #2
0
 void add_vertex(vertex_id_type id, vertex_data_type data) {
     std::set<vertex_id_type>::iterator it;
     it = vertex_ids.find(id);
     if ( it == vertex_ids.end() ){
         vertex_ids.insert(id);
         auto vertex = vertex_type(*this, id);
         vertex_id_2_vertex.insert( std::pair<vertex_id_type, vertex_type>(id, vertex) );
         vertex_id_2_data.insert( std::pair<vertex_id_type, vertex_data_type>(id, data) );
         ++nvertex;
     }
 }
예제 #3
0
void textureglyph::rectangle(std::vector<vertex_type>& vertices, bounds2f xy, bounds2f uv)
{
	vertices.push_back(vertex_type(glm::vec2(xy.min.x, xy.min.y), glm::vec2(uv.min.x, uv.min.y)));
	vertices.push_back(vertex_type(glm::vec2(xy.min.x, xy.max.y), glm::vec2(uv.min.x, uv.max.y)));
	vertices.push_back(vertex_type(glm::vec2(xy.max.x, xy.max.y), glm::vec2(uv.max.x, uv.max.y)));
	vertices.push_back(vertex_type(glm::vec2(xy.max.x, xy.max.y), glm::vec2(uv.max.x, uv.max.y)));
	vertices.push_back(vertex_type(glm::vec2(xy.max.x, xy.min.y), glm::vec2(uv.max.x, uv.min.y)));
	vertices.push_back(vertex_type(glm::vec2(xy.min.x, xy.min.y), glm::vec2(uv.min.x, uv.min.y)));
}
void CreateGraph::way(const osmium::Way& way)
{
  const char* highway = way.get_value_by_key("highway");
  if (!highway || !strcmp(highway, "footway"))
  {
    return;
  }

  vertex_type u = -1;
  for (const auto& node_ref : way.nodes())
  {
    node_id_map_type::iterator pos;
    bool inserted;
    boost::tie(pos, inserted) = node_id_map.emplace(node_ref.positive_ref(), vertex_type());

    if (inserted)
    {
      double x = osmium::geom::detail::lon_to_x(node_ref.lon());
      double y = osmium::geom::detail::lat_to_y(node_ref.lat());
      Location loc(x, y);

      pos->second = boost::add_vertex(vertex_property(loc), graph);
    }

    const vertex_type v = pos->second;

    if (u+1)
    {
      const char* street_name = way.get_value_by_key("name", "");

      const Location& a = boost::get(boost::vertex_name, graph, u);
      const Location& b = boost::get(boost::vertex_name, graph, v);
      const double length = dist(a, b);

      edge_property prop;
      boost::get_property_value(prop, boost::edge_name) = street_name;
      boost::get_property_value(prop, boost::edge_weight) = length;

      boost::add_edge(u, v, prop, graph);
    }

    u = v;
  }
}
예제 #5
0
 operator vertex_type() const {
     return vertex_type(graph_ref, lvid);
 }
예제 #6
0
 vertex_type vertex(vertex_id_type vid){
     return vertex_type(*this, vid);
 }
예제 #7
0
 vertex_type target() const {
     return vertex_type(graph_ref, target_id);
 }
예제 #8
0
 vertex_type source() const {
     return vertex_type(graph_ref, source_id);
 }
예제 #9
0
파일: graph.hpp 프로젝트: SkTim/saedb
 vertex_type target() const {
     return vertex_type(std::move(ei->Target()));
 }
예제 #10
0
파일: graph.hpp 프로젝트: SkTim/saedb
 vertex_type source() const {
     return vertex_type(std::move(ei->Source()));
 }
예제 #11
0
파일: graph.hpp 프로젝트: mabodx/saedb
 vertex_type vertex(vertex_id_type vid){
     sae::io::VertexIteratorPtr v = graph->Vertices();
     v->MoveTo(vid);
     return vertex_type(std::move(v));
 }
예제 #12
0
/*
 * the::graphics::directx::d2d_interop_surface::alloc_rendering_res
 */
void the::graphics::directx::d2d_interop_surface::alloc_rendering_res(void) {
    THE_STACK_TRACE;
    D3D11_BUFFER_DESC bd;                   // Describes new buffers.
    D3D11_BLEND_DESC blendStateDesc;        // Blend state configuration.
    DWORD dwShaderFlags = 0;                // Compiler flags for shader.
    HRESULT hr = S_OK;                      // Result of API calls.
    pixel_shader_constants initConsts;      // Initial constants.
    D3D11_SUBRESOURCE_DATA initData;        // Buffer initialisation data.
    system::com_ptr<ID3DBlob> msg;          // Messages of shader compiler.
    UINT offset = 0;                        // Offset of VB.
    D3D11_SAMPLER_DESC samplerDesc;         // Texture sampler config.
    system::com_ptr<ID3DBlob> shaderSource; // Shader source code.
    UINT stride = sizeof(vertex_type);      // Stride of VB.

    THE_ASSERT(this->d3d11Device.is_not_null());

    THE_DIRECTX_TRACE_INFO("Getting immediate context...\n");
    this->d3d11Device->GetImmediateContext(&this->d3d11ImmediateContext);
    THE_ASSERT(this->d3d11ImmediateContext.is_not_null());

    // Allocate and fill VB.
    vertex_type vertices[] = {
        vertex_type(-0.5f,  0.5f,  0.5f),
        vertex_type( 0.5f,  0.5f,  0.5f),
        vertex_type(-0.5f, -0.5f,  0.5f),
        vertex_type( 0.5f, -0.5f,  0.5f)
    };

    the::zero_memory(&bd);
    bd.Usage = D3D11_USAGE_IMMUTABLE;
    bd.ByteWidth = sizeof(vertices);
    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;

    the::zero_memory(&initData);
    initData.pSysMem = vertices;

    THE_DIRECTX_TRACE_INFO("Allocating vertex buffer...\n");
    hr = this->d3d11Device->CreateBuffer(&bd, &initData,
        &this->d3d11VertexBuffer);
    if (FAILED(hr)) {
        THE_DIRECTX_TRACE_AND_THROW(hr, "Allocating vertex buffer failed with "
            "error code %d.\n", hr);
    }
    THE_DIRECTX_SET_DEBUG_NAME(this->d3d11VertexBuffer, "Vertex buffer of "
        "d2d_interop_surface 0x%p", this);

    // Prepare the vertex shader.
    THE_DIRECTX_TRACE_INFO("Compiling vertex shader...\n");
    THE_ASSERT(shaderSource.is_null());
    THE_ASSERT(msg.is_null());
    hr = ::D3DCompile(VERTEX_SHADER, ::strlen(VERTEX_SHADER),
         "the::graphics::directx::d2d_interop_surface::VERTEX_SHADER",
         NULL, NULL, "VsMain", "vs_4_0", 0, 0, &shaderSource, &msg);
    if (FAILED(hr)) {
        if (msg.is_not_null()) {
            THE_DIRECTX_TRACE_ERROR(reinterpret_cast<char *>(
                msg->GetBufferPointer()));
        }
        THE_DIRECTX_TRACE_AND_THROW(hr, "Compiling vertex shader failed with "
            "error code %d.\n", hr);
    }

    THE_DIRECTX_TRACE_INFO("Creating vertex shader...\n");
    hr = this->d3d11Device->CreateVertexShader(shaderSource->GetBufferPointer(),
        shaderSource->GetBufferSize(), NULL, &this->d3d11VertexShader);
    if (FAILED(hr)) {
        THE_DIRECTX_TRACE_AND_THROW(hr, "Creating vertex shader failed with "
            "error code %d.\n", hr);
    }
    THE_DIRECTX_SET_DEBUG_NAME(this->d3d11VertexShader, "Vertex shader of "
        "d2d_interop_surface 0x%p", this);

    // Create input layout.
    THE_DIRECTX_TRACE_INFO("Creating  input layout from vertex shader "
        "source...\n");
    hr = this->d3d11Device->CreateInputLayout(vertex_type::d3d11_input_layout,
        sizeof(vertex_type::d3d11_input_layout)
        / sizeof(*vertex_type::d3d11_input_layout),
        shaderSource->GetBufferPointer(), shaderSource->GetBufferSize(),
        &this->d3d11InputLayout);
    if (FAILED(hr)) {
        THE_DIRECTX_TRACE_AND_THROW(hr, "Creating input layout from vertex "
            "shader source failed with error code %d.\n", hr);
    }
    THE_DIRECTX_SET_DEBUG_NAME(this->d3d11InputLayout, "Input layout of "
        "d2d_interop_surface 0x%p", this);

    // Prepare for re-use.
    msg = NULL;
    shaderSource = NULL;

    // Prepare the pixel shader.
    THE_DIRECTX_TRACE_INFO("Compiling pixel shader...\n");
    THE_ASSERT(shaderSource.is_null());
    THE_ASSERT(msg.is_null());
    hr = ::D3DCompile(PIXEL_SHADER, ::strlen(PIXEL_SHADER), 
        "the::graphics::directx::d2d_interop_surface:PIXEL_SHADER", NULL, NULL,
        "PsMain", "ps_4_0", 0, 0, &shaderSource, &msg);
    if (FAILED(hr)) {
        if (msg.is_not_null()) {
            THE_DIRECTX_TRACE_ERROR(reinterpret_cast<char *>(
                msg->GetBufferPointer()));
        }
        THE_DIRECTX_TRACE_AND_THROW(hr, "Compiling pixel shader failed with "
            "error code %d.\n", hr);
    }

    THE_DIRECTX_TRACE_INFO("Creating pixel shader...\n");
    hr = this->d3d11Device->CreatePixelShader(shaderSource->GetBufferPointer(),
        shaderSource->GetBufferSize(), NULL, &this->d3d11PixelShader);
    if (FAILED(hr)) {
        THE_DIRECTX_TRACE_AND_THROW(hr, "Creating pixel shader failed with "
            "error code %d.\n", hr);
    }
    THE_DIRECTX_SET_DEBUG_NAME(this->d3d11PixelShader, "Pixel shader of "
        "d2d_interop_surface 0x%p", this);

    // Create D3D 11 resource view for shared texture.
    this->alloc_shader_res_view();

    // Allocate constant buffer for passing uniform parameters.
    THE_DIRECTX_TRACE_INFO("Creating constant buffer for pixel shader uniform "
        "parameters...\n");
    the::zero_memory(&bd);
    bd.Usage = D3D11_USAGE_DYNAMIC;
    bd.ByteWidth = sizeof(pixel_shader_constants);
    bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
    bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

    the::zero_memory(&initConsts);
    initConsts.opacity = 1.0f;

    the::zero_memory(&initData);
    initData.pSysMem = &initConsts;
    initData.SysMemPitch = bd.ByteWidth;

    THE_DIRECTX_TRACE_INFO("Creating constant buffer for pixel shader uniform "
        "parameters...\n");
    hr = this->d3d11Device->CreateBuffer(&bd, &initData,
        &this->d3d11CbPsParams);
    if (FAILED(hr)) {
        THE_DIRECTX_TRACE_AND_THROW(hr, "Creating constant buffer for pixel "
            "shader uniform parameters failed with error code %d.\n", hr);
    }
    THE_DIRECTX_SET_DEBUG_NAME(this->d3d11CbPsParams, "Constant buffer for "
        "pixel shader uniform variables of d2d_interop_surface 0x%p", this);

    // Allocate sampler state for reading shared surface.
    THE_DIRECTX_TRACE_INFO("Creating sampler state...\n");
    the::zero_memory(&samplerDesc);
    samplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
    samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
    samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
    samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
    samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    hr = this->d3d11Device->CreateSamplerState(&samplerDesc,
        &this->d3d11SamplerState);
    if (FAILED(hr)) {
        THE_DIRECTX_TRACE_AND_THROW(hr, "Creating sampler state failed with "
            "error code %d.\n", hr);
    }
    THE_DIRECTX_SET_DEBUG_NAME(this->d3d11SamplerState, "Sampler state of "
        "d2d_interop_surface 0x%p", this);

    // Allocate blend state for Porter-Duff over operator.
    THE_DIRECTX_TRACE_INFO("Creating blend state...\n");
    the::zero_memory(&blendStateDesc);
    blendStateDesc.RenderTarget[0].BlendEnable = TRUE;
    blendStateDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
    blendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
    blendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
    blendStateDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
    blendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
    blendStateDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
    blendStateDesc.RenderTarget[0].RenderTargetWriteMask
        = D3D11_COLOR_WRITE_ENABLE_ALL;
    hr = this->d3d11Device->CreateBlendState(&blendStateDesc,
        &this->d3d11BlendState);
    if (FAILED(hr)) {
        THE_DIRECTX_TRACE_AND_THROW(hr, "Creating blend state failed with "
            "error code %d.\n", hr);
    }
    THE_DIRECTX_SET_DEBUG_NAME(this->d3d11BlendState, "Blend state of "
        "d2d_interop_surface 0x%p", this);
}