IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 29, 2004, 10:17:58 AM (22 years ago)
Author:
desonia
Message:

changes associated with the testing of psImageSubsection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/image/tst_psImageExtraction.c

    r1924 r1929  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2004-09-29 01:10:27 $
     8*  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2004-09-29 20:17:58 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1212*/
    1313#include<stdlib.h>
     14#include<string.h>
    1415
    1516#include "psTest.h"
     
    1718#include "psType.h"
    1819
    19 static int testImageSlice( void );
     20static int testImageSlice(void);
     21static int testImageSubset(void);
     22static int testImageSubsection(void);
    2023
    2124testDescription tests[] = {
     25                              {testImageSubset,547,"psImageSubset",0,false},
     26                              {testImageSubset,550,"psImageSubset",0,true},
     27                              {testImageSubsection,730,"psImageSubsection",0,true},
    2228                              {testImageSlice, 552, "psImageSlice", 0, false},
    2329                              {NULL}
     
    2935}
    3036
    31 int testImageSlice( void )
     37int testImageSlice(void)
    3238{
    3339    const int r = 1000;
     
    286292}
    287293
     294// #547: psImageSubset shall create child image of a specified size from a parent psImage structure
     295int testImageSubset(void)
     296{
     297    psImage preSubsetStruct;
     298    psImage* original;
     299    psImage* subset1 = NULL;
     300    psImage* subset2 = NULL;
     301    psImage* subset3 = NULL;
     302    int c = 128;
     303    int r = 256;
     304
     305    original = psImageAlloc(c,r,PS_TYPE_U32);
     306    for (int row=0;row<r;row++) {
     307        for (int col=0;col<c;col++) {
     308            original->data.F32[row][col] = row*1000+col;
     309        }
     310    }
     311
     312    memcpy(&preSubsetStruct,original,sizeof(psImage));
     313
     314    subset2 = psImageSubset(original,c/4,r/4,c/4+c/2,r/4+r/2);
     315
     316    subset3 = psImageSubset(original,0,0,c/2,r/2);
     317
     318    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure members nrow and ncol are equal to "
     319             "the input parameter nrow and ncol respectively.");
     320
     321    if (subset2->numCols != c/2 || subset2->numRows != r/2) {
     322        psError(__func__,"psImageSubset output size was not proper(%dx%d, should be %dx%d).",
     323                subset2->numCols, subset2->numRows, c/2,r/2);
     324        return 1;
     325    }
     326
     327    if (subset3->numCols != c/2 || subset3->numRows != r/2) {
     328        psError(__func__,"psImageSubset output size was not proper(%dx%d, should be %dx%d).",
     329                subset3->numCols, subset3->numRows, c/2,r/2);
     330        return 2;
     331    }
     332
     333    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure contains expected values in the "
     334             "row member, if the input psImage structure image contains known values.");
     335
     336    for (int row=0;row<r/2;row++) {
     337        for (int col=0;col<c/2;col++) {
     338            if (subset2->data.U32[row][col] != original->data.U32[row+r/4][col+c/4]) {
     339                psError(__func__,"psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
     340                        row,col,subset2->data.U32[row][col], original->data.U32[row+r/4][col+c/4]);
     341                return 3;
     342            }
     343            if (subset3->data.U32[row][col] != original->data.U32[row][col]) {
     344                psError(__func__,"psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
     345                        row,col,subset2->data.U32[row][col], original->data.U32[row][col]);
     346                return 4;
     347            }
     348        }
     349    }
     350
     351    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member type is equal to the input "
     352             "psImage structure member type.");
     353
     354    if (subset2->type.type != PS_TYPE_U32) {
     355        psError(__func__,"psImageSubset output type was not proper(%d, should be %d).",
     356                subset2->type.type, PS_TYPE_U32);
     357        return 6;
     358    }
     359    if (subset3->type.type != PS_TYPE_U32) {
     360        psError(__func__,"psImageSubset output type was not proper(%d, should be %d).",
     361                subset3->type.type, PS_TYPE_U32);
     362        return 7;
     363    }
     364
     365    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure members row0 and col0 are equal to "
     366             "the input parameters row0 and col0 respectively.");
     367
     368    if (subset2->col0 != c/4 || subset2->row0 != r/4) {
     369        psError(__func__,"psImageSubset didn't set col0/row0 for subset2 (%d/%d, should be %d/%d).",
     370                subset2->col0,subset2->row0,c/4,r/4);
     371        return 8;
     372    }
     373    if (subset3->col0 != 0 || subset3->row0 != 0) {
     374        psError(__func__,"psImageSubset didn't set col0/row0 for subset3 (%d/%d, should be %d/%d).",
     375                subset3->col0,subset3->row0,0,0);
     376        return 9;
     377    }
     378
     379    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member parent is equal to the "
     380             "input psImage structure pointer image.");
     381
     382    if (subset2->parent != original || subset3->parent != original) {
     383        psError(__func__,"psImageSubset didn't set parent.");
     384        return 10;
     385    }
     386
     387    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member children is null.");
     388
     389    if (subset2->children != NULL || subset3->children != NULL) {
     390        psError(__func__,"psImageSubset didn't set children to NULL.");
     391        return 11;
     392    }
     393
     394    psLogMsg(__func__,PS_LOG_INFO,"Verify the input psImage structure image only has the following members "
     395             "changed: 1) Nchildren is increased by one. 2) parent contains pointer psImage structure "
     396             "out at parent[Nchildren-1].");
     397
     398    if (original->children == NULL || original->children->n != 2) {
     399        psError(__func__,"psImageSubset didn't increment number of children by one per subset.");
     400        return 12;
     401    }
     402    if (original->children->data[0] != subset2 || original->children->data[1] != subset3) {
     403        psError(__func__,"psImageSubset didn't properly store the children pointers.");
     404        return 13;
     405    }
     406
     407    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
     408             "execution doesn't stop, if the input parameter image is null. Also verified the input "
     409             "psImage structure is not modified.");
     410
     411    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     412    subset1 = psImageSubset(NULL,0,0,c/2,r/2);
     413    if (subset1 != NULL) {
     414        psError(__func__,"psImageSubset didn't return NULL when input image was NULL.");
     415        return 14;
     416    }
     417
     418    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
     419             " execution doesn't stop, if the input parameters nrow and/or ncol are zero. Also verify "
     420             "input psImage structure is not modified.");
     421
     422    memcpy(&preSubsetStruct,original,sizeof(psImage));
     423    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     424    subset1 = psImageSubset(original,0,r/2,c/2,r/2);
     425    if (subset1 != NULL) {
     426        psError(__func__,"psImageSubset didn't return NULL when numRows=0.");
     427        return 15;
     428    }
     429    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     430    subset1 = psImageSubset(original,c/2,0,c/2,r/2);
     431    if (subset1 != NULL) {
     432        psError(__func__,"psImageSubset didn't return NULL when numCols=0.");
     433        return 16;
     434    }
     435    if (memcmp(original,&preSubsetStruct,sizeof(psImage)) != 0) {
     436        psError(__func__,"psImageSubset changed the original struct though it failed to subset.");
     437        return 17;
     438    }
     439
     440
     441    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
     442             "execution doesn't stop, if the input parameters row0 and col0 are not within the range of "
     443             "values of psImage structure image.");
     444
     445    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     446    subset1 = psImageSubset(original,0,0,c/2,r*2);
     447    if (subset1 != NULL) {
     448        psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
     449                "image (via cols).");
     450        return 18;
     451    }
     452    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     453    subset1 = psImageSubset(original,0,0,c*2,r/2);
     454    if (subset1 != NULL) {
     455        psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
     456                "image (via rows).");
     457        return 19;
     458    }
     459    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     460    subset1 = psImageSubset(original,-1,0,c/2,r/2);
     461    if (subset1 != NULL) {
     462        psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
     463                "image (col0=-1).");
     464        return 20;
     465    }
     466    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     467    subset1 = psImageSubset(original,0,-1,c/2,r/2);
     468    if (subset1 != NULL) {
     469        psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
     470                "image (row0=-1).");
     471        return 21;
     472    }
     473
     474    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
     475             "execution doesn't stop if the input parameters nrow, ncol, row0 and col0 specify a range of "
     476             "data not within the input psImage structure image.  Also verify the input psImage structure "
     477             "is not modified.");
     478
     479    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     480    subset1 = psImageSubset(original,0,0,c/2,r+1);
     481    if (subset1 != NULL) {
     482        psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via rows).");
     483        return 22;
     484    }
     485    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     486    subset1 = psImageSubset(original,0,0,c+1,r/2);
     487    if (subset1 != NULL) {
     488        psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via cols).");
     489        return 23;
     490    }
     491    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     492    subset1 = psImageSubset(original,0,0,c+1,r+1);
     493    if (subset1 != NULL) {
     494        psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via row+cols).");
     495        return 24;
     496    }
     497
     498    psLogMsg(__func__, PS_LOG_INFO, "psImageFreeChildren shall deallocate any children images of a "
     499             "psImage structure");
     500
     501    memcpy(&preSubsetStruct,original,sizeof(psImage));
     502
     503    psImageFreeChildren(original);
     504
     505    // Verify the returned psImage structure member Nchildren is set to zero.
     506    if (original->children != NULL && original->children->n > 0) {
     507        psError(__func__,"psImageFreeChildren didn't set number of children to zero.");
     508        return 25;
     509    }
     510
     511    //Verify the returned psImage structure members type, nrow, ncol, row0, col0, rows and parent are not
     512    // modified.
     513    if (preSubsetStruct.numRows != original->numRows ||
     514            preSubsetStruct.numCols != original->numCols ||
     515            preSubsetStruct.row0 != original->row0 ||
     516            preSubsetStruct.col0 != original->col0) {
     517
     518        psError(__func__,"psImageFreeChildren modified parent's non-children elements.");
     519        return 27;
     520    }
     521
     522    psFree(original);
     523
     524    return 0;
     525}
     526
     527// #547: psImageSubset shall create child image of a specified size from a parent psImage structure
     528int testImageSubsection(void)
     529{
     530    psImage* original;
     531    psImage* subset;
     532    int c = 128;
     533    int r = 256;
     534    int i;
     535    int numRegions = 4;
     536    int x1[] = {  0, 32, 64, 32};
     537    int x2[] = { 32, 64,127, 64};
     538    int y1[] = {  0, 32, 32,128};
     539    int y2[] = { 32, 64, 64,255};
     540
     541    original = psImageAlloc(c,r,PS_TYPE_U32);
     542    for (int row=0;row<r;row++) {
     543        for (int col=0;col<c;col++) {
     544            original->data.F32[row][col] = row*1000+col;
     545        }
     546    }
     547
     548    for (i=0; i<numRegions; i++) {
     549        char sectionStr[64];
     550        sprintf(sectionStr,"[%d:%d,%d:%d]",x1[i],x2[i],y1[i],y2[i]);
     551
     552        psLogMsg(__func__,PS_LOG_INFO,"Testing subsection %s.",
     553                 sectionStr);
     554
     555        subset = psImageSubsection(original,sectionStr);
     556
     557        if (subset == NULL) {
     558            psError(__func__,"psImageSubsection returned a NULL with a subset of %s.",
     559                    sectionStr);
     560            return 10*i+1;
     561        }
     562
     563        if (subset->type.type != PS_TYPE_U32) {
     564            psError(__func__,"psImageSubsection output type was not proper(%d, should be %d).",
     565                    subset->type.type, PS_TYPE_U32);
     566            return 10*i+2;
     567        }
     568
     569        if (subset->col0 != x1[i] || subset->row0 != y1[i]) {
     570            psError(__func__,"psImageSubsection didn't set properly col0/row0 (%d/%d, should be %d/%d).",
     571                    subset->col0,subset->row0,x1[i],y1[i]);
     572            return 10*i+3;
     573        }
     574
     575        if (subset->parent != original) {
     576            psError(__func__,"psImageSubsection didn't set parent.");
     577            return 10*i+4;
     578        }
     579
     580        if (subset->children != NULL) {
     581            psError(__func__,"psImageSubsection didn't set children to NULL.");
     582            return 10*i+5;
     583        }
     584
     585        if (original->children == NULL || original->children->n != i+1) {
     586            psError(__func__,"psImageSubsection didn't increment number of children by one per subset.");
     587            return 10*i+6;
     588        }
     589
     590
     591        if (original->children->data[i] != subset) {
     592            psError(__func__,"psImageSubsection didn't properly store the children pointer.");
     593            return 10*i+7;
     594        }
     595
     596        int numCols = x2[i]-x1[i]+1;
     597        int numRows = y2[i]-y1[i]+1;
     598        if (subset->numCols != numCols || subset->numRows != numRows) {
     599            psError(__func__,"psImageSubsection output size was not proper(%dx%d, should be %dx%d).",
     600                    subset->numCols, subset->numRows, numCols, numRows);
     601            return 10*i+8;
     602        }
     603
     604        for (int row=0;row<numRows;row++) {
     605            for (int col=0;col<numCols;col++) {
     606                if (subset->data.U32[row][col] != original->data.U32[row+y1[i]][col+x1[i]]) {
     607                    psError(__func__,"psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
     608                            row,col,subset->data.U32[row][col], original->data.U32[row+y1[i]][col+x1[i]]);
     609                    return 10*i+9;
     610                }
     611            }
     612        }
     613    }
     614
     615    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (x1>x2)");
     616    subset = psImageSubsection(original,"[64:32,32:64]");
     617    if (subset != NULL) {
     618        psError(__func__,"psImageSubsection didn't return NULL when x1 > x2.");
     619        return 10*i+10;
     620    }
     621
     622    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (y1>y2)");
     623    subset = psImageSubsection(original,"[32:64,64:32]");
     624    if (subset != NULL) {
     625        psError(__func__,"psImageSubsection didn't return NULL when y1 > y2.");
     626        return 10*i+11;
     627    }
     628
     629    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (x2>nCols)");
     630    subset = psImageSubsection(original,"[64:256,32:64]"); // assumes c<256
     631    if (subset != NULL) {
     632        psError(__func__,"psImageSubsection didn't return NULL when x2 > c.");
     633        return 10*i+12;
     634    }
     635
     636    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (y2>=nRows)");
     637    subset = psImageSubsection(original,"[32:64,64:256]"); // assumes r==256
     638    if (subset != NULL) {
     639        psError(__func__,"psImageSubsection didn't return NULL when y2 > r.");
     640        return 10*i+13;
     641    }
     642
     643    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (malformed string - no brackets)");
     644    subset = psImageSubsection(original,"32:64,32:64");
     645    if (subset != NULL) {
     646        psError(__func__,"psImageSubsection didn't return NULL when subsection was '32:64,32:64'.");
     647        return 10*i+14;
     648    }
     649
     650    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (malformed string - no colons)");
     651    subset = psImageSubsection(original,"[32-64,32-64]");
     652    if (subset != NULL) {
     653        psError(__func__,"psImageSubsection didn't return NULL when subsection was '[32-64,32-64]'.");
     654        return 10*i+15;
     655    }
     656
     657    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (malformed string - not four numbers)");
     658    subset = psImageSubsection(original,"[32:64,32]");
     659    if (subset != NULL) {
     660        psError(__func__,"psImageSubsection didn't return NULL when subsection was '[32:64,32]'.");
     661        return 10*i+16;
     662    }
     663
     664    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (image is NULL)");
     665    subset = psImageSubsection(NULL,"[32:64,32:64]");
     666    if (subset != NULL) {
     667        psError(__func__,"psImageSubsection didn't return NULL when image was NULL.");
     668        return 10*i+17;
     669    }
     670
     671    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (subsection string is NULL)");
     672    subset = psImageSubsection(original,NULL);
     673    if (subset != NULL) {
     674        psError(__func__,"psImageSubsection didn't return NULL when subsection was NULL.");
     675        return 10*i+18;
     676    }
     677
     678    psFree(original);
     679
     680    return 0;
     681}
Note: See TracChangeset for help on using the changeset viewer.