Fraxinus  2023.01.05-dev+develop.0da12
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 
#define CX_ASSERT(statement)
Definition: cxLogger.h:116
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
virtual ~Image2DProxy()
vtkSmartPointer< class vtkImageActor > vtkImageActorPtr
boost::shared_ptr< class View > ViewPtr
void setImage(ImagePtr image)
void setTransformOffset(Transform3D rMrr)
vtkSmartPointer< class vtkLookupTable > vtkLookupTablePtr
Default implementation of Rep.
Definition: cxRepImpl.h:42
vtkImageActorPtr getActor()
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
boost::shared_ptr< class Image2DProxy > Image2DProxyPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
static Image2DProxyPtr New()
void setImage(ImagePtr image)
Helper class for applying sscLUT2D to an image.
virtual void addRepActorsToViewRenderer(ViewPtr view)
Namespace for all CustusX production code.