Changeset 15996
- Timestamp:
- Jan 4, 2008, 2:06:49 AM (18 years ago)
- Location:
- branches/eam_branch_20071222/Ohana/src/kapa2
- Files:
-
- 3 added
- 8 edited
-
Makefile (modified) (1 diff)
-
include/constants.h (modified) (3 diffs)
-
include/prototypes.h (modified) (2 diffs)
-
include/structures.h (modified) (1 diff)
-
src/ButtonFunctions.c (modified) (1 diff)
-
src/ColorCube.c (added)
-
src/ColorHistogram.c (added)
-
src/SetColorScale.c (modified) (6 diffs)
-
src/SetColormap.c (modified) (2 diffs)
-
src/sort.c (added)
-
test/input (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20071222/Ohana/src/kapa2/Makefile
r15935 r15996 78 78 $(SRC)/PSimage.$(ARCH).o $(SRC)/PSPixmap.$(ARCH).o \ 79 79 $(SRC)/PSOverlay.$(ARCH).o $(SRC)/SetChannel.$(ARCH).o \ 80 $(SRC)/SetColorScale.$(ARCH).o 80 $(SRC)/SetColorScale.$(ARCH).o $(SRC)/ColorCube.$(ARCH).o \ 81 $(SRC)/ColorHistogram.$(ARCH).o $(SRC)/sort.$(ARCH).o 81 82 82 83 OBJ = $(KAPA) -
branches/eam_branch_20071222/Ohana/src/kapa2/include/constants.h
r15935 r15996 12 12 # define NCHANNELS 3 13 13 # define NPIXELS_DYNAMIC 128 14 # define NPIXELS_STATIC 1024 14 15 // XXX for the moment, this is set to match the values in SetColorScale3D_CC 16 # define NPIXELS_STATIC 3000 15 17 16 18 # define PAD1 3 … … 33 35 typedef enum { 34 36 KAPA_SCALE_1D, 35 KAPA_SCALE_3D 37 KAPA_SCALE_3D_RUFF, 38 KAPA_SCALE_3D_FULL 36 39 } KapaColorScaleMode; 37 40 … … 47 50 LABELLR 48 51 } KapaLabelMode; 52 53 typedef enum { 54 KAPA_CHANNEL_RED, 55 KAPA_CHANNEL_GREEN, 56 KAPA_CHANNEL_BLUE, 57 } KapaChannels; 58 59 // use an enum to identify the 3 dimensions: 60 typedef enum { 61 CC_X, 62 CC_Y, 63 CC_Z, 64 } CCDimen; 49 65 50 66 /* EVENT_MASK consists of: -
branches/eam_branch_20071222/Ohana/src/kapa2/include/prototypes.h
r15935 r15996 142 142 void SetColorScale PROTO((Graphic *graphic, KapaImageWidget *image)); 143 143 void SetColorScale1D PROTO((Graphic *graphic, KapaImageWidget *image)); 144 voidSetColorScale3D PROTO((Graphic *graphic, KapaImageWidget *image));144 int SetColorScale3D PROTO((Graphic *graphic, KapaImageWidget *image)); 145 145 void Remap PROTO((Graphic *graphic, KapaImageWidget *image)); 146 146 void Remap8 PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix)); … … 223 223 void InvertButton (Graphic *graphic, Button *button); 224 224 void bDrawOverlay (KapaImageWidget *image, int N); 225 226 /* color cube tools */ 227 CCNode *CCNodeAlloc (); 228 CCNode *CCFindChild (CCNode *node, float x, float y, float z); 229 int CCSplitNode (CCNode *node); 230 int CCSplitNodeIterate (CCNode *node, int current, int max); 231 void CCNodeFree (CCNode *node); 232 CCNode *CCFindBottom (CCNode *top, float x, float y, float z); 233 int CCNodeExtractCounts (CCNode *node, float **values, int *nvalues, int *NVALUES); 234 int CCNodeDivideLimit (CCNode *node, float minValue); 235 int CCNodeInitCounts (CCNode *node, float value); 236 237 /* 3D color histogram */ 238 void ColorHistogram (KapaImageWidget *image, CCNode *cube); 239 void CCNodeSetColorPixels (KapaImageWidget *image, CCNode *cube); 240 int CCNodeSetColorMap (CCNode *node, XColor *cmap, int Npixels, int *current); 241 242 int SetColorScale3D_CC (Graphic *graphic, KapaImageWidget *image); 243 244 void sort (float *value, int N); -
branches/eam_branch_20071222/Ohana/src/kapa2/include/structures.h
r15935 r15996 66 66 } TextBox; 67 67 68 /*** 3C color cube histogram tree thingy ***/ 69 typedef struct CCNode { 70 // for the moment, this structure is specific to the color-histogram analysis. if 71 // this were a void *pointer and we defined some additional apis, we could use this 72 // structure to track any 3D space 73 int count; 74 int pixel; 75 char bottom; 76 float min[3]; // min value for each of the 3 dimensions for this node 77 float mid[3]; // mid-point for each of the 3 dimensions for this node 78 float max[3]; // max value for each of the 3 dimensions for this node 79 struct CCNode *sub[2][2][2]; 80 } CCNode; 81 68 82 /**************** general structures ****************/ 69 83 typedef struct { -
branches/eam_branch_20071222/Ohana/src/kapa2/src/ButtonFunctions.c
r15935 r15996 29 29 char *name; 30 30 name = HEAT; 31 SetColormap ( name);31 SetColormap ("ruffcolor"); 32 32 CreateColorbar (image, graphic); 33 33 SetColorScale (graphic, image); -
branches/eam_branch_20071222/Ohana/src/kapa2/src/SetColorScale.c
r15935 r15996 7 7 SetColorScale1D (graphic, image); 8 8 break; 9 case KAPA_SCALE_3D: 10 SetColorScale3D (graphic, image); 9 case KAPA_SCALE_3D_RUFF: 10 // fall-back on 1D colors (ie, if images are mis-matched) 11 if (!SetColorScale3D (graphic, image)) { 12 graphic[0].ColorScaleMode = KAPA_SCALE_1D; 13 SetColorScale1D (graphic, image); 14 } 15 break; 16 case KAPA_SCALE_3D_FULL: 17 // fall-back on 1D colors (ie, if images are mis-matched) 18 if (!SetColorScale3D_CC (graphic, image)) { 19 graphic[0].ColorScaleMode = KAPA_SCALE_1D; 20 SetColorScale1D (graphic, image); 21 } 11 22 break; 12 23 default: … … 60 71 61 72 // in 3D we use channels 0,1,2 to choose the pixel from the cube 62 void SetColorScale3D (Graphic *graphic, KapaImageWidget *image) { 73 // XXX this uses a crude, uniform-spacing cube 74 int SetColorScale3D (Graphic *graphic, KapaImageWidget *image) { 63 75 int i, j, DX, DY, value, nPixels, rValue, gValue, bValue; 64 76 float *rData, *bData, *gData; … … 67 79 float redStart, blueStart, greenStart; 68 80 81 DX = image[0].channel[KAPA_CHANNEL_RED].matrix.Naxis[0]; 82 DY = image[0].channel[KAPA_CHANNEL_RED].matrix.Naxis[1]; 83 84 if (DX != image[0].channel[KAPA_CHANNEL_GREEN].matrix.Naxis[0]) return FALSE; 85 if (DY != image[0].channel[KAPA_CHANNEL_GREEN].matrix.Naxis[1]) return FALSE; 86 if (DX != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[0]) return FALSE; 87 if (DY != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[1]) return FALSE; 88 69 89 // define the color transform parameters 70 90 unsigned short maxRed = graphic[0].nRed - 1; … … 73 93 74 94 // set start & slope for red (channel 0) 75 if (image[0].channel[ 0].range != 0.0) {76 redSlope = graphic[0].nRed / image[0].channel[ 0].range;77 redStart = graphic[0].nRed * image[0].channel[ 0].zero / image[0].channel[0].range;95 if (image[0].channel[KAPA_CHANNEL_RED].range != 0.0) { 96 redSlope = graphic[0].nRed / image[0].channel[KAPA_CHANNEL_RED].range; 97 redStart = graphic[0].nRed * image[0].channel[KAPA_CHANNEL_RED].zero / image[0].channel[KAPA_CHANNEL_RED].range; 78 98 } else { 79 99 redSlope = 1.0; 80 redStart = image[0].channel[ 0].zero;100 redStart = image[0].channel[KAPA_CHANNEL_RED].zero; 81 101 } 82 102 // set start & slope for blue (channel 0) 83 if (image[0].channel[ 1].range != 0.0) {84 blueSlope = graphic[0].nBlue / image[0].channel[ 1].range;85 blueStart = graphic[0].nBlue * image[0].channel[ 1].zero / image[0].channel[1].range;103 if (image[0].channel[KAPA_CHANNEL_BLUE].range != 0.0) { 104 blueSlope = graphic[0].nBlue / image[0].channel[KAPA_CHANNEL_BLUE].range; 105 blueStart = graphic[0].nBlue * image[0].channel[KAPA_CHANNEL_BLUE].zero / image[0].channel[KAPA_CHANNEL_BLUE].range; 86 106 } else { 87 107 blueSlope = 1.0; 88 blueStart = image[0].channel[ 1].zero;108 blueStart = image[0].channel[KAPA_CHANNEL_BLUE].zero; 89 109 } 90 110 // set start & slope for green (channel 0) 91 if (image[0].channel[ 2].range != 0.0) {92 greenSlope = graphic[0].nGreen / image[0].channel[ 2].range;93 greenStart = graphic[0].nGreen * image[0].channel[ 2].zero / image[0].channel[2].range;111 if (image[0].channel[KAPA_CHANNEL_GREEN].range != 0.0) { 112 greenSlope = graphic[0].nGreen / image[0].channel[KAPA_CHANNEL_GREEN].range; 113 greenStart = graphic[0].nGreen * image[0].channel[KAPA_CHANNEL_GREEN].zero / image[0].channel[KAPA_CHANNEL_GREEN].range; 94 114 } else { 95 115 greenSlope = 1.0; 96 greenStart = image[0].channel[2].zero; 97 } 98 99 DX = image[0].channel[0].matrix.Naxis[0]; 100 DY = image[0].channel[0].matrix.Naxis[1]; 101 // check on equal size for channel[1] and channel[2] 116 greenStart = image[0].channel[KAPA_CHANNEL_GREEN].zero; 117 } 102 118 103 119 nPixels = DX*DY; … … 108 124 109 125 oData = image[0].pixmap; 110 rData = (float *) image[0].channel[ 0].matrix.buffer;111 bData = (float *) image[0].channel[ 1].matrix.buffer;112 gData = (float *) image[0].channel[ 2].matrix.buffer;126 rData = (float *) image[0].channel[KAPA_CHANNEL_RED].matrix.buffer; 127 bData = (float *) image[0].channel[KAPA_CHANNEL_BLUE].matrix.buffer; 128 gData = (float *) image[0].channel[KAPA_CHANNEL_GREEN].matrix.buffer; 113 129 114 130 // convert pixel data values to pixel index values (0 - Npixel) … … 128 144 *oData = gValue + bValue * (maxGreen + 1) + rValue * (maxGreen + 1) * (maxBlue + 1); 129 145 } 130 } 146 return TRUE; 147 } 148 149 // in 3D we use channels 0,1,2 to choose the pixel from the cube 150 int SetColorScale3D_CC (Graphic *graphic, KapaImageWidget *image) { 151 152 int i, DX, DY, Nvalues, NVALUES, Npixels, Nmin; 153 float *values, *colors; 154 CCNode *cube; 155 156 DX = image[0].channel[KAPA_CHANNEL_RED].matrix.Naxis[0]; 157 DY = image[0].channel[KAPA_CHANNEL_RED].matrix.Naxis[1]; 158 if (DX != image[0].channel[KAPA_CHANNEL_GREEN].matrix.Naxis[0]) return FALSE; 159 if (DY != image[0].channel[KAPA_CHANNEL_GREEN].matrix.Naxis[1]) return FALSE; 160 if (DX != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[0]) return FALSE; 161 if (DY != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[1]) return FALSE; 162 163 // create the top-level cube 164 cube = CCNodeAlloc(); 165 cube->min[CC_X] = cube->min[CC_Y] = cube->min[CC_Z] = 0.0; 166 cube->max[CC_X] = cube->max[CC_Y] = cube->max[CC_Z] = 1.0; 167 cube->mid[CC_X] = cube->mid[CC_Y] = cube->mid[CC_Z] = 0.5; 168 169 // subdivide cube into first, uniform division (4x4x4) 170 CCSplitNodeIterate (cube, 0, 2); 171 172 // need to allocate at least 1184 pixels 173 // 64, 288, 512, 736, 960, 1184 174 for (i = 0; i < 8; i++) { 175 // generate histogram 176 ColorHistogram (image, cube); 177 178 // extract histogram values 179 values = NULL; 180 Nvalues = 0; 181 NVALUES = 0; 182 CCNodeExtractCounts (cube, &values, &Nvalues, &NVALUES); 183 184 // select top N cells 185 sort (values, Nvalues); 186 187 // split nodes with more than value[n] 188 Nmin = MAX (0, Nvalues - 50); 189 CCNodeDivideLimit (cube, values[Nmin]); 190 free (values); 191 192 CCNodeInitCounts (cube, 0.0); 193 } 194 195 // generate histogram 196 ColorHistogram (image, cube); 197 198 // convert histogram 3D values to cmap colors 199 Npixels = 0; 200 CCNodeSetColorMap (cube, graphic[0].cmap, graphic[0].Npixels, &Npixels); 201 202 // store the colors 203 if (USE_XWINDOW) { 204 if (graphic[0].visualclass) { 205 XStoreColors(graphic[0].display, graphic[0].colormap, graphic[0].cmap, Npixels); 206 } else { 207 for (i = 0; i < Npixels; i++) { 208 if (XAllocColor (graphic[0].display, graphic[0].colormap, &graphic[0].cmap[i]) == 0) { 209 fprintf (stderr, "error on %d\n", i); 210 } 211 } 212 } 213 } 214 CCNodeSetColorPixels (image, cube); 215 return TRUE; 216 } 217 -
branches/eam_branch_20071222/Ohana/src/kapa2/src/SetColormap.c
r15935 r15996 19 19 graphic = GetGraphic(); 20 20 21 // the "fullcolor" colormap is uniquely defined for each image; 22 // defer to the 'SetColorScale' step 23 if (!strcasecmp (name, "fullcolor")) { 24 graphic[0].ColorScaleMode = KAPA_SCALE_3D_FULL; 25 return TRUE; 26 } 27 21 28 // very simple color model: evenly spaced cube 22 if (!strcasecmp (name, " fullcolor")) {29 if (!strcasecmp (name, "ruffcolor")) { 23 30 graphic[0].nRed = pow (graphic[0].Npixels, 0.333); 24 31 graphic[0].nBlue = pow (graphic[0].Npixels, 0.333); … … 43 50 44 51 // all other modes are 1D: set the flag: 45 graphic[0].ColorScaleMode = KAPA_SCALE_3D ;52 graphic[0].ColorScaleMode = KAPA_SCALE_3D_RUFF; 46 53 goto store_colors; 47 54 } -
branches/eam_branch_20071222/Ohana/src/kapa2/test/input
r15934 r15996 23 23 tv R 0 256 24 24 tvchannel 1 25 tv G 0 256 26 tvchannel 2 25 27 tv B 0 256 26 tvchannel 227 tv G 0 25628 28 end
Note:
See TracChangeset
for help on using the changeset viewer.
