Changeset 4890


Ignore:
Timestamp:
03/03/09 16:08:16 (11 years ago)
Author:
curtis
Message:

Fix various bugs with Bio-Formats ITK plugin. Also works on Mac OS X now.

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

Legend:

Unmodified
Added
Removed
  • trunk/components/native/itk-plugin/CMakeLists.txt

    r4877 r4890  
    4545# Include dirs 
    4646 
     47find_package(JNI REQUIRED) 
     48message("-- Java Native Interface:") 
     49message("jawt lib         : ${JAVA_AWT_LIBRARY}") 
     50message("jvm lib          : ${JAVA_JVM_LIBRARY}") 
     51message("jni.h            : ${JAVA_INCLUDE_PATH}") 
     52message("jni_md.h         : ${JAVA_INCLUDE_PATH2}") 
     53message("jawt.h           : ${JAVA_AWT_INCLUDE_PATH}") 
     54message("") 
     55 
     56set(Boost_USE_STATIC_LIBS OFF) 
     57set(Boost_USE_MULTITHREAD ON) 
     58set(Boost_ADDITIONAL_VERSIONS "1.38" "1.38.0" "1.38.1" "1.39" "1.39.0" "1.39.1" 
     59  "1.40" "1.40.0" "1.40.1" "1.41" "1.41.0" "1.41.1" "1.42" "1.42.0" "1.42.1") 
     60find_package(Boost COMPONENTS thread REQUIRED) 
     61message("-- Boost:") 
     62if(EXISTS ${Boost_LIBRARIES}) 
     63message("boost/thread.hpp : ${Boost_INCLUDE_DIR}") 
     64message("boost libs       : ${Boost_LIBRARIES}") 
     65message("") 
     66else(EXISTS ${Boost_LIBRARIES}) 
     67  message(FATAL_ERROR "Cannot build without Boost Thread library. Please install libboost-thread-dev package or visit www.boost.org.") 
     68endif(EXISTS ${Boost_LIBRARIES}) 
     69 
    4770set(JACE_DIR NOTFOUND CACHE PATH "The path to toplevel directory of your Jace checkout") 
    4871if(NOT JACE_DIR) 
     
    5275set(BF_JACE_DIR ${PROJECT_SOURCE_DIR}/../bf-cpp) 
    5376 
    54 find_package(JNI REQUIRED) 
    55  
    5677set(include_dirs 
    5778 ${CMAKE_CURRENT_SOURCE_DIR} 
    5879 ${CMAKE_CURRENT_BINARY_DIR} 
    59  ${JNI_INCLUDE_DIRS} 
    60 #CTR 
     80 ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2} ${Boost_INCLUDE_DIR} 
    6181 ${JACE_DIR}/source/c++/include 
    6282 ${BF_JACE_DIR}/include 
     
    7191include_directories(${include_dirs}) 
    7292 
    73 #CTR 
    7493link_directories(${BF_JACE_DIR}/build) 
    7594 
     
    104123target_link_libraries(${lib_name} 
    105124 ITKIO 
    106 #CTR 
    107125 jace 
    108126 bfjace 
     127 ${JAVA_JVM_LIBRARY} ${Boost_LIBRARIES} 
    109128) 
    110129 
     
    139158target_link_libraries(BioFormatsIOPlugin 
    140159 ${lib_name} 
    141 #CTR 
    142160 jace 
    143161 bfjace 
     162 ${JAVA_JVM_LIBRARY} ${Boost_LIBRARIES} 
    144163) 
    145164 
  • trunk/components/native/itk-plugin/itkBioFormatsImageIO.cxx

    r4877 r4890  
    103103    // call Bio-Formats to check file type 
    104104 
    105     // NB: Calling reader->isThisType() causes a symbol lookup error on: 
    106     //     _ZNK4jace5proxy5types8JBooleancvaEv 
    107     /* 
     105    // NB: On Linux, reader->isThisType() causes a symbol lookup error on: 
     106    //       _ZNK4jace5proxy5types8JBooleancvaEv 
    108107    bool isType = reader->isThisType(filename); 
    109108    PRINT("BioFormatsImageIO::CanReadFile: isType=" << isType); 
    110109    return isType; 
    111     */ 
    112  
    113     return true; 
    114110  } 
    115111 
     
    133129    // get byte order 
    134130 
    135     // NB: Calling reader->isLittleEndian() causes a symbol lookup error on: 
    136     //     _ZNK4jace5proxy5types8JBooleancvaEv 
    137     /* 
     131    // NB: On Linux, reader->isLittleEndian() causes a symbol lookup error on: 
     132    //       _ZNK4jace5proxy5types8JBooleancvaEv 
    138133    bool little = reader->isLittleEndian(); 
    139     if (little) SetByteOrderToLittleEndian(); 
    140     else SetByteOrderToBigEndian(); 
    141     */ 
    142     SetByteOrderToBigEndian(); // m_ByteOrder 
     134    if (little) SetByteOrderToLittleEndian(); // m_ByteOrder 
     135    else SetByteOrderToBigEndian(); // m_ByteOrder 
    143136 
    144137    // get component type 
    145138 
    146     // NB: Calling FormatTools::UINT8() causes a symbol lookup error on: 
    147     //     _ZN4jace6helper15deleteGlobalRefEP10_Jv_JNIEnvP9__jobject 
     139    // NB: On Linux, FormatTools::UINT8() causes a symbol lookup error on: 
     140    //       _ZN4jace6helper15deleteGlobalRefEP10_Jv_JNIEnvP9__jobject 
    148141    int pixelType = reader->getPixelType(); 
    149142    int bpp = FormatTools::getBytesPerPixel(pixelType); 
    150143    PRINT("\tBytes per pixel = " << bpp); 
    151     /* 
    152144    IOComponentType componentType; 
    153145    if (pixelType == FormatTools::UINT8()) 
     
    155147    else if (pixelType == FormatTools::INT8()) 
    156148      componentType = CHAR; 
    157     if (pixelType == FormatTools::UINT16()) 
     149    else if (pixelType == FormatTools::UINT16()) 
    158150      componentType = USHORT; 
    159151    else if (pixelType == FormatTools::INT16()) 
    160152      componentType = SHORT; 
    161     if (pixelType == FormatTools::UINT32()) 
     153    else if (pixelType == FormatTools::UINT32()) 
    162154      componentType = UINT; 
    163155    else if (pixelType == FormatTools::INT32()) 
    164156      componentType = INT; 
    165     if (pixelType == FormatTools::FLOAT()) 
     157    else if (pixelType == FormatTools::FLOAT()) 
    166158      componentType = FLOAT; 
    167159    else if (pixelType == FormatTools::DOUBLE()) 
     
    174166      itkExceptionMacro(<<"Unknown pixel type: " << pixelType); 
    175167    } 
    176     */ 
    177  
    178     // TEMP - for now we assume 8-bit unsigned integer data 
    179     SetComponentType(UCHAR); 
    180168 
    181169    // get pixel resolution and dimensional extents 
     
    252240 
    253241    int p = 0; 
     242    //ByteArray buf(bytesPerSubPlane); // pre-allocate buffer 
    254243    for (int no=pIndex; no<pIndex+pCount; no++) 
    255244    { 
    256       PRINT("Reading image plane " << 
    257         (no + 1) << "/" << reader->getImageCount()); 
    258       ByteArray buf = reader->openBytes(no, xIndex, xCount, yIndex, yCount); 
    259  
    260       // NB: Using brackets with a JArray causes a symbol lookup error on: 
    261       //     _ZN4jace6helper12newGlobalRefEP10_Jv_JNIEnvP9__jobject 
    262       //for (int i=0; i<bytesPerSubPlane; i++) data[p++] = buf[i]; 
    263  
    264       // TEMP - for now we populate the buffer with dummy data 
    265       for (int i=0; i<bytesPerSubPlane; i++) data[p++] = 255 - no; 
     245      PRINT("Reading image plane " << no << 
     246        " (" << (no - pIndex + 1) << "/" << pCount << 
     247        " of " << reader->getImageCount() << " available planes)"); 
     248      const ByteArray& buf = reader->openBytes(no, 
     249        xIndex, yIndex, xCount, yCount); 
     250      if (buf.isNull()) 
     251      { 
     252        itkExceptionMacro(<<"Image data is null."); 
     253      } 
     254      else if ((int) buf.length() != bytesPerSubPlane) 
     255      { 
     256        itkExceptionMacro(<<"Invalid image buffer size: " << 
     257          buf.length() << " (expected " << bytesPerSubPlane << ")"); 
     258      } 
     259 
     260      // NB: On Linux, brackets with a JArray cause a symbol lookup error on: 
     261      //       _ZN4jace6helper12newGlobalRefEP10_Jv_JNIEnvP9__jobject 
     262      for (int i=0; i<bytesPerSubPlane; i++) data[p++] = buf[i]; 
    266263    } 
    267264 
  • trunk/components/native/itk-plugin/readme.txt

    r4877 r4890  
    55to read and write supported life sciences file formats. 
    66 
    7 The initial plugin implementation is complete. However, there are a number of 
    8 symbol lookup errors at runtime, so portions of the functionality are currently 
    9 commented out to avoid them. 
     7The implementation is still very preliminary, and may be substantially changed 
     8before a stable release is announced. 
    109 
    1110 
     
    3837 
    3938 
    40 BUILDING AND TESTING THE PLUGIN ON LINUX 
     39BUILDING AND TESTING THE PLUGIN ON LINUX AND MAC OS X 
    4140 
    42411) Download and build the Insight Toolkit source code from: 
    4342 
    44   http://www.itk.org/ITK/resources/software.html 
     43     http://www.itk.org/ITK/resources/software.html 
     44 
     45   Be sure to build with shared libraries (BUILD_SHARED_LIBS set to ON). 
    4546 
    46472) Follow the directions in components/native/bf-cpp to build the Bio-Formats 
     
    51524) Run the (lame, temporary) build script: 
    5253 
    53   ITK_DIR=/path/to/itk/build sh build.sh 2> /dev/null 
     54     ITK_DIR=/path/to/itk/build sh build.sh 2> /dev/null 
    5455 
    55565) After the build succeeds, the script will copy dependent libraries 
     
    6061   rerun to compare against the results with ITK's built-in TIFF reader. 
    6162 
    62 If you get this far, you will have noticed that the histogram is always filled 
    63 with 255s. This is because the plugin does not currently copy the planar data 
    64 between data structures, due to one of the symbol lookup errors. 
    65  
    66  
    67 SYMBOL LOOKUP ERRORS 
    68  
    69 As a rule of thumb, anything labeled "NB:" or "TEMP" in the 
    70 itkBioFormatsImageIO.cxx source file documents a known problem and/or 
    71 associated workaround at the moment, the most show-stopping of which are the 
    72 symbol lookup errors. 
    73  
    74 For example, from lines 260-2 of itkBioFormatsImageIO.cxx: 
    75  
    76   // NB: Using brackets with a JArray causes a symbol lookup error on: 
    77   //     _ZN4jace6helper12newGlobalRefEP10_Jv_JNIEnvP9__jobject 
    78   //for (int i=0; i<bytesPerSubPlane; i++) data[p++] = buf[i]; 
    79  
    80 Uncommenting the for loop and rerunning the build script yields: 
    81  
    82   $ ./ImageHistogram1 image.tif 
    83   *snip output* 
    84   Reading image plane 1/1 
    85   ./ImageHistogram1: symbol lookup error: libBioFormatsIO.so: undefined symbol: _ZN4jace6helper12newGlobalRefEP10_Jv_JNIEnvP9__jobject 
    86  
    87 Dumping the relevant symbols from libjace.so yields: 
    88  
    89   $ nm libjace.so | grep newGlobalRef 
    90   00025621 T _ZN4jace6helper12newGlobalRefEP7JNIEnv_P8_jobject 
    91  
    92 So the symbol is essentially there, but slightly different... 
     63Please direct questions to the Bio-Formats team at bioformats@loci.wisc.edu. 
Note: See TracChangeset for help on using the changeset viewer.