Search in sources :

Example 6 with Tre

use of org.codice.imaging.nitf.core.tre.Tre in project alliance by codice.

the class CatalogOutputAdapter method createIchipb.

@SuppressWarnings("UnnecessaryLocalVariable")
Tre createIchipb(BufferedImage chip, int sourceX, int sourceY, float selectWidth, float selectHeight) {
    Tre ichipb = TreFactory.getDefault("ICHIPB", TreSource.ImageExtendedSubheaderData);
    ichipb.add(new TreEntryImpl("XFRM_FLAG", "00", UINT));
    ichipb.add(new TreEntryImpl("SCALE_FACTOR", "0001.00000", REAL));
    ichipb.add(new TreEntryImpl("ANAMRPH_CORR", "00", UINT));
    ichipb.add(new TreEntryImpl("SCANBLK_NUM", "01", UINT));
    float halfPixel = 0.5f;
    float chipX0 = halfPixel;
    float chipY0 = halfPixel;
    float chipX1 = (float) chip.getWidth() - halfPixel;
    float chipY1 = (float) chip.getHeight() - halfPixel;
    ichipb.add(new TreEntryImpl("OP_ROW_11", formatCoord(chipY0), REAL));
    ichipb.add(new TreEntryImpl("OP_COL_11", formatCoord(chipX0), REAL));
    ichipb.add(new TreEntryImpl("OP_ROW_12", formatCoord(chipY0), REAL));
    ichipb.add(new TreEntryImpl("OP_COL_12", formatCoord(chipX1), REAL));
    ichipb.add(new TreEntryImpl("OP_ROW_21", formatCoord(chipY1), REAL));
    ichipb.add(new TreEntryImpl("OP_COL_21", formatCoord(chipX0), REAL));
    ichipb.add(new TreEntryImpl("OP_ROW_22", formatCoord(chipY1), REAL));
    ichipb.add(new TreEntryImpl("OP_COL_22", formatCoord(chipX1), REAL));
    float origX0 = sourceX + halfPixel;
    float origY0 = sourceY + halfPixel;
    float origX1 = sourceX + selectWidth - halfPixel;
    float origY1 = sourceY + selectHeight - halfPixel;
    ichipb.add(new TreEntryImpl("FI_ROW_11", formatCoord(origY0), REAL));
    ichipb.add(new TreEntryImpl("FI_COL_11", formatCoord(origX0), REAL));
    ichipb.add(new TreEntryImpl("FI_ROW_12", formatCoord(origY0), REAL));
    ichipb.add(new TreEntryImpl("FI_COL_12", formatCoord(origX1), REAL));
    ichipb.add(new TreEntryImpl("FI_ROW_21", formatCoord(origY1), REAL));
    ichipb.add(new TreEntryImpl("FI_COL_21", formatCoord(origX0), REAL));
    ichipb.add(new TreEntryImpl("FI_ROW_22", formatCoord(origY1), REAL));
    ichipb.add(new TreEntryImpl("FI_COL_22", formatCoord(origX1), REAL));
    ichipb.add(new TreEntryImpl("FI_ROW", "00000000", UINT));
    ichipb.add(new TreEntryImpl("FI_COL", "00000000", UINT));
    return ichipb;
}
Also used : Tre(org.codice.imaging.nitf.core.tre.Tre) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)

Example 7 with Tre

use of org.codice.imaging.nitf.core.tre.Tre in project alliance by codice.

the class CatalogOutputAdapterTest method testCreateIchipb.

@Test
public void testCreateIchipb() throws NitfFormatException {
    BufferedImage bufferedImage = mock(BufferedImage.class);
    int originalWidth = 200;
    int originalHeight = 100;
    when(bufferedImage.getWidth()).thenReturn(originalWidth);
    when(bufferedImage.getHeight()).thenReturn(originalHeight);
    int chipX = 20;
    int chipY = 10;
    Tre tre = catalogOutputAdapter.createIchipb(bufferedImage, chipX, chipY, 160, 80);
    assertTreEntry(tre, "XFRM_FLAG", TWO_DIGIT_REGEX, UINT);
    assertTreEntry(tre, "SCALE_FACTOR", Pattern.compile("^[0-9]{4}\\.[0-9]{5}$"), REAL);
    assertTreEntry(tre, "ANAMRPH_CORR", TWO_DIGIT_REGEX, UINT);
    assertTreEntry(tre, "SCANBLK_NUM", TWO_DIGIT_REGEX, UINT);
    assertTreEntry(tre, "OP_ROW_11", COORD_REGEX, REAL);
    assertTreEntry(tre, "OP_COL_11", COORD_REGEX, REAL);
    assertTreEntry(tre, "OP_ROW_12", COORD_REGEX, REAL);
    assertTreEntry(tre, "OP_COL_12", COORD_REGEX, REAL);
    assertTreEntry(tre, "OP_ROW_21", COORD_REGEX, REAL);
    assertTreEntry(tre, "OP_COL_21", COORD_REGEX, REAL);
    assertTreEntry(tre, "OP_ROW_22", COORD_REGEX, REAL);
    assertTreEntry(tre, "OP_COL_22", COORD_REGEX, REAL);
    assertTreEntry(tre, "FI_ROW_11", COORD_REGEX, REAL);
    assertTreEntry(tre, "FI_COL_11", COORD_REGEX, REAL);
    assertTreEntry(tre, "FI_ROW_12", COORD_REGEX, REAL);
    assertTreEntry(tre, "FI_COL_12", COORD_REGEX, REAL);
    assertTreEntry(tre, "FI_ROW_21", COORD_REGEX, REAL);
    assertTreEntry(tre, "FI_COL_21", COORD_REGEX, REAL);
    assertTreEntry(tre, "FI_ROW_22", COORD_REGEX, REAL);
    assertTreEntry(tre, "FI_COL_22", COORD_REGEX, REAL);
    assertTreEntry(tre, "FI_ROW", EIGHT_DIGIT_REGEX, UINT);
    assertTreEntry(tre, "FI_COL", EIGHT_DIGIT_REGEX, UINT);
    assertThat(tre.getDoubleValue("OP_ROW_11"), closeTo(0.5, 0.01));
    assertThat(tre.getDoubleValue("OP_COL_11"), closeTo(0.5, 0.01));
    assertThat(tre.getDoubleValue("OP_ROW_12"), closeTo(0.5, 0.01));
    assertThat(tre.getDoubleValue("OP_COL_12"), closeTo(originalWidth - 0.5, 0.01));
    assertThat(tre.getDoubleValue("OP_ROW_21"), closeTo(originalHeight - 0.5, 0.01));
    assertThat(tre.getDoubleValue("OP_COL_21"), closeTo(0.5, 0.01));
    assertThat(tre.getDoubleValue("OP_ROW_22"), closeTo(originalHeight - 0.5, 0.01));
    assertThat(tre.getDoubleValue("OP_COL_22"), closeTo(originalWidth - 0.5, 0.01));
    assertThat(tre.getDoubleValue("FI_ROW_11"), closeTo(chipY + 0.5, 0.01));
    assertThat(tre.getDoubleValue("FI_COL_11"), closeTo(chipX + 0.5, 0.01));
    assertThat(tre.getDoubleValue("FI_ROW_12"), closeTo(chipY + 0.5, 0.01));
    assertThat(tre.getDoubleValue("FI_COL_12"), closeTo(originalWidth - chipX - 0.5, 0.01));
    assertThat(tre.getDoubleValue("FI_ROW_21"), closeTo(originalHeight - chipY - 0.5, 0.01));
    assertThat(tre.getDoubleValue("FI_COL_21"), closeTo(chipX + 0.5, 0.01));
    assertThat(tre.getDoubleValue("FI_ROW_22"), closeTo(originalHeight - chipY - 0.5, 0.01));
    assertThat(tre.getDoubleValue("FI_COL_22"), closeTo(originalWidth - chipX - 0.5, 0.01));
}
Also used : Tre(org.codice.imaging.nitf.core.tre.Tre) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 8 with Tre

use of org.codice.imaging.nitf.core.tre.Tre in project alliance by codice.

the class TreUtilityTest method testConvertToFloat.

@Test
public void testConvertToFloat() throws NitfFormatException, IOException {
    Tre tre = TreFactory.getDefault("TestTre", TreSource.ImageExtendedSubheaderData);
    tre.add(new TreEntryImpl("FLOAT_VALID_1", "+123.456e2", "float"));
    tre.add(new TreEntryImpl("FLOAT_VALID_2", "-123", "float"));
    tre.add(new TreEntryImpl("FLOAT_VALID_3", "0x1FFF.0p0", "float"));
    tre.add(new TreEntryImpl("FLOAT_VALID_4", "0009.9000", "float"));
    tre.add(new TreEntryImpl("FLOAT_VALID_5", "-0009.9000", "float"));
    tre.add(new TreEntryImpl("FLOAT_INVALID_1", "0D2310", "float"));
    tre.add(new TreEntryImpl("FLOAT_INVALID_2", "-0w.D3", "float"));
    tre.add(new TreEntryImpl("FLOAT_INVALID_3", "-+0x1FFF.0p0", "float"));
    tre.add(new TreEntryImpl("FLOAT_INVALID_4", "12367.0x0FF", "float"));
    tre.add(new TreEntryImpl("FLOAT_INVALID_5", "1,0", "float"));
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_VALID_1"), is(12345.6f));
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_VALID_2"), is(-123.0f));
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_VALID_3"), is(8191.0f));
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_VALID_4"), is(9.9f));
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_VALID_5"), is(-9.9f));
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_INVALID_1"), nullValue());
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_INVALID_2"), nullValue());
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_INVALID_3"), nullValue());
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_INVALID_4"), nullValue());
    assertThat(TreUtility.convertToFloat(tre, "FLOAT_INVALID_5"), nullValue());
}
Also used : Tre(org.codice.imaging.nitf.core.tre.Tre) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl) Test(org.junit.Test)

Example 9 with Tre

use of org.codice.imaging.nitf.core.tre.Tre in project alliance by codice.

the class TreUtilityTest method createMtirpbTre.

public static Tre createMtirpbTre() throws NitfFormatException {
    final String[] fieldNames = { "MTI_DP", "MTI_PACKET_ID", "PATCH_NO", "WAMTI_FRAME_NO", "WAMTI_BAR_NO", "DATIME", "ACFT_LOC", "ACFT_ALT", "ACFT_ALT_UNIT", "ACFT_HEADING", "MTI_LR", "SQUINT_ANGLE", "COSGRZ", "NO_VALID_TARGETS" };
    final String[] values = { "00", "001", "0001", "00001", "1", "20141108235219", "+52.123456-004.123456", "150000", "m", "000", " ", "      ", "0.03111", "001" };
    StringBuilder accumulator = new StringBuilder();
    Tre tre = mock(Tre.class);
    when(tre.getName()).thenReturn("MTIRPB");
    for (int i = 0; i < fieldNames.length; i++) {
        accumulator.append(values[i]);
        when(tre.getEntry(fieldNames[i])).thenReturn(new TreEntryImpl(fieldNames[i], values[i], "string"));
    }
    TreGroup targetsGroup = createTreGroup(accumulator);
    TreEntryImpl targetsEntry = new TreEntryImpl("TARGETS");
    targetsEntry.addGroup(targetsGroup);
    when(tre.getEntry("TARGETS")).thenReturn(targetsEntry);
    when(tre.getSource()).thenReturn(TreSource.UserDefinedHeaderData);
    when(tre.getRawData()).thenReturn(accumulator.toString().getBytes());
    return tre;
}
Also used : Tre(org.codice.imaging.nitf.core.tre.Tre) TreGroup(org.codice.imaging.nitf.core.tre.TreGroup) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)

Example 10 with Tre

use of org.codice.imaging.nitf.core.tre.Tre in project alliance by codice.

the class TreUtilityTest method testConvertToInteger.

@Test
public void testConvertToInteger() throws NitfFormatException, IOException {
    Tre tre = TreFactory.getDefault("TestTre", TreSource.ImageExtendedSubheaderData);
    tre.add(new TreEntryImpl("INTEGER_VALID_1", "12345", "UINT"));
    tre.add(new TreEntryImpl("INTEGER_VALID_2", "-12345", "UINT"));
    tre.add(new TreEntryImpl("INTEGER_VALID_3", "-0120", "UINT"));
    tre.add(new TreEntryImpl("INTEGER_INVALID_1", "1.2", "UINT"));
    tre.add(new TreEntryImpl("INTEGER_INVALID_2", "-1.3-9", "UINT"));
    tre.add(new TreEntryImpl("INTEGER_INVALID_3", "ABCD", "UINT"));
    assertThat(TreUtility.convertToInteger(tre, "INTEGER_VALID_1"), is(12345));
    assertThat(TreUtility.convertToInteger(tre, "INTEGER_VALID_2"), is(-12345));
    assertThat(TreUtility.convertToInteger(tre, "INTEGER_VALID_3"), is(-120));
    assertThat(TreUtility.convertToInteger(tre, "INTEGER_INVALID_1"), nullValue());
    assertThat(TreUtility.convertToInteger(tre, "INTEGER_INVALID_2"), nullValue());
    assertThat(TreUtility.convertToInteger(tre, "INTEGER_INVALID_3"), nullValue());
}
Also used : Tre(org.codice.imaging.nitf.core.tre.Tre) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl) Test(org.junit.Test)

Aggregations

Tre (org.codice.imaging.nitf.core.tre.Tre)14 TreEntryImpl (org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)11 NitfCreationFlowImpl (org.codice.imaging.nitf.fluent.impl.NitfCreationFlowImpl)7 TreUtilityTest.createImageSegment (org.codice.alliance.transformer.nitf.TreUtilityTest.createImageSegment)6 ImageSegment (org.codice.imaging.nitf.core.image.ImageSegment)6 NitfHeader (org.codice.imaging.nitf.core.header.NitfHeader)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 NitfAttribute (org.codice.alliance.transformer.nitf.common.NitfAttribute)3 TreGroup (org.codice.imaging.nitf.core.tre.TreGroup)2 BufferedImage (java.awt.image.BufferedImage)1 TreUtilityTest (org.codice.alliance.transformer.nitf.TreUtilityTest)1 TreCollection (org.codice.imaging.nitf.core.tre.TreCollection)1