Changeset 5671


Ignore:
Timestamp:
11/04/09 16:40:40 (11 years ago)
Author:
curtis
Message:

Progress on Bio-Formats ITK plugin. But still broken.

Location:
trunk/components/native/itk-plugin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/native/itk-plugin/itkBioFormatsImageIO.cxx

    r5663 r5671  
    6161  BioFormatsImageIO::BioFormatsImageIO() { 
    6262    DebugOn(); // NB: For debugging. 
    63     itkDebugMacro(<<"BioFormatsImageIO constructor"); 
     63    itkDebugMacro("BioFormatsImageIO constructor"); 
    6464    m_FileType = Binary; 
    6565 
    6666    try { 
    6767      // initialize the Java virtual machine 
    68       itkDebugMacro(<<"Creating JVM..."); 
     68      itkDebugMacro("Creating JVM..."); 
    6969      jace::StaticVmLoader loader(JNI_VERSION_1_4); 
    7070      jace::OptionList list; 
     
    7878      //list.push_back(jace::CustomOption("-verbose:jni")); 
    7979      jace::helper::createVm(loader, list, false); 
    80       itkDebugMacro(<<"JVM created."); 
    81     } 
    82     catch (JNIException& jniException) { 
    83       itkDebugMacro(<<"Exception creating JVM: " << jniException.what()); 
    84     } 
    85  
    86     try { 
    87       itkDebugMacro(<<"Creating Bio-Formats objects..."); 
     80      itkDebugMacro("JVM created."); 
     81    } 
     82    catch (JNIException& jniException) { 
     83      itkDebugMacro("Exception creating JVM: " << jniException.what()); 
     84    } 
     85 
     86    try { 
     87      itkDebugMacro("Creating Bio-Formats objects..."); 
    8888      reader = new ChannelFiller; 
    8989      writer = new ImageWriter; 
    90       itkDebugMacro(<<"Created reader and writer."); 
    91     } 
    92     catch (FormatException& fe) { 
    93       //fe.printStackTrace(); 
    94       itkDebugMacro( 
    95         <<"An unexpected Java format error occurred. " << fe.what()); 
    96     } 
    97     catch (IOException& ioe) { 
    98       //ioe.printStackTrace(); 
    99       itkDebugMacro(<<"An unexpected Java I/O error occurred. " << ioe.what()); 
    100     } 
    101     catch (JNIException& jniException) { 
    102       itkDebugMacro( 
    103         <<"An unexpected JNI error occurred. " << jniException.what()); 
     90      itkDebugMacro("Created reader and writer."); 
     91    } 
     92    catch (Exception& e) { 
     93      itkDebugMacro("A Java error occurred: " << Log::getStackTrace(e)); 
     94    } 
     95    catch (JNIException& jniException) { 
     96      itkDebugMacro("A JNI error occurred. " << jniException.what()); 
    10497    } 
    10598    catch (std::exception& e) { 
    106       itkDebugMacro(<<"An unexpected C++ error occurred. " << e.what()); 
     99      itkDebugMacro("A C++ error occurred. " << e.what()); 
    107100    } 
    108101  } // end constructor 
     
    115108  bool BioFormatsImageIO::CanReadFile(const char* FileNameToRead) { 
    116109    itkDebugMacro( 
    117       <<"BioFormatsImageIO::CanReadFile: FileNameToRead=" << FileNameToRead); 
     110      "BioFormatsImageIO::CanReadFile: FileNameToRead=" << FileNameToRead); 
    118111    std::string filename(FileNameToRead); 
    119112 
    120113    if (filename == "") { 
    121       itkExceptionMacro(<<"A FileName must be specified."); 
     114      itkDebugMacro("A FileName must be specified."); 
    122115      return false; 
    123116    } 
     
    127120      // call Bio-Formats to check file type 
    128121      isType = reader->isThisType(filename); 
    129       itkDebugMacro(<<"BioFormatsImageIO::CanReadFile: isType=" << isType); 
    130     } 
    131     catch (FormatException& fe) { 
    132       //fe.printStackTrace(); 
    133       itkDebugMacro( 
    134         <<"An unexpected Java format error occurred. " << fe.what()); 
    135     } 
    136     catch (IOException& ioe) { 
    137       //ioe.printStackTrace(); 
    138       itkDebugMacro(<<"An unexpected Java I/O error occurred. " << ioe.what()); 
    139     } 
    140     catch (JNIException& jniException) { 
    141       itkDebugMacro( 
    142         <<"An unexpected JNI error occurred. " << jniException.what()); 
     122      itkDebugMacro("BioFormatsImageIO::CanReadFile: isType=" << isType); 
     123    } 
     124    catch (Exception& e) { 
     125      itkDebugMacro("A Java error occurred: " << Log::getStackTrace(e)); 
     126    } 
     127    catch (JNIException& jniException) { 
     128      itkDebugMacro("A JNI error occurred. " << jniException.what()); 
    143129    } 
    144130    catch (std::exception& e) { 
    145       itkDebugMacro(<<"An unexpected C++ error occurred. " << e.what()); 
     131      itkDebugMacro("A C++ error occurred. " << e.what()); 
    146132    } 
    147133    return isType; 
     
    150136  void BioFormatsImageIO::ReadImageInformation() { 
    151137    itkDebugMacro( 
    152       <<"BioFormatsImageIO::ReadImageInformation: m_FileName=" << m_FileName); 
     138      "BioFormatsImageIO::ReadImageInformation: m_FileName=" << m_FileName); 
    153139 
    154140    try { 
     
    158144 
    159145      // initialize dataset 
    160       itkDebugMacro(<<"Initializing..."); 
     146      itkDebugMacro("Initializing..."); 
    161147      reader->setId(m_FileName); 
    162       itkDebugMacro(<<"Initialized."); 
     148      itkDebugMacro("Initialized."); 
    163149 
    164150      int seriesCount = reader->getSeriesCount(); 
    165       itkDebugMacro(<<"\tSeriesCount = " << seriesCount); 
     151      itkDebugMacro("\tSeriesCount = " << seriesCount); 
    166152 
    167153      // set ITK byte order 
     
    173159      int pixelType = reader->getPixelType(); 
    174160      int bpp = FormatTools::getBytesPerPixel(pixelType); 
    175       itkDebugMacro(<<"\tBytes per pixel = " << bpp); 
     161      itkDebugMacro("\tBytes per pixel = " << bpp); 
    176162      IOComponentType itkComponentType; 
    177163      if (pixelType == FormatTools::UINT8()) 
     
    196182      if (itkComponentType == UNKNOWNCOMPONENTTYPE) 
    197183      { 
    198         itkExceptionMacro(<<"Unknown pixel type: " << pixelType); 
     184        itkDebugMacro("Unknown pixel type: " << pixelType); 
    199185      } 
    200186 
     
    210196 
    211197      itkDebugMacro("Dimensional extents:" << std::endl 
    212         <<"\tSizeX = " << sizeX << std::endl 
    213         <<"\tSizeY = " << sizeY << std::endl 
    214         <<"\tSizeZ = " << sizeZ << std::endl 
    215         <<"\tSizeC = " << sizeC << std::endl 
    216         <<"\tSizeT = " << sizeT << std::endl 
    217         <<"\tRGB Channel Count = " << rgbChannelCount << std::endl 
    218         <<"\tEffective SizeC = " << rgbChannelCount << std::endl 
    219         <<"\tImage Count = " << imageCount); 
     198        << "\tSizeX = " << sizeX << std::endl 
     199        << "\tSizeY = " << sizeY << std::endl 
     200        << "\tSizeZ = " << sizeZ << std::endl 
     201        << "\tSizeC = " << sizeC << std::endl 
     202        << "\tSizeT = " << sizeT << std::endl 
     203        << "\tRGB Channel Count = " << rgbChannelCount << std::endl 
     204        << "\tEffective SizeC = " << rgbChannelCount << std::endl 
     205        << "\tImage Count = " << imageCount); 
    220206 
    221207      int numDims = 2; // X and Y 
     
    250236      if (imageCount > 1) m_Spacing[2] = 1; 
    251237 
    252       itkDebugMacro(<<"\tPhysicalSizeX = " << physX); 
    253       itkDebugMacro(<<"\tPhysicalSizeY = " << physY); 
    254     } 
    255     catch (FormatException& fe) { 
    256       //fe.printStackTrace(); 
    257       itkDebugMacro( 
    258         <<"An unexpected Java format error occurred. " << fe.what()); 
    259     } 
    260     catch (IOException& ioe) { 
    261       //ioe.printStackTrace(); 
    262       itkDebugMacro(<<"An unexpected Java I/O error occurred. " << ioe.what()); 
    263     } 
    264     catch (JNIException& jniException) { 
    265       itkDebugMacro( 
    266         <<"An unexpected JNI error occurred. " << jniException.what()); 
     238      itkDebugMacro("Physical resolution: " << physX << " x " << physY); 
     239    } 
     240    catch (Exception& e) { 
     241      itkDebugMacro("A Java error occurred: " << Log::getStackTrace(e)); 
     242    } 
     243    catch (JNIException& jniException) { 
     244      itkDebugMacro("A JNI error occurred. " << jniException.what()); 
    267245    } 
    268246    catch (std::exception& e) { 
    269       itkDebugMacro(<<"An unexpected C++ error occurred. " << e.what()); 
     247      itkDebugMacro("A C++ error occurred. " << e.what()); 
    270248    } 
    271249  } // end ReadImageInformation function 
     
    273251  void BioFormatsImageIO::Read(void* pData) { 
    274252    char* data = (char*) pData; 
    275     itkDebugMacro(<<"BioFormatsImageIO::Read"); 
     253    itkDebugMacro("BioFormatsImageIO::Read"); 
    276254 
    277255    try { 
     
    280258      int rgbChannelCount = reader->getRGBChannelCount(); 
    281259 
    282       itkDebugMacro(<<"Pixel type code = " << pixelType); 
    283       itkDebugMacro(<<"Bytes per pixel = " << bpp); 
     260      itkDebugMacro("Pixel type:" << std::endl 
     261        << "Pixel type code = " << pixelType << std::endl 
     262        << "Bytes per pixel = " << bpp << std::endl 
     263        << "RGB channel count = " << rgbChannelCount); 
    284264 
    285265      // check IO region to identify the planar extents desired 
    286266      ImageIORegion region = GetIORegion(); 
    287267      int regionDim = region.GetImageDimension(); 
    288       int xIndex = region.GetIndex(0); 
    289       int xCount = region.GetSize(0); 
    290       int yIndex = region.GetIndex(1); 
    291       int yCount = region.GetSize(1); 
    292       int pIndex = 0, pCount = 1; 
    293       if (regionDim > 2) { 
    294         pIndex = region.GetIndex(2); 
    295         pCount = region.GetSize(2); 
     268      int xStart = 0, xCount = 1; 
     269      int yStart = 0, yCount = 1; 
     270      int zStart = 0, zCount = 1; 
     271      int tStart = 0, tCount = 1; 
     272      int cStart = 0, cCount = 1; 
     273 
     274      int sizeZ = reader->getSizeZ(); 
     275      int sizeT = reader->getSizeT(); 
     276      int effSizeC = reader->getEffectiveSizeC(); 
     277 
     278      int xIndex = 0, yIndex = 1, zIndex = 2, tIndex = 3, cIndex = 4; 
     279      if (sizeZ == 1) { 
     280        zIndex = -1; 
     281        tIndex--; 
     282        cIndex--; 
     283      } 
     284      if (sizeT == 1) { 
     285        tIndex = -1; 
     286        cIndex--; 
     287      } 
     288      if (effSizeC == 1) { 
     289        cIndex = -1; 
     290      } 
     291      for (int dim = 0; dim < regionDim; dim++) { 
     292        int index = region.GetIndex(dim); 
     293        int size = region.GetSize(dim); 
     294        if (dim == xIndex) { 
     295          xStart = index; 
     296          xCount = size; 
     297        } 
     298        else if (dim == yIndex) { 
     299          yStart = index; 
     300          yCount = size; 
     301        } 
     302        else if (dim == zIndex) { 
     303          zStart = index; 
     304          zCount = size; 
     305        } 
     306        else if (dim == tIndex) { 
     307          tStart = index; 
     308          tCount = size; 
     309        } 
     310        else if (dim == cIndex) { 
     311          cStart = index; 
     312          cCount = size; 
     313        } 
    296314      } 
    297315      int bytesPerSubPlane = xCount * yCount * bpp * rgbChannelCount; 
    298316 
    299317      itkDebugMacro("Region extents:" << std::endl 
    300         <<"\tRegion dimension = " << regionDim << std::endl 
    301         <<"\tX index = " << xIndex << std::endl 
    302         <<"\tX count = " << xCount << std::endl 
    303         <<"\tY index = " << yIndex << std::endl 
    304         <<"\tY count = " << yCount << std::endl 
    305         <<"\tPlane index = " << pIndex << std::endl 
    306         <<"\tPlane count = " << pCount << std::endl 
    307         <<"\tBytes per plane = " << bytesPerSubPlane); 
     318        << "\tRegion dimension = " << regionDim << std::endl 
     319        << "\tX: start = " << xStart << ", count = " << xCount << std::endl 
     320        << "\tY: start = " << yStart << ", count = " << yCount << std::endl 
     321        << "\tZ: start = " << zStart << ", count = " << zCount << std::endl 
     322        << "\tT: start = " << tStart << ", count = " << tCount << std::endl 
     323        << "\tC: start = " << cStart << ", count = " << cCount << std::endl 
     324        << "\tBytes per plane = " << bytesPerSubPlane); 
     325 
     326      int imageCount = reader->getImageCount(); 
    308327 
    309328      int p = 0; 
    310       ByteArray buf(bytesPerSubPlane); // pre-allocate buffer 
    311       for (int no=pIndex; no<pIndex+pCount; no++) { 
    312         int imageCount = reader->getImageCount(); 
    313         itkDebugMacro(<<"Reading image plane " << no << 
    314           " (" << (no - pIndex + 1) << "/" << pCount << 
    315           " of " << imageCount << " available planes)"); 
    316         reader->openBytes(no, buf, xIndex, yIndex, xCount, yCount); 
    317         for (int i=0; i<bytesPerSubPlane; i++) data[p++] = buf[i]; 
     329      //ByteArray buf(bytesPerSubPlane); // pre-allocate buffer 
     330      for (int c=cStart; c<cCount; c++) { 
     331        for (int t=tStart; t<tCount; t++) { 
     332          for (int z=zStart; z<zCount; z++) { 
     333            int no = reader->getIndex(z, c, t); 
     334            itkDebugMacro("Reading image plane " << no 
     335              << " (Z=" << z << ", T=" << t << ", C=" << c << ")" 
     336              << " of " << imageCount << " available planes)"); 
     337            //reader->openBytes(no, buf, xStart, yStart, xCount, yCount); 
     338            ByteArray buf = reader->openBytes(no, 
     339              xStart, yStart, xCount, yCount); 
     340            for (int i=0; i<bytesPerSubPlane; i++) { 
     341              itkDebugMacro("\tdata #" << i << " = " << buf[i]); 
     342              data[p++] = buf[i]; 
     343            } 
     344          } 
     345        } 
    318346      } 
    319347 
    320348      reader->close(); 
    321349    } 
    322     catch (FormatException& fe) { 
    323       //fe.printStackTrace(); 
     350    catch (Exception& e) { 
     351      itkDebugMacro("A Java error occurred: " << Log::getStackTrace(e)); 
     352    } 
     353    catch (JNIException& jniException) { 
    324354      itkDebugMacro( 
    325         <<"An unexpected Java format error occurred. " << fe.what()); 
    326     } 
    327     catch (IOException& ioe) { 
    328       //ioe.printStackTrace(); 
    329       itkDebugMacro(<<"An unexpected Java I/O error occurred. " << ioe.what()); 
    330     } 
    331     catch (JNIException& jniException) { 
    332       itkDebugMacro( 
    333         <<"An unexpected JNI error occurred. " << jniException.what()); 
     355        "A JNI error occurred. " << jniException.what()); 
    334356    } 
    335357    catch (std::exception& e) { 
    336       itkDebugMacro(<<"An unexpected C++ error occurred. " << e.what()); 
    337     } 
    338     itkDebugMacro(<<"Done."); 
     358      itkDebugMacro("A C++ error occurred. " << e.what()); 
     359    } 
     360    itkDebugMacro("Done."); 
    339361  } // end Read function 
    340362 
    341363  bool BioFormatsImageIO::CanWriteFile(const char* name) { 
    342     itkDebugMacro(<<"BioFormatsImageIO::CanWriteFile: name=" << name); 
     364    itkDebugMacro("BioFormatsImageIO::CanWriteFile: name=" << name); 
    343365    std::string filename(name); 
    344366 
    345367    if (filename == "") { 
    346       itkExceptionMacro(<<"A FileName must be specified."); 
     368      itkDebugMacro("A FileName must be specified."); 
    347369      return false; 
    348370    } 
     
    353375      ImageWriter writer; 
    354376      isType = writer.isThisType(filename); 
    355       itkDebugMacro(<<"BioFormatsImageIO::CanWriteFile: isType=" << isType); 
    356     } 
    357     catch (FormatException& fe) { 
    358       //fe.printStackTrace(); 
    359       itkDebugMacro( 
    360         <<"An unexpected Java format error occurred. " << fe.what()); 
    361     } 
    362     catch (IOException& ioe) { 
    363       //ioe.printStackTrace(); 
    364       itkDebugMacro(<<"An unexpected Java I/O error occurred. " << ioe.what()); 
    365     } 
    366     catch (JNIException& jniException) { 
    367       itkDebugMacro( 
    368         <<"An unexpected JNI error occurred. " << jniException.what()); 
     377      itkDebugMacro("BioFormatsImageIO::CanWriteFile: isType=" << isType); 
     378    } 
     379    catch (Exception& e) { 
     380      itkDebugMacro("A Java error occurred: " << Log::getStackTrace(e)); 
     381    } 
     382    catch (JNIException& jniException) { 
     383      itkDebugMacro("A JNI error occurred. " << jniException.what()); 
    369384    } 
    370385    catch (std::exception& e) { 
    371       itkDebugMacro(<<"An unexpected C++ error occurred. " << e.what()); 
     386      itkDebugMacro("A C++ error occurred. " << e.what()); 
    372387    } 
    373388    return isType; 
     
    375390 
    376391  void BioFormatsImageIO::WriteImageInformation() { 
    377     itkDebugMacro(<<"BioFormatsImageIO::WriteImageInformation"); 
     392    itkDebugMacro("BioFormatsImageIO::WriteImageInformation"); 
    378393    // NB: Nothing to do. 
    379394  } // end WriteImageInformation function 
    380395 
    381396  void BioFormatsImageIO::Write(const void* buffer) { 
    382     itkDebugMacro(<<"BioFormatsImageIO::Write"); 
     397    itkDebugMacro("BioFormatsImageIO::Write"); 
    383398    // CTR TODO - implement Write function 
    384399  } // end Write function 
  • trunk/components/native/itk-plugin/itkBioFormatsImageIO.h

    r5663 r5671  
    3636 
    3737// for Bio-Formats C++ bindings 
     38#include "loci-common.h" 
     39using jace::JNIException; 
     40using jace::proxy::java::lang::Exception; 
     41using jace::proxy::loci::common::Log; 
    3842#include "bio-formats.h" 
    39 using jace::JNIException; 
    40 using jace::proxy::java::io::IOException; 
    4143using jace::proxy::loci::formats::ChannelFiller; 
    42 using jace::proxy::loci::formats::FormatException; 
    4344using jace::proxy::loci::formats::FormatTools; 
    4445using jace::proxy::loci::formats::ImageWriter; 
Note: See TracChangeset for help on using the changeset viewer.