home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / graphics / explorer / 145 < prev    next >
Encoding:
Text File  |  1992-08-13  |  5.4 KB  |  156 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!mips!odin!texas.asd.sgi.com!robert
  2. From: robert@texas.asd.sgi.com (Robert Skinner)
  3. Newsgroups: comp.graphics.explorer
  4. Subject: Re: PseudocolorImg
  5. Message-ID: <1992Aug13.230141.3977@odin.corp.sgi.com>
  6. Date: 13 Aug 92 23:01:41 GMT
  7. References: <1992Jul23.030121.22502@qdpii.comp.qdpi.oz.au>
  8. Sender: news@odin.corp.sgi.com (Net News)
  9. Reply-To: robert@sgi.com
  10. Organization: Silicon Graphics Inc., Advanced Systems Division
  11. Lines: 142
  12. Nntp-Posting-Host: texas.asd.sgi.com
  13.  
  14. In article <1992Jul23.030121.22502@qdpii.comp.qdpi.oz.au>, dres@qdpii.comp.qdpi.oz.au (Drought Research Account) writes:
  15. |> Recently I pulled SGI's PseudocolorImg module off the edinburgh ftp site.
  16. |> It works fine on byte lattices, but doesn't seem to cope with other
  17. |> primitive data types. If it really only wants byte data, it should have
  18. |> its input port so configured, invoking the automatic type coercion. If
  19. |> not, what else does it need to work with other data types ? Any clues 
  20. |> anyone  (especially SGI) ? I checked the mres file, and it is currently set
  21. |> to allow any primitive data type.
  22. |> 
  23.  
  24. PseudocolorImg didn't properly scale float and double outputs.
  25. Here is the updated code:
  26.  
  27.  
  28. #include <malloc.h>
  29.  
  30. #include <cx/DataTypes.h>
  31. #include <cx/DataAccess.h>
  32. #include <cx/Lookup.h>
  33.  
  34. void pseudo(cxLattice *inLat, cxLattice *cMap, cxLattice **outLat)
  35. {
  36.     long nDim, *dims, hasData, hasCoord, nCoordVar, nDataVar;
  37.     long newDataVar, number,i, size, j;
  38.     cxPrimType primType;
  39.     cxCoordType coordType;
  40.     cxCoord *coordStruct;
  41.     cxLookup *clut;
  42.     float color_array[4], data, *ivec, *cptr;
  43.     void *oldDataVals;
  44.     void *newDataVals;
  45.     unsigned char *uc_data, *cc_data;
  46.     short *sc_data, hi_val, lo_val, tot_vals;
  47.  
  48.     cxLatDescGet(inLat,&nDim, &dims, &hasData, &nDataVar, &primType,
  49.      &hasCoord, &nCoordVar, &coordType);
  50.  
  51.     newDataVar = 3;
  52.     size = 4;
  53.     *outLat = cxLatDataNew(nDim, dims, newDataVar, cx_prim_byte);
  54.     cxLatPtrGet(inLat, NULL, &oldDataVals, &coordStruct, NULL);
  55.     cxLatPtrSet(*outLat, NULL, NULL, coordStruct, NULL);
  56.     cxLatPtrGet(*outLat,NULL,&newDataVals,NULL,NULL);
  57.     uc_data = newDataVals;
  58.     cc_data = oldDataVals;
  59.     sc_data = oldDataVals;
  60.     clut = cxLookupCreate(cMap,0);
  61.     number = cxDimsProd(nDim, dims, nDataVar);
  62.     switch (primType){
  63.         case cx_prim_byte:
  64.           cptr = (float *)malloc(4*256*sizeof(float));
  65.           ivec = (float *)malloc(256*sizeof(float));
  66.           for(i=0;i<256;i++){
  67.            ivec[i] = i;
  68.           }
  69.           cxLookupInterpV(clut,256,ivec,cptr);
  70.           free(ivec);
  71.           for(i=0;i<number;i++)
  72.              for(j=0;j<newDataVar;j++){
  73.              uc_data[i*newDataVar+j] = cptr[cc_data[i]*4 + j] * 255.;
  74.              }
  75.           free(cptr);
  76.           break;
  77.         case cx_prim_short:
  78.           cxLatPtrGet(cMap,NULL,NULL,NULL,&cptr);
  79.           lo_val = cptr[0];
  80.           hi_val = cptr[1];
  81.           tot_vals = hi_val-lo_val+1;
  82.           cptr = (float *)malloc(4*tot_vals*sizeof(float));
  83.           ivec = (float *)malloc(tot_vals*sizeof(float));
  84.           for(i=0; i< tot_vals; i++)
  85.           ivec[i] = lo_val + i;
  86.           cxLookupInterpV(clut,tot_vals,ivec,cptr);
  87.           free(ivec);
  88.           for(i=0;i<number;i++)
  89.           if(sc_data[i] <= lo_val){
  90.             uc_data[i*newDataVar  ] = cptr[0]*255;
  91.             uc_data[i*newDataVar+1] = cptr[1]*255;
  92.             uc_data[i*newDataVar+2] = cptr[2]*255;
  93.             uc_data[i*newDataVar+3] = cptr[3]*255;
  94.           }else if(sc_data[i] >= hi_val){
  95.             uc_data[i*newDataVar  ] = cptr[4*tot_vals  ]*255;
  96.             uc_data[i*newDataVar+1] = cptr[4*tot_vals+1]*255;
  97.             uc_data[i*newDataVar+2] = cptr[4*tot_vals+2]*255;
  98.             uc_data[i*newDataVar+3] = cptr[4*tot_vals+3]*255;
  99.           }else{
  100.                   for(j=0;j<newDataVar;j++)
  101.                      uc_data[i*newDataVar+j] = cptr[(sc_data[i]-lo_val)*4 + j] * 255.;
  102.              }
  103.           free(cptr);
  104.           break;
  105.      case cx_prim_long:
  106.             for(i=0; i<number;i++){
  107.           data = ((long *)oldDataVals)[i];
  108.           cxLookupInterp(clut, &data,color_array);
  109.           for(j=0;j<newDataVar;j++){
  110.            uc_data[i*newDataVar+j] = color_array[j] * 255.;
  111.           }
  112.         }
  113.         break;
  114.      case cx_prim_float:
  115.             for(i=0; i<number;i++){
  116.           data = ((float *)oldDataVals)[i];
  117.           cxLookupInterp(clut, &data,color_array);
  118.           for(j=0;j<newDataVar;j++){
  119.            uc_data[i*newDataVar+j] = color_array[j] * 255.;
  120.           }
  121.         }
  122.         break;
  123.      case cx_prim_double:
  124.             for(i=0; i<number;i++){
  125.           data = ((double *)oldDataVals)[i];
  126.           cxLookupInterp(clut, &data,color_array);
  127.           for(j=0;j<newDataVar;j++){
  128.            uc_data[i*newDataVar+j] = color_array[j] * 255.;
  129.           }
  130.         }
  131.         break;
  132.     }
  133.     cxLookupDestroy(clut);
  134. }
  135.  
  136. -- 
  137.  
  138. Robert Skinner
  139. robert@sgi.com
  140.  
  141.     "I don't know about you, but I've always assumed that the TV
  142. ratings were based on the viewing habits of people who could easily
  143. fit their cerebral cortices inside a standard cold capsule.  I based
  144. this opinion on such evidence as the extreme popularity of the show
  145. "Wheel of Fortune".  Every time I tune it in, there's a contestant
  146. frowning with intense concentration at a group of letters like
  147. "H-A-P-P-Y B-I-R-T-H-D-A-(blank),"  then guessing that the missing
  148. letter is: "W."  Then the lovely Miss Vanna White, displaying the
  149. poise and talent that have made her one of the most respected, if not
  150. THE most respected, bimbos in the Free World, turns over the blank to
  151. reveal -- oh, no! -- a Y, causing the live studio audience to react
  152. with an outpouring of grief of the type normally associated with the
  153. loss of a popular family member."
  154.  
  155.                 Dave Barry
  156.