static void send_pending_removes (EDataBookView *view) { EDataBookViewPrivate *priv = view->priv; if (priv->removes->len == 0) return; e_gdbus_book_view_emit_contacts_removed (view->priv->gdbus_object, (const gchar * const *) priv->removes->data); reset_array (priv->removes); }
static void send_pending_removes (EDataCalView *view) { EDataCalViewPrivate *priv = view->priv; if (priv->removes->len == 0) return; /* TODO: send ECalComponentIds as a list of pairs */ e_gdbus_cal_view_emit_objects_removed (view->priv->gdbus_object, (const gchar * const *) priv->removes->data); reset_array (priv->removes); }
static void e_data_book_view_finalize (GObject *object) { EDataBookView *book_view = E_DATA_BOOK_VIEW (object); EDataBookViewPrivate *priv = book_view->priv; reset_array (priv->adds); reset_array (priv->changes); reset_array (priv->removes); g_array_free (priv->adds, TRUE); g_array_free (priv->changes, TRUE); g_array_free (priv->removes, TRUE); g_free (priv->card_query); g_mutex_free (priv->pending_mutex); g_hash_table_destroy (priv->ids); G_OBJECT_CLASS (e_data_book_view_parent_class)->finalize (object); }
int main() { reset_array(al_result_1, RESULT_SIZE); reset_array(al_result_2, RESULT_SIZE); int last_city, taxi_max; scanf("%d%d", &last_city, &taxi_max); scanf("%d", &ticket_prizes[0].middle); for(int i = 0; i < last_city; i++) scanf("%d%d%d", &ticket_prizes[i].left, &ticket_prizes[i + 1].middle, &ticket_prizes[i].right); //dla n = 1 potrafimy policzyć(jesteśmy w 1 mieście, uciekliśmy z miasta nr 0 al_result_1[0][1] = ticket_prizes[0].left; al_result_1[1][0] = ticket_prizes[0].middle + ticket_prizes[0].right; for(int n = 2; n <= last_city; n++) { for(int i = 0; i <= std::min(n - 1, taxi_max) ; i++) for(int j = 0; j <= std::min(n - 1, last_city); j++) propagate(n - 1, al_result_1, al_result_2, i, j); array_from_to(al_result_2, al_result_1, n + 1); reset_array(al_result_2, n + 1); } // Dla parzystej liczby taksówek musimy jeszcze dodać koszt ostatniej taksówki, bo jesteśmy po złej stronie // Zrobimy to tylko dla kolumny o indeksie równym last_city/2, bo w tej kolumnie jest wynik for(int i = 0; i <= taxi_max; i +=2) al_result_1[i][last_city/2] += ticket_prizes[last_city].middle; //Szukamy minimum w tej kolumnie; long min = INFINITY; // Szukamy minimum w tej kolumnie z limitem na liczbę taksówek, jednak parzyste wiersze zostały // zwiększone o jedną taksówkę, więc dla parzystych k nie rozważamy ostatniego wiersza if(taxi_max % 2 == 0) --taxi_max; for(int i = 0; i <= taxi_max; i++) if(min > al_result_1[i][last_city/2]) min = al_result_1[i][last_city/2]; printf("%ld\n", min); return 0; }
boost::shared_ptr< Base<EncodingT> > IDiaSourceFilePtrInterpreter<EncodingT>::get_checksum(boost::shared_ptr< Base<EncodingT> >& cbData, boost::shared_ptr< Base<EncodingT> >& pcbData, boost::shared_ptr< Base<EncodingT> >& data) { boost::shared_ptr< Base<EncodingT> > res(new Numeric<EncodingT>()); unsigned long nativeCbData; unsigned long nativePcbData; std::vector< unsigned char > nativeData; if (check_numeric(cbData, nativeCbData) && check_numeric(pcbData, nativePcbData) && check_array(data, nativeData, check_numeric<EncodingT, unsigned char>)) { res.reset(new Numeric<EncodingT>(value()->get_checksum(nativeCbData, &nativePcbData, nativeData.data()))); reset_numeric(cbData, nativeCbData); reset_numeric(pcbData, nativePcbData); reset_array(data, nativeData, reset_numeric<EncodingT, unsigned char>); } return res; }
int main(void) { // testing const int size = 5; int fst_arr[] = {1, 2, 3, 4, 5}; int snd_arr[] = {5, 4, 3, 2, 1}; int res[size]; array_sum(fst_arr, snd_arr, res, size); // output result print_array(fst_arr, size); print_array(snd_arr, size); print_array(res, size); // allocate an array from heap int* dynamic = (int*) malloc (sizeof(int) * size); int i; for (i = 0; i < size; ++i) dynamic[i] = i; print_array(dynamic, size); // delete a value in a staticly declared array delete_shift(fst_arr, 2, size); print_array(fst_arr, size - 1); // delete a value in a dynamicly allocated array delete_realloc(dynamic, 1, size); print_array(dynamic, size - 1); // free memory free(dynamic); reset_array(fst_arr, size); print_array(fst_arr, size); inverse(snd_arr, size); print_array(snd_arr, size); square(res, size); print_array(res, size); return 0; }
void PtrFreeScene :: translate_geometry_qbvh(const lux_ext_mesh_list_t& meshs) { lux_defined_meshs_t defined_meshs(PtrFreeScene::mesh_ptr_compare); Mesh new_mesh; Mesh current_mesh; std::vector<Point> tmp_vertexes; std::vector<Normal> tmp_normals; std::vector<Spectrum> tmp_colors; std::vector<UV> tmp_uvs; std::vector<Triangle> tmp_triangles; std::vector<Mesh> tmp_mesh_descs; for(lux_ext_mesh_list_t::const_iterator it = meshs.begin(); it != meshs.end(); ++it) { const luxrays::ExtMesh* mesh = *it; bool is_existing_instance; if (mesh->GetType() == luxrays::TYPE_EXT_TRIANGLE_INSTANCE) { const luxrays::ExtInstanceTriangleMesh* imesh = static_cast<const luxrays::ExtInstanceTriangleMesh*>(mesh); // check if is one of the already done meshes lux_defined_meshs_t::iterator it = defined_meshs.find(imesh->GetExtTriangleMesh()); if (it == defined_meshs.end()) { // it is a new one current_mesh = new_mesh; new_mesh.verts_offset += imesh->GetTotalVertexCount(); new_mesh.tris_offset += imesh->GetTotalTriangleCount(); is_existing_instance = false; const uint index = tmp_mesh_descs.size(); defined_meshs[imesh->GetExtTriangleMesh()] = index; } else { // it is not a new one current_mesh = tmp_mesh_descs[it->second]; is_existing_instance = true; } current_mesh.trans = imesh->GetTransformation().GetMatrix().m; current_mesh.inv_trans = imesh->GetInvTransformation().GetMatrix().m; mesh = imesh->GetExtTriangleMesh(); } else { // not a luxrays::TYPE_EXT_TRIANGLE_INSTANCE current_mesh = new_mesh; new_mesh.verts_offset += mesh->GetTotalVertexCount(); new_mesh.tris_offset += mesh->GetTotalTriangleCount(); if (mesh->HasColors()) { new_mesh.colors_offset += mesh->GetTotalVertexCount(); current_mesh.has_colors = true; } else { current_mesh.has_colors = false; } is_existing_instance = false; } tmp_mesh_descs.push_back(current_mesh); if (!is_existing_instance) { assert(mesh->GetType() == luxrays::TYPE_EXT_TRIANGLE); // translate mesh normals and colors uint offset = tmp_normals.size(); tmp_normals.resize(offset + mesh->GetTotalVertexCount()); for(uint j = 0; j < mesh->GetTotalVertexCount(); ++j) tmp_normals[offset + j] = Normal(mesh->GetNormal(j)); if (mesh->HasColors()) { offset = tmp_colors.size(); tmp_colors.resize(offset + mesh->GetTotalVertexCount()); for(uint j = 0; j < mesh->GetTotalVertexCount(); ++j) tmp_colors[offset + j] = Spectrum(mesh->GetColor(j)); } // translate vertex uvs if (original_scene->texMapCache->GetSize()) { // TODO: should check if the only texture map is used for infintelight offset = tmp_uvs.size(); tmp_uvs.resize(offset + mesh->GetTotalVertexCount()); if (mesh->HasUVs()) for(uint j = 0; j < mesh->GetTotalVertexCount(); ++j) tmp_uvs[offset + j] = UV(mesh->GetUV(j)); else for(uint j = 0; j < mesh->GetTotalVertexCount(); ++j) tmp_uvs[offset + j] = UV(0.f, 0.f); } // translate meshrverticener size, the content is expanded by inserting at the end as many elements as needed to reach a size of n. If val is specified, the new elements are initialized as copies of val, otherwise, they are value-initialized.s offset = tmp_vertexes.size(); tmp_vertexes.resize(offset + mesh->GetTotalVertexCount()); for(uint j = 0; j < mesh->GetTotalVertexCount(); ++j) tmp_vertexes[offset + j] = Point(mesh->GetVertex(j)); // translate mesh indices offset = tmp_triangles.size(); const luxrays::Triangle *mtris = mesh->GetTriangles(); tmp_triangles.resize(offset + mesh->GetTotalTriangleCount()); for(uint j = 0; j < mesh->GetTotalTriangleCount(); ++j) tmp_triangles[offset + j] = Triangle(mtris[j]); } } this->vertex_count = tmp_vertexes.size(); this->normals_count = tmp_normals.size(); this->colors_count = tmp_colors.size(); this->uvs_count = tmp_uvs.size(); this->triangles_count = tmp_triangles.size(); this->mesh_descs_count = tmp_mesh_descs.size(); reset_array(this->vertexes, this->vertex_count); reset_array(this->normals, this->normals_count); reset_array(this->colors, this->colors_count); reset_array(this->uvs, this->uvs_count); reset_array(this->triangles, this->triangles_count); reset_array(this->mesh_descs, this->mesh_descs_count); memcpy(vertexes, &tmp_vertexes[0], sizeof(Point) * this->vertex_count); memcpy(normals, &tmp_normals[0], sizeof(Normal) * this->normals_count); memcpy(colors, &tmp_colors[0], sizeof(Spectrum) * this->colors_count); memcpy(uvs, &tmp_uvs[0], sizeof(UV) * this->uvs_count); memcpy(triangles, &tmp_triangles[0], sizeof(Triangle) * this->triangles_count); memcpy(mesh_descs, &tmp_mesh_descs[0], sizeof(Mesh) * this->mesh_descs_count); }
void PtrFreeScene :: compile_texture_maps() { delete_array(tex_maps); delete_array(rgb_tex); delete_array(alpha_tex); delete_array(mesh_texs); delete_array(bump_map); delete_array(bump_map_scales); delete_array(normal_map); this->tex_maps_count = 0; // translate mesh texture maps std::vector<luxrays::TextureMap*> tms; original_scene->texMapCache->GetTexMaps(tms); // compute amount of RAM to allocate //uint rgb_tex_size = 0; //uint alpha_tex_size = 0; this->rgb_tex_count = 0; this->alpha_tex_count = 0; for(uint i = 0; i < tms.size(); ++i) { luxrays::TextureMap* tm = tms[i]; const uint pixel_count = tm->GetWidth() * tm->GetHeight(); this->rgb_tex_count += pixel_count; if (tm->HasAlpha()) this->alpha_tex_count += pixel_count; } // allocate texture map if ((this->rgb_tex_count > 0) || (this->alpha_tex_count) > 0) { this->tex_maps_count = tms.size(); reset_array(this->tex_maps, this->tex_maps_count); //tex_maps.resize(tms.size()); if (this->rgb_tex_count > 0) { uint rgb_offset = 0; //rgb_tex.resize(rgb_tex_size); reset_array(this->rgb_tex, this->rgb_tex_count); for(uint i = 0; i < tms.size(); ++i) { luxrays::TextureMap* tm = tms[i]; const uint pixel_count = tm->GetWidth() * tm->GetHeight(); // TODO memcpy safe? memcpy(&rgb_tex[rgb_offset], tm->GetPixels(), pixel_count * sizeof(Spectrum)); this->tex_maps[i].rgb_offset = rgb_offset; rgb_offset += pixel_count; } } if (this->alpha_tex_count > 0) { uint alpha_offset = 0; //alpha_tex.resize(alpha_tex_size); reset_array(this->alpha_tex, this->alpha_tex_count); for(uint i = 0; i < tms.size(); ++i) { luxrays::TextureMap* tm = tms[i]; const uint pixel_count = tm->GetWidth() * tm->GetHeight(); if (tm->HasAlpha()) { memcpy(&alpha_tex[alpha_offset], tm->GetAlphas(), pixel_count * sizeof(float)); this->tex_maps[i].alpha_offset = alpha_offset; alpha_offset += pixel_count; } else { this->tex_maps[i].alpha_offset = PPM_NONE; } } } // translate texture map description for(uint i = 0; i < tms.size(); ++i) { luxrays::TextureMap* tm = tms[i]; this->tex_maps[i].width = tm->GetWidth(); this->tex_maps[i].height = tm->GetHeight(); } // translate mesh texture indexes //const uint mesh_count = mesh_mats.size(); //mesh_texs.resize(mesh_count); reset_array(this->mesh_texs, this->mesh_materials_count); for(uint i = 0; i < this->mesh_materials_count; ++i) { luxrays::TexMapInstance* t = original_scene->objectTexMaps[i]; if (t) { // look for the index uint index = 0; for(uint j = 0; j < tms.size(); ++j) { if (t->GetTexMap() == tms[j]) { index = j; break; } } this->mesh_texs[i] = index; } else { this->mesh_texs[i] = PPM_NONE; } } // translate mesh bump map indexes bool has_bump_mapping = false; //bump_map.resize(mesh_count); reset_array(this->bump_map, this->mesh_materials_count); for(uint i = 0; i < this->mesh_materials_count; ++i) { luxrays::BumpMapInstance* bm = original_scene->objectBumpMaps[i]; if (bm) { // look for the index uint index = 0; for(uint j = 0; j < tms.size(); ++j) { if (bm->GetTexMap() == tms[j]) { index = j; break; } } this->bump_map[i] = index; has_bump_mapping = true; } else { this->bump_map[i] = PPM_NONE; } } if (has_bump_mapping) { //bump_map_scales.resize(mesh_count); reset_array(this->bump_map_scales, this->mesh_materials_count); for(uint i = 0; i < mesh_count; ++i) { luxrays::BumpMapInstance* bm = original_scene->objectBumpMaps[i]; if (bm) this->bump_map_scales[i] = bm->GetScale(); else this->bump_map_scales[i] = 1.f; } } // translate mesh normal map indices //unused? bool has_normal_mapping = false; //normal_map.resize(mesh_count); reset_array(this->normal_map, this->mesh_materials_count); for(uint i = 0; i < mesh_count; ++i) { luxrays::NormalMapInstance* nm = original_scene->objectNormalMaps[i]; if (nm) { // look for the index uint index = 0; for(uint j = 0; j < tms.size(); ++j) { if (nm->GetTexMap() == tms[j]) { index = j; break; } } this->normal_map[i] = index; //has_normal_mapping = true; } else { this->normal_map[i] = PPM_NONE; } } } }
void PtrFreeScene :: compile_materials() { // reset all materials to false //compiled_materials.resize(ppm::MAT_NULL); this->compiled_materials_count = ppm::MAT_MAX; reset_array(this->compiled_materials, this->compiled_materials_count); for(uint i = 0; i < ppm::MAT_MAX; ++i) this->compiled_materials[i] = false; this->materials_count = original_scene->materials.size(); //materials.resize(materials_count); reset_array(this->materials, this->materials_count); memset(this->materials, 0, sizeof(ppm::Material)*this->materials_count); for(uint i = 0; i < materials_count; ++i) { const luxrays::Material* orig_m = original_scene->materials[i]; ppm::Material* m = &materials[i]; switch(orig_m->GetType()) { case luxrays::MATTE: { compiled_materials[ppm::MAT_MATTE] = true; const luxrays::MatteMaterial* mm = static_cast<const luxrays::MatteMaterial*>(orig_m); m->diffuse = mm->IsDiffuse(); m->specular = mm->IsSpecular(); m->type = ppm::MAT_MATTE; m->param.matte.kd.r = mm->GetKd().r; m->param.matte.kd.g = mm->GetKd().g; m->param.matte.kd.b = mm->GetKd().b; break; } case luxrays::AREALIGHT: { compiled_materials[ppm::MAT_AREALIGHT] = true; const luxrays::AreaLightMaterial* alm = static_cast<const luxrays::AreaLightMaterial*>(orig_m); m->diffuse = alm->IsDiffuse(); m->specular = alm->IsSpecular(); m->type = ppm::MAT_AREALIGHT; m->param.area_light.gain.r = alm->GetGain().r; m->param.area_light.gain.g = alm->GetGain().g; m->param.area_light.gain.b = alm->GetGain().b; break; } case luxrays::MIRROR: { compiled_materials[ppm::MAT_MIRROR] = true; const luxrays::MirrorMaterial* mm = static_cast<const luxrays::MirrorMaterial*>(orig_m); m->type = ppm::MAT_MIRROR; m->param.mirror.kr.r = mm->GetKr().r; m->param.mirror.kr.g = mm->GetKr().g; m->param.mirror.kr.b = mm->GetKr().b; m->param.mirror.specular_bounce = mm->HasSpecularBounceEnabled(); break; } case luxrays::GLASS: { compiled_materials[ppm::MAT_GLASS] = true; const luxrays::GlassMaterial* gm = static_cast<const luxrays::GlassMaterial*>(orig_m); m->diffuse = gm->IsDiffuse(); m->specular = gm->IsSpecular(); m->type = ppm::MAT_GLASS; m->param.glass.refl.r = gm->GetKrefl().r; m->param.glass.refl.g = gm->GetKrefl().g; m->param.glass.refl.b = gm->GetKrefl().b; m->param.glass.refrct.r = gm->GetKrefrct().r; m->param.glass.refrct.g = gm->GetKrefrct().g; m->param.glass.refrct.b = gm->GetKrefrct().b; m->param.glass.outside_ior = gm->GetOutsideIOR(); m->param.glass.ior = gm->GetIOR(); m->param.glass.R0 = gm->GetR0(); m->param.glass.reflection_specular_bounce = gm->HasReflSpecularBounceEnabled(); m->param.glass.transmission_specular_bounce = gm->HasRefrctSpecularBounceEnabled(); break; } case luxrays::MATTEMIRROR: { compiled_materials[ppm::MAT_MATTEMIRROR] = true; const luxrays::MatteMirrorMaterial *mmm = static_cast<const luxrays::MatteMirrorMaterial*>(orig_m); m->diffuse = mmm->IsDiffuse(); m->specular = mmm->IsSpecular(); m->type = ppm::MAT_MATTEMIRROR; m->param.matte_mirror.matte.kd.r = mmm->GetMatte().GetKd().r; m->param.matte_mirror.matte.kd.g = mmm->GetMatte().GetKd().g; m->param.matte_mirror.matte.kd.b = mmm->GetMatte().GetKd().b; m->param.matte_mirror.mirror.kr.r = mmm->GetMirror().GetKr().r; m->param.matte_mirror.mirror.kr.g = mmm->GetMirror().GetKr().g; m->param.matte_mirror.mirror.kr.b = mmm->GetMirror().GetKr().b; m->param.matte_mirror.mirror.specular_bounce = mmm->GetMirror().HasSpecularBounceEnabled(); m->param.matte_mirror.matte_filter = mmm->GetMatteFilter(); m->param.matte_mirror.tot_filter = mmm->GetTotFilter(); m->param.matte_mirror.matte_pdf = mmm->GetMattePdf(); m->param.matte_mirror.mirror_pdf = mmm->GetMirrorPdf(); break; } case luxrays::METAL: { compiled_materials[ppm::MAT_METAL] = true; const luxrays::MetalMaterial* mm = static_cast<const luxrays::MetalMaterial*>(orig_m); m->diffuse = mm->IsDiffuse(); m->specular = mm->IsSpecular(); m->type = ppm::MAT_METAL; m->param.metal.kr.r = mm->GetKr().r; m->param.metal.kr.g = mm->GetKr().g; m->param.metal.kr.b = mm->GetKr().b; m->param.metal.exp = mm->GetExp(); m->param.metal.specular_bounce = mm->HasSpecularBounceEnabled(); break; } case luxrays::MATTEMETAL: { compiled_materials[ppm::MAT_MATTEMETAL] = true; const luxrays::MatteMetalMaterial* mmm = static_cast<const luxrays::MatteMetalMaterial*>(orig_m); m->diffuse = mmm->IsDiffuse(); m->specular = mmm->IsSpecular(); m->type = ppm::MAT_MATTEMETAL; m->param.matte_metal.matte.kd.r = mmm->GetMatte().GetKd().r; m->param.matte_metal.matte.kd.g = mmm->GetMatte().GetKd().g; m->param.matte_metal.matte.kd.b = mmm->GetMatte().GetKd().b; m->param.matte_metal.metal.kr.r = mmm->GetMetal().GetKr().r; m->param.matte_metal.metal.kr.g = mmm->GetMetal().GetKr().g; m->param.matte_metal.metal.kr.b = mmm->GetMetal().GetKr().b; m->param.matte_metal.metal.exp = mmm->GetMetal().GetExp(); m->param.matte_metal.metal.specular_bounce = mmm->GetMetal().HasSpecularBounceEnabled(); m->param.matte_metal.matte_filter = mmm->GetMatteFilter(); m->param.matte_metal.tot_filter = mmm->GetTotFilter(); m->param.matte_metal.matte_pdf = mmm->GetMattePdf(); m->param.matte_metal.metal_pdf = mmm->GetMetalPdf(); break; } case luxrays::ALLOY: { compiled_materials[ppm::MAT_ALLOY] = true; const luxrays::AlloyMaterial* am = static_cast<const luxrays::AlloyMaterial*>(orig_m); m->diffuse = am->IsDiffuse(); m->specular = am->IsSpecular(); m->type = ppm::MAT_ALLOY; m->param.alloy.refl.r = am->GetKrefl().r; m->param.alloy.refl.g = am->GetKrefl().g; m->param.alloy.refl.b = am->GetKrefl().b; m->param.alloy.diff.r = am->GetKd().r; m->param.alloy.diff.g = am->GetKd().g; m->param.alloy.diff.b = am->GetKd().b; m->param.alloy.exp = am->GetExp(); m->param.alloy.R0 = am->GetR0(); m->param.alloy.specular_bounce = am->HasSpecularBounceEnabled(); break; } case luxrays::ARCHGLASS: { compiled_materials[ppm::MAT_ARCHGLASS] = true; const luxrays::ArchGlassMaterial* agm = static_cast<const luxrays::ArchGlassMaterial*>(orig_m); m->diffuse = agm->IsDiffuse(); m->specular = agm->IsSpecular(); m->type = ppm::MAT_ARCHGLASS; m->param.arch_glass.refl.r = agm->GetKrefl().r; m->param.arch_glass.refl.g = agm->GetKrefl().g; m->param.arch_glass.refl.b = agm->GetKrefl().b; m->param.arch_glass.refrct.r = agm->GetKrefrct().r; m->param.arch_glass.refrct.g = agm->GetKrefrct().g; m->param.arch_glass.refrct.b = agm->GetKrefrct().b; m->param.arch_glass.trans_filter = agm->GetTransFilter(); m->param.arch_glass.tot_filter = agm->GetTotFilter(); m->param.arch_glass.refl_pdf = agm->GetReflPdf(); m->param.arch_glass.trans_pdf = agm->GetTransPdf(); break; } default: /* MATTE */ { compiled_materials[ppm::MAT_MATTE] = true; m->type = ppm::MAT_MATTE; m->param.matte.kd.r = 0.75f; m->param.matte.kd.g = 0.75f; m->param.matte.kd.b = 0.75f; break; } } } // translate mesh material indexes this->mesh_materials_count = original_scene->objectMaterials.size(); //mesh_mats.resize(mesh_coutlt); reset_array(this->mesh_materials, this->mesh_materials_count); for(uint i = 0; i < this->mesh_materials_count; ++i) { const luxrays::Material* m = original_scene->objectMaterials[i]; // look for the index uint index = 0; for(uint j = 0; j < materials_count; ++j) { if (m == original_scene->materials[j]) { index = j; break; } } this->mesh_materials[i] = index; } }