#2607 Adjust handle size to follow characteristic cell size. Add vertical axis handle.

This commit is contained in:
Jacob Støren
2018-08-17 10:35:42 +02:00
parent 2ed84c9df2
commit 67d4df69b2
2 changed files with 101 additions and 8 deletions

View File

@@ -70,6 +70,15 @@ void RicPointTangentManipulator::setTangent(const cvf::Vec3d& tangent)
emit notifyRedraw();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPointTangentManipulator::setHandleSize(double handleSize)
{
m_partManager->setHandleSize(handleSize);
emit notifyRedraw();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -177,7 +186,8 @@ bool RicPointTangentManipulator::eventFilter(QObject *obj, QEvent* inputEvent)
#include "cvfHitItem.h"
#include <QDebug>
#include "cvfGeometryBuilderTriangles.h"
#include "cvfGeometryUtils.h"
//
@@ -188,7 +198,8 @@ bool RicPointTangentManipulator::eventFilter(QObject *obj, QEvent* inputEvent)
RicPointTangentManipulatorPartMgr::RicPointTangentManipulatorPartMgr()
: m_tangentOnStartManipulation(cvf::Vec3d::UNDEFINED),
m_originOnStartManipulation(cvf::Vec3d::UNDEFINED),
m_currentHandleIndex(cvf::UNDEFINED_SIZE_T)
m_currentHandleIndex(cvf::UNDEFINED_SIZE_T),
m_handleSize(1.0)
{
}
@@ -225,6 +236,14 @@ void RicPointTangentManipulatorPartMgr::setTangent(const cvf::Vec3d& tangent)
clearAllGeometryAndParts();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPointTangentManipulatorPartMgr::setHandleSize(double handleSize)
{
m_handleSize = handleSize;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -375,13 +394,17 @@ void RicPointTangentManipulatorPartMgr::recreateAllGeometryAndParts()
void RicPointTangentManipulatorPartMgr::createAllHandleParts()
{
createHorizontalPlaneHandle();
createVerticalAxisHandle();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPointTangentManipulatorPartMgr::createHorizontalPlaneHandle()
{
using namespace cvf;
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray(6);
float handleSize = 1.0;
vertexArray->set(0, {-1, -1, 0} );
vertexArray->set(1, { 1, -1, 0});
vertexArray->set(2, { 1, 1, 0});
@@ -392,20 +415,71 @@ void RicPointTangentManipulatorPartMgr::createHorizontalPlaneHandle()
Vec3f origin(m_origin);
for (cvf::Vec3f& vx: *vertexArray)
{
vx *= handleSize;
vx *= 0.5*m_handleSize;
vx += origin;
}
ref<DrawableGeo> geo = createTriangelDrawableGeo(vertexArray.p());
HandleType handleId = HORIZONTAL_PLANE;
cvf::Color4f color = cvf::Color4f(cvf::Color3::MAGENTA);
cvf::Color4f color = cvf::Color4f({1.0f, 0.0f, 1.0f, 0.5f});
cvf::String partName("PointTangentManipulator Horizontal Plane Handle");
addHandlePart(geo.p(), color, handleId, partName);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPointTangentManipulatorPartMgr::createVerticalAxisHandle()
{
using namespace cvf;
cvf::ref< cvf::GeometryBuilderTriangles> geomBuilder = new cvf::GeometryBuilderTriangles;
cvf::GeometryUtils::createBox({-0.25f, -0.25f, -1.0f}, { 0.25f, 0.25f, 1.0f}, geomBuilder.p());
cvf::ref<cvf::Vec3fArray> vertexArray = geomBuilder->vertices();
cvf::ref<cvf::UIntArray> indexArray = geomBuilder->triangles();
Vec3f origin(m_origin);
for (cvf::Vec3f& vx: *vertexArray)
{
vx *= 0.5*m_handleSize;
vx += origin;
}
ref<DrawableGeo> geo = createIndexedTriangelDrawableGeo(vertexArray.p(), indexArray.p());
HandleType handleId = VERTICAL_AXIS;
cvf::Color4f color = cvf::Color4f({0.0f, 0.2f, 0.8f, 0.5f});
cvf::String partName("PointTangentManipulator Vertical Axis Handle");
addHandlePart(geo.p(), color, handleId, partName);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo> RicPointTangentManipulatorPartMgr::createIndexedTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray,
cvf::UIntArray* triangleIndices)
{
using namespace cvf;
ref<DrawableGeo> geo = new DrawableGeo;
ref<PrimitiveSetIndexedUInt> primSet = new PrimitiveSetIndexedUInt(PT_TRIANGLES, triangleIndices);
geo->setVertexArray(triangleVertexArray);
geo->addPrimitiveSet(primSet.p());
geo->computeNormals();
return geo;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo> RicPointTangentManipulatorPartMgr::createTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray)
{
using namespace cvf;
@@ -630,6 +704,8 @@ void RicWellPathGeometry3dEditor::configureAndUpdateUi(const QString& uiConfigNa
#include "RimWellPathTarget.h"
#include "RiuViewer.h"
#include "cafDisplayCoordTransform.h"
#include "Rim3dView.h"
#include "RimCase.h"
CAF_PDM_UI_OBJECT_3D_EDITOR_SOURCE_INIT(RicWellTarget3dEditor);
@@ -692,11 +768,18 @@ void RicWellTarget3dEditor::configureAndUpdateUi(const QString& uiConfigName)
m_ownerViewer->addStaticModelOnce(m_cvfModel.p());
}
RiuViewer* viewer = dynamic_cast<RiuViewer*>(m_ownerViewer.data());
cvf::ref<caf::DisplayCoordTransform> dispXf = viewer->ownerReservoirView()->displayCoordTransform();
cvf::ref<caf::DisplayCoordTransform> dispXf;
double handleSize = 1.0;
{
RiuViewer* viewer = dynamic_cast<RiuViewer*>(m_ownerViewer.data());
dispXf = viewer->ownerReservoirView()->displayCoordTransform();
Rim3dView* view = dynamic_cast<Rim3dView*>(viewer->ownerReservoirView());
handleSize = 0.5 * view->ownerCase()->characteristicCellSize();
}
m_manipulator->setOrigin(dispXf->transformToDisplayCoord( target->targetPointXYZ() + geomDef->referencePoint()));
m_manipulator->setTangent(target->tangent());
m_manipulator->setHandleSize(handleSize);
m_cvfModel->removeAllParts();
m_manipulator->appendPartsToModel(m_cvfModel.p());

View File

@@ -54,6 +54,7 @@ public:
void setOrigin(const cvf::Vec3d& origin);
void setTangent(const cvf::Vec3d& tangent);
void setHandleSize(double handleSize);
void appendPartsToModel(cvf::ModelBasicList* model);
@@ -92,6 +93,8 @@ class HitItem;
template <typename> class Array;
typedef Array<Vec3f> Vec3fArray;
typedef Array<uint> UIntArray;
}
class RicPointTangentManipulatorPartMgr : public cvf::Object
@@ -111,6 +114,7 @@ public:
void setOrigin(const cvf::Vec3d& origin);
void setTangent(const cvf::Vec3d& tangent);
void setHandleSize(double handleSize);
void originAndTangent(cvf::Vec3d* origin, cvf::Vec3d* tangent);
bool isManipulatorActive() const;
@@ -126,6 +130,7 @@ private:
void recreateAllGeometryAndParts();
void createHorizontalPlaneHandle();
void createVerticalAxisHandle();
void addHandlePart(cvf::DrawableGeo* geo,
const cvf::Color4f& color,
@@ -138,6 +143,8 @@ private:
const cvf::String& partName);
static cvf::ref<cvf::DrawableGeo> createTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray);
static cvf::ref<cvf::DrawableGeo> createIndexedTriangelDrawableGeo(cvf::Vec3fArray* triangleVertexArray,
cvf::UIntArray* triangleIndices);
static cvf::ref<cvf::Part> createPart(cvf::DrawableGeo* geo,
const cvf::Color4f& color,
const cvf::String& partName);
@@ -149,6 +156,7 @@ private:
cvf::Vec3d m_origin;
cvf::Vec3d m_tangent;
double m_handleSize;
cvf::Vec3d m_initialPickPoint;
cvf::Vec3d m_tangentOnStartManipulation;
@@ -168,7 +176,9 @@ private:
#include "cafSelectionChangedReceiver.h"
#include "cafPdmUiObjectEditorHandle.h"
#include "cafFactory.h"
// PdmUiObjectEditorHandle
// PdmUiObjectWidgetEditorHandle --<| PdmUiWidgetBasedObjectEditor PdmUiObjectFormLayoutEditor
// PdmUiObject3dEditorHandle
namespace caf
{