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

merge DataUpdateAndVTK9Dependence

parents 5c42229e f796986e
No related branches found
No related tags found
No related merge requests found
Showing
with 206 additions and 248 deletions
......@@ -10,78 +10,47 @@ endif()
set(${PROJECT_NAME}_VTK_REPO_SOURCE "9.0" CACHE STRING "Select VTK Source Branch/Tag")
set(VTK_SOURCES "8.2;8.9;9.0;master;release;nightly-master" CACHE INTERNAL "List of available VTK branch,tags to get")
set(VTK_SOURCES "9.0;master;release;nightly-master" CACHE INTERNAL "List of available VTK branch,tags to get")
set_property(CACHE ${PROJECT_NAME}_VTK_REPO_SOURCE PROPERTY STRINGS ${VTK_SOURCES})
if (${${PROJECT_NAME}_ENABLE_OPENVR})
set(VTK_OPENVR "WANT")
else()
set(VTK_OPENVR "DONT_WANT")
endif()
set(VTK_MODULE_SETTINGS
-DVTK_MODULE_ENABLE_VTK_ChartsCore:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingOpenGL2:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOExport:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOImport:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOParallel:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOParallelXML:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOXML:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOLegacy:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOPLY:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOGeometry:STRING=YES
-DVTK_MODULE_ENABLE_VTK_InteractionStyle:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingAnnotation:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingOpenVR:STRING=${VTK_OPENVR}
-DVTK_MODULE_ENABLE_VTK_InteractionWidgets:STRING=YES
-DVTK_MODULE_ENABLE_VTK_glew:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingContext2D:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingVolumeOpenGL2:STRING=YES
-DVTK_MODULE_ENABLE_VTK_ViewsContext2D:STRING=YES
-DVTK_BUILD_EXAMPLES:STRING=DONT_WANT
-DVTK_BUILD_TESTING:STRING=OFF
-DVTK_GROUP_ENABLE_StandAlone:STRING=DONT_WANT
-DVTK_GROUP_ENABLE_Rendering:STRING=DONT_WANT
-DVTK_MODULE_ENABLE_MODULE_FiltersModeling:STRING=YES
-DVTK_MODULE_ENABLE_MODULE_FiltersExtraction:STRING=YES
)
set(${PROJECT_NAME}_VTK_SOURCE GIT_REPOSITORY https://gitlab.kitware.com/vtk/vtk.git)
if(${PROJECT_NAME}_VTK_REPO_SOURCE EQUAL "8.2")
set(VTK_MODULE_SETTINGS
-DModule_vtkChartsCore:BOOL=ON
-DModule_vtkRenderingOpenGL2:BOOL=ON
-DModule_vtkIOXML:BOOL=ON
-DModule_vtkIOLegacy:BOOL=ON
-DModule_vtkIOPLY:BOOL=ON
-DModule_vtkIOGeometry:BOOL=ON
-DModule_vtkInteractionStyle:BOOL=ON
-DModule_vtkRenderingAnnotation:BOOL=ON
-DModule_vtkRenderingOpenVR:BOOL=${${PROJECT_NAME}_ENABLE_VR}
-DModule_vtkInteractionWidgets:BOOL=ON
-DModule_vtkglew:BOOL=ON
-DModule_vtkRenderingContext2D:BOOL=ON
-DModule_vtkRenderingVolumeOpenGL2:BOOL=ON
-DModule_vtkViewsContext2D:BOOL=ON
-DBUILD_EXAMPLES:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
-DVTK_Group_StandAlone:BOOL=OFF
-DVTK_Group_Rendering:BOOL=OFF
)
set(${PROJECT_NAME}_VTK_SOURCE URL https://gitlab.kitware.com/vtk/vtk/-/archive/v8.2.0/vtk-v8.2.0.tar.gz)
set(${PROJECT_NAME}_VTK_HASH URL_HASH MD5=4115fb396f99466fe444472f412118cd)
if(${PROJECT_NAME}_VTK_REPO_SOURCE EQUAL "9.0")
set(${PROJECT_NAME}_VTK_HASH GIT_TAG ab278e87b181e3a02082bea7361fbaa3ddafb3ad)
else()
if (${${PROJECT_NAME}_ENABLE_OPENVR})
set(VTK_OPENVR "WANT")
else()
set(VTK_OPENVR "DONT_WANT")
endif()
set(VTK_MODULE_SETTINGS
-DVTK_MODULE_ENABLE_VTK_ChartsCore:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingOpenGL2:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOExport:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOImport:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOParallel:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOParallelXML:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOXML:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOLegacy:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOPLY:STRING=YES
-DVTK_MODULE_ENABLE_VTK_IOGeometry:STRING=YES
-DVTK_MODULE_ENABLE_VTK_InteractionStyle:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingAnnotation:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingOpenVR:STRING=${VTK_OPENVR}
-DVTK_MODULE_ENABLE_VTK_InteractionWidgets:STRING=YES
-DVTK_MODULE_ENABLE_VTK_glew:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingContext2D:STRING=YES
-DVTK_MODULE_ENABLE_VTK_RenderingVolumeOpenGL2:STRING=YES
-DVTK_MODULE_ENABLE_VTK_ViewsContext2D:STRING=YES
-DVTK_BUILD_EXAMPLES:STRING=DONT_WANT
-DVTK_BUILD_TESTING:STRING=OFF
-DVTK_GROUP_ENABLE_StandAlone:STRING=DONT_WANT
-DVTK_GROUP_ENABLE_Rendering:STRING=DONT_WANT
-DVTK_MODULE_ENABLE_MODULE_FiltersModeling:STRING=YES
-DVTK_MODULE_ENABLE_MODULE_FiltersExtraction:STRING=YES
)
set(${PROJECT_NAME}_VTK_SOURCE GIT_REPOSITORY https://gitlab.kitware.com/vtk/vtk.git)
# TODO Update to a zip download when there is a new version after 8.2
if(${PROJECT_NAME}_VTK_REPO_SOURCE EQUAL "8.9")
set(${PROJECT_NAME}_VTK_HASH GIT_TAG 9b6a039f43404053a0653f742148d123f6ada7d6)
elseif(${PROJECT_NAME}_VTK_REPO_SOURCE EQUAL "9.0")
set(${PROJECT_NAME}_VTK_HASH GIT_TAG ab278e87b181e3a02082bea7361fbaa3ddafb3ad)
else()
set(${PROJECT_NAME}_VTK_HASH GIT_TAG origin/${${PROJECT_NAME}_VTK_REPO_SOURCE})
endif()
set(${PROJECT_NAME}_VTK_HASH GIT_TAG origin/${${PROJECT_NAME}_VTK_REPO_SOURCE})
endif()
#-----------------------------------------------------------------------------
......@@ -100,6 +69,6 @@ imstk_add_external_project( VTK
#VERBOSE
)
if(NOT USE_SYSTEM_VTK)
set(VTK_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake/vtk-8.2)
set(VTK_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake/vtk-9.0)
#message(STATUS "VTK_DIR : ${VTK_DIR}")
endif()
message(STATUS "Patching VTK")
file(COPY ${VTK_SOURCE_DIR}/Common/Core/vtkEventData.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/vtk-8.2/)
file(COPY ${VTK_SOURCE_DIR}/Rendering/OpenVR/vtkOpenVROverlayInternal.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/vtk-8.2/)
\ No newline at end of file
......@@ -274,37 +274,30 @@ endif()
# VTK
find_package(VTK CONFIG)
if (VTK_VERSION VERSION_LESS "8.90")
# Modules are linked via `vtkCommonCore`
# VTK_DEFINITIONS has autoinit information
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
# modules are linked via `VTK::CommonCore`
# vtk_module_autoinit is needed
find_package(VTK COMPONENTS
ChartsCore
CommonCore
CommonDataModel
FiltersGeneral
FiltersSources
FiltersModeling
FiltersExtraction
IOExport
IOImport
IOPLY
IOParallel
IOParallelXML
ImagingCore
InteractionStyle
RenderingAnnotation
RenderingCore
RenderingOpenGL2
RenderingVolume
RenderingVolumeOpenGL2
ViewsContext2D
)
endif()
# modules are linked via `VTK::CommonCore`
# vtk_module_autoinit is needed
find_package(VTK COMPONENTS
ChartsCore
CommonCore
CommonDataModel
FiltersGeneral
FiltersSources
FiltersModeling
FiltersExtraction
IOExport
IOImport
IOPLY
IOParallel
IOParallelXML
ImagingCore
InteractionStyle
RenderingAnnotation
RenderingCore
RenderingOpenGL2
RenderingVolume
RenderingVolumeOpenGL2
ViewsContext2D
)
# Vulkan
set(Vulkan_Dependency)
......
8e9f278002a3a17b2bb3471523672947034de0ed87d07dd6a422e2b9157bd6f91e4be5df4b3e820ab3f722b599b10d0a77c68ac0d320d1a2ecc94515aefb11fe
\ No newline at end of file
30c084333b758578905445e55918095b12979fc50bebe4d23f7903f6aae50c1bc4e9aceec22ea1c62491f64db509835d3c0e8310ecbdb2ee4f4fd6af401f5e85
\ No newline at end of file
......@@ -96,17 +96,17 @@ buildStairs(int nSteps, double width, double height, double depth)
}
static std::shared_ptr<PbdObject>
makeDragonPbdObject(const std::string& name)
makeArmadilloPbdObject(const std::string& name)
{
auto pbdObj = std::make_shared<PbdObject>(name);
// Read in the dragon mesh
auto highResSurfMesh = std::dynamic_pointer_cast<SurfaceMesh>(MeshIO::read(iMSTK_DATA_ROOT "/asianDragon/asianDragon.obj"));
auto coarseTetMesh = std::dynamic_pointer_cast<TetrahedralMesh>(MeshIO::read(iMSTK_DATA_ROOT "/asianDragon/asianDragon.veg"));
highResSurfMesh->translate(Vec3d(0.0f, 10.0f, 0.0f), Geometry::TransformType::ApplyToData);
coarseTetMesh->translate(Vec3d(0.0f, 10.0f, 0.0f), Geometry::TransformType::ApplyToData);
auto coarseSurfMesh = std::make_shared<SurfaceMesh>();
coarseTetMesh->extractSurfaceMesh(coarseSurfMesh, true);
// Read in the armadillo mesh
auto tetMesh = std::dynamic_pointer_cast<TetrahedralMesh>(MeshIO::read(iMSTK_DATA_ROOT "armadillo/armadillo_volume.vtk"));
tetMesh->scale(0.07, Geometry::TransformType::ApplyToData);
tetMesh->rotate(Vec3d(1.0, 0.0, 0.0), 1.3, Geometry::TransformType::ApplyToData);
tetMesh->translate(Vec3d(0.0f, 10.0f, 0.0f), Geometry::TransformType::ApplyToData);
auto surfMesh = std::make_shared<SurfaceMesh>();
tetMesh->extractSurfaceMesh(surfMesh, true);
// Setup the Parameters
auto pbdParams = std::make_shared<PBDModelConfig>();
......@@ -117,27 +117,26 @@ makeDragonPbdObject(const std::string& name)
pbdParams->m_uniformMassValue = 1.0;
pbdParams->m_gravity = Vec3d(0, -10.0, 0);
pbdParams->m_defaultDt = 0.01;
pbdParams->m_iterations = 10;
pbdParams->m_iterations = 5;
pbdParams->collisionParams->m_proximity = 0.3;
pbdParams->collisionParams->m_stiffness = 0.1;
// Setup the Model
auto pbdModel = std::make_shared<PbdModel>();
pbdModel->setModelGeometry(coarseTetMesh);
pbdModel->setModelGeometry(tetMesh);
pbdModel->configure(pbdParams);
// Setup the VisualModel
auto material = std::make_shared<RenderMaterial>();
material->setDisplayMode(RenderMaterial::DisplayMode::WireframeSurface);
auto surfMeshModel = std::make_shared<VisualModel>(highResSurfMesh);
auto surfMeshModel = std::make_shared<VisualModel>(surfMesh);
surfMeshModel->setRenderMaterial(material);
// Setup the Object
pbdObj->addVisualModel(surfMeshModel);
pbdObj->setCollidingGeometry(coarseSurfMesh);
pbdObj->setPhysicsGeometry(coarseTetMesh);
pbdObj->setPhysicsToCollidingMap(std::make_shared<OneToOneMap>(coarseTetMesh, coarseSurfMesh));
pbdObj->setPhysicsToVisualMap(std::make_shared<TetraTriangleMap>(coarseTetMesh, highResSurfMesh));
pbdObj->setCollidingGeometry(surfMesh);
pbdObj->setPhysicsGeometry(tetMesh);
pbdObj->setPhysicsToVisualMap(std::make_shared<TetraTriangleMap>(tetMesh, surfMesh));
pbdObj->setDynamicalModel(pbdModel);
return pbdObj;
......@@ -189,7 +188,7 @@ main()
scene->getCamera()->setFocalPoint(0.0, 0.0, 0.0);
// Create and add the dragon to the scene
auto pbdDragon1 = makeDragonPbdObject("PbdDragon1");
auto pbdDragon1 = makeArmadilloPbdObject("PbdArmadillo1");
scene->addSceneObject(pbdDragon1);
auto stairObj = makeStairsPbdObject("PbdStairs", 12, 20.0, 10.0, 20.0);
......
......@@ -41,12 +41,10 @@ using namespace imstk;
/// \brief Create a PbdObject and add it to a \p scene
///
std::shared_ptr<PbdObject> createAndAddPbdObject(std::shared_ptr<Scene> scene,
const std::string& surfMeshName,
const std::string& tetMeshName);
// mesh file names
const std::string& surfMeshFileName = iMSTK_DATA_ROOT "/asianDragon/asianDragon.obj";
const std::string& tetMeshFileName = iMSTK_DATA_ROOT "/asianDragon/asianDragon.veg";
const std::string& tetMeshFileName = iMSTK_DATA_ROOT "textured_organs/heart_volume.vtk";
///
/// \brief This example demonstrates the soft body simulation
......@@ -60,7 +58,7 @@ main()
scene->getCamera()->setPosition(0, 2.0, 15.0);
// create and add a PBD object
createAndAddPbdObject(scene, surfMeshFileName, tetMeshFileName);
createAndAddPbdObject(scene, tetMeshFileName);
// Setup plane
auto planeGeom = std::make_shared<Plane>();
......@@ -86,17 +84,21 @@ main()
std::shared_ptr<PbdObject>
createAndAddPbdObject(std::shared_ptr<Scene> scene,
const std::string& surfMeshName,
const std::string& tetMeshName)
{
auto surfMesh = std::dynamic_pointer_cast<SurfaceMesh>(MeshIO::read(surfMeshName));
auto tetMesh = std::dynamic_pointer_cast<TetrahedralMesh>(MeshIO::read(tetMeshName));
//auto tetMesh = TetrahedralMesh::createTetrahedralMeshCover(surfMesh, 10, 6, 6);
tetMesh->rotate(Vec3d(1.0, 0.0, 0.0), -1.3, Geometry::TransformType::ApplyToData);
auto surfMesh = std::make_shared<SurfaceMesh>();
tetMesh->extractSurfaceMesh(surfMesh, true);
auto map = std::make_shared<TetraTriangleMap>(tetMesh, surfMesh);
auto material = std::make_shared<RenderMaterial>();
material->setDisplayMode(RenderMaterial::DisplayMode::Surface);
material->setColor(Color(147.0 / 255.0, 32.0 / 255.0, 30.0 / 255.0));
material->setMetalness(0.9f);
material->setRoughness(0.5);
material->setShadingModel(RenderMaterial::ShadingModel::PBR);
auto surfMeshModel = std::make_shared<VisualModel>(surfMesh);
surfMeshModel->setRenderMaterial(material);
......@@ -108,15 +110,15 @@ createAndAddPbdObject(std::shared_ptr<Scene> scene,
auto pbdParams = std::make_shared<PBDModelConfig>();
// FEM constraint
pbdParams->m_femParams->m_YoungModulus = 1000.0;
pbdParams->m_femParams->m_YoungModulus = 500.0;
pbdParams->m_femParams->m_PoissonRatio = 0.3;
pbdParams->m_fixedNodeIds = { 50, 126, 177 };
pbdParams->m_fixedNodeIds = { 350 };
pbdParams->enableFEMConstraint(PbdConstraint::Type::FEMTet, PbdFEMConstraint::MaterialType::StVK);
// Other parameters
pbdParams->m_uniformMassValue = 1.0;
pbdParams->m_gravity = Vec3d(0, -9.8, 0);
pbdParams->m_iterations = 15;
pbdParams->m_iterations = 10;
// pbdParams->m_solverType = PbdConstraint::SolverType::PBD;
// Set the parameters
......
......@@ -95,7 +95,6 @@ makePbdString(
// Setup the VisualModel
std::shared_ptr<RenderMaterial> material = std::make_shared<RenderMaterial>();
material->setBackFaceCulling(false);
material->setColor(color);
material->setEdgeColor(color);
material->setLineWidth(2.0f);
material->setPointSize(6.0f);
......
......@@ -68,11 +68,11 @@ makeStringGeometry(const Vec3d& pos, const size_t numVerts, const double stringL
static std::shared_ptr<PbdObject>
makePbdString(
const std::string& name,
const Vec3d& pos,
const Vec3d& pos,
const size_t numVerts,
const double stringLength,
const double bendStiffness,
const Color& color)
const Color& color)
{
std::shared_ptr<PbdObject> stringObj = std::make_shared<PbdObject>(name);
......@@ -83,10 +83,10 @@ makePbdString(
auto pbdParams = std::make_shared<PBDModelConfig>();
pbdParams->enableConstraint(PbdConstraint::Type::Distance, 1e7);
pbdParams->enableConstraint(PbdConstraint::Type::Bend, bendStiffness);
pbdParams->m_fixedNodeIds = { 0 };
pbdParams->m_fixedNodeIds = { 0 };
pbdParams->m_uniformMassValue = 5.0;
pbdParams->m_gravity = Vec3d(0, -9.8, 0);
pbdParams->m_defaultDt = 0.0005;
pbdParams->m_gravity = Vec3d(0, -9.8, 0);
pbdParams->m_defaultDt = 0.0005;
pbdParams->m_iterations = 5;
// Setup the Model
......@@ -97,7 +97,7 @@ makePbdString(
// Setup the VisualModel
std::shared_ptr<RenderMaterial> material = std::make_shared<RenderMaterial>();
material->setBackFaceCulling(false);
material->setColor(color);
material->setEdgeColor(color);
material->setLineWidth(2.0f);
material->setDisplayMode(RenderMaterial::DisplayMode::Wireframe);
......@@ -114,11 +114,11 @@ makePbdString(
static std::vector<std::shared_ptr<PbdObject>>
makePbdStrings(const size_t numStrings,
const size_t numVerts,
const double stringSpacing,
const double stringLength,
const Color& startColor,
const Color& endColor)
const size_t numVerts,
const double stringSpacing,
const double stringLength,
const Color& startColor,
const Color& endColor)
{
std::vector<std::shared_ptr<PbdObject>> pbdStringObjs(numStrings);
......@@ -127,7 +127,7 @@ makePbdStrings(const size_t numStrings,
for (unsigned int i = 0; i < numStrings; i++)
{
const Vec3d tipPos = Vec3d(static_cast<double>(i) * stringSpacing - size * 0.5, stringLength * 0.5, 0.0);
const double t = static_cast<double>(i) / (numStrings - 1);
const double t = static_cast<double>(i) / (numStrings - 1);
pbdStringObjs[i] = makePbdString(
"String " + std::to_string(i),
......@@ -141,14 +141,14 @@ makePbdStrings(const size_t numStrings,
return pbdStringObjs;
}
const double dt = 0.0005;
const double radius = 1.5;
const size_t numStrings = 8; // Number of strings
const size_t numVerts = 30; // Number of vertices on each string
const double dt = 0.0005;
const double radius = 1.5;
const size_t numStrings = 8; // Number of strings
const size_t numVerts = 30; // Number of vertices on each string
const double stringSpacing = 2.0; // How far each string is apart
const double stringLength = 10.0; // Total length of string
const Color startColor = Color(1.0, 0.0, 0.0); // Color of first string
const Color endColor = Color(0.0, 1.0, 0.0); // Color of last string
const double stringLength = 10.0; // Total length of string
const Color startColor = Color(1.0, 0.0, 0.0); // Color of first string
const Color endColor = Color(0.0, 1.0, 0.0); // Color of last string
///
/// \brief This examples uses the timing features of the task graph. This allows one
......@@ -165,6 +165,7 @@ main()
// Setup N separate strings with varying bend stiffnesses
std::vector<std::shared_ptr<PbdObject>> pbdStringObjs =
makePbdStrings(numStrings, numVerts, stringSpacing, stringLength, startColor, endColor);
// Add them to the scene
for (std::shared_ptr<PbdObject> obj : pbdStringObjs)
{
scene->addSceneObject(obj);
......@@ -176,7 +177,6 @@ main()
// Move the points every frame
double t = 0.0;
auto movePoints =
[&pbdStringObjs, &t](Module* module)
{
......
......@@ -124,9 +124,9 @@ Geometry::rotate(const Quatd& q, TransformType type)
}
void
Geometry::rotate(const Vec3d& axis, double angle, TransformType type)
Geometry::rotate(const Vec3d& axis, double radians, TransformType type)
{
this->rotate(Rotd(angle, axis).toRotationMatrix(), type);
this->rotate(Rotd(radians, axis).toRotationMatrix(), type);
}
void
......
......@@ -118,7 +118,7 @@ public:
///
void rotate(const Quatd& q, TransformType type = TransformType::ConcatenateToTransform);
void rotate(const Mat3d& m, TransformType type = TransformType::ConcatenateToTransform);
void rotate(const Vec3d& axis, double angle, TransformType type = TransformType::ConcatenateToTransform);
void rotate(const Vec3d& axis, double radians, TransformType type = TransformType::ConcatenateToTransform);
///
/// \brief Scale in Cartesian directions
......
......@@ -419,76 +419,76 @@ VTKRenderer::getAxesVisibility() const
return m_AxesActor->GetVisibility();
}
void
VTKRenderer::setTimeTable(const std::unordered_map<std::string, double>& timeTable)
{
// Sort by elapsed times
std::vector<std::pair<std::string, double>> nameToTimesVec(timeTable.begin(), timeTable.end());
std::sort(nameToTimesVec.begin(), nameToTimesVec.end(),
[](const std::pair<std::string, double>& a, const std::pair<std::string, double>& b) { return a.second < b.second; });
// Construct vtkTable from provided data
vtkSmartPointer<vtkDoubleArray> xIndices = vtkDoubleArray::SafeDownCast(m_timeTable->GetColumn(0));
vtkSmartPointer<vtkDoubleArray> yElapsedTimes = vtkDoubleArray::SafeDownCast(m_timeTable->GetColumn(1));
vtkSmartPointer<vtkStringArray> labels = vtkStringArray::SafeDownCast(m_timeTable->GetColumn(2));
labels->SetNumberOfValues(nameToTimesVec.size());
xIndices->SetNumberOfValues(nameToTimesVec.size());
yElapsedTimes->SetNumberOfValues(nameToTimesVec.size());
for (size_t i = 0; i < nameToTimesVec.size(); i++)
{
labels->SetValue(i, nameToTimesVec[i].first.c_str());
xIndices->SetValue(i, i + 1);
yElapsedTimes->SetValue(i, nameToTimesVec[i].second);
}
// The range for the x axis is based on history of the elapsed times
vtkAxis* botAxis = m_timeTableChart->GetAxis(vtkAxis::BOTTOM);
// Get the previous and current range
double newMaxElapsed = yElapsedTimes->GetRange()[1];
yElapsedTimes->Modified();
double currMaxElapsed = botAxis->GetMaximum();
// Always respect the max as all information should be shown
if (newMaxElapsed > currMaxElapsed)
{
botAxis->SetRange(0.0, newMaxElapsed);
}
// But if current elapsed is less than the existing one we can lag
else
{
// Lag downscaling by 400 iterations
if (m_timeTableIter % 400 == 0)
{
botAxis->SetRange(0.0, newMaxElapsed);
}
else
{
botAxis->SetRange(0.0, currMaxElapsed);
}
m_timeTableIter++;
}
botAxis->Modified();
vtkAxis* leftAxis = m_timeTableChart->GetAxis(vtkAxis::LEFT);
leftAxis->SetRange(xIndices->GetRange());
leftAxis->SetCustomTickPositions(xIndices, labels);
m_timeTable->Modified();
}
void
VTKRenderer::setTimeTableVisibility(const bool visible)
{
m_timeTableChartActor->SetVisibility(visible);
}
bool
VTKRenderer::getTimeTableVisibility() const
{
return m_timeTableChartActor->GetVisibility();
}
//void
//VTKRenderer::setTimeTable(const std::unordered_map<std::string, double>& timeTable)
//{
// // Sort by elapsed times
// std::vector<std::pair<std::string, double>> nameToTimesVec(timeTable.begin(), timeTable.end());
// std::sort(nameToTimesVec.begin(), nameToTimesVec.end(),
// [](const std::pair<std::string, double>& a, const std::pair<std::string, double>& b) { return a.second < b.second; });
//
// // Construct vtkTable from provided data
// vtkSmartPointer<vtkDoubleArray> xIndices = vtkDoubleArray::SafeDownCast(m_timeTable->GetColumn(0));
// vtkSmartPointer<vtkDoubleArray> yElapsedTimes = vtkDoubleArray::SafeDownCast(m_timeTable->GetColumn(1));
// vtkSmartPointer<vtkStringArray> labels = vtkStringArray::SafeDownCast(m_timeTable->GetColumn(2));
//
// labels->SetNumberOfValues(nameToTimesVec.size());
// xIndices->SetNumberOfValues(nameToTimesVec.size());
// yElapsedTimes->SetNumberOfValues(nameToTimesVec.size());
// for (size_t i = 0; i < nameToTimesVec.size(); i++)
// {
// labels->SetValue(i, nameToTimesVec[i].first.c_str());
// xIndices->SetValue(i, i + 1);
// yElapsedTimes->SetValue(i, nameToTimesVec[i].second);
// }
//
// // The range for the x axis is based on history of the elapsed times
// vtkAxis* botAxis = m_timeTableChart->GetAxis(vtkAxis::BOTTOM);
//
// // Get the previous and current range
// double newMaxElapsed = yElapsedTimes->GetRange()[1];
// yElapsedTimes->Modified();
// double currMaxElapsed = botAxis->GetMaximum();
//
// // Always respect the max as all information should be shown
// if (newMaxElapsed > currMaxElapsed)
// {
// botAxis->SetRange(0.0, newMaxElapsed);
// }
// // But if current elapsed is less than the existing one we can lag
// else
// {
// // Lag downscaling by 400 iterations
// if (m_timeTableIter % 400 == 0)
// {
// botAxis->SetRange(0.0, newMaxElapsed);
// }
// else
// {
// botAxis->SetRange(0.0, currMaxElapsed);
// }
// m_timeTableIter++;
// }
// botAxis->Modified();
//
// vtkAxis* leftAxis = m_timeTableChart->GetAxis(vtkAxis::LEFT);
// leftAxis->SetRange(xIndices->GetRange());
// leftAxis->SetCustomTickPositions(xIndices, labels);
//
// m_timeTable->Modified();
//}
//
//void
//VTKRenderer::setTimeTableVisibility(const bool visible)
//{
// m_timeTableChartActor->SetVisibility(visible);
//}
//
//bool
//VTKRenderer::getTimeTableVisibility() const
//{
// return m_timeTableChartActor->GetVisibility();
//}
void
VTKRenderer::updateSceneCamera(std::shared_ptr<Camera> imstkCam)
......
......@@ -102,17 +102,17 @@ public:
///
/// \brief Sets the benchmarking table using unordered_map
///
void setTimeTable(const std::unordered_map<std::string, double>& timeTable);
//void setTimeTable(const std::unordered_map<std::string, double>& timeTable);
///
/// \brief Set the visibility of the benchmark graph
///
void setTimeTableVisibility(const bool visible);
//void setTimeTableVisibility(const bool visible);
///
/// \brief Get the visibility of the benchmark graph
///
bool getTimeTableVisibility() const;
//bool getTimeTableVisibility() const;
///
/// \brief Updates the scene camera's position and orientation
......
......@@ -80,9 +80,9 @@ VTKViewer::VTKViewer(SimulationManager* manager /*= nullptr*/, bool enableVR /*=
#endif
// Setup callback for timer on the interactor
timerCallbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
/*timerCallbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
timerCallbackCommand->SetCallback(timerCallback);
timerCallbackCommand->SetClientData(this);
timerCallbackCommand->SetClientData(this);*/
}
void
......@@ -190,13 +190,13 @@ VTKViewer::startRenderingLoop()
m_vtkRenderWindow->GetInteractor()->CreateOneShotTimer(0);
// If the Scene wants benchmarking hookup timer to update the table
auto vtkRen = std::dynamic_pointer_cast<VTKRenderer>(getActiveRenderer());
/*auto vtkRen = std::dynamic_pointer_cast<VTKRenderer>(getActiveRenderer());
vtkRen->setTimeTableVisibility(m_activeScene->getConfig()->taskTimingEnabled);
if (m_activeScene->getConfig()->taskTimingEnabled)
{
m_vtkRenderWindow->GetInteractor()->AddObserver(vtkCommand::TimerEvent, timerCallbackCommand);
m_vtkRenderWindow->GetInteractor()->CreateRepeatingTimer(500);
}
}*/
m_vtkRenderWindow->SetWindowName(m_config->m_windowName.c_str());
m_vtkRenderWindow->GetInteractor()->Start();
......@@ -254,17 +254,17 @@ VTKViewer::getTextStatusManager()
return m_vtkInteractorStyle->getTextStatusManager();
}
void
VTKViewer::timerCallback(vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* clientData, void* vtkNotUsed(callData))
{
VTKViewer* self = static_cast<VTKViewer*>(clientData);
if (self->getActiveScene()->getConfig()->taskTimingEnabled)
{
auto vtkRen = std::dynamic_pointer_cast<VTKRenderer>(self->getActiveRenderer());
self->getActiveScene()->lockComputeTimes();
vtkRen->setTimeTable(self->getActiveScene()->getTaskComputeTimes());
self->getActiveScene()->unlockComputeTimes();
}
}
//void
//VTKViewer::timerCallback(vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* clientData, void* vtkNotUsed(callData))
//{
// VTKViewer* self = static_cast<VTKViewer*>(clientData);
//
// if (self->getActiveScene()->getConfig()->taskTimingEnabled)
// {
// auto vtkRen = std::dynamic_pointer_cast<VTKRenderer>(self->getActiveRenderer());
// self->getActiveScene()->lockComputeTimes();
// vtkRen->setTimeTable(self->getActiveScene()->getTaskComputeTimes());
// self->getActiveScene()->unlockComputeTimes();
// }
//}
} // imstk
......@@ -111,13 +111,13 @@ public:
protected:
/// \brief TODO
static void timerCallback(vtkObject* caller, long unsigned int eventId, void* clientData, void* callData);
//static void timerCallback(vtkObject* caller, long unsigned int eventId, void* clientData, void* callData);
vtkSmartPointer<vtkRenderWindow> m_vtkRenderWindow;
std::shared_ptr<VTKInteractorStyle> m_vtkInteractorStyle;
bool m_enableVR;
vtkSmartPointer<vtkCallbackCommand> timerCallbackCommand;
//vtkSmartPointer<vtkCallbackCommand> timerCallbackCommand;
#ifdef iMSTK_ENABLE_VR
vtkSmartPointer<OpenVRCommand> m_openVRCommand;
......
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