コード例 #1
0
int main ( int argc, char **argv ) {
  std::shared_ptr<Vipper::IRouter> nextRouter;
  std::shared_ptr<Vipper::IPresenter> presenter;
  std::shared_ptr<Vipper::IRouter> router;
  
  auto renderer = std::make_shared<BlockyFalls::CSDLRenderer>();
  
  auto titleScreenRouter = std::make_shared<BlockyFalls::CTitleScreenRouter>(renderer);
  
  titleScreenRouter->initWithDefaults();
  
  nextRouter = titleScreenRouter;
  presenter = titleScreenRouter->getPresenter();

  std::vector<std::shared_ptr<Vipper::IRouter>> routers;
  
  do {  
    if ( nextRouter != nullptr ) {
      if ( router != nullptr ) {
        router->onRelinquishFocus();
        if ( !router->isFinished() ) {
          routers.push_back( router );
        }
        
      }      
      router = nextRouter;
      router->onFocus();
      nextRouter = nullptr;
    }
    
    presenter = router->getPresenter();
    presenter->present();
    
    renderer->update();
    renderer->render();
    SDL_Delay(33);
    
    nextRouter = router->route();

    if ( router->isFinished() && nextRouter == nullptr ) {
      
      nextRouter = routers.back();
      routers.pop_back();
    }

  } while ( nextRouter != router );

  renderer->shutdown();
  return 0;
}
コード例 #2
0
/**
 * Save an MD workspace to a vts/vtu file.
 * @param workspace: the workspace which is to be saved.
 * @param filename: the name of the file to which the workspace is to be saved.
 * @param normalization: the visual normalization option
 * @param recursionDepth: the recursion depth for MDEvent Workspaces determines
 * @param compressorType: the compression type used by VTK
 * from which level data should be displayed
 */
void SaveMDWorkspaceToVTKImpl::saveMDWorkspace(
    const Mantid::API::IMDWorkspace_sptr &workspace,
    const std::string &filename, VisualNormalization normalization,
    int recursionDepth, const std::string &compressorType) {
  auto isHistoWorkspace =
      boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(workspace) !=
      nullptr;
  auto fullFilename = getFullFilename(filename, isHistoWorkspace);

  const vtkXMLWriter::CompressorType compressor = [&compressorType] {
    if (compressorType == "NONE") {
      return vtkXMLWriter::NONE;
    } else if (compressorType == "ZLIB") {
      return vtkXMLWriter::ZLIB;
    } else {
      // This should never happen.
      Mantid::Kernel::Logger g_log("SaveMDWorkspaceToVTK");
      g_log.warning("Incorrect CompressorType: " + compressorType +
                    ". Using CompressorType=NONE.");
      return vtkXMLWriter::NONE;
    }
  }();
  // Define a time slice.
  auto time = selectTimeSliceValue(*workspace);

  // Get presenter and data set factory set up
  auto factoryChain =
      getDataSetFactoryChain(isHistoWorkspace, normalization, time);

  auto presenter = getPresenter(isHistoWorkspace, workspace, recursionDepth);

  // Create the vtk data
  NullProgressAction nullProgressA;
  NullProgressAction nullProgressB;
  auto dataSet =
      presenter->execute(factoryChain.get(), nullProgressA, nullProgressB);

  // Do an orthogonal correction
  dataSet = getDataSetWithOrthogonalCorrection(dataSet, presenter.get(),
                                               workspace, isHistoWorkspace);

  // ParaView 5.1 checks the range of the entire signal array, including blank
  // cells.
  if (isHistoWorkspace) {
    auto structuredGrid = vtkStructuredGrid::SafeDownCast(dataSet);
    vtkIdType imageSize = structuredGrid->GetNumberOfCells();
    vtkNew<vtkFloatArray> signal;
    signal->SetNumberOfComponents(1);
    signal->SetNumberOfTuples(imageSize);
    auto oldSignal = structuredGrid->GetCellData()->GetScalars();
    for (vtkIdType index = 0; index < imageSize; ++index) {
      if (structuredGrid->IsCellVisible(index)) {
        signal->SetComponent(index, 0, oldSignal->GetTuple1(index));
      } else {
        signal->SetComponent(index, 0, std::numeric_limits<float>::quiet_NaN());
      }
    }
    structuredGrid->GetCellData()->SetScalars(signal.GetPointer());
  }

  // Write the data to the file
  vtkSmartPointer<vtkXMLWriter> writer = getXMLWriter(isHistoWorkspace);
  auto writeSuccessFlag =
      writeDataSetToVTKFile(writer, dataSet, fullFilename, compressor);
  if (!writeSuccessFlag) {
    throw std::runtime_error("SaveMDWorkspaceToVTK: VTK could not write "
                             "your data set to a file.");
  }
}