| 143 | } |
| 144 | |
| 145 | public static boolean ImageBufferTest() |
| 146 | { |
| 147 | long[] v = {2,3,4}; |
| 148 | VectorUInt32 idx = new VectorUInt32( v ); |
| 149 | |
| 150 | int size = 7*8*9; |
| 151 | short val = 42; |
| 152 | |
| 153 | Image image = new Image(7,8,9, PixelIDValueEnum.sitkUInt8); |
| 154 | image.setPixelAsUInt8(idx, (short)99); |
| 155 | |
| 156 | // Low level method is not recommended, but has been useful when |
| 157 | // interfacing with other low level C based libraries in Java |
| 158 | long ptr = image.getBufferAsNativePointer(); |
| 159 | |
| 160 | if (ptr == 0) |
| 161 | { |
| 162 | System.out.println("Null native buffer pointer"); |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | java.nio.Buffer b1 = image.getBufferAsBuffer(); |
| 167 | |
| 168 | if (b1.capacity() != size) |
| 169 | { |
| 170 | System.out.println("Capacity is not as expected"); |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | if (!b1.isDirect()) |
| 175 | { |
| 176 | System.out.println("Buffer is not direct"); |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | if (b1.isReadOnly()) |
| 181 | { |
| 182 | System.out.println("Buffer is read-only"); |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | java.nio.ByteBuffer bb = (java.nio.ByteBuffer) b1; |
| 187 | |
| 188 | if (bb.get(0) != 0) |
| 189 | { |
| 190 | System.out.println("Expected 0 value"); |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | if (bb.get(2+7*3+7*8*4) != 99) |
| 195 | { |
| 196 | System.out.println("Expected 99 value"); |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | |
| 201 | |
| 202 | return true; |