// // Programmer: Craig Stuart Sapp // Creation Date: Thu Mar 24 16:40:42 PST 2005 // Last Modified: Thu Mar 24 16:40:44 PST 2005 // Filename: ...sig/examples/all/irangeplot.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/irangeplot.cpp // Syntax: C++; museinfo // // Description: Plot data generated by the irange program. // #include "humdrum.h" #define MAX_CODES 3 // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void storeData (HumdrumRecord& aRecord, int index, Array >& rdata); void printData (HumdrumFile& infile, Array >& rdata); void generateAnalysis (HumdrumFile& infile, Array >& rdata); void analyzeLevel (Array >& codecount, Array >& rdata, int level); void printRow (Array >& codecount); void plotData (Array >& rdata); // global variables Options options; // database for command-line arguments int debugQ = 0; // used with the --debug option int activityQ = 0; // used with the -a option int localQ = 0; // used with the -l option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; // process the command-line options checkOptions(options, argc, argv); // figure out the number of input files to process int numinputs = options.getArgCount(); Array values; values.setSize(0); Array > rdata; for (int i=0; i >& rdata) { // print header cout << "P3\n"; int rows = rdata.getSize(); int cols = rdata.getSize(); cout << rows << " " << cols << "\n"; cout << "255\n"; Array > codecount(MAX_CODES); int i; for (i=0; i=0; i--) { analyzeLevel(codecount, rdata, i); printRow(codecount); } } ////////////////////////////// // // printRow -- // void printRow(Array >& codecount) { int i; int j; for (i=0; i >& codecount, Array >& rdata, int level) { int i; int j; int k; for (i=0; i= rdata.getSize()) { break; } for (j=0; j < level + 1; j++) { for (k=0; k= 0) && (rdata[i+j][k] < MAX_CODES)) { codecount [rdata[i+j][k]] [i] += 1.0; } } } } Array max(rdata.getSize()); max.setAll(0.0); double globalmax = 0.0; Array colormax(3); colormax.setAll(0.0); for (i=0; i colormax[i]) { colormax[i] = codecount[i][j]; } if (codecount[i][j] > max[j]) { max[j] = codecount[i][j]; } if (codecount[i][j] > globalmax) { globalmax = codecount[i][j]; } } } if (globalmax <= 0.0) { return; } if (activityQ) { // nomalize one row of pixels according to the maximum // count of all range values on a level. // normalize the codecount data for (i=0; i 0.0) { codecount[i][j] /= max[j]; } } } } else { for (i=0; i 0.0) { codecount[i][j] /= colormax[i]; } } } } } ////////////////////////////// // // printData -- // void printData(HumdrumFile& infile, Array >& rdata) { int i; int j; for (i=0; idata1 = adata; } template class ACLass { public: void setData(int adata); private: int data1; }; template void AClass::setData(int adata) { this->data1 = adata; } AClass */ ////////////////////////////// // // generateAnalysis -- Extract the H, M, L tokens from all **irange spines. // void generateAnalysis(HumdrumFile& infile, Array >& rdata) { rdata.setSize(infile.getNumLines()); rdata.setSize(0); int i; int j; for (i=0; i < infile.getNumLines(); i++) { if (infile[i].getType() != E_humrec_data) { continue; } for (j=0; j < infile[i].getFieldCount(); j++) { if (strcmp(infile[i].getExInterp(j), "**irange") == 0) { storeData(infile[i], j, rdata); } break; } } } ////////////////////////////// // // storeData -- // #define TIM_UNKNOWN -1 #define TIM_LOW 0 #define TIM_MID 1 #define TIM_HIGH 2 void storeData(HumdrumRecord& aRecord, int index, Array >& rdata) { rdata.setSize(rdata.getSize()+1); rdata[rdata.getSize()-1].setSize(32); rdata[rdata.getSize()-1].setSize(0); int i; char buffer[1024] = {0}; int item = 0; int tokencount = aRecord.getTokenCount(index); for (i=0; i