File: convert_raw_image_to_inr.cpp

package info (click to toggle)
cgal 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (51 lines) | stat: -rw-r--r-- 1,394 bytes parent folder | download | duplicates (4)
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
#include <CGAL/ImageIO.h>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>

#define SHOW(attribut) "\n  "#attribut": " << image->attribut
#define SHOWENUM(enumitem) #enumitem"=" << enumitem

using std::cout;
using std::endl;

int main(int argc, char** argv)
{
  if(argc == 2)
  {
    const std::string input_filename = argv[1];
    std::stringstream sub_filename;
    sub_filename << input_filename.substr(0, input_filename.size()-4) << ".txt";

    std::ifstream input_aux_file(sub_filename.str().c_str());
    int xdim, ydim, zdim;
    input_aux_file >> xdim >> ydim >> zdim;
    if(!input_aux_file)
    {
      cout << "\nERROR: cannot read the auxiliary file '" << sub_filename.str() << "'!\n";
      return 1;
    }

    _image* image = ::_readImage_raw(argv[1],
                                     xdim, ydim, zdim);
    if(image)
    {
      input_aux_file >> image->vx >> image->vy >> image->vz;
      if(!input_aux_file)
        image->vx = image->vy = image->vz = 1.;

      std::stringstream output_filename;
      output_filename << input_filename.substr(0, input_filename.size()-4)
#ifdef CGAL_USE_ZLIB
                      << ".inr.gz";
#else
                      << ".inr";
#endif
      return ::_writeImage(image, output_filename.str().c_str());
    }
  }
  else
    std::cerr << "Usage:\n"
              << "  " << argv[0] << " filename.raw\n";
}