[vtkusers] Example VTK with Qt
Agata Krasoń
agatakrason at gmail.com
Fri Aug 17 10:22:26 EDT 2012
Thanks very much for this example ! And good advice ;)
I can load and display mesh corectly !
I have only small problem with save as.. file
// Constructor
SimpleView::SimpleView()
{
this->ui = new Ui_SimpleView;
this->ui->setupUi(this);
// Set up action signals and slots
connect(this->ui->actionExit, SIGNAL(triggered()), this,
SLOT(slotExit()));
connect(this->ui->openButton, SIGNAL(clicked()), this, SLOT(openFile()));
connect(this->ui->saveButton, SIGNAL(clicked()), this, SLOT(saveFile()));
}
void SimpleView::slotExit()
{
qApp->exit();
}
void SimpleView::openFile()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open file with
model/mesh"), "", tr("files (*.vtp);;All Files (*)"));
std::string filename = fileName.toLatin1();
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(fileName.toLatin1());
reader->Update();
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
polydata = reader->GetOutput();
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
this->ui->qvtkWidget->GetRenderWindow()->AddRenderer(renderer);
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
polydata = reader->GetOutput();
mapper->SetInput(polydata);
actor->SetMapper(mapper);
renderer->AddActor(actor);
}
void SimpleView::saveFile()
{
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(fileName.toLatin1());
reader->Update();
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "
",tr("Mesh (*.vtp)"));
std::string filename = fileName.toLatin1();
vtkSmartPointer<vtkXMLPolyDataWriter> writer =
vtkSmartPointer<vtkXMLPolyDataWriter>::New();
writer->SetInput(reader->GetOutput());
writer->SetFileName(fileName.toLatin1());
writer->Write();
}
Error message :
vtkStreamingDemandDrivenPipeline (053B1F78): Algorithm
vtkXMLPolyDataReader(053B2AD0) returned failure for request: vtkInformation
(053C1730)
Debug: Off
Modified Time: 2328
Reference Count: 1
Registered Events: (none)
Request: REQUEST_INFORMATION
ALGORITHM_AFTER_FORWARD: 1
FORWARD_DIRECTION: 0
ERROR: In C:\VTK\VTK-5.8\sources\IO\vtkXMLReader.cxx, line 219
vtkXMLPolyDataReader (053B2AD0): Error opening file
ERROR: In C:\VTK\VTK-5.8\sources\Filtering\vtkExecutive.cxx, line 756
vtkStreamingDemandDrivenPipeline (053B1F78): Algorithm
vtkXMLPolyDataReader(053B2AD0) returned failure for request: vtkInformation
(053C4060)
Debug: Off
Modified Time: 2453
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FROM_OUTPUT_PORT: 0
ALGORITHM_AFTER_FORWARD: 1
FORWARD_DIRECTION: 0
2012/8/17 David Doria <daviddoria at gmail.com>
> On Fri, Aug 17, 2012 at 10:19 AM, Agata Krasoń <agatakrason at gmail.com>
> wrote:
> > Thanks very much for this example ! And good advice ;)
> >
> > I can load and display mesh corectly !
> > I have only small problem with save as.. file
>
> Please keep the discussion on the mailing list.
>
> What is the problem?
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120817/1cc5d29b/attachment.htm>
More information about the vtkusers
mailing list