Skip to content

Commit

Permalink
Merged default into Model-becomes-transparent-while-being-manpulated
Browse files Browse the repository at this point in the history
  • Loading branch information
mayman99 committed Feb 3, 2016
2 parents 0895e14 + c79de79 commit 519fee3
Show file tree
Hide file tree
Showing 28 changed files with 1,725 additions and 118 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ using the same arguments used in the command line.
1. Scale link mass and inertia when a link is scaled
* [Pull request #1836](https://bitbucket.org/osrf/gazebo/pull-request/1836)

1. Add density widget to config widget and link inspector
* [Pull request #1978](https://bitbucket.org/osrf/gazebo/pull-request/1978)

1. Added icons for child and parent link in joint inspector
* [Pull request #1953](https://bitbucket.org/osrf/gazebo/pull-request/1953)

Expand Down
81 changes: 44 additions & 37 deletions cmake/CheckDRIDisplay.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,54 @@ SET (VALID_DRI_DISPLAY FALSE)
SET (CHECKER_ERROR "(no glxinfo or pyopengl)")

IF((DEFINED ENV{DISPLAY}) AND NOT ("$ENV{DISPLAY}" STREQUAL ""))
MESSAGE(STATUS " + found a display available ($DISPLAY is set)")
SET (VALID_DISPLAY TRUE)
EXECUTE_PROCESS(
COMMAND xwininfo -root
RESULT_VARIABLE DISPLAY_FAIL_RESULT
ERROR_QUIET
OUTPUT_QUIET)
IF (NOT DISPLAY_FAIL_RESULT)
MESSAGE(STATUS " + found a display available ($DISPLAY is set)")
SET (VALID_DISPLAY TRUE)

# Continue check for DRI support in the display
# Try to run glxinfo. If not found, variable will be empty
FIND_PROGRAM(GLXINFO glxinfo)
# Continue check for DRI support in the display
# Try to run glxinfo. If not found, variable will be empty
FIND_PROGRAM(GLXINFO glxinfo)

# If not display found, it will throw an error
# Another grep pattern: "direct rendering:[[:space:]]*Yes[[:space:]]*"
IF (GLXINFO)
EXECUTE_PROCESS(
COMMAND glxinfo
COMMAND grep "direct rendering:[[:space:]]*Yes[[:space:]]*"
ERROR_QUIET
OUTPUT_VARIABLE GLX)
# If not display found, it will throw an error
# Another grep pattern: "direct rendering:[[:space:]]*Yes[[:space:]]*"
IF (GLXINFO)
EXECUTE_PROCESS(
COMMAND glxinfo
COMMAND grep "direct rendering:[[:space:]]*Yes[[:space:]]*"
ERROR_QUIET
OUTPUT_VARIABLE GLX)

IF (GLX)
MESSAGE(STATUS " + found a valid dri display (glxinfo)")
SET (VALID_DRI_DISPLAY TRUE)
ELSE()
SET (CHECKER_ERROR "using glxinfo")
ENDIF ()
ELSE ()
EXECUTE_PROCESS(
# RESULT_VARIABLE is store in a FAIL variable since the command
# returns 0 if ok and 1 if error (inverse than cmake IF)
COMMAND ${PROJECT_SOURCE_DIR}/tools/gl-test.py
RESULT_VARIABLE GL_FAIL_RESULT
ERROR_VARIABLE GL_ERROR
OUTPUT_QUIET)
IF (GLX)
MESSAGE(STATUS " + found a valid dri display (glxinfo)")
SET (VALID_DRI_DISPLAY TRUE)
ELSE()
SET (CHECKER_ERROR "using glxinfo")
ENDIF ()
ELSE ()
EXECUTE_PROCESS(
# RESULT_VARIABLE is store in a FAIL variable since the command
# returns 0 if ok and 1 if error (inverse than cmake IF)
COMMAND ${PROJECT_SOURCE_DIR}/tools/gl-test.py
RESULT_VARIABLE GL_FAIL_RESULT
ERROR_VARIABLE GL_ERROR
OUTPUT_QUIET)

IF (NOT GL_FAIL_RESULT)
MESSAGE(STATUS " + found a valid dri display (pyopengl)")
SET (VALID_DRI_DISPLAY TRUE)
ELSE()
# Check error string: no python module means no pyopengl
STRING(FIND ${GL_ERROR}
"ImportError: No module named OpenGL.GLUT" ERROR_POS)
# -1 will imply pyopengl is present but real DRI test fails
IF ("${ERROR_POS}" STREQUAL "-1")
SET (CHECKER_ERROR "using pyopengl")
IF (NOT GL_FAIL_RESULT)
MESSAGE(STATUS " + found a valid dri display (pyopengl)")
SET (VALID_DRI_DISPLAY TRUE)
ELSE()
# Check error string: no python module means no pyopengl
STRING(FIND ${GL_ERROR}
"ImportError: No module named OpenGL.GLUT" ERROR_POS)
# -1 will imply pyopengl is present but real DRI test fails
IF ("${ERROR_POS}" STREQUAL "-1")
SET (CHECKER_ERROR "using pyopengl")
ENDIF ()
ENDIF ()
ENDIF ()
ENDIF ()
Expand Down
2 changes: 1 addition & 1 deletion cmake/SearchForStuff.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ endif ()
# Find ignition math in unix platforms
# In Windows we expect a call from configure.bat script with the paths
if (NOT WIN32)
find_package(ignition-math2 QUIET)
find_package(ignition-math2 2.3 QUIET)
if (NOT ignition-math2_FOUND)
message(STATUS "Looking for ignition-math2-config.cmake - not found")
BUILD_ERROR ("Missing: Ignition math2 library.")
Expand Down
3 changes: 3 additions & 0 deletions gazebo/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ set (sources
KeyEvent.cc
KeyFrame.cc
Material.cc
MaterialDensity.cc
Mesh.cc
MeshExporter.cc
MeshLoader.cc
Expand Down Expand Up @@ -102,6 +103,7 @@ set (headers
KeyEvent.hh
KeyFrame.hh
Material.hh
MaterialDensity.hh
Mesh.hh
MeshLoader.hh
MeshManager.hh
Expand Down Expand Up @@ -138,6 +140,7 @@ set (gtest_sources
Image_TEST.cc
ImageHeightmap_TEST.cc
Material_TEST.cc
MaterialDensity_TEST.cc
Mesh_TEST.cc
MeshManager_TEST.cc
MouseEvent_TEST.cc
Expand Down
16 changes: 9 additions & 7 deletions gazebo/common/EnumIface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include <algorithm>
#include "gazebo/util/system.hh"
#include "gazebo/common/Assert.hh"

namespace gazebo
Expand All @@ -36,9 +37,10 @@ namespace gazebo
/// \sa EnumIface
/// \sa EnumIterator
#define GZ_ENUM(enumType, begin, end, ...) \
template<> enumType common::EnumIface<enumType>::range[] = {begin, end}; \
template<> std::vector<std::string> common::EnumIface<enumType>::names = \
{__VA_ARGS__};
template<> GZ_COMMON_VISIBLE enumType \
common::EnumIface<enumType>::range[] = {begin, end}; \
template<> GZ_COMMON_VISIBLE \
std::vector<std::string> common::EnumIface<enumType>::names = {__VA_ARGS__};

/// \brief Enum interface. Use this interface to convert an enum to
/// a string, and set an enum from a string.
Expand Down Expand Up @@ -66,8 +68,8 @@ namespace gazebo
/// set.
static std::string Str(T const &_e)
{
if (_e < names.size())
return names[_e];
if (static_cast<unsigned int>(_e) < names.size())
return names[static_cast<unsigned int>(_e)];
else
return "";
}
Expand Down Expand Up @@ -173,7 +175,7 @@ namespace gazebo
public: EnumIterator &operator++()
{
GZ_ASSERT(this->c != this->End(), "Incrementing past end of enum");
this->c = static_cast<Enum>(this->c + 1);
this->c = static_cast<Enum>(static_cast<int>(this->c) + 1);
return *this;
}

Expand All @@ -192,7 +194,7 @@ namespace gazebo
public: EnumIterator &operator--()
{
GZ_ASSERT(this->c != this->Begin(), "decrementing beyond begin?");
this->c = static_cast<Enum>(this->c - 1);
this->c = static_cast<Enum>(static_cast<int>(this->c) - 1);
return *this;
}

Expand Down
118 changes: 118 additions & 0 deletions gazebo/common/MaterialDensity.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (C) 2016 Open Source Robotics Foundation
*
* 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
*
* 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.
*
*/
#include <ignition/math/Helpers.hh>
#include "gazebo/common/EnumIface.hh"
#include "gazebo/common/MaterialDensity.hh"

using namespace gazebo;
using namespace common;

// Initialize enum iterator, and string converter
GZ_ENUM(MaterialType,
MaterialType::BEGIN,
MaterialType::END,
"Styrofoam",
"Pine",
"Wood",
"Oak",
"Ice",
"Water",
"Plastic",
"Concrete",
"Aluminum",
"Steel, Alloy",
"Steel, Stainless",
"Iron",
"Brass",
"Copper",
"Tungsten",
"end"
)

// Initialize the materials
std::map<MaterialType, double> MaterialDensity::materials =
{
{MaterialType::STYROFOAM, 75.0},
{MaterialType::PINE, 373.0},
{MaterialType::WOOD, 700.0},
{MaterialType::OAK, 710.0},
{MaterialType::ICE, 916.0},
{MaterialType::WATER, 1000.0},
{MaterialType::PLASTIC, 1175.0},
{MaterialType::CONCRETE, 2000.0},
{MaterialType::ALUMINUM, 2700.0},
{MaterialType::STEEL_ALLOY, 7600.0},
{MaterialType::STEEL_STAINLESS, 7800.0},
{MaterialType::IRON, 7870.0},
{MaterialType::BRASS, 8600.0},
{MaterialType::COPPER, 8940.0},
{MaterialType::TUNGSTEN, 19300.0}
};

/////////////////////////////////////////////////
const std::map<MaterialType, double> &MaterialDensity::Materials()
{
return materials;
}

/////////////////////////////////////////////////
double MaterialDensity::Density(const std::string &_material)
{
MaterialType type = MaterialType::END;
EnumIface<MaterialType>::Set(type, _material);

if (type != MaterialType::END)
return materials[type];
else
return -1;
}

/////////////////////////////////////////////////
double MaterialDensity::Density(const MaterialType _material)
{
return materials[_material];
}

/////////////////////////////////////////////////
std::tuple<MaterialType, double> MaterialDensity::Nearest(
const double _value, const double _epsilon)
{
double min = IGN_DBL_MAX;
std::tuple<MaterialType, double> result
{
MaterialType::END, -1.0
};

for (auto const &mat : materials)
{
double diff = std::fabs(mat.second - _value);
if (diff < min && diff < _epsilon)
{
min = diff;
result = mat;
}
}

return result;
}

/////////////////////////////////////////////////
MaterialType MaterialDensity::NearestMaterial(const double _value,
const double _epsilon)
{
return std::get<0>(Nearest(_value, _epsilon));
}
Loading

0 comments on commit 519fee3

Please sign in to comment.