Skip to content
Snippets Groups Projects
Commit 574855c0 authored by Fabian Paus's avatar Fabian Paus
Browse files

ArViz: Reduce include files in CoinVisualizer.cpp

parent 8215830c
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ set(SOURCES
Coin/Visualizer.cpp
Coin/RegisterVisualizationTypes.cpp
Coin/ExportVRML.cpp
Introspection/ElementJsonSerializers.cpp
Introspection/exceptions.cpp
......@@ -66,6 +67,7 @@ set(HEADERS
Coin/VisualizationObject.h
Coin/Visualizer.h
Coin/ExportVRML.h
# Client
Client/Layer.h
......
#include "ExportVRML.h"
#include <ArmarXCore/core/logging/Logging.h>
#include <Inventor/actions/SoWriteAction.h>
#include <Inventor/actions/SoToVRML2Action.h>
#include <Inventor/nodes/SoFile.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/VRMLnodes/SoVRMLGroup.h>
namespace armarx::viz::coin
{
static SoGroup* convertSoFileChildren(SoGroup* orig)
{
if (!orig)
{
return new SoGroup;
}
SoGroup* storeResult;
if (orig->getTypeId() == SoSeparator::getClassTypeId())
{
storeResult = new SoSeparator;
}
else
{
storeResult = new SoGroup;
}
storeResult->ref();
if (orig->getTypeId().isDerivedFrom(SoGroup::getClassTypeId()))
{
// process group node
for (int i = 0; i < orig->getNumChildren(); i++)
{
SoNode* n1 = orig->getChild(i);
if (n1->getTypeId().isDerivedFrom(SoGroup::getClassTypeId()))
{
// convert group
SoGroup* n2 = (SoGroup*)n1;
SoGroup* gr1 = convertSoFileChildren(n2);
storeResult->addChild(gr1);
}
else if (n1->getTypeId() == SoFile::getClassTypeId())
{
// really load file!!
SoFile* fn = (SoFile*)n1;
SoGroup* fileChildren;
fileChildren = fn->copyChildren();
storeResult->addChild(fileChildren);
}
else
{
// just copy child node
storeResult->addChild(n1);
}
}
}
storeResult->unrefNoDelete();
return storeResult;
}
void exportToVRML(SoNode* node, std::string const& exportFilePath)
{
SoOutput* so = new SoOutput();
if (!so->openFile(exportFilePath.c_str()))
{
ARMARX_ERROR << "Could not open file " << exportFilePath << " for writing.";
return;
}
so->setHeaderString("#VRML V2.0 utf8");
SoGroup* n = new SoGroup;
n->ref();
n->addChild(node);
SoGroup* newVisu = convertSoFileChildren(n);
newVisu->ref();
SoToVRML2Action tovrml2;
tovrml2.apply(newVisu);
SoVRMLGroup* newroot = tovrml2.getVRML2SceneGraph();
newroot->ref();
SoWriteAction wra(so);
wra.apply(newroot);
newroot->unref();
so->closeFile();
newVisu->unref();
n->unref();
}
}
#pragma once
#include <Inventor/nodes/SoNode.h>
#include <string>
namespace armarx::viz::coin
{
void exportToVRML(SoNode* node, std::string const& exportFilePath);
}
#include "Visualizer.h"
#include "VisualizationRobot.h"
#include "VisualizationObject.h"
#include "ExportVRML.h"
#include <ArmarXCore/core/logging/Logging.h>
#include <ArmarXCore/util/CPPUtility/GetTypeString.h>
#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
#include <VirtualRobot/Visualization/VisualizationFactory.h>
#include <Inventor/nodes/SoUnits.h>
#include <Inventor/actions/SoWriteAction.h>
#include <Inventor/actions/SoToVRML2Action.h>
#include <Inventor/VRMLnodes/SoVRMLGroup.h>
#include <thread>
#include <Inventor/SoPath.h>
namespace armarx::viz
{
namespace coin
{
void clearRobotCache();
void clearObjectCache();
}
struct CoinVisualizerWrapper : IceUtil::Shared
{
class CoinVisualizer* this_;
......@@ -625,34 +621,6 @@ namespace armarx::viz
void CoinVisualizer::exportToVRML(const std::string& exportFilePath)
{
SoOutput* so = new SoOutput();
if (!so->openFile(exportFilePath.c_str()))
{
ARMARX_ERROR << "Could not open file " << exportFilePath << " for writing." << std::endl;
return;
}
so->setHeaderString("#VRML V2.0 utf8");
SoGroup* n = new SoGroup;
n->ref();
n->addChild(root);
SoGroup* newVisu = VirtualRobot::CoinVisualizationFactory::convertSoFileChildren(n);
newVisu->ref();
SoToVRML2Action tovrml2;
tovrml2.apply(newVisu);
SoVRMLGroup* newroot = tovrml2.getVRML2SceneGraph();
newroot->ref();
SoWriteAction wra(so);
wra.apply(newroot);
newroot->unref();
so->closeFile();
newVisu->unref();
n->unref();
coin::exportToVRML(root, exportFilePath);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment