Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 10 commits
  • 13 files changed
  • 0 commit comments
  • 3 contributors
View
67 Applications/ctkImageViewer/CMakeLists.txt
@@ -0,0 +1,67 @@
+PROJECT(ctkImageViewer)
+
+#
+# 3rd party dependencies
+#
+
+FIND_PACKAGE(VTK)
+IF(NOT VTK_FOUND)
+ MESSAGE(FATAL_ERROR "error: VTK package is required to build ${PROJECT_NAME}")
+ENDIF()
+INCLUDE(${VTK_USE_FILE})
+
+#
+# See CTK/CMake/ctkMacroBuildApp.cmake for details
+#
+
+# Source files
+SET(KIT_SRCS
+ ctkImageViewerMain.cpp
+ ctkImageViewerMainWindow.cpp
+ ctkImageViewerMainWindow.h
+ ctkImageViewerMainWindow_p.h
+
+ ctkVTKImageView.cpp
+ ctkVTKImageView.h
+ ctkVTKImageView_p.h
+ )
+
+# Headers that should run through moc
+SET(KIT_MOC_SRCS
+ ctkImageViewerMainWindow.h
+ ctkImageViewerMainWindow_p.h
+ ctkVTKImageView.h
+ ctkVTKImageView_p.h
+ )
+
+# UI files
+SET(KIT_UI_FORMS
+ ctkImageViewerMainWindow.ui
+)
+
+# Resources
+SET(KIT_resources
+)
+
+# Target libraries - See CMake/ctkMacroGetTargetLibraries.cmake
+# The following macro will read the target libraries from the file 'target_libraries.cmake'
+ctkMacroGetTargetLibraries(KIT_target_libraries)
+
+# Additional directories to include - Not that CTK_INCLUDE_LIBRARIES is already included
+SET(KIT_include_directories
+ )
+
+ctkMacroBuildApp(
+ NAME ${PROJECT_NAME}
+ INCLUDE_DIRECTORIES ${KIT_include_directories}
+ SRCS ${KIT_SRCS}
+ MOC_SRCS ${KIT_MOC_SRCS}
+ UI_FORMS ${KIT_UI_FORMS}
+ TARGET_LIBRARIES ${KIT_target_libraries}
+ RESOURCES ${KIT_resources}
+ )
+
+# Testing
+IF(BUILD_TESTING)
+ ADD_SUBDIRECTORY(Testing)
+ENDIF(BUILD_TESTING)
View
4 Applications/ctkImageViewer/README
@@ -0,0 +1,4 @@
+ABOUT
+-------------
+ctkImageViewer is a simple image viewing program with basic functionalities that make it ideal for quickly viewing
+test images and the like.
View
1 Applications/ctkImageViewer/Testing/CMakeLists.txt
@@ -0,0 +1 @@
+#ADD_SUBDIRECTORY(Cpp)
View
79 Applications/ctkImageViewer/ctkImageViewerMain.cpp
@@ -0,0 +1,79 @@
+/*=========================================================================
+
+ Library: CTK
+
+ Copyright (c) 2010 Kitware Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.commontk.org/LICENSE
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QApplication>
+
+// CTK includes
+#include "ctkLogger.h"
+#include "ctkCommandLineParser.h"
+#include "ctkImageViewerMainWindow.h"
+
+// STD includes
+#include <cstdlib>
+#include <iostream>
+
+//--------------------------------------------------------------------------
+static ctkLogger logger("org.commontk.applications.ctkImageViewer");
+//--------------------------------------------------------------------------
+
+int main(int argc, char** argv)
+{
+ ctkLogger::configure();
+ QApplication app(argc, argv);
+
+ // Arguments
+ bool displayHelp = false;
+ bool debugOutput = false;
+
+ // Command line parser
+ ctkCommandLineParser parser;
+ parser.addBooleanArgument("--help", "-h", &displayHelp);
+ parser.addBooleanArgument("--debut-output", "-d", &debugOutput);
+ if (!parser.parseArguments(app.arguments()))
+ {
+ std::cerr << qPrintable(parser.errorString()) << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // Process arguments
+ if (debugOutput)
+ {
+ logger.setTrace();
+ logger.trace("Debug output - ON");
+ }
+
+ if (displayHelp)
+ {
+ // Display help ...
+ return EXIT_SUCCESS;
+ }
+
+ // Display main widgets
+ ctkImageViewerMainWindow mainWindow;
+ mainWindow.show();
+
+ if(argc > 1)
+ {
+ mainWindow.openFileName(argv[1]);
+ }
+
+ return app.exec();
+}
View
95 Applications/ctkImageViewer/ctkImageViewerMainWindow.cpp
@@ -0,0 +1,95 @@
+
+// Qt includes
+#include <QDebug>
+#include <QFileDialog>
+#include <QDir>
+#include <QLayout>
+
+// CTK includes
+#include "ctkLogger.h"
+#include "ctkImageViewerMainWindow.h"
+#include "ctkImageViewerMainWindow_p.h"
+
+//--------------------------------------------------------------------------
+static ctkLogger logger("org.commontk.applications.ctkImageViewer.ctkImageViewerMainWindow");
+//--------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// ctkImageViewerMainWindowPrivate methods
+
+//-----------------------------------------------------------------------------
+void ctkImageViewerMainWindowPrivate::setupUi(QMainWindow * mainWindow)
+{
+ this->Ui_ctkImageViewerMainWindow::setupUi(mainWindow);
+ this->mainwindow = mainWindow;
+
+ // Connection between widgets should be done here ...
+ this->mainwindow->layout()->addWidget(this->imageviewer);
+
+ this->setupMenuActions();
+}
+
+void ctkImageViewerMainWindowPrivate::openFileName(const char *fileName)
+{
+ this->reader->SetFileName(fileName);
+ this->reader->Update();
+ this->imageviewer->setImageData(this->reader->GetOutput() );
+}
+
+//-----------------------------------------------------------------------------
+// Helper macro allowing to connect the MainWindow action with the corresponding slot
+#define ctkImageViewerMainWindow_connect(ACTION_NAME) \
+ this->connect( \
+ this->action##ACTION_NAME, SIGNAL(triggered()), \
+ SLOT(on##ACTION_NAME##ActionTriggered()));
+
+//-----------------------------------------------------------------------------
+void ctkImageViewerMainWindowPrivate::setupMenuActions()
+{
+ this->connect(
+ this->actionFileQuit, SIGNAL(triggered()),
+ QApplication::instance(), SLOT(quit()));
+
+ ctkImageViewerMainWindow_connect(FileOpen);
+
+}
+
+#undef ctkImageViewerMainWindow_connect
+
+//-----------------------------------------------------------------------------
+void ctkImageViewerMainWindowPrivate::onFileOpenActionTriggered()
+{
+ QString fileName = QFileDialog::getOpenFileName(this->mainwindow, tr("Open File"), QDir::currentPath());
+
+ if (!fileName.isEmpty())
+ {
+ this->openFileName(fileName.toAscii().constData() );
+ }
+
+
+ qDebug() << "onFileOpenActionTriggered";
+}
+
+//-----------------------------------------------------------------------------
+// ctkImageViewerMainWindow methods
+
+//-----------------------------------------------------------------------------
+ctkImageViewerMainWindow::ctkImageViewerMainWindow(QWidget *newParent):Superclass(newParent)
+{
+ CTK_INIT_PRIVATE(ctkImageViewerMainWindow);
+ CTK_D(ctkImageViewerMainWindow);
+
+ d->setupUi(this);
+}
+
+
+//-----------------------------------------------------------------------------
+void ctkImageViewerMainWindow::openFileName(const char *fileName)
+{
+ CTK_INIT_PRIVATE(ctkImageViewerMainWindow);
+ CTK_D(ctkImageViewerMainWindow);
+
+ d->openFileName(fileName);
+}
+
+
View
26 Applications/ctkImageViewer/ctkImageViewerMainWindow.h
@@ -0,0 +1,26 @@
+#ifndef __ctkImageViewerMainWindow_h
+#define __ctkImageViewerMainWindow_h
+
+// Qt includes
+#include <QMainWindow>
+
+// CTK includes
+#include "ctkPimpl.h"
+
+class ctkImageViewerMainWindowPrivate;
+
+class ctkImageViewerMainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ typedef QMainWindow Superclass;
+ ctkImageViewerMainWindow(QWidget *newParent = 0);
+ void openFileName(const char *fileName);
+
+private:
+ CTK_DECLARE_PRIVATE(ctkImageViewerMainWindow);
+};
+
+
+#endif
View
49 Applications/ctkImageViewer/ctkImageViewerMainWindow.ui
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkImageViewerMainWindow</class>
+ <widget class="QMainWindow" name="ctkImageViewerMainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>847</width>
+ <height>642</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget"/>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>847</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menu_File">
+ <property name="title">
+ <string>&amp;File</string>
+ </property>
+ <addaction name="actionFileOpen"/>
+ <addaction name="actionFileQuit"/>
+ </widget>
+ <addaction name="menu_File"/>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ <action name="actionFileQuit">
+ <property name="text">
+ <string>&amp;Quit</string>
+ </property>
+ </action>
+ <action name="actionFileOpen">
+ <property name="text">
+ <string>&amp;Open</string>
+ </property>
+ </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
View
52 Applications/ctkImageViewer/ctkImageViewerMainWindow_p.h
@@ -0,0 +1,52 @@
+#ifndef __ctkImageViewerMainWindowPrivate_p_h
+#define __ctkImageViewerMainWindowPrivate_p_h
+
+// CTK includes
+#include "ctkPimpl.h"
+#include "ctkImageViewerMainWindow.h"
+#include "ui_ctkImageViewerMainWindow.h"
+#include "vtkPNGReader.h"
+#include "vtkSmartPointer.h"
+#include "ctkVTKImageView.h"
+
+//-----------------------------------------------------------------------------
+class ctkImageViewerMainWindowPrivate: public QObject,
+ public ctkPrivate<ctkImageViewerMainWindow>,
+ public Ui_ctkImageViewerMainWindow
+{
+ Q_OBJECT
+public:
+ CTK_DECLARE_PUBLIC(ctkImageViewerMainWindow);
+ ctkImageViewerMainWindowPrivate()
+ {
+ this->reader = vtkSmartPointer<vtkPNGReader>::New();
+ this->imageviewer = new ctkVTKImageView;
+ }
+
+ ~ctkImageViewerMainWindowPrivate()
+ {
+ delete this->imageviewer;
+ }
+
+ void setupUi(QMainWindow * mainWindow);
+ void openFileName(const char *fileName);
+ ///
+ /// Connect MainWindow menu actions with corresponding slots
+ void setupMenuActions();
+
+public slots:
+ /// Handle actions
+ /// \sa setupMenuActions
+ void onFileOpenActionTriggered();
+
+public:
+
+private:
+ vtkSmartPointer <vtkPNGReader> reader;
+ QMainWindow *mainwindow;
+ ctkVTKImageView *imageviewer;
+
+};
+
+#endif
+
View
148 Applications/ctkImageViewer/ctkVTKImageView.cpp
@@ -0,0 +1,148 @@
+/*=========================================================================
+
+ Library: CTK
+
+ Copyright (c) 2010 Kitware Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.commontk.org/LICENSE
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QTimer>
+#include <QDebug>
+#include <QVBoxLayout>
+
+// CTK includes
+#include "ctkVTKImageView.h"
+#include "ctkVTKImageView_p.h"
+#include "ctkLogger.h"
+
+// VTK includes
+#include <vtkImageData.h>
+
+// Convenient macro
+#define VTK_CREATE(type, name) \
+ vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
+
+//--------------------------------------------------------------------------
+static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKImageView");
+//--------------------------------------------------------------------------
+
+
+// --------------------------------------------------------------------------
+// ctkVTKImageViewPrivate methods
+
+// --------------------------------------------------------------------------
+ctkVTKImageViewPrivate::ctkVTKImageViewPrivate()
+{
+ this->RenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
+ this->Renderer = vtkSmartPointer<vtkRenderer>::New();
+ this->ImageViewer = vtkSmartPointer<vtkImageViewer2>::New();
+
+ this->InteractorStyle = vtkSmartPointer <vtkInteractorStyleImage>::New();
+ this->Interactor = vtkSmartPointer <vtkRenderWindowInteractor>::New();
+}
+
+//---------------------------------------------------------------------------
+void ctkVTKImageViewPrivate::setupRendering()
+{
+ CTK_P(ctkVTKImageView);
+
+ Q_ASSERT(this->RenderWindow);
+ this->RenderWindow->SetAlphaBitPlanes(1);
+ this->RenderWindow->SetMultiSamples(0);
+ this->RenderWindow->StereoCapableWindowOn();
+ this->RenderWindow->AddRenderer(this->Renderer);
+ //this->RenderWindow->SetInteractor(this->Interactor);
+ this->Interactor = this->RenderWindow->GetInteractor();
+
+ this->ImageViewer->SetRenderWindow(this->RenderWindow);
+ this->ImageViewer->SetRenderer(this->Renderer);
+ this->ImageViewer->SetupInteractor(this->Interactor);
+ //this->Interactor->SetInteractorStyle(this->InteractorStyle);
+
+ this->VTKWidget->SetRenderWindow(this->RenderWindow);
+}
+
+//----------------------------------------------------------------------------
+CTK_SET_CXX(ctkVTKImageView, bool, setRenderEnabled, RenderEnabled);
+CTK_GET_CXX(ctkVTKImageView, bool, renderEnabled, RenderEnabled);
+
+//---------------------------------------------------------------------------
+// ctkVTKImageView methods
+
+// --------------------------------------------------------------------------
+ctkVTKImageView::ctkVTKImageView(QWidget* _parent) : Superclass(_parent)
+{
+ CTK_INIT_PRIVATE(ctkVTKImageView);
+ CTK_D(ctkVTKImageView);
+
+ d->VTKWidget = new QVTKWidget(this);
+ this->setLayout(new QVBoxLayout);
+ this->layout()->setMargin(0);
+ this->layout()->setSpacing(0);
+ this->layout()->addWidget(d->VTKWidget);
+
+ d->setupRendering();
+
+}
+
+// --------------------------------------------------------------------------
+ctkVTKImageView::~ctkVTKImageView()
+{
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKImageView::scheduleRender()
+{
+ CTK_D(ctkVTKImageView);
+
+ logger.trace("scheduleRender");
+ if (!d->RenderEnabled)
+ {
+ return;
+ }
+ if (!d->RenderPending)
+ {
+ d->RenderPending = true;
+ QTimer::singleShot(0, this, SLOT(forceRender()));
+ }
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKImageView::forceRender()
+{
+ CTK_D(ctkVTKImageView);
+ if (!d->RenderEnabled)
+ {
+ return;
+ }
+ logger.trace("forceRender");
+ d->RenderWindow->Render();
+ d->RenderPending = false;
+}
+
+
+//----------------------------------------------------------------------------
+void ctkVTKImageView::setImageData(vtkImageData* newImageData)
+{
+ CTK_D(ctkVTKImageView);
+
+ if (newImageData)
+ {
+ d->ImageViewer->SetInput(newImageData);
+ }
+
+ d->ImageData = newImageData;
+}
View
72 Applications/ctkImageViewer/ctkVTKImageView.h
@@ -0,0 +1,72 @@
+/*=========================================================================
+
+ Library: CTK
+
+ Copyright (c) 2010 Kitware Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.commontk.org/LICENSE
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkVTKImageView_h
+#define __ctkVTKImageView_h
+
+// Qt includes
+#include <QWidget>
+
+// CTK includes
+#include <ctkPimpl.h>
+
+#include "CTKVisualizationVTKWidgetsExport.h"
+
+class ctkVTKImageViewPrivate;
+class vtkRenderWindow;
+class vtkImageData;
+
+class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKImageView : public QWidget
+{
+ Q_OBJECT
+ Q_PROPERTY(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
+
+public:
+ /// Constructors
+ typedef QWidget Superclass;
+ explicit ctkVTKImageView(QWidget* parent = 0);
+ virtual ~ctkVTKImageView();
+
+ /// If a render has already been scheduled, this called is a no-op
+ void scheduleRender();
+
+public slots:
+
+ /// Force a render even if a render is already ocurring
+ void forceRender();
+
+
+public:
+
+ /// Set image data
+ void setImageData(vtkImageData* newImageData);
+
+ /// Return if rendering is enabled
+ bool renderEnabled() const;
+
+ /// Enable/Disable rendering
+ void setRenderEnabled(bool value);
+
+
+private:
+ CTK_DECLARE_PRIVATE(ctkVTKImageView);
+};
+
+#endif
View
74 Applications/ctkImageViewer/ctkVTKImageView_p.h
@@ -0,0 +1,74 @@
+/*=========================================================================
+
+ Library: CTK
+
+ Copyright (c) 2010 Kitware Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.commontk.org/LICENSE
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkVTKImageView_p_h
+#define __ctkVTKImageView_p_h
+
+// Qt includes
+#include <QObject>
+#include <QColor>
+#include <QList>
+#include <QSharedPointer>
+
+// CTK includes
+#include <ctkPimpl.h>
+#include <ctkVTKObject.h>
+#include "ctkVTKImageView.h"
+
+// VTK includes
+#include <QVTKWidget.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkSmartPointer.h>
+#include <vtkWeakPointer.h>
+#include <vtkImageViewer2.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkInteractorStyleImage.h>
+
+class vtkRenderWindowInteractor;
+
+
+//-----------------------------------------------------------------------------
+class ctkVTKImageViewPrivate : public QObject,
+ public ctkPrivate<ctkVTKImageView>
+{
+ Q_OBJECT
+ CTK_DECLARE_PUBLIC(ctkVTKImageView);
+public:
+ ctkVTKImageViewPrivate();
+
+ /// Convenient setup methods
+ void setupRendering();
+
+ QVTKWidget* VTKWidget;
+ vtkSmartPointer<vtkRenderWindow> RenderWindow;
+ vtkSmartPointer<vtkRenderer> Renderer;
+ vtkSmartPointer<vtkImageViewer2> ImageViewer;
+
+ vtkSmartPointer<vtkRenderWindowInteractor> Interactor;
+ vtkSmartPointer<vtkInteractorStyleImage> InteractorStyle;
+
+ bool RenderPending;
+ bool RenderEnabled;
+
+ vtkWeakPointer<vtkImageData> ImageData;
+};
+
+#endif
View
9 Applications/ctkImageViewer/target_libraries.cmake
@@ -0,0 +1,9 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+#
+# This file should list the libraries required to build the current CTK application.
+#
+
+SET(target_libraries
+ CTKVisualizationVTKWidgets
+ )
View
1 CMakeLists.txt
@@ -290,6 +290,7 @@ SET(CTK_APPLICATIONS
ctkDICOMIndexer:OFF
ctkDICOMDemoSCU:OFF
ctkDICOMQuery:OFF
+ ctkImageViewer:OFF
ctkPluginBrowser:OFF
)

No commit comments for this range

Something went wrong with that request. Please try again.