Cache cvf::Effect for text labels locally in RivContourMapProjectionPartMgr

This commit is contained in:
Gaute Lindkvist
2019-01-09 09:08:46 +01:00
parent b281a801a8
commit a024a772a8
2 changed files with 12 additions and 6 deletions

View File

@@ -32,6 +32,8 @@ RivContourMapProjectionPartMgr::RivContourMapProjectionPartMgr(RimContourMapProj
{ {
m_contourMapProjection = contourMapProjection; m_contourMapProjection = contourMapProjection;
m_parentContourMap = contourMap; m_parentContourMap = contourMap;
m_labelEffect = new cvf::Effect;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -110,7 +112,7 @@ cvf::ref<cvf::Vec2fArray> RivContourMapProjectionPartMgr::createTextureCoords(co
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RivContourMapProjectionPartMgr::appendContourLinesToModel(const cvf::Camera* camera, void RivContourMapProjectionPartMgr::appendContourLinesToModel(const cvf::Camera* camera,
cvf::ModelBasicList* model, cvf::ModelBasicList* model,
const caf::DisplayCoordTransform* displayCoordTransform) const const caf::DisplayCoordTransform* displayCoordTransform)
{ {
if (m_contourMapProjection->showContourLines()) if (m_contourMapProjection->showContourLines())
{ {
@@ -154,11 +156,9 @@ void RivContourMapProjectionPartMgr::appendContourLinesToModel(const cvf::Camera
} }
for (auto labelDrawableRef : labelDrawables) for (auto labelDrawableRef : labelDrawables)
{ {
cvf::ref<cvf::Effect> effect = new cvf::Effect;
cvf::ref<cvf::Part> part = new cvf::Part; cvf::ref<cvf::Part> part = new cvf::Part;
part->setDrawable(labelDrawableRef.p()); part->setDrawable(labelDrawableRef.p());
part->setEffect(effect.p()); part->setEffect(m_labelEffect.p());
part->setPriority(RivPartPriority::Text); part->setPriority(RivPartPriority::Text);
part->setSourceInfo(new RivMeshLinesSourceInfo(m_contourMapProjection.p())); part->setSourceInfo(new RivMeshLinesSourceInfo(m_contourMapProjection.p()));
model->addPart(part.p()); model->addPart(part.p());
@@ -378,7 +378,7 @@ std::vector<cvf::ref<cvf::Drawable>>
cvf::String labelText(m_contourLinePolygons[i][j].value); cvf::String labelText(m_contourLinePolygons[i][j].value);
size_t nVertices = m_contourLinePolygons[i][j].vertices.size(); size_t nVertices = m_contourLinePolygons[i][j].vertices.size();
size_t nLabels = m_contourMapProjection->showContourLabels() ? std::max((size_t)1, nVertices / 50u) : 0u; size_t nLabels = m_contourMapProjection->showContourLabels() ? std::max((size_t)1, (size_t) (nVertices / 50u * m_contourMapProjection->sampleSpacingFactor())) : 0u;
for (size_t l = 0; l < nLabels; ++l) for (size_t l = 0; l < nLabels; ++l)
{ {
size_t nVertex = (nVertices * l) / nLabels; size_t nVertex = (nVertices * l) / nLabels;

View File

@@ -32,6 +32,11 @@
class RimContourMapView; class RimContourMapView;
namespace cvf
{
class Effect;
}
class RivContourMapProjectionPartMgr : public cvf::Object class RivContourMapProjectionPartMgr : public cvf::Object
{ {
public: public:
@@ -40,7 +45,7 @@ public:
void createProjectionGeometry(); void createProjectionGeometry();
void appendProjectionToModel(cvf::ModelBasicList* model, void appendProjectionToModel(cvf::ModelBasicList* model,
const caf::DisplayCoordTransform* displayCoordTransform) const; const caf::DisplayCoordTransform* displayCoordTransform) const;
void appendContourLinesToModel(const cvf::Camera* camera, cvf::ModelBasicList* model, const caf::DisplayCoordTransform* displayCoordTransform) const; void appendContourLinesToModel(const cvf::Camera* camera, cvf::ModelBasicList* model, const caf::DisplayCoordTransform* displayCoordTransform);
void appendPickPointVisToModel(cvf::ModelBasicList* model, void appendPickPointVisToModel(cvf::ModelBasicList* model,
const caf::DisplayCoordTransform* displayCoordTransform) const; const caf::DisplayCoordTransform* displayCoordTransform) const;
@@ -60,5 +65,6 @@ private:
std::vector<RimContourMapProjection::ContourPolygons> m_contourLinePolygons; std::vector<RimContourMapProjection::ContourPolygons> m_contourLinePolygons;
std::vector<cvf::Vec4d> m_contourMapTriangles; std::vector<cvf::Vec4d> m_contourMapTriangles;
std::vector<std::vector<cvf::BoundingBox>> m_labelBoundingBoxes; std::vector<std::vector<cvf::BoundingBox>> m_labelBoundingBoxes;
cvf::ref<cvf::Effect> m_labelEffect;
}; };