void Component::showEllipse(Mat nbrhd, float radius_ir, Point2f ctr_ir) { if (size()<=5) return; Scalar cyan(255,255,0); Scalar black(0,0,0); Scalar yellow(0,255,255); Scalar white(255,255,255); float f_diff=0; stringstream ss; ss << id%100; Point2f ctr_tmp=ctr; ctr_tmp.x=ctr_tmp.x*radius_ir; ctr_tmp.y=ctr_tmp.y*radius_ir; ctr_tmp=ctr_tmp+ctr_ir; Size2f a_b(a,b); a_b=a_b*radius_ir; ellipse(nbrhd,ctr_tmp,a_b,(phi+f_diff)*(180/M_PI),0,360,black, 3,2); ellipse(nbrhd,ctr_tmp,a_b,(phi+f_diff)*(180/M_PI),0,360,white ,1,2); RNG rng( 0xFFFFFFFF ); putText( nbrhd, ss.str().c_str(), ctr_tmp, 0, // font face 0.3, // font scale white, // font color 2); putText( nbrhd, ss.str().c_str(), ctr_tmp, 0, // font face 0.3, // font scale black, // font color 1); }
QImage LunaticPEEntry::GetAsBMP() { QFile f(Parent->GetPEName()); if(!f.open(QIODevice::ReadOnly)) return QImage(); f.seek(Offset); QByteArray a = f.read(Size); QBuffer a_b(&a); if(!a_b.open(QIODevice::ReadWrite)) { qDebug("Couldn't create read/write buffer in order to load a resource image."); return QImage(); } QDataStream stream(&a_b); stream.setByteOrder(QDataStream::LittleEndian); // in order to actually read this BMP with any builtin methods, we need to make it valid... // in Windows resources, BMP header is stripped as it is "not required after the image is loaded into memory" // thus we need to generate it // upd: generating BMPv3 header on Qt < 5.3.0, generating 56-byte transparent BMPv3 header on Qt >= 5.3.0 quint16 bmp_sig = 0x4D42; // BM quint32 bmp_size = a.size() + 14; quint16 bmp_res1 = 0; quint16 bmp_res2 = 0; quint32 bmp_offset = 14+40; stream.device()->seek(0x0E); quint16 colorspace; stream >> colorspace; if(colorspace <= 8) { stream.device()->seek(0x20); quint32 colortable_size; stream >> colortable_size; if(!colortable_size) colortable_size = 1 << colorspace; bmp_offset += colortable_size*4; }
vec_type Polyhedron<plane_itt>::TestContour(const contour_t &cnt, VecContour<> *subcont, Vector_3 *subcenter) const{ /// testing bounding box Vector_3 bc1, bc2; cnt.GetBoundingBox(&bc1,&bc2); Vector_3 p1=box.get_p1(), p2=box.get_p2(); for(int i=0;i<3;i++){ if(bc1[i]>p2[i] || bc2[i]<p1[i])return 0.; } aggregate_it<plane_it, typename contour_t::plane_it, Plane_3> a_b(b,e,cnt.planes_begin()),a_e(e,e,cnt.planes_end()); // solving for intersection VecContour<> s_cont; int res=ProjectSimplex(cnt.GetPlane(),a_b,a_e,s_cont); if(res==1){ vec_type a=s_cont.Area(); if(subcenter)*subcenter=s_cont.GetCenter(); if(subcont)subcont->GetPoints().swap(s_cont.GetPoints()); return a; } return 0.; }
/* * === FUNCTION ====================================================================== * Name: main * Description: * ===================================================================================== */ int main(int argc, char *argv[]) { a_b(); c_b(); return EXIT_SUCCESS; } /* ---------- end of function main ---------- */
bool yee_compare(CompareArgs &args) { if ((args.image_a_->get_width() != args.image_b_->get_width()) or (args.image_a_->get_height() != args.image_b_->get_height())) { args.error_string_ = "Image dimensions do not match\n"; return false; } const auto w = args.image_a_->get_width(); const auto h = args.image_a_->get_height(); const auto dim = w * h; auto identical = true; for (auto i = 0u; i < dim; i++) { if (args.image_a_->get(i) != args.image_b_->get(i)) { identical = false; break; } } if (identical) { args.error_string_ = "Images are binary identical\n"; return true; } // Assuming colorspaces are in Adobe RGB (1998) convert to XYZ. std::vector<float> a_lum(dim); std::vector<float> b_lum(dim); std::vector<float> a_a(dim); std::vector<float> b_a(dim); std::vector<float> a_b(dim); std::vector<float> b_b(dim); if (args.verbose_) { std::cout << "Converting RGB to XYZ\n"; } const auto gamma = args.gamma_; const auto luminance = args.luminance_; #pragma omp parallel for shared(args, a_lum, b_lum, a_a, a_b, b_a, b_b) for (auto y = 0; y < static_cast<ptrdiff_t>(h); y++) { for (auto x = 0u; x < w; x++) { const auto i = x + y * w; const auto a_color_r = powf(args.image_a_->get_red(i) / 255.0f, gamma); const auto a_color_g = powf(args.image_a_->get_green(i) / 255.0f, gamma); const auto a_color_b = powf(args.image_a_->get_blue(i) / 255.0f, gamma); float a_x; float a_y; float a_z; adobe_rgb_to_xyz(a_color_r, a_color_g, a_color_b, a_x, a_y, a_z); float l; xyz_to_lab(a_x, a_y, a_z, l, a_a[i], a_b[i]); const auto b_color_r = powf(args.image_b_->get_red(i) / 255.0f, gamma); const auto b_color_g = powf(args.image_b_->get_green(i) / 255.0f, gamma); const auto b_color_b = powf(args.image_b_->get_blue(i) / 255.0f, gamma); float b_x; float b_y; float b_z; adobe_rgb_to_xyz(b_color_r, b_color_g, b_color_b, b_x, b_y, b_z); xyz_to_lab(b_x, b_y, b_z, l, b_a[i], b_b[i]); a_lum[i] = a_y * luminance; b_lum[i] = b_y * luminance; } } if (args.verbose_) { std::cout << "Constructing Laplacian Pyramids\n"; } const LPyramid la(a_lum, w, h); const LPyramid lb(b_lum, w, h); const auto num_one_degree_pixels = to_degrees(2 * std::tan(args.field_of_view_ * to_radians(.5f))); const auto pixels_per_degree = w / num_one_degree_pixels; if (args.verbose_) { std::cout << "Performing test\n"; } const auto adaptation_level = adaptation(num_one_degree_pixels); float cpd[MAX_PYR_LEVELS]; cpd[0] = 0.5f * pixels_per_degree; for (auto i = 1u; i < MAX_PYR_LEVELS; i++) { cpd[i] = 0.5f * cpd[i - 1]; } const auto csf_max = csf(3.248f, 100.0f); static_assert(MAX_PYR_LEVELS > 2, "MAX_PYR_LEVELS must be greater than 2"); float f_freq[MAX_PYR_LEVELS - 2]; for (auto i = 0u; i < MAX_PYR_LEVELS - 2; i++) { f_freq[i] = csf_max / csf(cpd[i], 100.0f); } auto pixels_failed = 0u; auto error_sum = 0.; #pragma omp parallel for reduction(+ : pixels_failed, error_sum) \ shared(args, a_a, a_b, b_a, b_b, cpd, f_freq) for (auto y = 0; y < static_cast<ptrdiff_t>(h); y++) { for (auto x = 0u; x < w; x++) { const auto index = y * w + x; const auto adapt = std::max((la.get_value(x, y, adaptation_level) + lb.get_value(x, y, adaptation_level)) * 0.5f, 1e-5f); auto sum_contrast = 0.f; auto factor = 0.f; for (auto i = 0u; i < MAX_PYR_LEVELS - 2; i++) { const auto n1 = fabsf(la.get_value(x, y, i) - la.get_value(x, y, i + 1)); const auto n2 = fabsf(lb.get_value(x, y, i) - lb.get_value(x, y, i + 1)); const auto numerator = std::max(n1, n2); const auto d1 = fabsf(la.get_value(x, y, i + 2)); const auto d2 = fabsf(lb.get_value(x, y, i + 2)); const auto denominator = std::max(std::max(d1, d2), 1e-5f); const auto contrast = numerator / denominator; const auto f_mask = mask(contrast * csf(cpd[i], adapt)); factor += contrast * f_freq[i] * f_mask; sum_contrast += contrast; } sum_contrast = std::max(sum_contrast, 1e-5f); factor /= sum_contrast; factor = std::min(std::max(factor, 1.f), 10.f); const auto delta = fabsf(la.get_value(x, y, 0) - lb.get_value(x, y, 0)); error_sum += delta; auto pass = true; // pure luminance test if (delta > factor * tvi(adapt)) { pass = false; } if (not args.luminance_only_) { // CIE delta E test with modifications auto color_scale = args.color_factor_; // ramp down the color test in scotopic regions if (adapt < 10.0f) { // Don't do color test at all. color_scale = 0.0; } const auto da = a_a[index] - b_a[index]; const auto db = a_b[index] - b_b[index]; const auto delta_e = (da * da + db * db) * color_scale; error_sum += delta_e; if (delta_e > factor) { pass = false; } } if (not pass) { pixels_failed++; if (args.image_difference_) { args.image_difference_->set(255, 0, 0, 255, index); } } else { if (args.image_difference_) { args.image_difference_->set(0, 0, 0, 255, index); } } } } const auto error_sum_buff = std::to_string(error_sum) + " error sum\n"; const auto different = std::to_string(pixels_failed) + " pixels are different\n"; // Always output image difference if requested. if (args.image_difference_) { args.image_difference_->write_to_file(args.image_difference_->get_name()); args.error_string_ += "Wrote difference image to "; args.error_string_ += args.image_difference_->get_name(); args.error_string_ += "\n"; } if (pixels_failed < args.threshold_pixels_) { args.error_string_ = "Images are perceptually indistinguishable\n"; args.error_string_ += different; return true; } args.error_string_ = "Images are visibly different\n"; args.error_string_ += different; if (args.sum_errors_) { args.error_string_ += error_sum_buff; } return false; }
void RawScannerDataRadarOverlay::onDraw(sf::RenderTarget& window) { if (!my_spaceship) return; sf::Vector2f view_position = my_spaceship->getPosition();; const int point_count = 512; float radius = std::min(rect.width, rect.height) / 2.0f; RawRadarSignatureInfo signatures[point_count]; foreach(SpaceObject, obj, space_object_list) { if (obj == my_spaceship) continue; float a_0, a_1; float dist = sf::length(obj->getPosition() - view_position); float scale = 1.0; if (dist > distance * 2.0) continue; if (dist > distance) scale = (dist - distance) / distance; if (dist <= obj->getRadius()) { a_0 = 0.0f; a_1 = 360.0f; }else{ float a_diff = asinf(obj->getRadius() / dist) / M_PI * 180.0f; float a_center = sf::vector2ToAngle(obj->getPosition() - view_position); a_0 = a_center - a_diff; a_1 = a_center + a_diff; } RawRadarSignatureInfo info = obj->getRadarSignatureInfo(); for(float a=a_0; a<=a_1; a += 360.f / float(point_count)) { int idx = (int(a / 360.0f * point_count) + point_count * 2) % point_count; signatures[idx] += info * scale; } } float amp_r[point_count]; float amp_g[point_count]; float amp_b[point_count]; for(int n=0; n<point_count; n++) { signatures[n].gravity = std::max(0.0f, std::min(1.0f, signatures[n].gravity)); signatures[n].electrical = std::max(0.0f, std::min(1.0f, signatures[n].electrical)); signatures[n].biological = std::max(0.0f, std::min(1.0f, signatures[n].biological)); float r = random(-1, 1); float g = random(-1, 1); float b = random(-1, 1); r += signatures[n].biological * 30; g += signatures[n].biological * 30; r += random(-20, 20) * signatures[n].electrical; b += random(-20, 20) * signatures[n].electrical; r = r * (1.0f - signatures[n].gravity); g = g * (1.0f - signatures[n].gravity) + 40 * signatures[n].gravity; b = b * (1.0f - signatures[n].gravity) + 40 * signatures[n].gravity; amp_r[n] = r; amp_g[n] = g; amp_b[n] = b; } sf::VertexArray a_r(sf::LinesStrip, point_count+1); sf::VertexArray a_g(sf::LinesStrip, point_count+1); sf::VertexArray a_b(sf::LinesStrip, point_count+1); for(int n=0; n<point_count; n++) { float r = 0.0; float g = 0.0; float b = 0.0; for(int m = n - 2 + point_count; m <= n + 2 + point_count; m++) { r += amp_r[m % point_count]; g += amp_g[m % point_count]; b += amp_b[m % point_count]; } r /= 5; g /= 5; b /= 5; a_r[n].position.x = rect.left + rect.width / 2.0f; a_r[n].position.y = rect.top + rect.height / 2.0f; a_r[n].position += sf::vector2FromAngle(float(n) / float(point_count) * 360.0f) * (radius * (0.95f - r / 500)); a_r[n].color = sf::Color(255, 0, 0); a_g[n].position.x = rect.left + rect.width / 2.0f; a_g[n].position.y = rect.top + rect.height / 2.0f; a_g[n].position += sf::vector2FromAngle(float(n) / float(point_count) * 360.0f) * (radius * (0.92f - g / 500)); a_g[n].color = sf::Color(0, 255, 0); a_b[n].position.x = rect.left + rect.width / 2.0f; a_b[n].position.y = rect.top + rect.height / 2.0f; a_b[n].position += sf::vector2FromAngle(float(n) / float(point_count) * 360.0f) * (radius * (0.89f - b / 500)); a_b[n].color = sf::Color(0, 0, 255); } a_r[point_count] = a_r[0]; a_g[point_count] = a_g[0]; a_b[point_count] = a_b[0]; window.draw(a_r, sf::BlendAdd); window.draw(a_g, sf::BlendAdd); window.draw(a_b, sf::BlendAdd); }
double PlanOperation::calcA(double totalTblSizeIn100k) { return a_a() * totalTblSizeIn100k + a_b(); }