Fraxinus  17.12-rc4
An IGT application
cxCameraStyleForView.h
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 #ifndef CXCameraStyleForViewFORVIEW_H
33 #define CXCameraStyleForViewFORVIEW_H
34 
35 #include "org_custusx_core_view_Export.h"
36 
37 #include "cxTransform3D.h"
38 #include "cxForwardDeclarations.h"
39 #include "cxEnumConverter.h"
40 #include "cxViewService.h"
41 #include "cxViewGroupData.h"
43 #include "cxDoubleRange.h"
44 class QIcon;
45 class QWidget;
46 class QMenu;
47 class QActionGroup;
48 class vtkInteractorStyle;
49 
50 namespace cx
51 {
52 typedef boost::shared_ptr<class ViewportPreRenderListener> ViewportPreRenderListenerPtr;
53 typedef boost::shared_ptr<class CoreServices> CoreServicesPtr;
54 
55 typedef boost::shared_ptr<class CameraStyleForView> CameraStyleForViewPtr;
56 using cx::Transform3D;
57 
74 {
75 public:
76  JitterFilter();
77  double newValue(double value);
78 private:
79  DoubleRange range;
80  double currentValue;
81 };
82 
83 struct CameraInfo
84 {
86  explicit CameraInfo(vtkCameraPtr camera);
87  double distance() const { return (pos-focus).length(); }
88  Vector3D vpn() const { return (pos-focus).normal(); }
89 
93  double viewAngle; // vtk View angle in DEGREES
94 };
95 
96 bool similar(const CameraInfo& lhs, const CameraInfo& rhs, double tol=1.0E-6);
97 
109 class org_custusx_core_view_EXPORT CameraStyleForView: public QObject
110 {
111 Q_OBJECT
112 public:
113  explicit CameraStyleForView(CoreServicesPtr backend);
114  void setView(ViewPtr widget);
115 
118  void setCameraStyle(CameraStyleData style);
119  CameraStyleData getCameraStyle();
120 
121 private slots:
122  void setModified();
123  void activeToolChangedSlot();
124 
125 private:
126  ViewPtr getView() const;
127  vtkRendererPtr getRenderer() const;
128  vtkCameraPtr getCamera() const;
129  ToolRep3DPtr getToolRep() const;
130  bool isToolFollowingStyle() const;
131  void onPreRender();
132  void applyCameraStyle();
133 
134  void connectTool();
135  void disconnectTool();
136  void viewportChangedSlot();
137  RegionOfInterest getROI(QString uid) const;
138  void setInteractor(vtkSmartPointer<vtkInteractorStyle> style);
139 
140  CameraStyleData mStyle;
141  ToolPtr mFollowingTool;
142  ViewportListenerPtr mViewportListener;
143  ViewportPreRenderListenerPtr mPreRenderListener;
144  bool mBlockCameraUpdate;
145  ViewPtr mView;
146  CoreServicesPtr mBackend;
147 
148 // Vector3D mPreviousZoomCameraPos;
149  JitterFilter mZoomJitterFilter;
150 
151  Vector3D smoothZoomedCameraPosition(Vector3D pos);
152  void handleLights();
153  CameraInfo viewEntireAutoZoomROI(CameraInfo info);
154  void updateCamera(CameraInfo info);
155  Vector3D getToolTip_r();
156  Transform3D get_rMto();
157 };
158 
162 } //namespace cx
163 
164 #endif // CXCameraStyleForViewFORVIEW_H
boost::shared_ptr< class ViewportListener > ViewportListenerPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
boost::shared_ptr< class ViewportPreRenderListener > ViewportPreRenderListenerPtr
boost::shared_ptr< class View > ViewPtr
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
double newValue(double value)
boost::shared_ptr< class CameraStyleForView > CameraStyleForViewPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
double distance() const
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:59
boost::shared_ptr< class ToolRep3D > ToolRep3DPtr
Vector3D vpn() const
vtkSmartPointer< class vtkCamera > vtkCameraPtr
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr