Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISBI2016-filaSimu-TM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Vladimír Ulman
ISBI2016-filaSimu-TM
Commits
ea664931
There was an error fetching the commit references. Please try again later.
Commit
ea664931
authored
8 years ago
by
Vladimír Ulman
Browse files
Options
Downloads
Patches
Plain Diff
Added support for reading volumetric and surface meshes in VTK.
parent
3e5f04de
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmath3d/TriangleMesh.cpp
+206
-1
206 additions, 1 deletion
cmath3d/TriangleMesh.cpp
cmath3d/TriangleMesh.h
+2
-0
2 additions, 0 deletions
cmath3d/TriangleMesh.h
src/main.cpp
+6
-1
6 additions, 1 deletion
src/main.cpp
with
214 additions
and
2 deletions
cmath3d/TriangleMesh.cpp
+
206
−
1
View file @
ea664931
...
...
@@ -174,7 +174,7 @@ int ActiveMesh::ImportSTL(const char *filename)
}
int
ActiveMesh
::
ImportVTK
(
const
char
*
filename
)
int
ActiveMesh
::
ImportVTK
(
const
char
*
filename
)
//surface version
{
Pos
.
clear
();
ID
.
clear
();
...
...
@@ -184,8 +184,213 @@ int ActiveMesh::ImportVTK(const char *filename)
std
::
ifstream
file
(
filename
);
if
(
!
file
.
is_open
())
return
1
;
//read the "header" line
char
tmp
[
1024
];
file
>>
tmp
>>
tmp
;
//dangerous...
//check tmp for "vtk" or complain
if
(
tmp
[
0
]
!=
'v'
||
tmp
[
1
]
!=
't'
||
tmp
[
2
]
!=
'k'
)
{
file
.
close
();
return
(
2
);
}
//read (and skip) the rest of the header line
file
.
ignore
(
10240
,
'\n'
);
//ignore "vtk output"
file
.
ignore
(
10240
,
'\n'
);
//read "ASCII"
file
>>
tmp
;
if
(
tmp
[
0
]
!=
'A'
||
tmp
[
1
]
!=
'S'
||
tmp
[
2
]
!=
'C'
||
tmp
[
3
]
!=
'I'
||
tmp
[
4
]
!=
'I'
)
{
file
.
close
();
return
(
3
);
}
file
.
ignore
(
10240
,
'\n'
);
//ignore "DATASET POLYDATA"
file
.
ignore
(
10240
,
'\n'
);
//read points header
int
itemCount
;
file
>>
tmp
>>
itemCount
;;
if
(
tmp
[
0
]
!=
'P'
||
tmp
[
1
]
!=
'O'
||
tmp
[
2
]
!=
'I'
||
tmp
[
3
]
!=
'N'
||
tmp
[
4
]
!=
'T'
||
tmp
[
5
]
!=
'S'
)
{
file
.
close
();
return
(
4
);
}
file
.
ignore
(
10240
,
'\n'
);
std
::
cout
<<
"reading "
<<
itemCount
<<
" point coordinates
\n
"
;
Pos
.
reserve
(
itemCount
);
//read all points...
float
x
,
y
,
z
;
while
(
itemCount
>
0
&&
file
>>
x
)
{
file
>>
y
>>
z
;
//... and save them
Vector3FC
v1
(
x
,
y
,
z
);
v1
*=
100.
f
;
Pos
.
push_back
(
v1
);
--
itemCount
;
}
std
::
cout
<<
"last coordinate was: "
<<
x
<<
","
<<
y
<<
","
<<
z
<<
"
\n
"
;
//prepare "information about faces normals"
Vector3F
fictiveNormal
(
1.
f
,
0.
f
,
0.
f
);
//read polyhedra header
file
>>
tmp
>>
itemCount
;
if
(
tmp
[
0
]
!=
'P'
||
tmp
[
1
]
!=
'O'
||
tmp
[
2
]
!=
'L'
||
tmp
[
3
]
!=
'Y'
||
tmp
[
4
]
!=
'G'
||
tmp
[
5
]
!=
'O'
||
tmp
[
6
]
!=
'N'
||
tmp
[
7
]
!=
'S'
)
{
file
.
close
();
return
(
5
);
}
file
.
ignore
(
10240
,
'\n'
);
std
::
cout
<<
"reading "
<<
itemCount
<<
" triangles
\n
"
;
ID
.
reserve
(
3
*
itemCount
);
norm
.
reserve
(
itemCount
);
//read all polyhedra vertices
int
ignore
,
v1
,
v2
,
v3
;
while
(
itemCount
>
0
&&
file
>>
ignore
&&
ignore
==
3
)
{
file
>>
v1
>>
v2
>>
v3
;
//save v1,v2,v3 (TODO: if not already saved...)
ID
.
push_back
(
v1
);
ID
.
push_back
(
v2
);
ID
.
push_back
(
v3
);
norm
.
push_back
(
fictiveNormal
);
--
itemCount
;
}
std
::
cout
<<
"last triangle was: "
<<
v1
<<
","
<<
v2
<<
","
<<
v3
<<
"
\n
"
;
file
.
close
();
return
(
0
);
}
int
ActiveMesh
::
ImportVTK_Volumetric
(
const
char
*
filename
)
{
Pos
.
clear
();
ID
.
clear
();
norm
.
clear
();
//try to open the file
std
::
ifstream
file
(
filename
);
if
(
!
file
.
is_open
())
return
1
;
//read the "header" line
char
tmp
[
1024
];
file
>>
tmp
>>
tmp
;
//dangerous...
//check tmp for "vtk" or complain
if
(
tmp
[
0
]
!=
'v'
||
tmp
[
1
]
!=
't'
||
tmp
[
2
]
!=
'k'
)
{
file
.
close
();
return
(
2
);
}
//read (and skip) the rest of the header line
file
.
ignore
(
10240
,
'\n'
);
//ignore "vtk output"
file
.
ignore
(
10240
,
'\n'
);
//read "ASCII"
file
>>
tmp
;
if
(
tmp
[
0
]
!=
'A'
||
tmp
[
1
]
!=
'S'
||
tmp
[
2
]
!=
'C'
||
tmp
[
3
]
!=
'I'
||
tmp
[
4
]
!=
'I'
)
{
file
.
close
();
return
(
3
);
}
file
.
ignore
(
10240
,
'\n'
);
//ignore "DATASET UNSTRUCTURED GRID"
file
.
ignore
(
10240
,
'\n'
);
//read points header
int
itemCount
;
file
>>
tmp
>>
itemCount
;;
if
(
tmp
[
0
]
!=
'P'
||
tmp
[
1
]
!=
'O'
||
tmp
[
2
]
!=
'I'
||
tmp
[
3
]
!=
'N'
||
tmp
[
4
]
!=
'T'
||
tmp
[
5
]
!=
'S'
)
{
file
.
close
();
return
(
4
);
}
file
.
ignore
(
10240
,
'\n'
);
std
::
cout
<<
"reading "
<<
itemCount
<<
" point coordinates
\n
"
;
Pos
.
reserve
(
itemCount
);
//read all points...
float
x
,
y
,
z
;
while
(
itemCount
>
0
&&
file
>>
x
)
{
file
>>
y
>>
z
;
//... and save them
Vector3FC
v1
(
x
,
y
,
z
);
v1
*=
100.
f
;
Pos
.
push_back
(
v1
);
--
itemCount
;
}
std
::
cout
<<
"last coordinate was: "
<<
x
<<
","
<<
y
<<
","
<<
z
<<
"
\n
"
;
//prepare "information about faces normals"
Vector3F
fictiveNormal
(
1.
f
,
0.
f
,
0.
f
);
//read polyhedra header
file
>>
tmp
>>
itemCount
;
if
(
tmp
[
0
]
!=
'C'
||
tmp
[
1
]
!=
'E'
||
tmp
[
2
]
!=
'L'
||
tmp
[
3
]
!=
'L'
||
tmp
[
4
]
!=
'S'
)
{
file
.
close
();
return
(
5
);
}
file
.
ignore
(
10240
,
'\n'
);
std
::
cout
<<
"reading "
<<
itemCount
<<
" polyhedra
\n
"
;
ID
.
reserve
(
3
*
itemCount
);
norm
.
reserve
(
itemCount
);
//read all polyhedra vertices
int
ignore
,
v1
,
v2
,
v3
,
v4
;
while
(
itemCount
>
0
&&
file
>>
ignore
)
{
file
>>
v1
>>
v2
>>
v3
>>
v4
;
//save v1,v2,v3 (TODO: if not already saved...)
ID
.
push_back
(
v1
);
ID
.
push_back
(
v2
);
ID
.
push_back
(
v3
);
norm
.
push_back
(
fictiveNormal
);
//save v1,v2,v4 (TODO: if not already saved...)
ID
.
push_back
(
v1
);
ID
.
push_back
(
v2
);
ID
.
push_back
(
v4
);
norm
.
push_back
(
fictiveNormal
);
//save v1,v4,v3 (TODO: if not already saved...)
ID
.
push_back
(
v1
);
ID
.
push_back
(
v4
);
ID
.
push_back
(
v3
);
norm
.
push_back
(
fictiveNormal
);
//save v4,v2,v3 (TODO: if not already saved...)
ID
.
push_back
(
v4
);
ID
.
push_back
(
v2
);
ID
.
push_back
(
v3
);
norm
.
push_back
(
fictiveNormal
);
--
itemCount
;
}
std
::
cout
<<
"last polyhedron was: "
<<
v1
<<
","
<<
v2
<<
","
<<
v3
<<
","
<<
v4
<<
"
\n
"
;
file
.
close
();
return
(
0
);
...
...
This diff is collapsed.
Click to expand it.
cmath3d/TriangleMesh.h
+
2
−
0
View file @
ea664931
...
...
@@ -97,6 +97,8 @@ class ActiveMesh
///returns 0 on success, otherwise non-zero
int
ImportSTL
(
const
char
*
filename
);
int
ImportVTK
(
const
char
*
filename
);
int
ImportVTK_Volumetric
(
const
char
*
filename
);
void
RenderMask
(
i3d
::
Image3d
<
i3d
::
GRAY16
>&
mask
);
void
RenderMaskB
(
i3d
::
Image3d
<
i3d
::
GRAY16
>&
mask
);
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
+
6
−
1
View file @
ea664931
...
...
@@ -20,7 +20,12 @@ int main(void)
//char filename[]="../sample_input/torus_100_30.stl";
char
filename
[]
=
"../sample_input/sphere.stl"
;
int
retval
=
mesh
.
ImportSTL
(
filename
);
char
VTKfile
[]
=
"../sample_input/ID1_t001_nucleusSurf2148.vtk"
;
//surface
//char VTKfile[]="../sample_input/ID1_t001_nucleus2038.vtk"; //volumetric
//int retval=mesh.ImportSTL(filename);
int
retval
=
mesh
.
ImportVTK
(
VTKfile
);
//int retval=mesh.ImportVTK_Volumetric(VTKfile);
if
(
retval
)
{
std
::
cout
<<
"some error reading file: "
<<
retval
<<
"
\n
"
;
...
...
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