#include "onf_adjustplotpositionimage2ddrawmanager.h" #include #include #include "ct_itemdrawable/ct_image2d.h" #include "ct_tools/ct_typeinfo.h" #include #include template< typename DataT > ONF_AdjustPlotPositionImage2DDrawManager::ONF_AdjustPlotPositionImage2DDrawManager(QString drawConfigurationName) : CT_StandardAbstractItemDrawableWithoutPointCloudDrawManager(drawConfigurationName.isEmpty() ? CT_Image2D::staticName() : drawConfigurationName) { _colorgradient = nullptr; _refZ = 0; } template< typename DataT > ONF_AdjustPlotPositionImage2DDrawManager::~ONF_AdjustPlotPositionImage2DDrawManager() { } template< typename DataT > void ONF_AdjustPlotPositionImage2DDrawManager::setGradient(ONF_ColorLinearInterpolator* colorgradient) { _colorgradient = colorgradient; } template< typename DataT > void ONF_AdjustPlotPositionImage2DDrawManager::setRefZ(double refZ) { _refZ = refZ; } template< typename DataT > void ONF_AdjustPlotPositionImage2DDrawManager::draw(GraphicsViewInterface &view, PainterInterface &painter, const CT_AbstractItemDrawable &itemDrawable) const { if (_colorgradient == nullptr) {return;} CT_StandardAbstractItemDrawableWithoutPointCloudDrawManager::draw(view, painter, itemDrawable); const CT_Image2D &item = dynamic_cast< const CT_Image2D& >(itemDrawable); double minZ = item.minValueAsDouble(); double maxZ = item.maxValueAsDouble(); if (minZ > maxZ) {minZ = maxZ;} double demiRes = item.resolution()/2.0; for (int cx = 0 ; cx < item.xdim() ; cx++) { for (int ly = 0 ; ly < item.ydim() ; ly++) { double x = item.getCellCenterColCoord(cx); double y = item.getCellCenterLinCoord(ly); double value = item.value(cx, ly); if (value != item.NA()) { double ratio = (value - minZ)/(maxZ - minZ); if (value < minZ) {ratio = 0;} if (value > maxZ) {ratio = 1;} painter.setColor(_colorgradient->intermediateColor(ratio)); Eigen::Vector2d tLeft(x - demiRes, y + demiRes); Eigen::Vector2d bRight(tLeft(0)+item.resolution(), tLeft(1)-item.resolution()); painter.fillRectXY(tLeft, bRight, _refZ); } } } } template< typename DataT > CT_ItemDrawableConfiguration ONF_AdjustPlotPositionImage2DDrawManager::createDrawConfiguration(QString drawConfigurationName) const { CT_ItemDrawableConfiguration item = CT_ItemDrawableConfiguration(drawConfigurationName); item.addAllConfigurationOf(CT_StandardAbstractItemDrawableWithoutPointCloudDrawManager::createDrawConfiguration(drawConfigurationName)); return item; } // PROTECTED //