Reduce redundant code in View3DInventorViewer class

This commit is contained in:
wmayer
2013-06-20 16:57:10 +02:00
parent 7e3751224a
commit f05be462bc
5 changed files with 38 additions and 113 deletions

View File

@@ -516,81 +516,6 @@ void View3DInventorViewer::setSceneGraph (SoNode *root)
}
}
void View3DInventorViewer::savePicture(const char* filename, int w, int h,
int eBackgroundType, const char* comment) const
{
// if no valid color use the current background
bool useBackground = false;
SbViewportRegion vp(getViewportRegion());
if (w>0 && h>0)
vp.setWindowSize( (short)w, (short)h );
//NOTE: To support pixels per inch we must use SbViewportRegion::setPixelsPerInch( ppi );
//The default value is 72.0.
//If we need to support grayscale images with must either use SoOffscreenRenderer::LUMINANCE or
//SoOffscreenRenderer::LUMINANCE_TRANSPARENCY.
SoFCOffscreenRenderer& renderer = SoFCOffscreenRenderer::instance();
renderer.setViewportRegion(vp);
SoCallback* cb = 0;
// if we use transparency then we must not set a background color
switch(eBackgroundType){
case Current:
if (backgroundroot->findChild(pcBackGround) == -1) {
renderer.setBackgroundColor(this->getBackgroundColor());
}
else {
useBackground = true;
cb = new SoCallback;
cb->setCallback(clearBuffer);
}
break;
case White:
renderer.setBackgroundColor( SbColor(1.0, 1.0, 1.0) );
break;
case Black:
renderer.setBackgroundColor( SbColor(0.0, 0.0, 0.0) );
break;
case Transparent:
renderer.setComponents(SoFCOffscreenRenderer::RGB_TRANSPARENCY );
break;
default:
break;
}
SoSeparator* root = new SoSeparator;
root->ref();
SoCamera* camera = getCamera();
if (useBackground) {
root->addChild(backgroundroot);
root->addChild(cb);
}
root->addChild(getHeadlight());
root->addChild(camera);
SoCallback* gl = new SoCallback;
gl->setCallback(setGLWidget,this->getGLWidget());
root->addChild(gl);
root->addChild(pcViewProviderRoot);
if (useBackground)
root->addChild(cb);
root->addChild(foregroundroot);
try {
// render the scene
if (!renderer.render(root))
throw Base::Exception("Offscreen rendering failed");
// set matrix for miba
renderer._Matrix = camera->getViewVolume().getMatrix();
renderer.writeToImageFile(filename, comment);
root->unref();
}
catch (...) {
root->unref();
throw; // re-throw exception
}
}
void View3DInventorViewer::savePicture(int w, int h, int eBackgroundType, QImage& img) const
{
// if no valid color use the current background