Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CGoGN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
CGoGN
CGoGN
Commits
53cd3199
Commit
53cd3199
authored
Jul 24, 2013
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add loading VTK to MC::Image
parent
ca42b69e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
14 deletions
+137
-14
include/Algo/MC/image.h
include/Algo/MC/image.h
+10
-1
include/Algo/MC/image.hpp
include/Algo/MC/image.hpp
+127
-13
No files found.
include/Algo/MC/image.h
View file @
53cd3199
...
...
@@ -133,6 +133,9 @@ protected:
PTRINRIMAGE
mImage
;
#endif
template
<
typename
T
>
void
readVTKBuffer
(
std
::
ifstream
&
in
);
public:
/**
...
...
@@ -168,7 +171,13 @@ public:
*/
bool
loadInrgz
(
const
char
*
filename
);
bool
loadVTK
(
const
char
*
filename
);
/**
* @brief load VTK binary mask image
* @param filename
* @return
*/
bool
loadVTKBinaryMask
(
const
char
*
filename
);
/**
* Constructor
* @param data pointer on voxel
...
...
include/Algo/MC/image.hpp
View file @
53cd3199
...
...
@@ -281,15 +281,39 @@ void Image<DataType>::saveInrMask(const char* filename)
#endif
template
<
typename
DataType
>
template
<
typename
T
>
void
Image
<
DataType
>::
readVTKBuffer
(
std
::
ifstream
&
in
)
{
int
total
=
m_WXY
*
m_WZ
;
if
(
m_Data
!=
NULL
)
delete
[]
m_Data
;
m_Data
=
new
DataType
[
total
];
DataType
*
ptr
=
m_Data
;
T
*
buffer
=
new
T
[
total
];
in
.
read
(
reinterpret_cast
<
char
*>
(
buffer
),
total
*
sizeof
(
T
));
T
*
buf
=
buffer
;
for
(
int
i
=
0
;
i
<
total
;
++
i
)
if
(
*
buf
++
!=
0
)
*
ptr
++
=
255
;
else
*
ptr
++
=
0
;
delete
[]
buffer
;
}
template
<
typename
DataType
>
bool
Image
<
DataType
>::
loadVTK
(
const
char
*
filename
)
bool
Image
<
DataType
>::
loadVTK
BinaryMask
(
const
char
*
filename
)
{
std
::
ifstream
in
(
filename
,
std
::
ios
::
binary
);
if
(
!
in
)
{
CGoGNerr
<<
"Mesh_Base::loadVox: Unable to open file "
<<
CGoGNendl
;
exit
(
0
)
;
return
false
;
}
m_SX
=
1.0
;
...
...
@@ -297,15 +321,23 @@ bool Image<DataType>::loadVTK(const char* filename)
m_SZ
=
1.0
;
// read encoding
// while(in.good())
for
(
unsigned
int
i
=
0
;
i
<
10
;
++
i
)
std
::
string
keyword
;
int
dtType
=
0
;
do
{
char
line
[
1024
]
;
in
.
getline
(
line
,
1024
)
;
std
::
cout
<<
"LINE = "
<<
line
<<
std
::
endl
;
std
::
istringstream
line_input
(
line
)
;
std
::
string
keyword
;
line_input
>>
keyword
;
std
::
cout
<<
"keyword = "
<<
keyword
<<
std
::
endl
;
if
(
keyword
==
"VTK"
)
{
std
::
cout
<<
"reading vtk file"
<<
std
::
endl
;
...
...
@@ -314,32 +346,114 @@ bool Image<DataType>::loadVTK(const char* filename)
line_input
>>
m_WX
;
line_input
>>
m_WY
;
line_input
>>
m_WZ
;
std
::
cout
<<
"DIM= "
<<
m_WX
<<
"/"
<<
m_WY
<<
"/"
<<
m_WZ
<<
std
::
endl
;
}
else
if
(
keyword
==
"SPACING"
)
{
line_input
>>
m_SX
;
line_input
>>
m_SY
;
line_input
>>
m_SZ
;
std
::
cout
<<
"SPACING= "
<<
m_SX
<<
"/"
<<
m_SY
<<
"/"
<<
m_SZ
<<
std
::
endl
;
}
/*else if(keyword == "ORIGIN")
else
if
(
keyword
==
"SCALARS"
)
{
} else if(keyword == "POINT_DATA")
std
::
string
str
;
line_input
>>
str
;
line_input
>>
str
;
std
::
cout
<<
"SCALAR= "
<<
str
<<
std
::
endl
;
if
(
str
==
"unsigned_char"
)
dtType
=
1
;
else
if
(
str
==
"unsigned_short"
)
dtType
=
2
;
else
if
(
str
==
"unsigned_int"
)
dtType
=
3
;
else
if
(
str
==
"char"
)
dtType
=
4
;
else
if
(
str
==
"short"
)
dtType
=
5
;
else
if
(
str
==
"int"
)
dtType
=
6
;
}
/*else if(keyword == "POINT_DATA")
{
} */
}
}
while
(
keyword
!=
"LOOKUP_TABLE"
);
m_WXY
=
m_WX
*
m_WY
;
int
total
=
m_WXY
*
m_WZ
;
//
int total = m_WXY * m_WZ;
m_Data
=
new
DataType
[
total
];
// m_Data = new DataType[total];
// DataType* ptr = m_Data;
switch
(
dtType
)
{
case
1
:
readVTKBuffer
<
unsigned
char
>
(
in
);
// {
// unsigned char* buffer = new unsigned char[total];
// in.read(reinterpret_cast<char*>(buffer), total*sizeof(unsigned char));
// unsigned char* buf = buffer;
// for (int i=0; i<total; ++i)
// if (*buf++ !=0)
// *ptr++ = 255;
// else
// *ptr++ = 0;
// delete[] buffer;
// }
break
;
in
.
read
(
reinterpret_cast
<
char
*>
(
m_Data
),
total
*
sizeof
(
DataType
));
case
2
:
readVTKBuffer
<
unsigned
short
>
(
in
);
// {
// unsigned short* buffer = new unsigned short[total];
// in.read(reinterpret_cast<char*>(buffer), total*sizeof(unsigned short));
// unsigned short* buf = buffer;
// for (int i=0; i<total; ++i)
// if (*buf++ !=0)
// *ptr++ = 255;
// else
// *ptr++ = 0;
// delete[] buffer;
// }
break
;
case
3
:
readVTKBuffer
<
unsigned
int
>
(
in
);
// {
// unsigned int* buffer = new unsigned int[total];
// in.read(reinterpret_cast<char*>(buffer), total*sizeof(unsigned int));
// unsigned int* buf = buffer;
// for (int i=0; i<total; ++i)
// if (*buf++ !=0)
// *ptr++ = 255;
// else
// *ptr++ = 0;
// delete[] buffer;
// }
break
;
case
4
:
readVTKBuffer
<
char
>
(
in
);
break
;
case
5
:
readVTKBuffer
<
short
>
(
in
);
break
;
case
6
:
readVTKBuffer
<
int
>
(
in
);
break
;
default:
CGoGNerr
<<
"unknown format"
<<
CGoGNendl
;
break
;
}
m_Alloc
=
true
;
return
true
;
}
template
<
typename
DataType
>
bool
Image
<
DataType
>::
loadIPB
(
const
char
*
filename
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment