diff --git a/ApplicationCode/Commands/IntersectionBoxCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/IntersectionBoxCommands/CMakeLists_files.cmake index 28bf5b761b..7f3ae05eaf 100644 --- a/ApplicationCode/Commands/IntersectionBoxCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/IntersectionBoxCommands/CMakeLists_files.cmake @@ -7,7 +7,6 @@ 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 @@ -17,7 +16,6 @@ ${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 @@ -35,7 +33,7 @@ ${SOURCE_GROUP_SOURCE_FILES} set (QT_MOC_HEADERS ${QT_MOC_HEADERS} ${CEE_CURRENT_LIST_DIR}RicBoxManipulatorEventHandler.h -${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxEventFeature.h +${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxFeature.h ) diff --git a/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.cpp b/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.cpp index 32e5dbbb52..2d852e7875 100644 --- a/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.cpp +++ b/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.cpp @@ -1,17 +1,18 @@ #include "RicBoxManipulatorEventHandler.h" +#include "cafBoxManipulatorPartManager.h" +#include "cafEffectGenerator.h" +#include "cafViewer.h" + +#include "cvfCamera.h" +#include "cvfDrawableGeo.h" +#include "cvfHitItemCollection.h" #include "cvfModelBasicList.h" #include "cvfPart.h" -#include "cvfDrawableGeo.h" -#include "cafEffectGenerator.h" - - -#include "cvfHitItemCollection.h" - -#include "cafViewer.h" -#include "cafBoxManipulatorPartManager.h" +#include "cvfRay.h" +#include #include //-------------------------------------------------------------------------------------------------- @@ -19,11 +20,12 @@ //-------------------------------------------------------------------------------------------------- RicBoxManipulatorEventHandler::RicBoxManipulatorEventHandler(caf::Viewer* viewer) : m_viewer(viewer), - m_scaleZ(1.0), - m_isGeometryCreated(false) + m_currentPartIndex(cvf::UNDEFINED_SIZE_T) { m_partManager = new caf::BoxManipulatorPartManager; m_model = new cvf::ModelBasicList; + + m_viewer->installEventFilter(this); } //-------------------------------------------------------------------------------------------------- @@ -31,36 +33,21 @@ RicBoxManipulatorEventHandler::RicBoxManipulatorEventHandler(caf::Viewer* viewer //-------------------------------------------------------------------------------------------------- RicBoxManipulatorEventHandler::~RicBoxManipulatorEventHandler() { + m_viewer->removeEventFilter(this); + + // Make sure the model owned by this manipulator is not used anywhere else + CVF_ASSERT(m_model->refCount() == 1); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicBoxManipulatorEventHandler::setScaleZ(double scaleZ) +void RicBoxManipulatorEventHandler::setOrigin(const cvf::Vec3d& origin) { - m_scaleZ = scaleZ; + m_partManager->setOrigin(origin); - updatePartManagerCoords(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicBoxManipulatorEventHandler::setDisplayModelOffset(cvf::Vec3d offset) -{ - m_displayModelOffset = offset; - - updatePartManagerCoords(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicBoxManipulatorEventHandler::setOrigin(const cvf::Mat4d& origin) -{ - m_domainCoordOrigin = origin; - - updatePartManagerCoords(); + updateParts(); + emit notifyRedraw(); } //-------------------------------------------------------------------------------------------------- @@ -68,9 +55,10 @@ void RicBoxManipulatorEventHandler::setOrigin(const cvf::Mat4d& origin) //-------------------------------------------------------------------------------------------------- void RicBoxManipulatorEventHandler::setSize(const cvf::Vec3d& size) { - m_domainCoordSize = size; - - updatePartManagerCoords(); + m_partManager->setSize(size); + + updateParts(); + emit notifyRedraw(); } //-------------------------------------------------------------------------------------------------- @@ -86,93 +74,79 @@ cvf::Model* RicBoxManipulatorEventHandler::model() //-------------------------------------------------------------------------------------------------- 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(inputEvent); - cvf::HitItemCollection hitItems; - if (m_viewer->rayPick(mouseEvent->x(), mouseEvent->y(), &hitItems)) + if (mouseEvent->button() == Qt::LeftButton) { - // TODO: Test if the first hit item is part of the manipulator -/ * - if (hitItems.firstItem() && hitItems.firstItem()->part()) + cvf::HitItemCollection hitItems; + if (m_viewer->rayPick(mouseEvent->x(), mouseEvent->y(), &hitItems)) { - const cvf::Object* siConstObj = hitItems.firstItem()->part()->sourceInfo(); - cvf::Object* siObj = const_cast(siConstObj); - - caf::BoxManipulatorSourceInfo* sourceInfo = dynamic_cast(siObj); - if (sourceInfo) + if (hitItems.firstItem() && hitItems.firstItem()->part()) { + m_currentPartIndex = m_partManager->partIndexFromSourceInfo(hitItems.firstItem()->part(), hitItems.firstItem()->intersectionPoint()); + if (m_currentPartIndex != cvf::UNDEFINED_SIZE_T) + { + updateParts(); + emit notifyRedraw(); + + return true; + } } } -* / + } + } + else if (inputEvent->type() == QEvent::MouseMove) + { + if (m_currentPartIndex != cvf::UNDEFINED_SIZE_T) + { + QMouseEvent* mouseEvent = static_cast(inputEvent); - switch (inputEvent->type()) + //qDebug() << "Inside mouse move"; + //qDebug() << mouseEvent->pos(); + + int translatedMousePosX = mouseEvent->pos().x(); + int translatedMousePosY = m_viewer->height() - mouseEvent->pos().y(); + + cvf::ref ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY); { - case QEvent::MouseButtonPress: - mouseMoveEvent(static_cast(inputEvent)); - break; - case QEvent::MouseButtonRelease: - mouseReleaseEvent(static_cast(inputEvent)); - break; - case QEvent::MouseMove: - mouseMoveEvent(static_cast(inputEvent)); - break; + m_partManager->updateFromPartIndexAndRay(m_currentPartIndex, ray.p()); + + updateParts(); + + cvf::Vec3d origin; + cvf::Vec3d size; + m_partManager->originAndSize(&origin, &size); + + emit notifyUpdate(origin, size); + + emit notifyRedraw(); + + return true; } + } + } + else if (inputEvent->type() == QEvent::MouseButtonRelease) + { + if (m_currentPartIndex != cvf::UNDEFINED_SIZE_T) + { + m_currentPartIndex = cvf::UNDEFINED_SIZE_T; - updateParts(); + cvf::Vec3d origin; + cvf::Vec3d size; + m_partManager->originAndSize(&origin, &size); - emit geometryUpdated(); + emit notifyUpdate(origin, size); - inputEvent->setAccepted(true); return true; } } return false; -*/ } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicBoxManipulatorEventHandler::mouseMoveEvent(QMouseEvent* event) -{ - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicBoxManipulatorEventHandler::mousePressEvent(QMouseEvent* event) -{ - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicBoxManipulatorEventHandler::mouseReleaseEvent(QMouseEvent* event) -{ - -} //-------------------------------------------------------------------------------------------------- /// @@ -184,29 +158,3 @@ void RicBoxManipulatorEventHandler::updateParts() 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; -} diff --git a/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.h b/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.h index 01d02da06d..aeb233e602 100644 --- a/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.h +++ b/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.h @@ -36,45 +36,27 @@ public: RicBoxManipulatorEventHandler(caf::Viewer* viewer); ~RicBoxManipulatorEventHandler(); - void setScaleZ(double scaleZ); - void setDisplayModelOffset(cvf::Vec3d offset); - - void setOrigin(const cvf::Mat4d& origin); + void setOrigin(const cvf::Vec3d& origin); void setSize(const cvf::Vec3d& size); cvf::Model* model(); signals: - void geometryUpdated(); + void notifyRedraw(); + void notifyUpdate(const cvf::Vec3d& origin, const cvf::Vec3d& size); protected: - bool eventFilter(QObject *obj, QEvent *event); - - void mouseMoveEvent(QMouseEvent* event); - void mousePressEvent(QMouseEvent* event); - void mouseReleaseEvent(QMouseEvent* event); - + bool eventFilter(QObject *obj, QEvent *event); private: - void updateParts(); - - void updatePartManagerCoords(); - - cvf::Vec3d displayModelCoordFromDomainCoord(const cvf::Vec3d& domainCoord) const; + void updateParts(); private: + cvf::ref m_model; + QPointer m_viewer; + + size_t m_currentPartIndex; + cvf::ref m_partManager; - - cvf::ref m_model; - QPointer m_viewer; - - double m_scaleZ; - cvf::Vec3d m_displayModelOffset; - - cvf::Mat4d m_domainCoordOrigin; - cvf::Vec3d m_domainCoordSize; - - bool m_isGeometryCreated; - }; diff --git a/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxEventFeature.cpp b/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxEventFeature.cpp deleted file mode 100644 index d2fd8645d3..0000000000 --- a/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxEventFeature.cpp +++ /dev/null @@ -1,128 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// 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 -// 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 - -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(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; -} diff --git a/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxEventFeature.h b/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxEventFeature.h deleted file mode 100644 index 849b7b7c96..0000000000 --- a/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxEventFeature.h +++ /dev/null @@ -1,52 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// 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 -// 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; -}; - diff --git a/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxFeature.cpp b/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxFeature.cpp index b04b47bb12..bbc526194f 100644 --- a/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxFeature.cpp +++ b/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxFeature.cpp @@ -20,25 +20,63 @@ #include "RiaApplication.h" +#include "RicBoxManipulatorEventHandler.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 "cafDisplayCoordTransform.h" #include CAF_CMD_SOURCE_INIT(RicEditIntersectionBoxFeature, "RicEditIntersectionBoxFeature"); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicEditIntersectionBoxFeature::RicEditIntersectionBoxFeature() + : m_eventHandler(nullptr), + m_intersectionBox(nullptr) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicEditIntersectionBoxFeature::slotScheduleRedraw() +{ + RimView* activeView = RiaApplication::instance()->activeReservoirView(); + if (activeView && activeView->viewer()) + { + activeView->viewer()->addStaticModelOnce(m_eventHandler->model()); + + activeView->scheduleCreateDisplayModelAndRedraw(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicEditIntersectionBoxFeature::slotUpdateGeometry(const cvf::Vec3d& origin, const cvf::Vec3d& size) +{ + if (m_intersectionBox) + { + RimView* activeView = RiaApplication::instance()->activeReservoirView(); + if (activeView) + { + cvf::ref transForm = activeView->displayCoordTransform(); + + cvf::Vec3d domainOrigin = transForm->transformToDomainCoord(origin); + cvf::Vec3d domainSize = transForm->scaleToDomainSize(size); + + m_intersectionBox->setFromOriginAndSize(domainOrigin, domainSize); + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -60,42 +98,31 @@ void RicEditIntersectionBoxFeature::onActionTriggered(bool isChecked) viewer = activeView->viewer(); } - if (isCommandChecked() && m_model.notNull()) + if (isCommandChecked() && m_eventHandler) { - if (viewer) viewer->removeStaticModel(m_model.p()); - m_model = nullptr; + if (viewer) + { + viewer->removeStaticModel(m_eventHandler->model()); + } + + m_eventHandler->deleteLater(); + m_eventHandler = nullptr; + + m_intersectionBox = nullptr; } else if (viewer) { - RimIntersectionBox* intersectionBox = dynamic_cast(viewer->lastPickedObject()); - if (intersectionBox) + m_intersectionBox = dynamic_cast(viewer->lastPickedObject()); + if (m_intersectionBox) { - caf::BoxManipulatorGeometryGenerator boxGen; + m_eventHandler = new RicBoxManipulatorEventHandler(viewer); + connect(m_eventHandler, SIGNAL(notifyRedraw()), this, SLOT(slotScheduleRedraw())); + connect(m_eventHandler, SIGNAL(notifyUpdate(const cvf::Vec3d&, const cvf::Vec3d&)), this, SLOT(slotUpdateGeometry(const cvf::Vec3d&, const cvf::Vec3d&))); - // TODO: boxGen operates in display coordinates, conversion is missing - boxGen.setOrigin(intersectionBox->boxOrigin()); - boxGen.setSize(intersectionBox->boxSize()); + cvf::ref transForm = activeView->displayCoordTransform(); - cvf::ref geoMesh = boxGen.createBoundingBoxMeshDrawable(); - if (geoMesh.notNull()) - { - cvf::ref part = new cvf::Part; - part->setName("Cross Section mesh"); - part->setDrawable(geoMesh.p()); - - part->updateBoundingBox(); -// part->setEnableMask(meshFaultBit); -// part->setPriority(priMesh); - - cvf::ref 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()); - } + m_eventHandler->setOrigin(transForm->transformToDisplayCoord(m_intersectionBox->boxOrigin().translation())); + m_eventHandler->setSize(transForm->scaleToDisplaySize(m_intersectionBox->boxSize())); } } } @@ -115,5 +142,5 @@ void RicEditIntersectionBoxFeature::setupActionLook(QAction* actionToSetup) //-------------------------------------------------------------------------------------------------- bool RicEditIntersectionBoxFeature::isCommandChecked() { - return m_model.notNull(); + return m_eventHandler != NULL; } diff --git a/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxFeature.h b/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxFeature.h index 8114203464..334c89ff5e 100644 --- a/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxFeature.h +++ b/ApplicationCode/Commands/IntersectionBoxCommands/RicEditIntersectionBoxFeature.h @@ -19,28 +19,28 @@ #pragma once #include "cafCmdFeature.h" -#include "cafCmdExecuteCommand.h" -#include "cafPdmPointer.h" - -#include "cvfBase.h" -#include "cvfObject.h" -namespace caf { - class BoxManipulatorGeometryGenerator; -}; +class RicBoxManipulatorEventHandler; +class RimIntersectionBox; -namespace cvf { - class ModelBasicList; -}; //================================================================================================== /// //================================================================================================== class RicEditIntersectionBoxFeature : public caf::CmdFeature { + Q_OBJECT; + CAF_CMD_HEADER_INIT; +public: + RicEditIntersectionBoxFeature(); + +public slots: + void slotScheduleRedraw(); + void slotUpdateGeometry(const cvf::Vec3d& origin, const cvf::Vec3d& size); + protected: // Overrides virtual bool isCommandEnabled() override; @@ -49,7 +49,7 @@ protected: virtual bool isCommandChecked() override; private: -// cvf::ref m_boxManipulatorGeometryGenerator; - cvf::ref m_model; + RicBoxManipulatorEventHandler* m_eventHandler; + RimIntersectionBox* m_intersectionBox; }; diff --git a/ApplicationCode/ProjectDataModel/RimIntersectionBox.cpp b/ApplicationCode/ProjectDataModel/RimIntersectionBox.cpp index 4a8cbc25ca..8803bd31bd 100644 --- a/ApplicationCode/ProjectDataModel/RimIntersectionBox.cpp +++ b/ApplicationCode/ProjectDataModel/RimIntersectionBox.cpp @@ -101,6 +101,24 @@ cvf::Vec3d RimIntersectionBox::boxSize() const return cvf::Vec3d(m_maxXCoord, m_maxYCoord, m_maxZCoord) - cvf::Vec3d(m_minXCoord, m_minYCoord, m_minZCoord); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimIntersectionBox::setFromOriginAndSize(const cvf::Vec3d& origin, const cvf::Vec3d& size) +{ + m_minXCoord = origin.x(); + m_minYCoord = origin.y(); + m_minZCoord = origin.z(); + + m_maxXCoord = origin.x() + size.x(); + m_maxYCoord = origin.y() + size.y(); + m_maxZCoord = origin.z() + size.z(); + + updateConnectedEditors(); + + rebuildGeometryAndScheduleCreateDisplayModel(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimIntersectionBox.h b/ApplicationCode/ProjectDataModel/RimIntersectionBox.h index 092fe14029..9815590955 100644 --- a/ApplicationCode/ProjectDataModel/RimIntersectionBox.h +++ b/ApplicationCode/ProjectDataModel/RimIntersectionBox.h @@ -54,6 +54,7 @@ public: cvf::Mat4d boxOrigin() const; cvf::Vec3d boxSize() const; SinglePlaneState singlePlaneState() const; + void setFromOriginAndSize(const cvf::Vec3d& origin, const cvf::Vec3d& size); RivIntersectionBoxPartMgr* intersectionBoxPartMgr(); diff --git a/ApplicationCode/ProjectDataModel/RimView.cpp b/ApplicationCode/ProjectDataModel/RimView.cpp index 0a296c8811..71b8d9b7b6 100644 --- a/ApplicationCode/ProjectDataModel/RimView.cpp +++ b/ApplicationCode/ProjectDataModel/RimView.cpp @@ -25,8 +25,10 @@ #include "RivWellPathCollectionPartMgr.h" +#include "cafDisplayCoordTransform.h" #include "cafFrameAnimationControl.h" #include "cafPdmObjectFactory.h" + #include "cvfCamera.h" #include "cvfModel.h" #include "cvfModelBasicList.h" @@ -927,3 +929,22 @@ void RimView::zoomAll() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RimView::displayCoordTransform() +{ + cvf::ref coordTrans = new caf::DisplayCoordTransform; + + cvf::Vec3d scale(1.0, 1.0, scaleZ); + coordTrans->setScale(scale); + + RimCase* rimCase = ownerCase(); + if (rimCase) + { + coordTrans->setTranslation(rimCase->displayModelOffset()); + } + + return coordTrans; +} + diff --git a/ApplicationCode/ProjectDataModel/RimView.h b/ApplicationCode/ProjectDataModel/RimView.h index 6ed4dc366b..1c0624eefc 100644 --- a/ApplicationCode/ProjectDataModel/RimView.h +++ b/ApplicationCode/ProjectDataModel/RimView.h @@ -62,6 +62,10 @@ namespace cvf class Part; } +namespace caf +{ + class DisplayCoordTransform; +} //================================================================================================== /// /// @@ -161,6 +165,8 @@ public: virtual void zoomAll() override; + cvf::ref displayCoordTransform(); + public: virtual void loadDataAndUpdate() = 0; virtual RimCase* ownerCase() = 0; diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index 9f42ba18e1..e3c1991642 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -208,12 +208,10 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event) m_currentPickedObject = const_cast(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); } diff --git a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorGeometryGenerator.cpp b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorGeometryGenerator.cpp index 2b1ffa4ed2..8a1254cc76 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorGeometryGenerator.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorGeometryGenerator.cpp @@ -28,7 +28,7 @@ BoxManipulatorGeometryGenerator::~BoxManipulatorGeometryGenerator() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void BoxManipulatorGeometryGenerator::setOrigin(const cvf::Mat4d& origin) +void BoxManipulatorGeometryGenerator::setOrigin(const cvf::Vec3d& origin) { m_origin = origin; @@ -76,8 +76,8 @@ void BoxManipulatorGeometryGenerator::calculateArrays() { BoxGenerator gen; - cvf::Vec3d min = m_origin.translation(); - cvf::Vec3d max = m_origin.translation() + m_size; + cvf::Vec3d min = m_origin; + cvf::Vec3d max = m_origin + m_size; gen.setMinMax(min, max); gen.setSubdivisions(1, 1, 1); diff --git a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorGeometryGenerator.h b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorGeometryGenerator.h index d4af669869..9d12a4bab6 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorGeometryGenerator.h +++ b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorGeometryGenerator.h @@ -25,7 +25,7 @@ public: BoxManipulatorGeometryGenerator(); ~BoxManipulatorGeometryGenerator(); - void setOrigin(const cvf::Mat4d& origin); + void setOrigin(const cvf::Vec3d& origin); void setSize(const cvf::Vec3d& size); cvf::ref createBoundingBoxMeshDrawable(); @@ -36,7 +36,7 @@ private: static cvf::ref lineIndicesFromQuadVertexArray(const cvf::Vec3fArray* vertexArray); private: - cvf::Mat4d m_origin; + cvf::Vec3d m_origin; cvf::Vec3d m_size; cvf::ref m_vertices; diff --git a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp index 50d92e7cab..03eee25f3e 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp @@ -1,15 +1,17 @@ #include "cafBoxManipulatorPartManager.h" +#include "cafBoxManipulatorGeometryGenerator.h" +#include "cafEffectGenerator.h" + #include "cvfBoxGenerator.h" #include "cvfDrawableGeo.h" #include "cvfGeometryBuilderFaceList.h" +#include "cvfModelBasicList.h" #include "cvfPart.h" #include "cvfPrimitiveSetIndexedUInt.h" #include "cvfPrimitiveSetIndexedUShort.h" -#include "cafBoxManipulatorGeometryGenerator.h" -#include "cafEffectGenerator.h" -#include "cvfModelBasicList.h" +#include "cvfRay.h" using namespace cvf; @@ -22,18 +24,15 @@ namespace caf { //-------------------------------------------------------------------------------------------------- BoxManipulatorPartManager::BoxManipulatorPartManager() { - m_geometryGenerator = new caf::BoxManipulatorGeometryGenerator; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void BoxManipulatorPartManager::setOrigin(const cvf::Mat4d& origin) +void BoxManipulatorPartManager::setOrigin(const cvf::Vec3d& origin) { m_origin = origin; - m_geometryGenerator->setOrigin(origin); - clearAllGeometryAndParts(); } @@ -44,11 +43,18 @@ void BoxManipulatorPartManager::setSize(const cvf::Vec3d& size) { m_size = size; - m_geometryGenerator->setSize(size); - clearAllGeometryAndParts(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void BoxManipulatorPartManager::originAndSize(cvf::Vec3d* origin, cvf::Vec3d* size) +{ + *origin = m_origin; + *size = m_size; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -71,11 +77,14 @@ void BoxManipulatorPartManager::appendPartsToModel(cvf::ModelBasicList* model) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -size_t BoxManipulatorPartManager::partIndexFromSourceInfo(cvf::Part* candidatePart) +size_t BoxManipulatorPartManager::partIndexFromSourceInfo(const cvf::Part* candidatePart, const cvf::Vec3d& intersectionPoint) { if (!candidatePart) return cvf::UNDEFINED_SIZE_T; - BoxManipulatorSourceInfo* candidateSourceInfo = dynamic_cast(candidatePart->sourceInfo()); + const cvf::Object* siConstObj = candidatePart->sourceInfo(); + cvf::Object* siObj = const_cast(siConstObj); + + BoxManipulatorSourceInfo* candidateSourceInfo = dynamic_cast(siObj); if (!candidateSourceInfo) return cvf::UNDEFINED_SIZE_T; for (size_t i = 0; i < m_cubeParts.size(); i++) @@ -86,6 +95,8 @@ size_t BoxManipulatorPartManager::partIndexFromSourceInfo(cvf::Part* candidatePa if (si->m_cubeFace == candidateSourceInfo->m_cubeFace && si->m_cubeFaceItem == candidateSourceInfo->m_cubeFaceItem) { + m_initialPickPoint = intersectionPoint; + return i; } } @@ -93,6 +104,110 @@ size_t BoxManipulatorPartManager::partIndexFromSourceInfo(cvf::Part* candidatePa return cvf::UNDEFINED_SIZE_T; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void BoxManipulatorPartManager::updateFromPartIndexAndRay(size_t partIndex, const cvf::Ray* ray) +{ + BoxCubeFace face = m_cubeItemType[partIndex].first; + cvf::Vec3d faceDir = normalFromFace(face); + + cvf::Vec3d closestPoint1; + cvf::Vec3d closestPoint2; + BoxManipulatorPartManager::closestPointOfTwoLines(ray->origin(), ray->origin() + ray->direction(), m_initialPickPoint, m_initialPickPoint + faceDir, &closestPoint1, &closestPoint2); + + cvf::Vec3d newOrigin = m_origin; + cvf::Vec3d newSize = m_size; + + switch (face) + { + case caf::BoxManipulatorPartManager::BCF_X_POS: + newSize.x() = CVF_MAX(0.0, closestPoint2.x() - m_origin.x()); + break; + case caf::BoxManipulatorPartManager::BCF_X_NEG: + if (m_size.x() - (closestPoint2.x() - m_origin.x()) > 0.0) + { + newOrigin.x() = closestPoint2.x(); + newSize.x() = m_size.x() - (closestPoint2.x() - m_origin.x()); + } + else + { + newOrigin.x() = m_origin.x() + m_size.x(); + newSize.x() = 0.0; + } + break; + case caf::BoxManipulatorPartManager::BCF_Y_POS: + newSize.y() = CVF_MAX(0.0, closestPoint2.y() - m_origin.y()); + break; + case caf::BoxManipulatorPartManager::BCF_Y_NEG: + if (m_size.y() - (closestPoint2.y() - m_origin.y()) > 0.0) + { + newOrigin.y() = closestPoint2.y(); + newSize.y() = m_size.y() - (closestPoint2.y() - m_origin.y()); + } + else + { + newOrigin.y() = m_origin.y() + m_size.y(); + newSize.y() = 0.0; + } + break; + case caf::BoxManipulatorPartManager::BCF_Z_POS: + newSize.z() = CVF_MAX(0.0, closestPoint2.z() - m_origin.z()); + break; + case caf::BoxManipulatorPartManager::BCF_Z_NEG: + if (m_size.z() - (closestPoint2.z() - m_origin.z()) > 0.0) + { + newOrigin.z() = closestPoint2.z(); + newSize.z() = m_size.z() - (closestPoint2.z() - m_origin.z()); + } + else + { + newOrigin.z() = m_origin.z() + m_size.z(); + newSize.z() = 0.0; + } + break; + default: + break; + } + + setOrigin(newOrigin); + setSize(newSize); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec3d BoxManipulatorPartManager::normalFromFace(BoxCubeFace face) +{ + switch (face) + { + case caf::BoxManipulatorPartManager::BCF_X_POS: + return cvf::Vec3d::X_AXIS; + break; + case caf::BoxManipulatorPartManager::BCF_X_NEG: + return -cvf::Vec3d::X_AXIS; + break; + case caf::BoxManipulatorPartManager::BCF_Y_POS: + return cvf::Vec3d::Y_AXIS; + break; + case caf::BoxManipulatorPartManager::BCF_Y_NEG: + return -cvf::Vec3d::Y_AXIS; + break; + case caf::BoxManipulatorPartManager::BCF_Z_POS: + return cvf::Vec3d::Z_AXIS; + break; + case caf::BoxManipulatorPartManager::BCF_Z_NEG: + return -cvf::Vec3d::Z_AXIS; + break; + default: + CVF_ASSERT(false); + break; + } + + return cvf::Vec3d::UNDEFINED; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -101,96 +216,49 @@ 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(BCF_Y_NEG, cp[0], cp[1], cp[5], cp[4]); + createCubeFaceGeos(BCF_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(BCF_Z_POS, cp[4], cp[5], cp[6], cp[7]); + createCubeFaceGeos(BCF_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]); + createCubeFaceGeos(BCF_X_NEG, cp[3], cp[0], cp[4], cp[7]); + createCubeFaceGeos(BCF_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) +void BoxManipulatorPartManager::createCubeFaceGeos(BoxCubeFace 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 centerItemHeight = (p1 - p2).length(); + if ((p2 - p3).length() < centerItemHeight) + { + centerItemHeight = (p2 - p3).length(); + } + + float centerItemFactor = 0.1f; + centerItemHeight *= centerItemFactor; - 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 center = (p1 + p3) / 2.0f; + Vec3f u = (p2 - p1).getNormalized() * centerItemHeight; + Vec3f v = (p4 - p1).getNormalized() * centerItemHeight; - 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 pi1 = center - u / 2.0 - v / 2.0; - 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()); -*/ + Vec3f pi2 = pi1 + u; + Vec3f pi3 = pi2 + v; + Vec3f pi4 = pi1 + v; // 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()); + m_cubeItemType.push_back(navCubeItem(face, BCFI_CENTER)); + m_cubeGeos.push_back(createQuadGeo(pi1, pi2, pi3, pi4).p()); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref 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) +cvf::ref BoxManipulatorPartManager::createQuadGeo(const cvf::Vec3f& v1, const cvf::Vec3f& v2, const cvf::Vec3f& v3, const cvf::Vec3f& v4) { ref geo = new DrawableGeo; @@ -200,14 +268,7 @@ cvf::ref BoxManipulatorPartManager::createQuadGeo(const cvf::V vertexArray->set(2, v3); vertexArray->set(3, v4); - ref 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 indices = new cvf::UShortArray(6); indices->set(0, 0); @@ -230,8 +291,13 @@ cvf::ref BoxManipulatorPartManager::createQuadGeo(const cvf::V //-------------------------------------------------------------------------------------------------- void BoxManipulatorPartManager::navCubeCornerPoints(cvf::Vec3f points[8]) { - Vec3f min(m_origin.translation()); - Vec3f max(m_origin.translation() + m_size); + Vec3f offset(1.0, 1.0, 1.0); + + Vec3f min(m_origin); + min -= offset; + + Vec3f max(m_origin + m_size); + max += offset; points[0].set(min.x(), min.y(), min.z()); points[1].set(max.x(), min.y(), min.z()); @@ -246,7 +312,7 @@ void BoxManipulatorPartManager::navCubeCornerPoints(cvf::Vec3f points[8]) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::pair BoxManipulatorPartManager::navCubeItem(NavCubeFace face, NavCubeFaceItem faceItem) const +std::pair BoxManipulatorPartManager::navCubeItem(BoxCubeFace face, NavCubeFaceItem faceItem) const { return std::make_pair(face, faceItem); } @@ -258,7 +324,6 @@ void BoxManipulatorPartManager::clearAllGeometryAndParts() { m_boundingBoxPart = nullptr; m_cubeGeos.clear(); - m_cubeGeoFace.clear(); m_cubeItemType.clear(); m_cubeParts.clear(); } @@ -280,7 +345,11 @@ void BoxManipulatorPartManager::createBoundingBoxPart() { m_boundingBoxPart = nullptr; - cvf::ref geoMesh = m_geometryGenerator->createBoundingBoxMeshDrawable(); + cvf::ref geometryGenerator = new caf::BoxManipulatorGeometryGenerator; + geometryGenerator->setOrigin(m_origin); + geometryGenerator->setSize(m_size); + + cvf::ref geoMesh = geometryGenerator->createBoundingBoxMeshDrawable(); if (geoMesh.notNull()) { cvf::ref part = new cvf::Part; @@ -332,5 +401,70 @@ void BoxManipulatorPartManager::createCubeParts() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool BoxManipulatorPartManager::closestPointOfTwoLines(const cvf::Vec3d& p1, const cvf::Vec3d& q1, const cvf::Vec3d& p2, const cvf::Vec3d& q2, cvf::Vec3d* closestPoint1, cvf::Vec3d* closestPoint2) +{ + // qDebug() << p1 << " " << q1 << " " << p2 << " " << q2; + + // Taken from Real-Time Collistion Detection, Christer Ericson, 2005, p146-147 + + // L1(s) = P1 + sd1 + // L2(t) = P2 + td2 + + // d1 = Q1-P1 + // d2 = Q2-P2 + + // r = P1-P2 + + // a = d1*d1 + // b = d1*d2 + // c = d1*r + // e = d2*d2; + // d = ae-b^2 + // f = d2*r + + // s = (bf-ce)/d + // t = (af-bc)/d + + + cvf::Vec3d d1 = q1 - p1; + cvf::Vec3d d2 = q2 - p2; + + double a = d1.dot(d1); + double b = d1.dot(d2); + double e = d2.dot(d2); + + double d = a*e - b*b; + + if (d < std::numeric_limits::epsilon()) + { + // Parallel lines + if (closestPoint1) *closestPoint1 = p1; + if (closestPoint2) *closestPoint2 = p2; + return false; + } + + cvf::Vec3d r = p1 - p2; + double c = d1.dot(r); + double f = d2.dot(r); + + double s = (b*f - c*e) / d; + double t = (a*f - b*c) / d; + + if (closestPoint1) *closestPoint1 = p1 + s*d1; + if (closestPoint2) *closestPoint2 = p2 + t*d2; + + if (s >= 0 && s <= 1 && t >= 0 && t <= 1) + { + return true; + } + else + { + return false; + } +} + } // namespace cvf diff --git a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h index 1b910af5ea..7019f0bc8f 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h +++ b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h @@ -7,15 +7,12 @@ #include "cvfVector3.h" #include "cvfCollection.h" #include "cvfMatrix4.h" -/* -#include "cvfArray.h" -#include "cvfBoundingBox.h" -*/ namespace cvf { class ModelBasicList; class Part; class DrawableGeo; + class Ray; } namespace caf { @@ -33,129 +30,80 @@ namespace caf { class BoxManipulatorPartManager : public cvf::Object { public: - enum NavCubeFace + enum BoxCubeFace { - NCF_X_POS, - NCF_X_NEG, - NCF_Y_POS, - NCF_Y_NEG, - NCF_Z_POS, - NCF_Z_NEG + BCF_X_POS, + BCF_X_NEG, + BCF_Y_POS, + BCF_Y_NEG, + BCF_Z_POS, + BCF_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 + BCFI_NONE, + BCFI_CENTER }; - 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); + void setOrigin(const cvf::Vec3d& origin); + void setSize(const cvf::Vec3d& size); + void originAndSize(cvf::Vec3d* origin, cvf::Vec3d* size); + size_t partIndexFromSourceInfo(const cvf::Part* part, const cvf::Vec3d& intersectionPoint); + void updateFromPartIndexAndRay(size_t partIndex, const cvf::Ray* ray); + void appendPartsToModel(cvf::ModelBasicList* model); private: - void createCubeGeos(); - void createCubeFaceGeos(NavCubeFace face, cvf::Vec3f p1, cvf::Vec3f p2, cvf::Vec3f p3, cvf::Vec3f p4); - cvf::ref 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]); + cvf::Vec3d normalFromFace(BoxCubeFace face); + + void createCubeGeos(); + void createCubeFaceGeos(BoxCubeFace face, cvf::Vec3f p1, cvf::Vec3f p2, cvf::Vec3f p3, cvf::Vec3f p4); + void navCubeCornerPoints(cvf::Vec3f points[8]); - //NavCubeItem navCubeItem(NavCubeFace face, NavCubeFaceItem item) const; - std::pair navCubeItem(NavCubeFace face, NavCubeFaceItem item) const; - void clearAllGeometryAndParts(); - void recreateAllGeometryAndParts(); + void clearAllGeometryAndParts(); + void recreateAllGeometryAndParts(); - void createBoundingBoxPart(); - void createCubeParts(); + void createBoundingBoxPart(); + void createCubeParts(); + + cvf::ref createQuadGeo(const cvf::Vec3f& v1, const cvf::Vec3f& v2, const cvf::Vec3f& v3, const cvf::Vec3f& v4); + std::pair navCubeItem(BoxCubeFace face, NavCubeFaceItem item) const; + + static bool closestPointOfTwoLines(const cvf::Vec3d& p1, const cvf::Vec3d& q1, const cvf::Vec3d& p2, const cvf::Vec3d& q2, cvf::Vec3d* closestPoint1, cvf::Vec3d* closestPoint2); private: cvf::Collection m_cubeGeos; // These arrays have the same length - std::vector m_cubeGeoFace; // These arrays have the same length - std::vector< std::pair > m_cubeItemType; // These arrays have the same length - - cvf::Collection m_cubeParts; // These arrays have the same length + std::vector< std::pair > m_cubeItemType; // These arrays have the same length + cvf::Collection m_cubeParts; // These arrays have the same length + cvf::ref m_boundingBoxPart; - cvf::ref m_geometryGenerator; - - cvf::Mat4d m_origin; + cvf::Vec3d m_origin; cvf::Vec3d m_size; + + cvf::Vec3d m_initialPickPoint; }; - - - - +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- class BoxManipulatorSourceInfo : public cvf::Object { public: - BoxManipulatorSourceInfo(BoxManipulatorPartManager::NavCubeFace cubeFace, BoxManipulatorPartManager::NavCubeFaceItem cubeFaceItem) + BoxManipulatorSourceInfo(BoxManipulatorPartManager::BoxCubeFace cubeFace, BoxManipulatorPartManager::NavCubeFaceItem cubeFaceItem) : m_cubeFace(cubeFace), m_cubeFaceItem(cubeFaceItem) { } - BoxManipulatorPartManager::NavCubeFace m_cubeFace; + BoxManipulatorPartManager::BoxCubeFace m_cubeFace; BoxManipulatorPartManager::NavCubeFaceItem m_cubeFaceItem; }; diff --git a/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.cpp b/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.cpp index 93cd8fff83..413f99ebfd 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.cpp @@ -52,3 +52,31 @@ cvf::Vec3d caf::DisplayCoordTransform::scaleToDisplaySize(const cvf::Vec3d& doma return coord; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec3d caf::DisplayCoordTransform::transformToDomainCoord(const cvf::Vec3d& displayCoord) const +{ + cvf::Vec3d coord = displayCoord; + coord.x() /= m_scale.x(); + coord.y() /= m_scale.y(); + coord.z() /= m_scale.z(); + + coord += m_translation; + + return coord; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec3d caf::DisplayCoordTransform::scaleToDomainSize(const cvf::Vec3d& displaySize) const +{ + cvf::Vec3d coord = displaySize; + coord.x() /= m_scale.x(); + coord.y() /= m_scale.y(); + coord.z() /= m_scale.z(); + + return coord; +} diff --git a/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.h b/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.h index bc485ae093..73eaf5d980 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.h +++ b/Fwk/AppFwk/cafVizExtensions/cafDisplayCoordTransform.h @@ -22,6 +22,9 @@ public: cvf::Vec3d transformToDisplayCoord(const cvf::Vec3d& domainCoord) const; cvf::Vec3d scaleToDisplaySize(const cvf::Vec3d& domainSize) const; + cvf::Vec3d transformToDomainCoord(const cvf::Vec3d& displayCoord) const; + cvf::Vec3d scaleToDomainSize(const cvf::Vec3d& displaySize) const; + private: cvf::Vec3d m_scale; cvf::Vec3d m_translation;