CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 
34 
35 #include "cxLogger.h"
36 #include "cxImageStreamerOpenCV.h"
37 #include "cxMHDImageStreamer.h"
38 #include "cxImageStreamerSonix.h"
39 #include "cxConfig.h"
40 
41 namespace cx
42 {
43 
45 {
46  StringMap retval;
47 
48  for (int i = 0; i < cmdline.size(); ++i)
49  {
50  if (!cmdline[i].startsWith("--"))
51  continue;
52  QString name, val;
53  name = cmdline[i].remove(0, 2);
54  if (i + 1 < cmdline.size())
55  val = cmdline[i + 1];
56  retval[name] = val;
57  }
58 
59  return retval;
60 }
61 
62 
66 
68 {
69  QString type = this->getDefaultSenderType();
70  if (args.count("type"))
71  type = args["type"];
72 
73  StreamerPtr streamer = this->getImageSender(type);
74 
75  if (streamer)
76  reportSuccess("Created sender of type: "+type);
77  else
78  {
79  reportError("Failed to create sender based on type: "+type);
80  return streamer;
81  }
82 
83  CommandLineStreamerPtr commandlinestreamer = boost::dynamic_pointer_cast<CommandLineStreamer>(streamer);
84  if(commandlinestreamer)
85  commandlinestreamer->initialize(args);
86 
87  DummyImageStreamerPtr mhdimagestreamer = boost::dynamic_pointer_cast<DummyImageStreamer>(streamer);
88  QString filename = args["filename"];
89  bool secondary = args.count("secondary") ? true : false;
90  if(mhdimagestreamer)
91  mhdimagestreamer->initialize(filename, secondary);
92 
93  return streamer;
94 }
95 
96 
98 {
99 #ifdef CX_WIN32
100  mCommandLineStreamers.push_back(CommandLineStreamerPtr(new ImageStreamerSonix()));
101 #endif
102 #ifdef CX_USE_OpenCV
103  mCommandLineStreamers.push_back(CommandLineStreamerPtr(new ImageStreamerOpenCV()));
104 #endif
105  mImageStreamers.push_back(DummyImageStreamerPtr(new DummyImageStreamer()));
106 }
107 
109 {
110  return this->getSenderTypes().front();
111 }
112 
114 {
115  QStringList retval;
116  for (unsigned i=0; i< mCommandLineStreamers.size(); ++i)
117  retval << mCommandLineStreamers[i]->getType();
118  for (unsigned i=0; i< mImageStreamers.size(); ++i)
119  retval << mImageStreamers[i]->getType();
120  return retval;
121 }
122 
124 {
125  QStringList retval;
126  for (unsigned i=0; i< mCommandLineStreamers.size(); ++i)
127  {
128  if (mCommandLineStreamers[i]->getType()==type)
129  return mCommandLineStreamers[i]->getArgumentDescription();
130  }
131  return retval;
132 }
133 
135 {
136  for (unsigned i=0; i< mCommandLineStreamers.size(); ++i)
137  {
138  if (mCommandLineStreamers[i]->getType()==type)
139  return mCommandLineStreamers[i];
140  }
141  for (unsigned i=0; i< mImageStreamers.size(); ++i)
142  {
143  if (mImageStreamers[i]->getType()==type)
144  return mImageStreamers[i];
145  }
146  return StreamerPtr();
147 }
148 
149 
150 }
void reportError(QString msg)
Definition: cxLogger.cpp:92
QStringList getSenderTypes() const
all available sender types
virtual void initialize(QString filename, bool secondaryStream, bool sendonce=false)
std::map< QString, QString > StringMap
void reportSuccess(QString msg)
Definition: cxLogger.cpp:93
QStringList getArgumentDescription(QString type) const
arguments for one streamer
StringMap extractCommandlineOptions(QStringList cmdline)
boost::shared_ptr< class DummyImageStreamer > DummyImageStreamerPtr
boost::shared_ptr< CommandLineStreamer > CommandLineStreamerPtr
Definition: cxStreamer.h:121
virtual void initialize(StringMap arguments)
Definition: cxStreamer.cpp:80
boost::shared_ptr< class Streamer > StreamerPtr