Skip to content
Snippets Groups Projects
Commit 59001a18 authored by Andrew Wilson's avatar Andrew Wilson :elephant:
Browse files

Merge branch 'LinuxKeyFix' into 'master'

BUG: Fix linux events, keys and mouse

See merge request iMSTK/iMSTK!556
parents 87ac099d 63c4c104
No related branches found
No related tags found
No related merge requests found
......@@ -27,16 +27,16 @@
#include "imstkSurfaceMesh.h"
#include "imstkTetrahedralMesh.h"
#include "imstkGeometryUtilities.h"
#include <chrono>
using namespace std::chrono;
#include <chrono>
using namespace std::chrono;
using namespace imstk;
bool verifyColoring(const Graph& graph, const std::vector<unsigned short>& colors)
bool
verifyColoring(const Graph& graph, const std::vector<unsigned short>& colors)
{
std::unordered_set<size_t> edges;
for (size_t i=0; i<graph.size(); ++i)
for (size_t i = 0; i < graph.size(); ++i)
{
unsigned short color_i = colors[i];
graph.getEdges(i, edges);
......@@ -52,7 +52,6 @@ bool verifyColoring(const Graph& graph, const std::vector<unsigned short>& color
return true;
}
///
/// \brief This example demonstrates the imstk graph usage
/// Usage: Example-Graph.exe [method=greedy/welsh-powell]
......@@ -126,15 +125,15 @@ main(int argc, char** argv)
{
// auto colorsGVMesh = apiutils::getMeshGraph(tetMesh)->doColoring(method, true);
{
auto graph = apiutils::getMeshGraph(tetMesh);
auto t_start = high_resolution_clock::now();
auto graph = apiutils::getMeshGraph(tetMesh);
auto t_start = high_resolution_clock::now();
auto colorsGVMesh = graph->doColoring(method, false);
verifyColoring(*graph, colorsGVMesh.first);
std::cout << "number of colors = " << colorsGVMesh.second << std::endl;
auto t_end = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(t_end - t_start);
auto t_end = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(t_end - t_start);
std::cout << "runtime = " << duration.count() << " microseconds" << endl;
std::cout << "runtime = " << duration.count() << " microseconds" << endl;
}
// imstkNew<SurfaceMesh> surfMesh;
......@@ -147,5 +146,3 @@ main(int argc, char** argv)
return 0;
}
......@@ -42,7 +42,7 @@ Graph::addEdge(const size_t v, const size_t w)
}
void
Graph::getEdges(const size_t v, edgeType& edges) const
Graph::getEdges(const size_t v, edgeType& edges) const
{
edges = m_adjList[v];
}
......
......@@ -52,7 +52,7 @@ public:
VisualModel(std::shared_ptr<DebugRenderGeometry> geometry,
std::shared_ptr<RenderMaterial> renderMaterial);
VisualModel() = default;
virtual ~VisualModel() override = default;
virtual ~VisualModel() override= default;
public:
SIGNAL(VisualModel,modified);
......
......@@ -5,6 +5,12 @@
file(GLOB VTK_H_FILES VTKRenderer/imstk*.h)
file(GLOB VTK_CPP_FILES VTKRenderer/imstk*.cpp)
if(WIN32)
list(APPEND ExclusionFiles
VTKRenderer/imstkVtkXRenderWindowInteractor2.h
VTKRenderer/imstkVtkXRenderWindowInteractor2.cpp)
endif()
file(GLOB VULKAN_H_FILES VulkanRenderer/imstk*.h)
file(GLOB VULKAN_CPP_FILES VulkanRenderer/imstk*.cpp)
......@@ -31,6 +37,8 @@ imstk_add_library(SimulationManager
${SIMULATIONMANAGER_CPP_FILES}
SUBDIR_LIST
${SIMULATIONMANAGER_SUBDIR}
EXCLUDE_FILES
${Exclusion_FILES}
DEPENDS
Scene
Rendering
......
......@@ -30,7 +30,6 @@
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkTextActor.h>
#include <vtkOpenGLRenderWindow.h>
......@@ -39,6 +38,8 @@
#ifdef WIN32
#include <vtkWin32HardwareWindow.h>
#include <vtkWin32RenderWindowInteractor.h>
#else
#include "imstkVtkXRenderWindowInteractor2.h"
#endif
namespace imstk
......@@ -53,8 +54,13 @@ VTKViewer::VTKViewer(std::string name) : AbstractVTKViewer(name),
m_vtkInteractorStyle = std::dynamic_pointer_cast<vtkInteractorStyle>(m_interactorStyle);
// Create the interactor
#ifdef WIN32
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetInteractorStyle(m_vtkInteractorStyle.get());
#else
vtkSmartPointer<vtkXRenderWindowInteractor2> iren = vtkSmartPointer<vtkXRenderWindowInteractor2>::New();
iren->SetInteractorStyle(m_vtkInteractorStyle.get());
#endif
// Create the RenderWindow
m_vtkRenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
......
This diff is collapsed.
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#pragma once
//===========================================================
// now we define the C++ class
#include "vtkRenderWindowInteractor.h"
#include <X11/Xlib.h> // Needed for X types in the public interface
class vtkCallbackCommand;
class vtkXRenderWindowInteractor2Internals;
///
/// \class vtkXRenderWindowInteractor2
///
/// \brief This class exists to fix bugs in VTK 9.0, which are, as typing this
/// already merged into VTK master, this class should be deleted when upgrading
/// to yet to be released VTK 10
///
class vtkXRenderWindowInteractor2 : public vtkRenderWindowInteractor
{
public:
static vtkXRenderWindowInteractor2* New();
vtkTypeMacro(vtkXRenderWindowInteractor2, vtkRenderWindowInteractor);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Initializes the event handlers without an XtAppContext. This is
* good for when you don't have a user interface, but you still
* want to have mouse interaction.
*/
void Initialize() override;
/**
* Break the event loop on 'q','e' keypress. Want more ???
*/
void TerminateApp() override;
/**
* Run the event loop and return. This is provided so that you can
* implement your own event loop but yet use the vtk event handling as
* well.
*/
void ProcessEvents() override;
//@{
/**
* Enable/Disable interactions. By default interactors are enabled when
* initialized. Initialize() must be called prior to enabling/disabling
* interaction. These methods are used when a window/widget is being
* shared by multiple renderers and interactors. This allows a "modal"
* display where one interactor is active when its data is to be displayed
* and all other interactors associated with the widget are disabled
* when their data is not displayed.
*/
void Enable() override;
void Disable() override;
//@}
/**
* Update the Size data member and set the associated RenderWindow's
* size.
*/
void UpdateSize(int, int) override;
/**
* Re-defines virtual function to get mouse position by querying X-server.
*/
void GetMousePosition(int* x, int* y) override;
void DispatchEvent(XEvent*);
protected:
vtkXRenderWindowInteractor2();
~vtkXRenderWindowInteractor2() override;
/**
* Update the Size data member and set the associated RenderWindow's
* size but do not resize the XWindow.
*/
void UpdateSizeNoXResize(int, int);
// Using static here to avoid destroying context when many apps are open:
static int NumAppInitialized;
Display* DisplayId;
Window WindowId;
Atom KillAtom;
int PositionBeforeStereo[2];
vtkXRenderWindowInteractor2Internals* Internal;
// Drag and drop related
Window XdndSource;
Atom XdndPositionAtom;
Atom XdndDropAtom;
Atom XdndActionCopyAtom;
Atom XdndStatusAtom;
Atom XdndFinishedAtom;
//@{
/**
* X-specific internal timer methods. See the superclass for detailed
* documentation.
*/
int InternalCreateTimer(int timerId, int timerType, unsigned long duration) override;
int InternalDestroyTimer(int platformTimerId) override;
//@}
void FireTimers();
/**
* This will start up the X event loop and never return. If you
* call this method it will loop processing X events until the
* application is exited.
*/
void StartEventLoop() override;
private:
vtkXRenderWindowInteractor2(const vtkXRenderWindowInteractor2&) = delete;
void operator=(const vtkXRenderWindowInteractor2&) = delete;
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment