Exemplo n.º 1
0
//----------------------------------------------------------------------------
medGUITransformSliders::medGUITransformSliders(mafVME *input, double translationRange[6], mafObserver *listener /* = NULL */, bool enableScaling /* = true */,bool testMode /* = false */)
//----------------------------------------------------------------------------
{
  assert(input);

  m_EnableScaling = enableScaling;
  m_CurrentTime = -1;
  m_Listener = listener;
  m_InputVME = input;
  m_Gui = NULL;
  m_TestMode = testMode;

  m_RefSysVME = m_InputVME;

  m_Position[0] = m_Position[1] = m_Position[2] = 0;
  m_Orientation[0] = m_Orientation[1] = m_Orientation[2] = 0;
  m_Scaling[0] = m_Scaling[1] = m_Scaling[2] = 1; 
  
  for(int i=0;i<6;i++)
    m_TranslationRange[i] = translationRange[i];

  m_CurrentTime = m_InputVME->GetTimeStamp();

  if (!m_TestMode)
  {
  	CreateGui();
  }
  SetAbsPose(m_InputVME->GetOutput()->GetAbsMatrix());

  mafNEW(m_OldAbsMatrix);
  m_OldAbsMatrix->DeepCopy(m_InputVME->GetOutput()->GetAbsMatrix());
}
Exemplo n.º 2
0
//----------------------------------------------------------------------------
// Constants:
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void medOpSubdivide::OpRun()   
//----------------------------------------------------------------------------
{
  mafVMESurface *surface = mafVMESurface::SafeDownCast(m_Input);
  surface->Update();

  vtkPolyData *polydataInput = vtkPolyData::SafeDownCast(surface->GetOutput()->GetVTKData());
  polydataInput->Update();

  vtkNEW(m_OriginalPolydata);
  m_OriginalPolydata->DeepCopy(polydataInput);
  m_OriginalPolydata->Update();

  vtkNEW(m_ResultPolydata);
  m_ResultPolydata->DeepCopy(polydataInput);
  m_ResultPolydata->Update();

  for(int i=0;i<polydataInput->GetNumberOfCells();i++)
  {
    if(polydataInput->GetCell(i)->GetNumberOfPoints()!=3)
    {
      if(m_TestMode == false)
        wxMessageBox(_("The mesh will be triangolarized to be subdivide"));

      vtkTriangleFilter *triangleFilter;
      vtkNEW(triangleFilter);

      triangleFilter->SetInput(polydataInput);
      triangleFilter->Update();

      surface->SetData(triangleFilter->GetOutput(),surface->GetTimeStamp());
      surface->Update();

      m_ResultPolydata->DeepCopy(triangleFilter->GetOutput());
      m_ResultPolydata->Update();

      vtkDEL(triangleFilter);

      break;
    }
  }

  if(m_TestMode == false)
    CreateGui();
}
Exemplo n.º 3
0
//----------------------------------------------------------------------------
void medOpMove::OpRun()
//----------------------------------------------------------------------------
{
  // progress bar stuff
  if (!m_TestMode)
  {
    wxBusyInfo wait("creating gui...");
  }

  assert(m_Input);
  m_CurrentTime = ((mafVME *)m_Input)->GetTimeStamp();

  m_NewAbsMatrix = *((mafVME *)m_Input)->GetOutput()->GetAbsMatrix();
  m_OldAbsMatrix = *((mafVME *)m_Input)->GetOutput()->GetAbsMatrix();

  if (!m_TestMode)
  {
    CreateGui();
    ShowGui();
  }
}
//----------------------------------------------------------------------------
void medOpInteractiveClipSurface::OpRun()
//----------------------------------------------------------------------------
{

    vtkNEW(m_Clipper);
    vtkNEW(m_ClipperBoundingBox);
    vtkNEW(m_OldSurface);

    m_OldSurface->DeepCopy((vtkPolyData*)((mafVME *)m_Input)->GetOutput()->GetVTKData());

    vtkPolyData *initialData;
    vtkNEW(initialData);
    initialData->DeepCopy(m_OldSurface);
    m_ResultPolyData.push_back(initialData);

    if(!m_TestMode)
    {
        ShowClipPlane(m_ClipModality != medOpInteractiveClipSurface::MODE_SURFACE);
        BuildTransformGizmos();

        assert(m_CASH == NULL);
        m_CASH = new medCurvilinearAbscissaOnSkeletonHelper(m_ImplicitPlaneVMEGizmo, this) ;

        //Enable & show Gizmos
        ChangeGizmo();


        CreateGui();
        ShowGui();

        mafEventMacro(mafEvent(this,CAMERA_UPDATE));
    }
    // Added facility for test case
    else
    {
        ShowClipPlane(m_ClipModality != medOpInteractiveClipSurface::MODE_SURFACE);
    }
}
//----------------------------------------------------------------------------
void medOpIterativeRegistration::OpRun()   
//----------------------------------------------------------------------------
{
  // progress bar stuff
  wxString progress_string("creating gui...");
  wxBusyInfo wait(progress_string.c_str());

  m_UndoSourceAbsPose = vtkMatrix4x4::New();
  m_RegistrationMatrix = vtkMatrix4x4::New();

  m_SourceVME = mafVME::SafeDownCast(m_Input);
  m_RegistrationMatrix->DeepCopy(m_SourceVME->GetAbsMatrixPipe()->GetMatrixPointer()->GetVTKMatrix());

  // store source abs pose for undo
  m_UndoSourceAbsPose->DeepCopy(m_SourceVME->GetAbsMatrixPipe()->GetMatrixPointer()->GetVTKMatrix());   

  assert(m_Input);
//  m_CurrentTime = m_Input->GetCurrentTime();
  m_CurrentTime = mafVME::SafeDownCast(m_Input)->GetTimeStamp();
  
  
  m_SourceVmeName = m_Input->GetName();  
  CreateGui();
}
Exemplo n.º 6
0
int CALLBACK
old(
    HINSTANCE Instance,
    HINSTANCE PrevInstance,
    LPSTR CommandLine,
    int ShowCode)
{
#if 1
    Win32EnableConsole();
#endif

    sf::ContextSettings settings;
    settings.depthBits = 32; //24
    settings.stencilBits = 0; //0
    settings.antialiasingLevel = 0; //0
    settings.majorVersion = 3;
    settings.minorVersion = 2;

    // Display the list of all the video modes available for fullscreen
    std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
    for (std::size_t i = 0; i < modes.size(); ++i)
    {
        sf::VideoMode mode = modes[i];    
        std::cout << "Mode #" << i << ": "
        << mode.width << "x" << mode.height << " - "
        << mode.bitsPerPixel << " bpp" << std::endl;
    }
    
    uint8 defaultStyle = (sf::Style::Titlebar | sf::Style::Close);
    auto mode = modes[17];
    sf::RenderWindow renderWindow(sf::VideoMode(mode.width, mode.height, mode.bitsPerPixel), "OpenGL", defaultStyle , settings);
    
    renderWindow.setVerticalSyncEnabled(true);
    renderWindow.setFramerateLimit(60);
    renderWindow.resetGLStates();

    settings = renderWindow.getSettings();

    cout << "depth bits:" << settings.depthBits << endl;
    cout << "stencil bits:" << settings.stencilBits << endl;
    cout << "antialiasing level:" << settings.antialiasingLevel << endl;
    cout << "version:" << settings.majorVersion << "." << settings.minorVersion << endl;

    renderWindow.setActive(true);

    sfg::SFGUI sfgui;
    sfg::Desktop sfguiDesktop;

    CreateGui(sfguiDesktop);

    sf::Font retro_font;
    retro_font.loadFromFile( "../data/fonts/Retro Computer_DEMO.ttf" );
    auto fent = std::make_shared<sf::Font>();// = sf::Font>(retro_font);
    fent->loadFromFile( "../data/fonts/Retro Computer_DEMO.ttf" );
    
    //my_font.setGlobalBounds(text.getGlobalBounds.left, text.getGlobalBounds().top);
    sfguiDesktop.GetEngine().GetResourceManager().AddFont( "retro_font", fent );
    //desktop.SetProperty( "*", "FontName",  "custom_font" );

    sfguiDesktop.SetProperties(
        "* {"
        "   FontName: retro_font;"
        "   FontSize: 18;"
        "}"
        );

    sf::Text text;
    text.setFont(retro_font);
    text.setPosition(sf::Vector2f(2, 2));
    text.setCharacterSize(18);
    text.setColor(sf::Color::White);

    KeyboardManager keyboardManager;

    //Game game(renderWindow, retro_font, &keyboardManager);
    char *GameDLLFullPath = "J:/build/terrific.dll";
    char *TempDLLName = "J:/build/tmp.dll";
    char *LockFileName = "J:/build/lock.tmp";

    auto GameCodeDLL = Win32LoadGameCode(GameDLLFullPath, TempDLLName, LockFileName);
    Game *game = GameCodeDLL.CreateGame(renderWindow, retro_font, &keyboardManager);
    uint32 LoadCounter = 0;

    uint32 m_fps_counter = 0;
    float delta = 0;
    sf::Clock m_fps_clock;
    m_fps_clock.restart();

    sf::Clock clock;
    sf::Clock frame_time_clock;

    sf::Int64 frame_times[5000];
    std::size_t frame_times_index = 0;

    std::fill( std::begin( frame_times ), std::end( frame_times ), 0 );
    int X(0), Y(0);
    while (globalRunning)
    {
        sf::Event event;
        while (renderWindow.pollEvent(event))
        {
            if ((event.type == sf::Event::Closed))
            {
                globalRunning = false;
                break;
            }
            else if ((event.type == sf::Event::MouseMoved))
            {
                X = event.mouseMove.x;
                Y = event.mouseMove.y;
            } 
            else if ((event.type == sf::Event::KeyPressed) |
               (event.type == sf::Event::KeyReleased))
            {
                keyboardManager.ProcessEvent(event);
            }
            sfguiDesktop.HandleEvent(event);
        }

        FILETIME NewDLLWriteTime = Win32GetLastWriteTime(GameDLLFullPath);
        auto t = CompareFileTime(&NewDLLWriteTime, &GameCodeDLL.LastWriteTime);
        if(t != 0 && LoadCounter > 0)
        {
            //char buffer[256];
            //sprintf(buffer, "J:/build/tmp%d.dll", LoadCounter);
	  GameCodeDLL->DestroyGame(GameMemory);
            Win32UnloadGameCode(&GameCodeDLL);
            {
                sf::Clock clockT;
                while (clockT.getElapsedTime().asSeconds() < 0.5f)
                {
                    system("cls");
                    cout << "Unloading Game Code  . . . " << endl;
                }
                cout << "Game Code loaded!" << endl;
                clockT.restart();
            }
            GameCodeDLL = Win32LoadGameCode(GameDLLFullPath, TempDLLName, LockFileName);
            if(GameCodeDLL.IsValid) {
                game = GameCodeDLL.CreateGame(renderWindow, retro_font, &keyboardManager);
            }
            LoadCounter++;
        } 
        else 
        {
            LoadCounter++;
        }

        auto microseconds = clock.getElapsedTime().asMicroseconds();
        //delta = static_cast<float>( microseconds ) / 1000000.f;
        // Only update every 5ms
        delta = static_cast<float>(frame_time_clock.getElapsedTime().asSeconds());
        if( microseconds > 5000 ) {
            game->update(delta);
            sfguiDesktop.Update(delta);
            keyboardManager.Update();
            clock.restart();

            renderWindow.setActive( true );
        }
        renderWindow.clear();

        delta = static_cast<float>(frame_time_clock.getElapsedTime().asSeconds());
        game->draw(delta);
        sfgui.Display(renderWindow);
        renderWindow.draw(text);
        renderWindow.display();

        auto frame_time = frame_time_clock.getElapsedTime().asMicroseconds();
        frame_time_clock.restart();

        frame_times[ frame_times_index ] = frame_time;
        frame_times_index = ( frame_times_index + 1 ) % 5000;

        if( m_fps_clock.getElapsedTime().asMicroseconds() >= 1000000 ) {
            m_fps_clock.restart();

            sf::Int64 total_time = 0;

            for( std::size_t index = 0; index < 5000; ++index ) {
                total_time += frame_times[index];
            }

            std::stringstream sstr;
            sstr << "SFGUI test -- FPS: " << m_fps_counter << " -- Frame Time (microsecs): min: "
            << *std::min_element( frame_times, frame_times + 5000 ) << " max: "
            << *std::max_element( frame_times, frame_times + 5000 ) << " avg: "
            << static_cast<float>( total_time ) / 5000.f;

            renderWindow.setTitle( sstr.str() );
            

            m_fps_counter = 0;
        }

        ++m_fps_counter;
    }
    renderWindow.close();

    Win32UnloadGameCode(&GameCodeDLL);
    {
        sf::Clock clockT;
        while (clockT.getElapsedTime().asSeconds() < 0.5f)
        {
            cout << "Unloading Game Code  . . . " << endl;
        }
        clockT.restart();
    }
    DeleteFile(TempDLLName);

    return 0;
}