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 <Inventor/engines/SoElapsedTime.h>
25 #include <Inventor/nodes/SoPerspectiveCamera.h>
26 #include <Inventor/SoOffscreenRenderer.h>
27 #include <Inventor/nodes/SoDirectionalLight.h>
28 #include <Inventor/nodes/SoRotationXYZ.h>
29 
30 #include "PreviewGenerator.h"
31 
32 QImage scene3D::PreviewGenerator::createPreview(SoNode* node, int width, int height)
33 {
34  SoSeparator* root = new SoSeparator();
35  root->ref();
36 
37  SoPerspectiveCamera* camera = new SoPerspectiveCamera();
38  root->addChild(camera);
39 
40  SoDirectionalLight* light = new SoDirectionalLight();
41  root->addChild(light);
42 
43  root->addChild(node);
44 
45  SbViewportRegion const region;
46  camera->viewAll(node, region);
47 
48  SoOffscreenRenderer offscreenRenderer(region);
49  offscreenRenderer.setComponents(SoOffscreenRenderer::Components::RGB_TRANSPARENCY);
50  offscreenRenderer.render(root);
51 
52  QImage img(offscreenRenderer.getBuffer(), width,
53  height, QImage::Format_ARGB32);
54 
55  root->unref();
56 
57  // Important!
58  return img.rgbSwapped();
59 }
60 
62 {
63  SoSeparator* root = new SoSeparator;
64 
65  SoRotationXYZ* myRotXYZ = new SoRotationXYZ;
66  root->addChild(myRotXYZ);
67 
68  root->addChild(node);
69 
70  myRotXYZ->axis = SoRotationXYZ::Y; // rotate about X axis
71  SoElapsedTime* myCounter = new SoElapsedTime;
72  myRotXYZ->angle.connectFrom(&myCounter->timeOut);
73 
74 
75  return root;
76 }
77 
scene3D::PreviewGenerator::createAnimatedPreview
SoSeparator * createAnimatedPreview(SoNode *node)
Definition: PreviewGenerator.cpp:61
PreviewGenerator.h
scene3D::PreviewGenerator::createPreview
QImage createPreview(SoNode *node, int width, int height)
Definition: PreviewGenerator.cpp:32