void UIWidget::Draw(DrawContext& c){ if(display_mode == DisplayMode::Invisible) return; const Size2D drawsize = c.Size(); if(drawsize.IsEmpty()){ needs_redrawing = false; return; } if(drawsize != current_size){ std::cout << "WARNING: Implicitly calling Resize, because the draw " "context size " << drawsize.ToString() << " is incoherent with widget " "stored size " << current_size.ToString() << "!" << std::endl; //throw Exception(""); Resize(drawsize); } if(needs_redrawing){ //std::cout << "Needs redrawing. " << cache_texture->GetSize().ToString() << std::endl; c.Push(cache_texture, drawsize.width, drawsize.height); if(IsDrawn()){ c.Clear(clear_color); CustomDraw(c); c.SetColor(overlay_color); c.Fill(); }else{ c.Clear(); } c.Pop(); }else{ //std::cout << "No need to redraw. " << cache_texture->GetSize().ToString() << std::endl; } c.DrawTexture(cache_texture); current_size = drawsize; needs_redrawing = false; }
void writeToConsole(std::ostream& ocons) const { ocons << "SimHeader.size " << size.x() << " " << size.y() << std::endl; ocons << "SimHeader.nodes " << nodes.x() << " " << nodes.y() << std::endl; ocons << "SimHeader.step " << step << std::endl; ocons << "SimHeader.scale " << scale[0] << " " << scale[1] << std::endl; ocons << "SimHeader.cellSize " << cellSizeArr[0] << " " << cellSizeArr[1] << std::endl; }
void writeToConsole(std::ostream& ocons) const { ocons << "NodeHeader.maxSize " << maxSize.x() << " " << maxSize.y() << std::endl; ocons << "NodeHeader.size " << size.x() << " " << size.y() << std::endl; ocons << "NodeHeader.localOffset " << localOffset.x() << " " << localOffset.y() << std::endl; ocons << "NodeHeader.offset " << offset.x() << " " << offset.y() << std::endl; ocons << "NodeHeader.offsetToWindow " << offsetToWindow.x() << " " << offsetToWindow.y() << std::endl; }
void insertData(DstBox& dst, const SrcBox& src, Size2D offsetToSimNull, Size2D srcSize) { for (int y = 0; y < srcSize.y(); ++y) { for (int x = 0; x < srcSize.x(); ++x) { dst[y + offsetToSimNull.y()][x + offsetToSimNull.x()] = src[y][x]; } } }
size_t TensorInfo::init_auto_padding(const HOGInfo &hog_info, unsigned int width, unsigned int height) { // Number of cells for each block const Size2D num_cells_per_block = hog_info.num_cells_per_block(); // Tensor Size = (Number of horizontal blocks) * (Number of vertical blocks ) const Size2D num_blocks_per_img = hog_info.num_blocks_per_image(Size2D(width, height)); // Number of tensor channels = (Number of cells per block) * (Number of bins per cell) const size_t num_channels = num_cells_per_block.area() * hog_info.num_bins(); return init_auto_padding(TensorShape(num_blocks_per_img.width, num_blocks_per_img.height), num_channels, DataType::F32); }
void meanStdDev(const Size2D &size, const u8 * srcBase, ptrdiff_t srcStride, f32 * pMean, f32 * pStdDev) { internal::assertSupportedConfiguration(); #ifdef CAROTENE_NEON f64 fsum = 0.0f, fsqsum = 0.0f; sqsum(size, srcBase, srcStride, &fsum, &fsqsum, 1); // calc mean and stddev f64 itotal = 1.0 / size.total(); f64 mean = fsum * itotal; f64 stddev = sqrt(std::max(fsqsum * itotal - mean * mean, 0.0)); if (pMean) *pMean = mean; if (pStdDev) *pStdDev = stddev; #else (void)size; (void)srcBase; (void)srcStride; (void)pMean; (void)pStdDev; #endif }
void fbPutGlyph(char *framebuffer, unsigned char *tile, Size2D size, Point destination, int vga_color){ //8x8 font tile long bytePos = (destination.getY() * 320) + destination.getX(); for(int y=0; y<size.getY(); y++) { //for each row of the tile if(tile[y] & 0x80) { framebuffer[bytePos] = vga_color; } else { //framebuffer[bytePos] = 0x00; } if(tile[y] & 0x40) { framebuffer[bytePos+1] = vga_color; } else { //framebuffer[bytePos+1] = 0x00; } if(tile[y] & 0x20) { framebuffer[bytePos+2] = vga_color; } else { //framebuffer[bytePos+2] = 0x00; } if(tile[y] & 0x10) { framebuffer[bytePos+3] = vga_color; } else { //framebuffer[bytePos+3] = 0x00; } if(tile[y] & 0x08) { framebuffer[bytePos+4] = vga_color; } else { //framebuffer[bytePos+4] = 0x00; } if(tile[y] & 0x04) { framebuffer[bytePos+5] = vga_color; } else { //framebuffer[bytePos+5] = 0x00; } if(tile[y] & 0x02) { framebuffer[bytePos+6] = vga_color; } else { //framebuffer[bytePos+6] = 0x00; } if(tile[y] & 0x01) { framebuffer[bytePos+7] = vga_color; } else { //framebuffer[bytePos+7] = 0x00; } bytePos += 320; } };
void operator()( const Box data, const ValueType unit, const Size2D size, const MessageHeader & header) { if (createFolder) { mkdir((folder).c_str(), 0755); createFolder = false; } std::stringstream step; step << std::setw(6) << std::setfill('0') << header.sim.step; //std::string filename(name + "_" + step.str() + ".bin"); std::string filename(name + "_" + step.str() + ".dat"); double x_cell = header.sim.cellSizeArr[0]; double y_cell = header.sim.cellSizeArr[1]; double x_simOff = header.sim.simOffsetToNull[0]; double y_simOff = header.sim.simOffsetToNull[1]; DataSpace<DIM2> gOffset = header.window.offset; std::ofstream file(filename.c_str(), std::ofstream::out ); //| std::ofstream::binary); typedef std::numeric_limits< ValueType > dbl; file.precision(dbl::digits10); file << std::scientific; ValueType sizex = (int) size.x(); //file.write((char*) (&sizex), sizeof (ValueType)); file << sizex << " "; //first line with y header information for (int x = 0; x < size.x(); ++x) { ValueType cellPos = (ValueType) ((x + x_simOff + gOffset.x()) * x_cell * UNIT_LENGTH); //file.write((char*) &(cellPos), sizeof (ValueType)); file << cellPos << " "; } file << std::endl; //the first column is for x header information for (int y = 0; y < size.y(); ++y) { for (int x = 0; x <= size.x(); ++x) { if (x == 0) { ValueType cellPos = (ValueType) ((y + y_simOff + gOffset.y()) * y_cell * UNIT_LENGTH); //file.write((char*) &(cellPos), sizeof (ValueType)); file << cellPos; } else { const ValueType value = precisionCast<ValueType>(data[y][x]) * unit; /** \info take care, that gnuplots binary matrix does * not support float64 (IEEE float32 only) * \see http://stackoverflow.com/questions/8751154/looking-at-binary-output-from-fortran-on-gnuplot * http://gnuplot.sourceforge.net/docs_4.2/node101.html */ //file.write((char*) &(value), sizeof (ValueType)); file << " " << value; } } file << std::endl; } file.close(); }
void update(CellDesc & cellDesc, picongpu::Window vWindow, Size2D transpose, uint32_t currentStep, float* cellSizeArr = NULL, const PMacc::DataSpace<CellDesc::Dim> gpus = PMacc::DataSpace<CellDesc::Dim > ()) { using namespace PMacc; using namespace picongpu; enum { Dim = CellDesc::Dim }; const DataSpace<Dim> localSize(cellDesc.getGridLayout().getDataSpaceWithoutGuarding()); const DataSpace<DIM2> localSize2D(localSize[transpose.x()], localSize[transpose.y()]); /*update only if nuber of gpus are set, else use old value*/ if (gpus.productOfComponents() != 0) sim.nodes = DataSpace<DIM2 > (gpus[transpose.x()], gpus[transpose.y()]); PMACC_AUTO(simBox, Environment<simDim>::get().SubGrid().getSimulationBox()); const DataSpace<Dim> globalSize(simBox.getGlobalSize()); sim.size.x() = globalSize[transpose.x()]; sim.size.y() = globalSize[transpose.y()]; node.maxSize = DataSpace<DIM2 > (localSize[transpose.x()], localSize[transpose.y()]); const DataSpace<Dim> windowSize = vWindow.globalDimensions.size; window.size = DataSpace<DIM2 > (windowSize[transpose.x()], windowSize[transpose.y()]); if (cellSizeArr != NULL) { float scale[2]; scale[0] = cellSizeArr[transpose.x()]; scale[1] = cellSizeArr[transpose.y()]; sim.cellSizeArr[0] = cellSizeArr[transpose.x()]; sim.cellSizeArr[1] = cellSizeArr[transpose.y()]; const float scale0to1 = scale[0] / scale[1]; if (scale0to1 > 1.0f) { sim.setScale(scale0to1, 1.f); } else if (scale0to1 < 1.0f) { sim.setScale(1.f, 1.0f / scale0to1); } else { sim.setScale(1.f, 1.f); } } const DataSpace<Dim> offsetToSimNull(simBox.getGlobalOffset()); const DataSpace<Dim> windowOffsetToSimNull(vWindow.globalDimensions.offset); const DataSpace<Dim> localOffset(vWindow.localDimensions.offset); const DataSpace<DIM2> localOffset2D(localOffset[transpose.x()], localOffset[transpose.y()]); node.localOffset = localOffset2D; DataSpace<Dim> offsetToWindow(offsetToSimNull - windowOffsetToSimNull); const DataSpace<DIM2> offsetToWindow2D(offsetToWindow[transpose.x()], offsetToWindow[transpose.y()]); node.offsetToWindow = offsetToWindow2D; const DataSpace<DIM2> offsetToSimNull2D(offsetToSimNull[transpose.x()], offsetToSimNull[transpose.y()]); node.offset = offsetToSimNull2D; const DataSpace<DIM2> windowOffsetToSimNull2D(windowOffsetToSimNull[transpose.x()], windowOffsetToSimNull[transpose.y()]); window.offset = windowOffsetToSimNull2D; const DataSpace<Dim> currentLocalSize(vWindow.localDimensions.size); const DataSpace<DIM2> currentLocalSize2D(currentLocalSize[transpose.x()], currentLocalSize[transpose.y()]); node.size = currentLocalSize2D; sim.step = currentStep; /*add sliding windo informations to header*/ const uint32_t numSlides = MovingWindow::getInstance().getSlideCounter(currentStep); sim.simOffsetToNull = DataSpace<DIM2 > (); if (transpose.x() == 1) sim.simOffsetToNull.x() = node.maxSize.x() * numSlides; else if (transpose.y() == 1) sim.simOffsetToNull.y() = node.maxSize.y() * numSlides; }
void meanStdDev(const Size2D &size, const u16 * srcBase, ptrdiff_t srcStride, f32 * pMean, f32 * pStdDev) { internal::assertSupportedConfiguration(); #ifdef CAROTENE_NEON size_t blockSize0 = 1 << 10, roiw4 = size.width & ~3; f64 fsum = 0.0f, fsqsum = 0.0f; f32 arsum[8]; uint32x4_t v_zero = vdupq_n_u32(0u), v_sum; float32x4_t v_zero_f = vdupq_n_f32(0.0f), v_sqsum; for (size_t i = 0; i < size.height; ++i) { const u16 * src = internal::getRowPtr(srcBase, srcStride, i); size_t j = 0u; while (j < roiw4) { size_t blockSize = std::min(roiw4 - j, blockSize0) + j; v_sum = v_zero; v_sqsum = v_zero_f; for ( ; j + 16 < blockSize ; j += 16) { internal::prefetch(src + j); uint16x8_t v_src0 = vld1q_u16(src + j), v_src1 = vld1q_u16(src + j + 8); // 0 uint32x4_t v_srclo = vmovl_u16(vget_low_u16(v_src0)); uint32x4_t v_srchi = vmovl_u16(vget_high_u16(v_src0)); v_sum = vaddq_u32(v_sum, vaddq_u32(v_srclo, v_srchi)); float32x4_t v_srclo_f = vcvtq_f32_u32(v_srclo); float32x4_t v_srchi_f = vcvtq_f32_u32(v_srchi); v_sqsum = vmlaq_f32(v_sqsum, v_srclo_f, v_srclo_f); v_sqsum = vmlaq_f32(v_sqsum, v_srchi_f, v_srchi_f); // 1 v_srclo = vmovl_u16(vget_low_u16(v_src1)); v_srchi = vmovl_u16(vget_high_u16(v_src1)); v_sum = vaddq_u32(v_sum, vaddq_u32(v_srclo, v_srchi)); v_srclo_f = vcvtq_f32_u32(v_srclo); v_srchi_f = vcvtq_f32_u32(v_srchi); v_sqsum = vmlaq_f32(v_sqsum, v_srclo_f, v_srclo_f); v_sqsum = vmlaq_f32(v_sqsum, v_srchi_f, v_srchi_f); } for ( ; j < blockSize; j += 4) { uint32x4_t v_src = vmovl_u16(vld1_u16(src + j)); float32x4_t v_src_f = vcvtq_f32_u32(v_src); v_sum = vaddq_u32(v_sum, v_src); v_sqsum = vmlaq_f32(v_sqsum, v_src_f, v_src_f); } vst1q_f32(arsum, vcvtq_f32_u32(v_sum)); vst1q_f32(arsum + 4, v_sqsum); fsum += (f64)arsum[0] + arsum[1] + arsum[2] + arsum[3]; fsqsum += (f64)arsum[4] + arsum[5] + arsum[6] + arsum[7]; } // collect a few last elements in the current row for ( ; j < size.width; ++j) { f32 srcval = src[j]; fsum += srcval; fsqsum += srcval * srcval; } } // calc mean and stddev f64 itotal = 1.0 / size.total(); f64 mean = fsum * itotal; f64 stddev = sqrt(std::max(fsqsum * itotal - mean * mean, 0.0)); if (pMean) *pMean = mean; if (pStdDev) *pStdDev = stddev; #else (void)size; (void)srcBase; (void)srcStride; (void)pMean; (void)pStdDev; #endif }