Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxSlicePlaneClipper.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 
13 /*
14  * sscSlicePlaneClipper.cpp
15  *
16  * Created on: Aug 20, 2010
17  * Author: christiana
18  */
19 
20 #include "cxSlicePlaneClipper.h"
21 
22 #include <vector>
23 #include <vtkPlane.h>
24 
25 #include "cxSliceProxy.h"
26 
27 namespace cx
28 {
29 
31 {
33 }
34 
35 SlicePlaneClipper::SlicePlaneClipper() :
36  mInvertPlane(false)
37 {
38 }
39 
41 {
42 }
43 
45 {
46  if (mSlicer==slicer)
47  return;
48  if (mSlicer)
49  {
50  disconnect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(changedSlot()));
51  }
52  mSlicer = slicer;
53  if (mSlicer)
54  {
55  connect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(changedSlot()));
56  }
57 
58  this->updateClipPlane();
59  this->changedSlot();
60 }
61 
63 {
64  return mSlicer;
65 }
66 
68 {
69  mInvertPlane = on;
70  changedSlot();
71 }
72 
74 {
75  return mInvertPlane;
76 }
77 
81 Vector3D SlicePlaneClipper::getUnitNormal() const
82 {
83  if (mInvertPlane)
84  return Vector3D(0,0,1);
85  else
86  return Vector3D(0,0,-1);
87 }
88 
92 {
93  vtkPlanePtr retval = vtkPlanePtr::New();
94  retval->SetNormal(mClipPlane->GetNormal());
95  retval->SetOrigin(mClipPlane->GetOrigin());
96  return retval;
97 }
98 
100 {
101  return mClipPlane;
102 }
103 
104 void SlicePlaneClipper::updateClipPlane()
105 {
106  if (!mSlicer)
107  return;
108  if (!mClipPlane)
109  mClipPlane = vtkPlanePtr::New();
110 
111  Transform3D rMs = mSlicer->get_sMr().inv();
112 
113  Vector3D n = rMs.vector(this->getUnitNormal());
114  Vector3D p = rMs.coord(Vector3D(0,0,0));
115  mClipPlane->SetNormal(n.begin());
116  mClipPlane->SetOrigin(p.begin());
117 }
118 
119 void SlicePlaneClipper::changedSlot()
120 {
121  if (!mSlicer)
122  return;
123 
124  this->updateClipPlane();
125  emit slicePlaneChanged();
126 }
127 
128 } // namespace cx
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
void setSlicer(SliceProxyPtr slicer)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
static SlicePlaneClipperPtr New()
boost::shared_ptr< class SlicePlaneClipper > SlicePlaneClipperPtr
Clip several 3D volumes using a SliceProxy.
vtkSmartPointer< class vtkPlane > vtkPlanePtr
Namespace for all CustusX production code.