Skip to content
Snippets Groups Projects
Commit 32467337 authored by Lars Bilke's avatar Lars Bilke
Browse files

Merge pull request #589 from rinkk/VtkExportName

[Fix] Correct handling of file extension during VTK export
parents 967ca626 d2558966
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,8 @@
// ThirdParty/logog
#include "logog/include/logog.hpp"
#include "BaseLib/FileTools.h"
#include "VtkAlgorithmProperties.h"
#include "VtkGeoImageSource.h"
......@@ -140,15 +142,16 @@ void VtkVisImageItem::setVtkProperties(VtkAlgorithmProperties* vtkProps)
int VtkVisImageItem::callVTKWriter(vtkAlgorithm* algorithm, const std::string &filename) const
{
std::string file_name_cpy(filename);
vtkImageAlgorithm* algID = dynamic_cast<vtkImageAlgorithm*>(algorithm);
if (algID)
{
vtkSmartPointer<vtkXMLImageDataWriter> iWriter =
vtkSmartPointer<vtkXMLImageDataWriter>::New();
iWriter->SetInputData(algID->GetOutputDataObject(0));
std::string filenameWithExt = filename;
filenameWithExt.append(".vti");
iWriter->SetFileName(filenameWithExt.c_str());
if (BaseLib::getFileExtension(filename).compare("vti") != 0)
file_name_cpy.append(".vti");
iWriter->SetFileName(file_name_cpy.c_str());
return iWriter->Write();
}
ERR("VtkVisPipelineItem::writeToFile() - Unknown data type.");
......
......@@ -142,7 +142,7 @@ void VtkVisPipelineView::exportSelectedPipelineItemAsVtk()
QModelIndex idx = this->selectionModel()->currentIndex();
QString filename = QFileDialog::getSaveFileName(this, "Export object to vtk-file",
settings.value("lastExportedFileDirectory").toString(),
"All files (* *.*)");
"VTK file (*.*)");
if (!filename.isEmpty())
{
static_cast<VtkVisPipelineItem*>(static_cast<VtkVisPipeline*>(this->model())->
......
......@@ -25,6 +25,8 @@
// ThirdParty/logog
#include "logog/include/logog.hpp"
#include "BaseLib/FileTools.h"
#include "VtkAlgorithmProperties.h"
#include "VtkCompositeFilter.h"
#include "VtkCompositeContourFilter.h"
......@@ -212,33 +214,31 @@ void VtkVisPointSetItem::setVtkProperties(VtkAlgorithmProperties* vtkProps)
int VtkVisPointSetItem::callVTKWriter(vtkAlgorithm* algorithm, const std::string &filename) const
{
std::string file_name_cpy(filename);
vtkPolyDataAlgorithm* algPD = dynamic_cast<vtkPolyDataAlgorithm*>(algorithm);
vtkUnstructuredGridAlgorithm* algUG = dynamic_cast<vtkUnstructuredGridAlgorithm*>(algorithm);
if (algPD)
{
// vtkGenericDataObjectWriter* pdWriter = vtkGenericDataObjectWriter::New();
vtkSmartPointer<vtkXMLPolyDataWriter> pdWriter =
vtkSmartPointer<vtkXMLPolyDataWriter>::New();
pdWriter->SetInputData(algPD->GetOutputDataObject(0));
//pdWriter->SetDataModeToAscii();
//pdWriter->SetCompressorTypeToNone();
std::string filenameWithExt = filename;
filenameWithExt.append(".vtp");
pdWriter->SetFileName(filenameWithExt.c_str());
if (BaseLib::getFileExtension(filename).compare("vtp") != 0)
file_name_cpy.append(".vtp");
pdWriter->SetFileName(file_name_cpy.c_str());
return pdWriter->Write();
}
else if (algUG)
vtkUnstructuredGridAlgorithm* algUG = dynamic_cast<vtkUnstructuredGridAlgorithm*>(algorithm);
if (algUG)
{
vtkSmartPointer<vtkXMLUnstructuredGridWriter> ugWriter =
vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
ugWriter->SetInputData(algUG->GetOutputDataObject(0));
//ugWriter->SetDataModeToAscii();
//ugWriter->SetCompressorTypeToNone();
std::string filenameWithExt = filename;
filenameWithExt.append(".vtu");
ugWriter->SetFileName(filenameWithExt.c_str());
if (BaseLib::getFileExtension(filename).compare("vtu") != 0)
file_name_cpy.append(".vtu");
ugWriter->SetFileName(file_name_cpy.c_str());
return ugWriter->Write();
}
WARN("VtkVisPipelineItem::writeToFile(): Unknown data type.");
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment