#ifndef DM_ATTRIBUTESSCALART_HPP #define DM_ATTRIBUTESSCALART_HPP #include "tools/attributes/worker/dm_attributesscalart.h" #include "dm_guimanager.h" #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #include #else #include #endif template DM_AttributesScalarT::DM_AttributesScalarT() : DM_AbstractAttributesScalar() { m_as = NULL; m_autoAdjust = true; m_manualMin = 0; m_manualMax = 1; m_useSharedGradient = false; connect(&m_watcher, SIGNAL(progressRangeChanged(int,int)), this, SLOT(setProgressRanged(int,int)), Qt::DirectConnection); connect(&m_watcher, SIGNAL(progressValueChanged(int)), this, SLOT(setProgress(int)), Qt::DirectConnection); connect(this, SIGNAL(canceled()), &m_watcher, SLOT(cancel())); } template DM_AttributesScalarT::~DM_AttributesScalarT() { } template void DM_AttributesScalarT::setAutoAdjust(bool automatic) { m_autoAdjust = automatic; if(m_autoAdjust) autoAdjustMinMax(); } template void DM_AttributesScalarT::setMin(double min) { m_manualMin = min; setAutoAdjust(false); } template void DM_AttributesScalarT::setMax(double max) { m_manualMax = max; setAutoAdjust(false); } template void DM_AttributesScalarT::setGradient(const QLinearGradient &gradient) { m_gradient = gradient; } template void DM_AttributesScalarT::setUseSharedGradient(bool val) { m_useSharedGradient = val; } template bool DM_AttributesScalarT::setTypeAttributes(const Type *ta, const CT_AbstractAttributesScalar *as) { if(ta != dynamic_cast(as)) return false; setAttributes(ta); m_as = (CT_AbstractAttributesScalar*)as; if(m_autoAdjust) autoAdjustMinMax(); return true; } template bool DM_AttributesScalarT::isUsedSharedGradient() const { return m_useSharedGradient; } template bool DM_AttributesScalarT::isAutoAdjust() const { return m_autoAdjust; } template bool DM_AttributesScalarT::autoAdjust() const { return m_autoAdjust; } template double DM_AttributesScalarT::min() const { return m_manualMin; } template double DM_AttributesScalarT::max() const { return m_manualMax; } template QLinearGradient DM_AttributesScalarT::gradient() const { return m_gradient; } template bool DM_AttributesScalarT::process(GDocumentViewForGraphics *doc) { if(m_as == NULL) return false; double range = m_manualMax-m_manualMin; if(range == 0) range = 1; DM_ColorLinearInterpolator interpolator; interpolator.constructFromQGradient(m_gradient); const CT_AbstractCloudIndex *index = abstractTypeAttributes()->abstractCloudIndex(); size_t size = index->size(); osg::ref_ptr colorArray = doc->getOrCreateGlobalColorArrayForPoints(); if(colorArray.valid()) { QList list; size_t i = 0; while(i < size) { ConcurrentMapInfo *info = new ConcurrentMapInfo(); info->m_as = m_as; info->m_begin = i; i += 100000; if(i >= size) i = size; info->m_end = i; info->m_cc = colorArray; info->m_index = index; info->m_interpolator = &interpolator; info->m_manualMin = m_manualMin; info->m_range = range; info->m_fAccess = &m_fAccess; info->m_eAccess = &m_eAccess; list << info; }; QFuture future = QtConcurrent::map(list, staticApply); m_watcher.setFuture(future); future.waitForFinished(); qDeleteAll(list.begin(), list.end()); doc->dirtyColorsOfPoints(); return true; } return false; } template void DM_AttributesScalarT::attributesDeleted() { m_as = NULL; } template CT_AbstractAttributesScalar* DM_AttributesScalarT::scalarAttributes() const { return m_as; } template Type* DM_AttributesScalarT::abstractTypeAttributes() const { return dynamic_cast(abstractAttributes()); } template void DM_AttributesScalarT::autoAdjustMinMax() { m_manualMin = m_as->dMin(); m_manualMax = m_as->dMax(); } #endif // DM_ATTRIBUTESSCALART_HPP