Skip to content

Commit c200eb0

Browse files
authored
Various Updates (#14)
* Fixed default material manager * Replaced PCL PCA * Removed dependency on PCL * Added override keyword to destructors * Added Eigen target for Xenial
1 parent 06baa00 commit c200eb0

File tree

6 files changed

+29
-27
lines changed

6 files changed

+29
-27
lines changed

CMakeLists.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ set(CMAKE_CXX_STANDARD 14)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_CXX_EXTENSIONS OFF)
77

8+
find_package(Eigen3 REQUIRED)
9+
if(NOT TARGET Eigen3::Eigen)
10+
if(NOT EIGEN3_INCLUDE_DIRS)
11+
set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
12+
endif()
13+
find_package(Threads REQUIRED)
14+
add_library(Eigen3::Eigen IMPORTED INTERFACE)
15+
set_property(TARGET Eigen3::Eigen PROPERTY INTERFACE_COMPILE_DEFINITIONS ${EIGEN3_DEFINITIONS})
16+
set_property(TARGET Eigen3::Eigen PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${EIGEN3_INCLUDE_DIRS})
17+
endif()
18+
19+
find_package(Qt5 REQUIRED COMPONENTS Widgets)
820
find_package(catkin REQUIRED COMPONENTS
921
rviz
1022
pluginlib
11-
pcl_ros
1223
)
1324

14-
find_package(Eigen3 REQUIRED)
15-
1625
catkin_package(
1726
INCLUDE_DIRS
1827
include
@@ -21,7 +30,6 @@ catkin_package(
2130
CATKIN_DEPENDS
2231
rviz
2332
pluginlib
24-
pcl_ros
2533
)
2634

2735
###########
@@ -33,9 +41,6 @@ include_directories(
3341
${catkin_INCLUDE_DIRS}
3442
)
3543

36-
# QT
37-
find_package(Qt5 ${rviz_QT_VERSION} EXACT REQUIRED Core Widgets)
38-
3944
qt5_wrap_cpp(MOC_FILES
4045
include/${PROJECT_NAME}/rviz_tool_cursor.h
4146
src/circle_tool_cursor.h
@@ -51,6 +56,7 @@ add_library(tool_cursor
5156
target_link_libraries(tool_cursor
5257
${catkin_LIBRARIES}
5358
Qt5::Widgets
59+
Eigen3::Eigen
5460
)
5561

5662
#############

package.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<license>Apache 2.0</license>
1111

1212
<buildtool_depend>catkin</buildtool_depend>
13-
<depend>rviz</depend>
13+
<build_depend>eigen</build_depend>
14+
<build_depend>qtbase5-dev</build_depend>
15+
<depend>libqt5-widgets</depend>
1416
<depend>pluginlib</depend>
15-
<depend>pcl_ros</depend>
17+
<depend>rviz</depend>
1618

1719
<export>
1820
<rviz plugin="${prefix}/plugin_description.xml"/>

src/circle_tool_cursor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Q_OBJECT
2323

2424
CircleToolCursor();
2525

26-
virtual ~CircleToolCursor();
26+
virtual ~CircleToolCursor() override;
2727

2828
public Q_SLOTS:
2929

src/mesh_tool_cursor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MeshToolCursor::MeshToolCursor()
2424
"The mesh resource to display as a cursor",
2525
getPropertyContainer(), SLOT(updateToolVisualization()), this);
2626

27-
material_ = Ogre::MaterialManager::getSingletonPtr()->create(COLOR_NAME, "rviz");
27+
material_ = Ogre::MaterialManager::getSingletonPtr()->create(COLOR_NAME, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
2828

2929
const Ogre::ColourValue& color = color_property_->getOgreColor();
3030
material_->getTechnique(0)->getPass(0)->setDiffuse(color.r, color.g, color.b, 1.0);

src/mesh_tool_cursor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Q_OBJECT
1919

2020
MeshToolCursor();
2121

22-
virtual ~MeshToolCursor();
22+
virtual ~MeshToolCursor() override;
2323

2424
public Q_SLOTS:
2525

src/rviz_tool_cursor/rviz_tool_cursor.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
#include <Eigen/Dense>
1919

20-
#include <pcl/common/pca.h>
21-
2220
namespace
2321
{
2422

@@ -52,29 +50,25 @@ Eigen::Matrix3f createMatrix(const Eigen::Vector3f& norm)
5250
Ogre::Quaternion estimateNormal(const std::vector<Ogre::Vector3>& points,
5351
const Ogre::Vector3& camera_norm)
5452
{
55-
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ> ());
53+
Eigen::MatrixXf data;
54+
data.resize(points.size(), 3);
5655

5756
for(std::size_t i = 0; i < points.size(); ++i)
5857
{
59-
pcl::PointXYZ pt;
60-
pt.x = points[i].x;
61-
pt.y = points[i].y;
62-
pt.z = points[i].z;
63-
64-
cloud->push_back(pt);
58+
data.row(i) = Eigen::Map<const Eigen::Vector3f>(points[i].ptr());
6559
}
6660

61+
Eigen::MatrixXf centered = data.rowwise() - data.colwise().mean();
62+
6763
// Use principal component analysis to the get eigenvectors
68-
pcl::PCA<pcl::PointXYZ> pca;
69-
pca.setInputCloud(cloud);
70-
Eigen::Matrix3f& evecs = pca.getEigenVectors();
64+
Eigen::MatrixXf cov = centered.transpose() * centered;
65+
Eigen::SelfAdjointEigenSolver<Eigen::MatrixXf> eig(cov);
7166

7267
// Get the eigenvector associated with the smallest eigenvalue
7368
// (should be Z-axis, assuming points are relatively planar)
74-
Eigen::Vector3f norm = evecs.col(2);
69+
Eigen::Vector3f norm = eig.eigenvectors().col(0);
7570
norm.normalize();
7671

77-
// The
7872
Eigen::Vector3f camera_normal;
7973
camera_normal << camera_norm.x, camera_norm.y, camera_norm.z;
8074
camera_normal.normalize();
@@ -84,7 +78,7 @@ Ogre::Quaternion estimateNormal(const std::vector<Ogre::Vector3>& points,
8478
norm *= -1;
8579
}
8680

87-
// Create a random orientation matrix with the normal being in the direction of the smalles eigenvector
81+
// Create an arbitrary orientation matrix with the normal being in the direction of the smallest eigenvector
8882
Eigen::Matrix3f mat = createMatrix(norm);
8983

9084
Eigen::Quaternionf q(mat); //Eigen::AngleAxisf(0.0, evecs.col(2)));

0 commit comments

Comments
 (0)