#ifndef CT_STANDARDPROFILEDRAWMANAGER_HPP #define CT_STANDARDPROFILEDRAWMANAGER_HPP #include "ct_itemdrawable/tools/drawmanager/ct_standardprofiledrawmanager.h" #include "ct_itemdrawable/ct_profile.h" #include #include #ifndef _USE_MATH_DEFINES #define _USE_MATH_DEFINES #endif #include #include "qdebug.h" template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_COLUMN_MODE_ENABLED = CT_StandardProfileDrawManager::staticInitConfigColumnModeEnabled(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_COLUMN_RADIUS = CT_StandardProfileDrawManager::staticInitConfigColumnRadius(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_GRAPH_MODE_ENABLED = CT_StandardProfileDrawManager::staticInitConfigGraphModeEnabled(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_DRAW_AXIS = CT_StandardProfileDrawManager::staticInitConfigDrawAxis(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_DRAW_BARS = CT_StandardProfileDrawManager::staticInitConfigDrawBars(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_DRAW_POINTS = CT_StandardProfileDrawManager::staticInitConfigDrawPoints(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_POINTS_SIZE = CT_StandardProfileDrawManager::staticInitConfigPointsSize(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_DRAW_CURVE = CT_StandardProfileDrawManager::staticInitConfigDrawCurve(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_GRAPH_ORIENTATION = CT_StandardProfileDrawManager::staticInitConfigGraphOrientation(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_SCALE = CT_StandardProfileDrawManager::staticInitConfigScale(); template< typename DataT > const QString CT_StandardProfileDrawManager::INDEX_CONFIG_SCALE8COEFFICIENT = CT_StandardProfileDrawManager::staticInitConfigScaleCoeff(); template< typename DataT > CT_StandardProfileDrawManager::CT_StandardProfileDrawManager(QString drawConfigurationName) : CT_StandardAbstractItemDrawableWithoutPointCloudDrawManager(drawConfigurationName.isEmpty() ? CT_Profile::staticName() : drawConfigurationName) { } template< typename DataT > CT_StandardProfileDrawManager::~CT_StandardProfileDrawManager() { } template< typename DataT > void CT_StandardProfileDrawManager::draw(GraphicsViewInterface &view, PainterInterface &painter, const CT_AbstractItemDrawable &itemDrawable) const { CT_StandardAbstractItemDrawableWithoutPointCloudDrawManager::draw(view, painter, itemDrawable); const CT_Profile &item = dynamic_cast&>(itemDrawable); // Getting the configuration values bool columnMode = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_COLUMN_MODE_ENABLED).toBool(); double radius = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_COLUMN_RADIUS).toDouble(); bool graphMode = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_GRAPH_MODE_ENABLED).toBool(); bool drawAxis = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_DRAW_AXIS).toBool(); bool drawBars = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_DRAW_BARS).toBool(); bool drawPoints = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_DRAW_POINTS).toBool(); int pointsSize = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_POINTS_SIZE).toInt(); bool drawCurve = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_DRAW_CURVE).toBool(); int orientation = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_GRAPH_ORIENTATION).toInt(); bool scale = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_SCALE).toBool(); double scaleCoeff = getDrawConfiguration()->getVariableValue(INDEX_CONFIG_SCALE8COEFFICIENT).toDouble(); if (radius <= 0) {radius = 0.50;} if (orientation < 0) {orientation = 0;} if (scaleCoeff <= 0) {scaleCoeff = 0.1;} if (orientation > 360) {orientation = 360;} double amplitude = item.dataMax() - item.dataMin(); double scaling = 2*scaleCoeff / amplitude; double orientationRad = M_PI * (orientation % 360) / 180.0; const Eigen::Vector3d &direction = item.getDirection(); double lastX = 0; double lastY = 0; double lastZ = 0; bool lastNa = false; for (size_t index = 0 ; index < item.nCells() ; index++) { bool isNa = (item.valueAtIndex(index) == item.NA()); double value = item.valueAtIndexAsDouble(index); Eigen::Vector3d center; if (item.getCellCenterXYZ(index, center)) { QColor color = painter.getColor(); if (columnMode) { if (isNa) { painter.setColor(QColor(125, 0, 0)); } else { int colorLevel = ((value - (double)item.dataMin()) / amplitude)*255; painter.setColor(QColor(colorLevel, colorLevel, colorLevel)); } painter.drawPoint(center(0), center(1), center(2)); Eigen::Vector3d cc(center.x(), center.y(), center.z()); Eigen::Vector3d dd(direction.x(), direction.y(), direction.z()); painter.drawCylinder3D(cc, dd, radius, item.resolution()); } painter.setColor(color); if (graphMode) { if (scale) {value = (value - (double)item.dataMin()) * scaling;} Eigen::Vector3d normalVector; if ((direction(0) >= direction(1)) && (direction(0) >= direction(2))) { normalVector(0) = 0; // = 0 normalVector(1) = cos(orientationRad); normalVector(2) = -sin(orientationRad); } else if ((direction(1) >= direction(0)) && (direction(1) >= direction(2))){ normalVector(0) = sin(orientationRad); normalVector(1) = 0; // = 0 normalVector(2) = cos(orientationRad); } else { normalVector(0) = cos(orientationRad); normalVector(1) = -sin(orientationRad); normalVector(2) = 0; // = 0 } normalVector.normalize(); if (isNa) { value = 0; painter.setColor(QColor(125, 0, 0)); } if (drawBars) { Eigen::Vector3d pt1, pt2, pt3, pt4; if (item.getCellCoordinates(index, pt1, pt2)) { pt3 = pt2 + normalVector*value; pt4 = pt1 + normalVector*value; painter.drawLine(pt1(0), pt1(1), pt1(2), pt2(0), pt2(1), pt2(2)); painter.drawLine(pt2(0), pt2(1), pt2(2), pt3(0), pt3(1), pt3(2)); painter.drawLine(pt3(0), pt3(1), pt3(2), pt4(0), pt4(1), pt4(2)); painter.drawLine(pt4(0), pt4(1), pt4(2), pt1(0), pt1(1), pt1(2)); } } if (drawPoints || drawCurve) { double x = center(0) + normalVector(0)*value; double y = center(1) + normalVector(1)*value; double z = center(2) + normalVector(2)*value; if (drawCurve && index > 0) { if (lastNa) {painter.setColor(QColor(125, 0, 0));} painter.drawLine(lastX, lastY, lastZ, x, y, z); } if (drawPoints && index > 0) { painter.setPointSize(pointsSize); painter.enableSetPointSize(false); painter.drawPoint(x, y, z); painter.enableSetPointSize(true); painter.restoreDefaultPointSize(); } lastX = x; lastY = y; lastZ = z; lastNa = isNa; } painter.setColor(color); } } } if (graphMode && drawAxis) { painter.drawLine(item.minX(), item.minY(), item.minZ(), item.maxX(), item.maxY(), item.maxZ()); } } template< typename DataT > CT_ItemDrawableConfiguration CT_StandardProfileDrawManager::createDrawConfiguration(QString drawConfigurationName) const { CT_ItemDrawableConfiguration item = CT_ItemDrawableConfiguration(drawConfigurationName); item.addNewConfiguration(staticInitConfigColumnModeEnabled(), QObject::tr("Mode colonne"), CT_ItemDrawableConfiguration::Bool, false); item.addNewConfiguration(staticInitConfigColumnRadius(), QObject::tr("Rayon de colonne"), CT_ItemDrawableConfiguration::Double, 0.50); item.addNewConfiguration(staticInitConfigGraphModeEnabled(), QObject::tr("Mode graph"), CT_ItemDrawableConfiguration::Bool, true); item.addNewConfiguration(staticInitConfigDrawAxis(), QObject::tr("Dessiner axe"), CT_ItemDrawableConfiguration::Bool, true); item.addNewConfiguration(staticInitConfigDrawBars(), QObject::tr("Dessiner barres"), CT_ItemDrawableConfiguration::Bool, false); item.addNewConfiguration(staticInitConfigDrawPoints(), QObject::tr("Dessiner points"), CT_ItemDrawableConfiguration::Bool, false); item.addNewConfiguration(staticInitConfigPointsSize(), QObject::tr("Taille des points"), CT_ItemDrawableConfiguration::Int, 5); item.addNewConfiguration(staticInitConfigDrawCurve(), QObject::tr("Dessiner courbe"), CT_ItemDrawableConfiguration::Bool, true); item.addNewConfiguration(staticInitConfigGraphOrientation(), QObject::tr("Orientation graph"), CT_ItemDrawableConfiguration::Int, 0); item.addNewConfiguration(staticInitConfigScale(), QObject::tr("Mise à l'échelle"), CT_ItemDrawableConfiguration::Bool, true); item.addNewConfiguration(staticInitConfigScaleCoeff(), QObject::tr("Coefficient d'échelle (m)"), CT_ItemDrawableConfiguration::Double, 5); return item; } // PROTECTED // template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigColumnModeEnabled() { return "PROF_COL"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigColumnRadius() { return "PROF_RAD"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigGraphModeEnabled() { return "PROF_GRA"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigDrawAxis() { return "PROF_AXI"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigDrawBars() { return "PROF_BAR"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigDrawPoints() { return "PROF_PTS"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigPointsSize() { return "PROF_SZP"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigDrawCurve() { return "PROF_CUR"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigGraphOrientation() { return "PROF_ORI"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigScale() { return "PROF_SCA"; } template< typename DataT > QString CT_StandardProfileDrawManager::staticInitConfigScaleCoeff() { return "PROF_COE"; } #endif // CT_STANDARDPROFILEDRAWMANAGER_HPP