From d8424feeddb7446ba92115d9bc5e181f47e198ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 30 Sep 2016 13:16:00 +0200 Subject: [PATCH] Renamed somewhat in BoxManipulator --- .../cafBoxManipulatorPartManager.cpp | 127 +++++++----------- .../cafBoxManipulatorPartManager.h | 36 +++-- 2 files changed, 67 insertions(+), 96 deletions(-) diff --git a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp index 03eee25f3e..ac54d2b390 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.cpp @@ -68,9 +68,9 @@ void BoxManipulatorPartManager::appendPartsToModel(cvf::ModelBasicList* model) CVF_ASSERT(m_boundingBoxPart.notNull()); model->addPart(m_boundingBoxPart.p()); - for (size_t i = 0; i < m_cubeParts.size(); i++) + for (size_t i = 0; i < m_handleParts.size(); i++) { - model->addPart(m_cubeParts.at(i)); + model->addPart(m_handleParts.at(i)); } } @@ -87,13 +87,13 @@ size_t BoxManipulatorPartManager::partIndexFromSourceInfo(const cvf::Part* candi BoxManipulatorSourceInfo* candidateSourceInfo = dynamic_cast(siObj); if (!candidateSourceInfo) return cvf::UNDEFINED_SIZE_T; - for (size_t i = 0; i < m_cubeParts.size(); i++) + for (size_t i = 0; i < m_handleParts.size(); i++) { - cvf::Part* part = m_cubeParts.at(i); + cvf::Part* part = m_handleParts.at(i); BoxManipulatorSourceInfo* si = static_cast(part->sourceInfo()); if (si->m_cubeFace == candidateSourceInfo->m_cubeFace && - si->m_cubeFaceItem == candidateSourceInfo->m_cubeFaceItem) + si->m_cubeHandle == candidateSourceInfo->m_cubeHandle) { m_initialPickPoint = intersectionPoint; @@ -110,7 +110,7 @@ size_t BoxManipulatorPartManager::partIndexFromSourceInfo(const cvf::Part* candi //-------------------------------------------------------------------------------------------------- void BoxManipulatorPartManager::updateFromPartIndexAndRay(size_t partIndex, const cvf::Ray* ray) { - BoxCubeFace face = m_cubeItemType[partIndex].first; + BoxFace face = m_handleIds[partIndex].first; cvf::Vec3d faceDir = normalFromFace(face); cvf::Vec3d closestPoint1; @@ -178,7 +178,7 @@ void BoxManipulatorPartManager::updateFromPartIndexAndRay(size_t partIndex, cons //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::Vec3d BoxManipulatorPartManager::normalFromFace(BoxCubeFace face) +cvf::Vec3d BoxManipulatorPartManager::normalFromFace(BoxFace face) { switch (face) { @@ -211,25 +211,25 @@ cvf::Vec3d BoxManipulatorPartManager::normalFromFace(BoxCubeFace face) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void BoxManipulatorPartManager::createCubeGeos() +void BoxManipulatorPartManager::createAllHandleParts() { Vec3f cp[8]; navCubeCornerPoints(cp); - createCubeFaceGeos(BCF_Y_NEG, cp[0], cp[1], cp[5], cp[4]); - createCubeFaceGeos(BCF_Y_POS, cp[2], cp[3], cp[7], cp[6]); + createCubeFaceHandlePart(BCF_Y_NEG, cp[0], cp[1], cp[5], cp[4]); + createCubeFaceHandlePart(BCF_Y_POS, cp[2], cp[3], cp[7], cp[6]); - createCubeFaceGeos(BCF_Z_POS, cp[4], cp[5], cp[6], cp[7]); - createCubeFaceGeos(BCF_Z_NEG, cp[3], cp[2], cp[1], cp[0]); + createCubeFaceHandlePart(BCF_Z_POS, cp[4], cp[5], cp[6], cp[7]); + createCubeFaceHandlePart(BCF_Z_NEG, cp[3], cp[2], cp[1], cp[0]); - createCubeFaceGeos(BCF_X_NEG, cp[3], cp[0], cp[4], cp[7]); - createCubeFaceGeos(BCF_X_POS, cp[1], cp[2], cp[6], cp[5]); + createCubeFaceHandlePart(BCF_X_NEG, cp[3], cp[0], cp[4], cp[7]); + createCubeFaceHandlePart(BCF_X_POS, cp[1], cp[2], cp[6], cp[5]); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void BoxManipulatorPartManager::createCubeFaceGeos(BoxCubeFace face, cvf::Vec3f p1, cvf::Vec3f p2, cvf::Vec3f p3, cvf::Vec3f p4) +void BoxManipulatorPartManager::createCubeFaceHandlePart(BoxFace face, cvf::Vec3f p1, cvf::Vec3f p2, cvf::Vec3f p3, cvf::Vec3f p4) { float centerItemHeight = (p1 - p2).length(); if ((p2 - p3).length() < centerItemHeight) @@ -250,15 +250,28 @@ void BoxManipulatorPartManager::createCubeFaceGeos(BoxCubeFace face, cvf::Vec3f Vec3f pi3 = pi2 + v; Vec3f pi4 = pi1 + v; - // Inner part - m_cubeItemType.push_back(navCubeItem(face, BCFI_CENTER)); - m_cubeGeos.push_back(createQuadGeo(pi1, pi2, pi3, pi4).p()); + ref geo = createHandleGeo(pi1, pi2, pi3, pi4); + + cvf::ref handlePart = new cvf::Part; + handlePart->setName("Box manipulator handle"); + handlePart->setDrawable(geo.p()); + + handlePart->updateBoundingBox(); + + caf::SurfaceEffectGenerator surfaceGen(cvf::Color3::GREEN, caf::PO_1); + cvf::ref eff = surfaceGen.generateCachedEffect(); + handlePart->setEffect(eff.p()); + + handlePart->setSourceInfo(new BoxManipulatorSourceInfo(face, BCFI_CENTER)); + + m_handleParts.push_back(handlePart.p()); + m_handleIds.push_back(std::make_pair(face, BCFI_CENTER)); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref BoxManipulatorPartManager::createQuadGeo(const cvf::Vec3f& v1, const cvf::Vec3f& v2, const cvf::Vec3f& v3, const cvf::Vec3f& v4) +cvf::ref BoxManipulatorPartManager::createHandleGeo(const cvf::Vec3f& v1, const cvf::Vec3f& v2, const cvf::Vec3f& v3, const cvf::Vec3f& v4) { ref geo = new DrawableGeo; @@ -309,13 +322,6 @@ void BoxManipulatorPartManager::navCubeCornerPoints(cvf::Vec3f points[8]) points[7].set(min.x(), max.y(), max.z()); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::pair BoxManipulatorPartManager::navCubeItem(BoxCubeFace face, NavCubeFaceItem faceItem) const -{ - return std::make_pair(face, faceItem); -} //-------------------------------------------------------------------------------------------------- /// @@ -323,9 +329,8 @@ std::pair 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 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()); - } - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -408,25 +381,25 @@ bool BoxManipulatorPartManager::closestPointOfTwoLines(const cvf::Vec3d& p1, con { // qDebug() << p1 << " " << q1 << " " << p2 << " " << q2; - // Taken from Real-Time Collistion Detection, Christer Ericson, 2005, p146-147 + // Taken from Real-Time Collistion Detection, Christer Ericson, 2005, p146-147 - // L1(s) = P1 + sd1 - // L2(t) = P2 + td2 + // L1(s) = P1 + sd1 + // L2(t) = P2 + td2 - // d1 = Q1-P1 - // d2 = Q2-P2 + // d1 = Q1-P1 + // d2 = Q2-P2 - // r = P1-P2 + // r = P1-P2 - // a = d1*d1 - // b = d1*d2 - // c = d1*r - // e = d2*d2; - // d = ae-b^2 - // f = d2*r + // 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 + // s = (bf-ce)/d + // t = (af-bc)/d cvf::Vec3d d1 = q1 - p1; diff --git a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h index 7019f0bc8f..6a882037db 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h +++ b/Fwk/AppFwk/cafVizExtensions/cafBoxManipulatorPartManager.h @@ -30,7 +30,7 @@ namespace caf { class BoxManipulatorPartManager : public cvf::Object { public: - enum BoxCubeFace + enum BoxFace { BCF_X_POS, BCF_X_NEG, @@ -40,7 +40,7 @@ public: BCF_Z_NEG }; - enum NavCubeFaceItem + enum HandleType { BCFI_NONE, BCFI_CENTER @@ -59,28 +59,26 @@ public: void appendPartsToModel(cvf::ModelBasicList* model); private: - cvf::Vec3d normalFromFace(BoxCubeFace face); - - void createCubeGeos(); - void createCubeFaceGeos(BoxCubeFace face, cvf::Vec3f p1, cvf::Vec3f p2, cvf::Vec3f p3, cvf::Vec3f p4); + cvf::Vec3d normalFromFace(BoxFace face); void navCubeCornerPoints(cvf::Vec3f points[8]); - + + void createBoundingBoxPart(); + //void createAllHandleParts(); + + void createAllHandleParts(); + void createCubeFaceHandlePart(BoxFace face, cvf::Vec3f p1, cvf::Vec3f p2, cvf::Vec3f p3, cvf::Vec3f p4); void clearAllGeometryAndParts(); void recreateAllGeometryAndParts(); - 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 cvf::ref createHandleGeo(const cvf::Vec3f& v1, const cvf::Vec3f& v2, const cvf::Vec3f& v3, const cvf::Vec3f& v4); 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< std::pair > m_cubeItemType; // These arrays have the same length - cvf::Collection m_cubeParts; // These arrays have the same length + //cvf::Collection m_handleGeos; // These arrays have the same length + std::vector< std::pair > m_handleIds; // These arrays have the same length + cvf::Collection m_handleParts; // These arrays have the same length cvf::ref m_boundingBoxPart; @@ -97,14 +95,14 @@ private: class BoxManipulatorSourceInfo : public cvf::Object { public: - BoxManipulatorSourceInfo(BoxManipulatorPartManager::BoxCubeFace cubeFace, BoxManipulatorPartManager::NavCubeFaceItem cubeFaceItem) + BoxManipulatorSourceInfo(BoxManipulatorPartManager::BoxFace cubeFace, BoxManipulatorPartManager::HandleType cubeFaceItem) : m_cubeFace(cubeFace), - m_cubeFaceItem(cubeFaceItem) + m_cubeHandle(cubeFaceItem) { } - BoxManipulatorPartManager::BoxCubeFace m_cubeFace; - BoxManipulatorPartManager::NavCubeFaceItem m_cubeFaceItem; + BoxManipulatorPartManager::BoxFace m_cubeFace; + BoxManipulatorPartManager::HandleType m_cubeHandle; };