PreviewGenerator.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::gui-plugins::SceneEditor
19  * @date 2015
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #include "PreviewGenerator.h"
25 
26 #include <Inventor/SoOffscreenRenderer.h>
27 #include <Inventor/engines/SoElapsedTime.h>
28 #include <Inventor/nodes/SoDirectionalLight.h>
29 #include <Inventor/nodes/SoPerspectiveCamera.h>
30 #include <Inventor/nodes/SoRotationXYZ.h>
31 
32 QImage
33 scene3D::PreviewGenerator::createPreview(SoNode* node, int width, int height)
34 {
35  SoSeparator* root = new SoSeparator();
36  root->ref();
37 
38  SoPerspectiveCamera* camera = new SoPerspectiveCamera();
39  root->addChild(camera);
40 
41  SoDirectionalLight* light = new SoDirectionalLight();
42  root->addChild(light);
43 
44  root->addChild(node);
45 
46  SbViewportRegion const region;
47  camera->viewAll(node, region);
48 
49  SoOffscreenRenderer offscreenRenderer(region);
50  offscreenRenderer.setComponents(SoOffscreenRenderer::Components::RGB_TRANSPARENCY);
51  offscreenRenderer.render(root);
52 
53  QImage img(offscreenRenderer.getBuffer(), width, height, QImage::Format_ARGB32);
54 
55  root->unref();
56 
57  // Important!
58  return img.rgbSwapped();
59 }
60 
61 SoSeparator*
63 {
64  SoSeparator* root = new SoSeparator;
65 
66  SoRotationXYZ* myRotXYZ = new SoRotationXYZ;
67  root->addChild(myRotXYZ);
68 
69  root->addChild(node);
70 
71  myRotXYZ->axis = SoRotationXYZ::Y; // rotate about X axis
72  SoElapsedTime* myCounter = new SoElapsedTime;
73  myRotXYZ->angle.connectFrom(&myCounter->timeOut);
74 
75 
76  return root;
77 }
scene3D::PreviewGenerator::createAnimatedPreview
SoSeparator * createAnimatedPreview(SoNode *node)
Definition: PreviewGenerator.cpp:62
PreviewGenerator.h
scene3D::PreviewGenerator::createPreview
QImage createPreview(SoNode *node, int width, int height)
Definition: PreviewGenerator.cpp:33