예제 #1
0
bool LuaIOManagerProxy::ExtractImageStack(
    LuaClassInstance ds,
    LuaClassInstance tf1d,
    uint64_t iLODlevel, 
    const std::string& strTargetFilename,
    const std::string& strTempDir,
    bool bAllDirs) const {
  if (mSS->cexecRet<LuaDatasetProxy::DatasetType>(
          ds.fqName() + ".getDSType") != LuaDatasetProxy::UVF) {
    T_ERROR("tuvok.io.exportDataset only accepts UVF.");
    return false;
  }

  // Convert LuaClassInstance -> LuaDatasetProxy -> UVFdataset
  LuaDatasetProxy* dsProxy = ds.getRawPointer<LuaDatasetProxy>(mSS);
  UVFDataset* uvf = dynamic_cast<UVFDataset*>(dsProxy->getDataset());
  assert(uvf != NULL);

  // Now we need to extract the transfer function...
  LuaTransferFun1DProxy* tfProxy = tf1d.getRawPointer<LuaTransferFun1DProxy>(
      mSS);
  TransferFunction1D* pTrans = tfProxy->get1DTransferFunction();
  assert(pTrans != NULL);

  return mIO->ExtractImageStack(
      uvf, pTrans, iLODlevel,
      strTargetFilename,
      strTempDir,
      bAllDirs);
}
void MainWindow::Transfer1DLoad() {
  QSettings settings;
  QString strLastDir="";

  shared_ptr<LuaScripting> ss = m_MasterController.LuaScript();

  // First try to grab the directory from the currently-opened file.
  if(m_pActiveRenderWin) {
    LuaClassInstance ds = m_pActiveRenderWin->GetRendererDataset();
    strLastDir = QString(SysTools::GetPath(
            ss->cexecRet<string>(ds.fqName() + ".fullpath")).c_str());
  }

  // if that didn't work, fall back on our previously saved path.
  if(strLastDir == "" || !SysTools::FileExists(strLastDir.toStdString())) {
    strLastDir = settings.value("Folders/Transfer1DLoad", ".").toString();
  }

  QString selectedFilter;
  QFileDialog::Options options;
#ifdef DETECTED_OS_APPLE
  options |= QFileDialog::DontUseNativeDialog;
#endif

  QString fileName =
    QFileDialog::getOpenFileName(this,
         "Load 1D Transfer function", strLastDir,
         "1D Transfer function File (*.1dt)",&selectedFilter, options);

  if (!fileName.isEmpty()) {
    settings.setValue("Folders/Transfer1DLoad", QFileInfo(fileName).absoluteDir().path());
    m_1DTransferFunction->QLoadFromFile(fileName);
  }
}
bool MainWindow::ExportGeometry(size_t i, std::string strFilename) {
  if (!m_pActiveRenderWin) return false;
  LuaClassInstance ds = m_pActiveRenderWin->GetRendererDataset();
  shared_ptr<LuaScripting> ss(m_MasterController.LuaScript());
  if (!ds.isValid(ss) || 
      (ss->cexecRet<LuaDatasetProxy::DatasetType>(ds.fqName() + ".getDSType") !=
       LuaDatasetProxy::UVF) )
    return false;

  PleaseWaitDialog pleaseWait(this);
  pleaseWait.SetText("Exporting Mesh...");
  pleaseWait.AttachLabel(&m_MasterController);

  std::vector<shared_ptr<Mesh>> meshes =
      ss->cexecRet<std::vector<shared_ptr<Mesh>>>(ds.fqName() + "getMeshes");
  return ss->cexecRet<bool>("tuvok.io.exportMesh", meshes[i], strFilename);
}
void MainWindow::SaveAspectRatioToUVF() {
  if (m_pActiveRenderWin) {
    m_pActiveRenderWin->SetDatasetIsInvalid(true);

    PleaseWaitDialog pleaseWait(this);
    pleaseWait.SetText("Writing rescale factors to file...");
    pleaseWait.AttachLabel(&m_MasterController);

    shared_ptr<LuaScripting> ss(m_MasterController.LuaScript());
    LuaClassInstance ds = m_pActiveRenderWin->GetRendererDataset();

    try {
      if (!ss->cexecRet<bool>(ds.fqName() + ".saveRescaleFactors")) {
        if (!m_bScriptMode) {
          QMessageBox::warning(this, "File Error", "Unable to save rescale factors to file.", QMessageBox::Ok);
        }
      }
    }
    catch (std::exception& e) {
      std::string errMsg = "Unable to save scale factors to UVF file.";
      if (strlen(e.what()) > 0) {
        errMsg += "  Error: ";
        errMsg += e.what();
      }
      QMessageBox::warning(this, "Scale Factor Save Error", errMsg.c_str(), 
                           QMessageBox::Ok);
    }

    DOUBLEVECTOR3 vfRescaleFactors = 
        ss->cexecRet<DOUBLEVECTOR3>(ds.fqName() + ".getRescaleFactors");
    doubleSpinBox_RescaleX->setValue(vfRescaleFactors.x);
    doubleSpinBox_RescaleY->setValue(vfRescaleFactors.y);
    doubleSpinBox_RescaleZ->setValue(vfRescaleFactors.z);

    pleaseWait.close();
    m_pActiveRenderWin->SetDatasetIsInvalid(false);
  }
}
void MainWindow::RemoveGeometry() {
  if (!m_pActiveRenderWin) return;
  LuaClassInstance ds = m_pActiveRenderWin->GetRendererDataset();
  shared_ptr<LuaScripting> ss(m_MasterController.LuaScript());
  if (!ds.isValid(ss) || 
      (ss->cexecRet<LuaDatasetProxy::DatasetType>(ds.fqName() + ".getDSType") !=
       LuaDatasetProxy::UVF) )
    return;

  PleaseWaitDialog pleaseWait(this);
  pleaseWait.SetText("Removing Mesh from UVF file...");
  pleaseWait.AttachLabel(&m_MasterController);

  int iCurrent = listWidget_DatasetComponents->currentRow();

  if (iCurrent < 1 || iCurrent >= listWidget_DatasetComponents->count()) {
    T_ERROR("No Mesh selected.");
    return;
  }

  m_pActiveRenderWin->SetDatasetIsInvalid(true);

  if (!ss->cexecRet<bool>(ds.fqName() + ".removeMesh", size_t(iCurrent-1))) {
    pleaseWait.close();
    ShowCriticalDialog("Mesh Removal Failed.",
             "Could not remove mesh from the UVF file, "
             "maybe the file is write protected? For details please "
             "check the debug log ('Help | Debug Window').");
  } else {
    m_pActiveRenderWin->RemoveMeshData(size_t(iCurrent-1));
    UpdateExplorerView(true);
    pleaseWait.close();
  }

  m_pActiveRenderWin->SetDatasetIsInvalid(false);
}
예제 #6
0
bool LuaIOManagerProxy::ExportDataset(LuaClassInstance ds,
                                      uint64_t iLODlevel,
                                      const string& strTargetFilename,
                                      const string& strTempDir) const
{
  if (mSS->cexecRet<LuaDatasetProxy::DatasetType>(
          ds.fqName() + ".getDSType") != LuaDatasetProxy::UVF) {
    T_ERROR("tuvok.io.exportDataset only accepts UVF.");
    return false;
  }

  // Convert LuaClassInstance -> LuaDatasetProxy -> UVFdataset
  LuaDatasetProxy* dsProxy = ds.getRawPointer<LuaDatasetProxy>(mSS);
  UVFDataset* uvf = dynamic_cast<UVFDataset*>(dsProxy->getDataset());
  assert(uvf != NULL);

  return mIO->ExportDataset(uvf, iLODlevel, strTargetFilename, 
                            strTempDir);
}
void MainWindow::Transfer1DSave() {
  QSettings settings;
  QString strLastDir="";
  std::string defaultFilename;
  
  shared_ptr<LuaScripting> ss = m_MasterController.LuaScript();

  // First try to grab the directory from the currently-opened file...
  if(m_pActiveRenderWin) {
    LuaClassInstance ds = m_pActiveRenderWin->GetRendererDataset();
    string dsFullpath = ss->cexecRet<string>(ds.fqName() + ".fullpath");
    strLastDir = QString(SysTools::GetPath(dsFullpath).c_str());
    defaultFilename = SysTools::ChangeExt(dsFullpath, "1dt");
  }

  if(strLastDir == "" || !SysTools::FileExists(strLastDir.toStdString()+".")) {
    // ...if that didn't work, fall back on our previously saved path.
    strLastDir = settings.value("Folders/Transfer1DSave", ".").toString();
  } else {
    // if the path exitst propose the default name as save default
    strLastDir = QString(defaultFilename.c_str());
  }

  QString selectedFilter;
  QFileDialog::Options options;
#ifdef DETECTED_OS_APPLE
  options |= QFileDialog::DontUseNativeDialog;
#endif

  QString fileName =
    QFileDialog::getSaveFileName(this,
         "Save 1D Transfer function", strLastDir,
         "1D Transfer function File (*.1dt)",&selectedFilter, options);

  if (!fileName.isEmpty()) {
    fileName = SysTools::CheckExt(string(fileName.toAscii()), "1dt").c_str();
    settings.setValue("Folders/Transfer1DSave", QFileInfo(fileName).absoluteDir().path());
    m_1DTransferFunction->SaveToFile(fileName);
  }
}
void MainWindow::ExportImageStack() {
  QFileDialog::Options options;
#ifdef DETECTED_OS_APPLE
  options |= QFileDialog::DontUseNativeDialog;
#endif
  QString selectedFilter;

  QSettings settings;
  QString strLastDir = settings.value("Folders/ExportImageStack", ".").toString();

  shared_ptr<LuaScripting> ss(m_MasterController.LuaScript());
  string filterStr = ss->cexecRet<string>("tuvok.io.getImageExportDialogString").c_str();

  QString fileName =
    QFileDialog::getSaveFileName(this, "Export Current Dataset to a Set of Images",
         strLastDir,filterStr.c_str(),&selectedFilter, options);

  if (!fileName.isEmpty()) {
    settings.setValue("Folders/ExportImageStack", QFileInfo(fileName).absoluteDir().path());
    string targetFileName = string(fileName.toAscii());
    
    string selectedFilterStr = string(selectedFilter.toAscii());
    std::string filterExt = ss->cexecRet<string>("tuvok.io.imageExportDialogFilterToExt", selectedFilterStr);

    if (SysTools::GetExt(targetFileName).empty())  {
      if (filterExt.empty()) {
        ShowCriticalDialog( "Error during image stack export.", "Unable to determine file type from filename.");
        return;
      } else {
        targetFileName += std::string(".") + filterExt;
      }
    }

    shared_ptr<LuaScripting> ss = m_MasterController.LuaScript();
    LuaClassInstance ds = m_pActiveRenderWin->GetRendererDataset();
    int iMaxLODLevel = static_cast<int>(
        ss->cexecRet<uint64_t>(ds.fqName() + ".getLODLevelCount") ) - 1;

    int iLODLevel = 0;
    if (iMaxLODLevel > 0) {
      int iMinLODLevel = 0;
      vector<QString> vDesc;
      for (int i = iMinLODLevel;i<=iMaxLODLevel;i++) {
        UINTVECTOR3 vLODSize = UINTVECTOR3( ss->cexecRet<UINT64VECTOR3>(
                ds.fqName() + ".getDomainSize", size_t(i), size_t(0)) );
        QString qstrDesc = tr("%1 x %2 x %3").arg(vLODSize.x).arg(vLODSize.y).arg(vLODSize.z);
        vDesc.push_back(qstrDesc);
      }
      LODDlg lodDlg("For which LOD Level do you want to export the image stack?", iMinLODLevel, iMaxLODLevel, vDesc, this);

      if (lodDlg.exec() != QDialog::Accepted)
        return;
      else
        iLODLevel = lodDlg.GetLOD();
    }

    bool bAllDirs = QMessageBox::Yes == QMessageBox::question(this, "Texture Stack Exporter",
                                                                    "Do you want to export three stacks along all three directions? Otherwise only one stack along the z-axis is created.",
                                                              QMessageBox::Yes, QMessageBox::No);

    if(!ExportImageStack(uint32_t(iLODLevel), targetFileName, bAllDirs)) {
      ShowCriticalDialog( "Error during image stack export.", "The system was unable to export the current data set, please check the error log for details (Menu -> \"Help\" -> \"Debug Window\").");
      return;
    }

  }
}
void MainWindow::ExportDataset() {
  if (!m_pActiveRenderWin) return;
  QFileDialog::Options options;
#ifdef DETECTED_OS_APPLE
  options |= QFileDialog::DontUseNativeDialog;
#endif
  QString selectedFilter;

  QSettings settings;
  QString strLastDir = settings.value("Folders/ExportDataset", ".").toString();

  shared_ptr<LuaScripting> ss(m_MasterController.LuaScript());
  QString dialogString =
      ss->cexecRet<string>("tuvok.io.getExportDialogString").c_str();

  std::string ext;
  QString fileName;
  do {
    fileName = QFileDialog::getSaveFileName(this, "Export Current Dataset",
                                            strLastDir, dialogString,
                                            &selectedFilter, options);
    if(fileName.isEmpty()) {
      // not an error -- the user might get here if they wanted to cancel the
      // export.
      break;
    }
    // get it out of a QString && figure out what file type we're dealing with.
    std::string filter = std::string(selectedFilter.toAscii());
    size_t start = filter.find_last_of("*.")+1;
    size_t end = filter.find_last_of(")");
    ext = filter.substr(start, end-start);
    SysTools::TrimStr(ext);
    if(ext == "") {
      QMessageBox noformat;
      noformat.setText("No file extension: unknown export format");
      noformat.setIcon(QMessageBox::Critical);
      noformat.exec();
    }
  } while(ext == "");

  if (!fileName.isEmpty()) {
    settings.setValue("Folders/ExportDataset",
                      QFileInfo(fileName).absoluteDir().path());

    string strCompletefileName = SysTools::CheckExt(string(fileName.toAscii()),
                                                    ext);

    shared_ptr<LuaScripting> ss = m_MasterController.LuaScript(); 
    LuaClassInstance ds = m_pActiveRenderWin->GetRendererDataset();
    int iMaxLODLevel = static_cast<int>(
        ss->cexecRet<uint64_t>(ds.fqName() + ".getLODLevelCount")) - 1;

    int iLODLevel = 0;
    if (iMaxLODLevel > 0) {
      int iMinLODLevel = 0;
      vector<QString> vDesc;
      for (int i = iMinLODLevel;i<=iMaxLODLevel;i++) {
        UINTVECTOR3 vLODSize = UINTVECTOR3(ss->cexecRet<UINT64VECTOR3>(
                ds.fqName() + ".getDomainSize", size_t(i), size_t(0)));
        QString qstrDesc = tr("%1 x %2 x %3").arg(vLODSize.x).arg(vLODSize.y).arg(vLODSize.z);
        vDesc.push_back(qstrDesc);
      }
      LODDlg lodDlg("Which LOD Level do you want to export?", iMinLODLevel, iMaxLODLevel, vDesc, this);

      if (lodDlg.exec() != QDialog::Accepted)
        return;
      else
        iLODLevel = lodDlg.GetLOD();
    }

    PleaseWaitDialog pleaseWait(this);
    pleaseWait.SetText("Exporting, please wait  ...");
    pleaseWait.AttachLabel(&m_MasterController);

    if (!ExportDataset(iLODLevel, strCompletefileName)) {
      ShowCriticalDialog( "Error during dataset export.", "The system was unable to export the current data set, please check the error log for details (Menu -> \"Help\" -> \"Debug Window\").");
    } else {
      pleaseWait.hide();
      QString msg = tr("The dataset has been exported as %1.").arg(strCompletefileName.c_str());
      ShowInformationDialog( tr("Export successful"), msg);
    }
  }
}
bool MainWindow::LoadDatasetInternal(QStringList files, QString targetFilename,
                                     bool bNoUserInteraction)
{

  if(files.empty()) {
    T_ERROR("No files!");
    return false;
  }

  PleaseWaitDialog pleaseWait(this);
  pleaseWait.SetText("Loading dataset, please wait  ...");
  pleaseWait.AttachLabel(&m_MasterController);

  // First check to make sure the list of files we've been given makes sense.
  for(QStringList::const_iterator fn = files.begin();
      fn != files.end(); ++fn) {
    if(fn->isEmpty()) {
      T_ERROR("Empty filelist");
      return false;
    }
    if(!SysTools::FileExists(std::string(fn->toAscii()))) {
      QString strText = tr("File %1 not found.").arg(*fn);
      T_ERROR("%s", strText.toStdString().c_str());
      if(!bNoUserInteraction) {
        ShowCriticalDialog( "Load Error", strText);
      }
      return false;
    }
  }

  // now determine if we've been given a UVF, and can just open it and be done,
  // or if we need to convert the files.
  // If we were given multiple files, we don't need to do any work; we *know*
  // that needs to be converted.
  shared_ptr<LuaScripting> ss(m_MasterController.LuaScript());
  bool needs_conversion = true;
  if(files.size() == 1) {
    // check to see if we need to convert this file to a supported format.

    if(!ss->cexecRet<bool>("tuvok.io.needsConversion",files[0].toStdString())) {
      needs_conversion = false;

      // It might also be the case that the checksum is bad && we need to
      // report an error, but we don't bother with the checksum if they've
      // asked us not to in the preferences.
      if(!m_bQuickopen && 
         false == ss->cexecRet<bool>("tuvok.io.verify", files[0].toStdString()))
      {
        QString strText = tr("File %1 appears to be a broken UVF file: "
                             "the header looks ok, "
                             "but the checksum does not match.").arg(files[0]);
        T_ERROR("%s", strText.toStdString().c_str());
        if (!bNoUserInteraction) {
          ShowCriticalDialog("Load Error", strText);
        }
        return false;
      }
    }
  }

  QString filename = files[0];
  if(needs_conversion) {
    if (!bNoUserInteraction && targetFilename.isEmpty()) {
      targetFilename = GetConvFilename(files[0]);
    }
    if (targetFilename.isEmpty()) {
      T_ERROR("User interaction disabled but no targetFilename given");
      return false;
    }

    std::list<std::string> stdfiles;
    for(QStringList::const_iterator fn = files.begin();
        fn != files.end(); ++fn) {
      stdfiles.push_back(std::string(fn->toAscii()));
    }

    PleaseWaitDialog pleaseWait(this);
    pleaseWait.SetText("Converting, please wait  ...");
    pleaseWait.AttachLabel(&m_MasterController);

    try {
      ss->cexec("tuvok.io.convertDataset", stdfiles, 
                std::string(targetFilename.toAscii()), m_strTempDir, 
                bNoUserInteraction, false);
      filename = targetFilename;
    } catch(const tuvok::io::IOException& e) {
      // create a (hopefully) useful error message
      std::ostringstream error;
      error << "Unable to convert ";
      std::copy(stdfiles.begin(), stdfiles.end(),
                std::ostream_iterator<std::string>(error, ", "));
      error << " into " << std::string(targetFilename.toAscii())
            << ": " << e.what();
      T_ERROR("%s", error.str().c_str());
      if(!bNoUserInteraction) {
        ShowCriticalDialog("Conversion Error", QString(error.str().c_str()));
      }

      // now close that dialog and bail.
      pleaseWait.close();
      return false;
    }

    pleaseWait.close();
  }

  RenderWindow *renderWin = NULL;
  try {
    renderWin = CreateNewRenderWindow(filename);

    if(renderWin == NULL) {
      T_ERROR("Renderwindow creation failed.  Bailing...");
      return false;
    }

    renderWin->GetQtWidget()->show();  // calls RenderWindowActive automatically
    UpdateMenus();
    AddFileToMRUList(filename);
  } catch(tuvok::io::DSBricksOversized&) {
    WARNING("Bricks are too large.  Querying the user to see if we should "
            "rebrick the dataset.");
    if(renderWin) { delete renderWin; renderWin = NULL; }
    if(bNoUserInteraction) {
      T_ERROR("Dataset needs rebricking but ImageVis3D is not running interactively.");
      return false;
    }
    if(QMessageBox::Yes ==
       QMessageBox::question(NULL, "Rebricking required",
        "The bricking scheme in this dataset is not compatible with "
        "your current brick size settings.  Do you want to convert this "
        "dataset so that it can be loaded?  Note that this operation can "
        "take as long as originally converting the data took!",
        QMessageBox::Yes, QMessageBox::No)) {
      // m_bIgnoreLoadDatasetFailure is an ugly hack, but I can't see any other
      // *good* options.
      // 
      // An alternative to m_bIgnoreLoadDatasetFailure is to throw a custom 
      // exception which would include bNoUserInteraction's value, and catch  
      // the exception in MainWindow::LoadDataset(std::string strFilename). 
      // (and MainWindow::LoadDataset(), and MainWindow::OpenRecentFile).
      // We would perform the rebricking upon catching the exception.
      // This method seemed equally hacky so I opted for the smallest code 
      // footprint and inserted this boolean flag.
      //
      // Also, we can use the flag when the user specifies 'no' on the dialog.
      // It doesn't make much sense to tell the user that we failed to
      // load the RenderWindow because they told us to not load it =P.
      //
      // The problem: if we reach here, we were in the process of creating
      // a series of Lua classes to support a render window. Since we are no
      // longer creating a viable render window (renderWin was deleted, and 
      // RebrickDataset is creating a new render window), lua needs to be 
      // notified and clean up any supporting classes.
      //
      // The only way to notify Lua is to do 1 of 2 things:
      // 1) Return false from this function (behaving as if the requested 
      //    dataset failed to load -- which it did).
      // 2) Or throw an exception and let lua capture and rethrow it.
      //
      // I opted for #1.
      RebrickDataset(filename, targetFilename, bNoUserInteraction);
      m_bIgnoreLoadDatasetFailure = true;
      return false;
    } else {
      m_bIgnoreLoadDatasetFailure = true;
      return false;
    }
  }

  if (renderWin) RenderWindowActive(renderWin);
  if (CheckForMeshCapabilities(bNoUserInteraction, files)) return true;

  if(renderWin) {
    LuaClassInstance ds = renderWin->GetRendererDataset();
    shared_ptr<LuaScripting> ss = m_MasterController.LuaScript();
    UINT64VECTOR3 dom_sz = ss->cexecRet<UINT64VECTOR3>(ds.fqName() + 
                                                       ".getDomainSize", 
                                                       size_t(0), 
                                                       size_t(0));
    // Disable lighting for 2D datasets (images).
    if(dom_sz[2] == 1) {
      checkBox_Lighting->setChecked(false);
      checkBox_Lighting->setEnabled(false);
      SetLighting(false);
    }
  }

  return true;
}
void MainWindow::AddGeometry(std::string filename) {
  if (!m_pActiveRenderWin) return;

  if(!m_pActiveRenderWin->SupportsMeshes()) {
      if(QMessageBox::Yes == 
        QMessageBox::question(NULL, 
                         "Mesh feature not supported in this renderer",
                         "You can add a mesh to this dataset but you will "
                         "not be able to see it until you switch to a renderer "
                         "that supports this feature e.g. the 3D slice "
                         "based volume renderer. Do you want to switch to "
                         "the 3D slice based volume renderer now?",
          QMessageBox::Yes, QMessageBox::No)) {
        QString dataset = m_pActiveRenderWin->GetDatasetName();
        CloseCurrentView();
        MasterController::EVolumeRendererType currentType = m_eVolumeRendererType;
        m_eVolumeRendererType = MasterController::OPENGL_SBVR;    
        LoadDataset(std::string(dataset.toAscii()));
        m_eVolumeRendererType = currentType;
      }
  }


  shared_ptr<LuaScripting> ss = m_MasterController.LuaScript();
  LuaClassInstance ds = m_pActiveRenderWin->GetRendererDataset();
  LuaDatasetProxy::DatasetType type = 
      ss->cexecRet<LuaDatasetProxy::DatasetType>(ds.fqName() + ".getDSType");
  if (type != LuaDatasetProxy::UVF) {
    ShowCriticalDialog("Mesh Import Failed.",
                 "Mesh Integration only supported for UVF datasets.");
    return;
  }

  PleaseWaitDialog pleaseWait(this);

  pleaseWait.SetText("Loading mesh, please wait  ...");
  pleaseWait.AttachLabel(&m_MasterController);

  std::shared_ptr<Mesh> m;
  try {
    m = ss->cexecRet<std::shared_ptr<Mesh>>("tuvok.io.loadMesh", filename);
  } catch (const tuvok::io::DSOpenFailed& err) {
    WARNING("Conversion failed! %s", err.what());
  }

  if (!m)  {
    ShowCriticalDialog("Mesh Import Failed.",
                 "Could not load mesh file. For details please "
                 "check the debug log ('Help | Debug Window').");
    return;
  }

  // make sure we have at least normals
  if (m->GetNormalIndices().empty()) {
    pleaseWait.SetText("Computing normals, please wait  ...");
    m->RecomputeNormals();
  }

  pleaseWait.SetText("Integrating Mesh into volume file, please wait  ...");

  m_pActiveRenderWin->SetDatasetIsInvalid(true);

  shared_ptr<const Mesh> constMeshPtr = m;
  if (!ss->cexecRet<bool>(ds.fqName() + ".appendMesh", constMeshPtr)) {
    pleaseWait.close();
    ShowCriticalDialog("Mesh Import Failed.",
                 "Could not integrate the mesh into this UVF file. "
                 "For details please check the debug log "
                 "('Help | Debug Window').");
  } else {
    pleaseWait.SetText("Creating render resources, please wait  ...");
    m_pActiveRenderWin->ScanForNewMeshes();
    pleaseWait.close();
    UpdateExplorerView(true);
  }

  m_pActiveRenderWin->SetDatasetIsInvalid(false);
}
void MainWindow::ExportIsosurface() {
  QFileDialog::Options options;
#ifdef DETECTED_OS_APPLE
  options |= QFileDialog::DontUseNativeDialog;
#endif
  QString selectedFilter;

  QSettings settings;
  QString strLastDir = settings.value("Folders/ExportIso", ".").toString();

  shared_ptr<LuaScripting> ss(m_MasterController.LuaScript());
  QString fileName =
    QFileDialog::getSaveFileName(this, "Export Current Isosurface to Mesh",
         strLastDir,
         ss->cexecRet<string>("tuvok.io.getGeoExportDialogString").c_str(),
         &selectedFilter, options);

  if (!fileName.isEmpty()) {
    settings.setValue("Folders/ExportIso", QFileInfo(fileName).absoluteDir().path());
    string targetFileName = string(fileName.toAscii());

    // still a valid filename ext ?
    if (!ss->cexecRet<bool>("tuvok.io.hasGeoConverterForExt", 
                            SysTools::ToLowerCase(SysTools::GetExt(
                                    string(fileName.toAscii()))),
                            true,false)) {
      ShowCriticalDialog("Extension Error", 
                         "Unable to determine the file type "
                         "from the file extension.");
      return;
    }

    LuaClassInstance ds = m_pActiveRenderWin->GetRendererDataset();
    int iMaxLODLevel = int(ss->cexecRet<uint64_t>(ds.fqName() + ".getLODLevelCount"))-1;

    int iLODLevel = 0;
    if (iMaxLODLevel > 0) {
      int iMinLODLevel = 0;
      vector<QString> vDesc;
      for (int i = iMinLODLevel;i<=iMaxLODLevel;i++) {
        UINTVECTOR3 vLODSize = UINTVECTOR3(
            ss->cexecRet<UINT64VECTOR3>(ds.fqName() + ".getDomainSize",
                                        static_cast<size_t>(i),
                                        static_cast<size_t>(0)));
        QString qstrDesc = tr("%1 x %2 x %3").arg(vLODSize.x).arg(vLODSize.y).arg(vLODSize.z);
        vDesc.push_back(qstrDesc);
      }
      LODDlg lodDlg("For which LOD Level do you want to compute the mesh?", iMinLODLevel, iMaxLODLevel, vDesc, this);

      if (lodDlg.exec() != QDialog::Accepted)
        return;
      else
        iLODLevel = lodDlg.GetLOD();
    }

    if(!ExportIsosurface(uint32_t(iLODLevel), targetFileName)) {
      ShowCriticalDialog( "Error during mesh export.", "The system was unable to export the current data set, please check the error log for details (Menu -> \"Help\" -> \"Debug Window\").");
      return;
    }

    // if the choosen format supports import then ask the users if they want to re-import the mesh
    bool hasConverter = ss->cexecRet<bool>("tuvok.io.hasGeoConverterForExt",
                                           SysTools::GetExt(targetFileName),
                                           false,true);
    if (hasConverter) {
     if(QMessageBox::Yes ==
       QMessageBox::question(this, "Add Mesh to Project",
        "Do you want to load the surface a part of this project?",
        QMessageBox::Yes, QMessageBox::No)) {

        AddGeometry(targetFileName);
      }
    }
  }
}