[IGSTK-Users] Display my first object with QT

Özgür Güler ozgur_guler at gmx.at
Fri Dec 20 12:26:47 EST 2013


Hi Steve,

following code works for me, I will let you compare and find out about
the issue :)
I didn't change much I used your code where you generate the cube,
just be aware, as you start the app the camera is inside the cube and
you have to zoom out to see the entire cube. Find attached the
screenshot of the cube (after zooming out)

Best,
Ozgur

///////
#if defined(_MSC_VER)
//  Warning about: identifier was truncated to '255' characters in the
//  debug information (MVC6.0 Debug)
#pragma warning( disable : 4786 )
#endif

// QT header files
#include <QApplication>
#include <QMainWindow>
#include <QtTest/QTest>

#include <iostream>
#include "igstkView3D.h"
#include "igstkQTWidget.h"
#include "igstkBoxObject.h"
#include "igstkBoxObjectRepresentation.h"

int main( int argc, char * argv[])
{
  igstk::RealTimeClock::Initialize();

  typedef igstk::View3D  View3DType;

  try
    {
     // Create the box
    typedef igstk::BoxObject                ObjectType;
    typedef igstk::BoxObjectRepresentation  ObjectRepresentationType;
    ObjectType::Pointer cube = ObjectType::New();
    ObjectRepresentationType::Pointer cubeRepresentation =
ObjectRepresentationType::New();
    cubeRepresentation->SetColor( 0.0, 0.0, 1.0 );
    cubeRepresentation->SetOpacity( 0.5);
    cubeRepresentation->RequestSetBoxObject(cube);

    //creat the transformation
    igstk::Transform transform;
    transform.SetToIdentity(
igstk::TimeStamp::GetLongestPossibleTime()); //identity transform

    //Add the annotations to each corner ([0,3]
    igstk::Annotation2D::Pointer annotation = igstk::Annotation2D::New();
    annotation->RequestSetAnnotationText(0,"BL");
    annotation->RequestSetFontSize(0,14);
    annotation->RequestSetFontColor(0,0.0,1.0,1.0);
    annotation->RequestSetAnnotationText(1,"BR");
    annotation->RequestSetFontSize(1,14);
    annotation->RequestSetAnnotationText(2,"TL");
    annotation->RequestSetFontSize(2,14);
    annotation->RequestSetAnnotationText(3,"TR");
    annotation->RequestSetFontSize(3,14);

    View3DType::Pointer view3D = View3DType::New();
     cube->RequestSetTransformAndParent( transform, view3D );
    view3D->RequestResetCamera();

    view3D->RequestAddObject( cubeRepresentation );
    view3D->RequestAddAnnotation2D (annotation);
    view3D->SetRefreshRate( 30 );
 view3D->SetRendererBackgroundColor(0,0,0);

    // Create QT minimal GUI
    QApplication app(argc, argv);
    QMainWindow  * qtMainWindow = new QMainWindow();
    qtMainWindow->setFixedSize(600,300);

    typedef igstk::QTWidget      QTWidgetType;

    QTWidgetType * qtWidget3D = new QTWidgetType();
    qtWidget3D->RequestEnableInteractions();
    qtWidget3D->RequestSetView( view3D );

    qtMainWindow->setCentralWidget( qtWidget3D );
    qtMainWindow->show();

 view3D->RequestStart();

    while(1)
      {
      QTest::qWait(10);
      igstk::PulseGenerator::CheckTimeouts();
      }
    system("PAUSE");
    delete qtWidget3D;
    delete qtMainWindow;
    }
  catch(...)
    {
    std::cerr << "Exception catched !!" << std::endl;
    return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}
///////

On Fri, Dec 20, 2013 at 8:17 AM,  <steve.berger at istb.unibe.ch> wrote:
> Hi Ozgür,
>
> Thank you very much for your answer.
> I'm comming back to you with my question about displaying a cube in a
> View3D.
> I did what you suggested, but the cube is still not here.
> I can display annotation without problem, I checked that the Cube was
> located at position (0,0,0), then I tried to put the camera in another
> place, but still not possible to display the cube.
>
> Would you have any suggestions?
> Bellow are my code, updated with your scene graph suggestion.
>
> Thank you for your support,
> Steve
>
>
>
> #include "MainWindow.h"
>
> MainWindow::MainWindow()
> {
>
>     //initialize the RealTimeClock.
>     igstk::RealTimeClock::Initialize();
>
>     // Create the box
>     typedef igstk::BoxObject                ObjectType;
>     typedef igstk::BoxObjectRepresentation  ObjectRepresentationType;
>     ObjectType::Pointer cube = ObjectType::New();
>     ObjectRepresentationType::Pointer cubeRepresentation =
> ObjectRepresentationType::New();
>     cubeRepresentation->SetColor( 0.0, 0.0, 1.0 );
>     cubeRepresentation->SetOpacity( 0.5);
>     cubeRepresentation->RequestSetBoxObject(cube);
>
>     //creat the transformation
>     igstk::Transform transform;
>     transform.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime());
> //identity transform
>
>
>     //Add the annotations to each corner ([0,3]
>     igstk::Annotation2D::Pointer annotation = igstk::Annotation2D::New();
>     annotation->RequestSetAnnotationText(0,"BL");
>     annotation->RequestSetFontSize(0,14);
>     annotation->RequestSetFontColor(0,0.0,1.0,1.0);
>     annotation->RequestSetAnnotationText(1,"BR");
>     annotation->RequestSetFontSize(1,14);
>     annotation->RequestSetAnnotationText(2,"TL");
>     annotation->RequestSetFontSize(2,14);
>     annotation->RequestSetAnnotationText(3,"TR");
>     annotation->RequestSetFontSize(3,14);
>
>
>     // View 3D
>     typedef igstk::View3D View3DType;
>     View3DType::Pointer view3D = View3DType::New();
>
>     // scene graph
>     //view3D->cube
>
>     cube->RequestSetTransformAndParent( transform, view3D );
>
>     //    view3D->SetCameraPosition(10.0,10.0,10.0);
>     //    view3D->SetCameraFocalPoint(0.0,0.0,0.0);
>     //    view3D->SetCameraViewUp(0.0,0.0,1.0);
>     //    view3D->SetCameraClippingRange(0.0,100000.0);
>
>     view3D->RequestResetCamera();
>     view3D->RequestAddObject( cubeRepresentation );
>     view3D->RequestAddAnnotation2D (annotation);
>
>     view3D->SetRefreshRate( 30 );
>     view3D->RequestStart();
>     view3D->SetRendererBackgroundColor (0.0, 0.0, 0.0);
>
>
>
>     //QT Widget
>     igstk::QTWidget * myQTWidget = new igstk::QTWidget();
>     myQTWidget->RequestSetView( view3D );
>     setCentralWidget( myQTWidget );
>     setFixedSize(720,576);
>
> }
>
>
>
> ________________________________
> De : ozgur.guler.phd at gmail.com [ozgur.guler.phd at gmail.com] de la part de
> Özgür Güler [ozgur_guler at gmx.at]
> Envoyé : mardi, 17. décembre 2013 00:39
> À : Berger, Steve (ISTB)
> Cc : igstk-users at public.kitware.com
> Objet : Re: [IGSTK-Users] Display my first object with QT
>
> Hi Steve,
>
> you have to build also the scene graph, which describes the spatial
> relationship between the objects in your scene. In your case it contains
> just a cube and the view.
>
> //identity transform
> igstk::Transform transform;
> transform.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() );
>
> // scene graph
> // view3D->cube
> cube->RequestSetTransformAndParent( transform, view3D );
>
> Best,
> Ozgur
>
> On Fri, Dec 13, 2013 at 10:51 AM, <steve.berger at istb.unibe.ch> wrote:
>> Hi,
>>
>> I'm starting to use IGSTK and try to simply display a cube in the QT's
>> main
>> windows. My code is very basic and compile, the window pop-up but nothing
>> is
>> displayed in the windows (it's only gray).
>> Could anyone give me a clue? I'm puzzled with that from 3 days...
>>
>> Bellow are my codes, and the software versions I am using.
>>
>> Thanks a lot for your support,
>> Cheers,
>> Steve
>>
>>
>>
>> The main:
>> int main(int argc, char *argv[])
>> {
>> QApplication app(argc,argv);
>>
>> MainWindow w;
>> w.show();
>>
>> return app.exec();
>> }
>>
>>
>>
>> The MainWindow.h:
>>
>> #ifndef MAINWINDOW_H
>> #define MAINWINDOW_H
>> #include <QtGui>
>> #include "igstkBoxObject.h"
>> #include "igstkBoxObjectRepresentation.h"
>> #include "igstkView3D.h"
>> #include "igstkQTWidget.h"
>>
>> class MainWindow : public QMainWindow
>> {
>> public:
>> MainWindow();
>>
>> };
>> #endif
>>
>>
>>
>>
>> The MainWindow.cpp
>>
>> #include "MainWindow.h"
>> MainWindow::MainWindow()
>> {
>> //initialize the RealTimeClock.
>> igstk::RealTimeClock::Initialize();
>>
>> // Create the box
>> typedef igstk::BoxObject ObjectType;
>> typedef igstk::BoxObjectRepresentation ObjectRepresentationType;
>> ObjectType::Pointer cube = ObjectType::New();
>> ObjectRepresentationType::Pointer cubeRepresentation =
>> ObjectRepresentationType::New();
>> cubeRepresentation->SetColor( 0.0, 0.0, 1.0 );
>> cubeRepresentation->SetOpacity( 1.0 );
>> cubeRepresentation->RequestSetBoxObject(cube);
>>
>> // View 3D
>> typedef igstk::View3D View3DType;
>> View3DType::Pointer view3D = View3DType::New();
>> view3D->RequestResetCamera();
>> view3D->RequestAddObject( cubeRepresentation );
>> view3D->SetRefreshRate( 30 );
>> view3D->RequestStart();
>>
>> //QT Widget
>> igstk::QTWidget * myQTWidget = new igstk::QTWidget();
>> myQTWidget->RequestSetView( view3D );
>> setCentralWidget( myQTWidget );
>> }
>>
>>
>> The software versions:
>> QT 4.8.5
>> ITK 4.4.2
>> VTK 5.10.1
>> IGSTK 5.2
>>
>> During the installation of VTK, I checked
>> VTK_USE_QT ON
>> VTK_USE_QTCHARTS ON
>> VTK_USE_RENDERING ON
>>
>> During installation of IGSTK, I checked
>> IGSTK_USE_Qt ON
>> DESIRED_QT_VERSION 4
>> QT_QMAKE_EXECUTABLE /usr/local/Trolltech/Qt-4.8.5/bin/qmake
>>
>>
>>
>> Thanks a lot for your help!
>> Steve
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/cgi-bin/mailman/listinfo/igstk-users
>
> --
> *********************************************************************
> Dr. Dipl.-Ing. Özgür Güler, Bakk. techn. PhD
> Research Assistant
> 4D-Visualization Laboratory
> Univ. ENT Clinic
> Innsbruck Medical University
> Anichstr. 35, A-6020 Innsbruck, Austria
>
> tel.: +43 512 504 23428, fax.: +43 512 504 25231
>
> voxelmaster.eu
> www.gueler.at
> *********************************************************************



-- 
*********************************************************************
Dr. Dipl.-Ing. Özgür Güler, Bakk. techn. PhD
Research Assistant
4D-Visualization Laboratory
Univ. ENT Clinic
Innsbruck Medical University
Anichstr. 35, A-6020 Innsbruck, Austria

tel.: +43 512 504 23428, fax.: +43 512 504 25231

voxelmaster.eu
www.gueler.at
*********************************************************************
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cube.JPG
Type: image/jpeg
Size: 20651 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/igstk-users/attachments/20131220/aa173e9e/attachment.jpe>


More information about the IGSTK-Users mailing list