8 #include <boost/optional.hpp>
9 #include <boost/preprocessor/stringize.hpp>
10 #include <opencv2/core.hpp>
11 #include <opencv2/imgproc.hpp>
12 #include <opencv2/highgui/highgui.hpp>
33 cv::Mat img(500, 500, CV_8UC3, cv::Scalar(239,234,224));
36 cv::line(img,
cv::Point(250, 50),
cv::Point(450, 450), cv::Scalar(0, 0, 0), 3, CV_AA );
38 cv::line(img,
cv::Point(50, 450),
cv::Point(450, 450), cv::Scalar(0, 0, 0), 3, CV_AA );
41 cv::line(img,
cv::Point(150, 250),
cv::Point(350, 250), cv::Scalar(0, 0, 0), 3, CV_AA );
42 cv::line(img,
cv::Point(150, 250),
cv::Point(250, 450), cv::Scalar(0, 0, 0), 3, CV_AA );
43 cv::line(img,
cv::Point(350, 250),
cv::Point(250, 450), cv::Scalar(0, 0, 0), 3, CV_AA );
64 using MergedIO = MyHDF5IO::Merge<MyHDF5IOTest>;
67 if(MyHDF5IO::HasFeature<lvr2::hdf5features::PointCloudIO>)
69 std::cout <<
"MyHDF5IO has the feature lvr2::hdf5features::PointCloudIO" << std::endl;
71 std::cout <<
"MyHDF5IO doesnt have feature lvr2::hdf5features::PointCloudIO" << std::endl;
75 using Duplicate = MyHDF5IO::add_feature<lvr2::hdf5features::PointCloudIO>::type;
78 pointcloud->add(
"points", channel);
80 io.open(
"gen_test.h5");
81 io.save(
"apointcloud",pointcloud);
85 std::cout <<
"has feature check on object success" << std::endl;
91 pcl_io->
save(
"bpointcloud", pointcloud);
99 std::cout <<
"wrong dynamic cast success" << std::endl;
105 std::cout <<
"correct dynamic cast success" << std::endl;
106 dyn_pcl_io->
save(
"cpointcloud", pointcloud);
115 size_t num_data = 10000;
116 boost::shared_array<float> data(
new float[num_data]);
137 my_io.open(
"test.h5");
142 my_io.
save(
"agroup",
"anarray", num_data, data);
144 boost::shared_array<float> data_loaded = my_io.ArrayIO::load<
float>(
"agroup",
"anarray", N);
148 std::cout <<
"ArrayIO successful" << std::endl;
154 my_io.save(
"agroup",
"achannel", channel);
162 if(channel_loaded->numElements() == channel.
numElements() && channel_loaded->width() == channel.
width())
164 std::cout <<
"ChannelIO successful" << std::endl;
167 std::cout <<
"channel not found" << std::endl;
174 pointcloud->add(
"points", channel);
175 my_io.save(
"apointcloud", pointcloud);
177 if(pointcloud_loaded)
179 std::cout <<
"PointCloudIO read success" << std::endl;
180 std::cout << *pointcloud_loaded << std::endl;
182 std::cout <<
"PointCloudIO read failed" << std::endl;
192 = my_io.loadVariantChannel<VChannel>(
"apointcloud",
"points");
195 VChannel vchannel = *ovchannel;
196 std::cout <<
"succesfully read VariantChannel: " << vchannel << std::endl;
198 std::cout <<
"could not load point from group apointcloud" << std::endl;
201 my_io.save(
"apointcloud",
"points2", *ovchannel);
209 std::cout <<
"saving matrix:" << std::endl;
210 std::cout << T << std::endl;
212 my_io.save(
"matrices",
"amatrix", T);
214 auto T2 = my_io.MatrixIO::template load<lvr2::Transformd>(
"matrices",
"amatrix");
217 std::cout <<
"succesfully loaded Matrix:" << std::endl;
218 std::cout << *T2 << std::endl;
220 std::cout <<
"could not load matrix!" << std::endl;
233 cv::Mat a = (cv::Mat_<float>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
234 my_io.save(
"images",
"fallback", a);
235 boost::optional<cv::Mat> mat_loaded = my_io.ImageIO::load(
"images",
"fallback");
239 cv::Mat fb_mat = *mat_loaded;
240 std::cout << a << std::endl;
241 std::cout << fb_mat << std::endl;
243 std::cout <<
"fallback doesnt work" << std::endl;
246 cv::Mat b = cv::Mat::zeros(50, 50, CV_16SC4);
247 my_io.save(
"images",
"fallback2", b);
249 cv::Mat c = *my_io.loadImage(
"images",
"fallback2");
251 if(b.type() == c.type())
253 std::cout <<
"fallback success" << std::endl;
259 my_io.save(
"images",
"image", image);
260 boost::optional<cv::Mat> image_loaded = my_io.ImageIO::load(
"images",
"image");
264 cv::imshow(
"loaded image", *image_loaded);
267 std::cout <<
"could not load image from hdf5 file." << std::endl;
272 cv::cvtColor(image, image_gray, cv::COLOR_BGR2GRAY);
273 my_io.save(
"images",
"image_gray", image_gray);
274 boost::optional<cv::Mat> image_gray_loaded = my_io.ImageIO::load(
"images",
"image_gray");
284 std::cout <<
"N: " << MeshIO::N << std::endl;
287 mesh_io.open(
"test.h5");
291 new float[18] {2, 0, 0, 1, 2, 0, 3, 2, 0, 0, 4, 0, 2, 4, 0, 4, 4, 0}
294 new unsigned int[12] {0, 1, 2, 1, 3, 4, 2, 4, 5, 1, 4, 2}
296 mesh_io.save(
"multimesh/amesh",
mesh);
300 std::cout <<
"MeshIO read success" << std::endl;
301 std::cout << *mesh_loaded << std::endl;
303 std::cout <<
"MeshIO read failed" << std::endl;
313 std::cout << BaseIO::N << std::endl;
316 using MeshIO = BaseIO::AddFeatures<lvr2::hdf5features::MeshIO>;
317 std::cout << MeshIO::N << std::endl;
320 using MeshIO2 = MeshIO::AddFeatures<lvr2::hdf5features::MeshIO, lvr2::hdf5features::ImageIO>;
321 std::cout << MeshIO2::N << std::endl;