| 980 | | // compute range of values |
| 981 | | FindRangeOperator rangeOp; |
| 982 | | for(int r=0;r<sizeR;++r) |
| 983 | | { |
| 984 | | for(int t=0;t<sizeT;++t) |
| 985 | | { |
| 986 | | readRow(sizeS, pixelFormat, dataType, image->data(0,t,r), rangeOp); |
| 987 | | } |
| 988 | | } |
| 989 | | |
| 990 | | // scale the values |
| 991 | | for(int r=0;r<sizeR;++r) |
| 992 | | { |
| 993 | | for(int t=0;t<sizeT;++t) |
| 994 | | { |
| 995 | | modifyRow(sizeS, pixelFormat, dataType, image->data(0,t,r), ScaleOperator(1.0f/rangeOp._rmax)); |
| 996 | | } |
| 997 | | } |
| 998 | | |
| | 980 | |
| | 981 | // normalise texture |
| | 982 | { |
| | 983 | // compute range of values |
| | 984 | FindRangeOperator rangeOp; |
| | 985 | for(int r=0;r<sizeR;++r) |
| | 986 | { |
| | 987 | for(int t=0;t<sizeT;++t) |
| | 988 | { |
| | 989 | readRow(sizeS, pixelFormat, dataType, image->data(0,t,r), rangeOp); |
| | 990 | } |
| | 991 | } |
| | 992 | |
| | 993 | // scale the values |
| | 994 | for(int r=0;r<sizeR;++r) |
| | 995 | { |
| | 996 | for(int t=0;t<sizeT;++t) |
| | 997 | { |
| | 998 | modifyRow(sizeS, pixelFormat, dataType, image->data(0,t,r), ScaleOperator(1.0f/rangeOp._rmax)); |
| | 999 | } |
| | 1000 | } |
| | 1001 | } |
| | 1002 | |
| | 1003 | |
| | 1009 | |
| | 1010 | osg::ref_ptr<osg::Image> new_image = new osg::Image; |
| | 1011 | new_image->allocateImage(sizeS, sizeT, sizeR, pixelFormat, GL_UNSIGNED_BYTE); |
| | 1012 | |
| | 1013 | RecordRowOperator readOp(sizeS); |
| | 1014 | WriteRowOperator writeOp; |
| | 1015 | |
| | 1016 | for(int r=0;r<sizeR;++r) |
| | 1017 | { |
| | 1018 | for(int t=0;t<sizeT;++t) |
| | 1019 | { |
| | 1020 | // reset the indices to begining |
| | 1021 | readOp._pos = 0; |
| | 1022 | writeOp._pos = 0; |
| | 1023 | |
| | 1024 | // read the pixels into readOp's _colour array |
| | 1025 | readRow(sizeS, pixelFormat, dataType, image->data(0,t,r), readOp); |
| | 1026 | |
| | 1027 | // pass readOp's _colour array contents over to writeOp (note this is just a pointer swap). |
| | 1028 | writeOp._colours.swap(readOp._colours); |
| | 1029 | |
| | 1030 | modifyRow(sizeS, pixelFormat, GL_UNSIGNED_BYTE, new_image->data(0,t,r), writeOp); |
| | 1031 | |
| | 1032 | // return readOp's _colour array contents back to its rightful owner. |
| | 1033 | writeOp._colours.swap(readOp._colours); |
| | 1034 | } |
| | 1035 | } |
| | 1036 | |
| | 1037 | image = new_image; |