From 712368cb3736c11de5c9734713754f8c1f9650a7 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Sat, 28 May 2022 19:59:25 -0700 Subject: [PATCH] Fix build errors on Windows + VS2022 --- dart/common/IncludeWindows.hpp | 50 +++++++++++++++++++++ dart/common/SharedLibrary.hpp | 8 +--- dart/common/Timer.hpp | 20 +++------ dart/common/detail/SharedLibraryManager.hpp | 4 ++ dart/constraint/ConstraintSolver.cpp | 5 +++ dart/gui/LoadOpengl.hpp | 8 +--- dart/gui/osg/DefaultEventHandler.cpp | 22 ++++----- dart/gui/osg/TrackballManipulator.hpp | 2 +- dart/gui/osg/render/MeshShapeNode.cpp | 2 +- python/dartpy/CMakeLists.txt | 13 ++---- python/dartpy/gui/osg/GUIEventHandler.cpp | 2 +- 11 files changed, 85 insertions(+), 51 deletions(-) create mode 100644 dart/common/IncludeWindows.hpp diff --git a/dart/common/IncludeWindows.hpp b/dart/common/IncludeWindows.hpp new file mode 100644 index 0000000000000..9c0ed655eee60 --- /dev/null +++ b/dart/common/IncludeWindows.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011-2022, The DART development contributors + * All rights reserved. + * + * The list of contributors can be found at: + * https://github.com/dartsim/dart/blob/master/LICENSE + * + * This file is provided under the following "BSD-style" License: + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DART_COMMON_INCLUDEWINDOWS_HPP_ +#define DART_COMMON_INCLUDEWINDOWS_HPP_ + +#ifdef _WIN32 + #ifdef NOMINMAX + #include + #undef near + #undef far + #else + #define NOMINMAX + #include + #undef NOMINMAX + #undef near + #undef far + #endif +#endif + +#endif // DART_COMMON_INCLUDEWINDOWS_HPP_ diff --git a/dart/common/SharedLibrary.hpp b/dart/common/SharedLibrary.hpp index 8137061575c27..ceaa649aa9fc8 100644 --- a/dart/common/SharedLibrary.hpp +++ b/dart/common/SharedLibrary.hpp @@ -50,13 +50,7 @@ #elif DART_OS_WINDOWS - #ifdef NOMINMAX - #include - #else - #define NOMINMAX - #include - #undef NOMINMAX - #endif + #include "dart/common/IncludeWindows.hpp" using hInstance = HINSTANCE__*; #define DYNLIB_HANDLE hInstance diff --git a/dart/common/Timer.hpp b/dart/common/Timer.hpp index b999c7a260960..d53da4e2287f5 100644 --- a/dart/common/Timer.hpp +++ b/dart/common/Timer.hpp @@ -36,18 +36,7 @@ #include #ifdef _WIN32 - #ifdef NOMINMAX - #include - #else - #define NOMINMAX - #include - #undef NOMINMAX - #endif -typedef struct -{ - LARGE_INTEGER start; - LARGE_INTEGER stop; -} stopWatch; + #include "dart/common/IncludeWindows.hpp" #else #include #endif @@ -101,7 +90,12 @@ class DART_DEPRECATED(6.13) Timer int mCount; #ifdef _WIN32 - stopWatch mTimer; + struct StopWatch + { + LARGE_INTEGER start; + LARGE_INTEGER stop; + }; + StopWatch mTimer; #else timeval mTimeVal; double mStartedTime; diff --git a/dart/common/detail/SharedLibraryManager.hpp b/dart/common/detail/SharedLibraryManager.hpp index 2f9cf836e98d9..81292df15c2f7 100644 --- a/dart/common/detail/SharedLibraryManager.hpp +++ b/dart/common/detail/SharedLibraryManager.hpp @@ -41,6 +41,8 @@ #include "dart/common/Filesystem.hpp" #include "dart/common/Singleton.hpp" +#ifndef _WIN32 + namespace std { template <> @@ -54,6 +56,8 @@ struct hash<::dart::common::filesystem::path> } // namespace std +#endif + namespace dart { namespace common { diff --git a/dart/constraint/ConstraintSolver.cpp b/dart/constraint/ConstraintSolver.cpp index 215be7b0d4342..c30b25b2e788f 100644 --- a/dart/constraint/ConstraintSolver.cpp +++ b/dart/constraint/ConstraintSolver.cpp @@ -406,8 +406,13 @@ bool ConstraintSolver::containSkeleton(const ConstSkeletonPtr& skeleton) const //============================================================================== bool ConstraintSolver::hasSkeleton(const ConstSkeletonPtr& skeleton) const { +#if _WIN32 + DART_ASSERT( + skeleton != nullptr && "Not allowed to insert null pointer skeleton."); +#else DART_ASSERT( skeleton != nullptr, "Not allowed to insert null pointer skeleton."); +#endif for (const auto& itrSkel : mSkeletons) { diff --git a/dart/gui/LoadOpengl.hpp b/dart/gui/LoadOpengl.hpp index 8639b2eb5292f..98ea6476246fd 100644 --- a/dart/gui/LoadOpengl.hpp +++ b/dart/gui/LoadOpengl.hpp @@ -34,13 +34,7 @@ #define DART_GUI_LOADOPENGL_HPP_ #if defined(_WIN32) - #ifdef NOMINMAX - #include - #else - #define NOMINMAX - #include - #undef NOMINMAX - #endif + #include "dart/common/IncludeWindows.hpp" #include #include #elif defined(__linux__) diff --git a/dart/gui/osg/DefaultEventHandler.cpp b/dart/gui/osg/DefaultEventHandler.cpp index 427b3e82e0fde..3869c07e2f07f 100644 --- a/dart/gui/osg/DefaultEventHandler.cpp +++ b/dart/gui/osg/DefaultEventHandler.cpp @@ -103,13 +103,13 @@ Eigen::Vector3d DefaultEventHandler::getDeltaCursor( ::osg::Vec3d eye, center, up; mViewer->getCamera()->getViewMatrixAsLookAt(eye, center, up); - Eigen::Vector3d near, far; - getNearAndFarPointUnderCursor(near, far); - Eigen::Vector3d v1 = far - near; + Eigen::Vector3d nearPt, farPt; + getNearAndFarPointUnderCursor(nearPt, farPt); + Eigen::Vector3d v1 = farPt - nearPt; if (LINE_CONSTRAINT == _constraint) { - const Eigen::Vector3d& b1 = near; + const Eigen::Vector3d& b1 = nearPt; const Eigen::Vector3d& v2 = _constraintVector; const Eigen::Vector3d& b2 = _fromPosition; @@ -131,14 +131,14 @@ Eigen::Vector3d DefaultEventHandler::getDeltaCursor( else if (PLANE_CONSTRAINT == _constraint) { const Eigen::Vector3d& n = _constraintVector; - double s = n.dot(_fromPosition - near) / n.dot(v1); - return near - _fromPosition + s * v1; + double s = n.dot(_fromPosition - nearPt) / n.dot(v1); + return nearPt - _fromPosition + s * v1; } else { Eigen::Vector3d n = osgToEigVec3(center - eye); - double s = n.dot(_fromPosition - near) / n.dot(v1); - return near - _fromPosition + s * v1; + double s = n.dot(_fromPosition - nearPt) / n.dot(v1); + return nearPt - _fromPosition + s * v1; } return Eigen::Vector3d::Zero(); @@ -146,7 +146,7 @@ Eigen::Vector3d DefaultEventHandler::getDeltaCursor( //============================================================================== void DefaultEventHandler::getNearAndFarPointUnderCursor( - Eigen::Vector3d& near, Eigen::Vector3d& far, double distance) const + Eigen::Vector3d& nearPt, Eigen::Vector3d& farPt, double distance) const { ::osg::Camera* C = mViewer->getCamera(); ::osg::Matrix VPW = C->getViewMatrix() * C->getProjectionMatrix() @@ -158,8 +158,8 @@ void DefaultEventHandler::getNearAndFarPointUnderCursor( auto osgNear = ::osg::Vec3d(x, y, 0.0) * invVPW; auto osgFar = ::osg::Vec3d(x, y, distance) * invVPW; - near = osgToEigVec3(osgNear); - far = osgToEigVec3(osgFar); + nearPt = osgToEigVec3(osgNear); + farPt = osgToEigVec3(osgFar); } //============================================================================== diff --git a/dart/gui/osg/TrackballManipulator.hpp b/dart/gui/osg/TrackballManipulator.hpp index 5c94ee83c440c..3767338b3b057 100644 --- a/dart/gui/osg/TrackballManipulator.hpp +++ b/dart/gui/osg/TrackballManipulator.hpp @@ -64,7 +64,7 @@ namespace osg { // and dart::gui::osg, we need to explicitly specify the root namespace osg as // ::osg -class OSGGA_EXPORT TrackballManipulator : public ::osgGA::OrbitManipulator +class TrackballManipulator : public ::osgGA::OrbitManipulator { public: /// Constructor diff --git a/dart/gui/osg/render/MeshShapeNode.cpp b/dart/gui/osg/render/MeshShapeNode.cpp index b8ac0f196ddae..2ae4e97d15458 100644 --- a/dart/gui/osg/render/MeshShapeNode.cpp +++ b/dart/gui/osg/render/MeshShapeNode.cpp @@ -935,7 +935,7 @@ void MeshShapeGeometry::extractData(bool firstTime) // Load textures on the first pass through if (firstTime) { - uint unit = 0; + unsigned int unit = 0; const aiVector3D* aiTexCoords = mAiMesh->mTextureCoords[unit]; while (nullptr != aiTexCoords) diff --git a/python/dartpy/CMakeLists.txt b/python/dartpy/CMakeLists.txt index 4580c4af524e7..5805ebca6e82f 100644 --- a/python/dartpy/CMakeLists.txt +++ b/python/dartpy/CMakeLists.txt @@ -13,22 +13,15 @@ endif() # Find pybind11, including PythonInterp and PythonLibs # Needs to set PYBIND11_PYTHON_VERSION before finding pybind11 set(PYBIND11_PYTHON_VERSION ${DARTPY_PYTHON_VERSION}) +if(WIN32) + set(PYBIND11_FINDPYTHON TRUE) +endif() find_package(pybind11 2.2.0 QUIET) if(NOT pybind11_FOUND) message(WARNING "Disabling [dartpy] due to missing pybind11 >= 2.2.0.") return() endif() -if(NOT PythonInterp_FOUND AND NOT PYTHONINTERP_FOUND) - message(WARNING "Disabling [dartpy] due to missing [PythonInterp].") - return() -endif() - -if(NOT PythonLibs_FOUND AND NOT PYTHONLIBS_FOUND) - message(WARNING "Disabling [dartpy] due to missing [PythonLibs].") - return() -endif() - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib;\ print(get_python_lib(plat_specific=True, prefix=''))" diff --git a/python/dartpy/gui/osg/GUIEventHandler.cpp b/python/dartpy/gui/osg/GUIEventHandler.cpp index 04ac973703a5a..934717ae11149 100644 --- a/python/dartpy/gui/osg/GUIEventHandler.cpp +++ b/python/dartpy/gui/osg/GUIEventHandler.cpp @@ -65,7 +65,7 @@ class PyGUIEventHandler final : public GUIEventHandlerNoRef { public: // Inherit the constructors - using GUIEventHandlerNoRef::GUIEventHandler; + using GUIEventHandlerNoRef::GUIEventHandlerNoRef; // Trampoline for virtual function bool handle(