<HTML><BODY>Anybody who can tell me whats wrong with my code???<br><br><br>Wed, 18 Jun 2014 02:06:35 +0400 от Роман Глуховский <roman_glu@mail.ru>:<br>
<blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
<div id="">
<div class="js-helper js-readmsg-msg">
<style type="text/css"></style>
<div>
<base target="_self" href="https://e.mail.ru/">
<div id="style_14031922350000000726_BODY">
Sorry my fault.<br><br>I use VTK 6.0.0, QT 4.8.1.<br><br>I want to include a SliceViewer in my QT application, when i compile my programm i get no<br>error. The programm loads the DICOM files from the folder, but i get only a black screen, with <br>the correct number of slices.<br><br>I take the SliceViewer from this examaple:<br><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/ReadDICOMSeries" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/ReadDICOMSeries</a>.<br>The example works, but not in my application.<br><br>Here is my code:<br>------------------------------mainwindow.h-------------------------<br>#ifndef MAINWINDOW_H<br>#define MAINWINDOW_H<br><br>#include <QMainWindow><br><br>// some standard vtk headers<br>#include <vtkSmartPointer.h><br>#include <vtkObjectFactory.h><br>#include <vtkRenderWindow.h><br>#include <vtkRenderWindowInteractor.h><br>#include <vtkRenderer.h><br>#include <vtkActor.h><br>// headers needed for this example<br>#include <vtkImageViewer2.h><br>#include <vtkDICOMImageReader.h><br>#include <vtkInteractorStyleImage.h><br>#include <vtkActor2D.h><br>#include <vtkTextProperty.h><br>#include <vtkTextMapper.h><br>// needed to easily convert int to std::string<br>#include <sstream><br><br><br>namespace Ui {<br>class MainWindow;<br>}<br><br>class MainWindow : public QMainWindow<br>{<br> Q_OBJECT<br> <br>public:<br> explicit MainWindow(QWidget *parent = 0);<br> ~MainWindow();<br> <br>private slots:<br> void on_pushButton_clicked();<br><br>private:<br> Ui::MainWindow *ui;<br>};<br><br><br>#endif // MAINWINDOW_H<br><br><br>----------------------mainwindow.cpp--------------------------------<br>#include "mainwindow.h"<br>#include "ui_mainwindow.h"<br><br>// helper class to format slice status message<br>class StatusMessage {<br>public:<br> static std::string Format(int slice, int maxSlice) {<br> std::stringstream tmp;<br> tmp << "Slice Number " << slice + 1 << "/" << maxSlice + 1;<br> return tmp.str();<br> }<br>};<br><br><br>// Define own interaction style<br>class myVtkInteractorStyleImage : public vtkInteractorStyleImage<br>{<br>public:<br> static myVtkInteractorStyleImage* New();<br> vtkTypeMacro(myVtkInteractorStyleImage, vtkInteractorStyleImage);<br><br>protected:<br> vtkImageViewer2* _ImageViewer;<br> vtkTextMapper* _StatusMapper;<br> int _Slice;<br> int _MinSlice;<br> int _MaxSlice;<br><br>public:<br> void SetImageViewer(vtkImageViewer2* imageViewer) {<br> _ImageViewer = imageViewer;<br> _MinSlice = imageViewer->GetSliceMin();<br> _MaxSlice = imageViewer->GetSliceMax();<br> _Slice = _MinSlice;<br> cout << "Slicer: Min = " << _MinSlice << ", Max = " << _MaxSlice << std::endl;<br> }<br><br> void SetStatusMapper(vtkTextMapper* statusMapper) {<br> _StatusMapper = statusMapper;<br> }<br><br><br>protected:<br> void MoveSliceForward() {<br> if(_Slice < _MaxSlice) {<br> _Slice += 1;<br> cout << "MoveSliceForward::Slice = " << _Slice << std::endl;<br> _ImageViewer->SetSlice(_Slice);<br> std::string msg = StatusMessage::Format(_Slice, _MaxSlice);<br> _StatusMapper->SetInput(msg.c_str());<br> _ImageViewer->Render();<br> }<br> }<br><br> void MoveSliceBackward() {<br> if(_Slice > _MinSlice) {<br> _Slice -= 1;<br> cout << "MoveSliceBackward::Slice = " << _Slice << std::endl;<br> _ImageViewer->SetSlice(_Slice);<br> std::string msg = StatusMessage::Format(_Slice, _MaxSlice);<br> _StatusMapper->SetInput(msg.c_str());<br> _ImageViewer->Render();<br> }<br> }<br><br><br> virtual void OnKeyDown() {<br> std::string key = this->GetInteractor()->GetKeySym();<br> if(key.compare("Up") == 0) {<br> //cout << "Up arrow key was pressed." << endl;<br> MoveSliceForward();<br> }<br> else if(key.compare("Down") == 0) {<br> //cout << "Down arrow key was pressed." << endl;<br> MoveSliceBackward();<br> }<br> // forward event<br> vtkInteractorStyleImage::OnKeyDown();<br> }<br><br><br> virtual void OnMouseWheelForward() {<br> //std::cout << "Scrolled mouse wheel forward." << std::endl;<br> MoveSliceForward();<br> // don't forward events, otherwise the image will be zoomed<br> // in case another interactorstyle is used (e.g. trackballstyle, ...)<br> // vtkInteractorStyleImage::OnMouseWheelForward();<br> }<br><br><br> virtual void OnMouseWheelBackward() {<br> //std::cout << "Scrolled mouse wheel backward." << std::endl;<br> if(_Slice > _MinSlice) {<br> MoveSliceBackward();<br> }<br> // don't forward events, otherwise the image will be zoomed<br> // in case another interactorstyle is used (e.g. trackballstyle, ...)<br> // vtkInteractorStyleImage::OnMouseWheelBackward();<br> }<br>};<br><br>vtkStandardNewMacro(myVtkInteractorStyleImage);<br><br><br>MainWindow::MainWindow(QWidget *parent) :<br> QMainWindow(parent),<br> ui(new Ui::MainWindow)<br>{<br> ui->setupUi(this);<br>}<br><br>MainWindow::~MainWindow()<br>{<br> delete ui;<br>}<br><br>void MainWindow::on_pushButton_clicked()<br>{<br> //std::string folder = argv[1];<br> //std::string folder = "/home/joe/Daten/dicom-data/Angio";<br> //std::string folder = "/home/joe/Daten/DicomTestImages";<br><br> //std::cout << std::endl << "Die Daten werden aus dem Ordner: " << folder << " geladen" << std::endl;<br> // Read all the DICOM files in the specified directory.<br> vtkSmartPointer<vtkDICOMImageReader> reader =<br> vtkSmartPointer<vtkDICOMImageReader>::New();<br> reader->SetDirectoryName("/home/joe/Daten/dicom-data/Angio");<br> reader->Update();<br><br> char* fname = reader->GetDirectoryName();<br> std::cout << std::endl << "Die Daten werden aus dem Ordner: " << fname << " geladen" << std::endl;<br><br> // Visualize<br> vtkSmartPointer<vtkImageViewer2> imageViewer =<br> vtkSmartPointer<vtkImageViewer2>::New();<br> imageViewer->SetInputConnection(reader->GetOutputPort());<br><br> // slice status message<br> vtkSmartPointer<vtkTextProperty> sliceTextProp = vtkSmartPointer<vtkTextProperty>::New();<br> sliceTextProp->SetFontFamilyToCourier();<br> sliceTextProp->SetFontSize(20);<br> sliceTextProp->SetVerticalJustificationToBottom();<br> sliceTextProp->SetJustificationToLeft();<br><br> vtkSmartPointer<vtkTextMapper> sliceTextMapper = vtkSmartPointer<vtkTextMapper>::New();<br> std::string msg = StatusMessage::Format(imageViewer->GetSliceMin(), imageViewer->GetSliceMax());<br> sliceTextMapper->SetInput(msg.c_str());<br> sliceTextMapper->SetTextProperty(sliceTextProp);<br><br> vtkSmartPointer<vtkActor2D> sliceTextActor = vtkSmartPointer<vtkActor2D>::New();<br> sliceTextActor->SetMapper(sliceTextMapper);<br> sliceTextActor->SetPosition(15, 10);<br><br> // usage hint message<br> vtkSmartPointer<vtkTextProperty> usageTextProp = vtkSmartPointer<vtkTextProperty>::New();<br> usageTextProp->SetFontFamilyToCourier();<br> usageTextProp->SetFontSize(14);<br> usageTextProp->SetVerticalJustificationToTop();<br> usageTextProp->SetJustificationToLeft();<br><br> vtkSmartPointer<vtkTextMapper> usageTextMapper = vtkSmartPointer<vtkTextMapper>::New();<br> usageTextMapper->SetInput("- Slice with mouse wheel\n or Up/Down-Key\n- Zoom with pressed right\n mouse button while dragging");<br> usageTextMapper->SetTextProperty(usageTextProp);<br><br> vtkSmartPointer<vtkActor2D> usageTextActor = vtkSmartPointer<vtkActor2D>::New();<br> usageTextActor->SetMapper(usageTextMapper);<br> usageTextActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedDisplay();<br> usageTextActor->GetPositionCoordinate()->SetValue( 0.05, 0.95);<br><br> // create an interactor with our own style (inherit from vtkInteractorStyleImage)<br> // in order to catch mousewheel and key events<br> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br> vtkSmartPointer<vtkRenderWindowInteractor>::New();<br><br> vtkSmartPointer<myVtkInteractorStyleImage> myInteractorStyle =<br> vtkSmartPointer<myVtkInteractorStyleImage>::New();<br><br> // make imageviewer2 and sliceTextMapper visible to our interactorstyle<br> // to enable slice status message updates when scrolling through the slices<br> myInteractorStyle->SetImageViewer(imageViewer);<br> myInteractorStyle->SetStatusMapper(sliceTextMapper);<br><br> imageViewer->SetupInteractor(renderWindowInteractor);<br> // make the interactor use our own interactorstyle<br> // cause SetupInteractor() is defining it's own default interatorstyle<br> // this must be called after SetupInteractor()<br> renderWindowInteractor->SetInteractorStyle(myInteractorStyle);<br> // add slice status message and usage hint message to the renderer<br> imageViewer->GetRenderer()->AddActor2D(sliceTextActor);<br> imageViewer->GetRenderer()->AddActor2D(usageTextActor);<br><br> // initialize rendering and interaction<br> //imageViewer->GetRenderWindow()->SetSize(400, 300);<br> //imageViewer->GetRenderer()->SetBackground(0.2, 0.3, 0.4);<br> imageViewer->Render();<br> imageViewer->GetRenderer()->ResetCamera();<br> imageViewer->Render();<br> renderWindowInteractor->Start();<br> return EXIT_SUCCESS;<br>}<br><br>---------------------------------main.cpp------------------<br>#include <QtGui/QApplication><br>#include "mainwindow.h"<br><br>int main(int argc, char *argv[])<br>{<br> QApplication a(argc, argv);<br> MainWindow w;<br> w.show();<br> <br> return a.exec();<br>}<br><br>--------------------------CMakeLists.txt------------------------<br><br>cmake_minimum_required(VERSION 2.8)<br><br>PROJECT(Test)<br><br>FIND_PACKAGE( Qt4 REQUIRED )<br>INCLUDE(${QT_USE_FILE})<br><br>QT4_WRAP_UI(UISrcs mainwindow.ui)<br>QT4_WRAP_CPP(MOCSrcs mainwindow.h)<br><br>find_package(ITK REQUIRED)<br>include(${ITK_USE_FILE})<br>if (ITKVtkGlue_LOADED)<br> find_package(VTK REQUIRED)<br> include(${VTK_USE_FILE})<br>else()<br> find_package(ItkVtkGlue REQUIRED)<br> include(${ItkVtkGlue_USE_FILE})<br> set(Glue ItkVtkGlue)<br>endif()<br>add_executable(Test main.cpp mainwindow.cpp ${MOCSrcs} ${UISrcs})<br><br>if(VTK_LIBRARIES)<br> target_link_libraries(Test<br> ${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES} ${QT_LIBRARIES})<br>else()<br> target_link_libraries(Test vtkHybrid)<br>endif()<br>-------------------------------------------------------------------------------------------------<br><br><br>I hope thats enough informations and somebody can help me.<br><br>Thanks a lot.<br><br><br><br>Tue, 17 Jun 2014 12:18:06 -0400 (EDT) от David Cole <dlrdave@aol.com>:<br>
<blockquote style="border-left:1px solid #0857A6;margin:10px;padding:0 0 0 10px;">
<div>
<div>
<div>
<div>> Can nobody tell me, why i get a black screen?<br>
<br>
Maybe you could send some code that shows us what you're doing. It's <br>
kind of hard to tell you what's wrong without looking at some code... <br>
There are any number of things that could cause a "black screen".<br>
<br>
Do you get any errors reported? What version of VTK are you using?<br>
<br>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</div>
<div>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br>
</div>
<base target="_self" href="https://e.mail.ru/">
</div>
</div>
</div>
</blockquote>
<br></BODY></HTML>