NorMIT-nav  22.09
An IGT application
cxImage2DRep3D.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxImage2DRep3D.h"
12 
13 #include "vtkRenderer.h"
14 #include "vtkImageActor.h"
15 #include "vtkImageData.h"
16 #include "vtkMatrix4x4.h"
17 #include "cxLogger.h"
18 
19 #include "cxSlicedImageProxy.h"
20 #include "cxImage.h"
21 #include "cxView.h"
22 #include "cxImageLUT2D.h"
23 
24 //---------------------------------------------------------
25 namespace cx
26 {
27 //---------------------------------------------------------
28 
30 {
31  m_rMrr = Transform3D::Identity();
32  mActor = vtkImageActorPtr::New();
33  mImageWithLUTProxy.reset(new ApplyLUTToImage2DProxy());
34 }
35 
37 {
38  mImage.reset();
39 }
40 
42 {
43  return Image2DProxyPtr(new Image2DProxy());
44 }
45 
47 {
48  return mActor;
49 }
50 
52 {
53 
54  if (image==mImage)
55  {
56  return;
57  }
58 
59  if (mImage)
60  {
61  disconnect(mImage.get(), SIGNAL(vtkImageDataChanged()), this, SLOT(vtkImageDataChangedSlot()));
62  disconnect(mImage.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
63  disconnect(mImage.get(), SIGNAL(transferFunctionsChanged()), this, SLOT(transferFunctionsChangedSlot()));
64  }
65 
66  mImage = image;
67 
68  if (mImage)
69  {
70  connect(mImage.get(), SIGNAL(vtkImageDataChanged()), this, SLOT(vtkImageDataChangedSlot()));
71  connect(mImage.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
72  connect(mImage.get(), SIGNAL(transferFunctionsChanged()), this, SLOT(transferFunctionsChangedSlot()));
73  }
74 
75  if (mImage)
76  {
77  CX_ASSERT(mImage->is2D()); // class only treats 2d images.
78 
79  mImageWithLUTProxy->setInputData(mImage->getBaseVtkImageData(), mImage->getLookupTable2D()->getOutputLookupTable());
80  }
81  else
82  {
83  mImageWithLUTProxy->setInputData(vtkImageDataPtr(), vtkLookupTablePtr());
84  }
85 
86  this->vtkImageDataChangedSlot();
87  this->transformChangedSlot();
88 }
89 
90 void Image2DProxy::vtkImageDataChangedSlot()
91 {
92  mActor->SetInputData(mImageWithLUTProxy->getOutput());
93 }
94 
97 void Image2DProxy::transformChangedSlot()
98 {
99  if (!mImage)
100  {
101  return;
102  }
103 
104  Transform3D rrMd = mImage->get_rMd();
105  Transform3D rMd = m_rMrr * rrMd;
106 
107  mActor->SetUserMatrix(rMd.getVtkMatrix());
108 }
109 
110 void Image2DProxy::transferFunctionsChangedSlot()
111 {
112  mImageWithLUTProxy->setInputData(mImage->getBaseVtkImageData(), mImage->getLookupTable2D()->getOutputLookupTable());
113 }
114 
116 {
117  m_rMrr = rMrr;
118  this->transformChangedSlot();
119 }
120 
121 
122 
123 // --------------------------------------------------------
124 // --------------------------------------------------------
125 // --------------------------------------------------------
126 
127 
129  RepImpl("")
130 {
131  mProxy = Image2DProxy::New();
132 }
133 
135 {
136 }
137 
139 {
140  mProxy->setImage(image);
141 }
142 
144 {
145  view->getRenderer()->AddActor(mProxy->getActor());
146 }
147 
149 {
150  view->getRenderer()->RemoveActor(mProxy->getActor());
151 }
152 
153 
154 //---------------------------------------------------------
155 }//end namespace
156 //---------------------------------------------------------
157 
vtkImageActorPtr
vtkSmartPointer< class vtkImageActor > vtkImageActorPtr
Definition: vtkForwardDeclarations.h:64
cxLogger.h
CX_ASSERT
#define CX_ASSERT(statement)
Definition: cxLogger.h:116
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxImage.h
cxImage2DRep3D.h
vtkImageDataPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
Definition: cxVideoConnectionWidget.h:30
cxSlicedImageProxy.h
cx::ApplyLUTToImage2DProxy
Helper class for applying sscLUT2D to an image.
Definition: cxSlicedImageProxy.h:48
cx::Image2DProxy::setImage
void setImage(ImagePtr image)
Definition: cxImage2DRep3D.cpp:51
cx::Image2DProxyPtr
boost::shared_ptr< class Image2DProxy > Image2DProxyPtr
Definition: cxCustomMetricRep.h:29
cx::Image2DProxy::New
static Image2DProxyPtr New()
Definition: cxImage2DRep3D.cpp:41
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cxView.h
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cx::Image2DRep3D::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxImage2DRep3D.cpp:148
cx::Image2DRep3D::addRepActorsToViewRenderer
virtual void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxImage2DRep3D.cpp:143
cx::Image2DRep3D::Image2DRep3D
Image2DRep3D()
Definition: cxImage2DRep3D.cpp:128
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::RepImpl
Default implementation of Rep.
Definition: cxRepImpl.h:42
cx::Image2DRep3D::setImage
void setImage(ImagePtr image)
Definition: cxImage2DRep3D.cpp:138
cx::Image2DProxy::getActor
vtkImageActorPtr getActor()
Definition: cxImage2DRep3D.cpp:46
cx::Image2DProxy::setTransformOffset
void setTransformOffset(Transform3D rMrr)
Definition: cxImage2DRep3D.cpp:115
cxImageLUT2D.h
vtkLookupTablePtr
vtkSmartPointer< class vtkLookupTable > vtkLookupTablePtr
Definition: vtkForwardDeclarations.h:88
cx::Image2DRep3D::~Image2DRep3D
virtual ~Image2DRep3D()
Definition: cxImage2DRep3D.cpp:134
cx::Image2DProxy::~Image2DProxy
virtual ~Image2DProxy()
Definition: cxImage2DRep3D.cpp:36
cx::Image2DProxy::Image2DProxy
Image2DProxy()
Definition: cxImage2DRep3D.cpp:29