[opengtl-commits] [246] initial commit of QtShiva |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 246
Author: cyrille
Date: 2008-06-26 23:01:17 +0200 (Thu, 26 Jun 2008)
Log Message:
-----------
initial commit of QtShiva
Added Paths:
-----------
trunk/QtShiva/CMakeLists.txt
trunk/QtShiva/MainWindow.ui
trunk/QtShiva/QtShiva.cpp
trunk/QtShiva/QtShiva.h
trunk/QtShiva/cmake/
trunk/QtShiva/cmake/modules/
trunk/QtShiva/cmake/modules/FindOpenShiva.cmake
trunk/QtShiva/main.cpp
Property Changed:
----------------
trunk/QtShiva/
Property changes on: trunk/QtShiva
___________________________________________________________________
Name: svn:ignore
+ Doxyfile
QtShiva.kdevelop
QtShiva.kdevelop.filelist
QtShiva.kdevelop.pcs
QtShiva.kdevses
Added: trunk/QtShiva/CMakeLists.txt
===================================================================
--- trunk/QtShiva/CMakeLists.txt (rev 0)
+++ trunk/QtShiva/CMakeLists.txt 2008-06-26 21:01:17 UTC (rev 246)
@@ -0,0 +1,26 @@
+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules )
+
+find_package(OpenShiva REQUIRED)
+find_package(Qt4 REQUIRED)
+
+set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
+
+message(STATUS ${OPENSHIVA_INCLUDE_DIR})
+
+include_directories(${QT_QTGUI_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${OPENSHIVA_INCLUDE_DIR})
+
+
+message(STATUS ${OPENSHIVA_INCLUDE_DIR})
+
+## QtShiva
+
+set(Qt_SHIVA_SRCS QtShiva.cpp main.cpp )
+
+
+qt4_wrap_ui(Qt_SHIVA_SRCS MainWindow.ui)
+
+qt4_automoc(${Qt_SHIVA_SRCS})
+
+add_executable(QtShiva ${Qt_SHIVA_SRCS})
+target_link_libraries(QtShiva ${QT_LIBRARY_DIR} ${QT_QTGUI_LIBRARY} ${OPENSHIVA_LIBRARIES})
+install(TARGETS QtShiva DESTINATION ${BIN_INSTALL_DIR} )
Added: trunk/QtShiva/MainWindow.ui
===================================================================
--- trunk/QtShiva/MainWindow.ui (rev 0)
+++ trunk/QtShiva/MainWindow.ui 2008-06-26 21:01:17 UTC (rev 246)
@@ -0,0 +1,146 @@
+<ui version="4.0" >
+ <class>MainWindow</class>
+ <widget class="QWidget" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>872</width>
+ <height>587</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="0" >
+ <widget class="QSplitter" name="splitter_2" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QLabel" name="imageViewer" >
+ <property name="text" >
+ <string>No Image</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QWidget" name="" >
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <widget class="QListWidget" name="listImages" />
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <item>
+ <widget class="QPushButton" name="buttonAdd" >
+ <property name="text" >
+ <string>Add</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="buttonRemove" >
+ <property name="text" >
+ <string>Remove</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="" >
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <widget class="QTextEdit" name="ctlCodeEditor" >
+ <property name="html" >
+ <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+<html><head><meta name="qrichtext" content="1" /><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;">
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt;">kernel PlainGenerator</span></p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;">{</p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;"> void evaluatePixel(out pixel result)</p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;"> {</p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;"> result[0] = 0.5;</p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;"> }</p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;">}</p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;"></p></body></html></string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QPushButton" name="buttonApply" >
+ <property name="text" >
+ <string>Apply</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="buttonRefresh" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
+ <property name="text" >
+ <string>Refresh</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ <zorder>imageViewer</zorder>
+ <zorder>ctlCodeEditor</zorder>
+ <zorder>buttonApply</zorder>
+ <zorder>pushButtonReload</zorder>
+ <zorder>buttonRefresh</zorder>
+ <zorder>pushButtonOpen</zorder>
+ <zorder>horizontalSpacer</zorder>
+ <zorder>buttonAdd</zorder>
+ <zorder>buttonRemove</zorder>
+ <zorder>horizontalSpacer_2</zorder>
+ <zorder>listImages</zorder>
+ <zorder>listImages</zorder>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
Added: trunk/QtShiva/QtShiva.cpp
===================================================================
--- trunk/QtShiva/QtShiva.cpp (rev 0)
+++ trunk/QtShiva/QtShiva.cpp 2008-06-26 21:01:17 UTC (rev 246)
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <QtGui>
+#include "QtShiva.h"
+
+#include <QTextEdit>
+#include <QTextStream>
+#include <QCloseEvent>
+#include <QFileDialog>
+
+#include "ui_MainWindow.h"
+
+#include <OpenShiva/Kernel.h>
+#include <OpenShiva/Image.h>
+#include <GTLCore/PixelDescription.h>
+#include <GTLCore/Region.h>
+#include <GTLCore/RegionF.h>
+#include <GTLCore/Type.h>
+
+QtShiva::QtShiva()
+{
+ m_mainWindow = new Ui_MainWindow;
+ QWidget* widget = new QWidget;
+ m_mainWindow->setupUi(widget);
+ setCentralWidget(widget);
+ connect(m_mainWindow->buttonAdd, SIGNAL(released()), SLOT(add()));
+ connect(m_mainWindow->buttonRemove, SIGNAL(released()), SLOT(remove()));
+ connect(m_mainWindow->buttonApply, SIGNAL(released()), SLOT(apply()));
+ connect(m_mainWindow->buttonRefresh, SIGNAL(released()), SLOT(refreshImageViewer()));
+}
+
+QtShiva::~QtShiva()
+{
+ delete m_mainWindow;
+}
+
+void QtShiva::refreshImageViewer()
+{
+ QPixmap pm = QPixmap::fromImage(currentImage);
+ m_mainWindow->imageViewer->setPixmap(pm.scaled( m_mainWindow->imageViewer->size(), Qt::KeepAspectRatio));
+}
+
+void QtShiva::add()
+{
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (fileName.isEmpty()) return;
+ QListWidgetItem* lwi = new QListWidgetItem( QFileInfo(fileName).fileName() );
+ lwi->setData(Qt::UserRole, fileName );
+ m_mainWindow->listImages->addItem( lwi );
+}
+
+void QtShiva::remove()
+{
+ delete m_mainWindow->listImages->currentItem();
+}
+
+int clamp255( int v)
+{
+ if( v > 255 ) return 255;
+ if( v < 0 ) return 0;
+ return v;
+}
+
+void QtShiva::apply()
+{
+ GTLCore::PixelDescription pixel( GTLCore::Type::Float, 3 );
+ OpenShiva::Kernel p("", pixel);
+ p.setSource( m_mainWindow->ctlCodeEditor->toPlainText().toAscii ().data());
+ p.compile();
+ if(p.isCompiled())
+ {
+ OpenShiva::Image image(1000, 1000, pixel );
+ std::list<OpenShiva::AbstractImage*> inputImages;
+ for( int k = 0; k < m_mainWindow->listImages->count(); ++k)
+ {
+ QString fileName = m_mainWindow->listImages->item( k )->data( Qt::UserRole ).toString();
+ QImage img;
+ if (not img.load(fileName)) {
+ QMessageBox::warning(this, tr("QtShiva"),
+ tr("Cannot read image %1..")
+ .arg(fileName));
+ return;
+ }
+ OpenShiva::Image* iImage = new OpenShiva::Image(img.width(), img.height(), pixel );
+ for( int j = 0; j < img.height(); ++j )
+ {
+ for(int i = 0; i < img.width(); ++i )
+ {
+ QRgb rgb = img.pixel(i, j);
+ float* ptr = (float*)iImage->data(i,j);
+ ptr[0] = qRed(rgb);
+ ptr[1] = qGreen(rgb);
+ ptr[2] = qBlue(rgb);
+ ptr[3] = qAlpha(rgb);
+ }
+ }
+ inputImages.push_back( iImage );
+ }
+ p.evaluatePixeles( GTLCore::Region(0,0, 1000,1000), inputImages, &image );
+ currentImage = QImage( image.width(), image.height(), QImage::Format_RGB32);
+ for( int j = 0; j < image.height(); ++j )
+ {
+ for(int i = 0; i < image.width(); ++i )
+ {
+ int r = clamp255( *(((float*)image.data(i,j)) + 0) * 255 );
+ int g = clamp255( *(((float*)image.data(i,j)) + 1) * 255 );
+ int b = clamp255( *(((float*)image.data(i,j)) + 2) * 255 );
+ currentImage.setPixel( i,j, qRgb(r,g,b) );
+ }
+ }
+ for( std::list<OpenShiva::AbstractImage*>::iterator it = inputImages.begin();
+ it != inputImages.end(); ++it)
+ {
+ delete *it;
+ }
+ refreshImageViewer();
+ } else {
+ QMessageBox::critical(this, tr("QtShiva"), tr("Compilation error: %1").arg( p.compilationErrorsMessage().c_str() ));
+ }
+}
+
+#include "QtShiva.moc"
Property changes on: trunk/QtShiva/QtShiva.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/QtShiva/QtShiva.h
===================================================================
--- trunk/QtShiva/QtShiva.h (rev 0)
+++ trunk/QtShiva/QtShiva.h 2008-06-26 21:01:17 UTC (rev 246)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef QTSHIVA_H
+#define QTSHIVA_H
+
+#include <QMainWindow>
+#include <QCloseEvent>
+#include <QImage>
+
+class Ui_MainWindow;
+
+class QtShiva:public QMainWindow
+{
+ Q_OBJECT
+ public:
+ QtShiva();
+ ~QtShiva();
+
+ private slots:
+ void add();
+ void remove();
+ void apply();
+ void refreshImageViewer();
+ private:
+// void loadFile(const QString &fileName);
+ private:
+ Ui_MainWindow* m_mainWindow;
+ QImage currentImage;
+};
+
+#endif
Property changes on: trunk/QtShiva/QtShiva.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/QtShiva/cmake/modules/FindOpenShiva.cmake
===================================================================
--- trunk/QtShiva/cmake/modules/FindOpenShiva.cmake (rev 0)
+++ trunk/QtShiva/cmake/modules/FindOpenShiva.cmake 2008-06-26 21:01:17 UTC (rev 246)
@@ -0,0 +1,35 @@
+
+INCLUDE(UsePkgConfig)
+PKGCONFIG(OpenShiva _OpenShivaIncDir _OpenShivaLinkDir _OpenShivaLinkFlags _OpenShivaCflags)
+
+set(OPENSHIVA_DEFINITIONS ${_OpenShivaCflags})
+set(OPENSHIVA_LIBRARIES ${_OpenShivaLinkFlags})
+set(OPENSHIVA_INCLUDE_DIR ${_OpenShivaIncDir})
+
+if(OPENSHIVA_DEFINITIONS AND OPENSHIVA_LIBRARIES)
+
+ FIND_PROGRAM(PKGCONFIG_EXECUTABLE NAMES pkg-config PATHS /usr/bin/ /usr/local/bin )
+
+ # query pkg-config asking for OpenShiva >= 0.9.2
+ EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS --atleast-version=0.9.3 OpenShiva RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
+
+ if(_return_VALUE STREQUAL "0")
+ set(OPENSHIVA_FOUND TRUE)
+ set(HAVE_OPENSHIVA TRUE)
+ else(_return_VALUE STREQUAL "0")
+ message(STATUS "OpenShiva >= 0.9.3 was found")
+ endif(_return_VALUE STREQUAL "0")
+endif(OPENSHIVA_DEFINITIONS AND OPENSHIVA_LIBRARIES)
+
+if (OPENSHIVA_FOUND)
+ if (NOT OPENSHIVA_FIND_QUIETLY)
+ message(STATUS "Found OpenShiva: ${OPENSHIVA_LIBRARIES}")
+ endif (NOT OPENSHIVA_FIND_QUIETLY)
+else (OPENShiva_FOUND)
+ if (NOT OPENSHIVA_FIND_QUIETLY)
+ message(STATUS "OpenShiva was NOT found.")
+ endif (NOT OPENSHIVA_FIND_QUIETLY)
+ if (OPENSHIVA_FIND_REQUIRED)
+ message(FATAL_ERROR "Could NOT find OPENShiva")
+ endif (OPENSHIVA_FIND_REQUIRED)
+endif (OPENSHIVA_FOUND)
Added: trunk/QtShiva/main.cpp
===================================================================
--- trunk/QtShiva/main.cpp (rev 0)
+++ trunk/QtShiva/main.cpp 2008-06-26 21:01:17 UTC (rev 246)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <QApplication>
+#include "QtShiva.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QtShiva * mw = new QtShiva();
+ mw->show();
+ return app.exec();
+}
+
Property changes on: trunk/QtShiva/main.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native