Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored to lib #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

set(CMAKE_INSTALL_PREFIX /usr/bin)

Expand All @@ -11,8 +11,14 @@ include_directories(include)
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (pcd2ptx pcd2ptx.cpp)
file(GLOB HDRS ${CMAKE_CURRENT_SOURCE_DIR}/include/*)

add_library(pcd2ptx pcd2ptx.cpp ${HDRS})
target_include_directories(pcd2ptx PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries (pcd2ptx ${PCL_LIBRARIES})
install(TARGETS pcd2ptx
DESTINATION ${CMAKE_INSTALL_PREFIX}
)


add_executable(ConversionTest tests/conversion_test.cpp)
target_link_libraries(ConversionTest pcd2ptx)

add_test(NAME Conversion_Test COMMAND ConversionTest)
22 changes: 22 additions & 0 deletions include/pcd2ptx.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include <iostream>

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

class Pcd2PtxConverter
{
private:

std::string inputFile;
std::string outputFile;
void writePTXHeader(std::ofstream &file, const int width, const int height);
void writePTXFileXYZ(const std::string &filename, const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud);
void writePTXFileXYZRGB(const std::string &filename, const pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud);

public:
bool execute();
void setInputFile(std::string file);
void setOutputFile(std::string file);

};
25 changes: 18 additions & 7 deletions pcd2ptx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#include <fstream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcd2ptx.hpp>

void writePTXHeader(std::ofstream &file, const int width, const int height)
void Pcd2PtxConverter::writePTXHeader(std::ofstream &file, const int width, const int height)
{
file << width << std::endl
<< height << std::endl;
Expand All @@ -19,7 +20,7 @@ void writePTXHeader(std::ofstream &file, const int width, const int height)
file << 0.f << " " << 0.f << " " << 0.f << " " << 1.f << std::endl;
}

void writePTXFileXYZ(const std::string &filename, const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud)
void Pcd2PtxConverter::writePTXFileXYZ(const std::string &filename, const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud)
{
std::ofstream file(filename.c_str());

Expand All @@ -33,7 +34,7 @@ void writePTXFileXYZ(const std::string &filename, const pcl::PointCloud<pcl::Poi
file.close();
}

void writePTXFileXYZRGB(const std::string &filename, const pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud)
void Pcd2PtxConverter::writePTXFileXYZRGB(const std::string &filename, const pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud)
{
std::ofstream file(filename.c_str());

Expand All @@ -51,14 +52,24 @@ void writePTXFileXYZRGB(const std::string &filename, const pcl::PointCloud<pcl::
file.close();
}

int main()
bool Pcd2PtxConverter::execute()
{
// Load the point cloud data
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::io::loadPCDFile("pc.pcd", *cloud);
pcl::io::loadPCDFile(inputFile, *cloud);

// Save to PTX format
writePTXFileXYZRGB("pc.ptx", cloud);
writePTXFileXYZRGB(outputFile, cloud);

return 0;
return true;
}

void Pcd2PtxConverter::setInputFile(std::string file)
{
inputFile = file;
}

void Pcd2PtxConverter::setOutputFile(std::string file)
{
outputFile = file;
}
10 changes: 10 additions & 0 deletions tests/conversion_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>
#include <pcd2ptx.hpp>

int main(int argc, char **argv)
{
Pcd2PtxConverter converter;
converter.setInputFile("pca-modelo.pcd");
converter.setOutputFile("pca-modelo.ptx");
converter.execute();
}