Commit f9460780 authored by Andrew Wilson's avatar Andrew Wilson 🐘
Browse files

Merge branch 'TetCut' into 'master'

REFAC: KeyPressEvent renamed to KeyEvent, TetrahedralMeshRenderDelegate...

See merge request iMSTK/iMSTK!538
parents 322afabe 07a65ed9
......@@ -490,8 +490,8 @@ main()
viewer->addControl(keyControl);
// Add an extra control
connect<KeyPressEvent>(viewer->getKeyboardDevice(), EventType::KeyEvent,
[&](KeyPressEvent* e)
connect<KeyEvent>(viewer->getKeyboardDevice(), EventType::KeyEvent,
[&](KeyEvent* e)
{
if (e->m_key == 'b' && e->m_keyPressType == KEY_PRESS)
{
......
......@@ -17,12 +17,12 @@
###########################################################################
if(iMSTK_USE_OpenHaptics)
project(Example-LevelSet-RigidInteraction)
project(Example-FemurCut)
#-----------------------------------------------------------------------------
# Create executable
#-----------------------------------------------------------------------------
imstk_add_executable(${PROJECT_NAME} LevelSet-RigidInteractionExample.cpp)
imstk_add_executable(${PROJECT_NAME} FemurCutExample.cpp)
#-----------------------------------------------------------------------------
# Add the target to Examples folder
......
#-----------------------------------------------------------------------------
# Add Example subdirectories
#-----------------------------------------------------------------------------
macro(listOfSubDir result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
list(APPEND dirlist ${child})
endif()
endforeach()
set(${result} ${dirlist})
endmacro()
listOfSubDir(subDirs ${CMAKE_CURRENT_SOURCE_DIR})
foreach(subdir ${subDirs})
add_subdirectory(${subdir})
endforeach()
......@@ -306,8 +306,8 @@ testMultipleScenesInRenderMode()
LOG(INFO) << "s/S followed by enter to switch scenes";
LOG(INFO) << "q/Q followed by enter to quit";
connect<KeyPressEvent>(viewer->getKeyboardDevice(), EventType::KeyEvent,
[&, driver](KeyPressEvent* e)
connect<KeyEvent>(viewer->getKeyboardDevice(), EventType::KeyEvent,
[&, driver](KeyEvent* e)
{
if (e->m_keyPressType == KEY_PRESS)
{
......@@ -358,7 +358,7 @@ testMultipleScenesInBackgroundMode()
LOG(INFO) << "s/S followed by enter to switch scenes";
LOG(INFO) << "q/Q followed by enter to quit";
auto keyPressFunc = [&](KeyPressEvent* e)
auto keyPressFunc = [&](KeyEvent* e)
{
if (e->m_keyPressType == KEY_PRESS)
{
......@@ -382,7 +382,7 @@ testMultipleScenesInBackgroundMode()
}
}
};
connect<KeyPressEvent>(console->getKeyboardDevice(), EventType::KeyEvent, keyPressFunc);
connect<KeyEvent>(console->getKeyboardDevice(), EventType::KeyEvent, keyPressFunc);
driver->start();
}
......
......@@ -210,7 +210,7 @@ main()
}
// Queue keypress to be called after scene thread
queueConnect<KeyPressEvent>(viewer->getKeyboardDevice(), EventType::KeyEvent, sceneManager, [&](KeyPressEvent* e)
queueConnect<KeyEvent>(viewer->getKeyboardDevice(), EventType::KeyEvent, sceneManager, [&](KeyEvent* e)
{
// When i is pressed replace the PBD cloth with a subdivided one
if (e->m_key == 'i' && e->m_keyPressType == KEY_PRESS)
......
......@@ -26,7 +26,7 @@ imstk_add_executable(${PROJECT_NAME} SPH-Obj-SDFInteractionExample.cpp)
#-----------------------------------------------------------------------------
# Add the target to Examples folder
#-----------------------------------------------------------------------------
SET_TARGET_PROPERTIES (${PROJECT_NAME} PROPERTIES FOLDER Examples/Interaction)
SET_TARGET_PROPERTIES (${PROJECT_NAME} PROPERTIES FOLDER Examples)
#-----------------------------------------------------------------------------
# Link libraries to executable
......
......@@ -125,8 +125,8 @@ main()
keyControl->setModuleDriver(driver);
viewer->addControl(keyControl);
connect<KeyPressEvent>(viewer->getKeyboardDevice(), EventType::KeyEvent,
[&](KeyPressEvent* e)
connect<KeyEvent>(viewer->getKeyboardDevice(), EventType::KeyEvent,
[&](KeyEvent* e)
{
if (e->m_keyPressType == KEY_PRESS)
{
......
......@@ -48,7 +48,7 @@ KeyboardControl::setDevice(std::shared_ptr<DeviceClient> device)
}
void
KeyboardControl::keyPressEvent(KeyPressEvent* keyPressEvent)
KeyboardControl::keyPressEvent(KeyEvent* keyPressEvent)
{
// If the key was just pressed
if (keyPressEvent->m_keyPressType == KEY_PRESS)
......
......@@ -27,7 +27,7 @@
namespace imstk
{
class KeyboardDeviceClient;
class KeyPressEvent;
class KeyEvent;
///
/// \class KeyboardSceneController
......@@ -55,7 +55,7 @@ public:
/// \brief Posts key press/release events
/// override to filter the event, or implement OnkeyDown/OnKeyUp
///
virtual void keyPressEvent(KeyPressEvent* e);
virtual void keyPressEvent(KeyEvent* e);
protected:
std::shared_ptr<KeyboardDeviceClient> m_keyboardDeviceClient;
......
......@@ -36,7 +36,7 @@ KeyboardDeviceClient::emitKeyDown(char key)
m_buttons[key] = KEY_PRESS;
if (prevKeyState != KEY_PRESS)
{
this->postEvent(KeyPressEvent(key, KEY_PRESS));
this->postEvent(KeyEvent(key, KEY_PRESS));
}
}
......@@ -47,7 +47,7 @@ KeyboardDeviceClient::emitKeyUp(char key)
m_buttons[key] = KEY_RELEASE;
if (prevKeyState != KEY_RELEASE)
{
this->postEvent(KeyPressEvent(key, KEY_RELEASE));
this->postEvent(KeyEvent(key, KEY_RELEASE));
}
}
......
......@@ -31,11 +31,11 @@ using KeyStateType = int;
#define KEY_RELEASE 0
#define KEY_PRESS 1
class KeyPressEvent : public Event
class KeyEvent : public Event
{
public:
KeyPressEvent(const char key, const KeyStateType keyPressType) : Event(EventType::KeyEvent, 1), m_keyPressType(keyPressType), m_key(key) { }
virtual ~KeyPressEvent() override = default;
KeyEvent(const char key, const KeyStateType keyPressType) : Event(EventType::KeyEvent, 1), m_keyPressType(keyPressType), m_key(key) { }
virtual ~KeyEvent() override = default;
public:
KeyStateType m_keyPressType;
......
......@@ -30,6 +30,7 @@
#include "imstkTetrahedralMesh.h"
#include "imstkCube.h"
#include "imstkSphere.h"
#include "imstkPlane.h"
#include "imstkMacros.h"
#include "imstkTypes.h"
......@@ -37,12 +38,14 @@
#include <vtkAppendPolyData.h>
#include <vtkCellData.h>
#include <vtkCharArray.h>
#include <vtkCleanPolyData.h>
#include <vtkCubeSource.h>
#include <vtkDoubleArray.h>
#include <vtkFeatureEdges.h>
#include <vtkFloatArray.h>
#include <vtkImageData.h>
#include <vtkMassProperties.h>
#include <vtkPlaneSource.h>
#include <vtkPointData.h>
#include <vtkShortArray.h>
#include <vtkSphereSource.h>
......@@ -743,6 +746,33 @@ GeometryUtils::toUVSphereSurfaceMesh(std::shared_ptr<Sphere> sphere,
return copyToSurfaceMesh(sphereSource->GetOutput());
}
std::shared_ptr<SurfaceMesh>
GeometryUtils::toQuadSurfaceMesh(std::shared_ptr<Plane> plane)
{
const Quatd r = Quatd::FromTwoVectors(Vec3d(0.0, 1.0, 0.0), plane->getOrientationAxis());
const Vec3d i = r._transformVector(Vec3d(1.0, 0.0, 0.0));
const Vec3d j = r._transformVector(Vec3d(0.0, 0.0, 1.0));
//Vec3d p1 = plane->getPosition() + plane->getWidth() * (i + j);
Vec3d p2 = plane->getPosition() + plane->getWidth() * (i - j);
Vec3d p3 = plane->getPosition() + plane->getWidth() * (-i + j);
Vec3d p4 = plane->getPosition() + plane->getWidth() * (-i - j);
vtkNew<vtkPlaneSource> planeSource;
planeSource->SetOrigin(p4.data());
planeSource->SetPoint1(p3.data());
planeSource->SetPoint2(p2.data());
planeSource->Update();
vtkNew<vtkTriangleFilter> triangulate;
triangulate->SetInputData(planeSource->GetOutput());
triangulate->Update();
vtkNew<vtkCleanPolyData> cleanData;
cleanData->SetInputConnection(triangulate->GetOutputPort());
cleanData->Update();
return copyToSurfaceMesh(cleanData->GetOutput());
}
int
GeometryUtils::getOpenEdgeCount(std::shared_ptr<SurfaceMesh> surfMesh)
{
......
......@@ -58,6 +58,7 @@ class VolumetricMesh;
class Cube;
class Sphere;
class Plane;
///
/// \brief Contains a set of free functions for processing geometry
......@@ -203,6 +204,11 @@ std::shared_ptr<SurfaceMesh> toCubeSurfaceMesh(std::shared_ptr<Cube> cube);
std::shared_ptr<SurfaceMesh> toUVSphereSurfaceMesh(std::shared_ptr<Sphere> sphere,
const unsigned int phiDivisions, const unsigned int thetaDivisions);
///
/// \brief Produces SurfaceMesh cube from imstkPlane
///
std::shared_ptr<SurfaceMesh> toQuadSurfaceMesh(std::shared_ptr<Plane> plane);
///
/// \brief Returns the number of open edges, use to tell if manifold (==0)
///
......
......@@ -258,10 +258,9 @@ VTKSurfaceMeshRenderDelegate::geometryModified(Event* imstkNotUsed(e))
}
m_cellArray->Modified();
}
//vertexOrIndexBufferChanged = true;
}
if (/*vertexOrIndexBufferChanged && */ m_visualModel->getRenderMaterial()->getRecomputeVertexNormals())
if (m_visualModel->getRenderMaterial()->getRecomputeVertexNormals())
{
geometry->computeVertexNormals();
std::shared_ptr<VecDataArray<double, 3>> normals = geometry->getVertexNormals();
......
......@@ -170,10 +170,12 @@ VTKTetrahedralMeshRenderDelegate::geometryModified(Event* imstkNotUsed(e))
// Update the pointer of the coupled array
m_mappedVertexArray->SetNumberOfComponents(3);
m_mappedVertexArray->SetArray(reinterpret_cast<double*>(m_vertices->getPointer()), m_vertices->size() * 3, 1);
m_mappedVertexArray->Modified();
}
m_mesh->GetPoints()->SetNumberOfPoints(m_vertices->size());
}
m_mappedVertexArray->Modified();
// Test if the index buffer changed
if (m_indices != geometry->getTetrahedraIndices())
{
......@@ -182,15 +184,16 @@ VTKTetrahedralMeshRenderDelegate::geometryModified(Event* imstkNotUsed(e))
{
// Copy cells
m_cellArray->Reset();
vtkIdType cell[3];
vtkIdType cell[4];
for (const auto& t : *m_indices)
{
for (size_t i = 0; i < 3; ++i)
for (size_t i = 0; i < 4; i++)
{
cell[i] = t[i];
}
m_cellArray->InsertNextCell(3, cell);
m_cellArray->InsertNextCell(4, cell);
}
m_mesh->SetCells(VTK_TETRA, m_cellArray);
m_cellArray->Modified();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment