Hi there,
has anyone tried making their application load images or other data from the
command line on startup?
Something like:
./bin/ExtApp image1.nii image2.nii image3.img etc.
I have tried to do this in QmitkExtWorkbenchWindowAdvisor.cpp, and it appears
to work.
(see attached patch).
Is this the right way to do it? It can probably be improved, as it does
duplicate code from the FileOpenAction a bit.
If we want it including more generally, I can raise a bug, fork MITK, and get
it checked in.
Thanks
Matt
diff --git
Modules/Bundles/org.mitk.gui.qt.ext/src/QmitkExtWorkbenchWindowAdvisor.cpp
Modules/Bundles/org.mitk.gui.qt.ext/src/QmitkExtWorkbenchWindowAdvisor.cpp
index c8fd8eb..1e86dd7 100644
--- Modules/Bundles/org.mitk.gui.qt.ext/src/QmitkExtWorkbenchWindowAdvisor.cpp
+++ Modules/Bundles/org.mitk.gui.qt.ext/src/QmitkExtWorkbenchWindowAdvisor.cpp
@@ -27,6 +27,7 @@ PURPOSE. See the above copyright notices for more
information.
#include <QRegExp>
#include <QTextStream>
#include <QSettings>
+#include <QApplication>
#include <berryPlatform.h>
#include <berryPlatformUI.h>
@@ -54,6 +55,16 @@ PURPOSE. See the above copyright notices for more
information.
#include <vtkConfigure.h>
#include <mitkVersion.h>
+#include "mitkDataNode.h"
+#include "mitkDataNodeFactory.h"
+#include "mitkDataStorage.h"
+#include "mitkIDataStorageService.h"
+#include "mitkNodePredicateData.h"
+#include "mitkNodePredicateNot.h"
+#include "mitkNodePredicateProperty.h"
+#include "mitkProperties.h"
+#include "mitkRenderingManager.h"
+
// UGLYYY
#include "internal/QmitkExtWorkbenchWindowAdvisorHack.h"
#include "internal/QmitkCommonExtPlugin.h"
@@ -631,6 +642,61 @@ void QmitkExtWorkbenchWindowAdvisor::PostWindowCreate()
QmitkMemoryUsageIndicatorView* memoryIndicator =
new QmitkMemoryUsageIndicatorView();
qStatusBar->addPermanentWidget(memoryIndicator, 0);
+
+ // If any command line args look like data sets we can load, then load them.
+ QApplication *application = dynamic_cast<QApplication*>(qApp);
+ if (application != NULL)
+ {
+ QStringList arguments = application->arguments();
+ unsigned int argumentsAdded = 0;
+
+ if (arguments.size() > 1)
+ {
+
+ mitk::IDataStorageService::Pointer service =
+
berry::Platform::GetServiceRegistry().GetServiceById<mitk::IDataStorageService>(mitk::IDataStorageService::ID);
+
+ mitk::DataStorage::Pointer dataStorage =
service->GetDefaultDataStorage()->GetDataStorage();
+
+ for (int i = 1; i < arguments.size(); i++)
+ {
+ QString argument = arguments[i];
+ mitk::DataNodeFactory::Pointer nodeReader =
mitk::DataNodeFactory::New();
+ try
+ {
+ nodeReader->SetFileName(argument.toLocal8Bit().constData());
+ nodeReader->Update();
+ for ( unsigned int i = 0 ; i < nodeReader->GetNumberOfOutputs( ); ++i
)
+ {
+ mitk::DataNode::Pointer node;
+ node = nodeReader->GetOutput(i);
+ if ( node->GetData() != NULL )
+ {
+ dataStorage->Add(node);
+ argumentsAdded++;
+ MITK_INFO << "QmitkExtWorkbenchWindowAdvisor::PostWindowCreate,
loaded:" << argument.toLocal8Bit().constData() << std::endl;
+ }
+ }
+ }
+ catch(...)
+ {
+ MITK_DEBUG << "QmitkExtWorkbenchWindowAdvisor::PostWindowCreate
failed to load argument:" << argument.toLocal8Bit().constData() << std::endl;
+ }
+ } // end for each command line argument
+
+ if (argumentsAdded > 0)
+ {
+ // Get bounds of every dataset that doesn't have "includeInBoundingBox"
set to false.
+ mitk::NodePredicateNot::Pointer pred
+ =
mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox"
+ , mitk::BoolProperty::New(false)));
+
+ mitk::DataStorage::SetOfObjects::ConstPointer rs =
dataStorage->GetSubset(pred);
+ mitk::TimeSlicedGeometry::Pointer bounds =
dataStorage->ComputeBoundingGeometry3D(rs);
+ mitk::RenderingManager::GetInstance()->InitializeViews(bounds);
+ }
+ }
+ }
}
void QmitkExtWorkbenchWindowAdvisor::PreWindowOpen()
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users