comparison Applications/Samples/SimpleViewerApplication.h @ 249:54c7284b0eff am-2

merged useful changes from branch am
author am@osimis.io
date Mon, 02 Jul 2018 12:45:40 +0200
parents e802578e1554
children 192e6e349e69
comparison
equal deleted inserted replaced
248:2da24bf88100 249:54c7284b0eff
11 * 11 *
12 * This program is distributed in the hope that it will be useful, but 12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details. 15 * Affero General Public License for more details.
16 * 16 *
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 21
32 namespace OrthancStone 32 namespace OrthancStone
33 { 33 {
34 namespace Samples 34 namespace Samples
35 { 35 {
36 class SimpleViewerApplication : 36 class SimpleViewerApplication :
37 public SampleApplicationBase, 37 public SampleApplicationBase,
38 private ILayerSource::IObserver 38 private ILayerSource::IObserver
39 { 39 {
40 private: 40 private:
41 class Interactor : public IWorldSceneInteractor 41 class Interactor : public IWorldSceneInteractor
42 { 42 {
43 private: 43 private:
69 if (statusBar != NULL) 69 if (statusBar != NULL)
70 { 70 {
71 Vector p = dynamic_cast<LayerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y); 71 Vector p = dynamic_cast<LayerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y);
72 72
73 char buf[64]; 73 char buf[64];
74 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)", 74 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)",
75 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0); 75 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0);
76 statusBar->SetMessage(buf); 76 statusBar->SetMessage(buf);
77 } 77 }
78 } 78 }
79 79
80 virtual void MouseWheel(WorldSceneWidget& widget, 80 virtual void MouseWheel(WorldSceneWidget& widget,
81 MouseWheelDirection direction, 81 MouseWheelDirection direction,
82 KeyboardModifiers modifiers, 82 KeyboardModifiers modifiers,
83 IStatusBar* statusBar) 83 IStatusBar* statusBar)
84 { 84 {
85 // int scale = (modifiers & KeyboardModifiers_Control ? 10 : 1); 85 // int scale = (modifiers & KeyboardModifiers_Control ? 10 : 1);
86 86
87 // switch (direction) 87 // switch (direction)
88 // { 88 // {
89 // case MouseWheelDirection_Up: 89 // case MouseWheelDirection_Up:
90 // application_.OffsetSlice(-scale); 90 // application_.OffsetSlice(-scale);
91 // break; 91 // break;
92 92
93 // case MouseWheelDirection_Down: 93 // case MouseWheelDirection_Down:
94 // application_.OffsetSlice(scale); 94 // application_.OffsetSlice(scale);
95 // break; 95 // break;
96 96
97 // default: 97 // default:
98 // break; 98 // break;
99 // } 99 // }
100 } 100 }
101 101
102 virtual void KeyPressed(WorldSceneWidget& widget, 102 virtual void KeyPressed(WorldSceneWidget& widget,
103 char key, 103 char key,
104 KeyboardModifiers modifiers, 104 KeyboardModifiers modifiers,
105 IStatusBar* statusBar) 105 IStatusBar* statusBar)
106 { 106 {
107 switch (key) 107 switch (key)
108 { 108 {
109 case 's': 109 case 's':
110 widget.SetDefaultView(); 110 widget.SetDefaultView();
111 break; 111 break;
112 112 case 'n':
113 default: 113 application_.NextImage(widget);
114 break; 114 break;
115
116 default:
117 break;
115 } 118 }
116 } 119 }
117 }; 120 };
118 121
119 122
120 // void OffsetSlice(int offset) 123 // void OffsetSlice(int offset)
121 // { 124 // {
122 // if (source_ != NULL) 125 // if (source_ != NULL)
123 // { 126 // {
124 // int slice = static_cast<int>(slice_) + offset; 127 // int slice = static_cast<int>(slice_) + offset;
125 128
126 // if (slice < 0) 129 // if (slice < 0)
127 // { 130 // {
128 // slice = 0; 131 // slice = 0;
129 // } 132 // }
130 133
131 // if (slice >= static_cast<int>(source_->GetSliceCount())) 134 // if (slice >= static_cast<int>(source_->GetSliceCount()))
132 // { 135 // {
133 // slice = source_->GetSliceCount() - 1; 136 // slice = source_->GetSliceCount() - 1;
134 // } 137 // }
135 138
136 // if (slice != static_cast<int>(slice_)) 139 // if (slice != static_cast<int>(slice_))
137 // { 140 // {
138 // SetSlice(slice); 141 // SetSlice(slice);
139 // } 142 // }
140 // } 143 // }
141 // } 144 // }
142 145
143 146
144 // void SetSlice(size_t index) 147 // void SetSlice(size_t index)
145 // { 148 // {
146 // if (source_ != NULL && 149 // if (source_ != NULL &&
147 // index < source_->GetSliceCount()) 150 // index < source_->GetSliceCount())
148 // { 151 // {
149 // slice_ = index; 152 // slice_ = index;
150 153
151 //#if 1 154 //#if 1
152 // widget_->SetSlice(source_->GetSlice(slice_).GetGeometry()); 155 // widget_->SetSlice(source_->GetSlice(slice_).GetGeometry());
153 //#else 156 //#else
154 // // TEST for scene extents - Rotate the axes 157 // // TEST for scene extents - Rotate the axes
155 // double a = 15.0 / 180.0 * M_PI; 158 // double a = 15.0 / 180.0 * M_PI;
156 159
157 //#if 1 160 //#if 1
158 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0); 161 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0);
159 // Vector y; GeometryToolbox::AssignVector(y, -sin(a), cos(a), 0); 162 // Vector y; GeometryToolbox::AssignVector(y, -sin(a), cos(a), 0);
160 //#else 163 //#else
161 // // Flip the normal 164 // // Flip the normal
162 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0); 165 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0);
163 // Vector y; GeometryToolbox::AssignVector(y, sin(a), -cos(a), 0); 166 // Vector y; GeometryToolbox::AssignVector(y, sin(a), -cos(a), 0);
164 //#endif 167 //#endif
165 168
166 // SliceGeometry s(source_->GetSlice(slice_).GetGeometry().GetOrigin(), x, y); 169 // SliceGeometry s(source_->GetSlice(slice_).GetGeometry().GetOrigin(), x, y);
167 // widget_->SetSlice(s); 170 // widget_->SetSlice(s);
168 //#endif 171 //#endif
169 // } 172 // }
170 // } 173 // }
171 174
172 175
173 virtual void NotifyGeometryReady(const ILayerSource& source) 176 virtual void NotifyGeometryReady(const ILayerSource& source)
174 { 177 {
175 // Once the geometry of the series is downloaded from Orthanc, 178 // Once the geometry of the series is downloaded from Orthanc,
176 // display its first slice, and adapt the viewport to fit this 179 // display its first slice, and adapt the viewport to fit this
193 196
194 virtual void NotifySliceChange(const ILayerSource& source, 197 virtual void NotifySliceChange(const ILayerSource& source,
195 const Slice& slice) 198 const Slice& slice)
196 { 199 {
197 } 200 }
198 201
199 virtual void NotifyLayerReady(std::auto_ptr<ILayerRenderer>& layer, 202 virtual void NotifyLayerReady(std::auto_ptr<ILayerRenderer>& layer,
200 const ILayerSource& source, 203 const ILayerSource& source,
201 const CoordinateSystem3D& slice, 204 const CoordinateSystem3D& slice,
202 bool isError) 205 bool isError)
203 { 206 {
232 235
233 virtual void DeclareStartupOptions(boost::program_options::options_description& options) 236 virtual void DeclareStartupOptions(boost::program_options::options_description& options)
234 { 237 {
235 boost::program_options::options_description generic("Sample options"); 238 boost::program_options::options_description generic("Sample options");
236 generic.add_options() 239 generic.add_options()
237 // ("study", boost::program_options::value<std::string>(), 240 // ("study", boost::program_options::value<std::string>(),
238 // "Orthanc ID of the study") 241 // "Orthanc ID of the study")
239 ("instance1", boost::program_options::value<std::string>(), 242 ("instance1", boost::program_options::value<std::string>(),
240 "Orthanc ID of the instances") 243 "Orthanc ID of the instances")
241 ("instance2", boost::program_options::value<std::string>(), 244 ("instance2", boost::program_options::value<std::string>(),
242 "Orthanc ID of the instances") 245 "Orthanc ID of the instances")
243 ; 246 ;
244 247
245 options.add(generic); 248 options.add(generic);
246 } 249 }
247 250
248 virtual void Initialize(BasicApplicationContext* context, 251 virtual void Initialize(BasicApplicationContext* context,
249 IStatusBar& statusBar, 252 IStatusBar& statusBar,
250 const boost::program_options::variables_map& parameters) 253 const boost::program_options::variables_map& parameters)
314 317
315 AttachWidgetToWasmViewport("canvas", thumbnailsLayout_); 318 AttachWidgetToWasmViewport("canvas", thumbnailsLayout_);
316 AttachWidgetToWasmViewport("canvas2", mainViewport_); 319 AttachWidgetToWasmViewport("canvas2", mainViewport_);
317 } 320 }
318 #endif 321 #endif
322
323 void NextImage(WorldSceneWidget& widget) {
324 assert(context_);
325
326 currentInstanceIndex_ = (currentInstanceIndex_ + 1) % instances_.size();
327
328 std::auto_ptr<OrthancFrameLayerSource> layer
329 (new OrthancFrameLayerSource(context_->GetWebService()));
330 layer->LoadFrame(instances_[currentInstanceIndex_], 0);
331
332 mainViewport_->ReplaceLayer(0, layer.release());
333 // source_->LoadFrame("45b7e6bc-168e8ed1-063dc08d-cffd6431-133a276a", 0);
334 }
319 }; 335 };
336
337
320 } 338 }
321 } 339 }