Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
wenqing
ogs
Commits
f1f84d35
Commit
f1f84d35
authored
10 years ago
by
Norihiro Watanabe
Browse files
Options
Downloads
Plain Diff
Merge pull request #34 from TomFischer/add-TIN-tools
Add tin tools
parents
677b96c4
35a2fa8b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
FileIO/TINInterface.cpp
+22
-9
22 additions, 9 deletions
FileIO/TINInterface.cpp
Tests/FileIO/TestGLIReader.cpp
+92
-2
92 additions, 2 deletions
Tests/FileIO/TestGLIReader.cpp
with
114 additions
and
11 deletions
FileIO/TINInterface.cpp
+
22
−
9
View file @
f1f84d35
...
...
@@ -22,26 +22,39 @@
namespace
FileIO
{
GeoLib
::
Surface
*
TINInterface
::
readTIN
(
std
::
string
const
&
fname
,
std
::
vector
<
GeoLib
::
Point
*>
&
pnt_vec
,
std
::
vector
<
std
::
string
>*
errors
)
GeoLib
::
Surface
*
TINInterface
::
readTIN
(
std
::
string
const
&
fname
,
std
::
vector
<
GeoLib
::
Point
*>
&
pnt_vec
,
std
::
vector
<
std
::
string
>*
errors
)
{
// open file
std
::
ifstream
in
(
fname
.
c_str
());
if
(
!
in
)
{
WARN
(
"readTIN(): could not open stream from %s."
,
fname
.
c_str
());
if
(
errors
)
errors
->
push_back
(
"readTINFile error opening stream from "
+
fname
);
if
(
errors
)
errors
->
push_back
(
"readTINFile error opening stream from "
+
fname
);
return
nullptr
;
}
GeoLib
::
Surface
*
sfc
=
new
GeoLib
::
Surface
(
pnt_vec
);
std
::
size_t
id
;
double
p0
[
3
],
p1
[
3
],
p2
[
3
];
while
(
in
.
good
())
std
::
string
line
;
while
(
std
::
getline
(
in
,
line
).
good
())
{
//
read id
if
(
!
(
in
>>
id
))
//
allow empty lines
if
(
line
.
empty
(
))
continue
;
// parse line
std
::
stringstream
input
(
line
);
// read id
if
(
!
(
input
>>
id
))
{
in
.
close
();
delete
sfc
;
return
nullptr
;
}
// read first point
if
(
!
(
in
>>
p0
[
0
]
>>
p0
[
1
]
>>
p0
[
2
]))
{
if
(
!
(
in
put
>>
p0
[
0
]
>>
p0
[
1
]
>>
p0
[
2
]))
{
ERR
(
"Could not read coords of 1st point of triangle %d."
,
id
);
if
(
errors
)
errors
->
push_back
(
std
::
string
(
"readTIN error: "
)
+
...
...
@@ -52,7 +65,7 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, std::vector<Geo
return
nullptr
;
}
// read second point
if
(
!
(
in
>>
p1
[
0
]
>>
p1
[
1
]
>>
p1
[
2
]))
{
if
(
!
(
in
put
>>
p1
[
0
]
>>
p1
[
1
]
>>
p1
[
2
]))
{
ERR
(
"Could not read coords of 2nd point of triangle %d."
,
id
);
if
(
errors
)
errors
->
push_back
(
std
::
string
(
"readTIN error: "
)
+
...
...
@@ -63,7 +76,7 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, std::vector<Geo
return
nullptr
;
}
// read third point
if
(
!
(
in
>>
p2
[
0
]
>>
p2
[
1
]
>>
p2
[
2
]))
{
if
(
!
(
in
put
>>
p2
[
0
]
>>
p2
[
1
]
>>
p2
[
2
]))
{
ERR
(
"Could not read coords of 3rd point of triangle %d."
,
id
);
if
(
errors
)
errors
->
push_back
(
std
::
string
(
"readTIN error: "
)
+
...
...
@@ -86,7 +99,7 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, std::vector<Geo
}
// determine size pnt_vec to insert the correct ids
std
::
size_t
pnt_pos
(
pnt_vec
.
size
());
std
::
size_t
const
pnt_pos
(
pnt_vec
.
size
());
pnt_vec
.
push_back
(
new
GeoLib
::
Point
(
p0
));
pnt_vec
.
push_back
(
new
GeoLib
::
Point
(
p1
));
pnt_vec
.
push_back
(
new
GeoLib
::
Point
(
p2
));
...
...
This diff is collapsed.
Click to expand it.
Tests/FileIO/TestGLIReader.cpp
+
92
−
2
View file @
f1f84d35
...
...
@@ -72,7 +72,74 @@ TEST_F(OGSIOVer4InterfaceTest, SimpleTIN)
boost
::
filesystem
::
remove
(
tin_fname
);
}
TEST_F
(
OGSIOVer4InterfaceTest
,
InvalidTIN
)
TEST_F
(
OGSIOVer4InterfaceTest
,
StillCorrectTINWihtAdditionalValueAtEndOfLine
)
{
std
::
string
tin_fname
(
BaseLib
::
BuildInfo
::
tests_tmp_path
+
"Surface.tin"
);
std
::
ofstream
tin_out
(
tin_fname
);
tin_out
<<
"0 0.0 0.0 0.0 1.0 0.0.0 0.0 0.0 1.0 10
\n
"
;
tin_out
<<
"1 0.0 0.0 0.0 1.0 0.0.0 0.0 0.0 1.0
\n
"
;
tin_out
.
close
();
// read geometry
GeoLib
::
GEOObjects
geometries
;
std
::
vector
<
std
::
string
>
errors
;
std
::
string
geometry_name
(
"TestGeometry"
);
FileIO
::
Legacy
::
readGLIFileV4
(
_gli_fname
,
&
geometries
,
geometry_name
,
errors
);
std
::
vector
<
GeoLib
::
Surface
*>
const
*
sfcs
(
geometries
.
getSurfaceVec
(
geometry_name
));
ASSERT_TRUE
(
sfcs
!=
nullptr
);
ASSERT_EQ
(
1u
,
geometries
.
getSurfaceVec
(
geometry_name
)
->
size
());
ASSERT_EQ
(
2u
,
(
*
geometries
.
getSurfaceVec
(
geometry_name
))[
0
]
->
getNTriangles
());
boost
::
filesystem
::
remove
(
tin_fname
);
}
TEST_F
(
OGSIOVer4InterfaceTest
,
InvalidTIN_ZeroAreaTri
)
{
std
::
string
tin_fname
(
BaseLib
::
BuildInfo
::
tests_tmp_path
+
"Surface.tin"
);
std
::
ofstream
tin_out
(
tin_fname
);
tin_out
<<
"0 0.0 0.0 0.0 1.0 0.0.0 0.0 0.0 0.0
\n
"
;
tin_out
.
close
();
// read geometry
GeoLib
::
GEOObjects
geometries
;
std
::
vector
<
std
::
string
>
errors
;
std
::
string
geometry_name
(
"TestGeometry"
);
FileIO
::
Legacy
::
readGLIFileV4
(
_gli_fname
,
&
geometries
,
geometry_name
,
errors
);
std
::
vector
<
GeoLib
::
Surface
*>
const
*
sfcs
(
geometries
.
getSurfaceVec
(
geometry_name
));
ASSERT_TRUE
(
sfcs
==
nullptr
);
boost
::
filesystem
::
remove
(
tin_fname
);
}
TEST_F
(
OGSIOVer4InterfaceTest
,
InvalidTIN_LineDoesNotStartWithID
)
{
std
::
string
tin_fname
(
BaseLib
::
BuildInfo
::
tests_tmp_path
+
"Surface.tin"
);
std
::
ofstream
tin_out
(
tin_fname
);
tin_out
<<
"0 0.0 0.0 0.0 1.0 0.0.0 0.0 0.0 1.0
\n
"
;
tin_out
<<
"a
\n
"
;
tin_out
<<
"1 0.0 0.0 0.0 1.0 0.0.0 0.0 0.0 1.0
\n
"
;
tin_out
.
close
();
// read geometry
GeoLib
::
GEOObjects
geometries
;
std
::
vector
<
std
::
string
>
errors
;
std
::
string
geometry_name
(
"TestGeometry"
);
FileIO
::
Legacy
::
readGLIFileV4
(
_gli_fname
,
&
geometries
,
geometry_name
,
errors
);
std
::
vector
<
GeoLib
::
Surface
*>
const
*
sfcs
(
geometries
.
getSurfaceVec
(
geometry_name
));
ASSERT_TRUE
(
sfcs
==
nullptr
);
boost
::
filesystem
::
remove
(
tin_fname
);
}
TEST_F
(
OGSIOVer4InterfaceTest
,
InvalidTIN_PointIsMissing
)
{
std
::
string
tin_fname
(
BaseLib
::
BuildInfo
::
tests_tmp_path
+
"Surface.tin"
);
std
::
ofstream
tin_out
(
tin_fname
);
...
...
@@ -93,7 +160,7 @@ TEST_F(OGSIOVer4InterfaceTest, InvalidTIN)
boost
::
filesystem
::
remove
(
tin_fname
);
}
TEST_F
(
OGSIOVer4InterfaceTest
,
InvalidTIN_
II
)
TEST_F
(
OGSIOVer4InterfaceTest
,
InvalidTIN_
CoordOfPointIsMissing
)
{
std
::
string
tin_fname
(
BaseLib
::
BuildInfo
::
tests_tmp_path
+
"Surface.tin"
);
std
::
ofstream
tin_out
(
tin_fname
);
...
...
@@ -114,3 +181,26 @@ TEST_F(OGSIOVer4InterfaceTest, InvalidTIN_II)
boost
::
filesystem
::
remove
(
tin_fname
);
}
TEST_F
(
OGSIOVer4InterfaceTest
,
SimpleTIN_AdditionalEmptyLinesAtEnd
)
{
std
::
string
tin_fname
(
BaseLib
::
BuildInfo
::
tests_tmp_path
+
"Surface.tin"
);
std
::
ofstream
tin_out
(
tin_fname
);
tin_out
<<
"0 0.0 0.0 0.0 1.0 0.0.0 0.0 0.0 1.0 10
\n
"
;
tin_out
<<
"1 0.0 0.0 0.0 1.0 0.0.0 0.0 0.0 1.0
\n\n\n
"
;
tin_out
.
close
();
// read geometry
GeoLib
::
GEOObjects
geometries
;
std
::
vector
<
std
::
string
>
errors
;
std
::
string
geometry_name
(
"TestGeometry"
);
FileIO
::
Legacy
::
readGLIFileV4
(
_gli_fname
,
&
geometries
,
geometry_name
,
errors
);
std
::
vector
<
GeoLib
::
Surface
*>
const
*
sfcs
(
geometries
.
getSurfaceVec
(
geometry_name
));
ASSERT_TRUE
(
sfcs
!=
nullptr
);
ASSERT_EQ
(
1u
,
geometries
.
getSurfaceVec
(
geometry_name
)
->
size
());
ASSERT_EQ
(
2u
,
(
*
geometries
.
getSurfaceVec
(
geometry_name
))[
0
]
->
getNTriangles
());
boost
::
filesystem
::
remove
(
tin_fname
);
}
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