A li’l more about SoQt and Coin3D

Getting acquainted with SoQt

SoQt requires the Coin3D library. It does not come with Qt. The Qt’s free license prohibits the building of SoQt along with Qt. So it says SoQt has to be built separately on the system. To be able to use SoQt, you must have Coin3D and Qt working on your systems.

By using the combination of Coin3D, Qt and SoQt for your 3D applications, you have a framework for writing completely portable software across the whole range of UNIX, Linux, Microsoft Windows and Mac OS X operating systems. Coin3D, Qt and SoQt creates minimum of hassle for developers when working on multiplatform software, with the resulting large gains in productivity.

Beginning with the name of SoQt itself, we know it is the binding between Qt and Coin3D library. Considering Coin3D library, it is free and opensource implementation of OpenInventor which is capable of easy construction of 3D scenes, animation and provides user interaction with the scene. SoQt is compatible with Open Inventor. All Inventor classes follow a naming convention.

The basic classes in Inventor are prefixed using letters Sb. A few of them are listed below:

  • SbBool: Boolean value
  • SbColor: RGB color value
  • SbLine: directed 3D line
  • SbCylinder: cylinder
  • SbSphere: sphere, and so on.

In order to be able to use any of the basic types, the corresponding header files are included.

The letters So refer to scene object. All the other classes in Inventor are prefixed by these letters.
eg., SoCone, SoTransform etc.
The names of methods and variables follow camel-casing. eg. setSceneGraph()

SoQt, like Coin and Qt, provides the programmer with a high-level application programmer’s interface (API) in C++. The library primarily includes a class-hierarchy of viewer components of varying functionality and complexity, with various modes for the end-user to control the 3D-scene camera interaction.

Working of Coin3D

The node is the basic building block used to create three dimensional scene databases in Inventor.
Each node holds a piece of information, such as a surface material, shape description, geometric
transformation, light, or camera. All 3D shapes, attributes, cameras, and light sources present in a
scene are represented as nodes.

An ordered collection of nodes is referred to as a scene graph. This scene graph is stored in the Inventor database. Inventor takes care of storing and managing the scene graph in the database. The database can contain more than one scene graph. After you have constructed a scene graph, you can apply a number of operations or actions to it, including rendering, picking, searching, computing a bounding box, and writing to a file.

Classes of database primitives include:

  • Nodes– Shape nodes, Property nodes, Group nodes
  • Engines:Engines are objects that can be connected to other objects in the scene graph and used to animate parts of the scene or constrain certain parts of the scene in relation to other parts.
  • Sensors:A sensor is an object that detects when something in the database changes and calls a function supplied by the application. Sensors can respond to specified timing requirements or to changes in the scene graph data.

Nodes

  • Group nodes: These nodes are used to collect child objects. The class for these nodes is SoGroup. This class has various sub-classes under it having different characteristics.
  • Shape nodes: They are used to represent 3D geometric objects.
  • Property nodes: They are used to represent qualitative features of the objects in the scene.

Example

I am referring to an example in my previous post.
#include <Inventor/Qt/SoQt.h>: The SoQt class takes care of Qt initialisation.
#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>: A number of viewers are available to view the 3D object generated. They are:

  • Constrained Viewer
  • Examiner Viewer
  • Fly Viewer
  • Plane Viewer
  • Full Viewer

I am using Examiner Viewer here. It is the general purpose viewer that has a convenient interface for repositioning and reorientation of the camera, by panning, rotating and zooming its position.

#include <Inventor/nodes/SoBaseColor.h>: SoBaseColor is a class used to define an object’s base color. The color is specified in RGB format. It falls under property nodes.

#include <Inventor/nodes/SoCone.h>: This is the node for cone shape. It comes under the category of shape nodes.

#include <Inventor/nodes/SoSeparator.h>: It is subclass of SoGroup class. It is used to isolate the effects of nodes in the scene.

QWidget * mainwin = SoQt::init(argc, argv, argv[0]);: Here the initilisation to the SoQt library is done.

SoSeparator * root = new SoSeparator;
root->ref();
: The root node of the scene graph is created here.

SoBaseColor * col = new SoBaseColor;
col->rgb = SbColor(2, 3, 0);
root->addChild(col);
: The base color of the object is set.

root->addChild(new SoCone);: A cone is added to the scene as a child to the root node.

SoQtExaminerViewer * eviewer = new SoQtExaminerViewer(mainwin);
eviewer->setSceneGraph(root);
eviewer->show();
: The ExaminerViewer class of the viewer is used for display of objects.

SoQt::show(mainwin);: This pops up the main window.

SoQt::mainLoop();: Cleans up all static data allocated by the SoQt library on initialization.

In this post, I discussed a few more details about SoQt and working of Coin3D. Will be posting something interesting soon. Keep reading!

Qt with Coin3D

Well, I do not know how many of you have heard of Qt and Coin3D. In this post, I will be telling you about these and how these two can be used together.

What is Qt?
Qt is a cross-platform application framework that is widely used for developing application software with a graphical user interface (GUI).

Qt can be implemented using following tools:
1.Qt Creator, a cross-platform IDE for C++ and QML. Qt Designer’s GUI layout/design functionality is integrated into this relatively new IDE, although Qt Designer can still be called as a standalone tool.
2.Qmake, a tool that automates the generation of Makefiles for development project across different platforms.

Installation:

  1. Download the source file from http://qt-project.org/downloads according to your system.
  2. Next step is to run the .run file.
  3. First place it in your home directory.
  4. Type in terminal: sudo chmod a+x file-name.run.
  5. Execute ./file-name.run in terminal.
    In my case, I ran qt-opensource-linux-x64-5.2.1.run file and had qt-5.2.1 working on my system.

What is Coin3D?
Check for its installation in my previous post http://kamalpreetgrewal.wordpress.com/2014/03/13/coin3d/.

What is SoQt?
In order to implement Coin3D in Qt, SoQt is required. It acts as glue between Coin3D and Qt.
Type sudo apt-get install libsoqt4-dev in terminal. Now you have SoQt installed.

I had to use Coin3D with Qt. In order to accomplish this, I had to be clear how SoQt and Coin3D work.
The basic working principle is scenegraphs.

What is a scenegraph?
A graphical scene is logically represented using scenegraphs. A scene graph can be defined as collection of nodes in a graph or tree structure. I will be discuusing these in another post.
I created a simple program for cone. The program is:

#include <Inventor/Qt/SoQt.h>

include <Inventor/Qt/viewers/SoQtExaminerViewer.h>

include <Inventor/nodes/SoBaseColor.h>

include <Inventor/nodes/SoCone.h>

include <Inventor/nodes/SoSeparator.h>

int main(int argc, char * argv)
{
// Initializes SoQt library
QWidget
mainwin = SoQt::init(argc, argv, argv[0]);

// Make a dead simple scene graph by using the Coin library.
SoSeparator * root = new SoSeparator;
root-&gt;ref();

SoBaseColor * col = new SoBaseColor;
col-&gt;rgb = SbColor(2, 3, 0);
root-&gt;addChild(col);

root-&gt;addChild(new SoCone);

// Use one of the convenient SoQt viewer classes.
SoQtExaminerViewer * eviewer = new SoQtExaminerViewer(mainwin);
eviewer-&gt;setSceneGraph(root);
eviewer-&gt;show();

// Pop up the main window.
SoQt::show(mainwin);
// Loop until exit.
SoQt::mainLoop();

// Clean up resources.
delete eviewer;
root-&gt;unref();
SoQt::done();

return 0;

}

The next step is open terminal and go to directory where you saved the file.
Follow these steps in terminal:

  1. qmake -project : generates cone.pro file
  2. qmake : generates Makefile
  3. make : In case of some errors regarding SoQt missing (or something similar), open Makefile. Go to LIBS. Append this line with -lSoQt -lCoin and you are done. Again run make.
  4. ./cone

An Examiner Viewer window will show a cone. That’s it. You used Coin3D with Qt. Yeah, was not tough so far. 😀 In case of any queries, do comment.

Coin3D

Coin3D is a high-level, retained-mode toolkit for effective 3D graphics development. It is API compatible with Open Inventor 2.1. Coin3D is a C++ object oriented retained mode 3D graphics API used to provide a higher layer of programming for OpenGL.

Let’s begin with its installation in your Ubuntu.

Installation:

  1. Download Coin-3.1.3.tar.gz fom https://bitbucket.org/Coin3D/coin/downloads.
  2. Next unzip the file using the following commands:
    • cd /tmp
    • gzip -cd Coin-3.1.3.tar.gz | tar xvf –
    • mkdir coin-build
  3. Run configure from the build directory:cd coin-build ../Coin-3.1.3/configure After the configuration is done, it may show some prefix problem. Instead use the following command: ../Coin-3.1.3/configure –prefix=/usr/local –bindir=/usr/local/bin
  4. Build the Coin library: make If this command runs fine, it is well and good. But you may get some errors namely Error1 and Error2 at the end. This can be solved by editing the file Coin-3.1.3/include/Inventor/SbBasic.h. Put #include <Inventor/C/errors/debugerror.h> in the beginning of this file. This is bound to solve the errors in case they appear.
  5. Install the Coin library: make install

This finishes the installation of the Coin3D library. Its implementation will be discussed in coming posts.