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.
- 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.
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);: Here the initilisation to the SoQt library is done.
SoSeparator * root = new SoSeparator;: The root node of the scene graph is created here.
SoBaseColor * col = new SoBaseColor;: The base color of the object is set.
col->rgb = SbColor(2, 3, 0);
root->addChild(new SoCone);: A cone is added to the scene as a child to the root node.
SoQtExaminerViewer * eviewer = new SoQtExaminerViewer(mainwin);: 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!