Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
O
openfpm_io
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openfpm
openfpm_io
Commits
daf30b1c
Commit
daf30b1c
authored
Nov 03, 2014
by
incardon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First commit
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
222 additions
and
0 deletions
+222
-0
src/MatLabWriter.hpp
src/MatLabWriter.hpp
+111
-0
src/TiffWriter.hpp
src/TiffWriter.hpp
+111
-0
No files found.
src/MatLabWriter.hpp
0 → 100644
View file @
daf30b1c
#ifndef MATLABWRITER_HPP
#define MATLABWRITER_HPP
#include <iostream>
#include "tiffio.h"
#include "map_grid.hpp"
#include <string>
/*! \brief This class is able to save grid into tiff files
*
* This class is able to save grid into tiff files
*
*/
template
<
unsigned
int
dim
,
typename
T
>
class
TiffWriter
{
/*! \brief Save grid into tiff files
*
* Save grid into tiff files
*
*/
template
<
typename
grid
,
typename
Mem
>
int
write
(
grid
data
,
std
::
string
file
)
{
// Grid can have several properties we can save only scalar fields
// for each properties save one scalar fields
// Tiff files can be saved up to 5D
if
(
dim
>
5
)
{
std
::
cerr
<<
"Error Tiff writer support until 5D images"
<<
"
\n
"
;
}
// Open the tiff image
uint32
width
;
uint32
height
;
TIFF
*
tif
=
TIFFOpen
(
file
.
c_str
(),
"w"
);
// if the file is open
if
(
tif
)
{
// set width and height for 2D
width
=
data
.
getGrid
().
size
(
0
);
height
=
data
.
getGrid
().
size
(
1
);
TIFFSetField
(
tif
,
TIFFTAG_IMAGEWIDTH
,
&
width
);
TIFFSetField
(
tif
,
TIFFTAG_IMAGELENGTH
,
&
height
);
// Create the tiff line, in case the grid is CPU, we have only
// one property and is a scalar, we can directly copy the line
typename
boost
::
fusion
::
result_of
::
at
<
T
::
type
,
0
>::
type
first_element_type
;
if
(
typeid
(
grid
).
name
()
==
"grid_cpu"
&&
T
::
num_prop
==
1
&&
boost
::
is_array
<
first_element_type
>::
type
::
value
==
true
)
{
// Get the grid key iterator
grid_key_dx_iterator
<
dim
>
key
=
data
.
getIterator
();
// write all lines
for
(
int
i
=
0
;
i
<
height
;
i
++
)
{
// select the correct lines
key
.
set
(
1
,
i
);
// we have only one scalar properties, get the buffer pointer
void
*
buf
=
&
data
.
template
get
<
0
>(
key
);
TIFFWriteScanline
(
tif
,
buf
,
i
,
0
);
}
}
else
{
// we have to create the a scan line for each properties and index array
// each property and index array became a channel
// Get the grid key iterator
grid_key_dx_iterator
<
dim
>
key
=
data
.
getIterator
();
// count how many properties and how many indexes we have
const
int
n_prp
=
total_prop
<
T
>
;
// write all lines
for
(
int
i
=
0
;
i
<
height
;
i
++
)
{
// select the correct lines
key
.
set
(
1
,
i
);
// we have only one scalar properties, get the buffer pointer
void
*
buf
=
&
data
.
template
get
<
0
>(
key
);
TIFFWriteScanline
(
tif
,
buf
,
i
,
0
);
}
}
}
}
};
#endif
src/TiffWriter.hpp
0 → 100644
View file @
daf30b1c
#ifndef TIFFWRITER_HPP
#define TIFFWRITER_HPP
#include <iostream>
#include "tiffio.h"
#include "map_grid.hpp"
#include <string>
/*! \brief This class is able to save grid into tiff files
*
* This class is able to save grid into tiff files
*
*/
template
<
unsigned
int
dim
,
typename
T
>
class
TiffWriter
{
/*! \brief Save grid into tiff files
*
* Save grid into tiff files
*
*/
template
<
typename
grid
,
typename
Mem
>
int
write
(
grid
data
,
std
::
string
file
)
{
// Grid can have several properties we can save only scalar fields
// for each properties save one scalar fields
// Tiff files can be saved up to 5D
if
(
dim
>
5
)
{
std
::
cerr
<<
"Error Tiff writer support until 5D images"
<<
"
\n
"
;
}
// Open the tiff image
uint32
width
;
uint32
height
;
TIFF
*
tif
=
TIFFOpen
(
file
.
c_str
(),
"w"
);
// if the file is open
if
(
tif
)
{
// set width and height for 2D
width
=
data
.
getGrid
().
size
(
0
);
height
=
data
.
getGrid
().
size
(
1
);
TIFFSetField
(
tif
,
TIFFTAG_IMAGEWIDTH
,
&
width
);
TIFFSetField
(
tif
,
TIFFTAG_IMAGELENGTH
,
&
height
);
// Create the tiff line, in case the grid is CPU, we have only
// one property and is a scalar, we can directly copy the line
typename
boost
::
fusion
::
result_of
::
at
<
T
::
type
,
0
>::
type
first_element_type
;
if
(
typeid
(
grid
).
name
()
==
"grid_cpu"
&&
T
::
num_prop
==
1
&&
boost
::
is_array
<
first_element_type
>::
type
::
value
==
true
)
{
// Get the grid key iterator
grid_key_dx_iterator
<
dim
>
key
=
data
.
getIterator
();
// write all lines
for
(
int
i
=
0
;
i
<
height
;
i
++
)
{
// select the correct lines
key
.
set
(
1
,
i
);
// we have only one scalar properties, get the buffer pointer
void
*
buf
=
&
data
.
template
get
<
0
>(
key
);
TIFFWriteScanline
(
tif
,
buf
,
i
,
0
);
}
}
else
{
// we have to create the a scan line for each properties and index array
// each property and index array became a channel
// Get the grid key iterator
grid_key_dx_iterator
<
dim
>
key
=
data
.
getIterator
();
// count how many properties and how many indexes we have
const
int
n_prp
=
total_prop
<
T
>
;
// write all lines
for
(
int
i
=
0
;
i
<
height
;
i
++
)
{
// select the correct lines
key
.
set
(
1
,
i
);
// we have only one scalar properties, get the buffer pointer
void
*
buf
=
&
data
.
template
get
<
0
>(
key
);
TIFFWriteScanline
(
tif
,
buf
,
i
,
0
);
}
}
}
}
};
#endif
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