int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(512, 512); glutInitWindowPosition (100, 100); g_win = glutCreateWindow(argv[0]); #ifndef __APPLE__ glewInit(); if (!glewIsSupported("GL_VERSION_2_0")) { printf("OpenGL 2.0 not supported\n"); exit(1); } #endif glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); glutDisplayFunc(Redisplay); const char * filename = 0; if(argc>1) filename = argv[1]; std::cout << USAGE_TEXT << std::endl; // TODO: switch profiles based on shading language // std::cout << "GL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; AllocateLut3D(); InitImageTexture(filename); try { InitOCIO(filename); } catch(OCIO::Exception & e) { std::cerr << e.what() << std::endl; exit(1); } PopulateOCIOMenus(); Reshape(1024, 512); UpdateOCIOGLState(); Redisplay(); /* if (Anim) { glutIdleFunc(Idle); } */ glutMainLoop(); return 0; }
void GameConfigLoop (double time_step) { int ww = param.x_resolution; int hh = param.y_resolution; Music.Update (); check_gl_error(); Music.Update (); set_gl_options (GUI); ClearRenderContext (); SetupGuiDisplay (); if (param.ui_snow) { update_ui_snow (time_step); draw_ui_snow(); } Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), 1.0); Tex.Draw (BOTTOM_LEFT, 0, hh-256, 1); Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); Tex.Draw (TOP_LEFT, 0, 0, 1); Tex.Draw (TOP_RIGHT, ww-256, 0, 1); // DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top, // 0, colMBackgr, colBlack, 0.2); FT.AutoSizeN (4); PrintCheckbox (0, curr_focus, curr_fullscreen); if (curr_focus == 1) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd, Trans.Text(32)); if (curr_focus == 2) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd*2, Trans.Text(33)); if (curr_focus == 3) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd*3, Trans.Text(34)); if (curr_focus == 4) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd*4, Trans.Text(36)); if (curr_focus == 5) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd*5, Trans.Text(35)); FT.SetColor (colWhite); FT.DrawString (area.left+240, area.top + dd, res_names[curr_res]); FT.DrawString (area.left+240, area.top + dd*2, Int_StrN (curr_mus_vol)); FT.DrawString (area.left+240, area.top + dd*3, Int_StrN (curr_sound_vol)); FT.DrawString (area.left+240, area.top + dd*4, Int_StrN (curr_detail_level)); FT.DrawString (area.left+240, area.top + dd*5, LangList[curr_language].language); PrintArrow (0, (curr_res < (NUM_RESOLUTIONS-1))); PrintArrow (1, (curr_res > 0)); PrintArrow (2, (curr_mus_vol < 120)); PrintArrow (3, (curr_mus_vol > 0)); PrintArrow (4, (curr_sound_vol < 120)); PrintArrow (5, (curr_sound_vol > 0)); PrintArrow (6, (curr_detail_level < 3)); PrintArrow (7, (curr_detail_level > 1)); PrintArrow (8, (curr_language > 0)); PrintArrow (9, (curr_language < lastLang)); PrintTextButton (0, curr_focus); PrintTextButton (1, curr_focus); #if defined (OS_WIN32_MINGW) if ((curr_res != prev_res || curr_fullscreen != prev_fullscreen) && param.restart_on_res_change) { FT.SetColor (colDYell); FT.AutoSizeN (4); FT.DrawString (CENTER, AutoYPosN (68), "The video adjustments have changed,"); FT.DrawString (CENTER, AutoYPosN (72), "You need to restart the game"); } else { FT.SetColor (colLGrey); FT.AutoSizeN (3); FT.DrawString (CENTER, AutoYPosN (68), Trans.Text(41)); FT.DrawString (CENTER, AutoYPosN (72), Trans.Text(42)); } #else FT.SetColor (colWhite); FT.AutoSizeN (3); FT.DrawString (CENTER, AutoYPosN (68), Trans.Text(41)); FT.DrawString (CENTER, AutoYPosN (72), Trans.Text(42)); #endif if (param.ice_cursor) DrawCursor (); Reshape (ww, hh); Winsys.SwapBuffers (); }
Blob<Dtype>::Blob(const int num, const int channels, const int height, const int width, const bool allocateDiff) // capacity_ must be initialized before calling Reshape : allocateDiff_(allocateDiff), capacity_(0) { Reshape(num, channels, height, width); }
void Blob<Dtype>::ReshapeLike(const Blob<Dtype>& other) { Reshape(other.shape()); }
Blob<Dtype>::Blob(const vector<int>& shape) // capacity_ must be initialized before calling Reshape : capacity_(0) { Reshape(shape); }
// ネットワークを使って画像を再構築する Waifu2x::eWaifu2xError Waifu2x::ReconstructImage(boost::shared_ptr<caffe::Net<float>> net, cv::Mat &im) { const auto Height = im.size().height; const auto Width = im.size().width; const auto Line = im.step1(); assert(Width % output_size == 0); assert(Height % output_size == 0); assert(im.channels() == 1 || im.channels() == 3); cv::Mat outim(im.rows, im.cols, im.type()); // float *imptr = (float *)im.data; float *imptr = (float *)outim.data; try { auto input_blobs = net->input_blobs(); auto input_blob = net->input_blobs()[0]; input_blob->Reshape(batch_size, input_plane, input_block_size, input_block_size); assert(im.channels() == input_plane); assert(input_blob->shape(1) == input_plane); const int WidthNum = Width / output_size; const int HeightNum = Height / output_size; const int BlockNum = WidthNum * HeightNum; const int input_block_plane_size = input_block_size * input_block_size * input_plane; const int output_block_plane_size = output_block_size * output_block_size * input_plane; const int output_padding = inner_padding + outer_padding - layer_num; // 画像は(消費メモリの都合上)output_size*output_sizeに分けて再構築する for (int num = 0; num < BlockNum; num += batch_size) { const int processNum = (BlockNum - num) >= batch_size ? batch_size : BlockNum - num; if (processNum < batch_size) input_blob->Reshape(processNum, input_plane, input_block_size, input_block_size); for (int n = 0; n < processNum; n++) { const int wn = (num + n) % WidthNum; const int hn = (num + n) / WidthNum; const int w = wn * output_size; const int h = hn * output_size; if (w + crop_size <= Width && h + crop_size <= Height) { int x, y; x = w - inner_padding; y = h - inner_padding; int width, height; width = crop_size + inner_padding * 2; height = crop_size + inner_padding * 2; int top, bottom, left, right; top = outer_padding; bottom = outer_padding; left = outer_padding; right = outer_padding; if (x < 0) { left += -x; width -= -x; x = 0; } if (x + width > Width) { right += (x + width) - Width; width = Width - x; } if (y < 0) { top += -y; height -= -y; y = 0; } if (y + height > Height) { bottom += (y + height) - Height; height = Height - y; } cv::Mat someimg = im(cv::Rect(x, y, width, height)); cv::Mat someborderimg; // 画像を中央にパディング。余白はcv::BORDER_REPLICATEで埋める // 実はimで画素が存在する部分は余白と認識されないが、inner_paddingがlayer_numでouter_paddingが1以上ならそこの部分の画素は結果画像として取り出す部分には影響しない cv::copyMakeBorder(someimg, someborderimg, top, bottom, left, right, cv::BORDER_REPLICATE); someimg.release(); // 画像を直列に変換 { float *fptr = input_block + (input_block_plane_size * n); const float *uptr = (const float *)someborderimg.data; const auto Line = someborderimg.step1(); if (someborderimg.channels() == 1) { if (input_block_size == Line) memcpy(fptr, uptr, input_block_size * input_block_size * sizeof(float)); else { for (int i = 0; i < input_block_size; i++) memcpy(fptr + i * input_block_size, uptr + i * Line, input_block_size * sizeof(float)); } } else { const auto LinePixel = someborderimg.step1() / someborderimg.channels(); const auto Channel = someborderimg.channels(); const auto Width = someborderimg.size().width; const auto Height = someborderimg.size().height; for (int i = 0; i < Height; i++) { for (int j = 0; j < LinePixel; j++) { for (int ch = 0; ch < Channel; ch++) fptr[(ch * Height + i) * Width + j] = uptr[(i * LinePixel + j) * Channel + ch]; } } /* { cv::Mat im(someborderimg.size(), CV_32F, fptr, Width * sizeof(float)); cv::Mat write_iamge; im.convertTo(write_iamge, CV_8U, 255.0); im.release(); if (!cv::imwrite("test_in.png", write_iamge)) return eWaifu2xError_FailedOpenOutputFile; } */ } } } } assert(input_blob->count() == input_block_plane_size * processNum); // ネットワークに画像を入力 input_blob->set_cpu_data(input_block); // 計算 auto out = net->ForwardPrefilled(nullptr); auto b = out[0]; assert(b->count() == output_block_plane_size * processNum); const float *ptr = nullptr; if (caffe::Caffe::mode() == caffe::Caffe::CPU) ptr = b->cpu_data(); else ptr = b->gpu_data(); caffe::caffe_copy(output_block_plane_size * processNum, ptr, output_block); for (int n = 0; n < processNum; n++) { const int wn = (num + n) % WidthNum; const int hn = (num + n) / WidthNum; const int w = wn * output_size; const int h = hn * output_size; const float *fptr = output_block + (output_block_plane_size * n); // 結果を出力画像にコピー if (outim.channels() == 1) { for (int i = 0; i < crop_size; i++) memcpy(imptr + (h + i) * Line + w, fptr + (i + output_padding) * output_block_size + output_padding, crop_size * sizeof(float)); } else { const auto LinePixel = outim.step1() / outim.channels(); const auto Channel = outim.channels(); for (int i = 0; i < crop_size; i++) { for (int j = 0; j < crop_size; j++) { for (int ch = 0; ch < Channel; ch++) imptr[((h + i) * LinePixel + (w + j)) * Channel + ch] = fptr[(ch * output_block_size + i + output_padding) * output_block_size + j + output_padding]; } } /* { cv::Mat im(someborderimg.size(), CV_32F, fptr, Width * sizeof(float)); cv::Mat write_iamge; im.convertTo(write_iamge, CV_8U, 255.0); im.release(); if (!cv::imwrite("test_in.png", write_iamge)) return eWaifu2xError_FailedOpenOutputFile; } */ } } } } catch (...) { return eWaifu2xError_FailedProcessCaffe; } im = outim; return eWaifu2xError_OK; }
void RenderChar (double timestep) { if (!must_render) return; bool is_visible = false; check_gl_error(); // ------------- 3d scenery --------------------------------------- set_gl_options (TUX); ClearRenderContext (colDDBackgr); TestChar.highlight_node = TestChar.GetNodeName (curr_node); glLoadIdentity (); glPushMatrix (); SetToolLight (); TestChar.ResetRoot (); TestChar.ResetJoints (); glTranslatef (xposition, yposition, zposition); glRotatef (xrotation, 1, 0, 0); glRotatef (yrotation, 0, 1, 0); glRotatef (zrotation, 0, 0, 1); if (drawcount > 0) TestChar.Draw (); glPopMatrix (); drawcount++; // --------------- 2d screen -------------------------------------- SetupGuiDisplay (); set_gl_options (TEXFONT); FT.SetFont ("bold"); FT.SetSize (20); FT.SetColor (colYellow); FT.DrawString (-1, 10, "Edit mode"); if (CharHasChanged ()) DrawChanged (); FT.SetFont ("normal"); FT.SetSize (16); int xl, yt; for (int i=0; i<=lastnode; i++) { if (i != curr_node) { FT.SetColor (colLGrey); FT.SetFont ("normal"); } else { FT.SetColor (colYellow); FT.SetFont ("bold"); } xl = ITrunc (i, charbase) * 100 + 20; yt = IFrac (i, charbase) * 18 + 60; FT.DrawString (xl, yt, TestChar.GetNodeJoint (i)); } int num = action->num; int type; if (num > 0) { for (int i=0; i<num; i++) { is_visible = false; type = action->type[i]; yt = param.y_resolution - 120 + i * 18; switch (type) { case 0: DrawActionVec (i, "trans", yt, action->vec[i]); break; case 1: DrawActionFloat (i, "x-rot", yt, action->dval[i]); break; case 2: DrawActionFloat (i, "y-rot", yt, action->dval[i]); break; case 3: DrawActionFloat (i, "z-rot", yt, action->dval[i]); break; case 4: DrawActionVec (i, "scale", yt, action->vec[i]); break; case 5: DrawActionFloat (i, "vis", yt, action->dval[i]); is_visible = true; break; default: break; } } } if (is_visible) FT.SetColor (colYellow); else FT.SetColor (colLGrey); FT.DrawString (20, 20, action->name); if (ToolsFinalStage ()) { FT.SetSize (20); FT.SetColor (colYellow); FT.DrawString (-1, param.y_resolution - 50, "Quit program. Save character list (y/n)"); } Reshape (param.x_resolution, param.y_resolution); Winsys.SwapBuffers (); if (drawcount > 3) must_render = false; }
GlowWidget::AutoPackError GlowWidgetLabelWidget::OnAutoPack( int hSize, int vSize, AutoPackOptions hOption, AutoPackOptions vOption, int& leftMargin, int& rightMargin, int& topMargin, int& bottomMargin) { GLOW_DEBUGSCOPE("GlowWidgetLabelWidget::OnAutoPack"); int hnew = Width(); int pwidth = 0, pheight = 0; FindPreferredSize(pwidth, pheight); if (hSize != unspecifiedSize) { if (hSize < 2) { return hAutoPackError; } if (hSize < pwidth) { pwidth = hSize; } } if (hOption == forcedSize || hOption == expandPreferredSize) { hnew = hSize; } else if (hOption == preferredSize) { hnew = pwidth; } int vnew = Height(); if (vSize != unspecifiedSize) { if (vSize < 2) { return vAutoPackError; } if (vSize < pheight) { pheight = vSize; } } if (vOption == forcedSize || vOption == expandPreferredSize) { vnew = vSize; } else if (vOption == preferredSize) { vnew = pheight; } Reshape(hnew, vnew); return noAutoPackError; }
int SDLShell::Run(int argc, char *argv[]) { printf("*** %s, V%s ***\n", GetAppName(), GetAppVersion()); int done; Uint8 *keys; if (SDL_Init(SDL_INIT_VIDEO)) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 0; } ProcessCommandLine(argc, argv); if (!InitApp()) { Exit(EXIT_INIT_APP); } SDL_Surface *screen; if (Verbose(VerboseAll)) { printf("Setting width = %d, height = %d, bpp = %d\n", ShellGet(SDLShell::SHELL_WIDTH), ShellGet(SDLShell::SHELL_HEIGHT), ShellGet(SDLShell::SHELL_BPP)); } screen = SDL_SetVideoMode(ShellGet(SDLShell::SHELL_WIDTH), ShellGet(SDLShell::SHELL_HEIGHT), ShellGet(SDLShell::SHELL_BPP), Flags()); if (!screen) { fprintf(stderr, "Couldn't set %dx%d GL video mode: %s\n", ShellGet(SDLShell::SHELL_WIDTH), ShellGet(SDLShell::SHELL_HEIGHT), SDL_GetError()); Exit(EXIT_NO_SCREEN); } char tempString[100]; sprintf(tempString, "%s V%s", GetAppName(), GetAppVersion()); SDL_WM_SetCaption(tempString, GetAppName()); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, ShellGet(SHELL_VSYNC)); if (RequiresOpenGL2()) { // Initialize GLEW and make sure OpenGL 2.0 is supported GLenum err = glewInit(); if(GLEW_OK != err) { fprintf(stderr, "[ Fail ] - Error: %s\n", glewGetErrorString(err)); Exit(EXIT_NO_GL2_SUPPORT); } if(!GLEW_VERSION_2_0 && !(GLEW_ARB_shading_language_100 && GLEW_ARB_shader_objects && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)) { fprintf(stderr, "[ Fail ] - Shaders not supported\n"); Exit(EXIT_NO_GL2_SUPPORT); } if(!GLEW_ARB_vertex_buffer_object) { fprintf(stderr, "[ Fail ] - VBO objects are not supported\n"); Exit(EXIT_NO_GL2_SUPPORT); } } if (RequiresTTF()) { if (TTF_Init() == -1) { printf("Unable to initialize SDL_ttf: %s \n", TTF_GetError()); Exit(EXIT_NO_FONT); } } CreatePointer(); if (!InitGL()) { Exit(EXIT_INIT_GL); } done = 0; while (!done) { pPointer->Input(); ResetPressed(); ResetMouse(); SDL_Event event; while ( SDL_PollEvent(&event) ) { switch(event.type) { case SDL_VIDEORESIZE: if (ShellGet(SDLShell::SHELL_RESIZABLE)) { screen = SDL_SetVideoMode(event.resize.w, event.resize.h, ShellGet(SDLShell::SHELL_BPP), Flags()); if (screen) { Reshape(screen->w, screen->h); } else { /* Uh oh, we couldn't set the new video mode?? */; } } break; case SDL_MOUSEMOTION: pPointer->UpdateMouseMotion(event.motion); /*if (Verbose(VerboseAll)) { printf("Mouse moved by %d,%d to (%d,%d)\n", event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y); }*/ break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_WHEELDOWN) { scrollDown = true; } pPointer->UpdateMouseButton(event.button); /*if (Verbose(VerboseAll)) { printf("Mouse button %d pressed at (%d,%d)\n", event.button.button, event.button.x, event.button.y); }*/ break; case SDL_MOUSEBUTTONUP: if (event.button.button == SDL_BUTTON_WHEELUP) { scrollUp = true; } if (event.button.button == SDL_BUTTON_LEFT) { leftClick = true; } if (event.button.button == SDL_BUTTON_RIGHT) { rightClick = true; } pPointer->UpdateMouseButton(event.button); /*if (Verbose(VerboseAll)) { printf("Mouse button %d released at (%d,%d)\n", event.button.button, event.button.x, event.button.y); }*/ break; case SDL_KEYUP: SetPressed(event.key.keysym.scancode, false); SetPressing(event.key.keysym.scancode, false); break; case SDL_KEYDOWN: if (Verbose(VerboseInfo)) { printf("Pressed key %d\n", (int)event.key.keysym.scancode); } if (!KeyPressing(event.key.keysym.scancode)) { SetPressed(event.key.keysym.scancode, true); } SetPressing(event.key.keysym.scancode, true); break; case SDL_QUIT: done = 1; break; } } keys = SDL_GetKeyState(NULL); if (keys[SDLK_ESCAPE]) { done = 1; } if (!Render()) break; SDL_GL_SwapBuffers(); shellFrame++; } ReleaseGL(); ReleaseApp(); SDL_Quit(); return 0; /* ANSI C requires main to return int. */ }
InverseOperator::InverseOperator(const Operator& Op, const string Type, Teuchos::ParameterList& List) { Reshape(Op, Type, List); }
void InverseOperator::Reshape(const Operator& Op, const string Type) { Teuchos::ParameterList List; Reshape(Op, Type, List); }
InverseOperator::InverseOperator(const Operator& Op, const string Type) { Reshape(Op, Type); }
void Menu(int value) { GLint tmp_texture; switch (value) { // kompresja tekstur - GL_FASTEST case TEXTURE_COMPRESSION_FASTEST: { texture_compression_hint = GL_FASTEST; tmp_texture = texture; GenerateTextures(); texture = tmp_texture; DisplayScene(); } break; // kompresja tekstur - GL_DONT_CARE case TEXTURE_COMPRESSION_DONT_CARE: { texture_compression_hint = GL_DONT_CARE; tmp_texture = texture; GenerateTextures(); texture = tmp_texture; DisplayScene(); } break; // kompresja tekstur - GL_NICEST case TEXTURE_COMPRESSION_NICEST: { texture_compression_hint = GL_NICEST; tmp_texture = texture; GenerateTextures(); texture = tmp_texture; DisplayScene(); } break; // tekstura white_skin_guy_black_hairs case TEXTURE_LENA: { texture = LENA; DisplayScene(); } break; // teksura white_skin_guy_black_hairs nieskompresowana case TEXTURE_LENA_UNC: { texture = LENA_UNC; DisplayScene(); } break; // tekstura white_skin_guy_black_hairs_gray case TEXTURE_LENA_GRAY: { texture = LENA_GRAY; DisplayScene(); } break; // tekstura white_skin_guy_black_hairs_gray nieskompresowana case TEXTURE_LENA_GRAY_UNC: { texture = LENA_GRAY_UNC; DisplayScene(); } break; // obszar renderingu - całe okno case FULL_WINDOW: { aspect = FULL_WINDOW; Reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)); } break; // obszar renderingu - aspekt 1:1 case ASPECT_1_1: { aspect = ASPECT_1_1; Reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)); } break; // wyjście case EXIT: exit(0); } }
void Tensor<Dtype>::ReshapeLike(const Tensor<Dtype>& other) { Reshape(other.shape()); }
void CRFWithLossLayer<Dtype>::Forward_cpu( const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { //Some prerequisites Reshape(bottom, top); if(!for_training_) { // TODO viterbi decode } else { // Get input featue table, data pointers of parameter and auxilary spaces Dtype* ptr_alpha = alpha_.mutable_cpu_data(); Dtype* ptr_beta = beta_.mutable_cpu_data(); Dtype* ptr_epsilon = epsilon_.mutable_cpu_data(); Dtype* ptr_gamma = gamma_.mutable_cpu_data(); Dtype* ptr_buf_state_energy = buf_state_energy_.mutable_cpu_data(); Dtype* ptr_buf_feature = buf_feature_.mutable_cpu_data(); Dtype* ptr_buf_state = buf_state_.mutable_cpu_data(); const Dtype* feature_table = buf_bottom_transposed_.cpu_data(); const Dtype* pi = this->blobs_[0]->cpu_data(); const Dtype* tr = this->blobs_[1]->cpu_data(); const Dtype* mu = this->blobs_[2]->cpu_data(); // Get each block size of the param and buffer for bias computation needed when // doing matrix multiplication // size of feature table int ts = feature_num_ * max_seq_length_; // size of alpha, beta, gamma table int abgs = max_seq_length_ * state_num_; // size of epsilon table int eps = max_seq_length_ * state_num_ * state_num_; for (int i = 0; i < num_; ++i) { // In comments below we assume: // "*" means element-wise multiply; // "dot" means matrix multiply; // "'" means transpose operation; // and all these operations are of LogSumExp version // sl need to be reconsidered int sl = max_seq_length_; // Compute state energy table by lieaner combination of the feature weights at each // state held in mu matrix and the feature_table from the bottom blob: buf_state_energy = feature_table dot mu' caffe_cpu_mm_logP(CblasNoTrans, CblasTrans, max_seq_length_, state_num_, feature_num_, feature_table + i * ts, mu, ptr_buf_state_energy, ptr_buf_feature); // alpha(0) = pi * buf_state_energy(0) caffe_dmul_logP(state_num_, pi, 1, ptr_buf_state_energy, 1, ptr_alpha + i * abgs); // alpha(j) = alpha(j-1) dot T * buf_state_energy(j) for (int j = 1; j < sl; ++j) { caffe_cpu_mm_logP(CblasNoTrans, CblasNoTrans, 1, state_num_, state_num_, alpha_.cpu_data() + i * abgs + (j - 1) * state_num_, tr, ptr_alpha + i * abgs + j * state_num_, ptr_buf_state); caffe_dmul_logP(state_num_, alpha_.cpu_data() + i * abgs + j * state_num_, 1, ptr_buf_state_energy + j * state_num_ , 1, ptr_alpha + i * abgs + j * state_num_); } // Set beta(sl) as all log1 vector caffe_set(state_num_, (Dtype)0., ptr_beta + (sl - 1) * state_num_); // The value of partition function for this sequence(one Z_ for one instance in batch) double Z_; Dtype* ptr_Z = (Dtype*)&Z_; caffe_cpu_mm_logP(CblasNoTrans, CblasTrans, 1, 1, state_num_, alpha_.cpu_data() + i * abgs + (sl - 1) * state_num_, beta_.cpu_data() + i * abgs + (sl - 1) * state_num_, ptr_Z, ptr_buf_state); // Set gamma(sl) as alpha(sl) * beta(sl) caffe_dmul_logP(state_num_, alpha_.cpu_data() + i * abgs + (sl - 1) * state_num_, 1, beta_.cpu_data() + i * abgs + (sl - 1) * state_num_, 1, ptr_gamma + i * abgs + (sl - 1) * state_num_); // Then we iterately flow back to the beginning from the end for (int j = sl - 2; j >= 0; --j) { // At this step we just store beta(j+1) * state_energy(j) in beta(j) as a buffer for epsilon caffe_dmul_logP(state_num_, beta_.cpu_data() + i * abgs + (j + 1) * state_num_, 1, ptr_buf_state_energy + (j + 1) * state_num_, 1, ptr_beta + i * abgs + j * state_num_); // Compute the epsilon(j) = alpha(j)' dot ( beta(j+1) * state_energy(j) ) double buf_ep; Dtype* ptr_buf_ep = (Dtype*)&buf_ep; caffe_cpu_mm_logP(CblasTrans, CblasNoTrans, state_num_, state_num_, 1, alpha_.cpu_data() + i * abgs + (j - 1) * state_num_, beta_.cpu_data() + i * abgs + j * state_num_, ptr_epsilon + i * eps + j * state_num_ * state_num_, ptr_buf_ep); // Continue to finish the computation in beta(j) = tr dot ( beta(j+1) * state_energy(j) ) caffe_cpu_mm_logP(CblasNoTrans, CblasTrans, state_num_, 1, state_num_, tr, beta_.cpu_data() + i * abgs + j * state_num_, ptr_beta + i * abgs + j * state_num_, ptr_buf_state); // Compute the gamma(j) = beta(j) * alpha(j) caffe_dmul_logP(state_num_, alpha_.cpu_data() + j * state_num_ , 1, beta_.cpu_data() + i * abgs + j * state_num_, 1, ptr_gamma + i * abgs + j * state_num_); } //nomalize for (int j = 0; j < sl; ++j) { for (int k = 0; k < state_num_; ++k) *(ptr_gamma + i * abgs + j * max_seq_length_ + k) -= Z_; if ( j >= sl - 1) continue; for (int k = 0; k < state_num_ * state_num_; ++k) *(ptr_epsilon + i * eps + j * max_seq_length_ + k) -= Z_; } // exponential to probability caffe_exp(abgs, gamma_.cpu_data() + i * abgs, ptr_gamma + i * abgs); caffe_exp(eps, epsilon_.cpu_data() + i * eps, ptr_epsilon + i * eps); } } }
void piglit_init(int argc, char **argv) { GLubyte data[256][256][4]; int x,y; static const char *fragProgramText = "!!ARBfp1.0\n" "# $Id$\n" "# Copyright (C) 2006 Oliver McFadden <*****@*****.**>\n" "#\n" "# This program is free software; you can redistribute it and/or modify\n" "# it under the terms of the GNU General Public License as published by\n" "# the Free Software Foundation; either version 2 of the License, or\n" "# (at your option) any later version.\n" "#\n" "# This program is distributed in the hope that it will be useful,\n" "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n" "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" "# GNU General Public License for more details.\n" "#\n" "# You should have received a copy of the GNU General Public License\n" "# along with this program; if not, write to the Free Software\n" "# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" "TEMP H, L, N, V, attenuationxy, attenuationz, color, diffuse, dot, specular, tmp;\n" "DP3 L.x, fragment.texcoord[4], fragment.texcoord[4];\n" "RSQ L.x, L.x;\n" "MUL L.xyz, L.x, fragment.texcoord[4];\n" "DP3 V.x, fragment.texcoord[5], fragment.texcoord[5];\n" "RSQ V.x, V.x;\n" "MUL V.xyz, V.x, fragment.texcoord[5];\n" "ADD tmp, L, V;\n" "DP3 H.x, tmp, tmp;\n" "RSQ H.x, H.x;\n" "MUL H.xyz, H.x, tmp;\n" "TEX tmp.xyz, fragment.texcoord[1], texture[1], 2D;\n" "MAD tmp.xyz, tmp, 2.0, -1.0;\n" "DP3 N.x, tmp, tmp;\n" "RSQ N.x, N.x;\n" "MUL N.xyz, N.x, tmp;\n" "DP3_SAT dot.x, N, L;\n" "MUL dot.xyz, program.local[0], dot.x;\n" "TEX diffuse.xyz, fragment.texcoord[0], texture[0], 2D;\n" "DP3_SAT tmp.x, N, H;\n" "POW tmp.x, tmp.x, program.local[2].x;\n" "TEX specular.xyz, fragment.texcoord[2], texture[2], 2D;\n" "MUL specular.xyz, specular, program.local[0];\n" "MUL specular.xyz, specular, tmp.x;\n" "TEX attenuationxy.xyz, fragment.texcoord[3], texture[3], 2D;\n" "MOV tmp.x, fragment.texcoord[3].z;\n" "MOV tmp.y, 0;\n" "TEX attenuationz.xyz, tmp, texture[4], 2D;\n" "MOV color, diffuse;\n" "MUL color.xyz, color, dot;\n" "ADD color.xyz, color, specular;\n" "MUL color.xyz, color, attenuationxy;\n" "MUL color.xyz, color, attenuationz;\n" "MUL color.xyz, color, program.local[1].x;\n" "MOV result.color, color;\n" "END"; piglit_require_gl_version(13); printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); piglit_require_fragment_program(); FragProg = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, fragProgramText); /* * Initialize textures */ // Diffuse for(y = 0; y < 256; ++y) { for(x = 0; x < 256; ++x) { data[y][x][0] = 255; // 1.0 data[y][x][1] = 192; // 0.75 data[y][x][2] = 255; // 1.0 data[y][x][3] = 0; } } glBindTexture(GL_TEXTURE_2D, TexDiffuse); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); // Normal for(y = 0; y < 256; ++y) { for(x = 0; x < 256; ++x) { data[y][x][0] = 255; // 1.0 data[y][x][1] = 0; // 0.0 data[y][x][2] = 0; // 0.0 data[y][x][3] = 0; } } glBindTexture(GL_TEXTURE_2D, TexNormal); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); // Specular for(y = 0; y < 256; ++y) { for(x = 0; x < 256; ++x) { data[y][x][0] = 255; // 1.0 data[y][x][1] = 255; // 1.0 data[y][x][2] = 192; // 0.75 data[y][x][3] = 0; } } glBindTexture(GL_TEXTURE_2D, TexSpecular); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); // Lookup texture for(y = 0; y < 256; ++y) { for(x = 0; x < 256; ++x) { data[y][x][0] = 255-x; data[y][x][1] = 255-y; data[y][x][2] = 255; data[y][x][3] = 0; } } glBindTexture(GL_TEXTURE_2D, TexLookup); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); Reshape(piglit_width, piglit_height); }
Eigen::MatrixXd ComputeP_NormalizedDLT(const Point2DVector& points2D, const Point3DVector& points3D) { unsigned int numberOfPoints = points2D.size(); if(points3D.size() != numberOfPoints) { std::stringstream ss; ss << "ComputeP_NormalizedDLT: The number of 2D points (" << points2D.size() << ") must match the number of 3D points (" << points3D.size() << ")!" << std::endl; throw std::runtime_error(ss.str()); } // std::cout << "ComputeP_NormalizedDLT: 2D points: " << std::endl; // for(Point2DVector::const_iterator iter = points2D.begin(); iter != points2D.end(); ++iter) // { // Point2DVector::value_type p = *iter; // std::cout << p[0] << " " << p[1] << std::endl; // } // std::cout << "ComputeP_NormalizedDLT: 3D points: " << std::endl; // for(Point3DVector::const_iterator iter = points3D.begin(); iter != points3D.end(); ++iter) // { // Point3DVector::value_type p = *iter; // std::cout << p[0] << " " << p[1] << " " << p[2] << std::endl; // } Eigen::MatrixXd similarityTransform2D = ComputeNormalizationTransform<Eigen::Vector2d>(points2D); Eigen::MatrixXd similarityTransform3D = ComputeNormalizationTransform<Eigen::Vector3d>(points3D); // std::cout << "Computed similarity transforms:" << std::endl; // std::cout << "similarityTransform2D: " << similarityTransform2D << std::endl; // std::cout << "similarityTransform3D: " << similarityTransform3D << std::endl; // The (, Eigen::VectorXd()) below are only required when using gnu++0x, it seems to be a bug in Eigen Point2DVector transformed2DPoints(numberOfPoints, Eigen::Vector2d()); Point3DVector transformed3DPoints(numberOfPoints, Eigen::Vector3d()); for(unsigned int i = 0; i < numberOfPoints; ++i) { Eigen::VectorXd point2Dhomogeneous = points2D[i].homogeneous(); Eigen::VectorXd point2Dtransformed = similarityTransform2D * point2Dhomogeneous; transformed2DPoints[i] = point2Dtransformed.hnormalized(); Eigen::VectorXd point3Dhomogeneous = points3D[i].homogeneous(); Eigen::VectorXd point3Dtransformed = similarityTransform3D * point3Dhomogeneous; transformed3DPoints[i] = point3Dtransformed.hnormalized(); //transformed2DPoints[i] = (similarityTransform2D * points2D[i].homogeneous()).hnormalized(); //transformed3DPoints[i] = (similarityTransform3D * points3D[i].homogeneous()).hnormalized(); } // std::cout << "Transformed points." << std::endl; // Compute the Camera Projection Matrix Eigen::MatrixXd A(2*numberOfPoints,12); for(unsigned int i = 0; i < numberOfPoints; ++i) { // First row/equation from the ith correspondence unsigned int row = 2*i; A(row, 0) = 0; A(row, 1) = 0; A(row, 2) = 0; A(row, 3) = 0; A(row, 4) = transformed3DPoints[i](0); A(row, 5) = transformed3DPoints[i](1); A(row, 6) = transformed3DPoints[i](2); A(row, 7) = 1; A(row, 8) = -transformed2DPoints[i](1) * transformed3DPoints[i](0); A(row, 9) = -transformed2DPoints[i](1) * transformed3DPoints[i](1); A(row, 10) = -transformed2DPoints[i](1) * transformed3DPoints[i](2); A(row, 11) = -transformed2DPoints[i](1); // Second row/equation from the ith correspondence row = 2*i+1; A(row, 0) = transformed3DPoints[i](0); A(row, 1) = transformed3DPoints[i](1); A(row, 2) = transformed3DPoints[i](2); A(row, 3) = 1; A(row, 4) = 0; A(row, 5) = 0; A(row, 6) = 0; A(row, 7) = 0; A(row, 8) = -transformed2DPoints[i](0) * transformed3DPoints[i](0); A(row, 9) = -transformed2DPoints[i](0) * transformed3DPoints[i](1); A(row, 10) = -transformed2DPoints[i](0) * transformed3DPoints[i](2); A(row, 11) = -transformed2DPoints[i](0); } // std::cout << "A: " << A << std::endl; Eigen::JacobiSVD<Eigen::MatrixXd> svd(A, Eigen::ComputeFullU | Eigen::ComputeFullV); Eigen::MatrixXd V = svd.matrixV(); Eigen::MatrixXd lastColumnOfV = V.col(11); Eigen::MatrixXd P = Reshape(lastColumnOfV, 3, 4); // Denormalization P = similarityTransform2D.inverse()*P*similarityTransform3D; // 3x3 * 3x4 * 4x4 = 4x4 return P; }
void Blob<Dtype>::ReshapeWithoutAllocation(const int num, const int channels, const int height, const int width) { // call Reshap() directly since SyncedMemory allocates memory lazily Reshape(num, channels, height, width); }
int main(int argc, char** argv) { if (freenect_init(&f_ctx, NULL) < 0) { printf("freenect_init() failed\n"); return 1; } freenect_set_log_level(f_ctx, FREENECT_LOG_INFO); freenect_select_subdevices(f_ctx, FREENECT_DEVICE_AUDIO); int nr_devices = freenect_num_devices (f_ctx); printf ("Number of devices found: %d\n", nr_devices); if (nr_devices < 1) { freenect_shutdown(f_ctx); return 1; } int user_device_number = 0; if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) { printf("Could not open device\n"); freenect_shutdown(f_ctx); return 1; } state.max_samples = 256 * 60; state.current_idx = 0; state.buffers[0] = (int32_t*)malloc(state.max_samples * sizeof(int32_t)); state.buffers[1] = (int32_t*)malloc(state.max_samples * sizeof(int32_t)); state.buffers[2] = (int32_t*)malloc(state.max_samples * sizeof(int32_t)); state.buffers[3] = (int32_t*)malloc(state.max_samples * sizeof(int32_t)); memset(state.buffers[0], 0, state.max_samples * sizeof(int32_t)); memset(state.buffers[1], 0, state.max_samples * sizeof(int32_t)); memset(state.buffers[2], 0, state.max_samples * sizeof(int32_t)); memset(state.buffers[3], 0, state.max_samples * sizeof(int32_t)); freenect_set_user(f_dev, &state); freenect_set_audio_in_callback(f_dev, in_callback); freenect_start_audio(f_dev); int res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL); if (res) { printf("pthread_create failed\n"); freenect_shutdown(f_ctx); return 1; } printf("This is the libfreenect microphone waveform viewer. Press 'q' to quit or spacebar to pause/unpause the view.\n"); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA ); glutInitWindowSize(800, 600); glutInitWindowPosition(0, 0); window = glutCreateWindow("Microphones"); glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Reshape(800, 600); glutReshapeFunc(Reshape); glutDisplayFunc(DrawMicData); glutIdleFunc(DrawMicData); glutKeyboardFunc(Keyboard); glutMainLoop(); return 0; }
int main(int, char **) { int argc = 2; const char* argv[] = { "main", "-glDebug" }; glutInit(&argc, const_cast<char**>(&argv[0])); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(g_winWidth, g_winHeight); glutInitWindowPosition(0, 0); g_win = glutCreateWindow(argv[0]); #ifndef __APPLE__ glewInit(); if (!glewIsSupported("GL_VERSION_2_0")) { std::cout << "OpenGL 2.0 not supported" << std::endl; exit(1); } #endif // Step 1: Initilize the OpenGL engine glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment #ifndef __APPLE__ glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE); // glClampColor(GL_CLAMP_VERTEX_COLOR, GL_FALSE); // avoid any kind of clamping glClampColor(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE); // #endif glEnable(GL_TEXTURE_2D); glClearColor(0, 0, 0, 0); // background color glClearStencil(0); // clear stencil buffer // Step 2: Allocate the needed textures AllocateImageTexture(); AllocateDefaultLut3D(); // Step 3: Create the frame buffer and render buffer GLuint fboId; // create a framebuffer object, you need to delete them when program exits. glGenFramebuffers(1, &fboId); glBindFramebuffer(GL_FRAMEBUFFER, fboId); GLuint rboId; // create a renderbuffer object to store depth info glGenRenderbuffers(1, &rboId); glBindRenderbuffer(GL_RENDERBUFFER, rboId); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA32F_ARB, g_winWidth, g_winHeight); glBindRenderbuffer(GL_RENDERBUFFER, 0); // attach a texture to FBO color attachement point glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, g_imageTexID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_3D, g_lut3dTexID, 0); // attach a renderbuffer to depth attachment point glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rboId); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Step 4: Execute all the unit tests unsigned failures = 0; const UnitTests & tests = GetUnitTests(); const size_t numTests = tests.size(); for(size_t idx=0; idx<numTests; ++idx) { OCIOGPUTest* test = tests[idx]; test->setup(); const unsigned curr_failures = failures; // Set the rendering destination to FBO glBindFramebuffer(GL_FRAMEBUFFER, fboId); // Clear buffer glClearColor(0.1f, 0.1f, 0.1f, 0.1f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); std::cerr << "Test [" << test->group() << "] [" << test->name() << "] - "; try { // Update the image texture UpdateImageTexture(); // Update the GPU shader program UpdateOCIOGLState(test->getProcessor()); // Enable the shader program, and its textures glUseProgram(g_program); glUniform1i(glGetUniformLocation(g_program, "tex1"), 1); glUniform1i(glGetUniformLocation(g_program, "tex2"), 2); // Process the image texture into the rendering buffer Reshape(); Redisplay(); // Validate the processed image using the rendering buffer ValidateImageTexture(test->getProcessor(), test->getErrorThreshold()); } catch(OCIO::Exception & ex) { ++failures; std::cerr << "FAILED - " << ex.what() << std::endl; } catch(...) { ++failures; std::cerr << "FAILED - Unexpected error" << std::endl; } if(curr_failures==failures) { std::cerr << "PASSED" << std::endl; } glUseProgram(0); glBindFramebuffer(GL_FRAMEBUFFER, 0); } std::cerr << std::endl << failures << " tests failed" << std::endl << std::endl; }
BOOL CreateGLWindow(char* title, int width, int height, int bit, bool fullScreenFlag) { GLuint PixelFormat; WNDCLASS wc; DWORD dwExStyle; DWORD dwStyle; RECT WindowRect; WindowRect.left = 0; WindowRect.right = width; WindowRect.top = 0; WindowRect.bottom = height; fullscreen = fullScreenFlag; hInstance = GetModuleHandle(NULL); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = L"OpenGL"; RegisterClass(&wc); dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; AdjustWindowRectEx(&WindowRect, dwStyle, NULL, dwExStyle); hWnd = CreateWindowEx(dwExStyle, L"OpenGL", (LPCWSTR)title, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN , 0, 0, WindowRect.right, WindowRect.bottom, NULL, NULL, hInstance, NULL); static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 24, 0,0,0,0,0,0, 0, 0, 0, 0, 32, 0, 0, PFD_MAIN_PLANE, 0, 0,0,0 }; hDC = GetDC(hWnd); PixelFormat = ChoosePixelFormat(hDC, &pfd); SetPixelFormat(hDC, PixelFormat, &pfd); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); //调用opemGL API Reshape(width, height); init(); return TRUE; }
bool Blob<Dtype>::ReshapeLike(const Blob<Dtype>& other) { return Reshape(other.shape()); }
Blob<Dtype>::Blob(const int num, const int channels, const int height, const int width) // capacity_ must be initialized before calling Reshape : capacity_(0) { Reshape(num, channels, height, width); }
Blob<Dtype>::Blob(const vector<int>& shape, device *device_context) // capacity_ must be initialized before calling Reshape : capacity_(0), device_(device_context) { Reshape(shape); }
///---------------------------------------------------------------------------- ///Initialize OpenGL graphic device context. ///---------------------------------------------------------------------------- void GLApp::InitGraphics() { GLuint PixelFormat; //this will hold the actual pixel format PIXELFORMATDESCRIPTOR pfd; //structure to maintain pixel format information //about our GL window //clear our PIXELFORMATDESCRIPTOR structure memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); //the size of this data structure pfd.nVersion = 1; //this value should be set to 1! pfd.dwFlags = PFD_DRAW_TO_WINDOW | //the buffer can draw to a window or DC PFD_SUPPORT_OPENGL | //the buffer supports OpenGL drawing PFD_DOUBLEBUFFER; //the buffer is double-buffered pfd.iPixelType = PFD_TYPE_RGBA; //RGBA pixels pfd.cColorBits = 32; //number of color bitplanes in each color buffer pfd.cDepthBits = 24; //depth of the deph (z-axis) buffer //get the window device context m_hDC = GetDC(m_hWnd); //we should select a pixel format in the device //context before calling wglCreateContext PixelFormat = ChoosePixelFormat(m_hDC, &pfd); SetPixelFormat(m_hDC, PixelFormat, &pfd); DescribePixelFormat(m_hDC, PixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); //creates a new OpenGL rendering context, which is //suitable for drawing on the device referenced by m_hDC m_hRC = wglCreateContext(m_hDC); if(wglMakeCurrent(m_hDC, m_hRC) == FALSE) { MessageBox(NULL, "Could not set the current window context!", "ERROR", MB_OK | MB_ICONEXCLAMATION); //exit the program with an error code exit(-1); } //initialize the viewport Reshape(m_Width, m_Height); //set lights, materials & textures GLfloat lightPos[3] = {-5.0, 10.0, 6.0}; m_Geometry.SetLights(lightPos); m_Geometry.SetMaterials(); m_Geometry.SetShadowTexture(); //set camera position GLfloat cameraPos[3] = {5.0, 5.0, 5.0}; m_Geometry.SetCameraPosition(cameraPos); //calculate & save matrices for later use, //select modelview as temporal matrix glMatrixMode(GL_MODELVIEW); glPushMatrix(); { //camera projection matrix glLoadIdentity(); gluPerspective(45.0f, (float)m_Width/m_Height, 1.0f, 100.0f); glGetDoublev(GL_MODELVIEW_MATRIX, m_CameraProjectionMatrix); //camera modelview matrix glLoadIdentity(); gluLookAt(cameraPos[0], cameraPos[1], cameraPos[2], 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glGetDoublev(GL_MODELVIEW_MATRIX, m_CameraViewMatrix); //light projection matrix glLoadIdentity(); gluPerspective(45.0f, 1.0f, 1.0, 100.0f); glGetDoublev(GL_MODELVIEW_MATRIX, m_LightProjectionMatrix); //light modelview matrix glLoadIdentity(); gluLookAt(lightPos[0], lightPos[1], lightPos[2], 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glGetDoublev(GL_MODELVIEW_MATRIX, m_LightViewMatrix); } glPopMatrix(); //enable needed states glEnable(GL_DEPTH_TEST); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); }
GlowWidget::AutoPackError GlowQuickRadioGroupWidget::OnAutoPack( int hSize, int vSize, AutoPackOptions hOption, AutoPackOptions vOption, int& leftMargin, int& rightMargin, int& topMargin, int& bottomMargin) { GLOW_DEBUGSCOPE("GlowQuickRadioGroupWidget::OnAutoPack"); // Pack buttons int position = 0; int size = 0; for (GlowComponent* child = FirstChild(); child != 0; child = child->Next()) { GlowRadioButtonWidget* button = dynamic_cast<GlowRadioButtonWidget*>(child); if (button != 0 && button->IsVisible() && !button->IsClosing()) { if (arrangement_ == GlowQuickPalette::horizontal) { button->AutoPack(position, unspecifiedPos, 0, unspecifiedPos, leftPos | preferredSize, topPos | preferredSize); if (size < button->Height()) { size = button->Height(); } position += button->Width()+spacing_; } else { button->AutoPack(0, unspecifiedPos, position, unspecifiedPos, leftPos | preferredSize, topPos | preferredSize); if (size < button->Width()) { size = button->Width(); } position += button->Height()+spacing_; } } } // Preferred width and height int pwidth = 0, pheight = 0; if (arrangement_ == GlowQuickPalette::horizontal) { pwidth = position-spacing_; pheight = size; } else { pwidth = size; pheight = position-spacing_; } int hnew = Width(); if (hSize != unspecifiedSize && hSize < pwidth) { return hAutoPackError; } if (hOption == forcedSize || hOption == expandPreferredSize) { hnew = hSize; } else if (hOption == preferredSize) { hnew = pwidth; } int vnew = Height(); if (vSize != unspecifiedSize && vSize < pheight) { return vAutoPackError; } if (vOption == forcedSize || vOption == expandPreferredSize) { vnew = vSize; } else if (vOption == preferredSize) { vnew = pheight; } Reshape(hnew, vnew); return noAutoPackError; }
Blob<Dtype>::Blob(const int num, const int channels, const int height, const int width) { Reshape(num, channels, height, width); }
GlowWidget::AutoPackError GlowQuickPanelWidget::OnAutoPack( int hSize, int vSize, AutoPackOptions hOption, AutoPackOptions vOption, int& leftMargin, int& rightMargin, int& topMargin, int& bottomMargin) { GLOW_DEBUGSCOPE("GlowQuickPanelWidget::OnAutoPack"); int position = (arrangement_ == vertical) ? vmargin_ : hmargin_; int size = 0; int minWidth = position; // Arrange widgets with default alignment for (GlowComponent* child = FirstChild(); child != 0; child = child->Next()) { // Get next widget GlowWidget* widget = dynamic_cast<GlowWidget*>(child); if (widget == 0 || !widget->IsVisible() || widget->IsClosing()) { continue; } // Handle the label of the panel (if any) differently. if (widget == label_) { if (GetStyle() == GlowPanelWidget::etchedStyle) { // Etched style: label is half in and half out of the panel widget->AutoPack(hmargin_, unspecifiedPos, 0, unspecifiedPos, leftPos | preferredSize, centerPos | preferredSize); topMargin = widget->Height()/2; if (arrangement_ == vertical) { position += widget->Height()/2; } } else { // Other style: label is completely out of the panel widget->AutoPack(hmargin_, unspecifiedPos, unspecifiedPos, 0, leftPos | preferredSize, bottomPos | preferredSize); topMargin = widget->Height(); } minWidth = widget->Width()+hmargin_+hmargin_; continue; } int leftMargin = 0, rightMargin = 0, topMargin = 0, bottomMargin = 0; if (arrangement_ == horizontal) { widget->AutoPack(position, unspecifiedPos, vmargin_, unspecifiedPos, leftPos | preferredSize, topPos | preferredSize, leftMargin, rightMargin, topMargin, bottomMargin); size = GLOW_STD::max(size, widget->Height()+topMargin+bottomMargin); position += widget->Width()+leftMargin+rightMargin+spacing_; } else { widget->AutoPack(hmargin_, unspecifiedPos, position, unspecifiedPos, leftPos | preferredSize, topPos | preferredSize, leftMargin, rightMargin, topMargin, bottomMargin); size = GLOW_STD::max(size, widget->Width()+leftMargin+rightMargin); position += widget->Height()+topMargin+bottomMargin+spacing_; } } // Preferred width and height int pwidth = 0, pheight = 0; if (arrangement_ == horizontal) { pwidth = GLOW_STD::max(minWidth, position-spacing_+hmargin_); pheight = size+vmargin_+vmargin_; } else { pwidth = GLOW_STD::max(minWidth, size+hmargin_+hmargin_); pheight = position-spacing_+vmargin_; } // Panel width int hnew = Width(); if (hOption == forcedSize || hOption == expandPreferredSize) { hnew = hSize; } else if (hOption == preferredSize) { hnew = pwidth; } if (hnew < pwidth) { return hAutoPackError; } // Panel height int vnew = Height(); if (vOption == forcedSize || vOption == expandPreferredSize) { vnew = vSize-topMargin; // because of label } else if (vOption == preferredSize) { vnew = pheight; } if (vnew < pheight) { return vAutoPackError; } // Update size if (arrangement_ == horizontal) { size = vnew-vmargin_-vmargin_; } else { size = hnew-hmargin_-hmargin_; } // Now align contents int i=0; for (GlowComponent* child = FirstChild(); child != 0; child = child->Next(), ++i) { GlowWidget* widget = dynamic_cast<GlowWidget*>(child); if (widget == 0 || widget == label_ || !widget->IsVisible()) { continue; } if (arrangement_ == horizontal) { // Horizontal arrangement AutoPackOptions vOption = (alignment_ & alignExpand) ? expandPreferredSize : preferredSize; if ((alignment_ & 3) == alignBottom) { vOption |= bottomPos; } else if ((alignment_ & 3) == alignCenter) { vOption |= centerPos; } else { vOption |= topPos; } widget->AutoPack(unspecifiedPos, unspecifiedPos, vmargin_, vmargin_+size, noMove | noReshape, vOption); } else { // Vertical arrangement AutoPackOptions hOption = (alignment_ & alignExpand) ? expandPreferredSize : preferredSize; if ((alignment_ & 3) == alignLeft) { hOption |= leftPos; } else if ((alignment_ & 3) == alignCenter) { hOption |= centerPos; } else { hOption |= rightPos; } widget->AutoPack(hmargin_, hmargin_+size, unspecifiedPos, unspecifiedPos, hOption, noMove | noReshape); } } Reshape(hnew, vnew); return noAutoPackError; }
void Blob<Dtype>::ReshapeLike(const Blob<Dtype>& other) { Reshape(other.num(), other.channels(), other.height(), other.width(), other.depth()); }
void CGameConfig::Loop () { int ww = Winsys.resolution.width; int hh = Winsys.resolution.height; Music.Update (); check_gl_error(); Music.Update (); ScopedRenderMode rm(GUI); ClearRenderContext (); SetupGuiDisplay (); if (param.ui_snow) { update_ui_snow (); draw_ui_snow(); } Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), 1.0); Tex.Draw (BOTTOM_LEFT, 0, hh-256, 1); Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); Tex.Draw (TOP_LEFT, 0, 0, 1); Tex.Draw (TOP_RIGHT, ww-256, 0, 1); // DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top, // 0, colMBackgr, colBlack, 0.2); FT.AutoSizeN (4); #ifndef PANDORA if (resolution->focussed()) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd, Trans.Text(32)); #endif if (mus_vol->focussed()) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd*2, Trans.Text(33)); if (sound_vol->focussed()) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd*3, Trans.Text(34)); if (detail_level->focussed()) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd*4, Trans.Text(36)); if (language->focussed()) FT.SetColor (colDYell); else FT.SetColor (colWhite); FT.DrawString (area.left, area.top + dd*5, Trans.Text(35)); FT.SetColor (colWhite); #ifndef PANDORA FT.DrawString (area.left+240, area.top + dd, res_names[resolution->GetValue()]); #endif FT.DrawString (area.left+240, area.top + dd*2, Int_StrN (mus_vol->GetValue())); FT.DrawString (area.left+240, area.top + dd*3, Int_StrN (sound_vol->GetValue())); FT.DrawString (area.left+240, area.top + dd*4, Int_StrN (detail_level->GetValue())); FT.DrawString (area.left+240, area.top + dd*5, Trans.languages[language->GetValue()].language); #if defined (_WIN32) if (fullscreen->checked != param.fullscreen) { FT.SetColor (colDYell); FT.AutoSizeN (4); FT.DrawString (CENTER, AutoYPosN (68), Trans.Text(84)); FT.DrawString (CENTER, AutoYPosN (72), Trans.Text(85)); } else { FT.SetColor (colLGrey); FT.AutoSizeN (3); FT.DrawString (CENTER, AutoYPosN (68), Trans.Text(41)); FT.DrawString (CENTER, AutoYPosN (72), Trans.Text(42)); } #else #ifndef PANDORA FT.SetColor (colWhite); FT.AutoSizeN (3); FT.DrawString (CENTER, AutoYPosN (68), Trans.Text(41)); FT.DrawString (CENTER, AutoYPosN (72), Trans.Text(42)); #endif #endif DrawGUI(); Reshape (ww, hh); Winsys.SwapBuffers (); }