Blog « VCreate Logic Blog
 
Home
 
 

Using vtkRenderWindow with QGraphicsView

Post: Blog — Posted by: abhishek @ 3:28 pm

We are about to begin on a project that requires us to have floating and transparent widgets over VTK render-window output. About a year back, we had wanted to provide something similar to VTK Designer 2. We wanted users to have the ability to load UI (created using Qt Designer) directly on the VTK output window. At that time (you can follow the thread here) we were unable to come up with something satisfactory.

With the recent changes in Qt, it is now possible for us to have vtkRenderWindow within QGraphicsView. Infact we can now have vtkRenderWindow paint on to a QGLWidget viewport of QGraphicsView. Thats exactly what the vtkQtGraphicsViewRenderWindow class allows us to do.

The class is defined as follows

#ifdef Q_WS_WIN
    #include "vtkWin32OpenGLRenderWindow.h"
    typedef vtkWin32OpenGLRenderWindow vtkRenderWindowClass;
#endif

#ifdef Q_WS_X11
    #include "vtkXOpenGLRenderWindow.h"
    typedef vtkXOpenGLRenderWindow vtkRenderWindowClass;
#endif

class vtkQtGraphicsViewRenderWindow : public QGraphicsView,
                                      public vtkRenderWindowClass
{
    Q_OBJECT

public:
    vtkQtGraphicsViewRenderWindow(QWidget* parent = 0);
    ~vtkQtGraphicsViewRenderWindow();
    ....
};

Since vtkQtGraphicsViewRenderWindow is a subclass of both QGraphicsView and vtkRenderWindow,
- we can add any QGraphicsItem to its scene.
- we can use it as a drop-in replacement for vtkRenderWindow.

For example, take a look at the code below.

vtkRenderer* CreateVTKPipeline()
{
    vtkRenderer* renderer = vtkRenderer::New();

    // Omitted code that create a fractal terrain scene.

    return renderer;
}

int main(int argc, char** argv)
{
    QApplication a(argc, argv);

    vtkRenderer* renderer = CreateVTKPipeline();

    vtkQtGraphicsViewRenderWindow gView;
    gView.AddRenderer( renderer );
    gView.resize(800, 600);
    gView.show();

    QCalendarWidget* calendar = new QCalendarWidget;
    calendar->setWindowOpacity(0.7);

    QGraphicsProxyWidget* sceneWidget = new QGraphicsProxyWidget(0, Qt::Dialog);
    sceneWidget->setWidget(calendar);
    sceneWidget->setPos( -sceneWidget->boundingRect().topLeft() );
    sceneWidget->setFlag(QGraphicsItem::ItemIsMovable);
    sceneWidget->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    sceneWidget->setWindowTitle("Calendar Widget");

    QGraphicsScene* scene = gView.scene();
    scene->addItem(sceneWidget);

    return a.exec();
}

Output of the above program becomes:

vtkQtGraphicsViewRenderWindow

vtkQtGraphicsViewRenderWindow

Whats cooler about the above program is that we can move and resize the translucent QCalendarWidget - and have the background VTK scene updated!

You can checkout a copy of the class and test program from here:
https://svn2.hosted-projects.com/vcreatelogic/VCLTools/vtkQtGraphicsViewRenderWindow
Username: anonymous
Password: anonymous

 

Moving to CMake

Post: Blog — Posted by: prashanthudupa @ 4:29 pm

Over the past few weeks we have been playing around with CMake and we figured that it would be a good idea to have GCF build-able using CMake. There are a few open-source projects that make use of GCF with CMake anyway; we figured it would be a good idea to have a CMake build-system GCF supported officially.

We have begun the process of making GCF build-able with CMake. Currently we are able to build the GCF library and all its built-in components. We are slowly moving examples and tools also into it. The idea is to have GCF compilable using both QMake and CMake for as long as possible. In the coming months we should also have the GCF-QtCreator plugin and CreateAppTemplateWizard supporting CMake based GCF projects.

Once all this is done, we will then be moving VTK Designer 2 away from QMake build system and totally into a CMake based one. This move coupled with the use of CPack should help us in fast generation of VTK Designer 2 installers.

 

Cadence acquires Taray

Post: Blog — Posted by: prashanthudupa @ 1:06 pm

About a year ago I had blogged about how Taray had signed an OEM deal with Cadence. [http://prashanthudupa.livejournal.com/42294.html]. Today I find out from Ravi, VP of Taray, that Cadence has acquired Taray.

Read the complete news here: http://www.cadence.com/cadence/newsroom/features/pages/feature.aspx?xml=taray

How much they got acquired for is something they are not sharing as yet (or maybe never). But it is wonderful to know that an Indian “product” company has gotten such a beautiful exit. It is even more wonderful to know that our company played a significant part in their product development in the recent past.

My congratulations to Nagesh (CEO), Ravi Vedula (VP), Nishit (FPGA Engineer) and the complete engineering team (made of 18 people in total). You guys rock!

 

GCFSupport Plugin for Qt SDK 2010.02.1

Post: Blog — Posted by: prashanthudupa @ 10:57 am

We have recently made available a GCFSupport plugin for Qt SDK 2010.02.1. Click on the link below to download the plugin.

GCF 2.3.0 Plugin for Qt Creator 1.3.1 (QtSDK 2010.02.1) [Windows Only]”

Using this plugin it is now possible to get started with GCF super-quickly using Qt Creator. Just unpack the ZIP file and take a look at the README.pdf file for instructions. Within minutes you will have GCFSupport enabled in the Qt Creator bundled with Qt-SDK 2010.02.01.

 

GCF 2.3 Released

Post: Blog — Posted by: prashanthudupa @ 1:28 pm

After a bit of a delay, today we announce the release of GCF 2.3. You can download the latest version of GCF from our website. The main new feature in this release is the GCF - Qt Creator integration. With this plugin developers can now use Qt Creator to ease their GCF application development. In addition to this main new feature the latest version comes with several bug-fixes and minor feature additions. Read the change log to find what all has changed in GCF 2.3.0.

In addition to the technical changes, from this version of GCF commercial users can buy licenses of GCF from VCreate Logic and from our official reseller, KDAB.

We hope you like this release.

 

Project/File/Class wizards…

Post: Blog — Posted by: prashanthudupa @ 5:24 pm

Qt Creator comes built in with a set of project/class/file wizards. These wizards are great to get started with, but I always wished if there were an easy way to add support for more project/file/class wizards. In our projects we frequently write models, delegates and widgets. And the skeleton (or starting point) for most classes look the same. So if there was an easy way to quickly create skeleton for a model/delegate/widget class it would be very useful. With this in mind, I started working on the HintBasedWizard plugin for Qt Creator. You can download the source code by checking out the code from the following SVN location

SVN Location: https://svn2.hosted-projects.com/vcreatelogic/VCLTools/QtCPlugins
Username: anonymous
Password: anonymous

Right now we only have support for class wizards based on hints. The hints are provided in three files

  • Header hint
  • Source hint
  • Description hint

The header-hint for item-model class looks like this (and is saved in a file called ItemModelHeader)

#ifndef {{UPPER_CLASS_NAME}}_H
#define {{UPPER_CLASS_NAME}}_H

#include 

struct {{CLASS_NAME}}Data;
class {{CLASS_NAME}} : public QAbstractItemModel
{
    Q_OBJECT

public:
    {{CLASS_NAME}}(QObject* parent=0);
    ~{{CLASS_NAME}}();

    int rowCount(const QModelIndex& parent=QModelIndex()) const;
    int columnCount(const QModelIndex& parent=QModelIndex()) const;
    QVariant data(const QModelIndex& index, int role=Qt::DisplayRole) const;
    QModelIndex index(int row, int column, const QModelIndex& parent=QModelIndex()) const;
    QModelIndex parent(const QModelIndex& index) const;

private:
    {{CLASS_NAME}}Data* d;
};

#endif // {{UPPER_CLASS_NAME}}_H

The source-hint for the same looks like this (and is stored in a file called ItemModelSource)

#include "{{H_FILE_NAME}}"

struct {{CLASS_NAME}}Data
{

};

{{CLASS_NAME}}::{{CLASS_NAME}}(QObject* parent)
:QAbstractItemModel(parent)
{
    d = new {{CLASS_NAME}}Data;
}

{{CLASS_NAME}}::~{{CLASS_NAME}}()
{
    delete d;
}

int {{CLASS_NAME}}::rowCount(const QModelIndex& parent) const
{
    Q_UNUSED(parent);

    return 0;
}

int {{CLASS_NAME}}::columnCount(const QModelIndex& parent) const
{
    Q_UNUSED(parent);

    return 0;
}

QVariant {{CLASS_NAME}}::data(const QModelIndex& index, int role) const
{
    Q_UNUSED(index);
    Q_UNUSED(role);

    return QVariant();
}

QModelIndex {{CLASS_NAME}}::index(int row, int column, const QModelIndex& parent) const
{
    Q_UNUSED(row);
    Q_UNUSED(column);
    Q_UNUSED(parent);

    return QModelIndex();
}

QModelIndex {{CLASS_NAME}}::parent(const QModelIndex& index) const
{
    Q_UNUSED(index);

    return QModelIndex();
}

The description-hint, which is an XML file, for the same looks like this (and is stored in a file called ItemModelClassHint.xml)

<hint>

    <!-- Meta information about the hints -->
    <title>QAbstractItemModel class</title>
    <type>class</type>
    <name>Model class</name>
    <category>Qt Classes</category>
    <description>Generates a QAbstractItemModel implementation</description>
    <icon></icon>

    <!-- actual hints file -->
    <header>ItemModelHeader</header>
    <implementation>ItemModelSource</implementation>

    <!-- hint fields to ask -->
    <field name="CLASS_NAME" label="Class name">ItemModel</field>

</hint>

I store these files in a folder and launch Qt Creator (with the HintBasedWizard plugin compiled/installed ofcourse). Go to Tools -> Options -> Hints Configuration page and add the newly created hint-description file (ItemModelClassHint.xml) by clicking on the “Add Class Hint” button.

Click on Ok. Now start a new project and try adding a new class using the “File-> New” class wizard.

Select the “QAbstractItemModel class” class under Qt Classes and click “Ok”. In the wizard that shows up next, enter appropriate values.

Notice how default values are picked up from the text for <field name=”CLASS_NAME”> xml element in ItemModelClassHint.xml file. Click on Next and notice how the class gets generated for you within your project.

I can now create as many class-hints as I want and increase my productivity in programming. The HintBasedWizard plugin comes with class-wizards for the following class types

  • QAbstractItemModel
  • QWidget
  • QAbstractItemDelegate and
  • QGraphicsItem

We plan to add more class-hints in the coming days and also provide support for hint based project and file wizards.

 

Expand Declarations in Qt Creator

Post: Blog — Posted by: prashanthudupa @ 5:08 pm

One of the things I dont particularly enjoy is to transfer functions from .h (declaration) to .cpp (implementation), specifying the class scope and then creating open and close brackets. The whole process consumes time and I always thought that it can be automated quite easily in Qt Creator. Just wrote a plugin for Qt Creator that makes it possible.

Consider the following class definition below.

Select the function declarations from constructor all the way down to setCurrentColor(). Copy the code snippet using Ctrl+C. Now in the .cpp file for this class as shown below

With the ExpandDeclarations plugin installed, we can now hit the key-combination Ctrl+Shift+V, to get this dialog box

to get this

This one really saves time, I tell you.

You can grab a copy of the plugin from here: https://svn2.hosted-projects.com/vcreatelogic/VCLTools/QtCPlugins/. Username and password for read-only access is anonymous/anonymous. In the same location you can also find a plugin that provides a project wizard called “Qt Creator Plugin” that automatically generates a Qt Creator Plugin skeleton project for you.

You can now select File -> New project and select the “Qt Creator Plugin” project.

Answer some simple questions

And have a fully functional empty plugin project automatically generated :-).

These plugins are given away under LGPL. So you can use them for any purpose you see fit.

 

Happy New Year 2010

Post: Blog — Posted by: prashanthudupa @ 4:22 pm

From all of us here at VCreate Logic, wish you a very happy new year 2010. The current year (2009) has been fantastic for us. Good lot of license sales and new consulting business. We have lost some colleagues and gained new ones. All in all the year was a fun and learning experience.

On the downside, we would like to announce that we are postponing the release of the next version of GCF and VTK Designer by 1.5 months. Sincere apologies to everyone following our development. The last 2 months have been over-hectic, with too many projects nearing completion.

On the up-side, over the last few months a couple of interesting things have begun to happen. We have now become aware of atleast 2 open-source projects that are creating a customized version of VTK Designer. Yay!!! We hope that by mid 2010, those products will be ready for release. We are going to start on 2 new projects from January. Our schedule for the next 5 months is filled :-)

Thanks to all users of our open-source products, commercial license holders and customers. Your presence has kept us motivated and pushed us this far. Keep them coming, we are preparing to up the ante.

Once again, wish you a happy new year 2010.

 

VTK Designer has better DICOM imaging support

Post: Blog — Posted by: prashanthudupa @ 3:14 pm

We have been working on improving medical imaging support in VTK Designer for quite sometime. However, due to heavy workload in other products and projects; this one took a back seat. Up-until now users could select DICOM image set and do a surface render.

But now; over and above this we also support something called “Axial, Coronal and Sagittal plane views”. When DICOM images are loaded in this view, you will get…

The DICOM data-file loader in VTK Designer automatically creates the required pipeline, script and configuration form; and embeds it into the right panel. In that form users can view details about the patient and also extract different axial, coronal and sagittal planes by dragging the sliderbars and clicking “Refresh”.

We are also working on supporting volume rendering of medical images in VTK Designer.

 

GUIXML Editor in Qt Creator

Post: Blog — Posted by: prashanthudupa @ 7:03 pm

When you open a GCF project in Qt Creator, you will notice that the project tree on the left hand side also shows GUIXML files against each component and the global ComponentLoaderComponent.xml (CLC for short) file. The CLC file describes the order of loading of components. Each component’s GUIXML file describes the GUI of the component.

When you double click on any of the GUIXML files, you will get a fancy XML editor that color codes the whole file. Known elements and attributes are marked in bold face; while unknown ones are color coded but in italics. The custom XML editor works only for GCF’s GUIXML files, Qt Creator will default to a simple QPlainTextEdit for other kinds of XML files. We have also implemented find support for the GUIXML editor; that way users can just hit “Ctrl+F” and search for text using the familiar “find text bar” along the bottom edge of the window.

[ Chapter 5 of the document on Writing Qt Creator Plugins was very useful for implementing this feature. Thanks to my colleague Vasudha for researching on this one]

 
Older Posts »