-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateMincFile.h
57 lines (43 loc) · 1.3 KB
/
CreateMincFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <string>
#include <iostream>
#include <sstream>
#include <cstdio>
/* Create a MINC file using rawtominc.
* The "args" argument contains arguments passed to "rawtominc".
* Files with 2, 3, or 4 dimensions may be created.
*/
namespace detail {
std::string createMincFile( const std::string& args,
unsigned int sampleCount )
{
std::string command( "rawtominc -clobber -2 -unsigned -byte " );
command += args;
//std::cout << "Executing [" << command << "]\n";
FILE* rawtominc = popen( command.c_str(), "w" );
unsigned char value = 0;
for( unsigned int i = 0; i < sampleCount; ++i )
{
fwrite( &value, sizeof(value), 1, rawtominc );
value += 1;
}
pclose( rawtominc );
return command;
}
}
std::string createMincFile( const std::string& extra_args,
unsigned int size1,
unsigned int size2 )
{
std::stringstream args;
args << extra_args << " " << size1 << " " << size2;
return detail::createMincFile( args.str(), size1 * size2 );
}
std::string createMincFile( const std::string& extra_args,
unsigned int size1,
unsigned int size2,
unsigned int size3 )
{
std::stringstream args;
args << extra_args << " " << size1 << " " << size2 << " " << size3;
return detail::createMincFile( args.str(), size1 * size2 * size3 );
}