Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkODFRenderWidget.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 "QmitkODFRenderWidget.h"
18 #include <mitkLookupTable.h>
20 #include <vtkSmartPointer.h>
21 #include <mitkPlaneGeometry.h>
22 
23 QmitkODFRenderWidget::QmitkODFRenderWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
24 {
25  //create Layouts
26  QmitkODFRenderWidgetLayout = new QHBoxLayout( this );
27 
28  //Set Layout to widget
29  this->setLayout(QmitkODFRenderWidgetLayout);
30 
31  //Create RenderWindow
32  m_RenderWindow = new QmitkRenderWindow(this, "odf render widget");
33  m_RenderWindow->setMaximumSize(300,300);
35 
36  //m_RenderWindow->SetLayoutIndex( 3 );
38 }
39 
40 
42 {
43 }
44 
46 {
47  try
48  {
52 
54 
55  vtkPolyData *polyData = vtkPolyData::New();
56  vtkPoints *points = vtkPoints::New();
57  vtkFloatArray *scalars = vtkFloatArray::New();
58 
59  for (int i=0; i<QBALL_ODFSIZE; i++){
60  double p[3];
61  m_TemplateOdf->GetPoints()->GetPoint(i,p);
62  double val = odf[i];
63 
64  p[0] *= val;
65  p[1] *= val;
66  p[2] *= val;
67  points->InsertPoint(i,p);
68 
69  scalars->InsertTuple1(i, 1-val);
70  }
71 
72  polyData->SetPoints(points);
73  vtkCellArray* polys = m_TemplateOdf->GetPolys();
74  polyData->SetPolys(polys);
75  polyData->GetPointData()->SetScalars(scalars);
76 
77  polys->Delete();
78  scalars->Delete();
79  points->Delete();
80 
81  m_Surface->SetVtkPolyData(polyData);
82  m_Node->SetData(m_Surface);
83 
85 
86  // assign an empty vtk lookup table to the odf renderer, it is the same
87  // the ODF 2D Mapper has
88  vtkLookupTable *lut = vtkLookupTable::New();
89  mitkLut->SetVtkLookupTable( lut );
90 
92  mitkLutProp->SetLookupTable(mitkLut);
93  m_Node->SetProperty( "LookupTable", mitkLutProp );
94 
95  m_Node->SetProperty("scalar visibility", mitk::BoolProperty::New(true));
96  m_Node->SetProperty("color mode", mitk::BoolProperty::New(true));
97  m_Node->SetProperty("material.specularCoefficient", mitk::FloatProperty::New(0.5));
98 
99  m_ds->Add(m_Node);
100 
102 
103  // adjust camera to current plane rotation
104  mitk::PlaneGeometry::ConstPointer worldPlaneGeometry = mitk::BaseRenderer::GetInstance(m_RenderWindow->GetVtkRenderWindow())->GetCurrentWorldPlaneGeometry();
105  mitk::Vector3D normal = worldPlaneGeometry->GetNormal();
106  mitk::Vector3D up = worldPlaneGeometry->GetAxisVector(1);
107  normal.Normalize();
108  up.Normalize();
109 
110  vtkSmartPointer<vtkCamera> cam = vtkSmartPointer<vtkCamera>::New();
111  const double camPos[3] = {normal[0],normal[1],normal[2]};
112  const double camUp[3] = {up[0],up[1],up[2]};
113  cam->SetPosition(camPos);
114  cam->SetViewUp(camUp);
115  cam->SetParallelProjection(1);
116  m_RenderWindow->GetRenderer()->GetVtkRenderer()->SetActiveCamera(cam);
117  m_RenderWindow->update();
118  }
119  catch (...)
120  {
121 
122  }
123 }
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
mitk::DataNode::Pointer m_Node
virtual void SetDataStorage(mitk::DataStorage *storage) override
set the datastorage that will be used for rendering
void GenerateODF(itk::OrientationDistributionFunction< double, QBALL_ODFSIZE > odf)
virtual vtkRenderWindow * GetVtkRenderWindow() override
static Pointer New()
mitk::StandaloneDataStorage::Pointer m_ds
Represents an ODF for Q-Ball imaging.
QmitkRenderWindow * m_RenderWindow
static Pointer New()
static Pointer New()
MITK implementation of the QVTKWidget.
#define QBALL_ODFSIZE
QmitkODFRenderWidget(QWidget *parent=0, Qt::WindowFlags f=0)
virtual mitk::VtkPropRenderer * GetRenderer()
static Pointer New()
mitk::Surface::Pointer m_Surface
QHBoxLayout * QmitkODFRenderWidgetLayout
virtual void SetMapperID(const MapperSlotId mapperId) override
Set the MapperSlotId to use.
static Pointer New()
vtkRenderer * GetVtkRenderer() const
static Pointer New()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.