comparison Samples/Sdl/FusionMprSdl.h @ 828:28f99af358fa

Merge + FusionMprSdl
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 29 May 2019 16:15:04 +0200
parents 2fd96a637a59
children e3c56d4f863f
comparison
equal deleted inserted replaced
827:2fd96a637a59 828:28f99af358fa
17 * You should have received a copy of the GNU Affero General Public License 17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/ 19 **/
20 20
21 #include "../../Framework/Messages/IObserver.h" 21 #include "../../Framework/Messages/IObserver.h"
22 #include "../../Framework/Messages/IMessageEmitter.h"
23 #include "../../Framework/Oracle/OracleCommandExceptionMessage.h"
22 #include "../../Framework/Scene2DViewport/ViewportController.h" 24 #include "../../Framework/Scene2DViewport/ViewportController.h"
25 #include "../../Framework/Volumes/DicomVolumeImage.h"
26 #include "../../Framework/Oracle/ThreadedOracle.h"
23 27
24 #include <boost/enable_shared_from_this.hpp> 28 #include <boost/enable_shared_from_this.hpp>
29 #include <boost/thread.hpp>
30 #include <boost/noncopyable.hpp>
31
25 #include <SDL.h> 32 #include <SDL.h>
26 #include "../../Framework/Volumes/DicomVolumeImage.h"
27 #include "../../Framework/Oracle/OracleCommandExceptionMessage.h"
28 33
29 namespace OrthancStone 34 namespace OrthancStone
30 { 35 {
31 class OpenGLCompositor; 36 class OpenGLCompositor;
32 class IVolumeSlicer; 37 class IVolumeSlicer;
33 class ILayerStyleConfigurator; 38 class ILayerStyleConfigurator;
34 class DicomStructureSetLoader; 39 class DicomStructureSetLoader;
35 class IOracle; 40 class IOracle;
41 class ThreadedOracle;
36 class VolumeSceneLayerSource; 42 class VolumeSceneLayerSource;
37 43 class NativeFusionMprApplicationContext;
44
45
38 enum FusionMprGuiTool 46 enum FusionMprGuiTool
39 { 47 {
40 FusionMprGuiTool_Rotate = 0, 48 FusionMprGuiTool_Rotate = 0,
41 FusionMprGuiTool_Pan, 49 FusionMprGuiTool_Pan,
42 FusionMprGuiTool_Zoom, 50 FusionMprGuiTool_Zoom,
52 static const unsigned int FONT_SIZE_0 = 32; 60 static const unsigned int FONT_SIZE_0 = 32;
53 static const unsigned int FONT_SIZE_1 = 24; 61 static const unsigned int FONT_SIZE_1 = 24;
54 62
55 class Scene2D; 63 class Scene2D;
56 64
65 /**
66 This application subclasses IMessageEmitter to use a mutex before forwarding Oracle messages (that
67 can be sent from multiple threads)
68 */
57 class FusionMprSdlApp : public IObserver 69 class FusionMprSdlApp : public IObserver
58 , public boost::enable_shared_from_this<FusionMprSdlApp> 70 , public boost::enable_shared_from_this<FusionMprSdlApp>
71 , public IMessageEmitter
59 { 72 {
60 public: 73 public:
61 // 12 because. 74 // 12 because.
62 FusionMprSdlApp(MessageBroker& broker); 75 FusionMprSdlApp(MessageBroker& broker);
76
63 void PrepareScene(); 77 void PrepareScene();
64 void Run(); 78 void Run();
65 void SetInfoDisplayMessage(std::string key, std::string value); 79 void SetInfoDisplayMessage(std::string key, std::string value);
66 void DisableTracker(); 80 void DisableTracker();
67 81
75 recompute the visual elements whose content depend upon the scene transform 89 recompute the visual elements whose content depend upon the scene transform
76 */ 90 */
77 void OnSceneTransformChanged( 91 void OnSceneTransformChanged(
78 const ViewportController::SceneTransformChanged& message); 92 const ViewportController::SceneTransformChanged& message);
79 93
94
95 virtual void EmitMessage(const IObserver& observer,
96 const IMessage& message) ORTHANC_OVERRIDE
97 {
98 try
99 {
100 boost::unique_lock<boost::shared_mutex> lock(mutex_);
101 oracleObservable_.EmitMessage(observer, message);
102 }
103 catch (Orthanc::OrthancException& e)
104 {
105 LOG(ERROR) << "Exception while emitting a message: " << e.What();
106 throw;
107 }
108 }
109
80 private: 110 private:
111 #if 1
112 // if threaded (not wasm)
113 MessageBroker& broker_;
114 IObservable oracleObservable_;
115 ThreadedOracle oracle_;
116 boost::shared_mutex mutex_; // to serialize messages from the ThreadedOracle
117 #endif
118
81 void SelectNextTool(); 119 void SelectNextTool();
82 120
83 /** 121 /**
84 This returns a random point in the canvas part of the scene, but in 122 This returns a random point in the canvas part of the scene, but in
85 scene coordinates 123 scene coordinates
130 void DisplayInfoText(); 168 void DisplayInfoText();
131 void HideInfoText(); 169 void HideInfoText();
132 170
133 private: 171 private:
134 CoordinateSystem3D plane_; 172 CoordinateSystem3D plane_;
135 IOracle* oracle_ = nullptr; 173
136 boost::shared_ptr<VolumeSceneLayerSource> source1_, source2_, source3_; 174 boost::shared_ptr<VolumeSceneLayerSource> source1_, source2_, source3_;
137 175
138 std::auto_ptr<OpenGLCompositor> compositor_; 176 std::auto_ptr<OpenGLCompositor> compositor_;
139 /** 177 /**
140 WARNING: the measuring tools do store a reference to the scene, and it 178 WARNING: the measuring tools do store a reference to the scene, and it