void theory_fpa::fpa2bv_converter_wrapped::mk_rm_const(func_decl * f, expr_ref & result) { SASSERT(f->get_family_id() == null_family_id); SASSERT(f->get_arity() == 0); expr * r; if (m_rm_const2bv.find(f, r)) { result = r; } else { SASSERT(is_rm(f->get_range())); expr_ref bv(m); bv = m_th.wrap(m.mk_const(f)); mk_rm(bv, result); m_rm_const2bv.insert(f, result); m.inc_ref(f); m.inc_ref(result); } }
MachineCode* CompiledCode::internalize(STATE, GCToken gct, const char** reason, int* ip) { MachineCode* mcode = machine_code_; atomic::memory_barrier(); if(mcode) return mcode; CompiledCode* self = this; OnStack<1> os(state, self); self->hard_lock(state, gct); mcode = self->machine_code_; if(!mcode) { { BytecodeVerification bv(self); if(!bv.verify(state)) { if(reason) *reason = bv.failure_reason(); if(ip) *ip = bv.failure_ip(); std::cerr << "Error validating bytecode: " << bv.failure_reason() << "\n"; return 0; } } mcode = new MachineCode(state, self); if(self->resolve_primitive(state)) { mcode->fallback = execute; } else { mcode->setup_argument_handler(); } // We need to have an explicit memory barrier here, because we need to // be sure that mcode is completely initialized before it's set. // Otherwise another thread might see a partially initialized // MachineCode. atomic::write(&self->machine_code_, mcode); set_executor(mcode->fallback); } self->hard_unlock(state, gct); return mcode; }
virtual lbool get_consequences_core(expr_ref_vector const& asms, expr_ref_vector const& vars, expr_ref_vector& consequences) { datatype_util dt(m); bv_util bv(m); expr_ref_vector bvars(m), conseq(m), bounds(m); // ensure that enumeration variables that // don't occur in the constraints // are also internalized. for (unsigned i = 0; i < vars.size(); ++i) { expr_ref tmp(m.mk_eq(vars[i], vars[i]), m); proof_ref proof(m); m_rewriter(tmp, tmp, proof); } m_rewriter.flush_side_constraints(bounds); m_solver->assert_expr(bounds); // translate enumeration constants to bit-vectors. for (unsigned i = 0; i < vars.size(); ++i) { func_decl* f; if (is_app(vars[i]) && is_uninterp_const(vars[i]) && m_rewriter.enum2bv().find(to_app(vars[i])->get_decl(), f)) { bvars.push_back(m.mk_const(f)); } else { bvars.push_back(vars[i]); } } lbool r = m_solver->get_consequences(asms, bvars, consequences); // translate bit-vector consequences back to enumeration types for (unsigned i = 0; i < consequences.size(); ++i) { expr* a, *b, *u, *v; func_decl* f; rational num; unsigned bvsize; VERIFY(m.is_implies(consequences[i].get(), a, b)); if (m.is_eq(b, u, v) && is_uninterp_const(u) && m_rewriter.bv2enum().find(to_app(u)->get_decl(), f) && bv.is_numeral(v, num, bvsize)) { SASSERT(num.is_unsigned()); expr_ref head(m); ptr_vector<func_decl> const& enums = *dt.get_datatype_constructors(f->get_range()); head = m.mk_eq(m.mk_const(f), m.mk_const(enums[num.get_unsigned()])); consequences[i] = m.mk_implies(a, head); } } return r; }
VMMethod* CompiledMethod::internalize(STATE, GCToken gct, const char** reason, int* ip) { VMMethod* vmm = backend_method_; atomic::memory_barrier(); if(vmm) return vmm; CompiledMethod* self = this; OnStack<1> os(state, self); self->hard_lock(state, gct); vmm = self->backend_method_; if(!vmm) { { BytecodeVerification bv(self); if(!bv.verify(state)) { if(reason) *reason = bv.failure_reason(); if(ip) *ip = bv.failure_ip(); std::cerr << "Error validating bytecode: " << bv.failure_reason() << "\n"; return 0; } } vmm = new VMMethod(state, self); if(self->resolve_primitive(state)) { vmm->fallback = execute; } else { vmm->setup_argument_handler(self); } // We need to have an explicit memory barrier here, because we need to // be sure that vmm is completely initialized before it's set. // Otherwise another thread might see a partially initialized // VMMethod. atomic::memory_barrier(); backend_method_ = vmm; } self->hard_unlock(state, gct); return vmm; }
void H264VideoStreamParser ::analyze_slice_header(u_int8_t* start, u_int8_t* end, u_int8_t nal_unit_type, unsigned &frame_num, unsigned &pic_parameter_set_id, unsigned& idr_pic_id, Boolean& field_pic_flag, Boolean& bottom_field_flag) { BitVector bv(start, 0, 8*(end-start)); // Some of the result parameters might not be present in the header; set them to default values: field_pic_flag = bottom_field_flag = 0; // Note: We assume that there aren't any 'emulation prevention' bytes here to worry about... bv.skipBits(8); // forbidden_zero_bit; nal_ref_idc; nal_unit_type unsigned first_mb_in_slice = bv.get_expGolomb(); DEBUG_PRINT(first_mb_in_slice); unsigned slice_type = bv.get_expGolomb(); DEBUG_PRINT(slice_type); pic_parameter_set_id = bv.get_expGolomb(); DEBUG_PRINT(pic_parameter_set_id); if (separate_colour_plane_flag) { bv.skipBits(2); // colour_plane_id } frame_num = bv.getBits(log2_max_frame_num); DEBUG_PRINT(frame_num); if (!frame_mbs_only_flag) { DEBUG_TAB; field_pic_flag = bv.get1BitBoolean(); DEBUG_PRINT(field_pic_flag); if (field_pic_flag) { DEBUG_TAB; bottom_field_flag = bv.get1BitBoolean(); DEBUG_PRINT(bottom_field_flag); } } Boolean IdrPicFlag = nal_unit_type == 5; if (IdrPicFlag) { DEBUG_TAB; idr_pic_id = bv.get_expGolomb(); DEBUG_PRINT(idr_pic_id); } // We don't parse any more of the "slice_header", because we don't need the remaining fields (for our purpose) }
/** * \fn void comp_bpoly_matrix( double**& a , double* param_pts , unsigned np ) const * * \brief Computes the pairwise product of all Bernstein polynomials * of two degrees at a given set of parameters points. The two * degrees are the the first and second index of the bi-degree of * this patch. * * \param a A (np x (( m + 1) * ( n + 1)) matrix such that ( m , n ) * is the bi-degree of this patch and each element of the matrix is * a product of two Bernstein polynomials at a given parameter * point. * \param patch_pts An array of 2D coordinates of parameter points. * \param np The number of parameter points. */ void tBezier::comp_bpoly_matrix( double**& a , double* param_pts , unsigned np ) const { /** * Compute the value of the Bernstein polynomials at the parameter * points. */ double rx = get_aff_1st_point_x_coord() ; double ry = get_aff_1st_point_y_coord() ; double sx = get_aff_2nd_point_x_coord() ; double sy = get_aff_2nd_point_y_coord() ; for ( unsigned i = 0 ; i < np ; i++ ) { double x = ( param_pts[ ( i << 1 ) ] - rx ) / ( sx - rx ) ; double y = ( param_pts[ ( i << 1 ) + 1 ] - ry ) / ( sy - ry ) ; unsigned m = get_bidegree_1st_index() ; unsigned n = get_bidegree_2nd_index() ; std::vector< double > bu( m + 1 ) ; std::vector< double > bv( n + 1 ) ; all_bernstein( m , x , bu ) ; all_bernstein( n , y , bv ) ; for ( unsigned k = 0 ; k <= n ; ++k ) { for ( unsigned j = 0 ; j <= m ; ++j ) { unsigned l = index( k , j ) ; a[ i ][ l ] = bu[ j ] * bv[ k ] ; } } } return ; }
bool is_value_sort(ast_manager& m, sort* s) { arith_util arith(m); datatype_util data(m); bv_util bv(m); ptr_vector<sort> sorts; ast_mark mark; sorts.push_back(s); while (!sorts.empty()) { s = sorts.back(); sorts.pop_back(); if (mark.is_marked(s)) { continue; } mark.mark(s, true); if (arith.is_int_real(s)) { // simple } else if (m.is_bool(s)) { // simple } else if (bv.is_bv_sort(s)) { // simple } else if (data.is_datatype(s)) { ptr_vector<func_decl> const& cs = *data.get_datatype_constructors(s); for (unsigned i = 0; i < cs.size(); ++i) { func_decl* f = cs[i]; for (unsigned j = 0; j < f->get_arity(); ++j) { sorts.push_back(f->get_domain(j)); } } } else { return false; } } return true; }
void CPlaneCallback::FillMeshData(Engine::Graphics::IMesh *pMesh) { // Declaration SVertexElement elems[4]; elems[0] = SVertexElement(0, ETYPE_FLOAT3, USG_POSITION, 0); elems[1] = SVertexElement(sizeof(float) * 3, ETYPE_FLOAT3, USG_NORMAL, 0); elems[2] = SVertexElement(sizeof(float) * 6, ETYPE_FLOAT2, USG_TEXCOORD, 0); elems[3] = END_DECLARATION(); pMesh->SetVertexDeclaration(elems); pMesh->setPrimitiveType(PT_TRIANGLE_STRIP); float x = m_x * 0.5f; float y = m_y * 0.5f; // Data const int n_verts = 4; struct Vert { float data[8]; }; Vert v[] = { { -x, 0, y, 0, 1, 0, 0, 0 }, { x, 0, y, 0, 1, 0, 1, 0 }, { -x, 0, -y, 0, 1, 0, 0, 1 }, { x, 0, -y, 0, 1, 0, 1, 1 }, }; IBuffer *vb = pMesh->GetVertexBuffer(); vb->Resize(sizeof(Vert) * n_verts); void *pData; vb->Lock(&pData, LOCK_DISCARD); memcpy(pData, v, sizeof(Vert) * n_verts); vb->Unlock(); // Subset IGeometry::TInterval vi(0, n_verts); IGeometry::TInterval ii(0, 0); pMesh->AddSubset(vi, ii); SBoundingVolume bv(VML::Vector3(-x, 0, -y), VML::Vector3(x, 0.001f, y)); pMesh->SetBoundingVolume(bv); }
void UpdateLevelOfDetailJob::updateEntityLodByScreenArea(Entity *entity, LevelOfDetail *lod) { QMatrix4x4 viewMatrix; QMatrix4x4 projectionMatrix; if (!Render::CameraLens::viewMatrixForCamera(m_manager->renderNodesManager(), lod->camera(), viewMatrix, projectionMatrix)) return; PickingUtils::ViewportCameraAreaGatherer vcaGatherer(lod->camera()); const QVector<PickingUtils::ViewportCameraAreaTriplet> vcaTriplets = vcaGatherer.gather(m_frameGraphRoot); if (vcaTriplets.isEmpty()) return; const PickingUtils::ViewportCameraAreaTriplet &vca = vcaTriplets.front(); const QVector<qreal> thresholds = lod->thresholds(); Sphere bv(lod->center(), lod->radius()); if (!lod->hasBoundingVolumeOverride() && entity->worldBoundingVolume() != nullptr) { bv = *(entity->worldBoundingVolume()); } else { bv.transform(*entity->worldTransform()); } bv.transform(projectionMatrix * viewMatrix); const float sideLength = bv.radius() * 2.f; float area = vca.viewport.width() * sideLength * vca.viewport.height() * sideLength; const QRect r = windowViewport(vca.area, vca.viewport); area = std::sqrt(area * r.width() * r.height()); const int n = thresholds.size(); for (int i = 0; i < n; ++i) { if (thresholds[i] < area || i == n -1) { m_filterValue = approxRollingAverage<30>(m_filterValue, i); i = qBound(0, static_cast<int>(qRound(m_filterValue)), n - 1); if (lod->currentIndex() != i) lod->setCurrentIndex(i); break; } } }
void moto_setVarVal(MotoEnv *env, MotoVar *var, MotoVal *val) { moto_castVal(env,var->vs,val); /* If the MotoVar is a member var then we need to set the var in the MCI which this var is a member of */ if(var->isMemberVar) { switch (var->type->kind) { case INT32_TYPE: *(int32_t*)var->address = iv(var->vs); break; case INT64_TYPE: *(int64_t*)var->address = lv(var->vs); break; case FLOAT_TYPE: *(float*)var->address = fv(var->vs); break; case DOUBLE_TYPE: *(double*)var->address = dv(var->vs); break; case BOOLEAN_TYPE: *(unsigned char*)var->address = bv(var->vs); break; case BYTE_TYPE: *(signed char*)var->address = yv(var->vs); break; case CHAR_TYPE: *(char*)var->address = cv(var->vs); break; case REF_TYPE: *(void**)var->address = var->vs->refval.value; break; default: break; } } }
Node PicklerPrivate::fromCaseConstant(Kind k, uint32_t constblocks) { switch(k) { case kind::CONST_BOOLEAN: { Assert(constblocks == 1); Block val = d_current.dequeue(); bool b= val.d_body.d_data; return d_nm->mkConst<bool>(b); } case kind::CONST_RATIONAL: { std::string s = fromCaseString(constblocks); Rational q(s, 16); return d_nm->mkConst<Rational>(q); } case kind::BITVECTOR_EXTRACT_OP: { Block high = d_current.dequeue(); Block low = d_current.dequeue(); BitVectorExtract bve(high.d_body.d_data, low.d_body.d_data); return d_nm->mkConst<BitVectorExtract>(bve); } case kind::CONST_BITVECTOR: { unsigned size = d_current.dequeue().d_body.d_data; Block header CVC4_UNUSED = d_current.dequeue(); Assert(header.d_headerConstant.d_kind == kind::CONST_BITVECTOR); Assert(header.d_headerConstant.d_constblocks == constblocks - 2); Integer value(fromCaseString(constblocks - 2)); BitVector bv(size, value); return d_nm->mkConst(bv); } case kind::BITVECTOR_SIGN_EXTEND_OP: { Block signExtendAmount = d_current.dequeue(); BitVectorSignExtend bvse(signExtendAmount.d_body.d_data); return d_nm->mkConst<BitVectorSignExtend>(bvse); } default: Unhandled(k); } }
void tst_expr_substitution() { memory::initialize(0); ast_manager m; reg_decl_plugins(m); bv_util bv(m); expr_ref a(m), b(m), c(m), d(m); expr_ref x(m); expr_ref new_a(m); proof_ref pr(m); x = m.mk_const(symbol("x"), bv.mk_sort(8)); a = mk_bv_and(bv, mk_bv_xor(bv, x,bv.mk_numeral(8,8)), mk_bv_xor(bv,x,x)); b = x; c = bv.mk_bv_sub(x, bv.mk_numeral(4, 8)); expr_substitution subst(m); th_rewriter rw(m); std::cout << mk_pp(c, m) << "\n"; // normalizing c does not help. rw(c, d, pr); std::cout << mk_pp(d, m) << "\n"; // This portion diverges. It attempts to replace x by (bvadd #xfc x), which contains x. // subst.insert(b, d); // std::cout << mk_pp(a, m) << "\n"; // rw.set_substitution(&subst); // enable_trace("th_rewriter_step"); // rw(a, new_a, pr); // std::cout << mk_pp(new_a, m) << "\n"; }
static void test1() { ast_manager m; reg_decl_plugins(m); bv_util bv(m); params_ref p; ref<solver> solver = mk_inc_sat_solver(m, p); expr_ref a = mk_bool(m, "a"), b = mk_bool(m, "b"), c = mk_bool(m, "c"); expr_ref ba = mk_bv(m, "ba", 3), bb = mk_bv(m, "bb", 3), bc = mk_bv(m, "bc", 3); solver->assert_expr(m.mk_implies(a, b)); solver->assert_expr(m.mk_implies(b, c)); expr_ref_vector asms(m), vars(m), conseq(m); asms.push_back(a); vars.push_back(b); vars.push_back(c); vars.push_back(bb); vars.push_back(bc); solver->assert_expr(m.mk_eq(ba, bc)); solver->assert_expr(m.mk_eq(bv.mk_numeral(2, 3), ba)); solver->get_consequences(asms, vars, conseq); std::cout << conseq << "\n"; }
void MulVsDiv::CsabaDynamicArrayLoop() { const int length = 256;//1024 *1024* 8; const int loops = 1e6;//1e3 / 2; std::cout << "Csaba loop:\n---" << std::endl; std::vector<double> av(length), bv(length); double *a = &av.front(), *b = &bv.front(); auto ignoreit = 0.0; ResetArrays(length, a, b, ignoreit); auto idx1 = (rand() % static_cast<int>(length)), idx2 = (rand() % static_cast<int>(length-1)); auto start = clock(); for (size_t l = 0; l < loops; l++) { // MSVC cannot vectorize this loop (message 1300). // However, if this loop will not be nested in, autovectorization will happen. // Same condition apply for mul/div/rcp loops // ICL does not have this issue, but to provide both vectorized and nonvectorized comparison // i specifically disabled vectorization in this method #pragma novector #pragma loop( no_vector ) for (int i = 1; i < length-1; ++i) { a[i] = b[idx1] + b[idx2]; } } auto add_time = clock() - start; std::cout << "Addition: " << add_time << std::endl; ignoreit += a[(rand() % static_cast<int>(length))] + b[(rand() % static_cast<int>(length))]; idx1 = (rand() % static_cast<int>(length)), idx2 = (rand() % static_cast<int>(length)); start = clock(); for (size_t l = 0; l < loops; l++) { #pragma novector #pragma loop( no_vector ) for (int i = 0; i < length-1; ++i) { a[i] =b[idx1] * b[idx2]; } } auto mul_time = clock() - start; std::cout << "Multiplication: " << mul_time << std::endl; ignoreit += a[(rand() % static_cast<int>(length))] + b[(rand() % static_cast<int>(length))]; idx1 = (rand() % static_cast<int>(length)), idx2 = (rand() % static_cast<int>(length)); start = clock(); for (size_t l = 0; l < loops; l++) { #pragma novector #pragma loop( no_vector ) for (int i = 0; i < length; ++i) { a[i] = b[idx1] / b[idx2]; } } auto div_time = clock() - start; ignoreit += a[(rand() % static_cast<int>(length))] + b[(rand() % static_cast<int>(length))]; std::cout << "Division: " << div_time << std::endl; std::cout << "Addition faster than multiplication: " << static_cast<double>(mul_time) / static_cast<double>(add_time) << std::endl; std::cout << "Multiplication faster than division: " << static_cast<double>(div_time) / static_cast<double>(mul_time) << std::endl; std::cout << "Just ignore it: " << ignoreit << std::endl << std::endl; }
void MulVsDiv::DependendDynamicArrayLoop() { const int length = 256; const int loops = 1e6; std::cout << "Dependend Dynamic loop:\n---" << std::endl; std::vector<double> av(length), bv(length); double *a = &av.front(), *b = &bv.front(); std::vector<long> add_times; std::vector<long> mul_times; std::vector<long> div_times; add_times.reserve(loops); mul_times.reserve(loops); div_times.reserve(loops); unsigned long long ignoreit[]{0,0,0}; for (size_t i = 0; i < length; i++) { av[i] = 8 * (static_cast<double>(rand()) / (RAND_MAX)) + 1; //bv[i] = DBL_MIN; } //Division for (size_t i = 0; i < loops; i++) { auto start = clock(); for (size_t j = 0; j < length-1; j++) { b[j] = a[j + 1] / a[j]; } auto finish = clock(); div_times.push_back(finish-start); ignoreit[0] += std::accumulate(bv.begin(), bv.end(), 0); } auto div_time = std::accumulate(div_times.begin(), div_times.end(), 0) / loops; std::cout << "Division:\t\t" << div_time << std::endl; //Multiplication for (size_t i = 0; i < loops; i++) { auto start = clock(); for (size_t j = 0; j < length - 1; j++) { b[j] = a[j + 1] * a[j]; } auto finish = clock(); mul_times.push_back(finish - start); ignoreit[1] += std::accumulate(bv.begin(),bv.end(), 0); } auto mul_time = std::accumulate(mul_times.begin(), mul_times.end(), 0) / loops; std::cout << "Multiplication:\t\t" << mul_time << std::endl; //Addition for (size_t i = 0; i < loops; i++) { auto start = clock(); for (size_t j = 0; j < length - 1; j++) { b[j] = a[j + 1] + a[j]; } auto finish = clock(); add_times.push_back(finish - start); ignoreit[2] += std::accumulate(bv.begin(), bv.end(), 0); } auto add_time = std::accumulate(add_times.begin(), add_times.end(), 0) / loops; std::cout << "Addition:\t\t" << add_time << std::endl; std::cout << "Addition faster than multiplication:\t" << static_cast<double>(mul_time) / static_cast<double>(add_time) << std::endl; std::cout << "Multiplication faster than division:\t" << static_cast<double>(div_time) / static_cast<double>(mul_time) << std::endl; std::cout << "Just ignore it: " << ignoreit[0]<< ignoreit[1]<< ignoreit[2] << std::endl << std::endl; }
void h(long *m, long *p) { long cb = *p; bv(m, &cb); }
void MulVsDiv::DynamicArrayLoopVectorized() { const int length = 256; const int loops = 1e6; std::cout << "Vectorized dynamic array loop:\n---" << std::endl; std::vector<double> av(length), bv(length), cv(length); double *a = &av.front(), *b = &bv.front(), *c = &bv.front(); auto ignoreit = 0.0; ResetArrays(length, a, b, ignoreit); int l = 0; auto start = clock(); add: for (int i = 0; i < length; i++) { c[i] = a[i] + b[i]; } // MSVC doesn't vectorize nested loops (message 1300 - too little computation to vectorize) in function 'DynamicArrayLoop'. // However if nested loop is replaced with this nasty workaround SIMD vectorization will happen. // Same condition apply for mul/div/rcp loops while (l < loops) { ++l; goto add; } auto add_time = clock() - start; std::cout << "Addition: " << add_time << std::endl; ResetArrays(length, a, b, ignoreit); ignoreit /= c[(rand() % (int)(length))]; l = 0; start = clock(); mul: for (int i = 0; i < length; ++i) { c[i] = a[i] * b[i]; } while (l < loops) { ++l; goto mul; } auto mul_time = clock() - start; std::cout << "Multiplication: " << mul_time << std::endl; ResetArrays(length, a, b, ignoreit); ignoreit /= c[(rand() % (int)(length))]; l = 0; start = clock(); div: for (int i = 0; i < length; ++i) { c[i] = a[i] / b[i]; } while (l < loops) { ++l; goto div; } auto div_time = clock() - start; ignoreit /= c[(rand() % (int)(length))]; ignoreit += a[(rand() % (int)(length))] + b[(rand() % (int)(length))]; std::cout << "Division: " << div_time << std::endl; std::cout << "Addition faster than multiplication: " << static_cast<double>(mul_time) / static_cast<double>(add_time) << std::endl; std::cout << "Multiplication faster than division: " << static_cast<double>(div_time) / static_cast<double>(mul_time) << std::endl; std::cout << "Just ignore it: " << ignoreit << std::endl << std::endl; }
void bv_elim::elim(quantifier* q, quantifier_ref& r) { svector<symbol> names, _names; sort_ref_buffer sorts(m_manager), _sorts(m_manager); expr_ref_buffer pats(m_manager); expr_ref_buffer no_pats(m_manager); expr_ref_buffer subst_map(m_manager), _subst_map(m_manager); var_subst subst(m_manager); bv_util bv(m_manager); expr_ref new_body(m_manager); expr* old_body = q->get_expr(); unsigned num_decls = q->get_num_decls(); family_id bfid = m_manager.get_family_id("bv"); // // Traverse sequence of bound variables to eliminate // bit-vecctor variables and replace them by // Booleans. // unsigned var_idx = 0; for (unsigned i = num_decls; i > 0; ) { --i; sort* s = q->get_decl_sort(i); symbol nm = q->get_decl_name(i); if (bv.is_bv_sort(s)) { // convert n-bit bit-vector variable into sequence of n-Booleans. unsigned num_bits = bv.get_bv_size(s); expr_ref_buffer args(m_manager); expr_ref bv(m_manager); for (unsigned j = 0; j < num_bits; ++j) { std::ostringstream new_name; new_name << nm.str(); new_name << "_"; new_name << j; var* v = m_manager.mk_var(var_idx++, m_manager.mk_bool_sort()); args.push_back(v); _sorts.push_back(m_manager.mk_bool_sort()); _names.push_back(symbol(new_name.str().c_str())); } bv = m_manager.mk_app(bfid, OP_MKBV, 0, 0, args.size(), args.c_ptr()); _subst_map.push_back(bv.get()); } else { _subst_map.push_back(m_manager.mk_var(var_idx++, s)); _sorts.push_back(s); _names.push_back(nm); } } // // reverse the vectors. // SASSERT(_names.size() == _sorts.size()); for (unsigned i = _names.size(); i > 0; ) { --i; names.push_back(_names[i]); sorts.push_back(_sorts[i]); } for (unsigned i = _subst_map.size(); i > 0; ) { --i; subst_map.push_back(_subst_map[i]); } expr* const* sub = subst_map.c_ptr(); unsigned sub_size = subst_map.size(); subst(old_body, sub_size, sub, new_body); for (unsigned j = 0; j < q->get_num_patterns(); j++) { expr_ref pat(m_manager); subst(q->get_pattern(j), sub_size, sub, pat); pats.push_back(pat); } for (unsigned j = 0; j < q->get_num_no_patterns(); j++) { expr_ref nopat(m_manager); subst(q->get_no_pattern(j), sub_size, sub, nopat); no_pats.push_back(nopat); } r = m_manager.mk_quantifier(true, names.size(), sorts.c_ptr(), names.c_ptr(), new_body.get(), q->get_weight(), q->get_qid(), q->get_skid(), pats.size(), pats.c_ptr(), no_pats.size(), no_pats.c_ptr()); }
ExecStatus LinkMulti::propagate(Space& home, const ModEventDelta& med) { int n = x.size(); // Always maintain the invariant that y lies inside the x-array assert((y.min()-o >= 0) && (y.max()-o < n)); if (y.assigned()) { status = S_RUN; int j=y.val()-o; GECODE_ME_CHECK(x[j].one(home)); for (int i=0; i<j; i++) GECODE_ME_CHECK(x[i].zero(home)); for (int i=j+1; i<n; i++) GECODE_ME_CHECK(x[i].zero(home)); return home.ES_SUBSUMED(*this); } // Check whether there is a one if (status == S_ONE) { status = S_RUN; for (int i=0; true; i++) if (x[i].one()) { for (int j=0; j<i; j++) GECODE_ME_CHECK(x[j].zero(home)); for (int j=i+1; j<n; j++) GECODE_ME_CHECK(x[j].zero(home)); GECODE_ME_CHECK(y.eq(home,i+o)); return home.ES_SUBSUMED(*this); } GECODE_NEVER; } status = S_RUN; redo: // Assign all Boolean views to zero that are outside bounds { int min=y.min()-o; for (int i=0; i<min; i++) GECODE_ME_CHECK(x[i].zero(home)); x.drop_fst(min); o += min; n = x.size(); int max=y.max()-o; for (int i=max+1; i<n; i++) GECODE_ME_CHECK(x[i].zero(home)); x.drop_lst(max); n = x.size(); } { // Remove zeros on the left int i=0; while ((i < n) && x[i].zero()) i++; if (i >= n) return ES_FAILED; x.drop_fst(i); o += i; n = x.size(); } { // Remove zeros on the right int i=n-1; while ((i >= 0) && x[i].zero()) i--; assert(i >= 0); x.drop_lst(i); n = x.size(); } assert(n >= 1); // Is there only one left? if (n == 1) { GECODE_ME_CHECK(x[0].one(home)); GECODE_ME_CHECK(y.eq(home,o)); return home.ES_SUBSUMED(*this); } // Update bounds GECODE_ME_CHECK(y.gq(home,o)); GECODE_ME_CHECK(y.lq(home,o+n-1)); if ((y.min() > o) || (y.max() < o+n-1)) goto redo; assert((n >= 2) && x[0].none() && x[n-1].none()); assert((y.min()-o == 0) && (y.max()-o == n-1)); // Propagate from y to Boolean views if ((IntView::me(med) == ME_INT_BND) || (IntView::me(med) == ME_INT_DOM)) { ViewValues<IntView> v(y); int i=0; do { int j = v.val()-o; if (i < j) { GECODE_ME_CHECK(x[i].zero(home)); ++i; } else if (i > j) { ++v; } else { assert(i == j); ++i; ++v; } } while (v() && (i < n)); } // Propagate from Boolean views to y if (BoolView::me(med) == ME_BOOL_VAL) { BoolIter bv(x,o); GECODE_ME_CHECK(y.minus_v(home,bv,false)); } status = S_NONE; return ES_FIX; }
void MP3HuffmanDecode(MP3SideInfo::gr_info_s_t* gr, Boolean isMPEG2, unsigned char const* fromBasePtr, unsigned fromBitOffset, unsigned fromLength, unsigned& scaleFactorsLength, MP3HuffmanEncodingInfo& hei) { unsigned i; int x, y, v, w; struct huffcodetab *h; BitVector bv((unsigned char*)fromBasePtr, fromBitOffset, fromLength); /* Compute the size of the scale factors (& also advance bv): */ scaleFactorsLength = getScaleFactorsLength(gr, isMPEG2); bv.skipBits(scaleFactorsLength); initialize_huffman(); hei.reg1Start = hei.reg2Start = hei.numSamples = 0; /* Read bigvalues area. */ if (gr->big_values < gr->region1start + gr->region2start) { gr->big_values = gr->region1start + gr->region2start; /* sanity check */ } for (i = 0; i < gr->big_values; ++i) { if (i < gr->region1start) { /* in region 0 */ h = &rsf_ht[gr->table_select[0]]; } else if (i < gr->region2start) { /* in region 1 */ h = &rsf_ht[gr->table_select[1]]; if (hei.reg1Start == 0) { hei.reg1Start = bv.curBitIndex(); } } else { /* in region 2 */ h = &rsf_ht[gr->table_select[2]]; if (hei.reg2Start == 0) { hei.reg2Start = bv.curBitIndex(); } } hei.allBitOffsets[i] = bv.curBitIndex(); rsf_huffman_decoder(bv, h, &x, &y, &v, &w); if (hei.decodedValues != NULL) { // Record the decoded values: unsigned* ptr = &hei.decodedValues[4*i]; ptr[0] = x; ptr[1] = y; ptr[2] = v; ptr[3] = w; } } hei.bigvalStart = bv.curBitIndex(); /* Read count1 area. */ h = &rsf_ht[gr->count1table_select+32]; while (bv.curBitIndex() < bv.totNumBits() && i < SSLIMIT*SBLIMIT) { hei.allBitOffsets[i] = bv.curBitIndex(); rsf_huffman_decoder(bv, h, &x, &y, &v, &w); if (hei.decodedValues != NULL) { // Record the decoded values: unsigned* ptr = &hei.decodedValues[4*i]; ptr[0] = x; ptr[1] = y; ptr[2] = v; ptr[3] = w; } ++i; } hei.allBitOffsets[i] = bv.curBitIndex(); hei.numSamples = i; }
static expr_ref mk_bv(ast_manager& m, char const* name, unsigned sz) { bv_util bv(m); return expr_ref(m.mk_const(symbol(name), bv.mk_sort(sz)), m); }
/** Return a bit vector of the results of Exclusive-or-ing each bit in \p bv1 with the corresponding bit in \p bv2 \param[in] bv1 A bit vector \param[in] bv2 Another bit vector \return A bit vector */ OBBitVec operator^ (const OBBitVec & bv1, const OBBitVec & bv2) { OBBitVec bv(bv1); bv ^= bv2; return(bv); }
void CBoxCallback::FillMeshData(Engine::Graphics::IMesh *pMesh) { // Declaration SVertexElement elems[4]; elems[0] = SVertexElement(0, ETYPE_FLOAT3, USG_POSITION, 0); elems[1] = SVertexElement(sizeof(float) * 3, ETYPE_FLOAT3, USG_NORMAL, 0); elems[2] = SVertexElement(sizeof(float) * 6, ETYPE_FLOAT2, USG_TEXCOORD, 0); elems[3] = END_DECLARATION(); pMesh->SetVertexDeclaration(elems); pMesh->setPrimitiveType(PT_INDEXED_TRIANGLE_LIST); // Data const int n_verts = 36; struct Vert { float data[8]; }; Vert v[] = { { mA[0], mB[1], mA[2], 0, 1, 0 , 0, 1 }, { mA[0], mB[1], mB[2], 0, 1, 0 , 0, 0 }, { mB[0], mB[1], mB[2], 0, 1, 0 , 1, 0 }, { mB[0], mB[1], mB[2], 0, 1, 0 , 1, 0 }, { mB[0], mB[1], mA[2], 0, 1, 0 , 1, 1 }, { mA[0], mB[1], mA[2], 0, 1, 0 , 0, 1 }, { mA[0], mA[1], mA[2], 0, 0, -1 , 0, 1 }, { mA[0], mB[1], mA[2], 0, 0, -1 , 0, 0 }, { mB[0], mB[1], mA[2], 0, 0, -1 , 1, 0 }, { mB[0], mB[1], mA[2], 0, 0, -1 , 1, 0 }, { mB[0], mA[1], mA[2], 0, 0, -1 , 1, 1 }, { mA[0], mA[1], mA[2], 0, 0, -1 , 0, 1 }, { mA[0], mA[1], mB[2], -1, 0, 0 , 0, 1 }, { mA[0], mB[1], mB[2], -1, 0, 0 , 0, 0 }, { mA[0], mB[1], mA[2], -1, 0, 0 , 1, 0 }, { mA[0], mB[1], mA[2], -1, 0, 0 , 1, 0 }, { mA[0], mA[1], mA[2], -1, 0, 0 , 1, 1 }, { mA[0], mA[1], mB[2], -1, 0, 0 , 0, 1 }, { mA[0], mB[1], mB[2], 0, 0, 1 , 1, 0 }, { mA[0], mA[1], mB[2], 0, 0, 1 , 1, 1 }, { mB[0], mA[1], mB[2], 0, 0, 1 , 0, 1 }, { mB[0], mA[1], mB[2], 0, 0, 1 , 0, 1 }, { mB[0], mB[1], mB[2], 0, 0, 1 , 0, 0 }, { mA[0], mB[1], mB[2], 0, 0, 1 , 1, 0 }, { mB[0], mA[1], mA[2], 1, 0, 0 , 0, 1 }, { mB[0], mB[1], mA[2], 1, 0, 0 , 0, 0 }, { mB[0], mB[1], mB[2], 1, 0, 0 , 1, 0 }, { mB[0], mB[1], mB[2], 1, 0, 0 , 1, 0 }, { mB[0], mA[1], mB[2], 1, 0, 0 , 1, 1 }, { mB[0], mA[1], mA[2], 1, 0, 0 , 0, 1 }, { mA[0], mA[1], mB[2], 0, -1, 0 , 0, 1 }, { mA[0], mA[1], mA[2], 0, -1, 0 , 0, 0 }, { mB[0], mA[1], mA[2], 0, -1, 0 , 1, 0 }, { mB[0], mA[1], mA[2], 0, -1, 0 , 1, 0 }, { mB[0], mA[1], mB[2], 0, -1, 0 , 1, 1 }, { mA[0], mA[1], mB[2], 0, -1, 0 , 0, 1 }, }; int i[] = { 0,1,2, 3,4,5, 6,7,8, 9,10,11, 12,13,14, 15,16,17, 18,19,20, 21,22,23, 24,25,26, 27,28,29, 30,31,32, 33,34,35, }; IBuffer *vb = pMesh->GetVertexBuffer(); vb->Resize(sizeof(Vert) * n_verts); void *pData; vb->Lock(&pData, LOCK_DISCARD); memcpy(pData, v, sizeof(Vert) * n_verts); vb->Unlock(); IBuffer *ib = pMesh->GetIndexBuffer(); ib->Resize(sizeof(int) * n_verts); ib->Lock(&pData, LOCK_DISCARD); memcpy(pData, i, sizeof(int) * n_verts); ib->Unlock(); // Subset IGeometry::TInterval vi(0, n_verts); IGeometry::TInterval ii(0, n_verts); pMesh->AddSubset(vi, ii); VML::Vector3 vmin(mA[0], mA[1], mA[2]); VML::Vector3 vmax(mB[0], mB[1], mB[2]); SBoundingVolume bv(vmin, vmax); pMesh->SetBoundingVolume(bv); }
void CSphereCallback::FillMeshData(Engine::Graphics::IMesh *pMesh) { // Declaration SVertexElement elems[4]; elems[0] = SVertexElement(0, ETYPE_FLOAT3, USG_POSITION, 0); elems[1] = SVertexElement(sizeof(float) * 3, ETYPE_FLOAT3, USG_NORMAL, 0); elems[2] = SVertexElement(sizeof(float) * 6, ETYPE_FLOAT2, USG_TEXCOORD, 0); elems[3] = END_DECLARATION(); pMesh->SetVertexDeclaration(elems); pMesh->setPrimitiveType(PT_INDEXED_TRIANGLE_LIST); // Data const int n_verts = (mRings + 1) * (mSegments + 1); const int n_indcs = 6 * mRings * (mSegments + 1); void *vertices, *indices; IBuffer* vb = pMesh->GetVertexBuffer(); IBuffer* ib = pMesh->GetIndexBuffer(); vb->Resize(n_verts * sizeof(float) * 8); ib->Resize(n_indcs * sizeof(int)); vb->Lock(&vertices, LOCK_DISCARD); ib->Lock(&indices, LOCK_DISCARD); const float PI = 3.1415926f; float fDeltaRingAngle = (PI / mRings); float fDeltaSegAngle = (2.0f * PI / mSegments); unsigned short wVerticeIndex = 0 ; float* pVertex = (float*)vertices; int* pIndices = (int*)indices; // Generate the group of rings for the sphere for(int ring = 0; ring <= mRings; ring++) { float r0 = mRadius * sinf (ring * fDeltaRingAngle); float y0 = mRadius * cosf (ring * fDeltaRingAngle); // Generate the group of segments for the current ring for(int seg = 0; seg <= mSegments; seg++) { float x0 = r0 * sinf(seg * fDeltaSegAngle); float z0 = r0 * cosf(seg * fDeltaSegAngle); // Position *pVertex++ = x0; *pVertex++ = y0; *pVertex++ = z0; // Normal VML::Vector3 vNormal(x0, y0, z0); vNormal.normalize(); *pVertex++ = vNormal.getX(); *pVertex++ = vNormal.getY(); *pVertex++ = vNormal.getZ(); // Texture coordinates *pVertex++ = 1.0f - (float) seg / (float) mSegments; *pVertex++ = (float) ring / (float) mRings; if (ring != mRings) { // each vertex (except the last) has six indices pointing to it *pIndices++ = wVerticeIndex + mSegments + 1; *pIndices++ = wVerticeIndex; *pIndices++ = wVerticeIndex + mSegments; *pIndices++ = wVerticeIndex + mSegments + 1; *pIndices++ = wVerticeIndex + 1; *pIndices++ = wVerticeIndex; wVerticeIndex ++; } } // end for seg } // end for ring vb->Unlock(); ib->Unlock(); // Subset IGeometry::TInterval vi(0, n_verts); IGeometry::TInterval ii(0, n_indcs); pMesh->AddSubset(vi, ii); SBoundingVolume bv(VML::Vector3(0), mRadius); pMesh->SetBoundingVolume(bv); }
void SoCapsule::build ( float len, float rt, float rb, int nfaces ) { P.clear(); C.clear(); // set size to zero, just in case float hlen = len/2.0f; int levels = std::ceil(static_cast<float>(nfaces) / 2.0f); float faceAngularHeight = (static_cast<float>(M_PI) / 2.0) / static_cast<float>(levels); float faceAngularLength = (2.0 * static_cast<float>(M_PI)) / static_cast<float>(nfaces); int vertices = 2 + (2*levels + 1)*(nfaces * 6); // Reserve space for the capsule vertices P.reserve(vertices); C.reserve(vertices); // Generate the coordinates for the capsule body std::vector<GsVec> bodyTopCoordinates; std::vector<GsVec> bodyBottomCoordinates; bodyTopCoordinates.reserve(nfaces); bodyBottomCoordinates.reserve(nfaces); // Compute the tube section of the capsule for(int i = 0; i < nfaces; i++) { float p = static_cast<float>(i) * faceAngularLength; bodyTopCoordinates.push_back(GsVec(rt * std::cos(p), hlen, rt * std::sin(p))); bodyBottomCoordinates.push_back(GsVec(rb * std::cos(p), -hlen, rb * std::sin(p))); } pushLevel(P, C, bodyTopCoordinates, bodyBottomCoordinates, nfaces); // Compute the top of the capsule std::vector<GsVec>& previousTopVector = bodyTopCoordinates; std::vector<GsVec> currentTopVector; currentTopVector.reserve(nfaces); for(int j = 1; j < levels; j++) { // theta coordinate float t = static_cast<float>(j) * faceAngularHeight; for(int i = 0; i < nfaces; i++) { // phi coordinate float p = static_cast<float>(i) * faceAngularLength; currentTopVector.push_back(GsVec((rt * std::cos(p)) * std::cos(t), hlen + (rt * std::sin(t)), (rt * std::sin(p)) * std::cos(t))); } pushLevel(P, C, currentTopVector, previousTopVector, nfaces); std::swap(currentTopVector, previousTopVector); currentTopVector.clear(); } // Compute the cap of the capsule GsVec tv(0.0f, hlen + rt, 0.0f); for(int i = 0; i < nfaces; i++) { GsVec a = previousTopVector[i]; GsVec b = (i+1 == nfaces) ? previousTopVector[0] : previousTopVector[i+1]; pushTriangle(P, C, {a, b, tv}); } // Compute the bottom of the capsule std::vector<GsVec>& previousBottomVector = bodyBottomCoordinates; std::vector<GsVec> currentBottomVector; currentBottomVector.reserve(nfaces); for(int j = 1; j < levels; j++) { // theta coordinate float t = static_cast<float>(j) * faceAngularHeight; for(int i = 0; i < nfaces; i++) { // phi coordinate float p = static_cast<float>(i) * faceAngularLength; currentBottomVector.push_back(GsVec((rb * std::cos(p)) * std::cos(t), -hlen - (rb * std::sin(t)), (rb * std::sin(p)) * std::cos(t))); } pushLevel(P, C, currentBottomVector, previousBottomVector, nfaces); std::swap(currentBottomVector, previousBottomVector); currentBottomVector.clear(); } // Compute the cap of the capsule GsVec bv(0.0f, -hlen - rb, 0.0f); for(int i = 0; i < nfaces; i++) { GsVec a = previousBottomVector[i]; GsVec b = (i+1 == nfaces) ? previousBottomVector[0] : previousBottomVector[i+1]; pushTriangle(P, C, {a, bv, b}); } //pushCap(P, C, previousBottomVector, bv, nfaces); // send data to OpenGL buffers: glBindBuffer ( GL_ARRAY_BUFFER, buf[0] ); glBufferData ( GL_ARRAY_BUFFER, P.size()*3*sizeof(float), &P[0], GL_STATIC_DRAW ); glBindBuffer ( GL_ARRAY_BUFFER, buf[1] ); glBufferData ( GL_ARRAY_BUFFER, C.size()*4*sizeof(gsbyte), &C[0], GL_STATIC_DRAW ); // save size so that we can free our buffers and later just draw the OpenGL arrays: _numpoints = P.size(); // free non-needed memory: P.resize(0); C.resize(0); changed = 0; }
int main(void){ //PRUEBA CLASE EDGE: /* Edge arista(1,2,0.65); cout << arista.Weight() <<" "<< arista.either() <<" "<< arista.other(1) << endl; arista.toString(); MiBag bolsa; bolsa.add(arista); bolsa.iterate_Edge();*/ /* //PRUEBA CLASE WEIGHTEDGRAPH EdgeWeightedGraph mi_grafo(5); Edge arista(1,2,0.65); Edge arista1(1,3,0.64); Edge arista2(4,2,0.70); Edge arista3(1,4,0.32); Edge arista4(3,0,0.3); Edge arista5(0,2,0.1); mi_grafo.addEdge(arista); mi_grafo.addEdge(arista1); mi_grafo.addEdge(arista2); mi_grafo.addEdge(arista3); mi_grafo.addEdge(arista4); mi_grafo.addEdge(arista5); */ // INICIO DE PRUEBA LAZY PRIM MST int V,E; ifstream fin("tinyEW.txt"); //ifstream fin("1000EWG.txt"); //ifstream fin("mediumEWG.txt"); char vertex[255]; char edges[255]; fin.getline(vertex,255);//lee la primera linea fin.getline(edges,255);//lee la segunda linea string Ve(vertex); string Ed(edges); istringstream bv(Ve); istringstream be(Ed); bv>>V; be>>E; char line[255]; //MinIndexedPQ pq(E);//prueba EdgeWeightedGraph mi_grafo(V); int u,v; float w; for (int i = 0; i<E; i++){ fin.getline(line,255); string s(line); vector <string> fields; boost::algorithm::split(fields, s, boost::algorithm::is_any_of(" ")); istringstream bu(fields[0]); bu>>u; //cout<<u<<" "; istringstream bv(fields[1]); bv>>v; //cout<<v<<" "; istringstream bw(fields[2]); bw>>w; //cout<<w<<" "; //cout<<" "<<endl; Edge e(u,v,w); /*float u = e.weight(); */mi_grafo.addEdge(e); } //PRUEBA DE PRIORITY QUEUE QUE ALMACENA TODOS LOS EDGES: /*priority_queue<Edge, vector<Edge>, CompareEdges> pq = mi_grafo.priorityQueue(); while(!pq.empty()){ Edge e = pq.top(); e.toString(); pq.pop(); }*/ //PRUEBAS DE ALGORITMOS: cout<<"El MST Eager Prim:"<<endl; EagerPrimMST mst1(mi_grafo); mst1.printMST(); cout<<"El MST Lazy Prim:"<<endl; LazyPrimMST mst2(mi_grafo); mst2.printMST(); cout<<"El MST Kruskal:"<<endl; kruskalMST mst3(mi_grafo); mst3.printMST(); //cout<<"El peso total del MST es: "<<mst.weight()<<endl; return 0; }
H264StreamParser::H264StreamParser(uint8_t* sps, unsigned spsSize) : _sps(SPS_MAX_SIZE), _width(0), _height(0), _framerate(0) { spsSize = removeH264or5EmulationBytes(_sps.data(), _sps.size(), sps, spsSize); BitVector bv(_sps.data(), 0, spsSize * 8); bv.skipBits(8); // forbidden_zero_bit; nal_ref_idc; nal_unit_type unsigned profile_idc = bv.getBits(8); bv.skipBits(8); // 6 constraint_setN_flag and "reserved_zero_2bits" at the end bv.skipBits(8); // level_idc unsigned seq_parameter_set_id = bv.get_expGolomb(); unsigned chroma_format_idc = 1; Boolean separate_colour_plane_flag = False; if (profile_idc == 100 || // High profile profile_idc == 110 || // High10 profile profile_idc == 122 || // High422 profile profile_idc == 244 || // High444 Predictive profile profile_idc == 44 || // Cavlc444 profile profile_idc == 83 || // Scalable Constrained High profile (SVC) profile_idc == 86 || // Scalable High Intra profile (SVC) profile_idc == 118 || // Stereo High profile (MVC) profile_idc == 128 || // Multiview High profile (MVC) profile_idc == 138 || // Multiview Depth High profile (MVCD) profile_idc == 144) // old High444 profile { chroma_format_idc = bv.get_expGolomb(); if (chroma_format_idc == 3) separate_colour_plane_flag = bv.get1BitBoolean(); bv.get_expGolomb(); // bit_depth_luma_minus8 bv.get_expGolomb(); // bit_depth_chroma_minus8 bv.skipBits(1); // qpprime_y_zero_transform_bypass_flag Boolean seq_scaling_matrix_present_flag = bv.get1BitBoolean(); if (seq_scaling_matrix_present_flag) { for (int i = 0; i < ((chroma_format_idc != 3) ? 8 : 12); ++i) { Boolean seq_scaling_list_present_flag = bv.get1BitBoolean(); if (seq_scaling_list_present_flag) { // Decode scaling matrices unsigned sizeOfScalingList = i < 6 ? 16 : 64; unsigned lastScale = 8; unsigned nextScale = 8; for (unsigned j = 0; j < sizeOfScalingList; ++j) { if (nextScale != 0) { unsigned delta_scale = bv.get_expGolomb(); nextScale = (lastScale + delta_scale + 256) % 256; } lastScale = (nextScale == 0) ? lastScale : nextScale; } } } } } unsigned log2_max_frame_num_minus4 = bv.get_expGolomb(); unsigned pic_order_cnt_type = bv.get_expGolomb(); if (pic_order_cnt_type == 0) { bv.get_expGolomb(); // log2_max_pic_order_cnt_lsb_minus4 } else if (pic_order_cnt_type == 1) { bv.skipBits(1); // delta_pic_order_always_zero_flag bv.get_expGolomb(); // offset_for_non_ref_pic SIGNED! bv.get_expGolomb(); // offset_for_top_to_bottom_field SIGNED! unsigned num_ref_frames_in_pic_order_cnt_cycle = bv.get_expGolomb(); for (unsigned i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i) bv.get_expGolomb(); // offset_for_ref_frame[i] SIGNED! } unsigned num_ref_frames = bv.get_expGolomb(); Boolean gaps_in_frame_num_value_allowed_flag = bv.get1BitBoolean(); unsigned pic_width_in_mbs_minus1 = bv.get_expGolomb(); unsigned pic_height_in_map_units_minus1 = bv.get_expGolomb(); Boolean frame_mbs_only_flag = bv.get1BitBoolean(); if (!frame_mbs_only_flag) bv.skipBits(1); // mb_adaptive_frame_field_flag bv.skipBits(1); // direct_8x8_inference_flag Boolean frame_cropping_flag = bv.get1BitBoolean(); unsigned frame_crop_left_offset = 0, frame_crop_right_offset = 0, frame_crop_top_offset = 0, frame_crop_bottom_offset = 0; if (frame_cropping_flag) { frame_crop_left_offset = bv.get_expGolomb(); frame_crop_right_offset = bv.get_expGolomb(); frame_crop_top_offset = bv.get_expGolomb(); frame_crop_bottom_offset = bv.get_expGolomb(); } // Formula taken from MediaInfo _width = (pic_width_in_mbs_minus1 + 1) * 16; _height = (pic_height_in_map_units_minus1 + 1) * 16 * (2 - frame_mbs_only_flag); unsigned chromaArrayType = separate_colour_plane_flag ? 0 : chroma_format_idc; unsigned cropUnitX = subWidthChroma[chromaArrayType]; unsigned cropUnitY = subHeightChroma[chromaArrayType] * (2 - frame_mbs_only_flag); _width -= (frame_crop_left_offset + frame_crop_right_offset) * cropUnitX; _height -= (frame_crop_top_offset + frame_crop_bottom_offset) * cropUnitY; Boolean vui_parameters_present_flag = bv.get1BitBoolean(); if (vui_parameters_present_flag) { // Decode VUI Boolean aspect_ratio_info_present_flag = bv.get1BitBoolean(); if (aspect_ratio_info_present_flag) { unsigned aspect_ratio_idc = bv.getBits(8); if (aspect_ratio_idc == 255 /*Extended_SAR*/) bv.skipBits(32); // sar_width(16); sar_height(16) } Boolean overscan_info_present_flag = bv.get1BitBoolean(); if (overscan_info_present_flag) bv.skipBits(1); // overscan_appropriate_flag Boolean video_signal_type_present_flag = bv.get1BitBoolean(); if (video_signal_type_present_flag) { bv.skipBits(4); // video_format(3); video_full_range_flag(1) Boolean colour_description_present_flag = bv.get1BitBoolean(); if (colour_description_present_flag) bv.skipBits(24); // colour_primaries(8); transfer_characteristics(8); // matrix_coefficients(8) } Boolean chroma_loc_info_present_flag = bv.get1BitBoolean(); if (chroma_loc_info_present_flag) { bv.get_expGolomb(); // chroma_sample_loc_type_top_field bv.get_expGolomb(); // chroma_sample_loc_type_bottom_field } Boolean timing_info_present_flag = bv.get1BitBoolean(); if (timing_info_present_flag) { unsigned num_units_in_tick = bv.getBits(32); unsigned time_scale = bv.getBits(32); Boolean fixed_frame_rate_flag = bv.get1BitBoolean(); _framerate = (double)time_scale / (double)num_units_in_tick / 2.0; } } }
void H264or5VideoStreamParser ::analyze_seq_parameter_set_data(unsigned& num_units_in_tick, unsigned& time_scale) { num_units_in_tick = time_scale = 0; // default values // Begin by making a copy of the NAL unit data, removing any 'emulation prevention' bytes: u_int8_t sps[SPS_MAX_SIZE]; unsigned spsSize; removeEmulationBytes(sps, sizeof sps, spsSize); BitVector bv(sps, 0, 8*spsSize); if (fHNumber == 264) { bv.skipBits(8); // forbidden_zero_bit; nal_ref_idc; nal_unit_type unsigned profile_idc = bv.getBits(8); DEBUG_PRINT(profile_idc); unsigned constraint_setN_flag = bv.getBits(8); // also "reserved_zero_2bits" at end DEBUG_PRINT(constraint_setN_flag); unsigned level_idc = bv.getBits(8); DEBUG_PRINT(level_idc); unsigned seq_parameter_set_id = bv.get_expGolomb(); DEBUG_PRINT(seq_parameter_set_id); if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 244 || profile_idc == 44 || profile_idc == 83 || profile_idc == 86 || profile_idc == 118 || profile_idc == 128 ) { DEBUG_TAB; unsigned chroma_format_idc = bv.get_expGolomb(); DEBUG_PRINT(chroma_format_idc); if (chroma_format_idc == 3) { DEBUG_TAB; Boolean separate_colour_plane_flag = bv.get1BitBoolean(); DEBUG_PRINT(separate_colour_plane_flag); } (void)bv.get_expGolomb(); // bit_depth_luma_minus8 (void)bv.get_expGolomb(); // bit_depth_chroma_minus8 bv.skipBits(1); // qpprime_y_zero_transform_bypass_flag Boolean seq_scaling_matrix_present_flag = bv.get1BitBoolean(); DEBUG_PRINT(seq_scaling_matrix_present_flag); if (seq_scaling_matrix_present_flag) { for (int i = 0; i < ((chroma_format_idc != 3) ? 8 : 12); ++i) { DEBUG_TAB; DEBUG_PRINT(i); Boolean seq_scaling_list_present_flag = bv.get1BitBoolean(); DEBUG_PRINT(seq_scaling_list_present_flag); if (seq_scaling_list_present_flag) { DEBUG_TAB; unsigned sizeOfScalingList = i < 6 ? 16 : 64; unsigned lastScale = 8; unsigned nextScale = 8; for (unsigned j = 0; j < sizeOfScalingList; ++j) { DEBUG_TAB; DEBUG_PRINT(j); DEBUG_PRINT(nextScale); if (nextScale != 0) { DEBUG_TAB; unsigned delta_scale = bv.get_expGolomb(); DEBUG_PRINT(delta_scale); nextScale = (lastScale + delta_scale + 256) % 256; } lastScale = (nextScale == 0) ? lastScale : nextScale; DEBUG_PRINT(lastScale); } } } } } unsigned log2_max_frame_num_minus4 = bv.get_expGolomb(); DEBUG_PRINT(log2_max_frame_num_minus4); unsigned pic_order_cnt_type = bv.get_expGolomb(); DEBUG_PRINT(pic_order_cnt_type); if (pic_order_cnt_type == 0) { DEBUG_TAB; unsigned log2_max_pic_order_cnt_lsb_minus4 = bv.get_expGolomb(); DEBUG_PRINT(log2_max_pic_order_cnt_lsb_minus4); } else if (pic_order_cnt_type == 1) { DEBUG_TAB; bv.skipBits(1); // delta_pic_order_always_zero_flag (void)bv.get_expGolomb(); // offset_for_non_ref_pic (void)bv.get_expGolomb(); // offset_for_top_to_bottom_field unsigned num_ref_frames_in_pic_order_cnt_cycle = bv.get_expGolomb(); DEBUG_PRINT(num_ref_frames_in_pic_order_cnt_cycle); for (unsigned i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i) { (void)bv.get_expGolomb(); // offset_for_ref_frame[i] } } unsigned max_num_ref_frames = bv.get_expGolomb(); DEBUG_PRINT(max_num_ref_frames); Boolean gaps_in_frame_num_value_allowed_flag = bv.get1BitBoolean(); DEBUG_PRINT(gaps_in_frame_num_value_allowed_flag); unsigned pic_width_in_mbs_minus1 = bv.get_expGolomb(); DEBUG_PRINT(pic_width_in_mbs_minus1); unsigned pic_height_in_map_units_minus1 = bv.get_expGolomb(); DEBUG_PRINT(pic_height_in_map_units_minus1); Boolean frame_mbs_only_flag = bv.get1BitBoolean(); DEBUG_PRINT(frame_mbs_only_flag); if (!frame_mbs_only_flag) { bv.skipBits(1); // mb_adaptive_frame_field_flag } bv.skipBits(1); // direct_8x8_inference_flag Boolean frame_cropping_flag = bv.get1BitBoolean(); DEBUG_PRINT(frame_cropping_flag); if (frame_cropping_flag) { (void)bv.get_expGolomb(); // frame_crop_left_offset (void)bv.get_expGolomb(); // frame_crop_right_offset (void)bv.get_expGolomb(); // frame_crop_top_offset (void)bv.get_expGolomb(); // frame_crop_bottom_offset } Boolean vui_parameters_present_flag = bv.get1BitBoolean(); DEBUG_PRINT(vui_parameters_present_flag); if (vui_parameters_present_flag) { DEBUG_TAB; analyze_vui_parameters(bv, num_units_in_tick, time_scale); } } else { // 265 unsigned i; bv.skipBits(16); // nal_unit_header bv.skipBits(4); // sps_video_parameter_set_id unsigned sps_max_sub_layers_minus1 = bv.getBits(3); DEBUG_PRINT(sps_max_sub_layers_minus1); bv.skipBits(1); // sps_temporal_id_nesting_flag profile_tier_level(bv, sps_max_sub_layers_minus1); (void)bv.get_expGolomb(); // sps_seq_parameter_set_id unsigned chroma_format_idc = bv.get_expGolomb(); DEBUG_PRINT(chroma_format_idc); if (chroma_format_idc == 3) bv.skipBits(1); // separate_colour_plane_flag unsigned pic_width_in_luma_samples = bv.get_expGolomb(); DEBUG_PRINT(pic_width_in_luma_samples); unsigned pic_height_in_luma_samples = bv.get_expGolomb(); DEBUG_PRINT(pic_height_in_luma_samples); Boolean conformance_window_flag = bv.get1BitBoolean(); DEBUG_PRINT(conformance_window_flag); if (conformance_window_flag) { DEBUG_TAB; unsigned conf_win_left_offset = bv.get_expGolomb(); DEBUG_PRINT(conf_win_left_offset); unsigned conf_win_right_offset = bv.get_expGolomb(); DEBUG_PRINT(conf_win_right_offset); unsigned conf_win_top_offset = bv.get_expGolomb(); DEBUG_PRINT(conf_win_top_offset); unsigned conf_win_bottom_offset = bv.get_expGolomb(); DEBUG_PRINT(conf_win_bottom_offset); } (void)bv.get_expGolomb(); // bit_depth_luma_minus8 (void)bv.get_expGolomb(); // bit_depth_chroma_minus8 unsigned log2_max_pic_order_cnt_lsb_minus4 = bv.get_expGolomb(); Boolean sps_sub_layer_ordering_info_present_flag = bv.get1BitBoolean(); DEBUG_PRINT(sps_sub_layer_ordering_info_present_flag); for (i = (sps_sub_layer_ordering_info_present_flag ? 0 : sps_max_sub_layers_minus1); i <= sps_max_sub_layers_minus1; ++i) { (void)bv.get_expGolomb(); // sps_max_dec_pic_buffering_minus1[i] (void)bv.get_expGolomb(); // sps_max_num_reorder_pics[i] (void)bv.get_expGolomb(); // sps_max_latency_increase[i] } (void)bv.get_expGolomb(); // log2_min_luma_coding_block_size_minus3 (void)bv.get_expGolomb(); // log2_diff_max_min_luma_coding_block_size (void)bv.get_expGolomb(); // log2_min_transform_block_size_minus2 (void)bv.get_expGolomb(); // log2_diff_max_min_transform_block_size (void)bv.get_expGolomb(); // max_transform_hierarchy_depth_inter (void)bv.get_expGolomb(); // max_transform_hierarchy_depth_intra Boolean scaling_list_enabled_flag = bv.get1BitBoolean(); DEBUG_PRINT(scaling_list_enabled_flag); if (scaling_list_enabled_flag) { DEBUG_TAB; Boolean sps_scaling_list_data_present_flag = bv.get1BitBoolean(); DEBUG_PRINT(sps_scaling_list_data_present_flag); if (sps_scaling_list_data_present_flag) { // scaling_list_data() DEBUG_TAB; for (unsigned sizeId = 0; sizeId < 4; ++sizeId) { DEBUG_PRINT(sizeId); for (unsigned matrixId = 0; matrixId < (sizeId == 3 ? 2 : 6); ++matrixId) { DEBUG_TAB; DEBUG_PRINT(matrixId); Boolean scaling_list_pred_mode_flag = bv.get1BitBoolean(); DEBUG_PRINT(scaling_list_pred_mode_flag); if (!scaling_list_pred_mode_flag) { (void)bv.get_expGolomb(); // scaling_list_pred_matrix_id_delta[sizeId][matrixId] } else { unsigned const c = 1 << (4+(sizeId<<1)); unsigned coefNum = c < 64 ? c : 64; if (sizeId > 1) { (void)bv.get_expGolomb(); // scaling_list_dc_coef_minus8[sizeId][matrixId] } for (i = 0; i < coefNum; ++i) { (void)bv.get_expGolomb(); // scaling_list_delta_coef } } } } } } bv.skipBits(2); // amp_enabled_flag, sample_adaptive_offset_enabled_flag Boolean pcm_enabled_flag = bv.get1BitBoolean(); DEBUG_PRINT(pcm_enabled_flag); if (pcm_enabled_flag) { bv.skipBits(8); // pcm_sample_bit_depth_luma_minus1, pcm_sample_bit_depth_chroma_minus1 (void)bv.get_expGolomb(); // log2_min_pcm_luma_coding_block_size_minus3 (void)bv.get_expGolomb(); // log2_diff_max_min_pcm_luma_coding_block_size bv.skipBits(1); // pcm_loop_filter_disabled_flag } unsigned num_short_term_ref_pic_sets = bv.get_expGolomb(); DEBUG_PRINT(num_short_term_ref_pic_sets); unsigned num_negative_pics = 0, prev_num_negative_pics = 0; unsigned num_positive_pics = 0, prev_num_positive_pics = 0; for (i = 0; i < num_short_term_ref_pic_sets; ++i) { // short_term_ref_pic_set(i): DEBUG_TAB; DEBUG_PRINT(i); Boolean inter_ref_pic_set_prediction_flag = False; if (i != 0) { inter_ref_pic_set_prediction_flag = bv.get1BitBoolean(); } DEBUG_PRINT(inter_ref_pic_set_prediction_flag); if (inter_ref_pic_set_prediction_flag) { DEBUG_TAB; if (i == num_short_term_ref_pic_sets) { // This can't happen here, but it's in the spec, so we include it for completeness (void)bv.get_expGolomb(); // delta_idx_minus1 } bv.skipBits(1); // delta_rps_sign (void)bv.get_expGolomb(); // abs_delta_rps_minus1 unsigned NumDeltaPocs = prev_num_negative_pics + prev_num_positive_pics; // correct??? for (unsigned j = 0; j < NumDeltaPocs; ++j) { DEBUG_PRINT(j); Boolean used_by_curr_pic_flag = bv.get1BitBoolean(); DEBUG_PRINT(used_by_curr_pic_flag); if (!used_by_curr_pic_flag) bv.skipBits(1); // use_delta_flag[j] } } else { prev_num_negative_pics = num_negative_pics; num_negative_pics = bv.get_expGolomb(); DEBUG_PRINT(num_negative_pics); prev_num_positive_pics = num_positive_pics; num_positive_pics = bv.get_expGolomb(); DEBUG_PRINT(num_positive_pics); unsigned k; for (k = 0; k < num_negative_pics; ++k) { (void)bv.get_expGolomb(); // delta_poc_s0_minus1[k] bv.skipBits(1); // used_by_curr_pic_s0_flag[k] } for (k = 0; k < num_positive_pics; ++k) { (void)bv.get_expGolomb(); // delta_poc_s1_minus1[k] bv.skipBits(1); // used_by_curr_pic_s1_flag[k] } } } Boolean long_term_ref_pics_present_flag = bv.get1BitBoolean(); DEBUG_PRINT(long_term_ref_pics_present_flag); if (long_term_ref_pics_present_flag) { DEBUG_TAB; unsigned num_long_term_ref_pics_sps = bv.get_expGolomb(); DEBUG_PRINT(num_long_term_ref_pics_sps); for (i = 0; i < num_long_term_ref_pics_sps; ++i) { bv.skipBits(log2_max_pic_order_cnt_lsb_minus4); // lt_ref_pic_poc_lsb_sps[i] bv.skipBits(1); // used_by_curr_pic_lt_sps_flag[1] } } bv.skipBits(2); // sps_temporal_mvp_enabled_flag, strong_intra_smoothing_enabled_flag Boolean vui_parameters_present_flag = bv.get1BitBoolean(); DEBUG_PRINT(vui_parameters_present_flag); if (vui_parameters_present_flag) { DEBUG_TAB; analyze_vui_parameters(bv, num_units_in_tick, time_scale); } Boolean sps_extension_flag = bv.get1BitBoolean(); DEBUG_PRINT(sps_extension_flag); } }
void H264VideoStreamParser ::analyze_seq_parameter_set_data(unsigned& num_units_in_tick, unsigned& time_scale, unsigned& fixed_frame_rate_flag) { num_units_in_tick = time_scale = fixed_frame_rate_flag = 0; // default values // Begin by making a copy of the NAL unit data, removing any 'emulation prevention' bytes: u_int8_t sps[SPS_MAX_SIZE]; unsigned spsSize; removeEmulationBytes(sps, sizeof sps, spsSize); BitVector bv(sps, 0, 8*spsSize); bv.skipBits(8); // forbidden_zero_bit; nal_ref_idc; nal_unit_type unsigned profile_idc = bv.getBits(8); DEBUG_PRINT(profile_idc); unsigned constraint_setN_flag = bv.getBits(8); // also "reserved_zero_2bits" at end DEBUG_PRINT(constraint_setN_flag); unsigned level_idc = bv.getBits(8); DEBUG_PRINT(level_idc); unsigned seq_parameter_set_id = bv.get_expGolomb(); DEBUG_PRINT(seq_parameter_set_id); if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 244 || profile_idc == 44 || profile_idc == 83 || profile_idc == 86 || profile_idc == 118 || profile_idc == 128 ) { DEBUG_TAB; unsigned chroma_format_idc = bv.get_expGolomb(); DEBUG_PRINT(chroma_format_idc); if (chroma_format_idc == 3) { DEBUG_TAB; separate_colour_plane_flag = bv.get1BitBoolean(); DEBUG_PRINT(separate_colour_plane_flag); } (void)bv.get_expGolomb(); // bit_depth_luma_minus8 (void)bv.get_expGolomb(); // bit_depth_chroma_minus8 bv.skipBits(1); // qpprime_y_zero_transform_bypass_flag unsigned seq_scaling_matrix_present_flag = bv.get1Bit(); DEBUG_PRINT(seq_scaling_matrix_present_flag); if (seq_scaling_matrix_present_flag) { for (int i = 0; i < ((chroma_format_idc != 3) ? 8 : 12); ++i) { DEBUG_TAB; DEBUG_PRINT(i); unsigned seq_scaling_list_present_flag = bv.get1Bit(); DEBUG_PRINT(seq_scaling_list_present_flag); if (seq_scaling_list_present_flag) { DEBUG_TAB; unsigned sizeOfScalingList = i < 6 ? 16 : 64; unsigned lastScale = 8; unsigned nextScale = 8; for (unsigned j = 0; j < sizeOfScalingList; ++j) { DEBUG_TAB; DEBUG_PRINT(j); DEBUG_PRINT(nextScale); if (nextScale != 0) { DEBUG_TAB; unsigned delta_scale = bv.get_expGolomb(); DEBUG_PRINT(delta_scale); nextScale = (lastScale + delta_scale + 256) % 256; } lastScale = (nextScale == 0) ? lastScale : nextScale; DEBUG_PRINT(lastScale); } } } } } unsigned log2_max_frame_num_minus4 = bv.get_expGolomb(); DEBUG_PRINT(log2_max_frame_num_minus4); log2_max_frame_num = log2_max_frame_num_minus4 + 4; unsigned pic_order_cnt_type = bv.get_expGolomb(); DEBUG_PRINT(pic_order_cnt_type); if (pic_order_cnt_type == 0) { DEBUG_TAB; unsigned log2_max_pic_order_cnt_lsb_minus4 = bv.get_expGolomb(); DEBUG_PRINT(log2_max_pic_order_cnt_lsb_minus4); } else if (pic_order_cnt_type == 1) { DEBUG_TAB; bv.skipBits(1); // delta_pic_order_always_zero_flag (void)bv.get_expGolomb(); // offset_for_non_ref_pic (void)bv.get_expGolomb(); // offset_for_top_to_bottom_field unsigned num_ref_frames_in_pic_order_cnt_cycle = bv.get_expGolomb(); DEBUG_PRINT(num_ref_frames_in_pic_order_cnt_cycle); for (unsigned i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i) { (void)bv.get_expGolomb(); // offset_for_ref_frame[i] } } unsigned max_num_ref_frames = bv.get_expGolomb(); DEBUG_PRINT(max_num_ref_frames); unsigned gaps_in_frame_num_value_allowed_flag = bv.get1Bit(); DEBUG_PRINT(gaps_in_frame_num_value_allowed_flag); unsigned pic_width_in_mbs_minus1 = bv.get_expGolomb(); DEBUG_PRINT(pic_width_in_mbs_minus1); unsigned pic_height_in_map_units_minus1 = bv.get_expGolomb(); DEBUG_PRINT(pic_height_in_map_units_minus1); frame_mbs_only_flag = bv.get1BitBoolean(); DEBUG_PRINT(frame_mbs_only_flag); if (!frame_mbs_only_flag) { bv.skipBits(1); // mb_adaptive_frame_field_flag } bv.skipBits(1); // direct_8x8_inference_flag unsigned frame_cropping_flag = bv.get1Bit(); DEBUG_PRINT(frame_cropping_flag); if (frame_cropping_flag) { (void)bv.get_expGolomb(); // frame_crop_left_offset (void)bv.get_expGolomb(); // frame_crop_right_offset (void)bv.get_expGolomb(); // frame_crop_top_offset (void)bv.get_expGolomb(); // frame_crop_bottom_offset } unsigned vui_parameters_present_flag = bv.get1Bit(); DEBUG_PRINT(vui_parameters_present_flag); if (vui_parameters_present_flag) { DEBUG_TAB; analyze_vui_parameters(bv,num_units_in_tick, time_scale, fixed_frame_rate_flag); } }
/** * \fn void point( double u , double v , double& x , double& y , double& z ) const * * \brief Compute a point on this rectangular Bezier patch. * * \param u First Cartesian coordinate of the parameter point. * \param v Second Cartesian coordinate of the parameter point. * \param x First Cartesian coordinate of the point on the patch. * \param y Second Caresian coordinate of the point on the patch. * \param z Third Cartesian coordinate of the point on the patch. */ void tBezier::point( double u , double v , double& x , double& y , double& z ) const { /** * Map the point to the affine frame [0,1]. */ double rx = get_aff_1st_point_x_coord() ; double ry = get_aff_1st_point_y_coord() ; double sx = get_aff_2nd_point_x_coord() ; double sy = get_aff_2nd_point_y_coord() ; /** * Compute all Bernstein polynomials of degree \var{_m}. */ double uu = ( u - rx ) / ( sx - rx ) ; double vv = ( v - ry ) / ( sy - ry ) ; if ( fabs( uu ) <= 1e-15 ) { uu = 0 ; } else if ( fabs( 1 - uu ) <= 1e-15 ) { uu = 1 ; } if ( fabs( vv ) <= 1e-15 ) { vv = 0 ; } else if ( fabs( 1 - vv ) <= 1e-15 ) { vv = 1 ; } unsigned m = get_bidegree_1st_index() ; unsigned n = get_bidegree_2nd_index() ; std::vector< double > bu( m + 1 ) ; all_bernstein( m , uu , bu ); /** * Compute all Bernstein polynomials of degree \var{_n}. */ std::vector< double > bv( n + 1 ) ; all_bernstein( n , vv , bv ); /** * Compute the image point, (x,y,z), of (u,v) on this patch. */ x = 0 ; y = 0 ; z = 0 ; for ( unsigned j = 0 ; j <= n ; j++ ) { for ( unsigned i = 0 ; i <= m ; i++ ) { double buv = bu[ i ] * bv[ j ] ; double xaux ; double yaux ; double zaux ; b( i , j , xaux , yaux , zaux ) ; x += buv * xaux ; y += buv * yaux ; z += buv * zaux ; } } return ; }