Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
txt2pcd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thibault Payet
txt2pcd
Commits
bfadafe0
Verified
Commit
bfadafe0
authored
4 years ago
by
Thibault Payet
Browse files
Options
Downloads
Patches
Plain Diff
add support to convert: x y z and x y z color
parent
6bc4686e
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
add support to convert: x y z and x y z color
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.cpp
+61
-14
61 additions, 14 deletions
main.cpp
with
61 additions
and
14 deletions
main.cpp
+
61
−
14
View file @
bfadafe0
#include
<filesystem>
#include
<fstream>
#include
<ios>
#include
<iostream>
#include
<string>
#include
<pcl/io/ascii_io.h>
#include
<pcl/io/pcd_io.h>
void
txt2pcd
(
std
::
filesystem
::
path
input
,
std
::
filesystem
::
path
output
)
...
...
@@ -11,28 +15,71 @@ void txt2pcd( std::filesystem::path input, std::filesystem::path output )
{
pcl
::
PointCloud
<
pcl
::
PointXYZRGB
>
cloud
;
while
(
!
inputFile
.
eof
()
)
// Read header
std
::
string
line
;
auto
len
=
inputFile
.
tellg
();
char
buf
{
'\0'
};
do
{
inputFile
.
get
(
buf
);
if
(
buf
!=
'\0'
&&
buf
!=
'\n'
)
{
line
.
push_back
(
buf
);
}
}
while
(
buf
!=
'\0'
&&
buf
!=
'\n'
);
auto
numberOfSpace
=
std
::
count
(
std
::
begin
(
line
),
std
::
end
(
line
),
' '
);
if
(
line
.
back
()
==
' '
)
{
if
(
numberOfSpace
>
0
)
{
--
numberOfSpace
;
}
}
auto
const
numArgument
=
numberOfSpace
+
1
;
inputFile
.
seekg
(
len
,
std
::
ios_base
::
beg
);
pcl
::
PCDWriter
pcdWriter
{};
if
(
numArgument
==
6
)
{
pcl
::
PointXYZRGB
point
;
while
(
!
inputFile
.
eof
()
)
{
pcl
::
PointXYZRGB
point
;
inputFile
>>
point
.
x
;
inputFile
>>
point
.
y
;
inputFile
>>
point
.
z
;
inputFile
>>
point
.
x
;
inputFile
>>
point
.
y
;
inputFile
>>
point
.
z
;
int
r
,
g
,
b
;
int
r
,
g
,
b
;
inputFile
>>
r
;
inputFile
>>
g
;
inputFile
>>
b
;
inputFile
>>
r
;
inputFile
>>
g
;
inputFile
>>
b
;
point
.
r
=
static_cast
<
char
>
(
r
);
point
.
g
=
static_cast
<
char
>
(
g
);
point
.
b
=
static_cast
<
char
>
(
b
);
point
.
r
=
static_cast
<
char
>
(
r
);
point
.
g
=
static_cast
<
char
>
(
g
);
point
.
b
=
static_cast
<
char
>
(
b
);
cloud
.
push_back
(
point
);
cloud
.
push_back
(
point
);
}
}
else
{
inputFile
.
close
();
pcl
::
ASCIIReader
reader
;
pcl
::
PCDWriter
pcdWriter
{};
auto
ext
=
input
.
extension
().
string
();
reader
.
setExtension
(
ext
);
reader
.
read
(
input
.
string
(),
cloud
);
}
pcdWriter
.
writeBinaryCompressed
(
output
.
string
(),
cloud
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment