CustusX  22.04-rc2
An IGT application
cxCommandlineImageStreamerFactory.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 
13 
14 #include "cxLogger.h"
15 #include "cxImageStreamerOpenCV.h"
16 #include "cxMHDImageStreamer.h"
17 #include "cxImageStreamerSonix.h"
18 #include "cxConfig.h"
19 
20 namespace cx
21 {
22 
24 {
25  StringMap retval;
26 
27  for (int i = 0; i < cmdline.size(); ++i)
28  {
29  if (!cmdline[i].startsWith("--"))
30  continue;
31  QString name, val;
32  name = cmdline[i].remove(0, 2);
33  if (i + 1 < cmdline.size())
34  val = cmdline[i + 1];
35  retval[name] = val;
36  }
37 
38  return retval;
39 }
40 
41 
45 
47 {
48  QString type = this->getDefaultSenderType();
49  if (args.count("type"))
50  type = args["type"];
51 
52  CommandLineStreamerPtr streamer = this->getImageSender(type);
53 
54  if (streamer)
55  reportSuccess("Created sender of type: "+type);
56  else
57  {
58  reportError("Failed to create sender based on type: "+type);
59  return streamer;
60  }
61 
62  streamer->initialize(args);
63  return streamer;
64 }
65 
66 
68 {
69 #ifdef CX_USE_OpenCV
70  mCommandLineStreamers.push_back(CommandLineStreamerPtr(new ImageStreamerOpenCV()));
71 #endif
72  mCommandLineStreamers.push_back(DummyImageStreamerPtr(new DummyImageStreamer()));
73 }
74 
76 {
77  return this->getSenderTypes().front();
78 }
79 
81 {
82  QStringList retval;
83  for (unsigned i=0; i< mCommandLineStreamers.size(); ++i)
84  retval << mCommandLineStreamers[i]->getType();
85  return retval;
86 }
87 
89 {
90  for (unsigned i=0; i< mCommandLineStreamers.size(); ++i)
91  if (mCommandLineStreamers[i]->getType()==type)
92  return mCommandLineStreamers[i]->getArgumentDescription();
93  return QStringList();
94 }
95 
97 {
98  for (unsigned i=0; i< mCommandLineStreamers.size(); ++i)
99  if (mCommandLineStreamers[i]->getType()==type)
100  return mCommandLineStreamers[i];
101  return CommandLineStreamerPtr();
102 }
103 
104 
105 }
void reportError(QString msg)
Definition: cxLogger.cpp:71
QStringList getSenderTypes() const
all available sender types
CommandLineStreamerPtr getImageSender(QString type)
std::map< QString, QString > StringMap
void reportSuccess(QString msg)
Definition: cxLogger.cpp:72
QStringList getArgumentDescription(QString type) const
arguments for one streamer
bool startsWith(std::string const &s, std::string const &prefix)
Definition: catch.hpp:162
StringMap extractCommandlineOptions(QStringList cmdline)
boost::shared_ptr< class DummyImageStreamer > DummyImageStreamerPtr
boost::shared_ptr< CommandLineStreamer > CommandLineStreamerPtr
Definition: cxStreamer.h:103
boost::shared_ptr< class Streamer > StreamerPtr
Namespace for all CustusX production code.