00001 //-------------------------------------------------------------------- 00002 // 00011 //-------------------------------------------------------------------- 00012 00013 #ifndef TXQ_PLOT_HELPER_H 00014 #define TXQ_PLOT_HELPER_H 00015 00016 // txmath includes 00017 #include <TxAttributeSet.h> 00018 00019 // Qt includes 00020 #include <qstring.h> 00021 00045 void addPolygon(TxAttributeSet *poly, 00046 TxAttributeSet *polyData, 00047 string polyName, 00048 int polyPoints, 00049 const std::vector<double> &x, 00050 const std::vector<double> &y, 00051 string polyColor, 00052 string polyFillColor, 00053 bool attribsUpToDate) { 00054 00055 // get the polyNumber 00056 int polyNumber = 0; 00057 00058 if (!attribsUpToDate) { 00059 if (poly->hasOption("polyNumber")) 00060 polyNumber = poly->getOption("polyNumber"); 00061 else 00062 poly->appendOption("polyNumber", polyNumber); 00063 polyNumber++; 00064 } 00065 else { 00066 if (poly->hasOption("polyNumber")) 00067 polyNumber = poly->getOption("polyNumber"); 00068 polyNumber++; 00069 } 00070 00071 // add the polyNumber to all the options 00072 QString spoly; 00073 QString spolyPoints; 00074 QString sxPolyData; 00075 QString syPolyData; 00076 QString spolyColor; 00077 QString spolyFillColor; 00078 spoly.sprintf("polygon%d", polyNumber); 00079 spolyPoints.sprintf("polyPoints%d", polyNumber); 00080 sxPolyData.sprintf("xPolyData%d", polyNumber); 00081 syPolyData.sprintf("yPolyData%d", polyNumber); 00082 spolyColor.sprintf("polyColor%d", polyNumber); 00083 spolyFillColor.sprintf("polyFillColor%d", polyNumber); 00084 00085 // set the options 00086 poly->setOption("polyNumber", polyNumber); 00087 if (!attribsUpToDate) { 00088 poly->appendString(spoly.ascii(),polyName); 00089 poly->appendString(spolyColor.ascii(), polyColor); 00090 if (polyColor != "none") 00091 poly->appendString(spolyFillColor.ascii(), polyFillColor); 00092 polyData->appendOption(spolyPoints.ascii(), polyPoints); 00093 polyData->appendPrmVec(sxPolyData.ascii(), x); 00094 polyData->appendPrmVec(syPolyData.ascii(), y); 00095 } 00096 else { 00097 polyData->setOption(spolyPoints.ascii(), polyPoints); 00098 polyData->setPrmVec(sxPolyData.ascii(), x); 00099 polyData->setPrmVec(syPolyData.ascii(), y); 00100 } 00101 } 00102 00103 00117 void addLine(TxAttributeSet *line, 00118 TxAttributeSet *lineData, 00119 string lineName, 00120 int linePoints, 00121 const std::vector<double> &x, 00122 const std::vector<double> &y, 00123 string lineColor, 00124 bool attribsUpToDate) { 00125 00126 // get the lineNumber 00127 int lineNumber = 0; 00128 if (!attribsUpToDate) { 00129 if (line->hasOption("lineNumber")) 00130 lineNumber = line->getOption("lineNumber"); 00131 else 00132 line->appendOption("lineNumber", lineNumber); 00133 lineNumber++; 00134 } 00135 else { 00136 if (line->hasOption("lineNumber")) 00137 lineNumber = line->getOption("lineNumber"); 00138 lineNumber++; 00139 } 00140 00141 // add the lineNumber to all the options 00142 QString sline; 00143 QString slinePoints; 00144 QString sxLineData; 00145 QString syLineData; 00146 QString slineColor; 00147 00148 sline.sprintf("line%d", lineNumber); 00149 slinePoints.sprintf("linePoints%d", lineNumber); 00150 sxLineData.sprintf("xLineData%d", lineNumber); 00151 syLineData.sprintf("yLineData%d", lineNumber); 00152 slineColor.sprintf("lineColor%d", lineNumber); 00153 00154 // set the options 00155 line->setOption("lineNumber", lineNumber); 00156 if (!attribsUpToDate) { 00157 line->appendString(sline.ascii(),lineName); 00158 line->appendString(slineColor.ascii(), lineColor); 00159 lineData->appendOption(slinePoints.ascii(), linePoints); 00160 lineData->appendPrmVec(sxLineData.ascii(), x); 00161 lineData->appendPrmVec(syLineData.ascii(), y); 00162 } 00163 else { 00164 lineData->setOption(slinePoints.ascii(), linePoints); 00165 lineData->setPrmVec(sxLineData.ascii(), x); 00166 lineData->setPrmVec(syLineData.ascii(), y); 00167 } 00168 } 00169 00170 00178 void applyFactor(std::vector<double> &data, double factor) { 00179 double qmin, qmax; 00180 qmin = data[0]; 00181 qmax = data[0]; 00182 for (unsigned int i=0; i < data.size(); i++) { 00183 if (qmin > data[i] ) qmin = data[i]; 00184 if (qmax < data[i] ) qmax = data[i]; 00185 } 00186 double qfact; 00187 qfact = factor/qmax; 00188 for (unsigned int i=0; i < data.size(); i++) { 00189 data[i] *= qfact; 00190 } 00191 } 00192 00193 00194 #endif //TXQ_PLOT_HELPER_H
Copyright Tech-X Corporation, all rights reserved.