Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Step3.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "QmitkRegisterClasses.h"
18 #include "QmitkRenderWindow.h"
19 
20 #include <mitkIOUtil.h>
21 #include <mitkProperties.h>
22 #include <mitkRenderingManager.h>
24 #include <mitkTransferFunction.h>
26 
27 #include <itksys/SystemTools.hxx>
28 
29 #include <QApplication>
30 
31 //##Documentation
32 //## @brief Change the type of display to 3D
33 //##
34 //## As in Step2, load one or more data sets (many image, surface
35 //## and other formats), but display it in a 3D view.
36 //## The QmitkRenderWindow is now used for displaying a 3D view, by
37 //## setting the used mapper-slot to Standard3D.
38 //## Since volume-rendering is a (rather) slow procedure, the default
39 //## is that images are not displayed in the 3D view. For this example,
40 //## we want volume-rendering, thus we switch it on by setting
41 //## the Boolean-property "volumerendering" to "true".
42 int main(int argc, char *argv[])
43 {
44  QApplication qtapplication(argc, argv);
45  if (argc < 2)
46  {
47  fprintf(
48  stderr, "Usage: %s [filename1] [filename2] ...\n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str());
49  return 1;
50  }
51 
52  // Register Qmitk-dependent global instances
54 
55  //*************************************************************************
56  // Part I: Basic initialization
57  //*************************************************************************
58 
59  // Create a DataStorage
61 
62  //*************************************************************************
63  // Part II: Create some data by reading files
64  //*************************************************************************
65  int i;
66  for (i = 1; i < argc; ++i)
67  {
68  // For testing
69  if (strcmp(argv[i], "-testing") == 0)
70  continue;
71 
72  //*********************************************************************
73  // Part III: Put the data into the datastorage
74  //*********************************************************************
75  // Load datanode (eg. many image formats, surface formats, etc.)
77 
78  if (dataNodes->empty())
79  {
80  fprintf(stderr, "Could not open file %s \n\n", argv[i]);
81  exit(2);
82  }
83  mitk::DataNode::Pointer node = dataNodes->at(0);
84 
85  // *********************************************************
86  // ********************* START OF NEW PART 1 (Step 3a) *****
87  // *********************************************************
88 
89  //*********************************************************************
90  // Part IV: We want all images to be volume-rendered
91  //*********************************************************************
92 
93  // Check if the data is an image by dynamic_cast-ing the data
94  // contained in the node. Warning: dynamic_cast's are rather slow,
95  // do not use it too often!
96  mitk::Image::Pointer image = dynamic_cast<mitk::Image *>(node->GetData());
97  if (image.IsNotNull())
98  {
99  // Set the property "volumerendering" to the Boolean value "true"
100  node->SetProperty("volumerendering", mitk::BoolProperty::New(true));
101 
102  // Create a transfer function to assign optical properties (color and opacity) to grey-values of the data
104  tf->InitializeByMitkImage(image);
105 
106  // Set the color transfer function AddRGBPoint(double x, double r, double g, double b)
107  tf->GetColorTransferFunction()->AddRGBPoint(tf->GetColorTransferFunction()->GetRange()[0], 1.0, 0.0, 0.0);
108  tf->GetColorTransferFunction()->AddRGBPoint(tf->GetColorTransferFunction()->GetRange()[1], 1.0, 1.0, 0.0);
109 
110  // Set the piecewise opacity transfer function AddPoint(double x, double y)
111  tf->GetScalarOpacityFunction()->AddPoint(0, 0);
112  tf->GetScalarOpacityFunction()->AddPoint(tf->GetColorTransferFunction()->GetRange()[1], 1);
113 
114  node->SetProperty("TransferFunction", mitk::TransferFunctionProperty::New(tf.GetPointer()));
115  }
116 
117  // *********************************************************
118  // ******************* END OF NEW PART 1 (Step 3a) *********
119  // *********************************************************
120  }
121 
122  //*************************************************************************
123  // Part V: Create window and pass the tree to it
124  //*************************************************************************
125 
126  // Create a renderwindow
127  QmitkRenderWindow renderWindow;
128 
129  // Tell the renderwindow which (part of) the datastorage to render
130  renderWindow.GetRenderer()->SetDataStorage(ds);
131 
132  // *********************************************************
133  // ****************** START OF NEW PART 2 (Step 3b) ********
134  // *********************************************************
135  // Use it as a 3D view!
137 
138  // Reposition the camera to include all visible actors
139  renderWindow.GetRenderer()->GetVtkRenderer()->ResetCamera();
140 
141  // *********************************************************
142  // ******************* END OF NEW PART 2 (Step 3b) *********
143  // *********************************************************
144 
145  //*************************************************************************
146  // Part VI: Qt-specific initialization
147  //*************************************************************************
148  renderWindow.show();
149  renderWindow.resize(256, 256);
150 
152 
153 // for testing
154 #include "QtTesting.h"
155  if (strcmp(argv[argc - 1], "-testing") != 0)
156  return qtapplication.exec();
157  else
158  return QtTesting();
159 }
160 
itk::SmartPointer< Self > Pointer
virtual void SetDataStorage(mitk::DataStorage *storage) override
set the datastorage that will be used for rendering
int main(int argc, char *argv[])
Change the type of display to 3D.
Definition: Step3.cpp:42
MITKQTWIDGETS_EXPORT void QmitkRegisterClasses()
static Pointer New()
static RenderingManager * GetInstance()
Image class for storing images.
Definition: mitkImage.h:76
MITK implementation of the QVTKWidget.
static Pointer New()
virtual mitk::VtkPropRenderer * GetRenderer()
virtual void SetMapperID(const MapperSlotId mapperId) override
Set the MapperSlotId to use.
int QtTesting()
Definition: QtTesting.cpp:22
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:483
vtkRenderer * GetVtkRenderer() const
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)