diff --git a/CMake/PackageDepends/MITK_SOFA_Config.cmake b/CMake/PackageDepends/MITK_SOFA_Config.cmake index ef28d61b0c..98e7418cdd 100644 --- a/CMake/PackageDepends/MITK_SOFA_Config.cmake +++ b/CMake/PackageDepends/MITK_SOFA_Config.cmake @@ -1,4 +1,4 @@ -find_package(SOFA REQUIRED) +find_package(SOFA REQUIRED CONFIG) list(APPEND ALL_INCLUDE_DIRECTORIES ${SOFA_INCLUDE_DIRS}) list(APPEND ALL_LIBRARIES ${SOFA_LIBRARIES}) link_directories(${SOFA_LIBRARY_DIRS}) diff --git a/CMakeExternals/PatchSOFA-rev8935.cmake b/CMakeExternals/PatchSOFA-rev8935.cmake deleted file mode 100644 index b90a96266d..0000000000 --- a/CMakeExternals/PatchSOFA-rev8935.cmake +++ /dev/null @@ -1,13 +0,0 @@ -set(baseDir "framework/sofa/helper/system/") -foreach(sourceFile "${baseDir}gl.h" "${baseDir}glu.h" "${baseDir}glut.h" "${baseDir}../gl/glfont.cpp") - file(STRINGS ${sourceFile} sourceCode NEWLINE_CONSUME) - string(REGEX REPLACE "<(Open)?GL(UT)?/" "<" sourceCode ${sourceCode}) - set(CONTENTS ${sourceCode}) - configure_file(${TEMPLATE_FILE} ${sourceFile} @ONLY) -endforeach() - -set(sourceFile "modules/sofa/component/linearsolver/SSORPreconditioner.inl") -file(STRINGS ${sourceFile} sourceCode NEWLINE_CONSUME) -string(REGEX REPLACE "getM" "this->getM" sourceCode ${sourceCode}) -set(CONTENTS ${sourceCode}) -configure_file(${TEMPLATE_FILE} ${sourceFile} @ONLY) diff --git a/CMakeExternals/PatchSOFA-rev9479.cmake b/CMakeExternals/PatchSOFA-rev9479.cmake new file mode 100644 index 0000000000..63ebc1be58 --- /dev/null +++ b/CMakeExternals/PatchSOFA-rev9479.cmake @@ -0,0 +1,72 @@ +file(STRINGS "cmake/preBuildConfig.cmake" preBuildConfig_cmake NEWLINE_CONSUME) +string(REPLACE "DEBUG \"\${SOFA_BIN_DIR}" "DEBUG \"\${SOFA_BIN_DIR}/Debug" preBuildConfig_cmake "${preBuildConfig_cmake}") +string(REPLACE "RELEASE \"\${SOFA_BIN_DIR}" "RELEASE \"\${SOFA_BIN_DIR}/Release" preBuildConfig_cmake "${preBuildConfig_cmake}") +string(REPLACE "RELWITHDEBINFO \"\${SOFA_BIN_DIR}" "RELWITHDEBINFO \"\${SOFA_BIN_DIR}/RelWithDebInfo" preBuildConfig_cmake "${preBuildConfig_cmake}") +string(REPLACE "MINSIZEREL \"\${SOFA_BIN_DIR}" "MINSIZEREL \"\${SOFA_BIN_DIR}/MinSizeRel" preBuildConfig_cmake "${preBuildConfig_cmake}") +string(REPLACE "DEBUG \"\${SOFA_LIB_DIR}" "DEBUG \"\${SOFA_LIB_DIR}/Debug" preBuildConfig_cmake "${preBuildConfig_cmake}") +string(REPLACE "RELEASE \"\${SOFA_LIB_DIR}" "RELEASE \"\${SOFA_LIB_DIR}/Release" preBuildConfig_cmake "${preBuildConfig_cmake}") +string(REPLACE "RELWITHDEBINFO \"\${SOFA_LIB_DIR}" "RELWITHDEBINFO \"\${SOFA_LIB_DIR}/RelWithDebInfo" preBuildConfig_cmake "${preBuildConfig_cmake}") +string(REPLACE "MINSIZEREL \"\${SOFA_LIB_DIR}" "MINSIZEREL \"\${SOFA_LIB_DIR}/MinSizeRel" preBuildConfig_cmake "${preBuildConfig_cmake}") +file(WRITE "cmake/preBuildConfig.cmake" "${preBuildConfig_cmake}") + +file(APPEND "CMakeLists.txt" "\n\nconfigure_file(SOFAConfig.cmake.in SOFAConfig.cmake @ONLY)") + +file(WRITE "SOFAConfig.cmake.in" +"add_definitions(-DSOFA_HAVE_EIGEN2;-DSOFA_XML_PARSER_TINYXML;-DTIXML_USE_STL;-DMINI_FLOWVR) + +set(SOFA_INCLUDE_DIRS \"@SOFA_EXTLIBS_DIR@/eigen-3.1.1;@SOFA_EXTLIBS_DIR@/miniBoost;@SOFA_EXTLIBS_DIR@/miniFlowVR/include;@SOFA_EXTLIBS_DIR@/newmat;@SOFA_EXTLIBS_DIR@/tinyxml;@SOFA_SRC_DIR@/framework;@SOFA_SRC_DIR@/modules\") + +set(SOFA_LIBRARY_DIRS \"@SOFA_LIB_DIR@\") + +set(SOFA_LIBRARIES + debug SofaBaseAnimationLoop_1_0d optimized SofaBaseAnimationLoop_1_0 + debug SofaBaseCollision_1_0d optimized SofaBaseCollision_1_0 + debug SofaBaseLinearSolver_1_0d optimized SofaBaseLinearSolver_1_0 + debug SofaBaseMechanics_1_0d optimized SofaBaseMechanics_1_0 + debug SofaBaseTopology_1_0d optimized SofaBaseTopology_1_0 + debug SofaBaseVisual_1_0d optimized SofaBaseVisual_1_0 + debug SofaBoundaryCondition_1_0d optimized SofaBoundaryCondition_1_0 + debug SofaComponentAdvanced_1_0d optimized SofaComponentAdvanced_1_0 + debug SofaComponentBase_1_0d optimized SofaComponentBase_1_0 + debug SofaComponentCommon_1_0d optimized SofaComponentCommon_1_0 + debug SofaComponentGeneral_1_0d optimized SofaComponentGeneral_1_0 + debug SofaComponentMain_1_0d optimized SofaComponentMain_1_0 + debug SofaComponentMisc_1_0d optimized SofaComponentMisc_1_0 + debug SofaConstraint_1_0d optimized SofaConstraint_1_0 + debug SofaCore_1_0d optimized SofaCore_1_0 + debug SofaDefaultType_1_0d optimized SofaDefaultType_1_0 + debug SofaDeformable_1_0d optimized SofaDeformable_1_0 + debug SofaDenseSolver_1_0d optimized SofaDenseSolver_1_0 + debug SofaEigen2Solver_1_0d optimized SofaEigen2Solver_1_0 + debug SofaEngine_1_0d optimized SofaEngine_1_0 + debug SofaEulerianFluid_1_0d optimized SofaEulerianFluid_1_0 + debug SofaExplicitOdeSolver_1_0d optimized SofaExplicitOdeSolver_1_0 + debug SofaExporter_1_0d optimized SofaExporter_1_0 + debug SofaGraphComponent_1_0d optimized SofaGraphComponent_1_0 + debug SofaHaptics_1_0d optimized SofaHaptics_1_0 + debug SofaHelper_1_0d optimized SofaHelper_1_0 + debug SofaImplicitOdeSolver_1_0d optimized SofaImplicitOdeSolver_1_0 + debug SofaLoader_1_0d optimized SofaLoader_1_0 + debug SofaMeshCollision_1_0d optimized SofaMeshCollision_1_0 + debug SofaMisc_1_0d optimized SofaMisc_1_0 + debug SofaMiscCollision_1_0d optimized SofaMiscCollision_1_0 + debug SofaMiscEngine_1_0d optimized SofaMiscEngine_1_0 + debug SofaMiscFem_1_0d optimized SofaMiscFem_1_0 + debug SofaMiscForceField_1_0d optimized SofaMiscForceField_1_0 + debug SofaMiscMapping_1_0d optimized SofaMiscMapping_1_0 + debug SofaMiscSolver_1_0d optimized SofaMiscSolver_1_0 + debug SofaMiscTopology_1_0d optimized SofaMiscTopology_1_0 + debug SofaNonUniformFem_1_0d optimized SofaNonUniformFem_1_0 + debug SofaObjectInteraction_1_0d optimized SofaObjectInteraction_1_0 + debug SofaPreconditioner_1_0d optimized SofaPreconditioner_1_0 + debug SofaRigid_1_0d optimized SofaRigid_1_0 + debug SofaSimpleFem_1_0d optimized SofaSimpleFem_1_0 + debug SofaSimulationCommon_1_0d optimized SofaSimulationCommon_1_0 + debug SofaSimulationTree_1_0d optimized SofaSimulationTree_1_0 + debug SofaSphFluid_1_0d optimized SofaSphFluid_1_0 + debug SofaTopologyMapping_1_0d optimized SofaTopologyMapping_1_0 + debug SofaUserInteraction_1_0d optimized SofaUserInteraction_1_0 + debug SofaValidation_1_0d optimized SofaValidation_1_0 + debug SofaVolumetricData_1_0d optimized SofaVolumetricData_1_0 + debug tinyxml_1_0d optimized tinyxml_1_0 +)") diff --git a/CMakeExternals/SOFA.cmake b/CMakeExternals/SOFA.cmake index aa8f865839..00040e429a 100644 --- a/CMakeExternals/SOFA.cmake +++ b/CMakeExternals/SOFA.cmake @@ -1,37 +1,65 @@ #----------------------------------------------------------------------------- # SOFA #----------------------------------------------------------------------------- if(MITK_USE_SOFA) # Sanity checks if(DEFINED SOFA_DIR AND NOT EXISTS ${SOFA_DIR}) message(FATAL_ERROR "SOFA_DIR variable is defined but corresponds to non-existing directory") endif() set(proj SOFA) set(proj_DEPENDENCIES) set(SOFA_DEPENDS ${proj}) - set(SOFA_PATCH_COMMAND ${CMAKE_COMMAND} -DTEMPLATE_FILE:FILEPATH=${MITK_SOURCE_DIR}/CMakeExternals/EmptyFileForPatching.dummy -P ${MITK_SOURCE_DIR}/CMakeExternals/PatchSOFA-rev8935.cmake) + set(additional_cmake_args + -DSOFA-APPLICATION_MODELER:BOOL=OFF + -DSOFA-APPLICATION_RUN_SOFA:BOOL=OFF + -DSOFA-APPLICATION_SOFA_BATCH:BOOL=OFF + -DSOFA-EXTERNAL_HAVE_ZLIB:BOOL=OFF + -DSOFA-EXTERNAL_HAVE_PNG:BOOL=OFF + -DSOFA-LIB_COMPONENT_EIGEN2_SOLVER:BOOL=ON + -DSOFA-LIB_COMPONENT_OPENGL_VISUAL:BOOL=OFF + -DSOFA-LIB_GUI_GLUT:BOOL=OFF + -DSOFA-LIB_GUI_QTVIEWER:BOOL=OFF + -DSOFA-MISC_NO_OPENGL:BOOL=ON + -DSOFA-TUTORIAL_CHAIN_HYBRID:BOOL=OFF + -DSOFA-TUTORIAL_COMPOSITE_OBJECT:BOOL=OFF + -DSOFA-TUTORIAL_HOUSE_OF_CARDS:BOOL=OFF + -DSOFA-TUTORIAL_MIXED_PENDULUM:BOOL=OFF + -DSOFA-TUTORIAL_ONE_PARTICLE:BOOL=OFF + -DSOFA-TUTORIAL_ONE_TETRAHEDRON:BOOL=OFF) + + set(SOFA_PATCH_COMMAND ${CMAKE_COMMAND} -DTEMPLATE_FILE:FILEPATH=${MITK_SOURCE_DIR}/CMakeExternals/EmptyFileForPatching.dummy -P ${MITK_SOURCE_DIR}/CMakeExternals/PatchSOFA-rev9479.cmake) + set(SOFA_PRECONFIGURE_COMMAND ${CMAKE_COMMAND} -G${gen} ${CMAKE_BINARY_DIR}/${proj}-src) + set(SOFA_CONFIGURE_COMMAND ${CMAKE_COMMAND} -G${gen} ${ep_common_args} ${additional_cmake_args} ${CMAKE_BINARY_DIR}/${proj}-src) if(NOT DEFINED SOFA_DIR) ExternalProject_Add(${proj} SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}-src BINARY_DIR ${proj}-build PREFIX ${proj}-cmake - URL ${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/SOFA_27fb9050.tar.gz - URL_MD5 1c4e68c6d6e6efb9b7e2da59627a9bdb + URL http://dl.dropboxusercontent.com/u/5822501/SOFA-rev9479.tar.gz + URL_MD5 fa43e6183abb8fc36c86ec43a095fdc2 PATCH_COMMAND ${SOFA_PATCH_COMMAND} INSTALL_COMMAND "" CMAKE_GENERATOR ${gen} CMAKE_ARGS ${ep_common_args} ${additional_cmake_args} DEPENDS ${proj_DEPENDENCIES} ) + ExternalProject_Add_Step(${proj} preconfigure + COMMAND ${SOFA_PRECONFIGURE_COMMAND} + WORKING_DIRECTORY ${proj}-build + DEPENDEES patch + DEPENDERS configure + LOG 1 + ) + set(SOFA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${proj}-build) else() mitkMacroEmptyExternalProject(${proj} "${proj}_DEPENDENCIES}") endif() endif() diff --git a/Modules/Simulation/mitkSimulationDrawTool.cpp b/Modules/Simulation/mitkSimulationDrawTool.cpp index 456a907ce4..c6ee8dbe5f 100644 --- a/Modules/Simulation/mitkSimulationDrawTool.cpp +++ b/Modules/Simulation/mitkSimulationDrawTool.cpp @@ -1,577 +1,589 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkSimulation.h" #include "mitkSimulationDrawTool.h" #include #include #include #include #include #include #include #include #include #include #include mitk::SimulationDrawTool::SimulationDrawTool() : m_PolygonMode(0), m_Wireframe(false), m_Update(true) { } mitk::SimulationDrawTool::~SimulationDrawTool() { m_Actors.clear(); } void mitk::SimulationDrawTool::DisableUpdate() { m_Update = false; } std::vector > mitk::SimulationDrawTool::GetActors() const { return m_Actors; } void mitk::SimulationDrawTool::InitProperty(vtkProperty* property) const { if (m_Wireframe) property->SetRepresentationToWireframe(); else property->SetRepresentationToSurface(); } void mitk::SimulationDrawTool::Reset() { m_Actors.clear(); m_Update = true; } void mitk::SimulationDrawTool::drawPoints(const std::vector& points, float pointSize, const Vec4f color) { if (!m_Update || points.empty()) return; unsigned int numPoints = points.size(); vtkSmartPointer vtkPoints = vtkSmartPointer< ::vtkPoints>::New(); vtkPoints->SetNumberOfPoints(numPoints); vtkSmartPointer cellArray = vtkSmartPointer::New(); for (unsigned int i = 0; i < numPoints; ++i) { vtkPoints->SetPoint(i, points[i].elems); cellArray->InsertNextCell(1); cellArray->InsertCellPoint(i); } vtkSmartPointer polyData = vtkSmartPointer::New(); polyData->SetPoints(vtkPoints); polyData->SetVerts(cellArray); vtkSmartPointer polyDataMapper = vtkSmartPointer::New(); polyDataMapper->SetInput(polyData); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(polyDataMapper); actor->SetScale(Simulation::ScaleFactor); vtkProperty* property = actor->GetProperty(); property->SetColor(color.x(), color.y(), color.z()); property->SetPointSize(pointSize); m_Actors.push_back(actor); } +void mitk::SimulationDrawTool::drawPoints(const std::vector&, float, const std::vector) +{ +} + void mitk::SimulationDrawTool::drawLines(const std::vector& points, float lineWidth, const Vec4f color) { if (!m_Update || points.empty()) return; unsigned int numPoints = points.size(); std::vector indices; for (unsigned int i = 0; i < numPoints; i += 2) indices.push_back(Vec2i(i, i + 1)); this->drawLines(points, indices, lineWidth, color); } void mitk::SimulationDrawTool::drawLines(const std::vector& points, const std::vector& indices, float lineWidth, const Vec4f color) { if (!m_Update || points.empty()) return; unsigned int numPoints = points.size(); vtkSmartPointer vtkPoints = vtkSmartPointer< ::vtkPoints>::New(); vtkPoints->SetNumberOfPoints(numPoints); for (unsigned int i = 0; i < numPoints; ++i) vtkPoints->SetPoint(i, points[i].elems); vtkSmartPointer polyData = vtkSmartPointer::New(); polyData->SetPoints(vtkPoints); vtkSmartPointer lines = vtkSmartPointer::New(); unsigned int numIndices = indices.size(); for (unsigned int i = 0; i < numIndices; ++i) { lines->InsertNextCell(2); lines->InsertCellPoint(indices[i].elems[0]); lines->InsertCellPoint(indices[i].elems[1]); } polyData->SetLines(lines); vtkSmartPointer polyDataMapper = vtkSmartPointer::New(); polyDataMapper->SetInput(polyData); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(polyDataMapper); actor->SetScale(Simulation::ScaleFactor); vtkProperty* property = actor->GetProperty(); property->SetLineWidth(lineWidth); property->SetColor(color.x(), color.y(), color.z()); m_Actors.push_back(actor); } void mitk::SimulationDrawTool::drawTriangles(const std::vector& points, const Vec4f color) { if (!m_Update || points.empty()) return; unsigned int numPoints = points.size(); vtkSmartPointer vtkPoints = vtkSmartPointer< ::vtkPoints>::New(); vtkPoints->SetNumberOfPoints(numPoints); for (unsigned int i = 0; i < numPoints; ++i) vtkPoints->SetPoint(i, points[i].elems); vtkSmartPointer polyData = vtkSmartPointer::New(); polyData->SetPoints(vtkPoints); vtkSmartPointer triangles = vtkSmartPointer::New(); for (unsigned int i = 0; i < points.size(); i += 3) { triangles->InsertNextCell(3); triangles->InsertCellPoint(i); triangles->InsertCellPoint(i + 1); triangles->InsertCellPoint(i + 2); } polyData->SetPolys(triangles); vtkSmartPointer polyDataNormals = vtkSmartPointer::New(); polyDataNormals->ComputeCellNormalsOff(); polyDataNormals->SetInput(polyData); polyDataNormals->SplittingOff(); vtkSmartPointer polyDataMapper = vtkSmartPointer::New(); polyDataMapper->SetInput(polyDataNormals->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(polyDataMapper); actor->SetScale(Simulation::ScaleFactor); vtkProperty* property = actor->GetProperty(); this->InitProperty(property); property->SetColor(color.x(), color.y(), color.z()); m_Actors.push_back(actor); } void mitk::SimulationDrawTool::drawTriangles(const std::vector& points, const Vector3 normal, const Vec4f color) { if (!m_Update || points.empty()) return; unsigned int numPoints = points.size(); unsigned int numNormals = numPoints / 3; vtkSmartPointer vtkPoints = vtkSmartPointer< ::vtkPoints>::New(); vtkPoints->SetNumberOfPoints(numPoints); for (unsigned int i = 0; i < numPoints; ++i) vtkPoints->SetPoint(i, points[i].elems); vtkSmartPointer polyData = vtkSmartPointer::New(); polyData->SetPoints(vtkPoints); vtkSmartPointer triangles = vtkSmartPointer::New(); for (unsigned int i = 0; i < points.size(); i += 3) { triangles->InsertNextCell(3); triangles->InsertCellPoint(i); triangles->InsertCellPoint(i + 1); triangles->InsertCellPoint(i + 2); } polyData->SetPolys(triangles); vtkSmartPointer normals = vtkSmartPointer::New(); normals->SetNumberOfComponents(3); normals->SetNumberOfTuples(numNormals); normals->SetName("Normals"); for (unsigned int i = 0; i < numNormals; ++i) normals->SetTuple(i, normal.elems); polyData->GetCellData()->SetNormals(normals); vtkSmartPointer polyDataMapper = vtkSmartPointer::New(); polyDataMapper->SetInput(polyData); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(polyDataMapper); actor->SetScale(Simulation::ScaleFactor); vtkProperty* property = actor->GetProperty(); this->InitProperty(property); property->SetColor(color.x(), color.y(), color.z()); m_Actors.push_back(actor); } void mitk::SimulationDrawTool::drawTriangles(const std::vector& points, const std::vector& indices, const std::vector& normals, const Vec4f color) { if (!m_Update || points.empty() || indices.empty() || normals.empty()) return; unsigned int numPoints = points.size(); vtkSmartPointer vtkPoints = vtkSmartPointer< ::vtkPoints>::New(); vtkPoints->SetNumberOfPoints(numPoints); for (unsigned int i = 0; i < numPoints; ++i) vtkPoints->SetPoint(i, points[i].elems); vtkSmartPointer polyData = vtkSmartPointer::New(); polyData->SetPoints(vtkPoints); vtkSmartPointer triangles = vtkSmartPointer::New(); unsigned int numIndices = indices.size(); for (unsigned int i = 0; i < numIndices; ++i) { triangles->InsertNextCell(3); triangles->InsertCellPoint(indices[i].elems[0]); triangles->InsertCellPoint(indices[i].elems[1]); triangles->InsertCellPoint(indices[i].elems[2]); } polyData->SetPolys(triangles); unsigned int numNormals = normals.size(); vtkSmartPointer vtkNormals = vtkSmartPointer::New(); vtkNormals->SetNumberOfComponents(3); vtkNormals->SetNumberOfTuples(numNormals); vtkNormals->SetName("Normals"); for (unsigned int i = 0; i < numNormals; ++i) vtkNormals->SetTuple(i, normals[i].elems); polyData->GetCellData()->SetNormals(vtkNormals); vtkSmartPointer polyDataMapper = vtkSmartPointer::New(); polyDataMapper->SetInput(polyData); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(polyDataMapper); actor->SetScale(Simulation::ScaleFactor); vtkProperty* property = actor->GetProperty(); this->InitProperty(property); property->SetColor(color.x(), color.y(), color.z()); m_Actors.push_back(actor); } void mitk::SimulationDrawTool::drawTriangles(const std::vector&, const std::vector&, const std::vector&) { } void mitk::SimulationDrawTool::drawTriangleStrip(const std::vector&, const std::vector&, const Vec4f) { } void mitk::SimulationDrawTool::drawTriangleFan(const std::vector&, const std::vector&, const Vec4f) { } void mitk::SimulationDrawTool::drawFrame(const Vector3& position, const Quaternion& orientation, const Vec3f& size) { if (!m_Update) return; float minSize = std::min(std::min(size.x(), size.y()), size.z()); float maxSize = std::max(std::max(size.x(), size.y()), size.z()); if (maxSize > minSize * 2.0f) { if (minSize > 0.0f) maxSize = minSize * 2.0f; else minSize = maxSize * 0.707f; } const float radii[] = { minSize * 0.1f, maxSize * 0.2f }; bool wireframeBackup = m_Wireframe; m_Wireframe = false; if (size.x() != 0.0f) { Vector3 point2 = position + orientation.rotate(Vec3f(size.x(), 0.0f, 0.0f)); Vector3 point3 = point2 + orientation.rotate(Vec3f(radii[1], 0.0f, 0.0f)); Vec4f red(1.0f, 0.0f, 0.0f, 1.0f); this->drawCylinder(position, point2, radii[0], red); this->drawCone(point2, point3, radii[1], 0.0f, red); } if (size.y() != 0.0f) { Vector3 point2 = position + orientation.rotate(Vec3f(0.0f, size.y(), 0.0f)); Vector3 point3 = point2 + orientation.rotate(Vec3f(0.0f, radii[1], 0.0f)); Vec4f green(0.0f, 1.0f, 0.0f, 1.0f); this->drawCylinder(position, point2, radii[0], green); this->drawCone(point2, point3, radii[1], 0.0f, green); } if (size.z() != 0.0f) { Vector3 point2 = position + orientation.rotate(Vec3f(0.0f, 0.0f, size.z())); Vector3 point3 = point2 + orientation.rotate(Vec3f(0.0f, 0.0f, radii[1])); Vec4f blue(0.0f, 0.0f, 1.0f, 1.0f); this->drawCylinder(position, point2, radii[0], blue); this->drawCone(point2, point3, radii[1], 0.0f, blue); } m_Wireframe = wireframeBackup; } +void mitk::SimulationDrawTool::drawFrame(const Vector3&, const Quaternion&, const Vec3f&, const Vec4f&) +{ +} + void mitk::SimulationDrawTool::drawSpheres(const std::vector& points, const std::vector& radii, const Vec4f color) { if (!m_Update || points.empty()) return; unsigned int numSpheres = points.size(); for (unsigned int i = 0; i < numSpheres; ++i) { vtkSmartPointer sphereSource = vtkSmartPointer::New(); sphereSource->SetCenter(const_cast(points[i].elems)); sphereSource->SetRadius(radii[i]); sphereSource->SetPhiResolution(16); sphereSource->SetThetaResolution(32); sphereSource->LatLongTessellationOn(); vtkSmartPointer polyDataMapper = vtkSmartPointer::New(); polyDataMapper->SetInputConnection(sphereSource->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(polyDataMapper); actor->SetScale(Simulation::ScaleFactor); vtkProperty* property = actor->GetProperty(); this->InitProperty(property); property->SetColor(color.x(), color.y(), color.z()); m_Actors.push_back(actor); } } void mitk::SimulationDrawTool::drawSpheres(const std::vector& points, float radius, const Vec4f color) { if (!m_Update || points.empty()) return; unsigned int numPoints = points.size(); std::vector radii(numPoints, radius); this->drawSpheres(points, radii, color); } void mitk::SimulationDrawTool::drawCone(const Vector3& point1, const Vector3& point2, float radius1, float radius2, const Vec4f color, int subdivisions) { if (!m_Update) return; vtkSmartPointer points = vtkSmartPointer::New(); points->SetNumberOfPoints(2); points->SetPoint(0, point1.elems); points->SetPoint(1, point2.elems); vtkSmartPointer line = vtkSmartPointer::New(); line->InsertNextCell(2); line->InsertCellPoint(0); line->InsertCellPoint(1); vtkSmartPointer polyData = vtkSmartPointer::New(); polyData->SetPoints(points); polyData->SetLines(line); const char* radiiName = "Radii"; vtkSmartPointer radii = vtkSmartPointer::New(); radii->SetName(radiiName); radii->SetNumberOfTuples(2); radii->SetTuple1(0, radius1); radii->SetTuple1(1, radius2); vtkPointData* pointData = polyData->GetPointData(); pointData->AddArray(radii); pointData->SetActiveScalars(radiiName); vtkSmartPointer tubeFilter = vtkSmartPointer::New(); tubeFilter->SetInput(polyData); tubeFilter->CappingOn(); tubeFilter->SetNumberOfSides(subdivisions); tubeFilter->SetVaryRadiusToVaryRadiusByAbsoluteScalar(); vtkSmartPointer polyDataMapper = vtkSmartPointer::New(); polyDataMapper->SetInputConnection(tubeFilter->GetOutputPort()); polyDataMapper->ScalarVisibilityOff(); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(polyDataMapper); actor->SetScale(Simulation::ScaleFactor); vtkProperty* property = actor->GetProperty(); this->InitProperty(property); property->SetColor(color.x(), color.y(), color.z()); m_Actors.push_back(actor); } void mitk::SimulationDrawTool::drawCube(const float&, const Vec4f&, const int&) { } void mitk::SimulationDrawTool::drawCylinder(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color, int subdivisions) { if (!m_Update) return; this->drawCone(point1, point2, radius, radius, color, subdivisions); } void mitk::SimulationDrawTool::drawCapsule(const Vector3&, const Vector3&, float, const Vec4f, int) { } void mitk::SimulationDrawTool::drawArrow(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color, int subdivisions) { if (!m_Update) return; Vector3 point3 = point1 * 0.2f + point2 * 0.8f; this->drawCylinder(point1, point3, radius, color, subdivisions); this->drawCone(point3, point2, radius * 2.5f, 0.0f, color, subdivisions); } void mitk::SimulationDrawTool::drawPlus(const float& edgeRadius, const Vec4f& color, const int& subdivisions) { if (!m_Update) return; this->drawCylinder(Vector3(-1.0, 0.0, 0.0), Vector3(1.0, 0.0, 0.0), edgeRadius, color, subdivisions); this->drawCylinder(Vector3(0.0, -1.0, 0.0), Vector3(0.0, 1.0, 0.0), edgeRadius, color, subdivisions); this->drawCylinder(Vector3(0.0, 0.0, -1.0), Vector3(0.0, 0.0, 1.0), edgeRadius, color, subdivisions); } void mitk::SimulationDrawTool::drawPoint(const Vector3&, const Vec4f&) { } void mitk::SimulationDrawTool::drawPoint(const Vector3&, const Vector3&, const Vec4f&) { } void mitk::SimulationDrawTool::drawTriangle(const Vector3&, const Vector3&, const Vector3&, const Vector3&) { } void mitk::SimulationDrawTool::drawTriangle(const Vector3&, const Vector3&, const Vector3&, const Vector3&, const Vec4f&) { } void mitk::SimulationDrawTool::drawTriangle(const Vector3&, const Vector3&, const Vector3&, const Vector3&, const Vec4f&, const Vec4f&, const Vec4f&) { } void mitk::SimulationDrawTool::drawSphere(const Vector3&, float) { } +void mitk::SimulationDrawTool::drawBoundingBox(const Vector3&, const Vector3&) +{ +} + void mitk::SimulationDrawTool::pushMatrix() { } void mitk::SimulationDrawTool::popMatrix() { } void mitk::SimulationDrawTool::multMatrix(float*) { } void mitk::SimulationDrawTool::scale(float) { } void mitk::SimulationDrawTool::setMaterial(const Vec4f&, std::string) { } void mitk::SimulationDrawTool::resetMaterial(const Vec4f&, std::string) { } void mitk::SimulationDrawTool::setPolygonMode(int mode, bool wireframe) { if (!m_Update) return; m_PolygonMode = mode; m_Wireframe = wireframe; } void mitk::SimulationDrawTool::setLightingEnabled(bool) { } void mitk::SimulationDrawTool::writeOverlayText(int, int, unsigned int, const Vec4f&, const char*) { } diff --git a/Modules/Simulation/mitkSimulationDrawTool.h b/Modules/Simulation/mitkSimulationDrawTool.h index 948638a254..ae23cfd035 100644 --- a/Modules/Simulation/mitkSimulationDrawTool.h +++ b/Modules/Simulation/mitkSimulationDrawTool.h @@ -1,107 +1,110 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkSimulationDrawTool_h #define mitkSimulationDrawTool_h #include #include #include #include class vtkProperty; namespace mitk { /** \brief Utility class used by SOFA classes to draw objects other than visual models. * * Implements the sofa::core::visual::DrawTool interface and replaces the default SOFA OpenGL implementation sofa::core::visual::DrawToolGL. * All draw methods create a VTK actor and append it to an internal list which can be queried by calling GetActors() to finally draw them. * In contrary to the original concept of DrawToolGL, which is set once during initialization of SOFA applications, every mitk::Simulation has its own exclusive copy of mitk::SimulationDrawTool. * Since SOFA can handle only a single DrawTool at once it must be ensured that the correct mitk::SimulationDrawTool is set when switching the active simulation. * * Each draw method checks if it is necessary to generate a new up-to-date VTK actor, i.e. after a simulation step, or if it is sufficient to use the already generated one. * This decision is controlled through the methods Reset() and DisableUpdate(). * The former method must be called right before a simulation step and mitk::SimulationMapper3D calls the latter method during rendering to disable unnecessary updates until the next simulation step. */ class Simulation_EXPORT SimulationDrawTool : public sofa::core::visual::DrawTool { public: SimulationDrawTool(); ~SimulationDrawTool(); /** \brief Disables creation of new VTK actors when calling draw methods. */ void DisableUpdate(); /** \brief Returns current list of VTK actors which were generated by draw methods since the last reset. * * \note Do not delete the VTK actors returned by this method. */ std::vector > GetActors() const; /** \brief Clears internal lists of current VTK objects and enables creation of new VTK actors when calling draw methods. */ void Reset(); void drawPoints(const std::vector& points, float pointSize, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawPoints(const std::vector& points, float pointSize, const std::vector colors); void drawLines(const std::vector& points, float lineWidth, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawLines(const std::vector& points, const std::vector& indices, float lineWidth, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawTriangles(const std::vector& points, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawTriangles(const std::vector& points, const Vector3 normal, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawTriangles(const std::vector& points, const std::vector& indices, const std::vector& normals, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawTriangles(const std::vector& points, const std::vector& normals, const std::vector& colors); void drawTriangleStrip(const std::vector& points, const std::vector& normals, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawTriangleFan(const std::vector& points, const std::vector& normals, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawFrame(const Vector3& position, const Quaternion& orientation, const Vec3f& size); + void drawFrame(const Vector3& position, const Quaternion& orientation, const Vec3f& size, const Vec4f& color); void drawSpheres(const std::vector& points, const std::vector& radii, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawSpheres(const std::vector& points, float radius, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawCone(const Vector3& point1, const Vector3& point2, float radius1, float radius2, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), int subdivisions = 16); void drawCube(const float& edgeRadius, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), const int& subdivisions = 16); void drawCylinder(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), int subdivisions = 16); void drawCapsule(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), int subdivisions = 16); void drawArrow(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), int subdivisions = 16); void drawPlus(const float& edgeRadius, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), const int& subdivisions = 16); void drawPoint(const Vector3& position, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawPoint(const Vector3& position, const Vector3& normal, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawTriangle(const Vector3& point1, const Vector3& point2, const Vector3& point3, const Vector3& normal); void drawTriangle(const Vector3& point1, const Vector3& point2, const Vector3& point3, const Vector3& normal, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); void drawTriangle(const Vector3& point1, const Vector3& point2, const Vector3& point3, const Vector3& normal, const Vec4f& color1, const Vec4f& color2, const Vec4f& color3); void drawSphere(const Vector3& position, float radius); + void drawBoundingBox(const Vector3& min, const Vector3& max); void pushMatrix(); void popMatrix(); void multMatrix(float* matrix); void scale(float factor); void setMaterial(const Vec4f& color, std::string name = ""); void resetMaterial(const Vec4f& color, std::string name = ""); void setPolygonMode(int mode, bool wireframe); void setLightingEnabled(bool isEnabled); void writeOverlayText(int x, int y, unsigned int fontSize, const Vec4f& color, const char* text); private: SimulationDrawTool(const SimulationDrawTool&); SimulationDrawTool& operator=(const SimulationDrawTool&); void InitProperty(vtkProperty* property) const; std::vector > m_Actors; int m_PolygonMode; bool m_Wireframe; bool m_Update; }; } #endif