Changeset 181:0ceacf6ef6be


Ignore:
Timestamp:
03/29/2011 05:39:38 PM (7 years ago)
Author:
Dmitry Fedorov <fedorov@…>
Branch:
default
Phase:
public
Message:

new libbioimage and better gobjects tree

Location:
bioView3D
Files:
264 added
15 deleted
39 edited
1 moved

Legend:

Unmodified
Added
Removed
  • bioView3D/libsrc/ffmpeg/build-ffmpeg-cygwin_vc9_x64.sh

    r119 r181  
    11#!/bin/bash
    22
    3 # this script handles compiling ot the repository from: 2008-10-19
     3chmod a+x ./ffmpeg/configure
     4chmod a+x ./ffmpeg/version.sh
     5chmod a+x ./ffmpeg/doc/texi2pod.pl
    46
    5 #mkdir -p ffmpeg-obj
     7rm -Rf ./ffmpeg-obj
     8rm -Rf ./ffmpeg-out
     9
    610mkdir -p ffmpeg-out
    7 
    811#cd ffmpeg-obj
    912cd ffmpeg
  • bioView3D/libsrc/ffmpeg/build-ffmpeg-cygwin_vc9_x86.sh

    r119 r181  
    11#!/bin/bash
    22
    3 # this script handles compiling ot the repository from: 2008-10-19
     3chmod a+x ./ffmpeg/configure
     4chmod a+x ./ffmpeg/version.sh
     5chmod a+x ./ffmpeg/doc/texi2pod.pl
     6
     7rm -Rf ./ffmpeg-obj
     8rm -Rf ./ffmpeg-out
    49
    510mkdir -p ffmpeg-obj
    6 mkdir -p ffmpeg-out
    7 
    811cd ffmpeg-obj
    912../ffmpeg/configure \
     
    2831cp $(find . -name '*.def') ../ffmpeg-out
    2932cd ../ffmpeg-out
    30 rm avutil*.dll
    31 rm avformat*.dll
    32 rm avcodec*.dll
    33 rm swscale*.dll
     33rm -f avutil*.dll
     34rm -f avformat*.dll
     35rm -f avcodec*.dll
     36rm -f swscale*.dll
    3437mv bin/avutil-50.*.dll ./avutil-50.dll
    3538mv bin/avformat-52.*.dll ./avformat-52.dll
     
    3841
    3942
    40 cp $(find ./include/ffmpeg -name '*.h') ../include/ffmpeg
     43#cp $(find ./include/ffmpeg -name '*.h') ../include/ffmpeg
    4144
    4245echo "
  • bioView3D/libsrc/ffmpeg/build-ffmpeg-linux.sh

    r119 r181  
    55chmod a+x ./ffmpeg/doc/texi2pod.pl
    66
    7 chmod a+x ./ffmpeg/configure
     7rm -Rf ./ffmpeg-obj
     8rm -Rf ./ffmpeg-out
     9
    810mkdir -p ffmpeg-obj
    911cd ffmpeg-obj
     
    1416        --disable-ffserver --disable-ffplay --disable-network --disable-ffmpeg --disable-devices
    1517
    16 #--enable-swscaler  may 9 2008 - does not take this option anymore
    17 
    1818make all install
    1919
    20 #rm -R ../include
    21 mkdir -p ../include
    22 mkdir -p ../include/ffmpeg
    23 cp -R ./include/ffmpeg ../include/ffmpeg
     20cd ..
    2421
    25 cd ..
     22mkdir -p ./include
     23cp -Rf ./ffmpeg-out/include/libavcodec ./include/
     24cp -Rf ./ffmpeg-out/include/libavformat ./include/
     25cp -Rf ./ffmpeg-out/include/libavutil ./include/
     26cp -Rf ./ffmpeg-out/include/libswscale ./include/
     27
    2628mkdir -p ../../libs
    2729mkdir -p ../../libs/linux
  • bioView3D/libsrc/ffmpeg/build-ffmpeg-macosx.sh

    r119 r181  
    55chmod a+x ./ffmpeg/doc/texi2pod.pl
    66
    7 rm -R ./ffmpeg-obj
    8 rm -R ./ffmpeg-out
    9 
    10 #powerpc  x86  x86_32  x86_64
    11 # -arch ppc -arch i386
     7rm -Rf ./ffmpeg-obj
     8rm -Rf ./ffmpeg-out
    129
    1310#####################################################
    1411# The default compile is now Intel
    1512#####################################################
     13
     14export MACOSX_DEPLOYMENT_TARGET=10.4
    1615
    1716mkdir -p ffmpeg-obj
     
    2120  --prefix=$PWD/../ffmpeg-out \
    2221  --enable-gpl --enable-swscale \
    23   --disable-ffserver --disable-ffplay --disable-network --disable-ffmpeg --disable-devices #\
    24   #--arch=x86 --enable-cross-compile \
    25   #--extra-cflags="-arch i386" \
    26   #--extra-libs="-headerpad_max_install_names -arch i386"
    27 
    28 #--arch=x86 --cpu=i686 --enable-cross-compile \
    29 #--enable-cross-compile
     22  --disable-ffserver --disable-ffplay --disable-network --disable-ffmpeg --disable-devices
    3023
    3124make all install
    3225
    33 #rm -R ../include
    34 mkdir ../include
    35 mkdir ../include/ffmpeg
    36 cp -R ./include/ffmpeg ../include/ffmpeg
     26cd ..
    3727
    38 cd ..
    39 mkdir ../../libs
    40 mkdir ../../libs/macosx
     28mkdir -p ./include
     29cp -Rf ./ffmpeg-out/include/libavcodec ./include/
     30cp -Rf ./ffmpeg-out/include/libavformat ./include/
     31cp -Rf ./ffmpeg-out/include/libavutil ./include/
     32cp -Rf ./ffmpeg-out/include/libswscale ./include/
    4133
    42 rm ../../libs/macosx/libavcodec.a
    43 rm ../../libs/macosx/libavformat.a
    44 rm ../../libs/macosx/libavutil.a
    45 rm ../../libs/macosx/libswscale.a
     34mkdir -p ../../libs
     35mkdir -p ../../libs/macosx
     36
     37rm -f ../../libs/macosx/libavcodec.a
     38rm -f ../../libs/macosx/libavformat.a
     39rm -f ../../libs/macosx/libavutil.a
     40rm -f ../../libs/macosx/libswscale.a
    4641
    4742cp ./ffmpeg-out/lib/libavcodec.a ../../libs/macosx/libavcodec.a
  • bioView3D/libsrc/ffmpeg/build-ffmpeg-macosx_uni.sh

    r119 r181  
    55chmod a+x ./ffmpeg/doc/texi2pod.pl
    66
     7rm -Rf ./ffmpeg-obj
     8rm -Rf ./ffmpeg-out
    79
     10#####################################################
    811#powerpc  x86  x86_32  x86_64
    912# -arch ppc -arch i386
     13#####################################################
    1014
    1115mkdir -p ffmpeg-obj
     
    2024  --extra-libs="-headerpad_max_install_names -arch ppc -arch i386"
    2125
    22 #--enable-swscaler  may 9 2008 - does not take this option anymore
    23 #--arch=generic --cross-compile \
    24 
    2526make all install
    2627
    27 #rm -R ../include
    28 mkdir ../include
    29 mkdir ../include/ffmpeg
    30 cp -R ./include/ffmpeg ../include/ffmpeg
     28cd ..
    3129
    32 cd ..
    33 mkdir ../../libs
    34 mkdir ../../libs/macosx
     30mkdir -p ./include
     31cp -Rf ./ffmpeg-out/include/libavcodec ./include/
     32cp -Rf ./ffmpeg-out/include/libavformat ./include/
     33cp -Rf ./ffmpeg-out/include/libavutil ./include/
     34cp -Rf ./ffmpeg-out/include/libswscale ./include/
    3535
    36 rm ../../libs/macosx/libavcodec.a
    37 rm ../../libs/macosx/libavformat.a
    38 rm ../../libs/macosx/libavutil.a
    39 rm ../../libs/macosx/libswscale.a
     36mkdir -p ../../libs
     37mkdir -p ../../libs/macosx
     38
     39rm -f ../../libs/macosx/libavcodec.a
     40rm -f ../../libs/macosx/libavformat.a
     41rm -f ../../libs/macosx/libavutil.a
     42rm -f ../../libs/macosx/libswscale.a
    4043
    4144cp ./ffmpeg-out/lib/libavcodec.a ../../libs/macosx/libavcodec.a
  • bioView3D/libsrc/libbioimg/core_lib/tag_map.cpp

    r154 r181  
    162162//******************************************************************************
    163163
    164 std::string DTagMap::readline( const std::string &str, int &pos ) const {
     164std::string DTagMap::readline( const std::string &str, int &pos ) {
    165165  std::string line;
    166166  std::string::const_iterator it = str.begin() + pos;
     
    180180  std::string dir;
    181181  int pos=0;
    182   std::string line = this->readline( ini, pos );
    183182  while (pos<ini.size()) {
    184    
     183    std::string line = DTagMap::readline( ini, pos );
     184    if (line.size()<=0) continue;
     185
    185186    // if directory
    186     if (line[0] == '[') {
     187    if (*line.begin()=='[' && line.size()>=1 && *(line.end()-1)==']') {
    187188      dir = line.substr( 1, line.size()-2);
    188189      if (stop_at_dir.size()>0 && dir == stop_at_dir) return;
    189     } else {
    190       // if tag-value pair
    191       size_t eq_pos = line.find(separator);
    192       if (eq_pos != std::string::npos ) {
    193         std::string key = line.substr( 0, eq_pos );
    194         if (dir!="")key = dir + "/" + line.substr( 0, eq_pos );
    195         std::string val = line.substr( eq_pos+1 );
    196         if ( *val.begin() == '"' && *(val.end()-1) == '"' ) val = val.substr( 1, val.size()-2);
    197         (*this)[prefix+key] = val;
    198       }// found '='
    199     } // if tag-value
    200 
    201     line = this->readline( ini, pos );
    202   }
     190      continue;
     191    }
     192
     193    // if tag-value pair
     194    size_t eq_pos = line.find(separator);
     195    if (eq_pos != std::string::npos ) { // found '='
     196      std::string key = line.substr( 0, eq_pos );
     197      if (dir!="") key = dir + "/" + line.substr( 0, eq_pos );
     198      std::string val = "";
     199      if (line.size()>eq_pos+1) val = line.substr( eq_pos+1 );
     200      if ( val.size()>0 && *val.begin() == '"' && *(val.end()-1) == '"' ) val = val.substr( 1, val.size()-2);
     201      (*this)[prefix+key] = val;
     202    }
     203
     204  } // while
     205}
     206
     207std::deque<std::string> DTagMap::iniGetBlock( const std::string &ini, const std::string &dir_name ) {
     208  std::deque<std::string> d;
     209  int pos=0;
     210  bool found=false;
     211  while (pos<ini.size()) {
     212    std::string line = DTagMap::readline( ini, pos );
     213    if (line.size()<=0) continue;
     214
     215    if (*line.begin()=='[' && line.size()>=1 && *(line.end()-1)==']') { // if directory
     216      found = (dir_name == line.substr( 1, line.size()-2));
     217      continue;
     218    }
     219   
     220    if (found) d.push_back(line);
     221  } // while
     222
     223  return d;
    203224}
    204225
  • bioView3D/libsrc/libbioimg/core_lib/tag_map.h

    r154 r181  
    1818#include <string>
    1919#include <map>
     20#include <deque>
    2021
    2122class DTagMap : public std::map<std::string, std::string>
     
    7374  // parse a string containing an INI formatted variables, using a prefix for a tag name: prefix+name
    7475  void parse_ini( const std::string &ini, const std::string &separator="=", const std::string &prefix="", const std::string &stop_at_dir="" );
     76  static std::deque<std::string> iniGetBlock( const std::string &ini, const std::string &dir_name );
    7577
    7678  std::string join( const std::string &line_sep, const std::string &tag_val_sep=": " ) const;
     
    8284
    8385private:
    84   std::string readline( const std::string &str, int &pos ) const;
     86  static std::string readline( const std::string &str, int &pos );
    8587};
    8688
  • bioView3D/libsrc/libbioimg/core_lib/xconf.h

    r95 r181  
    1717#include <map>
    1818
    19 #include <xstring.h>
     19#include "xstring.h"
    2020
    2121//--------------------------------------------------------------------------------------
     
    2727public:
    2828  XConf() {}
     29  XConf(int argc, char** argv) { readParams( argc, argv ); }
    2930  ~XConf() {}
    3031
  • bioView3D/libsrc/libbioimg/formats/jpeg/dim_jpeg_format.cpp

    r138 r181  
    9393void dimJpegSetWriteParameters  (TDimFormatHandle *fmtHndl) {
    9494  if (fmtHndl == NULL) return;
     95
     96  fmtHndl->order = 1; // use progressive encoding by default
     97  fmtHndl->quality = 95;
     98
    9599  if (!fmtHndl->options) return;
    96100  xstring str = fmtHndl->options;
     
    106110      fmtHndl->quality = options[i].toInt( 100 );
    107111      continue;
     112    } else
     113    if ( options[i]=="progressive" && options.size()-i>0 ) {
     114      i++;   
     115      if (options[i]=="no") fmtHndl->order = 0;
     116      else
     117        fmtHndl->order = 1;     
     118      continue;
    108119    }
     120   
    109121  } // while
    110122}
  • bioView3D/libsrc/libbioimg/formats/jpeg/dim_jpeg_format_io.cpp

    r172 r181  
    491491    if (quality > 100) quality = 100;   
    492492    jpeg_set_quality(&cinfo, quality, TRUE ); // limit to baseline-JPEG values );
     493
     494    if (fmtHndl->order == 1) jpeg_simple_progression(&cinfo);
    493495
    494496    jpeg_start_compress(&cinfo, TRUE);
  • bioView3D/libsrc/libbioimg/formats/meta_format_manager.cpp

    r154 r181  
    175175
    176176  char *meta_char = sessionGetTextMetaData();
    177   if (meta_char != NULL) {
     177  if (meta_char) {
    178178    meta_data_text = meta_char;
    179179    delete meta_char;
     
    230230  }
    231231
    232   for (int i=0; i<dim::min<int>(display_lut.size(), display_channel_tag_names.size()); ++i)
     232  for (int i=0; i<(int)dim::min<size_t>(display_lut.size(), display_channel_tag_names.size()); ++i)
    233233    appendMetadata( display_channel_tag_names[i], display_lut[i] );
    234234
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_fluoview_format.h

    r95 r181  
    2626//----------------------------------------------------------------------------
    2727
    28 #define MMHEADER  34361
     28#define BIM_MMHEADER    34361
     29#define BIM_MMSTAMP     34362
     30#define BIM_ANDORBLOCK  34363 // ???
     31#define BIM_MMUSERBLOCK 34386
    2932
    3033#define IMAGE_NAME_LENGTH   256
     
    3639
    3740#pragma pack(push, 1)
    38 typedef struct MM_DIM_INFO
    39 {
     41typedef struct MM_DIM_INFO {
    4042  DIM_CHAR      Name[DIMNAME_LENGTH]; //Dimension name e.g. Width   16
    4143  DIM_UINT32    Size;                 //Image width etc              4
     
    4547} MM_DIM_INFO;                        // Total Size (bytes):       100 
    4648
    47 typedef struct MM_HEAD
    48 {
     49typedef struct MM_HEAD {
    4950  DIM_INT16     HeaderFlag;                 //Size of header structure             2
    5051  DIM_UCHAR     ImageType;                  //Image Type                           1
     
    9899#endif // DIM_FLUOVIEW_FORMAT_H
    99100
    100 
    101 
    102 
    103 
    104 
    105 
    106 
    107 
    108 
    109 
    110 
    111 
    112 
    113 
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_fluoview_format_io.cpp

    r154 r181  
    2424#include <bim_metatags.h>
    2525
     26#include <Eigen/Dense>
     27
    2628// Disables Visual Studio 2005 warnings for deprecated code
    2729#if ( defined(_MSC_VER) && (_MSC_VER >= 1400) )
     
    3739//----------------------------------------------------------------------------
    3840
     41/*
    3942bool fluoviewIsTiffValid(TIFF *tif) {
    4043  if (tif->tif_flags&TIFF_BIGTIFF) return false;       
     
    4245  int16   d_list_count;
    4346  int res[3] = {0,0,0};
    44 
    45   if (tif == 0) return FALSE;
    46 
    47   res[0] = TIFFGetField(tif, 34361, &d_list_count, &b_list);
    48   res[1] = TIFFGetField(tif, 34362, &d_list_count, &b_list);
    49   res[2] = TIFFGetField(tif, 34386, &d_list_count, &b_list);
    50 
    51   if (res[0] == 1) return TRUE;
    52   if (res[1] == 1) return TRUE;
    53   if (res[2] == 1) return TRUE;
    54 
    55   return FALSE;
    56 }
    57 
    58 
    59 bool fluoviewIsTiffValid(DTiffParams *tiffParams) {
    60   if (tiffParams == NULL) return FALSE;
     47  if (tif == 0) return false;
     48  res[0] = TIFFGetField(tif, BIM_MMHEADER, &d_list_count, &b_list);
     49  res[1] = TIFFGetField(tif, BIM_MMSTAMP, &d_list_count, &b_list);
     50  res[2] = TIFFGetField(tif, BIM_MMUSERBLOCK, &d_list_count, &b_list);
     51  if (res[0]==1 && res[1]==1 //&& res[2]==1
     52    ) return true;
     53  return false;
     54}
     55*/
     56
     57bool isValidTiffFluoview(DTiffParams *tiffParams) {
     58  if (!tiffParams) return false;
    6159  if (tiffParams->dimTiff->tif_flags&TIFF_BIGTIFF) return false;   
    62   // if tag 33629 exists then the file is valid STAK file
    63   if (isTagPresentInFirstIFD( &tiffParams->ifds, 34361 ) == TRUE) return TRUE;
    64   if (isTagPresentInFirstIFD( &tiffParams->ifds, 34362 ) == TRUE) return TRUE;
    65   if (isTagPresentInFirstIFD( &tiffParams->ifds, 34386 ) == TRUE) return TRUE;
    66 
    67   return FALSE;
    68 }
    69 
    70 void doSwabMMHEAD(MM_DIM_INFO *mmdi)
    71 {
     60  return (isTagPresentInFirstIFD(&tiffParams->ifds, BIM_MMHEADER) &&
     61          isTagPresentInFirstIFD(&tiffParams->ifds, BIM_MMSTAMP) &&
     62          isTagPresentInFirstIFD(&tiffParams->ifds, BIM_MMUSERBLOCK) );
     63}
     64
     65bool isValidTiffAndor(DTiffParams *tiffParams) {
     66  if (!tiffParams) return false;
     67  if (tiffParams->dimTiff->tif_flags&TIFF_BIGTIFF) return false;   
     68  return (isTagPresentInFirstIFD(&tiffParams->ifds, BIM_MMHEADER) &&
     69          isTagPresentInFirstIFD(&tiffParams->ifds, BIM_MMSTAMP) &&
     70          isTagPresentInFirstIFD(&tiffParams->ifds, BIM_ANDORBLOCK) );
     71}
     72
     73void doSwabMMHEAD(MM_DIM_INFO *mmdi) {
    7274  TIFFSwabLong   ((uint32*) &mmdi->Size);
    7375  TIFFSwabDouble ((double*) &mmdi->Origin);
     
    7577}
    7678
    77 void doSwabMMHEAD(MM_HEAD *mmh)
    78 {
     79void doSwabMMHEAD(MM_HEAD *mmh) {
    7980  TIFFSwabShort((uint16*) &mmh->HeaderFlag);
    8081  TIFFSwabLong ((uint32*) &mmh->Data);     
     
    102103}
    103104
    104 void printMM_DIM_INFO(MM_DIM_INFO *mmdi)
    105 {
     105void printMM_DIM_INFO(MM_DIM_INFO *mmdi) {
    106106  printf( "\nMM_DIM_INFO Name: %s\n", mmdi->Name);
    107107  printf( "MM_DIM_INFO size: %d\n", mmdi->Size);
     
    111111}
    112112
    113 void printMMHEADER(MM_HEAD *mmh)
    114 {
     113void printMMHEADER(MM_HEAD *mmh) {
    115114  printf( "\nMMHEAD HeaderFlag: %.4X\n", mmh->HeaderFlag);
    116115  printf( "\nMMHEAD ImageType: %.1X\n", mmh->ImageType);
     
    128127}
    129128
    130 int fluoviewGetInfo (DTiffParams *tiffParams)
    131 {
     129int fluoviewGetInfo (DTiffParams *tiffParams) {
    132130  if (tiffParams == NULL) return 1;
    133131  if (tiffParams->dimTiff == NULL) return 1;
     
    140138  MM_HEAD *fvInfo;
    141139
    142   if (!isTagPresentInFirstIFD( &tiffParams->ifds, MMHEADER )) return 1;
    143 
    144   readTiffTag (tiffParams->dimTiff, &tiffParams->ifds.ifds[0], MMHEADER, size, type, &buf);
    145   if ( (size <= 0) || (buf == NULL) ) return 1;
    146 
     140  if (!isTagPresentInFirstIFD( &tiffParams->ifds, BIM_MMHEADER )) return 1;
     141
     142  readTiffTag (tiffParams->dimTiff, &tiffParams->ifds.ifds[0], BIM_MMHEADER, size, type, &buf);
     143  if (!buf || size<sizeof(MM_HEAD)) return 1;
    147144  if (bigendian) doSwabMMHEAD((MM_HEAD *) buf);
    148145
     
    161158  // Fluoview order is: XYZTC -> we obtain XYCZT
    162159  //---------------------------------------------------------------
    163   int d;
    164   for (d=0; d<SPATIAL_DIMENSION; d++)
    165   {
     160  for (int d=0; d<SPATIAL_DIMENSION; d++) {
    166161    if ( strncmp(fvInfo->DimInfo[d].Name, "Ch", 2 ) == 0 )
    167162      fvi->ch = fvInfo->DimInfo[d].Size;
     
    170165      fvi->t_frames = fvInfo->DimInfo[d].Size;
    171166    else
    172     if ( strncmp(fvInfo->DimInfo[d].Name, "Z", 1 ) == 0 )
    173     {
     167    if ( strncmp(fvInfo->DimInfo[d].Name, "Z", 1 ) == 0 ) {
    174168      fvi->z_slices = fvInfo->DimInfo[d].Size;
    175169      fvi->zR = fvInfo->DimInfo[d].Resolution;
     
    205199  fvi->sample_names.resize( fvi->ch );
    206200  for (int i=0; i<fvi->ch; i++)
    207     fvi->sample_names[i] = "unknown";
    208 
    209   if (isTagPresentInIFD ( ifd, 270 ) == TRUE ) {
     201    fvi->sample_names[i] = xstring::xprintf( "Channel %d", i+1 );
     202
     203  if (isTagPresentInIFD(ifd, 270)) {
    210204    uint32 buf_size, buf_type;
    211205    DIM_UCHAR *buf = NULL;
     
    213207    change_0_to_n ((char *) buf, buf_size);
    214208
    215     xstring search_str;
    216     char *line;
    217     char str[1024];
    218 
    219209    // Extract channel names
    220210    for (int i=0; i<fvi->ch; i++) {
    221       search_str.sprintf( "Channel %d Dye=", i+1 );
    222       line = strstr( (char *) buf, search_str.c_str() );
     211      char *line = strstr( (char *) buf, xstring::xprintf( "Channel %d Dye=", i+1 ).c_str() );
    223212      if (line) {
    224         search_str.sprintf( "Channel %d Dye=%%s\n", i+1 );
    225         sscanf( line, search_str.c_str(), str );
     213        char str[1024];
     214        sscanf( line, xstring::xprintf( "Channel %d Dye=%%s\n", i+1 ).c_str(), str );
    226215        fvi->sample_names[i] = str;
    227216      }
     
    238227    for (unsigned int sample=0; sample<fvi->ch; ++sample) {
    239228      int r=-1,g=-1,b=-1;
    240       line = strstr( (char*)buf, xstring::xprintf("[LUT Ch%d]", sample).c_str() );
     229      char *line = strstr( (char*)buf, xstring::xprintf("[LUT Ch%d]", sample).c_str() );
    241230      if (line) {
    242231        line = strstr( line, "RGB 255=" );   
     
    297286  }
    298287
    299 
    300288  return 0;
    301289}
    302290
    303291// in fluoview luts are saved as INI text in tag: 270 - Image Description
    304 void fluoviewInitPalette( DTiffParams *tiffParams, TDimImageInfo *info )
    305 {
     292void fluoviewInitPalette( DTiffParams *tiffParams, TDimImageInfo *info ) {
    306293  uint32 buf_size;
    307294  uint32 buf_type; 
     
    310297  TDimTiffIFD *ifd = &tiffParams->ifds.ifds[0];
    311298
    312   if (tif == NULL) return;
    313   if (info == NULL) return;
    314 
    315   if (tiffParams->subType != tstFluoview) return;
     299  if (!tif) return;
     300  if (!info) return;
     301  if (tiffParams->subType!=tstFluoview) return;
    316302  if (tiffParams->fluoviewInfo.ch > 1) return;
    317   if (isTagPresentInIFD ( ifd, 270 ) != TRUE ) return;
     303  if (!isTagPresentInIFD(ifd, 270)) return;
    318304
    319305  readTiffTag (tif, ifd, 270, buf_size, buf_type, &buf);
    320306  change_0_to_n ((char *) buf, buf_size);
    321307
    322 
    323   int i=0;
    324   char *line, str[100];
    325   int r,g,b;
    326 
    327308  info->lut.count = 0;
    328   for (i=0; i<256; i++) info->lut.rgba[i] = i*256;
    329 
    330   line = strstr( (char *) buf, "[LUT Ch0]" );
    331 
    332   if (line != NULL)
    333   for (i=0; i<256; i++) {
    334     sprintf(str, "RGB %d=", i);
    335     line = strstr( line, str );   
    336    
    337     sprintf(str, "RGB %d=%%d\t%%d\t%%d\n", i);
    338     sscanf( line, str, &r, &g, &b );
    339 
     309  for (int i=0; i<256; i++) info->lut.rgba[i] = i*256;
     310
     311  char *line = strstr( (char *) buf, "[LUT Ch0]" );
     312  if (line)
     313  for (int i=0; i<256; i++) {
     314    line = strstr( line, xstring::xprintf("RGB %d=", i).c_str() );   
     315    int r,g,b;
     316    sscanf( line, xstring::xprintf("RGB %d=%%d\t%%d\t%%d\n", i).c_str(), &r, &g, &b );
    340317    info->lut.rgba[i] = dimRGB( r, g, b );
    341318  }
     
    350327  TDimImageInfo *info = &tiffParams->info;
    351328
    352   if ( tiffParams->subType == tstFluoview ) {
     329  if ( tiffParams->subType==tstFluoview || tiffParams->subType==tstAndor) {
    353330    fluoviewInitPalette( tiffParams, info);
    354331    DFluoviewInfo *fvi = &tiffParams->fluoviewInfo;   
     
    363340//----------------------------------------------------------------------------
    364341
    365 DIM_UINT fluoviewReadPlane( TDimFormatHandle *fmtHndl, DTiffParams *tiffParams, int plane )
    366 {
     342DIM_UINT fluoviewReadPlane( TDimFormatHandle *fmtHndl, DTiffParams *tiffParams, int plane ) {
    367343  if (tiffParams == 0) return 1;
    368344  if (tiffParams->dimTiff == 0) return 1;
    369   if (tiffParams->subType != tstFluoview) return 1; 
    370 
    371   uint16 bitspersample = 1;
    372  
     345  if (!(tiffParams->subType==tstFluoview || tiffParams->subType==tstAndor)) return 1; 
     346
    373347  TIFF *tif = tiffParams->dimTiff; 
    374348  DFluoviewInfo *fvi = &tiffParams->fluoviewInfo; 
    375349  TDimImageInfo *ii = &tiffParams->info;
    376 
    377   if (tif == NULL) return 1;
     350  if (!tif) return 1;
     351
     352  uint16 bitspersample = 1;
    378353  TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample);
    379354
    380355  ii->samples = fvi->ch;
    381356  //ii->imageMode = DIM_GRAYSCALE;   
    382  
    383357  ii->depth = bitspersample;
    384   if (bitspersample == 16) ii->pixelType = D_FMT_UNSIGNED;
    385 
    386   unsigned int sample;
     358
    387359  TDimImageBitmap *img = fmtHndl->image;
    388360  if ( allocImg( fmtHndl, ii, img) != 0 ) return 1;
     361  DIM_UINT lineSize = getLineSizeInBytes( img );
    389362
    390363  //--------------------------------------------------------------------
    391364  // read data
    392365  //--------------------------------------------------------------------
    393   DIM_UINT lineSize = getLineSizeInBytes( img );
    394 
    395   for (sample=0; sample<(unsigned int)fvi->ch; ++sample) {
     366  for (unsigned int sample=0; sample<(unsigned int)fvi->ch; ++sample) {
    396367    // switch to correct page in original TIFF
    397368    int dirNum = fmtHndl->pageNumber + sample * ( fvi->pages_tiff / fvi->ch );
    398369    TIFFSetDirectory( tif, dirNum );
    399 
    400370    if( TIFFIsTiled(tif) ) continue;
     371
    401372    DIM_UCHAR *p = (DIM_UCHAR *) img->bits[ sample ];
    402     register DIM_UINT y = 0;
    403 
    404     for(y=0; y<img->i.height; y++) {
     373    for(unsigned int y=0; y<img->i.height; y++) {
    405374      dimProgress( fmtHndl, y*(sample+1), img->i.height*fvi->ch, "Reading FLUOVIEW" );
    406375      if ( dimTestAbort( fmtHndl ) == 1) break; 
    407 
    408376      TIFFReadScanline(tif, p, y, 0);
    409377      p += lineSize;
     
    418386// Metadata hash
    419387//----------------------------------------------------------------------------
     388
     389void parse_metadata_fluoview (TDimFormatHandle *fmtHndl, DTagMap *hash ) {
     390  DTiffParams *tiffParams = (DTiffParams *) fmtHndl->internalParams;
     391  TDimImageInfo *info = &tiffParams->info;
     392  DFluoviewInfo *fvi = &tiffParams->fluoviewInfo;
     393  MM_HEAD *fvInfo = &fvi->head;
     394
     395  //----------------------------------------------------------------------------
     396  // Additional info from Tag 270
     397  //----------------------------------------------------------------------------
     398  TDimTiffIFD *ifd = &tiffParams->ifds.ifds[0];
     399  TIFF *tif = tiffParams->dimTiff;
     400  xstring tag_270 = read_tag_as_string(tif, ifd, 270);
     401
     402  //----------------------------------------------------------------------------
     403  // Add all other tags as Custom tags
     404  //----------------------------------------------------------------------------
     405  DTagMap fluo_hash;
     406  fluo_hash.parse_ini( tag_270, "=" );
     407  fluo_hash.eraseKeysStaringWith("LUT Ch");
     408  hash->append_tags( fluo_hash, bim::CUSTOM_TAGS_PREFIX );
     409
     410
     411  //----------------------------------------------------------------------------
     412  // Parsing some additional specific tags
     413  //----------------------------------------------------------------------------
     414  std::map< std::string, std::string >::const_iterator it;
     415
     416  // objective
     417  it = hash->find("custom/Acquisition Parameters/Objective Lens");
     418  if (it != hash->end() )
     419    hash->append_tag( bim::OBJECTIVE_DESCRIPTION, it->second );
     420
     421  // magnification
     422  it = hash->find("custom/Acquisition Parameters/Magnification");
     423  if (it != hash->end() )
     424    hash->append_tag( bim::OBJECTIVE_MAGNIFICATION, it->second );
     425
     426
     427  //---------------------------------------
     428  //Date=02-17-2004
     429  //Time=11:54:50
     430  xstring line;
     431
     432  it = hash->find("custom/Acquisition Parameters/Date");
     433  if (it != hash->end() ) line = it->second;
     434  std::vector<xstring> date = line.split( "-" );
     435
     436  it = hash->find("custom/Acquisition Parameters/Time");
     437  if (it != hash->end() ) line = it->second;
     438  std::vector<xstring> time = line.split( ":" );
     439
     440  if (date.size()>2 && time.size()>2) {
     441    xstring imaging_time;
     442    imaging_time.sprintf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
     443       date[2].toInt(), date[0].toInt(), date[1].toInt(),
     444       time[0].toInt(), time[1].toInt(), time[2].toInt() );
     445    hash->append_tag( bim::IMAGE_DATE_TIME, imaging_time );
     446  }
     447}
     448
     449void parse_metadata_andor (TDimFormatHandle *fmtHndl, DTagMap *hash ) {
     450  DTiffParams *tiffParams = (DTiffParams *) fmtHndl->internalParams;
     451  TDimImageInfo *info = &tiffParams->info;
     452  DFluoviewInfo *fvi = &tiffParams->fluoviewInfo;
     453  MM_HEAD *fvInfo = &fvi->head;
     454
     455  //----------------------------------------------------------------------------
     456  // Additional info from Tag 270
     457  //----------------------------------------------------------------------------
     458  TDimTiffIFD *ifd = &tiffParams->ifds.ifds[0];
     459  TIFF *tif = tiffParams->dimTiff;
     460  xstring tag_270 = read_tag_as_string(tif, ifd, 270);
     461
     462  //----------------------------------------------------------------------------
     463  // Add all other tags as Custom tags
     464  //----------------------------------------------------------------------------
     465  DTagMap andor_hash;
     466
     467  // first parse all INI standard tags
     468  andor_hash.parse_ini( tag_270, "=" );
     469 
     470  // now parse out of standard Andor blocks
     471  std::deque<std::string> ProtocolDescription = DTagMap::iniGetBlock( tag_270, "Protocol Description" );
     472  // simply add lines, needed parsing
     473  if (ProtocolDescription.size()>0) {
     474    std::string pp;
     475    std::deque<std::string>::const_iterator itt = ProtocolDescription.begin(); 
     476    while (itt != ProtocolDescription.end()) {
     477      pp += *itt;
     478      pp += "\n";
     479      ++itt;
     480    }
     481    andor_hash["Protocol Description"] = pp;
     482  }
     483
     484  std::deque<std::string> RegionInfo = DTagMap::iniGetBlock( tag_270, "Region Info (Fields)" );
     485  // simply add lines, needed parsing
     486  if (RegionInfo.size()>0) {
     487    std::string pp;
     488    std::deque<std::string>::const_iterator itt = RegionInfo.begin(); 
     489    while (itt != RegionInfo.end()) {
     490      pp += *itt;
     491      pp += "\n";
     492      ++itt;
     493    }
     494    andor_hash["Region Info (Fields)"] = pp;
     495  } 
     496
     497
     498 
     499  hash->append_tags( andor_hash, bim::CUSTOM_TAGS_PREFIX );
     500
     501  //----------------------------------------------------------------------------
     502  // Parsing some additional specific tags
     503  //----------------------------------------------------------------------------
     504  std::map< std::string, std::string >::const_iterator it;
     505
     506/*
     507  // objective
     508  it = hash->find("custom/Acquisition Parameters/Objective Lens");
     509  if (it != hash->end() )
     510    hash->append_tag( bim::OBJECTIVE_DESCRIPTION, it->second );
     511
     512  // magnification
     513  it = hash->find("custom/Acquisition Parameters/Magnification");
     514  if (it != hash->end() )
     515    hash->append_tag( bim::OBJECTIVE_MAGNIFICATION, it->second );
     516*/
     517
     518  //---------------------------------------
     519  //Date=06/08/2010
     520  //Time=10:10:36 AM
     521  xstring line;
     522
     523  it = andor_hash.find("Created/Date");
     524  if (it != andor_hash.end() ) line = it->second;
     525  std::vector<xstring> date = line.split( "/" );
     526
     527  it = andor_hash.find("Created/Time");
     528  if (it != andor_hash.end() ) line = it->second;
     529  std::vector<xstring> time_ampm = line.split( " " );
     530  std::vector<xstring> time = time_ampm[0].split( ":" );
     531  int time_add=0;
     532  if (time_ampm.size()>=1 && time_ampm[1]=="PM") time_add=12;
     533
     534  if (date.size()>2 && time.size()>2) {
     535    xstring imaging_time;
     536    imaging_time.sprintf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
     537       date[2].toInt(), date[0].toInt(), date[1].toInt(),
     538       time[0].toInt()+time_add, time[1].toInt(), time[2].toInt() );
     539    hash->append_tag( bim::IMAGE_DATE_TIME, imaging_time );
     540  }
     541
     542  //----------------------------------------------------------------------------
     543  // Parsing stage
     544  //----------------------------------------------------------------------------
     545
     546  //parse XYFields
     547  std::deque< Eigen::Vector3d > xyFields;
     548  std::vector<xstring> XYFields = xstring(andor_hash["XYZScan/XYFields"]).split( "\t" );
     549  if ( XYFields.size()>0 && XYFields[0].toInt()<XYFields.size() ) {
     550    for (int i=1; i<XYFields.size(); ++i) {
     551      std::vector<xstring> XYZ = XYFields[i].split(",");
     552      if (XYZ.size()<3) continue;
     553      xyFields.push_back( Eigen::Vector3d(XYZ[0].toDouble(), XYZ[1].toDouble(), XYZ[2].toDouble()) );
     554    }
     555  }
     556
     557  //parse MontageOffsets
     558  std::deque< Eigen::Vector3d > montageOffsets;
     559  std::vector<xstring> MontageOffsets = xstring(andor_hash["XYZScan/MontageOffsets"]).split( "\t" );
     560  if ( MontageOffsets.size()>0 && MontageOffsets[0].toInt()<MontageOffsets.size() ) {
     561    for (int i=1; i<MontageOffsets.size(); ++i) {
     562      std::vector<xstring> XYZ = MontageOffsets[i].split(",");
     563      if (XYZ.size()<3) continue;
     564      montageOffsets.push_back( Eigen::Vector3d(XYZ[0].toDouble(), XYZ[1].toDouble(), XYZ[2].toDouble()) );
     565    }
     566  }
     567
     568  // write stage coordinates
     569  int p=0;
     570  for (int i=0; i<xyFields.size(); ++i)
     571    for (int j=0; j<montageOffsets.size(); ++j) {
     572      Eigen::Vector3d v = xyFields[i] + montageOffsets[j];
     573      hash->append_tag( xstring::xprintf( bim::STAGE_POSITION_TEMPLATE_X.c_str(), p ), v[0] );
     574      hash->append_tag( xstring::xprintf( bim::STAGE_POSITION_TEMPLATE_Y.c_str(), p ), v[1] );
     575      hash->append_tag( xstring::xprintf( bim::STAGE_POSITION_TEMPLATE_Z.c_str(), p ), v[2] );
     576      ++p;
     577    }
     578
     579}
    420580
    421581DIM_UINT append_metadata_fluoview (TDimFormatHandle *fmtHndl, DTagMap *hash ) {
     
    484644
    485645  //----------------------------------------------------------------------------
    486   // Additional info from Tag 270
    487   //----------------------------------------------------------------------------
    488 
    489   TDimTiffIFD *ifd = &tiffParams->ifds.ifds[0];
    490   TIFF *tif = tiffParams->dimTiff;
    491   xstring tag_270 = read_tag_as_string(tif, ifd, 270);
    492 
    493 
    494   //----------------------------------------------------------------------------
    495   // Add all other tags as Custom tags
    496   //----------------------------------------------------------------------------
    497   DTagMap fluo_hash;
    498   fluo_hash.parse_ini( tag_270, "=" );
    499   fluo_hash.eraseKeysStaringWith("LUT Ch");
    500   hash->append_tags( fluo_hash, bim::CUSTOM_TAGS_PREFIX );
    501 
    502 
    503   //----------------------------------------------------------------------------
    504   // Parsing some additional specific tags
    505   //----------------------------------------------------------------------------
    506   std::map< std::string, std::string >::const_iterator it;
    507 
    508   // objective
    509   it = hash->find("custom/Acquisition Parameters/Objective Lens");
    510   if (it != hash->end() )
    511     hash->append_tag( bim::OBJECTIVE_DESCRIPTION, it->second );
    512 
    513   // magnification
    514   it = hash->find("custom/Acquisition Parameters/Magnification");
    515   if (it != hash->end() )
    516     hash->append_tag( bim::OBJECTIVE_MAGNIFICATION, it->second );
    517 
    518 
    519   //---------------------------------------
    520   //Date=02-17-2004
    521   //Time=11:54:50
    522   xstring line;
    523 
    524   it = hash->find("custom/Acquisition Parameters/Date");
    525   if (it != hash->end() ) line = it->second;
    526   std::vector<xstring> date = line.split( "-" );
    527 
    528   it = hash->find("custom/Acquisition Parameters/Time");
    529   if (it != hash->end() ) line = it->second;
    530   std::vector<xstring> time = line.split( ":" );
    531 
    532   if (date.size()>2 && time.size()>2) {
    533     xstring imaging_time;
    534     imaging_time.sprintf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
    535        date[2].toInt(), date[0].toInt(), date[1].toInt(),
    536        time[0].toInt(), time[1].toInt(), time[2].toInt() );
    537     hash->append_tag( bim::IMAGE_DATE_TIME, imaging_time );
    538   }
     646  // Additional info
     647  //----------------------------------------------------------------------------
     648
     649  if (tiffParams->subType==tstFluoview) parse_metadata_fluoview( fmtHndl, hash );
     650  else
     651  if (tiffParams->subType==tstAndor) parse_metadata_andor( fmtHndl, hash );
    539652
    540653  return 0;
    541654}
    542655
    543 
    544 
    545 
    546 
    547 
    548 
    549 
    550 
    551 
    552 
    553 
    554 
    555 
    556 
    557 
    558 
    559 
    560 
    561 
    562 
    563 
    564 
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_tiff_format.cpp

    r154 r181  
    307307  tiffReadResolution( tif, info->resUnits, info->xRes, info->yRes);
    308308
    309   if (tiffParams->subType!=tstFluoview && tiffParams->subType!=tstPsia)
     309  if (tiffParams->subType!=tstFluoview && tiffParams->subType!=tstPsia && tiffParams->subType!=tstAndor)
    310310    init_image_palette( tif, info );
    311311
    312312
    313   if ( tiffParams->subType == tstFluoview )
     313  if ( tiffParams->subType == tstFluoview || tiffParams->subType == tstAndor )
    314314    fluoviewGetCurrentPageInfo(tiffParams);
    315315  else
     
    345345    psiaGetInfo ( tiffParams );
    346346  } else
    347   if (fluoviewIsTiffValid( tiffParams )) {
     347  if (isValidTiffFluoview(tiffParams)) {
    348348    tiffParams->subType = tstFluoview;
     349    fluoviewGetInfo ( tiffParams );
     350  } else
     351  if (isValidTiffAndor(tiffParams)) {
     352    tiffParams->subType = tstAndor;
    349353    fluoviewGetInfo ( tiffParams );
    350354  } else
     
    631635//****************************************************************************
    632636
    633 #define D_TIFF_NUM_FORMATS 8
     637#define D_TIFF_NUM_FORMATS 9
    634638
    635639TDimFormatItem dimTiffItems[D_TIFF_NUM_FORMATS] = {
     
    648652  {
    649653    "STK",            // short name, no spaces
    650     "Metamorph Stack File Format", // Long format name
     654    "Metamorph Stack", // Long format name
    651655    "stk",        // pipe "|" separated supported extension list
    652656    1, //canRead;      // 0 - NO, 1 - YES
     
    660664  {
    661665    "PSIA",            // short name, no spaces
    662     "AFM PSIA TIFF File Format", // Long format name
     666    "AFM PSIA TIFF", // Long format name
    663667    "tif|tiff",        // pipe "|" separated supported extension list
    664668    1, //canRead;      // 0 - NO, 1 - YES
     
    672676  {
    673677    "FLUOVIEW",            // short name, no spaces
    674     "Fluoview TIFF File Format", // Long format name
     678    "Fluoview TIFF", // Long format name
    675679    "tif|tiff",        // pipe "|" separated supported extension list
    676680    1, //canRead;      // 0 - NO, 1 - YES
     
    684688  {
    685689    "LSM",            // short name, no spaces
    686     "Carl Zeiss LSM5 File Format", // Long format name
     690    "Carl Zeiss LSM 5/7", // Long format name
    687691    "lsm",        // pipe "|" separated supported extension list
    688692    1, //canRead;      // 0 - NO, 1 - YES
     
    729733    //TDivFormatConstrains constrains ( w, h, pages, minsampl, maxsampl, minbitsampl, maxbitsampl, noLut )
    730734    { 0, 0, 0, 0, 0, 0, 0, 0 }
     735  },
     736  {
     737    "ANDOR",            // short name, no spaces
     738    "Andor TIFF", // Long format name
     739    "tif|tiff",        // pipe "|" separated supported extension list
     740    1, //canRead;      // 0 - NO, 1 - YES
     741    0, //canWrite;     // 0 - NO, 1 - YES
     742    1, //canReadMeta;  // 0 - NO, 1 - YES
     743    0, //canWriteMeta; // 0 - NO, 1 - YES
     744    0, //canWriteMultiPage;   // 0 - NO, 1 - YES
     745    //TDivFormatConstrains constrains ( w, h, pages, minsampl, maxsampl, minbitsampl, maxbitsampl, noLut )   
     746    { 0, 0, 0, 0, 0, 0, 0, 0 }
    731747  }
    732748};
     
    737753  "1.1.0",
    738754  "DIMIN TIFF CODEC",
    739   "Tagged Image File Format CODEC",
     755  "Tagged Image File Format variants",
    740756 
    741757  4,                      // 0 or more, specify number of bytes needed to identify the file
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_tiff_format.h

    r154 r181  
    8080
    8181typedef enum {
    82   tstGeneric  = 0,
    83   tstStk      = 1,
    84   tstPsia     = 2,
    85   tstFluoview = 3,
    86   tstCzLsm    = 4,
    87   tstOmeTiff  = 5,
    88   tstBigTiff  = 6,
    89   tstOmeBigTiff  = 7
     82  tstGeneric    = 0,
     83  tstStk        = 1,
     84  tstPsia       = 2,
     85  tstFluoview   = 3,
     86  tstCzLsm      = 4,
     87  tstOmeTiff    = 5,
     88  tstBigTiff    = 6,
     89  tstOmeBigTiff = 7,
     90  tstAndor      = 8
    9091} DIM_TiffSubType;
    9192
  • bioView3D/libsrc/libbioimg/formats/tiff/dim_tiff_format_io.cpp

    r154 r181  
    456456    append_metadata_psia(fmtHndl, hash);
    457457  else
    458   if (tifParams->subType == tstFluoview)
     458  if (tifParams->subType==tstFluoview || tifParams->subType==tstAndor)
    459459    append_metadata_fluoview(fmtHndl, hash);
    460460  else
     
    740740
    741741  // if image is Fluoview and contains 1..4 channels
    742   if ( (tifParams->subType == tstFluoview) && (tifParams->fluoviewInfo.ch > 1) )
     742  if ( (tifParams->subType==tstFluoview || tifParams->subType==tstAndor) && (tifParams->fluoviewInfo.ch > 1) )
    743743    return fluoviewReadPlane( fmtHndl, tifParams, fmtHndl->pageNumber );
    744744
  • bioView3D/libsrc/libbioimg/formats_api/bim_metatags.def

    r154 r181  
    8282DECLARE_STR( STAGE_DISTANCE_Z, "stage_distance_z" )
    8383
    84 DECLARE_STR( STAGE_POSITION_TEMPLATE_X, "stage_position_x/%d" )
    85 DECLARE_STR( STAGE_POSITION_TEMPLATE_Y, "stage_position_y/%d" )
    86 DECLARE_STR( STAGE_POSITION_TEMPLATE_Z, "stage_position_z/%d" )
     84DECLARE_STR( STAGE_POSITION_TEMPLATE_X, "stage_position/%d/x" )
     85DECLARE_STR( STAGE_POSITION_TEMPLATE_Y, "stage_position/%d/y" )
     86DECLARE_STR( STAGE_POSITION_TEMPLATE_Z, "stage_position/%d/z" )
    8787
    8888DECLARE_STR( CAMERA_SENSOR_X, "camera_sensor_x" )
  • bioView3D/libsrc/libbioimg/formats_api/dim_histogram.cpp

    r115 r181  
    1717#include "xtypes.h"
    1818
    19 #include "cmath"
    20 
     19#include <cmath>
     20#include <cstring>
    2121#include <limits>
    2222
     
    4040
    4141void DimHistogram::init( const unsigned int &bpp, const D_DataFormat &fmt ) {
    42   data_bpp = bpp;
    43   data_fmt = fmt;
    44 
    45   shift=0; scale=1;
    46   value_min=0; value_max=0;
     42  d.data_bpp = bpp;
     43  d.data_fmt = fmt;
     44
     45  d.shift=0; d.scale=1;
     46  d.value_min=0; d.value_max=0;
    4747  reversed_min_max = false;
    4848  hist.resize(0);
     
    5050  if (bpp==0) return;
    5151  else
    52   if ( bpp<=16 && (data_fmt==D_FMT_UNSIGNED || data_fmt==D_FMT_SIGNED) ) {
     52  if ( bpp<=16 && (d.data_fmt==D_FMT_UNSIGNED || d.data_fmt==D_FMT_SIGNED) ) {
    5353    hist.resize( (unsigned int) pow(2.0, fabs((double) bpp)), 0 );
    5454  } else
    55   if (bpp>16 || data_fmt==D_FMT_FLOAT) {
     55  if (bpp>16 || d.data_fmt==D_FMT_FLOAT) {
    5656    hist.resize( default_size );
    5757  }
     
    6060
    6161void DimHistogram::clear( ) {
    62   hist = std::vector<unsigned int>(hist.size(), 0);
     62  hist = std::vector<DimHistogram::StorageType>(hist.size(), 0);
    6363}
    6464
     
    7272template <typename T>
    7373void DimHistogram::init_stats() {
    74   value_min = std::numeric_limits<T>::min();
    75   value_max = std::numeric_limits<T>::max();
     74  d.value_min = std::numeric_limits<T>::min();
     75  d.value_max = std::numeric_limits<T>::max();
    7676  reversed_min_max = false;
    7777  recompute_shift_scale();
     
    7979
    8080void DimHistogram::initStats() {
    81   if (data_bpp==8  && data_fmt==D_FMT_UNSIGNED) init_stats<DIM_UINT8>();
    82   else
    83   if (data_bpp==16 && data_fmt==D_FMT_UNSIGNED) init_stats<DIM_UINT16>();
     81  if (d.data_bpp==8  && d.data_fmt==D_FMT_UNSIGNED) init_stats<DIM_UINT8>();
     82  else
     83  if (d.data_bpp==16 && d.data_fmt==D_FMT_UNSIGNED) init_stats<DIM_UINT16>();
    8484  else   
    85   if (data_bpp==32 && data_fmt==D_FMT_UNSIGNED) init_stats<DIM_UINT32>();
    86   else
    87   if (data_bpp==8  && data_fmt==D_FMT_SIGNED)   init_stats<DIM_INT8>();
    88   else
    89   if (data_bpp==16 && data_fmt==D_FMT_SIGNED)   init_stats<DIM_INT16>();
    90   else
    91   if (data_bpp==32 && data_fmt==D_FMT_SIGNED)   init_stats<DIM_INT32>();
    92   else
    93   if (data_bpp==32 && data_fmt==D_FMT_FLOAT)    init_stats<DIM_FLOAT32>();
    94   else
    95   if (data_bpp==64 && data_fmt==D_FMT_FLOAT)    init_stats<DIM_FLOAT64>();
    96   else
    97   if (data_bpp==80 && data_fmt==D_FMT_FLOAT)    init_stats<DIM_FLOAT80>();
     85  if (d.data_bpp==32 && d.data_fmt==D_FMT_UNSIGNED) init_stats<DIM_UINT32>();
     86  else
     87  if (d.data_bpp==8  && d.data_fmt==D_FMT_SIGNED)   init_stats<DIM_INT8>();
     88  else
     89  if (d.data_bpp==16 && d.data_fmt==D_FMT_SIGNED)   init_stats<DIM_INT16>();
     90  else
     91  if (d.data_bpp==32 && d.data_fmt==D_FMT_SIGNED)   init_stats<DIM_INT32>();
     92  else
     93  if (d.data_bpp==32 && d.data_fmt==D_FMT_FLOAT)    init_stats<DIM_FLOAT32>();
     94  else
     95  if (d.data_bpp==64 && d.data_fmt==D_FMT_FLOAT)    init_stats<DIM_FLOAT64>();
     96  else
     97  if (d.data_bpp==80 && d.data_fmt==D_FMT_FLOAT)    init_stats<DIM_FLOAT80>();
    9898}
    9999
    100100inline void DimHistogram::recompute_shift_scale() {
    101   shift = value_min;
    102   scale = ((double) bin_number()-1) / (value_max-value_min);
     101  d.shift = d.value_min;
     102  d.scale = ((double) bin_number()-1) / (d.value_max-d.value_min);
    103103}
    104104
     
    108108  if (num_data_points==0) return;
    109109  if (!reversed_min_max) {
    110     value_min = std::numeric_limits<T>::max();
    111     value_max = std::numeric_limits<T>::min();
     110    d.value_min = std::numeric_limits<T>::max();
     111    d.value_max = std::numeric_limits<T>::min();
    112112    reversed_min_max = true;
    113113  }
     
    116116  if (mask == 0) {
    117117    for (unsigned int i=0; i<num_data_points; ++i) {
    118       if (*p<value_min) value_min = *p;
    119       if (*p>value_max) value_max = *p;
     118      if (*p<d.value_min) d.value_min = *p;
     119      if (*p>d.value_max) d.value_max = *p;
    120120      ++p;
    121121    }
     
    123123    for (unsigned int i=0; i<num_data_points; ++i) {
    124124      if (mask[i]>128) {
    125         if (*p<value_min) value_min = *p;
    126         if (*p>value_max) value_max = *p;
     125        if (*p<d.value_min) d.value_min = *p;
     126        if (*p>d.value_max) d.value_max = *p;
    127127      }
    128128      ++p;
     
    136136void DimHistogram::get_data_stats( T *data, const unsigned int &num_data_points, unsigned char *mask ) {
    137137  init_stats<T>();
    138   value_min = std::numeric_limits<T>::max();
    139   value_max = std::numeric_limits<T>::min();
     138  d.value_min = std::numeric_limits<T>::max();
     139  d.value_max = std::numeric_limits<T>::min();
    140140  reversed_min_max = true;
    141141  update_data_stats(data, num_data_points, mask);
     
    143143
    144144void DimHistogram::getStats( void *data, const unsigned int &num_data_points, unsigned char *mask ) {
    145   if (data_fmt==D_FMT_UNSIGNED) {
    146     if (data_bpp == 32) get_data_stats<DIM_UINT32>( (DIM_UINT32*)data, num_data_points, mask );
     145  if (d.data_fmt==D_FMT_UNSIGNED) {
     146    if (d.data_bpp == 32) get_data_stats<DIM_UINT32>( (DIM_UINT32*)data, num_data_points, mask );
    147147  } else
    148   if (data_fmt==D_FMT_SIGNED) {
    149     if (data_bpp == 32) get_data_stats<DIM_INT32>( (DIM_INT32*)data, num_data_points, mask );
     148  if (d.data_fmt==D_FMT_SIGNED) {
     149    if (d.data_bpp == 32) get_data_stats<DIM_INT32>( (DIM_INT32*)data, num_data_points, mask );
    150150  } else
    151   if (data_fmt==D_FMT_FLOAT) {
    152     if (data_bpp == 32) get_data_stats<DIM_FLOAT32>( (DIM_FLOAT32*)data, num_data_points, mask );
    153     else
    154     if (data_bpp == 64) get_data_stats<DIM_FLOAT64>( (DIM_FLOAT64*)data, num_data_points, mask );
    155     else
    156     if (data_bpp == 80) get_data_stats<DIM_FLOAT80>( (DIM_FLOAT80*)data, num_data_points, mask );
     151  if (d.data_fmt==D_FMT_FLOAT) {
     152    if (d.data_bpp == 32) get_data_stats<DIM_FLOAT32>( (DIM_FLOAT32*)data, num_data_points, mask );
     153    else
     154    if (d.data_bpp == 64) get_data_stats<DIM_FLOAT64>( (DIM_FLOAT64*)data, num_data_points, mask );
     155    else
     156    if (d.data_bpp == 80) get_data_stats<DIM_FLOAT80>( (DIM_FLOAT80*)data, num_data_points, mask );
    157157  }
    158158}
     
    160160template <typename T>
    161161inline unsigned int DimHistogram::bin_from( const T &data_point ) const {
    162   return dim::trim<unsigned int, double>( (data_point - shift) * scale, 0, bin_number() );
     162  return dim::trim<unsigned int, double>( (data_point - d.shift) * d.scale, 0, bin_number() );
    163163}
    164164
     
    192192  if (mask==0) {
    193193    for (unsigned int i=0; i<num_data_points; ++i) {
    194       double v = (((double)*p) - shift) * scale;
     194      double v = (((double)*p) - d.shift) * d.scale;
    195195      unsigned int bin = dim::trim<unsigned int, double>( v, 0, bn-1 );
    196196      ++hist[bin];
     
    200200    for (unsigned int i=0; i<num_data_points; ++i) {
    201201      if (mask[i]>128) {
    202         double v = (((double)*p) - shift) * scale;
     202        double v = (((double)*p) - d.shift) * d.scale;
    203203        unsigned int bin = dim::trim<unsigned int, double>( v, 0, bn-1 );
    204204        ++hist[bin];
     
    210210
    211211void DimHistogram::updateStats( void *data, const unsigned int &num_data_points, unsigned char *mask ) {
    212   if (data_fmt==D_FMT_UNSIGNED) {
    213     if (data_bpp == 32) update_data_stats<DIM_UINT32>( (DIM_UINT32*)data, num_data_points, mask );
     212  if (d.data_fmt==D_FMT_UNSIGNED) {
     213    if (d.data_bpp == 32) update_data_stats<DIM_UINT32>( (DIM_UINT32*)data, num_data_points, mask );
    214214  } else
    215   if (data_fmt==D_FMT_SIGNED) {
    216     if (data_bpp == 32) update_data_stats<DIM_INT32>( (DIM_INT32*)data, num_data_points, mask );
     215  if (d.data_fmt==D_FMT_SIGNED) {
     216    if (d.data_bpp == 32) update_data_stats<DIM_INT32>( (DIM_INT32*)data, num_data_points, mask );
    217217  } else
    218   if (data_fmt==D_FMT_FLOAT) {
    219     if (data_bpp == 32) update_data_stats<DIM_FLOAT32>( (DIM_FLOAT32*)data, num_data_points, mask );
    220     else
    221     if (data_bpp == 64) update_data_stats<DIM_FLOAT64>( (DIM_FLOAT64*)data, num_data_points, mask );
    222     else
    223     if (data_bpp == 80) update_data_stats<DIM_FLOAT80>( (DIM_FLOAT80*)data, num_data_points, mask );
     218  if (d.data_fmt==D_FMT_FLOAT) {
     219    if (d.data_bpp == 32) update_data_stats<DIM_FLOAT32>( (DIM_FLOAT32*)data, num_data_points, mask );
     220    else
     221    if (d.data_bpp == 64) update_data_stats<DIM_FLOAT64>( (DIM_FLOAT64*)data, num_data_points, mask );
     222    else
     223    if (d.data_bpp == 80) update_data_stats<DIM_FLOAT80>( (DIM_FLOAT80*)data, num_data_points, mask );
    224224  }
    225225}
     
    227227void DimHistogram::addData( void *data, const unsigned int &num_data_points, unsigned char *mask ) {
    228228
    229   if (data_fmt==D_FMT_UNSIGNED) {
    230     if (data_bpp==8)    add_from_data<DIM_UINT8>( (DIM_UINT8*)data, num_data_points, mask );
    231     else
    232     if (data_bpp == 16) add_from_data<DIM_UINT16>( (DIM_UINT16*)data, num_data_points, mask );
    233     else
    234     if (data_bpp == 32) add_from_data_scale<DIM_UINT32>( (DIM_UINT32*)data, num_data_points, mask );
     229  if (d.data_fmt==D_FMT_UNSIGNED) {
     230    if (d.data_bpp==8)    add_from_data<DIM_UINT8>( (DIM_UINT8*)data, num_data_points, mask );
     231    else
     232    if (d.data_bpp == 16) add_from_data<DIM_UINT16>( (DIM_UINT16*)data, num_data_points, mask );
     233    else
     234    if (d.data_bpp == 32) add_from_data_scale<DIM_UINT32>( (DIM_UINT32*)data, num_data_points, mask );
    235235  } else
    236   if (data_fmt==D_FMT_SIGNED) {
    237     if (data_bpp==8)    add_from_data_scale<DIM_INT8>( (DIM_INT8*)data, num_data_points, mask );
    238     else
    239     if (data_bpp == 16) add_from_data_scale<DIM_INT16>( (DIM_INT16*)data, num_data_points, mask );
    240     else
    241     if (data_bpp == 32) add_from_data_scale<DIM_INT32>( (DIM_INT32*)data, num_data_points, mask );
     236  if (d.data_fmt==D_FMT_SIGNED) {
     237    if (d.data_bpp==8)    add_from_data_scale<DIM_INT8>( (DIM_INT8*)data, num_data_points, mask );
     238    else
     239    if (d.data_bpp == 16) add_from_data_scale<DIM_INT16>( (DIM_INT16*)data, num_data_points, mask );
     240    else
     241    if (d.data_bpp == 32) add_from_data_scale<DIM_INT32>( (DIM_INT32*)data, num_data_points, mask );
    242242  } else
    243   if (data_fmt==D_FMT_FLOAT) {
    244     if (data_bpp == 32) add_from_data_scale<DIM_FLOAT32>( (DIM_FLOAT32*)data, num_data_points, mask );
    245     else
    246     if (data_bpp == 64) add_from_data_scale<DIM_FLOAT64>( (DIM_FLOAT64*)data, num_data_points, mask );
    247     else
    248     if (data_bpp == 80) add_from_data_scale<DIM_FLOAT80>( (DIM_FLOAT80*)data, num_data_points, mask );
     243  if (d.data_fmt==D_FMT_FLOAT) {
     244    if (d.data_bpp == 32) add_from_data_scale<DIM_FLOAT32>( (DIM_FLOAT32*)data, num_data_points, mask );
     245    else
     246    if (d.data_bpp == 64) add_from_data_scale<DIM_FLOAT64>( (DIM_FLOAT64*)data, num_data_points, mask );
     247    else
     248    if (d.data_bpp == 80) add_from_data_scale<DIM_FLOAT80>( (DIM_FLOAT80*)data, num_data_points, mask );
    249249  }
    250250}
     
    253253
    254254int DimHistogram::bin_of_last_nonzero() const {
    255   for (int i=hist.size()-1; i>=0; --i)
     255  for (int i=(int)hist.size()-1; i>=0; --i)
    256256    if (hist[i] != 0)
    257257      return i;
     
    268268int DimHistogram::bin_of_max_value() const {
    269269  int bin = 0;
    270   unsigned int val = hist[0];
     270  DimHistogram::StorageType val = hist[0];
    271271  for (unsigned int i=0; i<hist.size(); ++i)
    272272    if (hist[i] > val) {
     
    279279int DimHistogram::bin_of_min_value() const {
    280280  int bin = 0;
    281   unsigned int val = hist[0];
     281  DimHistogram::StorageType val = hist[0];
    282282  for (unsigned int i=0; i<hist.size(); ++i)
    283283    if (hist[i] < val) {
     
    289289
    290290double DimHistogram::max_value() const {
    291   if (data_fmt==D_FMT_UNSIGNED && data_bpp<=16)
     291  if (d.data_fmt==D_FMT_UNSIGNED && d.data_bpp<=16)
    292292    return bin_of_last_nonzero();
    293293  else
    294     return value_max;
     294    return d.value_max;
    295295}
    296296
    297297double DimHistogram::min_value() const {
    298   if (data_fmt==D_FMT_UNSIGNED && data_bpp<=16)
     298  if (d.data_fmt==D_FMT_UNSIGNED && d.data_bpp<=16)
    299299    return bin_of_first_nonzero();
    300300  else
    301     return value_min;
     301    return d.value_min;
    302302}
    303303
     
    317317    }
    318318  double mu = a/s;
    319   return (mu/scale) + shift;
     319  return (mu/d.scale) + d.shift;
    320320}
    321321
     
    329329    }
    330330  double sig_sq = sqrt( a/(s-1) );
    331   return (sig_sq/scale) + shift;
    332 }
    333 
    334 unsigned int DimHistogram::cumsum( const unsigned int &bin ) const {
     331  return (sig_sq/d.scale) + d.shift;
     332}
     333
     334DimHistogram::StorageType DimHistogram::cumsum( const unsigned int &bin ) const {
    335335  unsigned int b = bin;
    336   if ( b >= hist.size() ) b = hist.size()-1;
    337   unsigned int sum=0;
     336  if ( b >= hist.size() ) b = (unsigned int)hist.size()-1;
     337  DimHistogram::StorageType sum=0;
    338338  for (unsigned int i=0; i<=b; ++i)
    339339    sum += hist[i];
     
    341341}
    342342
    343 unsigned int DimHistogram::get_value( const unsigned int &bin ) const {
     343DimHistogram::StorageType DimHistogram::get_value( const unsigned int &bin ) const {
    344344  if ( bin < hist.size() )
    345345    return hist[bin];
     
    348348}
    349349
    350 void DimHistogram::set_value( const unsigned int &bin, const unsigned int &val ) {
     350void DimHistogram::set_value( const unsigned int &bin, const DimHistogram::StorageType &val ) {
    351351  if ( bin < hist.size() )
    352352    hist[bin] = val;
    353353}
    354354
    355 void DimHistogram::append_value( const unsigned int &bin, const unsigned int &val ) {
     355void DimHistogram::append_value( const unsigned int &bin, const DimHistogram::StorageType &val ) {
    356356  if ( bin < hist.size() )
    357357    hist[bin] += val;
    358358}
     359
     360//------------------------------------------------------------------------------
     361// I/O
     362//------------------------------------------------------------------------------
     363
     364/*
     365Histogram binary content:
     3660x00 'BIM1' - 4 bytes header
     3670x04 'HST1' - 4 bytes spec
     3680x07        - XX bytes HistogramInternal
     3690xXX NUM    - 1xUINT32 number of elements in histogram vector
     3700xXX        - histogram vector DimHistogram::StorageType * NUM
     371*/
     372
     373const char Histogram_mgk[4] = { 'B','I','M','1' };
     374const char Histogram_spc[4] = { 'H','S','T','1' };
     375
     376bool DimHistogram::to(const std::string &fileName) {
     377  std::ofstream f( fileName.c_str(), std::ios_base::binary );
     378  return this->to(&f);
     379}
     380
     381bool DimHistogram::to(std::ostream *s) {
     382  // write header
     383  s->write( Histogram_mgk, sizeof(Histogram_mgk) );
     384  s->write( Histogram_spc, sizeof(Histogram_spc) );
     385  s->write( (const char *) &d, sizeof(bim::HistogramInternal) );
     386
     387  // write data
     388  DIM_UINT32 sz = this->hist.size();
     389  s->write( (const char *) &sz, sizeof(DIM_UINT32) );
     390  s->write( (const char *) &this->hist[0], sizeof(DimHistogram::StorageType)*this->hist.size() );
     391  return true;
     392}
     393
     394bool DimHistogram::from(const std::string &fileName) {
     395  std::ifstream f( fileName.c_str(), std::ios_base::binary  );
     396  return this->from(&f);
     397}
     398
     399bool DimHistogram::from(std::istream *s) {
     400  // read header
     401  char hts_hdr[sizeof(Histogram_mgk)];
     402  char hts_spc[sizeof(Histogram_spc)];
     403
     404  s->read( hts_hdr, sizeof(Histogram_mgk) );
     405  if (memcmp( hts_hdr, Histogram_mgk, sizeof(Histogram_mgk) )!=0) return false;
     406
     407  s->read( hts_spc, sizeof(Histogram_spc) );
     408  if (memcmp( hts_spc, Histogram_spc, sizeof(Histogram_spc) )!=0) return false;
     409
     410  s->read( (char *) &d, sizeof(bim::HistogramInternal) );
     411
     412  // read data
     413  DIM_UINT32 sz;
     414  s->read( (char *) &sz, sizeof(DIM_UINT32) );
     415  this->hist.resize(sz);
     416 
     417  s->read( (char *) &this->hist[0], sizeof(DimHistogram::StorageType)*this->hist.size() );
     418  return true;
     419}
     420
     421
    359422
    360423//******************************************************************************
     
    439502void DimLut::apply_lut_scale_from( const Ti *ibuf, To *obuf, const unsigned int &num_data_points ) const {
    440503  if (!ibuf || !obuf) return;
    441   double scale = h_in.scale;
    442   double shift = h_in.shift;
    443   double range = lut.size();
     504  double scale = h_in.d.scale;
     505  double shift = h_in.d.shift;
     506  double range = (double)lut.size();
    444507
    445508  for (unsigned int i=0; i<num_data_points; ++i)
     
    526589  out.clear();
    527590  for (unsigned int i=0; i<in.size(); ++i)
    528     out.append_value( lut[i], in[i] );
     591    out.append_value( (unsigned int) lut[i], in[i] );
    529592}
    530593
     
    609672  // equalize
    610673  std::vector<double> map(lut.size(), 0);
    611   map[0] = in[0];
     674  map[0] = (double) in[0];
    612675  for (unsigned int x=1; x<lut.size(); ++x)
    613676    map[x] = map[x-1] + in[x];
  • bioView3D/libsrc/libbioimg/formats_api/dim_histogram.h

    r135 r181  
    1818
    1919#include <vector>
     20#include <iostream>
     21#include <fstream>
    2022
    2123#include "dim_img_format_interface.h"
     
    2527//******************************************************************************
    2628
     29#define BIM_HISTOGRAM_VERSION 1
     30
     31namespace bim {
     32
     33#pragma pack(push, 1)
     34struct HistogramInternal {
     35  DIM_UINT16 data_bpp; // bits per pixel 
     36  DIM_UINT16 data_fmt; // signed, unsigned, float
     37  double shift;
     38  double scale;
     39  double value_min;
     40  double value_max;
     41};
     42#pragma pack(pop)
     43
     44} // namespace bim
     45
     46
    2747class DimLut;
    28 
    2948class DimHistogram {
    3049  public:
     50    typedef DIM_UINT64 StorageType;
    3151    static const unsigned int defaultSize=256; // 256, 65536
    3252
     
    4767    void         setDefaultSize(const unsigned int &v) { default_size=v; }
    4868
    49     unsigned int dataBpp()    const { return data_bpp; }
    50     D_DataFormat dataFormat() const { return data_fmt; }
     69    bool         isValid()    const { return d.data_bpp>0; }
     70    unsigned int dataBpp()    const { return d.data_bpp; }
     71    D_DataFormat dataFormat() const { return (D_DataFormat) d.data_fmt; }
    5172
    5273    int bin_of_max_value() const;
     
    6384
    6485    inline unsigned int bin_number() const { return size(); }
    65     inline unsigned int size() const { return hist.size(); }
    66     const std::vector<unsigned int> &get_hist( ) const { return hist; }
     86    inline unsigned int size() const { return (unsigned int) hist.size(); }
     87    const std::vector<StorageType> &get_hist( ) const { return hist; }
    6788
    6889    double average() const;
    6990    double std() const;
    70     unsigned int cumsum( const unsigned int &bin ) const;
    71 
    72     double get_shift() const { return shift; }
    73     double get_scale() const { return scale; }
    74 
    75     unsigned int get_value( const unsigned int &bin ) const;
    76     void set_value( const unsigned int &bin, const unsigned int &val );
    77     void append_value( const unsigned int &bin, const unsigned int &val );
    78 
    79     inline unsigned int operator[](unsigned int x) const { return hist[x]; }
     91    StorageType cumsum( const unsigned int &bin ) const;
     92
     93    double get_shift() const { return d.shift; }
     94    double get_scale() const { return d.scale; }
     95
     96    StorageType get_value( const unsigned int &bin ) const;
     97    void set_value( const unsigned int &bin, const StorageType &val );
     98    void append_value( const unsigned int &bin, const StorageType &val );
     99
     100    inline StorageType operator[](unsigned int x) const { return hist[x]; }
    80101
    81102    template <typename T>
    82103    inline unsigned int bin_from( const T &data_point ) const;
     104
     105  public:
     106    // I/O
     107    bool to(const std::string &fileName);
     108    bool to(std::ostream *s);
     109    bool from(const std::string &fileName);
     110    bool from(std::istream *s);
    83111   
    84112  protected:
    85     unsigned int data_bpp;
    86     D_DataFormat data_fmt; // signed, unsigned, float
    87113    int default_size;
    88     double shift, scale;
    89     double value_min, value_max;
    90114    bool reversed_min_max;
    91     std::vector<unsigned int> hist;
     115    bim::HistogramInternal d;
     116    std::vector<StorageType> hist;
    92117
    93118    template <typename T>
     
    110135    template <typename T>
    111136    void add_from_data_scale( T *data, const unsigned int &num_data_points, unsigned char *mask=0 );
     137
     138
    112139
    113140    friend class DimLut;
     
    143170    void clear( );
    144171
    145     unsigned int size() const { return lut.size(); }
     172    unsigned int size() const { return (unsigned int) lut.size(); }
    146173    const std::vector<StorageType> &get_lut( ) const { return lut; }
    147174
  • bioView3D/libsrc/libbioimg/formats_api/dim_image.cpp

    r138 r181  
    266266}
    267267
    268 TDimImage TDimImage::convertToDepth( int depth, DimLut::LutType method, D_DataFormat pxt ) const {
     268TDimImage TDimImage::convertToDepth( int depth, DimLut::LutType method, D_DataFormat pxt, DImageHistogram *hist ) const {
    269269  TDimImage img;
    270   if (bmp==NULL) return img;
     270  if (!bmp) return img;
    271271
    272272  // small optimization
     
    284284    if (pxt!=D_FMT_UNDEFINED) img.bmp->i.pixelType = pxt;
    285285   
    286     DImageHistogram ih(*this);
     286    DImageHistogram ih;
     287    if (!hist || !hist->isValid()) ih.fromImage(*this); else ih = *hist;
    287288    DImageHistogram oh( img.samples(), img.depth(), img.pixelType() );
    288289    DImageLut       lut(ih, oh, method);
    289290
     291    // TODO: we have to update the hist after the operation
     292
    290293    for (unsigned int sample=0; sample<bmp->i.samples; ++sample )
    291294      lut[sample]->apply( bmp->bits[sample], img.bits(sample), num_pix );
     
    296299}
    297300
    298 TDimImage TDimImage::normalize( int to_bpp ) const {
    299 
     301TDimImage TDimImage::normalize( int to_bpp, DImageHistogram *hist ) const {
    300302  if (bmp==NULL) return TDimImage();
    301   if (bmp->i.depth == to_bpp) return *this;
    302 
    303   return convertToDepth( to_bpp, DimLut::ltLinearDataRange, D_FMT_UNSIGNED );
     303  if (bmp->i.depth==to_bpp) return *this;
     304  return convertToDepth( to_bpp, DimLut::ltLinearDataRange, D_FMT_UNSIGNED, hist );
    304305}
    305306
     
    355356  if (fm.sessionStartRead( fileName ) == 0) {
    356357    fm.sessionReadImage( bmp, page );
    357 
     358   
    358359    // getting metadata fields
    359360    fm.sessionParseMetaData(0);
     
    363364
    364365  fm.sessionEnd();
     366
    365367  return res;
    366368}
     
    12151217
    12161218//------------------------------------------------------------------------------------
     1219// Channel fusion
     1220//------------------------------------------------------------------------------------
     1221
     1222template <typename T>
     1223void fuse_channels_weights ( TDimImage *img, int sample, const TDimImage &srci, const std::vector< std::pair<unsigned int,float> > &map ) {
     1224  double weight_sum=0;
     1225  for (std::vector< std::pair<unsigned int,float> >::const_iterator i=map.begin(); i!=map.end(); ++i)
     1226    weight_sum += i->second;
     1227  if (weight_sum==0) weight_sum=1;
     1228
     1229  for (unsigned int y=0; y<srci.height(); ++y) {
     1230    std::vector<double> line(srci.width(), 0);
     1231    T *dest = (T*) img->scanLine(sample, y);
     1232
     1233    for (std::vector< std::pair<unsigned int,float> >::const_iterator i=map.begin(); i!=map.end(); ++i) {
     1234      T *src = (T*) srci.scanLine(i->first, y);
     1235      for (unsigned int x=0; x<srci.width(); ++x)
     1236        line[x] += ((double)src[x])*i->second;
     1237    } // map
     1238
     1239    for (unsigned int x=0; x<srci.width(); ++x)
     1240      line[x] /= weight_sum;
     1241
     1242    for (unsigned int x=0; x<srci.width(); ++x)
     1243      dest[x] = (T) line[x];
     1244
     1245  } // y
     1246}
     1247
     1248TDimImage TDimImage::fuse( const std::vector< std::vector< std::pair<unsigned int,float> > > &map ) const {
     1249  TDimImage img;
     1250  if (bmp==NULL) return img;
     1251
     1252  int c = map.size();
     1253  if ( img.alloc( bmp->i.width, bmp->i.height, c, bmp->i.depth ) == 0 ) {
     1254    img.fill(0);
     1255    for (unsigned int sample=0; sample<img.samples(); ++sample ) {
     1256     
     1257      if ( map[sample].size()==1 ) // if no fusion is going on simply copy the data
     1258        memcpy( img.bits(sample), bmp->bits[map[sample].begin()->first], img.bytesPerChan() );
     1259      else // ok, here we fuse
     1260      if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_UNSIGNED)
     1261        fuse_channels_weights<DIM_UINT8> ( &img, sample, *this, map[sample] );
     1262      else
     1263      if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_UNSIGNED)
     1264        fuse_channels_weights<DIM_UINT16> ( &img, sample, *this, map[sample] );
     1265      else
     1266      if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_UNSIGNED)
     1267        fuse_channels_weights<DIM_UINT32> ( &img, sample, *this, map[sample] );
     1268      else
     1269      if (bmp->i.depth==8 && bmp->i.pixelType==D_FMT_SIGNED)
     1270        fuse_channels_weights<DIM_INT8> ( &img, sample, *this, map[sample] );
     1271      else
     1272      if (bmp->i.depth==16 && bmp->i.pixelType==D_FMT_SIGNED)
     1273        fuse_channels_weights<DIM_INT16> ( &img, sample, *this, map[sample] );
     1274      else
     1275      if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_SIGNED)
     1276        fuse_channels_weights<DIM_INT32> ( &img, sample, *this, map[sample] );
     1277      else
     1278      if (bmp->i.depth==32 && bmp->i.pixelType==D_FMT_FLOAT)
     1279        fuse_channels_weights<DIM_FLOAT32> ( &img, sample, *this, map[sample] );
     1280      else
     1281      if (bmp->i.depth==64 && bmp->i.pixelType==D_FMT_FLOAT)
     1282        fuse_channels_weights<DIM_FLOAT64> ( &img, sample, *this, map[sample] );
     1283
     1284    } // sample
     1285  }
     1286
     1287  img.bmp->i = this->bmp->i;
     1288  img.bmp->i.samples = c;
     1289  img.metadata = this->metadata;
     1290  return img;
     1291}
     1292
     1293    // this requires and RGB image
     1294TDimImage TDimImage::fuseToGrayscale() const {
     1295  if (this->samples()!=3) return TDimImage();
     1296
     1297  std::vector< std::vector< std::pair<unsigned int,float> > > mapping;
     1298  std::vector< std::pair<unsigned int,float> > gray;
     1299
     1300  gray.push_back( std::make_pair( 0, 0.3f ) );
     1301  gray.push_back( std::make_pair( 1, 0.59f ) );
     1302  gray.push_back( std::make_pair( 2, 0.11f ) );
     1303 
     1304  mapping.push_back(gray);
     1305
     1306  return fuse( mapping );
     1307}
     1308
     1309
     1310//------------------------------------------------------------------------------------
    12171311//Append channels
    12181312//------------------------------------------------------------------------------------
     
    13251419}
    13261420
     1421
     1422//------------------------------------------------------------------------------
     1423// I/O
     1424//------------------------------------------------------------------------------
     1425
     1426/*
     1427Histogram binary content:
     14280x00 'BIM1' - 4 bytes header
     14290x04 'IHS1' - 4 bytes spec
     14300x08 NUM    - 1xUINT32 number of histograms in the file (num channels in the image)
     14310xXX        - histograms
     1432*/
     1433
     1434const char IHistogram_mgk[4] = { 'B','I','M','1' };
     1435const char IHistogram_spc[4] = { 'I','H','S','1' };
     1436
     1437bool DImageHistogram::to(const std::string &fileName) {
     1438  std::ofstream f( fileName.c_str(), std::ios_base::binary );
     1439  return this->to(&f);
     1440}
     1441
     1442bool DImageHistogram::to(std::ostream *s) {
     1443  // write header
     1444  s->write( IHistogram_mgk, sizeof(IHistogram_mgk) );
     1445  s->write( IHistogram_spc, sizeof(IHistogram_spc) );
     1446
     1447  // write number of histograms
     1448  DIM_UINT32 sz = this->histograms.size();
     1449  s->write( (const char *) &sz, sizeof(DIM_UINT32) );
     1450
     1451  // write histograms
     1452  for (unsigned int c=0; c<histograms.size(); ++c)
     1453    this->histograms[c].to(s);
     1454
     1455  return true;
     1456}
     1457
     1458bool DImageHistogram::from(const std::string &fileName) {
     1459  std::ifstream f( fileName.c_str(), std::ios_base::binary  );
     1460  return this->from(&f);
     1461}
     1462
     1463bool DImageHistogram::from(std::istream *s) {
     1464  // read header
     1465  char hts_hdr[sizeof(IHistogram_mgk)];
     1466  char hts_spc[sizeof(IHistogram_spc)];
     1467
     1468  s->read( hts_hdr, sizeof(IHistogram_mgk) );
     1469  if (memcmp( hts_hdr, IHistogram_mgk, sizeof(IHistogram_mgk) )!=0) return false;
     1470
     1471  s->read( hts_spc, sizeof(IHistogram_spc) );
     1472  if (memcmp( hts_spc, IHistogram_spc, sizeof(IHistogram_spc) )) return false;
     1473
     1474  // read number of histograms
     1475  DIM_UINT32 sz;
     1476  s->read( (char *) &sz, sizeof(DIM_UINT32) );
     1477  this->histograms.resize(sz);
     1478
     1479  // read histograms
     1480  for (unsigned int c=0; c<histograms.size(); ++c)
     1481    this->histograms[c].from(s);
     1482
     1483  return true;
     1484}
     1485
    13271486//*****************************************************************************
    13281487//  DImageLut
  • bioView3D/libsrc/libbioimg/formats_api/dim_image.h

    r167 r181  
    5151#include <QImage>
    5252#include <QPixmap>
     53#include <QPainter>
    5354#endif //DIM_USE_QT
    5455
    55 #ifdef WIN32
     56#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
    5657#include <windows.h>
    57 #endif //WIN32
     58#endif //WINDOWS
    5859
    5960#include <cmath>
     
    6162#include <set>
    6263#include <limits>
     64#include <map>
    6365
    6466class DImageHistogram;
     
    101103    TDimImage(const std::string &fileName, int page);
    102104    #endif //DIM_USE_IMAGEMANAGER
     105
     106    #ifdef DIM_USE_QT
     107    TDimImage(const QImage &qimg);
     108    #endif //DIM_USE_QT
     109
    103110
    104111    // allow copy constructor, it will only point to the same memory area
     
    179186
    180187    #ifdef DIM_USE_QT
    181     QImage  toQImage  ( );
    182     QPixmap toQPixmap ( );
     188    QImage  toQImage  ( ) const;
     189    QPixmap toQPixmap ( ) const;
    183190    void fromQImage( const QImage &qimg );
    184     // paint( QPaintDevice, ROI );
     191    // paint( QPaintDevice, ROI ) const;
     192    void paint( QPainter *p ) const;
    185193    #endif //DIM_USE_QT
    186194
    187195    #ifdef WIN32
    188     HBITMAP toWinHBITMAP ( );
     196    HBITMAP toWinHBITMAP ( ) const;
    189197    // paint( HWINDOW, ROI );
    190198    #endif //WIN32
     
    216224    // some operations
    217225    //--------------------------------------------------------------------------
    218    
    219     TDimImage convertToDepth( int depth, DimLut::LutType method = DimLut::ltLinearFullRange, D_DataFormat pxtype = D_FMT_UNDEFINED ) const;
     226    TDimImage convertToDepth( int depth, DimLut::LutType method = DimLut::ltLinearFullRange, D_DataFormat pxtype = D_FMT_UNDEFINED, DImageHistogram *hist=0 ) const;
    220227    TDimImage convertToDepth( const DImageLut & ) const;
    221     TDimImage normalize( int to_bpp = 8 ) const;
     228    TDimImage normalize( int to_bpp = 8, DImageHistogram *hist=0 ) const;
    222229    bool      isUnTypedDepth() const;   
    223230    TDimImage ensureTypedDepth() const;
     
    276283    void extractChannel( int c );
    277284
     285    // creates an image with channels from both images starting with this
     286    TDimImage appendChannels( const TDimImage & ) const;
     287
     288    // CHANNEL FUSION
    278289    // fuse functions are slower but safer than the remap functions, they will physically create memory space for all output channels
    279290    // they also allow mixing channels into the same output channel
     291
     292    // generic channel fusion by selecting the max intensity of all inputs
    280293    // * the size of the mapping vector dictates how many output channels there will be,
    281294    // * vector for each channel indicates which input channels are mixed to produce the output channel
    282     // see how this will be used in the overloaded fuse methods
     295    // * the output channel intensity equals the max of all inputs
     296    // note: see how this will be used in the overloaded fuse methods
    283297    TDimImage fuse( const std::vector< std::set<int> > &mapping ) const;
    284298
    285     // this overloaded method provides a simple way of mixing up to 6 channels into the output 3 channel image
     299    // this overloaded method provides a simple way of mixing up to 7 channels into the output 3 channel image
     300    // this method is mostly good for fluorescence imagery with little colocalization
    286301    TDimImage fuse( int red, int green, int blue, int yellow=-1, int magenta=-1, int cyan=-1, int gray=-1 ) const;
    287302
    288     // this overloaded method provides a simple way of mixing up to 6 channels into the output 3 channel image
    289     TDimImage appendChannels( const TDimImage & ) const;
     303    // mixing channels using associated weights
     304    // * the size of the mapping vector dictates how many output channels there will be,
     305    // * vector for each channel indicates which input channels are mixed to produce the output channel
     306    // * the pair should contain a number of the channel as first and weight 0-1 as a second
     307    // note: see how this will be used in fuseToGrayscale
     308    TDimImage fuse( const std::vector< std::vector< std::pair<unsigned int,float> > > &mapping ) const;
     309
     310    // this requires and RGB image
     311    TDimImage fuseToGrayscale() const;
    290312
    291313  private:
     
    326348
    327349    void clear( ) { histograms.clear(); }
     350    bool isValid() const { return histograms.size()>0 && histograms[0].isValid(); }
    328351   
    329352    // mask has to be an 8bpp image where pixels >128 belong to the object of interest
     
    331354    void fromImage( const TDimImage &, const TDimImage *mask=0 );
    332355   
    333     int size() const { return histograms.size(); }
     356    int size() const { return (int) histograms.size(); }
    334357    int channels() const { return size(); }
    335358
    336359    const DimHistogram& histogram_for_channel( int c ) const { return histograms[c]; }
    337360    inline const DimHistogram* operator[](unsigned int c) const { return &histograms[c]; }
     361
     362  public:
     363    // I/O
     364    bool to(const std::string &fileName);
     365    bool to(std::ostream *s);
     366    bool from(const std::string &fileName);
     367    bool from(std::istream *s);
    338368
    339369  protected:
     
    359389    void clear( ) { luts.clear(); }
    360390   
    361     int size() const { return luts.size(); }
     391    int size() const { return (int) luts.size(); }
    362392    int channels() const { return size(); }
    363393
  • bioView3D/libsrc/libbioimg/formats_api/dim_image_pyramid.cpp

    r43 r181  
    3434int DImagePyramid::levelClosestTop( unsigned int w, unsigned int h ) const {
    3535  if (handling_image) return 0;
    36   for (int i = images.size()-1; i>0; --i) {
     36  for (int i = (int)images.size()-1; i>0; --i) {
    3737    if ( (images.at(i).width() >= w) ||
    3838         (images.at(i).height() >= h) ) return i;
     
    4545  if (images.size() <= 1) return 0;
    4646
    47   for (int i = images.size()-2; i>=0; --i) {
     47  for (int i = (int)images.size()-2; i>=0; --i) {
    4848    if ( (images.at(i).width() > w) ||
    4949         (images.at(i).height() > h) ) return i+1;
     
    5959  cur_position = 0;
    6060
    61   unsigned int min_side = dim::min<unsigned int>( images[0].width(), images[0].height() );
    62   int max_levels = (int) ceil( dim::log2<double>( min_side ) );
     61  unsigned int side = dim::max<unsigned int>( images[0].width(), images[0].height() );
     62  int max_levels = (int) ceil( dim::log2<double>( side ) );
    6363  int i = 0;
    64   while ( dim::min<unsigned int>( images[i].width(), images[i].height() ) > (unsigned int) min_width ) {
     64  while ( dim::max<unsigned int>( images[i].width(), images[i].height() ) > (unsigned int) min_width ) {
    6565    xstring x;
    6666    x.sprintf("Constructing pyramid, level %d", i+1);
     
    7777  TDimImage img;
    7878  bool res = img.fromFile( fileName, page );
    79   if (res) createFrom( img );
     79  if (res) {
     80    img = img.ensureTypedDepth();
     81    createFrom( img );
     82  }
    8083  return res;
    8184}
  • bioView3D/libsrc/libbioimg/formats_api/dim_image_qt.cpp

    r123 r181  
    2424#pragma message("TDimImage: Trolltech Qt support methods")
    2525
    26 QImage  TDimImage::toQImage ( ) {
    27   int max_samples = std::max( (int) this->samples(), 3);
     26TDimImage::TDimImage(const QImage &qimg) {
     27  bmp = NULL;
     28  connectToNewMemory();
     29  fromQImage(qimg);
     30}
     31
     32QImage  TDimImage::toQImage ( ) const {
     33  int max_samples = std::min<int>( this->samples(), 3);
    2834 
    2935  TDimImage img;
     
    3743  // Create QImage and copy data
    3844  //------------------------------------------------------------------
    39   QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied;
     45  //QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied;
     46  QImage::Format imageFormat = QImage::Format_ARGB32;
    4047  QImage image(img.width(), img.height(), imageFormat);
    4148
     
    4855        if (img.lutSize() <= 0) { // no LUT
    4956          for (int x=0; x<img.width(); ++x)
    50             dest[x] = qRgb ( src1[x], src1[x], src1[x] );
     57            dest[x] = qRgba ( src1[x], src1[x], src1[x], 255 );
    5158        }
    5259        else { // use LUT to create colors
    5360          TDimRGBA *pal = img.palette();
    5461          for (int x=0; x<img.width(); ++x)
    55             dest[x] = qRgb ( dimR(pal[src1[x]]), dimG(pal[src1[x]]), dimB(pal[src1[x]]) );
     62            dest[x] = qRgba ( dimR(pal[src1[x]]), dimG(pal[src1[x]]), dimB(pal[src1[x]]), 255 );
    5663        }
    5764    } // if (max_samples == 1)
     
    6370
    6471        for (int x=0; x<img.width(); ++x)
    65           dest[x] = qRgb ( src0[x], src1[x], 0 );
     72          dest[x] = qRgba ( src0[x], src1[x], 0, 255 );
    6673    } // if (max_samples == 2)
    6774
     
    7279
    7380        for (int x=0; x<img.width(); ++x)
    74           dest[x] = qRgb ( src0[x], src1[x], src2[x] );
     81          dest[x] = qRgba ( src0[x], src1[x], src2[x], 255 );
    7582    } // if (max_samples == 3)
    7683
     
    8087}
    8188
    82 QPixmap TDimImage::toQPixmap ( )
    83 {
     89QPixmap TDimImage::toQPixmap ( ) const {
    8490  QImage image = this->toQImage();
    85   return QPixmap::fromImage( image );
     91  return QPixmap::fromImage(image);
     92}
     93
     94void TDimImage::paint( QPainter *p ) const {
     95  p->drawImage ( 0, 0, this->toQImage() );
    8696}
    8797
     
    90100  if (qimg.depth() < 32) return;
    91101 
    92   if ( qimg.width() != width() || qimg.height() != height() )
     102  if ( qimg.width() != width() || qimg.height() != height() || this->depth()!=8 || this->samples()!=3 )
    93103    this->alloc( qimg.width(), qimg.height(), 3, 8 );
    94104
  • bioView3D/libsrc/libbioimg/formats_api/dim_image_stack.cpp

    r167 r181  
    110110bool DImageStack::positionLast() {
    111111  if (handling_image) return false;
    112   cur_position = images.size()-1;
     112  cur_position = (int)images.size()-1;
    113113  return true;
    114114}
     
    141141      TDimImage img;
    142142      if (fm.sessionReadImage( img.imageBitmap(), page ) != 0) break;
    143      
     143
    144144      // use channel constraint
    145145      if ( channel>=0 )
     
    167167  handling_image = true;
    168168  TMetaFormatManager fm;
    169   int pages = images.size();
     169  int pages = (int)images.size();
    170170
    171171  if (fm.isFormatSupportsWMP( formatName ) == false) return false;
     
    200200    if (page>=number_pages) continue;
    201201
    202     do_progress( i+1, pages.size(), "Loading stack" );
     202    do_progress( i+1, (long) pages.size(), "Loading stack" );
    203203    if (progress_abort()) break;
    204204
     
    233233  } else {
    234234    for (unsigned int i=0; i<images.size(); ++i) {
    235       do_progress( i, images.size(), "Converting depth" );
     235      do_progress( i, (long) images.size(), "Converting depth" );
    236236      images[i] = images[i].convertToDepth( depth, method, pxtype );
    237237    }
     
    241241void DImageStack::convertToDepth( const DImageLut &lut ) {
    242242  for (unsigned int i=0; i<images.size(); ++i) {
    243     do_progress( i, images.size(), "Converting depth" );
     243    do_progress( i, (long) images.size(), "Converting depth" );
    244244    images[i] = images[i].convertToDepth( lut );
    245245  }
     
    269269void DImageStack::rotate( double deg ) {
    270270  for (unsigned int i=0; i<images.size(); ++i) {
    271     do_progress( i, images.size(), "Rotate" );
     271    do_progress( i, (long) images.size(), "Rotate" );
    272272    images[i] = images[i].rotate(deg);
    273273  }
     
    311311  if ( x==0 && y==0 && width()==w && height()==h ) return;
    312312  for (unsigned int i=0; i<images.size(); ++i) {
    313     do_progress( i, images.size(), "ROI" );
     313    do_progress( i, (long) images.size(), "ROI" );
    314314    images[i] = images[i].ROI(x,y,w,h);
    315315  }
     
    328328
    329329  DImageStack stack;
    330   for (unsigned int i=z; i<z+d; ++i)
    331     stack.images.push_back( images[i].ROI( x, y, w, h ) );
     330  for (unsigned int i=z; i<(unsigned int)(z+d); ++i)
     331    stack.images.push_back( images[i].ROI( (unsigned int)x, (unsigned int)y, (unsigned int)w, (unsigned int)h ) );
    332332  stack.metadata = this->metadata;
    333333  return stack;
     
    403403  if (w != width() || h != height() )
    404404  for (unsigned int i=0; i<images.size(); ++i) {
    405     do_progress( i, images.size(), "Interpolating X/Y" );
     405    do_progress( i, (long)images.size(), "Interpolating X/Y" );
    406406    images[i] = images[i].resize(w, h, method, keep_aspect_ratio);
    407407  }
     
    439439  if (n < images.size()) { images.resize( n ); return; }
    440440
    441   int d = n - images.size();
     441  int d = n - (int)images.size();
    442442  TDimImage l = images[ images.size()-1 ];
    443443
  • bioView3D/libsrc/libbioimg/formats_api/dim_image_stack.h

    r167 r181  
    4343    bool       isEmpty() const;
    4444
    45     int        size() const { return images.size(); }
     45    int        size() const { return (int) images.size(); }
    4646    int        count() const { return size(); }
    4747    int        numberImages() const { return size(); }
  • bioView3D/libsrc/libbioimg/formats_api/dim_image_win.cpp

    r43 r181  
    1919#pragma message("TDimImage: WinAPI support methods")
    2020
    21 HBITMAP TDimImage::toWinHBITMAP ( )
    22 {
     21HBITMAP TDimImage::toWinHBITMAP() const {
    2322  HBITMAP hbmp = 0;
    2423
  • bioView3D/libsrc/libbioimg/formats_api/dim_img_format_interface.h

    r154 r181  
    102102#if defined WIN32 || defined WIN64 || defined _WIN32 || defined _WIN64
    103103#define DIM_UINT32 unsigned __int32
     104#define DIM_UINT64 unsigned __int64
    104105#else
    105106#define DIM_UINT32 unsigned int
    106 #endif
    107 
    108 #if defined WIN32 || defined WIN64 || defined _WIN32 || defined _WIN64
    109 #define DIM_UINT64 unsigned __int64
    110 #else
    111107#define DIM_UINT64 unsigned long long
    112108#endif
     109
    113110//#endif
    114111
  • bioView3D/src/glwidget.cpp

    r176 r181  
    4141
    4242// Eigen
    43 #include "matrix.h"
    44 #include "projective.h"
     43#include <Eigen/Core>
     44#include <Eigen/Geometry>
     45#include <Eigen/LU>
     46
    4547
    4648//BioImg
     
    279281void getAnglesFromModelView( GLdouble *modelview, GLdouble &a, GLdouble &b, GLdouble &g ) {
    280282
    281   Eigen::Matrix4d cameraMatrix;
    282   cameraMatrix.readArray( modelview );
    283   if ( cameraMatrix.isInvertible() )
    284     cameraMatrix = cameraMatrix.inverse();
     283  Eigen::Matrix4d cm(modelview);
     284  Eigen::Matrix4d cmi;
     285  bool invertible;
     286  cm.computeInverseWithCheck(cmi,invertible);
     287  //cmi = cm.inverse();
    285288
    286289  Eigen::Vector3d i(1,0,0);
     
    288291  Eigen::Vector3d k(0,0,1);
    289292
    290   Eigen::Matrix4d::VecType c0 = cameraMatrix.column(0);
    291   Eigen::Matrix4d::VecType c1 = cameraMatrix.column(1);
    292   Eigen::Matrix4d::VecType c2 = cameraMatrix.column(2);
    293 
    294   Eigen::Vector3d u( c0.x(), c0.y(), c0.z());
    295   Eigen::Vector3d v( c1.x(), c1.y(), c1.z());
    296   Eigen::Vector3d w( c2.x(), c2.y(), c2.z());
     293  Eigen::Vector3d u( cmi(0,0), cmi(1,0), cmi(2,0) );
     294  Eigen::Vector3d v( cmi(0,1), cmi(1,1), cmi(2,1) );
     295  Eigen::Vector3d w( cmi(0,2), cmi(1,2), cmi(2,2) );
    297296
    298297  a = acos(u.dot(i)) * 180.0 / M_PI;
     
    13051304  glGetFloatv(GL_MODELVIEW_MATRIX , modelview);
    13061305
     1306  Eigen::Matrix4f cm(modelview);
    13071307  Eigen::Matrix4f cameraMatrix;
    1308   cameraMatrix.readArray( modelview );
    1309   if ( cameraMatrix.isInvertible() )
    1310     cameraMatrix = cameraMatrix.inverse();
    1311 
    1312   float vec_coords[4] = {0.0, 0.0, 0.0, 1.0};
    1313   Eigen::Vector4f cameraPosition( vec_coords );
    1314   cameraPosition = cameraMatrix * cameraPosition;
    1315 
     1308  bool invertible;
     1309  cm.computeInverseWithCheck(cameraMatrix,invertible);
     1310
     1311  Eigen::Vector4f cameraPosition = cameraMatrix * Eigen::Vector4f( 0.0, 0.0, 0.0, 1.0 );
    13161312  camera.setPosition(cameraPosition[0], cameraPosition[1], cameraPosition[2]);
    13171313
     
    16081604GLWidget::Orientation GLWidget::getCurrentOrientation() const {
    16091605 
    1610   // get orientation
     1606  // obtain the current viewing transformation from the OpenGL state, disregarding scale
    16111607  GLdouble modelview_matrix_data[16];
    1612 
    1613 
    1614   // obtain the current viewing transformation from the OpenGL state, disregarding scale
    16151608  glPushMatrix();
    16161609  float scale  = 1.0 / (1.3*volume.volume_size[0]);
     
    16301623
    16311624  // extract rotation from the matrix
    1632   Eigen::Matrix<double,3> modelview_matrix;
    1633   modelview_matrix.setRow( 0, &modelview_matrix_data[0] );
    1634   modelview_matrix.setRow( 1, &modelview_matrix_data[4] );
    1635   modelview_matrix.setRow( 2, &modelview_matrix_data[8] );
    1636 
     1625  Eigen::Matrix3d modelview_matrix;
     1626  modelview_matrix.row(0) = Eigen::Vector3d(&modelview_matrix_data[0]);
     1627  modelview_matrix.row(1) = Eigen::Vector3d(&modelview_matrix_data[4]);
     1628  modelview_matrix.row(2) = Eigen::Vector3d(&modelview_matrix_data[8]);
    16371629
    16381630  // rotate the initial viewing direction
    1639   GLdouble view_vector_data[3] = { 0.0f, 0.0f, -1.0f };
    1640   Eigen::Vector<double,3> view_vector( view_vector_data );
    1641   view_vector = modelview_matrix * view_vector;
     1631  Eigen::Vector3d view_vector = modelview_matrix * Eigen::Vector3d(0.0, 0.0, -1.0);
    16421632
    16431633  // find the largest absolute vector component
    1644   Eigen::Vector<double,3> view_vector_abs( view_vector.array() ); 
    1645   view_vector_abs[0] = fabs(view_vector_abs[0]);
    1646   view_vector_abs[1] = fabs(view_vector_abs[1]);
    1647   view_vector_abs[2] = fabs(view_vector_abs[2]);
    1648   int max_component = dim::maxix(view_vector_abs.array(), 3);
     1634  Eigen::Vector3d view_vector_abs = view_vector.cwiseAbs(); 
     1635  int max_component = dim::maxix(view_vector_abs.data(), 3);
    16491636 
    16501637  switch ( max_component ) {
  • bioView3D/src/glwidget.h

    r175 r181  
    215215signals:
    216216  void rotationChanged(double angle, GLWidget::Axis axis);
    217   void autoRotationChanged(bool auto);
     217  void autoRotationChanged(bool autorot);
    218218
    219219  void timePointChanged(int t);
  • bioView3D/src/gobjects.cpp

    r148 r181  
    257257    *this << QSharedPointer<DGObject>( new DGObject(gobject_node) );
    258258    gobject_node = gobject_node.nextSiblingElement("gobject");
     259    QApplication::processEvents();
    259260  } // while
    260261
     
    281282    QDomDocument dom;
    282283    if ( !dom.setContent(&file) ) return 1;
     284    QApplication::processEvents();
    283285    return parse( &dom );
    284286  } else {
  • bioView3D/src/gobjects_render_gl.cpp

    r176 r181  
    2323
    2424// Eigen
    25 #include "matrix.h"
    26 #include "projective.h"
     25//#include "matrix.h"
     26//#include "projective.h"
    2727
    2828//BioImg
     
    3838//---------------------------------------------------------------------------------
    3939
    40 DGObjectRenderingOptionsGL::DGObjectRenderingOptionsGL(): DGObjectRenderingOptions() {
    41   glw = 0;
    42 }
     40//DGObjectRenderingOptionsGL::DGObjectRenderingOptionsGL(): DGObjectRenderingOptions() {
     41//  glw = 0;
     42//}
    4343
    4444template <typename T>
  • bioView3D/src/gobjects_render_gl.h

    r168 r181  
    4949
    5050public:
    51   DGObjectRenderingOptionsGL();
    52  
     51  DGObjectRenderingOptionsGL(): glw(0), DGObjectRenderingOptions() {}
     52  DGObjectRenderingOptionsGL(GLWidget *v): glw(0), DGObjectRenderingOptions() { setGLWidget(v); }
     53
    5354public:
    5455  inline GLWidget* getGLWidget()   const { return glw; }
    5556
    5657  template <typename T>
    57   bool   isVertexVisible(const DVertex5D<T> &v) const;
     58  bool isVertexVisible(const DVertex5D<T> &v) const;
    5859
    5960public slots:
  • bioView3D/src/gobjects_tree_model.cpp

    r144 r181  
    115115     DGObject *g = static_cast<DGObject*>(index.internalPointer());
    116116     g->setVisible( !g->isVisible() );
     117     //g->setVisible( !value.toBool()  ); // this does not work really
    117118     emit dataChanged(index, index);
    118119     return true;
  • bioView3D/src/ui/gobjectsRendering.ui

    r169 r181  
    362362      </sizepolicy>
    363363     </property>
     364     <property name="contextMenuPolicy">
     365      <enum>Qt::CustomContextMenu</enum>
     366     </property>
    364367     <property name="alternatingRowColors">
    365368      <bool>true</bool>
     369     </property>
     370     <property name="selectionMode">
     371      <enum>QAbstractItemView::ExtendedSelection</enum>
    366372     </property>
    367373    </widget>
  • bioView3D/src/widgets/d_histogram_widget.cpp

    r104 r181  
    216216#ifndef D_NO_DHISTOGRAM
    217217void DHistogramWidget::plot( const DimHistogram &in,  const DimHistogram &out ) {
    218   this->plot( in.get_hist(), out.get_hist() );
     218  std::vector<DimHistogram> inv;
     219  inv.push_back(in);
     220  std::vector<DimHistogram> outv;
     221  outv.push_back(out);
     222  this->plot( inv, outv );
    219223}
    220224
  • bioView3D/src/widgets/d_progress_widget.cpp

    r144 r181  
    3434  allow_interrupt = false;
    3535  min_interval = 500;
     36  timer = new QTimer();
    3637  display_style = DProgressAbstractWidget::normal;
    3738}
    3839
    3940DProgressAbstractWidget::~DProgressAbstractWidget() {
     41  delete timer;
    4042  _self_ref = 0;
    4143}
     
    5557  time_in_progress.addSecs(min_interval*2); 
    5658  doProgress( "", 0, 10 );
     59}
     60
     61void DProgressAbstractWidget::onTimer() {
     62  if (!in_progress) return;
     63  time_in_progress.addSecs(min_interval*2); 
     64  undefined_value++;
     65  if (undefined_value>10) undefined_value = 0;
     66  doProgress( "", undefined_value, 10 );
     67}
     68
     69void DProgressAbstractWidget::startUndefined( bool _allow_interrupt, DisplayStyle style ) {
     70  startNow( _allow_interrupt, style );
     71  undefined_value = 0;
     72  connect(timer, SIGNAL(timeout()), this, SLOT(onTimer()));
     73  timer->start(min_interval);
    5774}
    5875
     
    7592
    7693void DProgressAbstractWidget::stop() {
     94  timer->stop();
    7795  in_progress = false;
    7896  this->hide();
  • bioView3D/src/widgets/d_progress_widget.h

    r140 r181  
    5252  void start( bool allow_interrupt = false, DisplayStyle style = DProgressAbstractWidget::normal );
    5353  void startNow( bool allow_interrupt = false, DisplayStyle style = DProgressAbstractWidget::normal );
     54  void startUndefined( bool allow_interrupt = false, DisplayStyle style = DProgressAbstractWidget::normal );
    5455  void doProgress( const QString &, unsigned int done, unsigned int total );
    5556  void stop();
    5657  void requestStop();
     58  void onTimer();
    5759
    5860protected:
    59   QTime time_in_progress;
    60   bool  in_progress;
    61   bool  allow_interrupt;
    62   int   min_interval;
     61  QTime   time_in_progress;
     62  QTimer *timer;
     63  bool    in_progress;
     64  bool    allow_interrupt;
     65  int     min_interval;
     66  int     undefined_value;
    6367  DisplayStyle display_style;
    6468
  • bioView3D/src/window.cpp

    r176 r181  
    591591  QString fname = QFileDialog::getOpenFileName( 0, "Load GObjects XML file", init_path, tr("GObjects XML Files (*.gox *.xml *.bix)") );
    592592  if (!fname.isEmpty()) {
     593    progress->startUndefined();
    593594    QFileInfo fi( fname );
    594595    ui.gobjectsFileEdit->setText( fi.fileName() );
    595596    ui.glWidget->loadGObjects(fname);
    596     // set gobjects tree view model   
     597    // set gobjects tree view model 
     598    if (gobModel) delete gobModel;
    597599    gobModel = new DGObjectTreeModel(ui.glWidget->getGObjects());
    598600    connect(gobModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(onGobsChanged()));
     601    progress->stop();
    599602  } else {
    600603    ui.glWidget->clearGObjects();
     
    13141317  uiGObjectOptions.gobTreeView->resizeColumnToContents(2);
    13151318
    1316  
     1319  connect(uiGObjectOptions.gobTreeView, SIGNAL( customContextMenuRequested(const QPoint &)),
     1320          this, SLOT(onContextMenuGObjects(const QPoint &)));
    13171321
    13181322  rightPane->show();
     
    14561460#endif
    14571461}
     1462
     1463void Window::onContextMenuGObjects ( const QPoint & pos ) {
     1464  if (!rightPane) return;
     1465  QMenu menu(this);
     1466
     1467  QAction *a = menu.addAction ( "Expand" );
     1468  connect(a, SIGNAL(triggered()), this, SLOT(onGObjectsTreeExpand()));
     1469
     1470  a = menu.addAction ( "Collapse" );
     1471  connect(a, SIGNAL(triggered()), this, SLOT(onGObjectsTreeCollapse()));
     1472
     1473  menu.addSeparator();
     1474
     1475  a = menu.addAction ( "Show" );
     1476  connect(a, SIGNAL(triggered()), this, SLOT(onGObjectsTreeShow()));
     1477
     1478  a = menu.addAction ( "Hide" );
     1479  connect(a, SIGNAL(triggered()), this, SLOT(onGObjectsTreeHide()));
     1480
     1481  a = menu.addAction ( "Invert visibility" );
     1482  connect(a, SIGNAL(triggered()), this, SLOT(onGObjectsTreeInvertVisibility()));
     1483
     1484  menu.exec( uiGObjectOptions.gobTreeView->mapToGlobal(pos) );
     1485}
     1486
     1487void Window::onGObjectsTreeExpand() {
     1488  QModelIndexList s = uiGObjectOptions.gobTreeView->selectionModel()->selectedRows();
     1489  if (s.count()<=1)
     1490    uiGObjectOptions.gobTreeView->expandAll();
     1491  else {
     1492    for (int i=0; i<s.count(); ++i)
     1493      uiGObjectOptions.gobTreeView->expand(s[i]);
     1494  }
     1495}
     1496
     1497void Window::onGObjectsTreeCollapse() {
     1498  QModelIndexList s = uiGObjectOptions.gobTreeView->selectionModel()->selectedRows();
     1499  if (s.count()<=1)
     1500    uiGObjectOptions.gobTreeView->collapseAll();
     1501  else {
     1502    for (int i=0; i<s.count(); ++i)
     1503      uiGObjectOptions.gobTreeView->collapse(s[i]);
     1504  }
     1505}
     1506
     1507void Window::onGObjectsTreeInvertVisibility() {
     1508  uiGObjectOptions.gobTreeView->model()->blockSignals(true);
     1509  QModelIndexList s = uiGObjectOptions.gobTreeView->selectionModel()->selectedRows();
     1510  if (s.count()<=1) {
     1511    for (int i=0; i<uiGObjectOptions.gobTreeView->model()->rowCount(); ++i)
     1512      uiGObjectOptions.gobTreeView->model()->setData(uiGObjectOptions.gobTreeView->model()->index(i, 0), true);
     1513  } else {
     1514    for (int i=0; i<s.count(); ++i)
     1515      uiGObjectOptions.gobTreeView->model()->setData(s[i], true);
     1516  }
     1517  uiGObjectOptions.gobTreeView->model()->blockSignals(false);
     1518  ui.glWidget->update();
     1519}
     1520
     1521void Window::onGObjectsTreeShow() {
     1522  uiGObjectOptions.gobTreeView->model()->blockSignals(true);
     1523  QModelIndexList s = uiGObjectOptions.gobTreeView->selectionModel()->selectedRows();
     1524  if (s.count()<=1) {
     1525    for (int i=0; i<uiGObjectOptions.gobTreeView->model()->rowCount(); ++i)
     1526      if (uiGObjectOptions.gobTreeView->model()->data(uiGObjectOptions.gobTreeView->model()->index(i, 0), Qt::CheckStateRole)!=true)
     1527        uiGObjectOptions.gobTreeView->model()->setData(uiGObjectOptions.gobTreeView->model()->index(i, 0), true);
     1528  } else {
     1529    for (int i=0; i<s.count(); ++i)
     1530      if (uiGObjectOptions.gobTreeView->model()->data(s[i], Qt::CheckStateRole)!=true)
     1531        uiGObjectOptions.gobTreeView->model()->setData(s[i], true);
     1532  }
     1533  uiGObjectOptions.gobTreeView->model()->blockSignals(false);
     1534  ui.glWidget->update();
     1535}
     1536
     1537void Window::onGObjectsTreeHide() {
     1538  uiGObjectOptions.gobTreeView->model()->blockSignals(true);
     1539
     1540  QModelIndexList s = uiGObjectOptions.gobTreeView->selectionModel()->selectedRows();
     1541  if (s.count()<=1) {
     1542    for (int i=0; i<uiGObjectOptions.gobTreeView->model()->rowCount(); ++i)
     1543      if (uiGObjectOptions.gobTreeView->model()->data(uiGObjectOptions.gobTreeView->model()->index(i, 0), Qt::CheckStateRole)==true)
     1544        uiGObjectOptions.gobTreeView->model()->setData(uiGObjectOptions.gobTreeView->model()->index(i, 0), false);
     1545  } else {
     1546    for (int i=0; i<s.count(); ++i)
     1547      if (uiGObjectOptions.gobTreeView->model()->data(s[i], Qt::CheckStateRole)==true)
     1548        uiGObjectOptions.gobTreeView->model()->setData(s[i], false);
     1549  }
     1550  uiGObjectOptions.gobTreeView->model()->blockSignals(false);
     1551  ui.glWidget->update();
     1552}
     1553
  • bioView3D/src/window.h

    r172 r181  
    145145  void onCameraTab();   
    146146
     147  void onContextMenuGObjects ( const QPoint & pos );
     148
    147149private slots:
    148150  void onRightPanelResize();
     
    154156  void onTimePointChanged(int t);
    155157  void onSetPlaySpeed();
     158  void onGObjectsTreeExpand();
     159  void onGObjectsTreeCollapse();
     160  void onGObjectsTreeShow();
     161  void onGObjectsTreeHide();
     162  void onGObjectsTreeInvertVisibility();
    156163
    157164protected:
Note: See TracChangeset for help on using the changeset viewer.