Fraxinus  2023.01.05-dev+develop.0da12
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 
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
vtkSmartPointer< class vtkVolume > vtkVolumePtr
static ImageMapperMonitorPtr create(vtkVolumePtr volume, ImagePtr image)
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
boost::shared_ptr< class ImageMapperMonitor > ImageMapperMonitorPtr
void clipPlanesChanged()
vtkSmartPointer< class vtkVolumeMapper > vtkVolumeMapperPtr
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
void cropBoxChanged()
ImageMapperMonitor(vtkVolumePtr volume, ImagePtr image)
Namespace for all CustusX production code.