//========================================== void histogram(int sid) //========================================== { int i,j,k=0,temp,height = g_rows - 1; int color=0,div,rscale = 0,rn1,rn2; char sstr[40]; float fx = readLatestSidValue(sid,g_mid); // Get max and min value g_fmax = 0.; g_fmin = 999999.; for(i=1;i<=g_cols-5;i++) { g_fbuff[i] = g_fbuff[i+1]; if(g_fmin > g_fbuff[i])g_fmin = g_fbuff[i]; if(g_fmax < g_fbuff[i])g_fmax = g_fbuff[i]; } g_fmax = g_fmax*1.1; g_fbuff[g_cols-5] = fx; div = getDivision(g_fmax); k=1; int kindex = div; for(j=1;j<=g_rows;j++) { if(j == getRowNumber(g_fmax,kindex)) { writeInt(kindex,1, j, C_BLUE); writeInt(kindex,g_cols-4, j, C_BLUE); k++; kindex = k*div; } } rn1 = getRowNumber(g_fmax,3000.); rn2 = getRowNumber(g_fmax,1000.); //writeFloat(g_fmax,7,g_rows-1, 0); sprintf(sstr,"%d Watt",(int)fx); //writeFloat(fx,g_cols/2,g_rows-1, C_RED); writeString(sstr,g_cols/2,g_rows-1, C_RED); g_fmin = 0.0; for(i=1;i<=g_cols-5;i++) { if(g_fmax > 0)temp = (int)(height*(g_fbuff[i]-g_fmin)/(g_fmax - g_fmin)); for(j=1;j<=temp;j++) { if (j >= rn1)color = C_YELLOW; else if (j >= rn2)color = C_RED; if (j < rn2)color = C_GREEN; setElement('*',i,j,color); } } }
void SCylinder::subDraw() { getPrimitiveSetList().clear(); osg::ref_ptr<osg::Vec3Array> vertexArr = new osg::Vec3Array; osg::ref_ptr<osg::Vec3Array> normalArr = new osg::Vec3Array; setVertexArray(vertexArr); setNormalArray(normalArr, osg::Array::BIND_PER_VERTEX); osg::ref_ptr<osg::Vec4Array> colArr = new osg::Vec4Array(); colArr->push_back(m_color); setColorArray(colArr, osg::Array::BIND_OVERALL); int count = (int)getDivision(); double incAng = 2 * M_PI / count; osg::Vec3 topNormal = m_height; topNormal.normalize(); double angleCos = m_bottomNormal * (-topNormal) / m_bottomNormal.length() / topNormal.length(); double angle = acos(angleCos); double a = m_radius; double b = m_radius / sin(M_PI_2 - angle); osg::Vec3 vec = m_bottomNormal ^ topNormal; vec.normalize(); osg::Quat bottomQuat(incAng, m_bottomNormal); double currAngle = 0; osg::Quat localToWorldQuat; localToWorldQuat.makeRotate(osg::Z_AXIS, m_bottomNormal); osg::Vec3 yAxis = localToWorldQuat * osg::Y_AXIS; osg::Quat localToWorldQuat2; localToWorldQuat2.makeRotate(yAxis, vec); localToWorldQuat *= localToWorldQuat2; osg::Vec3 bottomVec(b * sin(currAngle), a * cos(currAngle), 0); bottomVec = localToWorldQuat * bottomVec; //bottomVec = localToWorldQuat2 * bottomVec; osg::Quat topQuat(incAng, topNormal); osg::Vec3 topVec = vec * m_radius; osg::Vec3 topCenter = m_org + m_height; size_t first = vertexArr->size(); for (int i = 0; i < count; ++i) { vertexArr->push_back(topCenter + topVec); vertexArr->push_back(m_org + bottomVec); normalArr->push_back(topVec); normalArr->back().normalize(); normalArr->push_back(normalArr->back()); currAngle += incAng; bottomVec.set(b * sin(currAngle), a * cos(currAngle), 0); bottomVec = localToWorldQuat * bottomVec; //bottomVec = localToWorldQuat2 * bottomVec; topVec = topQuat * topVec; } vertexArr->push_back((*vertexArr)[first]); vertexArr->push_back((*vertexArr)[first + 1]); normalArr->push_back((*normalArr)[first]); normalArr->push_back((*normalArr)[first + 1]); addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, first, vertexArr->size() - first)); if (m_bottomVis) { first = vertexArr->size(); vertexArr->push_back(m_org); normalArr->push_back(m_bottomNormal); for (int i = count; i >= 0; --i) { vertexArr->push_back((*vertexArr)[i * 2 + 1]); normalArr->push_back(m_bottomNormal); } addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN, first, vertexArr->size() - first)); } if (m_topVis) { first = vertexArr->size(); vertexArr->push_back(topCenter); normalArr->push_back(topNormal); for (int i = 0; i < count + 1; ++i) { vertexArr->push_back((*vertexArr)[i * 2]); normalArr->push_back(topNormal); } addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN, first, vertexArr->size() - first)); } }