Mesh(Vertex *vertices, unsigned numVertices, unsigned int *indices, unsigned int numIndices) : vertexArrayObject_(), vertexArrayBuffers(), drawCount_(numIndices) { IndexedModel model; model.positions.reserve(numVertices); model.texCoords.reserve(numVertices); for (unsigned i = 0 ; i < numVertices ; ++i) { model.positions.push_back(vertices[i].pos_); model.texCoords.push_back(vertices[i].texCoord_); } model.indices.reserve(numIndices); for (unsigned i = 0 ; i < numIndices ; ++i) model.indices.push_back(indices[i]); init_mesh(model); }
void SizeAdaptShapeWrapper::run_wrapper( Mesh* mesh, ParallelMesh* pmesh, MeshDomain* domain, Settings* settings, QualityAssessor* qa, MsqError& err ) { InstructionQueue q; // calculate average lambda for mesh TagVertexMesh init_mesh( err, mesh ); MSQ_ERRRTN(err); ReferenceMesh ref_mesh( &init_mesh ); RefMeshTargetCalculator W_0( &ref_mesh ); q.add_tag_vertex_mesh( &init_mesh, err ); MSQ_ERRRTN(err); // create objective function IdealShapeTarget W_i; LambdaTarget W( &W_0, &W_i ); Target2DShapeSizeBarrier tm2; Target3DShapeSizeBarrier tm3; TMPQualityMetric mu( &W, &tm2, &tm3 ); PMeanPTemplate of( 1.0, &mu ); // create quality assessor EdgeLengthMetric len(0.0); qa->add_quality_assessment( &mu ); qa->add_quality_assessment( &len ); q.add_quality_assessor( qa, err ); // create solver TrustRegion solver( &of ); TerminationCriterion tc, ptc; tc.add_absolute_vertex_movement( maxVtxMovement ); tc.add_iteration_limit( iterationLimit ); ptc.add_iteration_limit( pmesh ? parallelIterations : 1 ); solver.set_inner_termination_criterion( &tc ); solver.set_outer_termination_criterion( &ptc ); q.set_master_quality_improver( &solver, err ); MSQ_ERRRTN(err); q.add_quality_assessor( qa, err ); // Optimize mesh q.run_common( mesh, pmesh, domain, settings, err ); MSQ_CHKERR(err); }
bool SkyboxMaterialSystem::init(Context& context, const MaterialSystemContext& material_system_context) { set_layout(SkyboxLayout::handle); if (!context.shader_manager.get(shader(), material_system_context.shader_name)) return false; transform_uniform_ = context.uniform_pool.create(); UniformBuffer& uniform = context.uniform_pool.get(transform_uniform_); UniformBufferDesc uniform_buffer_desc; create_uniform_buffer_element(uniform_buffer_desc, "inv_vp", mat4x4::identity()); uniform_buffer_desc.name = "transform"; uniform_buffer_desc.program = &default_program(context); if (!uniform.init(uniform_buffer_desc)) { ERROR_LOG("Skybox material initialization failed - can't init uniform"); return false; } return init_mesh(context, material_system_context); }
int main() { init_display(); if ( glGetError() != 0 ) { printf("display : error\n"); exit(-1); } init_shaders(); if ( glGetError() != 0 ) { printf("shader : error\n"); exit(-1); } init_mesh(); if ( glGetError() != 0 ) { printf("mesh : error\n"); exit(-1); } init_texture(); if ( glGetError() != 0 ) { printf("texture : error\n"); exit(-1); } init_info(); if ( glGetError() != 0 ) { printf("init_info : error\n"); exit(-1); } draw_loop(); return (0); }
Mesh(const std::string &filename) { IndexedModel model = OBJModel(filename).ToIndexedModel(); init_mesh(model); }
void grid_eval(cl::program_t& prog, size_t block0, size_t block1, size_t refine) { const size_t Nx = px.size(); const size_t Ny = py.size(); const size_t Nz = pz.size(); cl::ctx_t ctx(prog.context()); cl::queue_t queue(ctx, ctx.device(0)); init_mesh(); { cl::kernel_t kern = prog.kernel("grid"); boost::scoped_array<uint8_t> out(new uint8_t[block0 * block0 * block0]); boost::scoped_array<float> gx(new float[block0]); boost::scoped_array<float> gy(new float[block0]); boost::scoped_array<float> gz(new float[block0]); cl::mem_t gx_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block0 * sizeof(float), NULL); cl::mem_t gy_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block0 * sizeof(float), NULL); cl::mem_t gz_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block0 * sizeof(float), NULL); cl::mem_t out_mem = ctx.create_buffer(CL_MEM_READ_WRITE, block0 * block0 * block0, NULL); const size_t Py = block0; const size_t Pz = block0 * block0; kern.arg(0, gx_mem); kern.arg(1, gy_mem); kern.arg(2, gz_mem); kern.arg(3, out_mem); kern.arg(4, Py); kern.arg(5, Pz); for (size_t _z = 0; _z < Nz; _z += block0 - 1) { const size_t Wz = std::min(block0, Nz - _z); for (size_t i = 0; i < Wz; ++i) gz[i] = (float)pz[_z + i]; queue.sync(cl::cmd_write_buffer(gz_mem, CL_FALSE, 0, Wz * sizeof(float), gz.get())); for (size_t _y = 0; _y < Ny; _y += block0 - 1) { const size_t Wy = std::min(block0, Ny - _y); for (size_t i = 0; i < Wy; ++i) gy[i] = (float)py[_y + i]; queue.sync(cl::cmd_write_buffer(gy_mem, CL_FALSE, 0, Wy * sizeof(float), gy.get())); for (size_t _x = 0; _x < Nx; _x += block0 - 1) { std::cerr << "block: " << _x << "," << _y << "," << _z << std::endl; const size_t Wx = std::min(block0, Nx - _x); for (size_t i = 0; i < Wx; ++i) gx[i] = (float)px[_x + i]; queue.sync(cl::cmd_write_buffer(gx_mem, CL_FALSE, 0, Wx * sizeof(float), gx.get())); queue.sync(cl::cmd_task(kern).wrk_sz(Wx, Wy, Wz)); queue.sync(cl::cmd_read_buffer( out_mem, CL_FALSE, 0, block0 * block0 * block0, out.get())); for (size_t z = 0; z < Wz - 1; ++z) { for (size_t y = 0; y < Wy - 1; ++y) { for (size_t x = 0; x < Wx - 1; ++x) { size_t bits = 0; if (out[(x + 0) + (y + 0) * Py + (z + 0) * Pz]) bits |= 0x01; if (out[(x + 1) + (y + 0) * Py + (z + 0) * Pz]) bits |= 0x02; if (out[(x + 0) + (y + 1) * Py + (z + 0) * Pz]) bits |= 0x04; if (out[(x + 1) + (y + 1) * Py + (z + 0) * Pz]) bits |= 0x08; if (out[(x + 0) + (y + 0) * Py + (z + 1) * Pz]) bits |= 0x10; if (out[(x + 1) + (y + 0) * Py + (z + 1) * Pz]) bits |= 0x20; if (out[(x + 0) + (y + 1) * Py + (z + 1) * Pz]) bits |= 0x40; if (out[(x + 1) + (y + 1) * Py + (z + 1) * Pz]) bits |= 0x80; const uint8_t* row = mc_table[bits]; size_t n_tri = *row++; if (n_tri == 0) continue; { for (size_t t = 0; t < n_tri; ++t) { uint8_t ea, eb, ec; size_t va, vb, vc; ea = *row++; eb = *row++; ec = *row++; va = get_intersection( decode_edge(_x + x, _y + y, _z + z, ea)); vb = get_intersection( decode_edge(_x + x, _y + y, _z + z, eb)); vc = get_intersection( decode_edge(_x + x, _y + y, _z + z, ec)); mesh->add_tri(va, vb, vc); } } } } } } } } } std::vector<std::pair<edgeint_t, size_t> > vert_calc; vert_calc.reserve(int_idx.size()); for (typename edgeint_map_t::iterator i = int_idx.begin(); i != int_idx.end(); ++i) { vert_calc.push_back(std::make_pair((*i).first, (*i).second)); } { boost::scoped_array<cl_float3> a(new cl_float3[block1]); boost::scoped_array<cl_float3> b(new cl_float3[block1]); boost::scoped_array<cl_float3> c(new cl_float3[block1]); cl::mem_t a_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block1 * sizeof(cl_float3), NULL); cl::mem_t b_mem = ctx.create_buffer(CL_MEM_READ_ONLY, block1 * sizeof(cl_float3), NULL); cl::mem_t c_mem = ctx.create_buffer(CL_MEM_READ_WRITE, block1 * sizeof(cl_float3), NULL); cl::kernel_t kern = prog.kernel("chop"); kern.arg(0, a_mem); kern.arg(1, b_mem); kern.arg(2, c_mem); kern.arg(3, refine); for (size_t i = 0; i < vert_calc.size(); i += block1) { const size_t N = std::min(vert_calc.size() - i, block1); for (size_t j = 0; j < N; ++j) { edgeint_t& e = vert_calc[i + j].first; v3d_t a_pos = position_of_vertex(e.a[0], e.a[1], e.a[2]); v3d_t b_pos = position_of_vertex(e.b[0], e.b[1], e.b[2]); a[j].x = (float)a_pos.x; a[j].y = (float)a_pos.y; a[j].z = (float)a_pos.z; b[j].x = (float)b_pos.x; b[j].y = (float)b_pos.y; b[j].z = (float)b_pos.z; } queue.sync(cl::cmd_write_buffer(a_mem, CL_FALSE, 0, N * sizeof(cl_float3), a.get())); queue.sync(cl::cmd_write_buffer(b_mem, CL_FALSE, 0, N * sizeof(cl_float3), b.get())); queue.sync(cl::cmd_task(kern).wrk_sz(N)); queue.sync(cl::cmd_read_buffer(c_mem, CL_FALSE, 0, N * sizeof(cl_float3), c.get())); for (size_t j = 0; j < N; ++j) { mesh->vertices[vert_calc[i + j].second].pos = v3d_t::init(c[j].x, c[j].y, c[j].z); } } } }