(#266) Added static model interface

This commit is contained in:
Magne Sjaastad 2015-11-17 10:53:41 +01:00
parent 96acc1e75d
commit c6454300d8
2 changed files with 93 additions and 5 deletions

View File

@ -200,6 +200,8 @@ cvf::Camera* caf::Viewer::mainCamera()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void caf::Viewer::setMainScene(cvf::Scene* scene) void caf::Viewer::setMainScene(cvf::Scene* scene)
{ {
appendAllStaticModelsToFrame(scene);
m_mainScene = scene; m_mainScene = scene;
m_mainRendering->setScene(scene); m_mainRendering->setScene(scene);
} }
@ -544,6 +546,8 @@ void caf::Viewer::zoomAll()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void caf::Viewer::addFrame(cvf::Scene* scene) void caf::Viewer::addFrame(cvf::Scene* scene)
{ {
appendAllStaticModelsToFrame(scene);
m_frameScenes.push_back(scene); m_frameScenes.push_back(scene);
m_animationControl->setNumFrames(static_cast<int>(m_frameScenes.size())); m_animationControl->setNumFrames(static_cast<int>(m_frameScenes.size()));
} }
@ -816,3 +820,75 @@ void caf::Viewer::navigationPolicyUpdate()
update(); update();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::Viewer::addStaticModel(cvf::Model* model)
{
if (m_staticModels.contains(model)) return;
m_staticModels.push_back(model);
appendModelToAllFrames(model);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::Viewer::removeStaticModel(cvf::Model* model)
{
removeModelFromAllFrames(model);
m_staticModels.erase(model);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::Viewer::removeAllStaticModels()
{
for (size_t i = 0; i < m_staticModels.size(); i++)
{
removeModelFromAllFrames(m_staticModels.at(i));
}
m_staticModels.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::Viewer::removeModelFromAllFrames(cvf::Model* model)
{
for (size_t i = 0; i < m_frameScenes.size(); i++)
{
cvf::Scene* scene = m_frameScenes.at(i);
scene->removeModel(model);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::Viewer::appendModelToAllFrames(cvf::Model* model)
{
for (size_t i = 0; i < m_frameScenes.size(); i++)
{
cvf::Scene* scene = m_frameScenes.at(i);
scene->addModel(model);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::Viewer::appendAllStaticModelsToFrame(cvf::Scene* scene)
{
for (size_t i = 0; i < m_staticModels.size(); i++)
{
scene->addModel(m_staticModels.at(i));
}
}

View File

@ -49,19 +49,20 @@
namespace cvf { namespace cvf {
class Camera; class Camera;
class Scene;
class Rendering;
class RenderSequence;
class OverlayScalarMapperLegend;
class HitItemCollection; class HitItemCollection;
class Model;
class OverlayImage; class OverlayImage;
class OverlayScalarMapperLegend;
class RenderSequence;
class Rendering;
class Scene;
class TextureImage; class TextureImage;
} }
namespace caf { namespace caf {
class FrameAnimationControl; class FrameAnimationControl;
class Viewer;
class NavigationPolicy; class NavigationPolicy;
class Viewer;
} }
class QInputEvent; class QInputEvent;
@ -93,6 +94,12 @@ public:
cvf::Scene* frame(size_t frameIndex); cvf::Scene* frame(size_t frameIndex);
void removeAllFrames(); void removeAllFrames();
// Static models to be shown in all frames
void addStaticModel(cvf::Model* model);
void removeStaticModel(cvf::Model* model);
void removeAllStaticModels();
// Recursively traverse all the scenes managed by the viewer and make sure all cached values are up-to-date // Recursively traverse all the scenes managed by the viewer and make sure all cached values are up-to-date
// Use when changing the contents inside the objects in the scene. // Use when changing the contents inside the objects in the scene.
// As of yet: Only updates bounding boxes. Other things might be added later. // As of yet: Only updates bounding boxes. Other things might be added later.
@ -170,6 +177,10 @@ private:
void setupMainRendering(); void setupMainRendering();
void setupRenderingSequence(); void setupRenderingSequence();
void appendAllStaticModelsToFrame(cvf::Scene* scene);
void appendModelToAllFrames(cvf::Model* model);
void removeModelFromAllFrames(cvf::Model* model);
void updateCamera(int width, int height); void updateCamera(int width, int height);
void releaseOGlResourcesForCurrentFrame(); void releaseOGlResourcesForCurrentFrame();
@ -195,6 +206,7 @@ private:
caf::FrameAnimationControl* m_animationControl; caf::FrameAnimationControl* m_animationControl;
cvf::Collection<cvf::Scene> m_frameScenes; cvf::Collection<cvf::Scene> m_frameScenes;
cvf::Collection<cvf::Model> m_staticModels;
}; };
} // End namespace caf } // End namespace caf