Skip to content

Commit 7c99e4c

Browse files
Cleanup test_sample_consensus
1 parent 545f423 commit 7c99e4c

File tree

1 file changed

+24
-44
lines changed

1 file changed

+24
-44
lines changed

test/sample_consensus/test_sample_consensus.cpp

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838

3939
#include <gtest/gtest.h>
4040

41-
#include <boost/bind.hpp>
42-
#include <boost/date_time/posix_time/posix_time.hpp>
43-
#include <boost/function.hpp>
44-
4541
#include <pcl/sample_consensus/msac.h>
4642
#include <pcl/sample_consensus/lmeds.h>
4743
#include <pcl/sample_consensus/rmsac.h>
@@ -57,7 +53,6 @@
5753
#include <thread>
5854

5955
using namespace pcl;
60-
using namespace std::chrono_literals;
6156

6257
typedef SampleConsensusModelSphere<PointXYZ>::Ptr SampleConsensusModelSpherePtr;
6358

@@ -87,32 +82,7 @@ TEST (SampleConsensus, Base)
8782
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8883
// Test if RANSAC finishes within a second.
8984
template <typename SacT>
90-
class SacTest : public ::testing::Test
91-
{
92-
public:
93-
94-
void SetUp ()
95-
{
96-
97-
const unsigned point_count = 100;
98-
PointCloud<PointXYZ> cloud;
99-
cloud.points.resize (point_count);
100-
for (unsigned idx = 0; idx < point_count; ++idx)
101-
{
102-
cloud.points[idx].x = static_cast<float> (idx);
103-
cloud.points[idx].y = 0.0;
104-
cloud.points[idx].z = 0.0;
105-
}
106-
107-
boost::function<bool ()> sac_function;
108-
SampleConsensusModelSpherePtr model (new SampleConsensusModelSphere<PointXYZ> (cloud.makeShared ()));
109-
110-
sac_ = std::make_unique<SacT> (model, 0.03);
111-
}
112-
113-
std::unique_ptr<SacT> sac_;
114-
};
115-
85+
class SacTest : public ::testing::Test {};
11686

11787
using sacTypes = ::testing::Types<
11888
RandomSampleConsensus<PointXYZ>,
@@ -126,20 +96,29 @@ TYPED_TEST_CASE(SacTest, sacTypes);
12696

12797
TYPED_TEST(SacTest, InfiniteLoop)
12898
{
99+
using namespace std::chrono_literals;
100+
101+
const unsigned point_count = 100;
102+
PointCloud<PointXYZ> cloud;
103+
cloud.points.resize (point_count);
104+
for (unsigned idx = 0; idx < point_count; ++idx)
105+
{
106+
cloud.points[idx].x = static_cast<float> (idx);
107+
cloud.points[idx].y = 0.0;
108+
cloud.points[idx].z = 0.0;
109+
}
110+
111+
SampleConsensusModelSpherePtr model (new SampleConsensusModelSphere<PointXYZ> (cloud.makeShared ()));
112+
TypeParam sac (model, 0.03);
113+
129114
// Set up timed conditions
130115
std::condition_variable cv;
131116
std::mutex mtx;
132-
#if defined(DEBUG) || defined(_DEBUG)
133-
std::chrono::seconds delay (15);
134-
#else
135-
std::chrono::seconds delay (1);
136-
#endif
137-
138117

139118
// Create the RANSAC object
140-
std::thread thread1 ([this,&mtx, &cv] ()
119+
std::thread thread ([&] ()
141120
{
142-
this->sac_->computeModel (0);
121+
sac.computeModel (0);
143122

144123
// Notify things are done
145124
std::lock_guard<std::mutex> lock (mtx);
@@ -149,16 +128,17 @@ TYPED_TEST(SacTest, InfiniteLoop)
149128

150129
// Waits for the delay
151130
std::unique_lock<std::mutex> lock (mtx);
152-
EXPECT_EQ (std::cv_status::no_timeout, cv.wait_for (lock, delay));
153-
thread1.join ();
131+
#if defined(DEBUG) || defined(_DEBUG)
132+
EXPECT_EQ (std::cv_status::no_timeout, cv.wait_for (lock, 15s));
133+
#else
134+
EXPECT_EQ (std::cv_status::no_timeout, cv.wait_for (lock, 1s));
135+
#endif
136+
thread.join ();
154137
}
155138

156-
157-
158139
int
159140
main (int argc, char** argv)
160141
{
161142
testing::InitGoogleTest (&argc, argv);
162143
return (RUN_ALL_TESTS ());
163144
}
164-

0 commit comments

Comments
 (0)