NorMIT-nav  22.09
An IGT application
cxImageMapperMonitor.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 
12 #include "cxImageMapperMonitor.h"
13 
14 #include <vector>
15 #include <vtkPlane.h>
16 #include <vtkVolume.h>
17 #include <vtkAbstractVolumeMapper.h>
18 #include <vtkPlaneCollection.h>
19 #include <vtkVolumeMapper.h>
20 
21 #include "cxImage.h"
22 
23 
24 namespace cx
25 {
26 
28 {
29  ImageMapperMonitorPtr retval(new ImageMapperMonitor(volume, image));
30  retval->init(); // contains virtual functions
31  return retval;
32 }
33 
34 ImageMapperMonitor::ImageMapperMonitor(vtkVolumePtr volume, ImagePtr image) : mVolume(volume), mImage(image)
35 {
36  if (!mImage)
37  return;
38  connect(mImage.get(), &Data::clipPlanesChanged, this, &ImageMapperMonitor::clipPlanesChangedSlot);
40 }
41 
43 {
44  this->applyClipping();
45  this->applyCropping();
46 }
47 
49 {
50  this->clearClipping();
51 }
52 
53 void ImageMapperMonitor::clipPlanesChangedSlot()
54 {
55  this->applyClipping();
56 }
57 
59 {
60  if (!mImage)
61  return;
62 
63  for (unsigned i=0; i<mPlanes.size(); ++i)
64  {
65  mVolume->GetMapper()->RemoveClippingPlane(mPlanes[i]);
66  }
67  mPlanes.clear();
68 }
69 
71 {
72  this->clearClipping();
73 
74  if (!mImage)
75  return;
76 
77  mPlanes = mImage->getAllClipPlanes();
78  for (unsigned i=0; i<mPlanes.size(); ++i)
79  {
80  mVolume->GetMapper()->AddClippingPlane(mPlanes[i]);
81  }
82 }
83 
84 vtkVolumeMapperPtr ImageMapperMonitor::getMapper()
85 {
86  vtkVolumeMapperPtr mapper = dynamic_cast<vtkVolumeMapper*>(mVolume->GetMapper());
87  return mapper;
88 }
89 
91 {
92  if (!mImage)
93  return;
94 
95  vtkVolumeMapperPtr mapper = this->getMapper();
96  if (!mapper)
97  return;
98  mapper->SetCropping(mImage->getCropping());
99 
100  DoubleBoundingBox3D bb_d = mImage->getCroppingBox();
101 
102  mapper->SetCroppingRegionPlanes(bb_d.begin());
103  mapper->Update();
104 }
105 
106 } // namespace cx
cx::ImageMapperMonitor::mVolume
vtkVolumePtr mVolume
Definition: cxImageMapperMonitor.h:50
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::ImageMapperMonitor::create
static ImageMapperMonitorPtr create(vtkVolumePtr volume, ImagePtr image)
Definition: cxImageMapperMonitor.cpp:27
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxImage.h
vtkVolumePtr
vtkSmartPointer< class vtkVolume > vtkVolumePtr
Definition: vtkForwardDeclarations.h:152
cx::Image::cropBoxChanged
void cropBoxChanged()
vtkVolumeMapperPtr
vtkSmartPointer< class vtkVolumeMapper > vtkVolumeMapperPtr
Definition: vtkForwardDeclarations.h:150
cx::ImageMapperMonitor::~ImageMapperMonitor
~ImageMapperMonitor()
Definition: cxImageMapperMonitor.cpp:48
cx::ImageMapperMonitor::mImage
ImagePtr mImage
Definition: cxImageMapperMonitor.h:51
cx::ImageMapperMonitor::ImageMapperMonitor
ImageMapperMonitor(vtkVolumePtr volume, ImagePtr image)
Definition: cxImageMapperMonitor.cpp:34
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cx::Data::clipPlanesChanged
void clipPlanesChanged()
cxImageMapperMonitor.h
cx::ImageMapperMonitor::clearClipping
virtual void clearClipping()
Definition: cxImageMapperMonitor.cpp:58
cx::ImageMapperMonitor::applyCropping
virtual void applyCropping()
Definition: cxImageMapperMonitor.cpp:90
cx::ImageMapperMonitorPtr
boost::shared_ptr< class ImageMapperMonitor > ImageMapperMonitorPtr
Definition: cxImageMapperMonitor.h:27
cx::ImageMapperMonitor::init
void init()
Definition: cxImageMapperMonitor.cpp:42
cx::ImageMapperMonitor::applyClipping
virtual void applyClipping()
Definition: cxImageMapperMonitor.cpp:70