CustusX  15.4.0-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxInteractiveClipper.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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxInteractiveClipper.h"
34 
35 #include "cxVolumetricRep.h"
36 
37 #include "cxSliceComputer.h"
38 
39 #include "cxSlicePlaneClipper.h"
40 #include "cxSlicePlanes3DRep.h"
41 #include "cxSliceProxy.h"
42 #include "cxImage.h"
43 #include "cxTrackingService.h"
44 
45 #include "cxCoreServices.h"
46 
47 
48 namespace cx
49 {
50 
52  mUseClipper(false),
53  mBackend(backend)
54 {
55 
56  // create a slice planes proxy containing all slice definitions,
57  // for use with the clipper
58  PatientModelServicePtr dm = mBackend->patientModelService;
59  mSlicePlanesProxy = SlicePlanesProxyPtr(new SlicePlanesProxy());
60  mSlicePlanesProxy->addSimpleSlicePlane(ptSAGITTAL, dm);
61  mSlicePlanesProxy->addSimpleSlicePlane(ptCORONAL, dm);
62  mSlicePlanesProxy->addSimpleSlicePlane(ptAXIAL, dm);
63  mSlicePlanesProxy->addSimpleSlicePlane(ptANYPLANE, dm);
64  mSlicePlanesProxy->addSimpleSlicePlane(ptSIDEPLANE, dm);
65  mSlicePlanesProxy->addSimpleSlicePlane(ptRADIALPLANE, dm);
66 
67  mSlicePlaneClipper = SlicePlaneClipper::New();
68 
69  connect(mSlicePlaneClipper.get(), SIGNAL(slicePlaneChanged()), this, SLOT(changedSlot()));
70  connect(this, SIGNAL(changed()), this, SLOT(changedSlot()));
71  connect(mBackend->trackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(activeToolChangedSlot()));
72 
73  this->activeToolChangedSlot();
74  this->changedSlot();
75 }
76 
77 
78 void InteractiveClipper::setSlicePlane(PLANE_TYPE plane)
79 {
80  if (mSlicePlaneClipper->getSlicer() && mSlicePlaneClipper->getSlicer()->getComputer().getPlaneType() == plane)
81  return;
82 
83  if (mSlicePlanesProxy->getData().count(plane))
84  {
85  mSlicePlaneClipper->setSlicer(mSlicePlanesProxy->getData()[plane].mSliceProxy);
86  emit changed();
87  }
88 }
89 
91 {
92  if (!mImage)
93  return;
94 
95  mImage->addPersistentClipPlane(mSlicePlaneClipper->getClipPlaneCopy());
96 }
98 {
99  if (!mImage)
100  return;
101  mImage->clearPersistentClipPlanes();
102 }
103 
105 {
106  if (!mSlicePlaneClipper->getSlicer())
107  return ptCOUNT;
108  return mSlicePlaneClipper->getSlicer()->getComputer().getPlaneType();
109 }
110 
112 {
113  return mUseClipper;
114 }
116 {
117  return mSlicePlaneClipper->getInvertPlane();
118 }
120 {
121  mUseClipper = on;
122  emit changed();
123 }
125 {
126  mSlicePlaneClipper->setInvertPlane(on);
127  emit changed();
128 }
129 
130 PLANE_TYPE InteractiveClipper::getPlaneType()
131 {
132  if (!mSlicePlaneClipper->getSlicer())
133  return ptCOUNT;
134  return mSlicePlaneClipper->getSlicer()->getComputer().getPlaneType();
135 }
136 
138 {
139  return mImage;
140 }
141 
143 {
144  if (mImage)
145  mImage->setInteractiveClipPlane(vtkPlanePtr());
146  mImage = image;
147  emit changed();
148 }
149 
150 void InteractiveClipper::changedSlot()
151 {
152  if (!mImage)
153  return;
154 
155  if (mUseClipper)
156  {
157  PLANE_TYPE currentPlane = this->getPlaneType();
158 
159  std::vector<PLANE_TYPE> planes = this->getAvailableSlicePlanes();
160 
161  if (!std::count(planes.begin(), planes.end(), currentPlane)) //if (this->getPlaneType()==ptCOUNT)
162  {
163  if (planes.empty()) // no slices: remove clipping
164  {
165  currentPlane = ptCOUNT;
166  }
167  else
168  {
169  currentPlane = planes.front();
170  }
171  }
172 
173  // reset plane anyway. It might be the same planeType but a different sliceProxy.
174  mSlicePlaneClipper->setSlicer(mSlicePlanesProxy->getData()[currentPlane].mSliceProxy);
175  mImage->setInteractiveClipPlane(mSlicePlaneClipper->getClipPlane());
176  }
177  else
178  {
179  mImage->setInteractiveClipPlane(vtkPlanePtr());
180  }
181 
182 }
183 
184 std::vector<PLANE_TYPE> InteractiveClipper::getAvailableSlicePlanes() const
185 {
186  std::vector<PLANE_TYPE> retval;
187  SlicePlanesProxy::DataMap data = mSlicePlanesProxy->getData();
188  for (SlicePlanesProxy::DataMap::iterator iter = data.begin(); iter != data.end(); ++iter)
189  {
190  retval.push_back(iter->first);
191  }
192  return retval;
193 }
194 
195 void InteractiveClipper::activeToolChangedSlot()
196 {
197  ToolPtr activTool = mBackend->trackingService->getActiveTool();
198 
199  SlicePlanesProxy::DataMap data = mSlicePlanesProxy->getData();
200  for (SlicePlanesProxy::DataMap::iterator iter = data.begin(); iter != data.end(); ++iter)
201  {
202  iter->second.mSliceProxy->setTool(activTool);
203  }
204 }
205 
206 } // namespace cx
ptCORONAL
a slice seen from the front of the patient
Definition: cxDefinitions.h:56
boost::shared_ptr< class SlicePlanesProxy > SlicePlanesProxyPtr
std::vector< PLANE_TYPE > getAvailableSlicePlanes() const
std::map< PLANE_TYPE, DataType > DataMap
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
ptAXIAL
a slice seen from the top of the patient
Definition: cxDefinitions.h:56
void saveClipPlaneToVolume()
save the current clip to image
ptSAGITTAL
a slice seen from the side of the patient
Definition: cxDefinitions.h:56
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Helper class for managing a set of slice planes.
ptRADIALPLANE
y-rotated 90* relative to anyplane (bird's view)
Definition: cxDefinitions.h:56
static SlicePlaneClipperPtr New()
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:59
void setSlicePlane(PLANE_TYPE plane)
InteractiveClipper(CoreServicesPtr backend)
ptANYPLANE
a plane aligned with the tool base plane
Definition: cxDefinitions.h:56
vtkSmartPointer< class vtkPlane > vtkPlanePtr
void setImage(ImagePtr image)
void clearClipPlanesInVolume()
clear all saved clips in the image.
ptSIDEPLANE
z-rotated 90* relative to anyplane (dual anyplane)
Definition: cxDefinitions.h:56
boost::shared_ptr< class Tool > ToolPtr