File: float3d.cpp

package info (click to toggle)
odin 2.0.5-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,196 kB
  • sloc: cpp: 62,638; sh: 4,541; makefile: 779
file content (139 lines) | stat: -rw-r--r-- 4,069 bytes parent folder | download | duplicates (5)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <qslider.h>

#include <odinpara/ldrtypes.h> // for LDRfileName

#include "float3d.h"


floatBox3D::floatBox3D(const float *data, float lowbound, float uppbound, long int nx, long int ny, long int nz,
                       bool disable_scale, int coarseFactor, QWidget *parent, const char *name,
                       const float *overlay_map, float lowbound_map, float uppbound_map, unsigned int nx_map, unsigned int ny_map, unsigned int nz_map, bool map_firescale, float map_rectsize,
                       bool colormap)
 : QGroupBox(name,parent) {
  Log<OdinQt> odinlog("floatBox3D","floatBox3D");

  data_cache=data;
  oneimagesize=nx*ny;
  nz_cache=nz;

  lowbound_cache=lowbound;
  uppbound_cache=uppbound;

  map_cache=0;
  onemapsize=0;

  lowbound_map_cache=lowbound_map;
  uppbound_map_cache=uppbound_map;
  rectsize_map_cache=map_rectsize;

  if(overlay_map) {
    if(nz==nz_map) {
      map_cache=overlay_map;
      onemapsize=nx_map*ny_map;
      ODINLOG(odinlog,normalDebug) << "map_cache/onemapsize/nz_map=" << map_cache << "/" << onemapsize << "/" << nz_map << STD_endl;
    } else {
      ODINLOG(odinlog,errorLog) << "Cannot handle overlay_map with nz(" << nz_map << ") differing from data's nz(" << nz << ")" << STD_endl;
    }
  }

  int nrow=1;
  if(nz>1) nrow++;

  int ncol=2;
  if(overlay_map) ncol++;

  grid=new GuiGridLayout( this, nrow, ncol);

  label = new floatLabel2D(data,lowbound,uppbound,nx,ny,disable_scale,coarseFactor,this,name,overlay_map,lowbound_map,uppbound_map,nx_map,ny_map,map_firescale,map_rectsize,colormap);
  grid->add_widget( label, 0, 0, GuiGridLayout::Default, 1, 2 );
  connect(label,SIGNAL(clicked(int,int)),this,SLOT(emitClicked(int,int)));
  connect(label,SIGNAL(newProfile(const float *, int, bool, int)),this,SLOT(emitNewProfile(const float *, int, bool, int)));
  connect(label,SIGNAL(newMask(const float *)),this,SLOT(emitNewMask(const float *)));

  maplegend=0;
  if(overlay_map) {
    maplegend = label->get_map_legend(this);
    if(maplegend) grid->add_widget( maplegend, 0, 2 );
  }


  zslider=0;
  zval=0;
  if(nz>1) {
    zslider=new GuiSlider(this, 0, nz-1, 1, 0, 1);
    connect(zslider->get_widget(), SIGNAL(valueChanged(int)), this, SLOT(changez(int)));
    grid->add_widget( zslider->get_widget(), 1, 0 );

    zval=new QLabel(this);
    grid->add_widget( zval, 1, 1 );

    // set size according to max num of digits
    zval->setMinimumWidth(_FONT_SIZE_*int(log10(nz-1)+1));
    zval->setNum(0);
  }


  mask3d=new float[nx*ny*nz];
  for(int i=0; i<nx*ny*nz; i++) mask3d[i]=0.0;

}

void floatBox3D::repaint_slice(int iz) const {
  label->refresh(data_cache+iz*oneimagesize,lowbound_cache,uppbound_cache);
  if(map_cache) label->refreshMap(map_cache+iz*onemapsize,lowbound_map_cache,uppbound_map_cache,rectsize_map_cache);
}



void floatBox3D::write_pixmap(const char* fname, const char* format, bool dump_all) const {
  if(dump_all) {

    LDRfileName dumpfname(fname);
    STD_string dumpprefix=dumpfname.get_dirname()+SEPARATOR_STR+dumpfname.get_basename_nosuffix();

    for(unsigned int iz=0; iz<nz_cache; iz++) {
      repaint_slice(iz);
      STD_string onefname(dumpprefix);
      if(nz_cache>1) onefname+=itos(iz,nz_cache-1);
      onefname+="."+::tolowerstr(format);
      label->write_pixmap( onefname.c_str(), format);
    }
    repaint_slice(get_current_z());
  } else {
    label->write_pixmap(fname,format);
  }
}

void floatBox3D::refresh(const float* data, float lowbound, float uppbound) {
  data_cache=data;
  label->refresh(data_cache+oneimagesize*get_current_z(),lowbound,uppbound);
  lowbound_cache=lowbound;
  uppbound_cache=uppbound;
}


void floatBox3D::changez(int iz) {
  Log<OdinQt> odinlog("floatBox3D","changez");
  repaint_slice(iz);
  repaint();
  if(zval) zval->setNum(iz);
}

int floatBox3D::get_current_z() const {
  if(zslider) return zslider->get_value();
  return 0;
}


floatBox3D::~floatBox3D() {
  if(zslider) delete zslider;
  if(zval) delete zval;
  if(maplegend) delete maplegend;
  delete label;
  delete grid;
  delete[] mask3d;
}