#2523 Mohr Circle: Improve circle appearence

This commit is contained in:
Rebecca Cox 2018-02-22 18:10:24 +01:00
parent 28efe4661d
commit bf1a621332
4 changed files with 88 additions and 26 deletions

View File

@ -482,6 +482,22 @@ const caf::ColorTable& RiaColorTables::timestepsPaletteColors()
return colorTable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const caf::ColorTable& RiaColorTables::mohrsCirclePaletteColors()
{
static std::vector<cvf::Color3ub> colors{
cvf::Color3ub::RED,
cvf::Color3ub::DARK_GREEN,
cvf::Color3ub::BLUE
};
static caf::ColorTable colorTable = caf::ColorTable(colors);
return colorTable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -52,6 +52,7 @@ public:
static const caf::ColorTable& wellLogPlotPaletteColors();
static const caf::ColorTable& selectionPaletteColors();
static const caf::ColorTable& timestepsPaletteColors();
static const caf::ColorTable& mohrsCirclePaletteColors();
static cvf::Color3f undefinedCellColor();
static cvf::Color3f perforationLengthColor();

View File

@ -18,10 +18,10 @@
#include "RiuMohrsCirclePlot.h"
#include "qwt_round_scale_draw.h"
#include "qwt_symbol.h"
#include "RiuSelectionManager.h"
#include "RiaColorTables.h"
#include "RigFemPartCollection.h"
#include "RigFemPartResultsCollection.h"
#include "RigGeoMechCaseData.h"
@ -33,6 +33,14 @@
#include "cvfAssert.h"
#include <QPainterPath>
#include <QWidget>
#include "qwt_plot_layout.h"
#include "qwt_plot_marker.h"
#include "qwt_plot_rescaler.h"
#include "qwt_plot_shapeitem.h"
//==================================================================================================
///
/// \class RiuMohrsCirclePlot
@ -47,8 +55,13 @@
RiuMohrsCirclePlot::RiuMohrsCirclePlot(QWidget* parent)
: QwtPlot(parent)
{
setDefaults();
setPrincipalsAndRedrawCircles(320, 200, 150);
//setPrincipalsAndRedrawCircles(40, 30, 20);
}
//--------------------------------------------------------------------------------------------------
@ -57,6 +70,7 @@ RiuMohrsCirclePlot::RiuMohrsCirclePlot(QWidget* parent)
RiuMohrsCirclePlot::~RiuMohrsCirclePlot()
{
deleteCircles();
delete m_rescaler;
}
//--------------------------------------------------------------------------------------------------
@ -141,21 +155,44 @@ void RiuMohrsCirclePlot::redrawCircles()
deleteCircles();
createMohrCircles();
for (MohrCircle circle : m_mohrCircles)
QwtPlotMarker* lineXPlotMarker = new QwtPlotMarker("LineX");
lineXPlotMarker->setLineStyle(QwtPlotMarker::HLine);
lineXPlotMarker->setYValue(0);
lineXPlotMarker->attach(this);
QwtPlotMarker* lineYPlotMarker = new QwtPlotMarker("LineY");
lineYPlotMarker->setLineStyle(QwtPlotMarker::VLine);
lineYPlotMarker->setXValue(0);
lineYPlotMarker->attach(this);
caf::ColorTable colors = RiaColorTables::mohrsCirclePaletteColors();
for (size_t i = 0; i < m_mohrCircles.size(); i++)
{
QwtSymbol* circleSymbol = new QwtSymbol(QwtSymbol::Ellipse);
circleSymbol->setSize(2 * circle.radius, 2 * circle.radius);
QwtPlotMarker* circlePlotItem = new QwtPlotMarker("Circle");
circlePlotItem->setSymbol(circleSymbol);
circlePlotItem->setXValue(circle.centerX);
circlePlotItem->setYValue(0);
m_mohrCirclesMarkers.push_back(circlePlotItem);
circlePlotItem->attach(this);
MohrCircle* circle = &m_mohrCircles[i];
QwtPlotShapeItem* plotItem = new QwtPlotShapeItem("Circle");
QPainterPath* circleDrawing = new QPainterPath();
QPointF center(circle->centerX, 0);
circleDrawing->addEllipse(center, circle->radius, circle->radius);
plotItem->setPen(QPen(colors.cycledQColor(i)));
plotItem->setShape(*circleDrawing);
plotItem->setRenderHint(QwtPlotItem::RenderAntialiased, true);
m_circlePlotItems.push_back(plotItem);
plotItem->attach(this);
}
double yHeight = 0.6*(m_principal1 - m_principal3);
this->setAxisScale(QwtPlot::yLeft, -yHeight, yHeight);
double xMin = m_principal3 < 0 ? 1.1*m_principal3 : -1;
double xMax = m_principal1 < 0 ? 1 : 1.1*m_principal1;
this->setAxisScale(QwtPlot::xBottom, xMin, xMax);
this->replot();
m_rescaler->rescale();
this->plotLayout()->setAlignCanvasToScales(true);
}
//--------------------------------------------------------------------------------------------------
@ -163,13 +200,13 @@ void RiuMohrsCirclePlot::redrawCircles()
//--------------------------------------------------------------------------------------------------
void RiuMohrsCirclePlot::deleteCircles()
{
for (size_t i = 0; i < m_mohrCirclesMarkers.size(); i++)
for (size_t i = 0; i < m_circlePlotItems.size(); i++)
{
m_mohrCirclesMarkers[i]->detach();
delete m_mohrCirclesMarkers[i];
m_circlePlotItems[i]->detach();
delete m_circlePlotItems[i];
}
m_mohrCirclesMarkers.clear();
m_circlePlotItems.clear();
}
//--------------------------------------------------------------------------------------------------
@ -210,13 +247,16 @@ bool RiuMohrsCirclePlot::queryDataAndUpdatePlot(RimGeoMechView* geoMechView, siz
//--------------------------------------------------------------------------------------------------
void RiuMohrsCirclePlot::setDefaults()
{
m_rescaler = new QwtPlotRescaler(this->canvas());
m_rescaler->setReferenceAxis(QwtPlot::yLeft);
m_rescaler->setAspectRatio(QwtPlot::xBottom, 1.0);
m_rescaler->setRescalePolicy(QwtPlotRescaler::Fixed);
m_rescaler->setEnabled(true);
enableAxis(QwtPlot::xBottom, true);
enableAxis(QwtPlot::yLeft, true);
enableAxis(QwtPlot::xTop, false);
enableAxis(QwtPlot::yRight, false);
this->setAxisScale(QwtPlot::yLeft, -400, 400);
this->setAxisScale(QwtPlot::xBottom, 0, 400);
}
//--------------------------------------------------------------------------------------------------

View File

@ -19,14 +19,16 @@
#pragma once
#include "qwt_plot.h"
#include "qwt_plot_marker.h"
#include <QWidget>
#include "qwt_plot_item.h"
#include <array>
class RiuSelectionItem;
class RimGeoMechView;
class QwtRoundScaleDraw;
class QwtPlotRescaler;
class QWidget;
//==================================================================================================
//
//
@ -73,7 +75,10 @@ private:
double m_principal1;
double m_principal2;
double m_principal3;
std::array<MohrCircle, 3> m_mohrCircles;
std::vector<QwtPlotMarker*> m_mohrCirclesMarkers;
std::array<MohrCircle, 3> m_mohrCircles;
std::vector<QwtPlotItem*> m_circlePlotItems;
QwtPlotRescaler* m_rescaler;
};