mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#884) Added prototype of event handler for interaction with box
This commit is contained in:
parent
fa6a6b4f08
commit
d4bdbcb7c8
@ -5,6 +5,9 @@ if (${CMAKE_VERSION} VERSION_GREATER "2.8.2")
|
||||
endif()
|
||||
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RicBoxManipulatorEventHandler.h
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxEventFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicAppendIntersectionBoxFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicIntersectionBoxXSliceFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicIntersectionBoxYSliceFeature.h
|
||||
@ -12,6 +15,9 @@ ${CEE_CURRENT_LIST_DIR}RicIntersectionBoxZSliceFeature.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RicBoxManipulatorEventHandler.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxEventFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicAppendIntersectionBoxFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicIntersectionBoxXSliceFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicIntersectionBoxYSliceFeature.cpp
|
||||
@ -26,4 +32,11 @@ list(APPEND CODE_SOURCE_FILES
|
||||
${SOURCE_GROUP_SOURCE_FILES}
|
||||
)
|
||||
|
||||
set (QT_MOC_HEADERS
|
||||
${QT_MOC_HEADERS}
|
||||
${CEE_CURRENT_LIST_DIR}RicBoxManipulatorEventHandler.h
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxEventFeature.h
|
||||
)
|
||||
|
||||
|
||||
source_group( "CommandFeature\\IntersectionBox" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CEE_CURRENT_LIST_DIR}CMakeLists_files.cmake )
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "cafCmdExecuteCommand.h"
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
class RimIntersectionBoxCollection;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
|
@ -0,0 +1,212 @@
|
||||
|
||||
#include "RicBoxManipulatorEventHandler.h"
|
||||
|
||||
#include "cvfModelBasicList.h"
|
||||
#include "cvfPart.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cafEffectGenerator.h"
|
||||
|
||||
|
||||
#include "cvfHitItemCollection.h"
|
||||
|
||||
#include "cafViewer.h"
|
||||
#include "cafBoxManipulatorPartManager.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicBoxManipulatorEventHandler::RicBoxManipulatorEventHandler(caf::Viewer* viewer)
|
||||
: m_viewer(viewer),
|
||||
m_scaleZ(1.0),
|
||||
m_isGeometryCreated(false)
|
||||
{
|
||||
m_partManager = new caf::BoxManipulatorPartManager;
|
||||
m_model = new cvf::ModelBasicList;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicBoxManipulatorEventHandler::~RicBoxManipulatorEventHandler()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::setScaleZ(double scaleZ)
|
||||
{
|
||||
m_scaleZ = scaleZ;
|
||||
|
||||
updatePartManagerCoords();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::setDisplayModelOffset(cvf::Vec3d offset)
|
||||
{
|
||||
m_displayModelOffset = offset;
|
||||
|
||||
updatePartManagerCoords();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::setOrigin(const cvf::Mat4d& origin)
|
||||
{
|
||||
m_domainCoordOrigin = origin;
|
||||
|
||||
updatePartManagerCoords();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::setSize(const cvf::Vec3d& size)
|
||||
{
|
||||
m_domainCoordSize = size;
|
||||
|
||||
updatePartManagerCoords();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Model* RicBoxManipulatorEventHandler::model()
|
||||
{
|
||||
return m_model.p();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicBoxManipulatorEventHandler::eventFilter(QObject *obj, QEvent* inputEvent)
|
||||
{
|
||||
if (!m_isGeometryCreated)
|
||||
{
|
||||
updateParts();
|
||||
|
||||
emit geometryUpdated();
|
||||
|
||||
inputEvent->setAccepted(true);
|
||||
|
||||
m_isGeometryCreated = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
/*
|
||||
if (inputEvent->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(inputEvent);
|
||||
|
||||
cvf::HitItemCollection hitItems;
|
||||
if (m_viewer->rayPick(mouseEvent->x(), mouseEvent->y(), &hitItems))
|
||||
{
|
||||
// TODO: Test if the first hit item is part of the manipulator
|
||||
/ *
|
||||
if (hitItems.firstItem() && hitItems.firstItem()->part())
|
||||
{
|
||||
const cvf::Object* siConstObj = hitItems.firstItem()->part()->sourceInfo();
|
||||
cvf::Object* siObj = const_cast<cvf::Object*>(siConstObj);
|
||||
|
||||
caf::BoxManipulatorSourceInfo* sourceInfo = dynamic_cast<caf::BoxManipulatorSourceInfo*>(siObj);
|
||||
if (sourceInfo)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
* /
|
||||
|
||||
switch (inputEvent->type())
|
||||
{
|
||||
case QEvent::MouseButtonPress:
|
||||
mouseMoveEvent(static_cast<QMouseEvent*>(inputEvent));
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
mouseReleaseEvent(static_cast<QMouseEvent*>(inputEvent));
|
||||
break;
|
||||
case QEvent::MouseMove:
|
||||
mouseMoveEvent(static_cast<QMouseEvent*>(inputEvent));
|
||||
break;
|
||||
}
|
||||
|
||||
updateParts();
|
||||
|
||||
emit geometryUpdated();
|
||||
|
||||
inputEvent->setAccepted(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::updateParts()
|
||||
{
|
||||
m_model->removeAllParts();
|
||||
|
||||
m_partManager->appendPartsToModel(m_model.p());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::updatePartManagerCoords()
|
||||
{
|
||||
cvf::Mat4d displayCoordOrigin = m_domainCoordOrigin;
|
||||
cvf::Vec3d domainCoordTrans = m_domainCoordOrigin.translation();
|
||||
displayCoordOrigin.setTranslation(displayModelCoordFromDomainCoord(domainCoordTrans));
|
||||
|
||||
m_partManager->setOrigin(displayCoordOrigin);
|
||||
|
||||
cvf::Vec3d domainCoordSize = m_domainCoordSize;
|
||||
domainCoordSize.z() *= m_scaleZ;
|
||||
m_partManager->setSize(domainCoordSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec3d RicBoxManipulatorEventHandler::displayModelCoordFromDomainCoord(const cvf::Vec3d& domainCoord) const
|
||||
{
|
||||
cvf::Vec3d coord = domainCoord - m_displayModelOffset;
|
||||
coord.z() *= m_scaleZ;
|
||||
|
||||
return coord;
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfMatrix4.h"
|
||||
#include "cvfVector3.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
|
||||
namespace cvf {
|
||||
class Model;
|
||||
class ModelBasicList;
|
||||
};
|
||||
|
||||
|
||||
namespace caf {
|
||||
class BoxManipulatorPartManager;
|
||||
class Viewer;
|
||||
};
|
||||
|
||||
class QMouseEvent;
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicBoxManipulatorEventHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RicBoxManipulatorEventHandler(caf::Viewer* viewer);
|
||||
~RicBoxManipulatorEventHandler();
|
||||
|
||||
void setScaleZ(double scaleZ);
|
||||
void setDisplayModelOffset(cvf::Vec3d offset);
|
||||
|
||||
void setOrigin(const cvf::Mat4d& origin);
|
||||
void setSize(const cvf::Vec3d& size);
|
||||
|
||||
cvf::Model* model();
|
||||
|
||||
signals:
|
||||
void geometryUpdated();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
|
||||
|
||||
private:
|
||||
void updateParts();
|
||||
|
||||
void updatePartManagerCoords();
|
||||
|
||||
cvf::Vec3d displayModelCoordFromDomainCoord(const cvf::Vec3d& domainCoord) const;
|
||||
|
||||
private:
|
||||
cvf::ref<caf::BoxManipulatorPartManager> m_partManager;
|
||||
|
||||
cvf::ref<cvf::ModelBasicList> m_model;
|
||||
QPointer<caf::Viewer> m_viewer;
|
||||
|
||||
double m_scaleZ;
|
||||
cvf::Vec3d m_displayModelOffset;
|
||||
|
||||
cvf::Mat4d m_domainCoordOrigin;
|
||||
cvf::Vec3d m_domainCoordSize;
|
||||
|
||||
bool m_isGeometryCreated;
|
||||
|
||||
};
|
||||
|
@ -0,0 +1,128 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2016- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicEditIntersectionBoxEventFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RicBoxManipulatorEventHandler.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RimIntersectionBox.h"
|
||||
#include "RimView.h"
|
||||
|
||||
|
||||
#include "RiuViewer.h"
|
||||
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicEditIntersectionBoxEventFeature, "RicEditIntersectionBoxEventFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicEditIntersectionBoxEventFeature::RicEditIntersectionBoxEventFeature()
|
||||
: m_eventHandler(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxEventFeature::updateGeometry()
|
||||
{
|
||||
RimView* activeView = RiaApplication::instance()->activeReservoirView();
|
||||
if (activeView && activeView->viewer())
|
||||
{
|
||||
activeView->viewer()->addStaticModelOnce(m_eventHandler->model());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicEditIntersectionBoxEventFeature::isCommandEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxEventFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
RiuViewer* viewer = nullptr;
|
||||
|
||||
RimView* activeView = RiaApplication::instance()->activeReservoirView();
|
||||
if (activeView && activeView->viewer())
|
||||
{
|
||||
viewer = activeView->viewer();
|
||||
}
|
||||
|
||||
if (isCommandChecked() && m_eventHandler)
|
||||
{
|
||||
if (viewer)
|
||||
{
|
||||
viewer->removeEventFilter(m_eventHandler);
|
||||
viewer->removeStaticModel(m_eventHandler->model());
|
||||
}
|
||||
|
||||
m_eventHandler->deleteLater();
|
||||
m_eventHandler = nullptr;
|
||||
}
|
||||
else if (viewer)
|
||||
{
|
||||
RimIntersectionBox* intersectionBox = dynamic_cast<RimIntersectionBox*>(viewer->lastPickedObject());
|
||||
if (intersectionBox)
|
||||
{
|
||||
m_eventHandler = new RicBoxManipulatorEventHandler(viewer);
|
||||
|
||||
cvf::Mat4d myMat = cvf::Mat4d::fromRotation(cvf::Vec3d::X_AXIS, 0.0);
|
||||
myMat.setTranslation(intersectionBox->boxOrigin().translation());
|
||||
m_eventHandler->setOrigin(myMat);
|
||||
|
||||
m_eventHandler->setSize(intersectionBox->boxSize());
|
||||
m_eventHandler->setScaleZ(activeView->scaleZ());
|
||||
|
||||
RimCase* rimCase = activeView->ownerCase();
|
||||
m_eventHandler->setDisplayModelOffset(rimCase->displayModelOffset());
|
||||
|
||||
viewer->installEventFilter(m_eventHandler);
|
||||
connect(m_eventHandler, SIGNAL(geometryUpdated()), this, SLOT(updateGeometry()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxEventFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/IntersectionBox16x16.png"));
|
||||
actionToSetup->setText("Edit Intersection Box (event handler)");
|
||||
actionToSetup->setCheckable(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicEditIntersectionBoxEventFeature::isCommandChecked()
|
||||
{
|
||||
return m_eventHandler != NULL;
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2016- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
|
||||
|
||||
class RicBoxManipulatorEventHandler;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicEditIntersectionBoxEventFeature : public caf::CmdFeature
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicEditIntersectionBoxEventFeature();
|
||||
|
||||
public slots:
|
||||
void updateGeometry();
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
virtual bool isCommandEnabled() override;
|
||||
virtual void onActionTriggered( bool isChecked ) override;
|
||||
virtual void setupActionLook( QAction* actionToSetup ) override;
|
||||
virtual bool isCommandChecked() override;
|
||||
|
||||
private:
|
||||
RicBoxManipulatorEventHandler* m_eventHandler;
|
||||
};
|
||||
|
@ -0,0 +1,119 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2016- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicEditIntersectionBoxFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RimIntersectionBox.h"
|
||||
#include "RimView.h"
|
||||
|
||||
#include "RiuViewer.h"
|
||||
|
||||
#include "cafBoxManipulatorGeometryGenerator.h"
|
||||
#include "cafEffectGenerator.h"
|
||||
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
#include "cvfPart.h"
|
||||
#include "cvfTransform.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicEditIntersectionBoxFeature, "RicEditIntersectionBoxFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicEditIntersectionBoxFeature::isCommandEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
RiuViewer* viewer = nullptr;
|
||||
|
||||
RimView* activeView = RiaApplication::instance()->activeReservoirView();
|
||||
if (activeView && activeView->viewer())
|
||||
{
|
||||
viewer = activeView->viewer();
|
||||
}
|
||||
|
||||
if (isCommandChecked() && m_model.notNull())
|
||||
{
|
||||
if (viewer) viewer->removeStaticModel(m_model.p());
|
||||
m_model = nullptr;
|
||||
}
|
||||
else if (viewer)
|
||||
{
|
||||
RimIntersectionBox* intersectionBox = dynamic_cast<RimIntersectionBox*>(viewer->lastPickedObject());
|
||||
if (intersectionBox)
|
||||
{
|
||||
caf::BoxManipulatorGeometryGenerator boxGen;
|
||||
|
||||
// TODO: boxGen operates in display coordinates, conversion is missing
|
||||
boxGen.setOrigin(intersectionBox->boxOrigin());
|
||||
boxGen.setSize(intersectionBox->boxSize());
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geoMesh = boxGen.createBoundingBoxMeshDrawable();
|
||||
if (geoMesh.notNull())
|
||||
{
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Cross Section mesh");
|
||||
part->setDrawable(geoMesh.p());
|
||||
|
||||
part->updateBoundingBox();
|
||||
// part->setEnableMask(meshFaultBit);
|
||||
// part->setPriority(priMesh);
|
||||
|
||||
cvf::ref<cvf::Effect> eff;
|
||||
caf::MeshEffectGenerator CrossSectionEffGen(cvf::Color3::WHITE);
|
||||
eff = CrossSectionEffGen.generateCachedEffect();
|
||||
part->setEffect(eff.p());
|
||||
|
||||
m_model = new cvf::ModelBasicList;
|
||||
m_model->addPart(part.p());
|
||||
viewer->addStaticModelOnce(m_model.p());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/IntersectionBox16x16.png"));
|
||||
actionToSetup->setText("Edit Intersection Box");
|
||||
actionToSetup->setCheckable(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicEditIntersectionBoxFeature::isCommandChecked()
|
||||
{
|
||||
return m_model.notNull();
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2016- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "cafCmdExecuteCommand.h"
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
|
||||
namespace caf {
|
||||
class BoxManipulatorGeometryGenerator;
|
||||
};
|
||||
|
||||
namespace cvf {
|
||||
class ModelBasicList;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicEditIntersectionBoxFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
virtual bool isCommandEnabled() override;
|
||||
virtual void onActionTriggered( bool isChecked ) override;
|
||||
virtual void setupActionLook( QAction* actionToSetup ) override;
|
||||
virtual bool isCommandChecked() override;
|
||||
|
||||
private:
|
||||
// cvf::ref<caf::BoxManipulatorGeometryGenerator> m_boxManipulatorGeometryGenerator;
|
||||
cvf::ref<cvf::ModelBasicList> m_model;
|
||||
};
|
||||
|
@ -40,3 +40,11 @@ const std::vector<size_t>& RivIntersectionBoxSourceInfo::triangleToCellIndex() c
|
||||
return m_intersectionBoxGeometryGenerator->triangleToCellIndex();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const RimIntersectionBox* RivIntersectionBoxSourceInfo::intersectionBox() const
|
||||
{
|
||||
return m_intersectionBoxGeometryGenerator->intersectionBox();
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,8 @@ public:
|
||||
|
||||
const std::vector<size_t>& triangleToCellIndex() const;
|
||||
|
||||
const RimIntersectionBox* intersectionBox() const;
|
||||
|
||||
private:
|
||||
cvf::cref<RivIntersectionBoxGeometryGenerator> m_intersectionBoxGeometryGenerator;
|
||||
};
|
||||
|
@ -699,6 +699,16 @@ cvf::Vec3d RiuViewer::lastPickPositionInDomainCoords() const
|
||||
return m_viewerCommands->lastPickPositionInDomainCoords();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObject* RiuViewer::lastPickedObject() const
|
||||
{
|
||||
CVF_ASSERT(m_viewerCommands);
|
||||
|
||||
return m_viewerCommands->currentPickedObject();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -90,6 +90,7 @@ public:
|
||||
void setAxisLabels(const cvf::String& xLabel, const cvf::String& yLabel, const cvf::String& zLabel);
|
||||
|
||||
cvf::Vec3d lastPickPositionInDomainCoords() const;
|
||||
caf::PdmObject* lastPickedObject() const;
|
||||
|
||||
public slots:
|
||||
virtual void slotSetCurrentFrame(int frameIndex);
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "RimGeoMechCase.h"
|
||||
#include "RimGeoMechCellColors.h"
|
||||
#include "RimGeoMechView.h"
|
||||
#include "RimIntersectionBox.h"
|
||||
#include "RimLegendConfig.h"
|
||||
#include "RimTernaryLegendConfig.h"
|
||||
#include "RimViewController.h"
|
||||
@ -133,6 +134,7 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
|
||||
{
|
||||
m_currentGridIdx = cvf::UNDEFINED_SIZE_T;
|
||||
m_currentCellIndex = cvf::UNDEFINED_SIZE_T;
|
||||
m_currentPickedObject = nullptr;
|
||||
|
||||
int winPosX = event->x();
|
||||
int winPosY = event->y();
|
||||
@ -195,7 +197,7 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
|
||||
{
|
||||
findCellAndGridIndex(crossSectionSourceInfo, firstPartTriangleIndex, &m_currentCellIndex, &m_currentGridIdx);
|
||||
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
|
||||
m_currentCrossSection = const_cast<RimIntersection*>(crossSectionSourceInfo->crossSection());
|
||||
m_currentPickedObject = const_cast<RimIntersection*>(crossSectionSourceInfo->crossSection());
|
||||
|
||||
menu.addAction(QString("Hide intersection"), this, SLOT(slotHideIntersection()));
|
||||
}
|
||||
@ -203,6 +205,16 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
|
||||
{
|
||||
findCellAndGridIndex(intersectionBoxSourceInfo, firstPartTriangleIndex, &m_currentCellIndex, &m_currentGridIdx);
|
||||
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
|
||||
|
||||
m_currentPickedObject = const_cast<RimIntersectionBox*>(intersectionBoxSourceInfo->intersectionBox());
|
||||
menu.addAction(caf::CmdFeatureManager::instance()->action("RicEditIntersectionBoxFeature"));
|
||||
menu.addAction(caf::CmdFeatureManager::instance()->action("RicEditIntersectionBoxEventFeature"));
|
||||
menu.addSeparator();
|
||||
|
||||
QStringList commandIdList;
|
||||
commandIdList << "RicEditIntersectionBoxFeature";
|
||||
commandIdList << "RicEditIntersectionBoxEventFeature";
|
||||
caf::CmdFeatureManager::instance()->refreshCheckedState(commandIdList);
|
||||
}
|
||||
|
||||
// IJK -slice commands
|
||||
@ -442,10 +454,11 @@ void RiuViewerCommands::slotAddGeoMechPropertyFilter()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuViewerCommands::slotHideIntersection()
|
||||
{
|
||||
if (m_currentCrossSection)
|
||||
RimIntersection* rimIntersection = dynamic_cast<RimIntersection*>(currentPickedObject());
|
||||
if (rimIntersection)
|
||||
{
|
||||
m_currentCrossSection->isActive = false;
|
||||
m_currentCrossSection->updateConnectedEditors();
|
||||
rimIntersection->isActive = false;
|
||||
rimIntersection->updateConnectedEditors();
|
||||
|
||||
if (m_reservoirView)
|
||||
{
|
||||
@ -591,6 +604,14 @@ cvf::Vec3d RiuViewerCommands::lastPickPositionInDomainCoords() const
|
||||
return m_currentPickPositionInDomainCoords;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObject* RiuViewerCommands::currentPickedObject() const
|
||||
{
|
||||
return m_currentPickedObject;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -36,6 +36,10 @@ class RivIntersectionSourceInfo;
|
||||
|
||||
class QMouseEvent;
|
||||
|
||||
namespace caf {
|
||||
class PdmObject;
|
||||
}
|
||||
|
||||
namespace cvf {
|
||||
class HitItemCollection;
|
||||
class Part;
|
||||
@ -55,6 +59,8 @@ public:
|
||||
void handlePickAction(int winPosX, int winPosY, Qt::KeyboardModifiers keyboardModifiers);
|
||||
cvf::Vec3d lastPickPositionInDomainCoords() const;
|
||||
|
||||
caf::PdmObject* currentPickedObject() const;
|
||||
|
||||
private slots:
|
||||
void slotRangeFilterI();
|
||||
void slotRangeFilterJ();
|
||||
@ -80,7 +86,7 @@ private:
|
||||
cvf::Vec3d m_currentPickPositionInDomainCoords;
|
||||
|
||||
caf::PdmPointer<RimView> m_reservoirView;
|
||||
caf::PdmPointer<RimIntersection> m_currentCrossSection;
|
||||
caf::PdmPointer<caf::PdmObject> m_currentPickedObject;
|
||||
|
||||
QPointer<RiuViewer> m_viewer;
|
||||
|
||||
|
@ -15,6 +15,10 @@ include_directories(
|
||||
)
|
||||
|
||||
add_library( ${PROJECT_NAME}
|
||||
cafBoxManipulatorPartManager.cpp
|
||||
cafBoxManipulatorPartManager.h
|
||||
cafBoxManipulatorGeometryGenerator.cpp
|
||||
cafBoxManipulatorGeometryGenerator.h
|
||||
cafCategoryLegend.cpp
|
||||
cafCategoryLegend.h
|
||||
cafCategoryMapper.cpp
|
||||
|
@ -0,0 +1,125 @@
|
||||
|
||||
#include "cafBoxManipulatorGeometryGenerator.h"
|
||||
|
||||
#include "cvfBoxGenerator.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfGeometryBuilderFaceList.h"
|
||||
#include "cvfPrimitiveSetIndexedUInt.h"
|
||||
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
namespace caf {
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
BoxManipulatorGeometryGenerator::BoxManipulatorGeometryGenerator()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
BoxManipulatorGeometryGenerator::~BoxManipulatorGeometryGenerator()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorGeometryGenerator::setOrigin(const cvf::Mat4d& origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
|
||||
m_vertices = nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorGeometryGenerator::setSize(const cvf::Vec3d& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
m_vertices = nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> BoxManipulatorGeometryGenerator::createBoundingBoxMeshDrawable()
|
||||
{
|
||||
if (m_vertices.isNull())
|
||||
{
|
||||
calculateArrays();
|
||||
}
|
||||
|
||||
if (!(m_vertices.notNull() && m_vertices->size() != 0)) return NULL;
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;
|
||||
geo->setVertexArray(m_vertices.p());
|
||||
|
||||
cvf::ref<cvf::UIntArray> indices = lineIndicesFromQuadVertexArray(m_vertices.p());
|
||||
cvf::ref<cvf::PrimitiveSetIndexedUInt> prim = new cvf::PrimitiveSetIndexedUInt(cvf::PT_LINES);
|
||||
prim->setIndices(indices.p());
|
||||
|
||||
geo->addPrimitiveSet(prim.p());
|
||||
|
||||
return geo;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorGeometryGenerator::calculateArrays()
|
||||
{
|
||||
BoxGenerator gen;
|
||||
|
||||
cvf::Vec3d min = m_origin.translation();
|
||||
cvf::Vec3d max = m_origin.translation() + m_size;
|
||||
|
||||
gen.setMinMax(min, max);
|
||||
gen.setSubdivisions(1, 1, 1);
|
||||
GeometryBuilderFaceList builder;
|
||||
gen.generate(&builder);
|
||||
|
||||
m_vertices = builder.vertices();
|
||||
|
||||
// TODO: Rotate generated vertices
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::UIntArray> BoxManipulatorGeometryGenerator::lineIndicesFromQuadVertexArray(const cvf::Vec3fArray* vertexArray)
|
||||
{
|
||||
CVF_ASSERT(vertexArray);
|
||||
|
||||
size_t numVertices = vertexArray->size();
|
||||
int numQuads = static_cast<int>(numVertices / 4);
|
||||
CVF_ASSERT(numVertices % 4 == 0);
|
||||
|
||||
cvf::ref<cvf::UIntArray> indices = new cvf::UIntArray;
|
||||
indices->resize(numQuads * 8);
|
||||
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < numQuads; i++)
|
||||
{
|
||||
int idx = 8 * i;
|
||||
indices->set(idx + 0, i * 4 + 0);
|
||||
indices->set(idx + 1, i * 4 + 1);
|
||||
indices->set(idx + 2, i * 4 + 1);
|
||||
indices->set(idx + 3, i * 4 + 2);
|
||||
indices->set(idx + 4, i * 4 + 2);
|
||||
indices->set(idx + 5, i * 4 + 3);
|
||||
indices->set(idx + 6, i * 4 + 3);
|
||||
indices->set(idx + 7, i * 4 + 0);
|
||||
}
|
||||
|
||||
return indices;
|
||||
}
|
||||
|
||||
} // namespace cvf
|
||||
|
@ -0,0 +1,45 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfVector3.h"
|
||||
#include "cvfArray.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
|
||||
namespace cvf {
|
||||
class DrawableGeo;
|
||||
}
|
||||
|
||||
|
||||
namespace caf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class BoxManipulatorGeometryGenerator : public cvf::Object
|
||||
{
|
||||
public:
|
||||
BoxManipulatorGeometryGenerator();
|
||||
~BoxManipulatorGeometryGenerator();
|
||||
|
||||
void setOrigin(const cvf::Mat4d& origin);
|
||||
void setSize(const cvf::Vec3d& size);
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> createBoundingBoxMeshDrawable();
|
||||
|
||||
private:
|
||||
void calculateArrays();
|
||||
|
||||
static cvf::ref<cvf::UIntArray> lineIndicesFromQuadVertexArray(const cvf::Vec3fArray* vertexArray);
|
||||
|
||||
private:
|
||||
cvf::Mat4d m_origin;
|
||||
cvf::Vec3d m_size;
|
||||
|
||||
cvf::ref<cvf::Vec3fArray> m_vertices;
|
||||
};
|
||||
|
||||
}
|
336
Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp
Normal file
336
Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp
Normal file
@ -0,0 +1,336 @@
|
||||
|
||||
#include "cafBoxManipulatorPartManager.h"
|
||||
|
||||
#include "cvfBoxGenerator.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfGeometryBuilderFaceList.h"
|
||||
#include "cvfPart.h"
|
||||
#include "cvfPrimitiveSetIndexedUInt.h"
|
||||
#include "cvfPrimitiveSetIndexedUShort.h"
|
||||
#include "cafBoxManipulatorGeometryGenerator.h"
|
||||
#include "cafEffectGenerator.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
namespace caf {
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
BoxManipulatorPartManager::BoxManipulatorPartManager()
|
||||
{
|
||||
m_geometryGenerator = new caf::BoxManipulatorGeometryGenerator;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::setOrigin(const cvf::Mat4d& origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
|
||||
m_geometryGenerator->setOrigin(origin);
|
||||
|
||||
clearAllGeometryAndParts();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::setSize(const cvf::Vec3d& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
m_geometryGenerator->setSize(size);
|
||||
|
||||
clearAllGeometryAndParts();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::appendPartsToModel(cvf::ModelBasicList* model)
|
||||
{
|
||||
if (m_boundingBoxPart.isNull())
|
||||
{
|
||||
recreateAllGeometryAndParts();
|
||||
}
|
||||
|
||||
CVF_ASSERT(m_boundingBoxPart.notNull());
|
||||
model->addPart(m_boundingBoxPart.p());
|
||||
|
||||
for (size_t i = 0; i < m_cubeParts.size(); i++)
|
||||
{
|
||||
model->addPart(m_cubeParts.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t BoxManipulatorPartManager::partIndexFromSourceInfo(cvf::Part* candidatePart)
|
||||
{
|
||||
if (!candidatePart) return cvf::UNDEFINED_SIZE_T;
|
||||
|
||||
BoxManipulatorSourceInfo* candidateSourceInfo = dynamic_cast<BoxManipulatorSourceInfo*>(candidatePart->sourceInfo());
|
||||
if (!candidateSourceInfo) return cvf::UNDEFINED_SIZE_T;
|
||||
|
||||
for (size_t i = 0; i < m_cubeParts.size(); i++)
|
||||
{
|
||||
cvf::Part* part = m_cubeParts.at(i);
|
||||
BoxManipulatorSourceInfo* si = static_cast<BoxManipulatorSourceInfo*>(part->sourceInfo());
|
||||
|
||||
if (si->m_cubeFace == candidateSourceInfo->m_cubeFace &&
|
||||
si->m_cubeFaceItem == candidateSourceInfo->m_cubeFaceItem)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return cvf::UNDEFINED_SIZE_T;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::createCubeGeos()
|
||||
{
|
||||
Vec3f cp[8];
|
||||
navCubeCornerPoints(cp);
|
||||
|
||||
createCubeFaceGeos(NCF_Y_NEG, cp[0], cp[1], cp[5], cp[4]);
|
||||
createCubeFaceGeos(NCF_Y_POS, cp[2], cp[3], cp[7], cp[6]);
|
||||
|
||||
createCubeFaceGeos(NCF_Z_POS, cp[4], cp[5], cp[6], cp[7]);
|
||||
createCubeFaceGeos(NCF_Z_NEG, cp[3], cp[2], cp[1], cp[0]);
|
||||
|
||||
createCubeFaceGeos(NCF_X_NEG, cp[3], cp[0], cp[4], cp[7]);
|
||||
createCubeFaceGeos(NCF_X_POS, cp[1], cp[2], cp[6], cp[5]);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::createCubeFaceGeos(NavCubeFace face, cvf::Vec3f p1, cvf::Vec3f p2, cvf::Vec3f p3, cvf::Vec3f p4)
|
||||
{
|
||||
Vec2f t1(0, 0);
|
||||
Vec2f t2(1, 0);
|
||||
Vec2f t3(1, 1);
|
||||
Vec2f t4(0, 1);
|
||||
|
||||
float fCornerFactor = 0.175f;
|
||||
float fOneMinusCF = 1.0f - fCornerFactor;
|
||||
Vec3f p12 = p1 + (p2 - p1)*fCornerFactor; Vec2f t12(fCornerFactor, 0);
|
||||
Vec3f p14 = p1 + (p4 - p1)*fCornerFactor; Vec2f t14(0, fCornerFactor);
|
||||
Vec3f pi1 = p1 + (p12 - p1) + (p14 - p1); Vec2f ti1(fCornerFactor, fCornerFactor);
|
||||
|
||||
Vec3f p21 = p2 + (p1 - p2)*fCornerFactor; Vec2f t21(fOneMinusCF, 0);
|
||||
Vec3f p23 = p2 + (p3 - p2)*fCornerFactor; Vec2f t23(1.0, fCornerFactor);
|
||||
Vec3f pi2 = p2 + (p21 - p2) + (p23 - p2); Vec2f ti2(fOneMinusCF, fCornerFactor);
|
||||
|
||||
Vec3f p32 = p3 + (p2 - p3)*fCornerFactor; Vec2f t32(1.0, fOneMinusCF);
|
||||
Vec3f p34 = p3 + (p4 - p3)*fCornerFactor; Vec2f t34(fOneMinusCF, 1.0);
|
||||
Vec3f pi3 = p3 + (p32 - p3) + (p34 - p3); Vec2f ti3(fOneMinusCF, fOneMinusCF);
|
||||
|
||||
Vec3f p41 = p4 + (p1 - p4)*fCornerFactor; Vec2f t41(0, fOneMinusCF);
|
||||
Vec3f p43 = p4 + (p3 - p4)*fCornerFactor; Vec2f t43(fCornerFactor, 1.0);
|
||||
Vec3f pi4 = p4 + (p41 - p4) + (p43 - p4); Vec2f ti4(fCornerFactor, fOneMinusCF);
|
||||
|
||||
/*
|
||||
// Bottom left
|
||||
m_cubeItemType.push_back(navCubeItem(face, NCFI_BOTTOM_LEFT));
|
||||
m_cubeGeoFace.push_back(face);
|
||||
m_cubeGeos.push_back(createQuadGeo(p1, p12, pi1, p14, t1, t12, ti1, t14).p());
|
||||
|
||||
// Bottom right
|
||||
m_cubeItemType.push_back(navCubeItem(face, NCFI_BOTTOM_RIGHT));
|
||||
m_cubeGeoFace.push_back(face);
|
||||
m_cubeGeos.push_back(createQuadGeo(p2, p23, pi2, p21, t2, t23, ti2, t21).p());
|
||||
|
||||
// Top right
|
||||
m_cubeItemType.push_back(navCubeItem(face, NCFI_TOP_RIGHT));
|
||||
m_cubeGeoFace.push_back(face);
|
||||
m_cubeGeos.push_back(createQuadGeo(p3, p34, pi3, p32, t3, t34, ti3, t32).p());
|
||||
|
||||
// Top left
|
||||
m_cubeItemType.push_back(navCubeItem(face, NCFI_TOP_LEFT));
|
||||
m_cubeGeoFace.push_back(face);
|
||||
m_cubeGeos.push_back(createQuadGeo(p4, p41, pi4, p43, t4, t41, ti4, t43).p());
|
||||
|
||||
// Bottom
|
||||
m_cubeItemType.push_back(navCubeItem(face, NCFI_BOTTOM));
|
||||
m_cubeGeoFace.push_back(face);
|
||||
m_cubeGeos.push_back(createQuadGeo(p12, p21, pi2, pi1, t12, t21, ti2, ti1).p());
|
||||
|
||||
// Top
|
||||
m_cubeItemType.push_back(navCubeItem(face, NCFI_TOP));
|
||||
m_cubeGeoFace.push_back(face);
|
||||
m_cubeGeos.push_back(createQuadGeo(p34, p43, pi4, pi3, t34, t43, ti4, ti3).p());
|
||||
|
||||
// Right
|
||||
m_cubeItemType.push_back(navCubeItem(face, NCFI_RIGHT));
|
||||
m_cubeGeoFace.push_back(face);
|
||||
m_cubeGeos.push_back(createQuadGeo(p23, p32, pi3, pi2, t23, t32, ti3, ti2).p());
|
||||
|
||||
// Left
|
||||
m_cubeItemType.push_back(navCubeItem(face, NCFI_LEFT));
|
||||
m_cubeGeoFace.push_back(face);
|
||||
m_cubeGeos.push_back(createQuadGeo(p41, p14, pi1, pi4, t41, t14, ti1, ti4).p());
|
||||
*/
|
||||
|
||||
// Inner part
|
||||
m_cubeItemType.push_back(navCubeItem(face, NCFI_CENTER));
|
||||
m_cubeGeoFace.push_back(face);
|
||||
m_cubeGeos.push_back(createQuadGeo(pi1, pi2, pi3, pi4, ti1, ti2, ti3, ti4).p());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> BoxManipulatorPartManager::createQuadGeo(const cvf::Vec3f& v1, const cvf::Vec3f& v2, const cvf::Vec3f& v3, const cvf::Vec3f& v4, const cvf::Vec2f& t1, const cvf::Vec2f& t2, const cvf::Vec2f& t3, const cvf::Vec2f& t4)
|
||||
{
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
|
||||
ref<Vec3fArray> vertexArray = new Vec3fArray(4);
|
||||
vertexArray->set(0, v1);
|
||||
vertexArray->set(1, v2);
|
||||
vertexArray->set(2, v3);
|
||||
vertexArray->set(3, v4);
|
||||
|
||||
ref<Vec2fArray> textureCoordArray = new Vec2fArray(4);
|
||||
textureCoordArray->set(0, t1);
|
||||
textureCoordArray->set(1, t2);
|
||||
textureCoordArray->set(2, t3);
|
||||
textureCoordArray->set(3, t4);
|
||||
|
||||
geo->setVertexArray(vertexArray.p());
|
||||
geo->setTextureCoordArray(textureCoordArray.p());
|
||||
|
||||
ref<cvf::UShortArray> indices = new cvf::UShortArray(6);
|
||||
indices->set(0, 0);
|
||||
indices->set(1, 1);
|
||||
indices->set(2, 2);
|
||||
indices->set(3, 0);
|
||||
indices->set(4, 2);
|
||||
indices->set(5, 3);
|
||||
|
||||
ref<cvf::PrimitiveSetIndexedUShort> primSet = new cvf::PrimitiveSetIndexedUShort(cvf::PT_TRIANGLES);
|
||||
primSet->setIndices(indices.p());
|
||||
geo->addPrimitiveSet(primSet.p());
|
||||
geo->computeNormals();
|
||||
|
||||
return geo;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::navCubeCornerPoints(cvf::Vec3f points[8])
|
||||
{
|
||||
Vec3f min(m_origin.translation());
|
||||
Vec3f max(m_origin.translation() + m_size);
|
||||
|
||||
points[0].set(min.x(), min.y(), min.z());
|
||||
points[1].set(max.x(), min.y(), min.z());
|
||||
points[2].set(max.x(), max.y(), min.z());
|
||||
points[3].set(min.x(), max.y(), min.z());
|
||||
points[4].set(min.x(), min.y(), max.z());
|
||||
points[5].set(max.x(), min.y(), max.z());
|
||||
points[6].set(max.x(), max.y(), max.z());
|
||||
points[7].set(min.x(), max.y(), max.z());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<BoxManipulatorPartManager::NavCubeFace, BoxManipulatorPartManager::NavCubeFaceItem> BoxManipulatorPartManager::navCubeItem(NavCubeFace face, NavCubeFaceItem faceItem) const
|
||||
{
|
||||
return std::make_pair(face, faceItem);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::clearAllGeometryAndParts()
|
||||
{
|
||||
m_boundingBoxPart = nullptr;
|
||||
m_cubeGeos.clear();
|
||||
m_cubeGeoFace.clear();
|
||||
m_cubeItemType.clear();
|
||||
m_cubeParts.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::recreateAllGeometryAndParts()
|
||||
{
|
||||
createBoundingBoxPart();
|
||||
createCubeGeos();
|
||||
createCubeParts();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::createBoundingBoxPart()
|
||||
{
|
||||
m_boundingBoxPart = nullptr;
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geoMesh = m_geometryGenerator->createBoundingBoxMeshDrawable();
|
||||
if (geoMesh.notNull())
|
||||
{
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Box Manipulator Mesh");
|
||||
part->setDrawable(geoMesh.p());
|
||||
|
||||
part->updateBoundingBox();
|
||||
// part->setEnableMask(meshFaultBit);
|
||||
// part->setPriority(priMesh);
|
||||
|
||||
cvf::ref<cvf::Effect> eff;
|
||||
caf::MeshEffectGenerator effectGenerator(cvf::Color3::WHITE);
|
||||
eff = effectGenerator.generateCachedEffect();
|
||||
part->setEffect(eff.p());
|
||||
|
||||
m_boundingBoxPart = part;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::createCubeParts()
|
||||
{
|
||||
for (size_t i = 0; i < m_cubeGeos.size(); i++)
|
||||
{
|
||||
cvf::DrawableGeo* geoMesh = m_cubeGeos.at(i);
|
||||
if (geoMesh)
|
||||
{
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Box Manipulator Mesh");
|
||||
part->setDrawable(geoMesh);
|
||||
|
||||
part->updateBoundingBox();
|
||||
// part->setEnableMask(meshFaultBit);
|
||||
// part->setPriority(priMesh);
|
||||
|
||||
|
||||
caf::SurfaceEffectGenerator surfaceGen(cvf::Color3::GREEN, caf::PO_1);
|
||||
cvf::ref<cvf::Effect> eff = surfaceGen.generateCachedEffect();
|
||||
part->setEffect(eff.p());
|
||||
|
||||
auto pair = m_cubeItemType[i];
|
||||
BoxManipulatorSourceInfo* sourceInfo = new BoxManipulatorSourceInfo(pair.first, pair.second);
|
||||
part->setSourceInfo(sourceInfo);
|
||||
|
||||
m_cubeParts.push_back(part.p());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cvf
|
||||
|
163
Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h
Normal file
163
Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h
Normal file
@ -0,0 +1,163 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
#include "cvfVector3.h"
|
||||
#include "cvfCollection.h"
|
||||
#include "cvfMatrix4.h"
|
||||
/*
|
||||
#include "cvfArray.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
|
||||
*/
|
||||
namespace cvf {
|
||||
class ModelBasicList;
|
||||
class Part;
|
||||
class DrawableGeo;
|
||||
}
|
||||
|
||||
namespace caf {
|
||||
class BoxManipulatorGeometryGenerator;
|
||||
};
|
||||
|
||||
|
||||
namespace caf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class BoxManipulatorPartManager : public cvf::Object
|
||||
{
|
||||
public:
|
||||
enum NavCubeFace
|
||||
{
|
||||
NCF_X_POS,
|
||||
NCF_X_NEG,
|
||||
NCF_Y_POS,
|
||||
NCF_Y_NEG,
|
||||
NCF_Z_POS,
|
||||
NCF_Z_NEG
|
||||
};
|
||||
|
||||
enum NavCubeFaceItem
|
||||
{
|
||||
NCFI_NONE,
|
||||
NCFI_CENTER,
|
||||
NCFI_BOTTOM_LEFT,
|
||||
NCFI_BOTTOM,
|
||||
NCFI_BOTTOM_RIGHT,
|
||||
NCFI_RIGHT,
|
||||
NCFI_TOP_RIGHT,
|
||||
NCFI_TOP,
|
||||
NCFI_TOP_LEFT,
|
||||
NCFI_LEFT
|
||||
};
|
||||
|
||||
enum NavCubeItem
|
||||
{
|
||||
NCI_NONE,
|
||||
|
||||
NCI_CORNER_XN_YN_ZN,
|
||||
NCI_CORNER_XP_YN_ZN,
|
||||
NCI_CORNER_XP_YP_ZN,
|
||||
NCI_CORNER_XN_YP_ZN,
|
||||
NCI_CORNER_XN_YN_ZP,
|
||||
NCI_CORNER_XP_YN_ZP,
|
||||
NCI_CORNER_XP_YP_ZP,
|
||||
NCI_CORNER_XN_YP_ZP,
|
||||
|
||||
NCI_EDGE_YN_ZN,
|
||||
NCI_EDGE_XP_ZN,
|
||||
NCI_EDGE_YP_ZN,
|
||||
NCI_EDGE_XN_ZN,
|
||||
NCI_EDGE_YN_ZP,
|
||||
NCI_EDGE_XP_ZP,
|
||||
NCI_EDGE_YP_ZP,
|
||||
NCI_EDGE_XN_ZP,
|
||||
NCI_EDGE_XN_YN,
|
||||
NCI_EDGE_XP_YN,
|
||||
NCI_EDGE_XP_YP,
|
||||
NCI_EDGE_XN_YP,
|
||||
|
||||
NCI_FACE_X_POS,
|
||||
NCI_FACE_X_NEG,
|
||||
NCI_FACE_Y_POS,
|
||||
NCI_FACE_Y_NEG,
|
||||
NCI_FACE_Z_POS,
|
||||
NCI_FACE_Z_NEG,
|
||||
|
||||
NCI_ARROW_LEFT,
|
||||
NCI_ARROW_RIGHT,
|
||||
NCI_ARROW_TOP,
|
||||
NCI_ARROW_BOTTOM,
|
||||
NCI_HOME,
|
||||
NCI_ROTATE_CW,
|
||||
NCI_ROTATE_CCW
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
BoxManipulatorPartManager();
|
||||
|
||||
void setOrigin(const cvf::Mat4d& origin);
|
||||
void setSize(const cvf::Vec3d& size);
|
||||
|
||||
void appendPartsToModel(cvf::ModelBasicList* model);
|
||||
|
||||
size_t partIndexFromSourceInfo(cvf::Part* part);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
void createCubeGeos();
|
||||
void createCubeFaceGeos(NavCubeFace face, cvf::Vec3f p1, cvf::Vec3f p2, cvf::Vec3f p3, cvf::Vec3f p4);
|
||||
cvf::ref<cvf::DrawableGeo> createQuadGeo(const cvf::Vec3f& v1, const cvf::Vec3f& v2, const cvf::Vec3f& v3, const cvf::Vec3f& v4, const cvf::Vec2f& t1, const cvf::Vec2f& t2, const cvf::Vec2f& t3, const cvf::Vec2f& t4);
|
||||
void navCubeCornerPoints(cvf::Vec3f points[8]);
|
||||
|
||||
//NavCubeItem navCubeItem(NavCubeFace face, NavCubeFaceItem item) const;
|
||||
std::pair<NavCubeFace, NavCubeFaceItem> navCubeItem(NavCubeFace face, NavCubeFaceItem item) const;
|
||||
|
||||
void clearAllGeometryAndParts();
|
||||
void recreateAllGeometryAndParts();
|
||||
|
||||
void createBoundingBoxPart();
|
||||
void createCubeParts();
|
||||
|
||||
private:
|
||||
cvf::Collection<cvf::DrawableGeo> m_cubeGeos; // These arrays have the same length
|
||||
std::vector<NavCubeFace> m_cubeGeoFace; // These arrays have the same length
|
||||
std::vector< std::pair<NavCubeFace, NavCubeFaceItem> > m_cubeItemType; // These arrays have the same length
|
||||
|
||||
cvf::Collection<cvf::Part> m_cubeParts; // These arrays have the same length
|
||||
cvf::ref<cvf::Part> m_boundingBoxPart;
|
||||
|
||||
cvf::ref<caf::BoxManipulatorGeometryGenerator> m_geometryGenerator;
|
||||
|
||||
cvf::Mat4d m_origin;
|
||||
cvf::Vec3d m_size;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class BoxManipulatorSourceInfo : public cvf::Object
|
||||
{
|
||||
public:
|
||||
BoxManipulatorSourceInfo(BoxManipulatorPartManager::NavCubeFace cubeFace, BoxManipulatorPartManager::NavCubeFaceItem cubeFaceItem)
|
||||
: m_cubeFace(cubeFace),
|
||||
m_cubeFaceItem(cubeFaceItem)
|
||||
{
|
||||
}
|
||||
|
||||
BoxManipulatorPartManager::NavCubeFace m_cubeFace;
|
||||
BoxManipulatorPartManager::NavCubeFaceItem m_cubeFaceItem;
|
||||
};
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user