calculix data visualizor using QT

Posted by Ann on Stack Overflow See other posts from Stack Overflow or by Ann
Published on 2010-03-13T04:03:54Z Indexed on 2010/03/13 4:07 UTC
Read the original article Hit count: 394

Filed under:

include "final1.h"

include "ui_final1.h"

include

include

include

ifndef GL_MULTISAMPLE

define GL_MULTISAMPLE 0x809D

endif

define numred 100

define numgrn 10

define numblu 6

final1::final1(QWidget *parent) : QGLWidget(parent) { setFormat(QGLFormat(QGL::SampleBuffers));

rotationX = -38.0;
rotationY = -58.0;
rotationZ = 0.0;
scaling = .05;

// glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); //createGradient(); createGLObject(); }

final1::~final1() { makeCurrent(); glDeleteLists(glObject, 1); }

void final1::paintEvent(QPaintEvent * /* event */) { QPainter painter(this); draw();

}

void final1::mousePressEvent(QMouseEvent *event) { lastPos = event->pos(); }

void final1::mouseMoveEvent(QMouseEvent *event) { GLfloat dx = GLfloat(event->x() - lastPos.x()) / width(); GLfloat dy = GLfloat(event->y() - lastPos.y()) / height();

if (event->buttons() & Qt::LeftButton) {
    rotationX += 180 * dy;
    rotationY += 180 * dx;
    update();
} else if (event->buttons() & Qt::RightButton) {
    rotationX += 180 * dy;
    rotationZ += 180 * dx;
    update();
}
lastPos = event->pos();

} void final1::createGLObject() { makeCurrent(); GLfloat f1[150],f2[150],f3[150],length=0; qreal size=2; int k=1,a,b,c,d,e,f,g,h,element_node_no=0; GLfloat x,y,z; QString str1,str2,str3,str4,str5,str6,str7,str8; int red,green,blue,index=1,displacement; int LUT[1000][3]; for(red=100;red

   glShadeModel(GL_SMOOTH);

    glObject = glGenLists(1);
    glNewList(glObject, GL_COMPILE);
   // qglColor(QColor(255, 239, 191));
    glLineWidth(1.0);
    QLinearGradient linearGradient(0, 0, 100, 100);
            linearGradient.setColorAt(0.0, Qt::red);
            linearGradient.setColorAt(0.2, Qt::green);
            linearGradient.setColorAt(1.0, Qt::black);
            //renderArea->setBrush(linearGradient);
    //glColor3f(1,0,0);pow((f1[e]-f1[a]),2)
    QFile file("/home/41407/input1.txt");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
      return;
    QTextStream in(&file);
    while (!in.atEnd())
    {
    QString line = in.readLine();
     if(k<=125)
     {

     str1= line.section(',', 1, 1);
     str2=line.section(',', 2, 2);
     str3=line.section(',', 3, 3);
     x=str1.toFloat();
     y=str2.toFloat();
     z=str3.toFloat();
     f1[k]=x;
     f2[k]=y;
     f3[k]=z;
   /*  glBegin(GL_TRIANGLES);
   //  glColor3f(LUT[k][0],LUT[k][1],LUT[k][2]);
     //QColorAt();//setPointSize(size);
     glVertex3f(x,y,z);
     glEnd();*/
    }
else if(k>125)

 {
    element_node_no=0;
    qCount(line.begin(),line.end(),',',element_node_no);
   // printf("\n%d",element_node_no);
    str1= line.section(',', 1, 1);
    str2=line.section(',', 2, 2);
    str3=line.section(',', 3, 3);
    str4= line.section(',', 4, 4);
    str5=line.section(',', 5, 5);
    str6=line.section(',', 6, 6);
    str7= line.section(',', 7, 7);
    str8=line.section(',', 8, 8);
    a=str1.toInt();
    b=str2.toInt();
    c=str3.toInt();
    d=str4.toInt();
    e=str5.toInt();
    f=str6.toInt();
    g=str7.toInt();
    h=str8.toInt();
    glBegin(GL_POLYGON);

    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    //brush.setColor(Qt::black);//setColor(QColor::black());
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
     // pmp.setBrush(gradient);
    glVertex3f(f1[a],f2[a] ,f3[a]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[b],f2[b] ,f3[b]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[c],f2[c] ,f3[c]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[d],f2[d] ,f3[d]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[a],f2[a] ,f3[a]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    //glEnd();
    //glBegin(GL_LINE_LOOP);

    glVertex3f(f1[e],f2[e] ,f3[e]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[f],f2[f] ,f3[f]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[g],f2[g], f3[g]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[h],f2[h], f3[h]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[d],f2[d] ,f3[d]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
   glVertex3f(f1[a],f2[a] ,f3[a]);
   glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glEnd();
    glBegin(GL_POLYGON);
   //glVertex3f(f1[a],f2[a] ,f3[a]);
    glVertex3f(f1[e],f2[e] ,f3[e]);
    glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[h],f2[h], f3[h]);
    glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
     //glVertex3f(f1[d],f2[d] ,f3[d]);
    glVertex3f(f1[g],f2[g], f3[g]);
    glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[c],f2[c] ,f3[c]);
    glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[f],f2[f] ,f3[f]);
    glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);
    glVertex3f(f1[b],f2[b] ,f3[b]);
    glColor3f(LUT[k][0],LUT[k][1],LUT[k++][2]);

    glEnd();
    /*length=sqrt(pow((f1[e]-f1[a]),2)+pow((f2[e]-f2[a]),2)+pow((f3[e]-f3[a]),2));
    printf("\n%d",length);*/
}
k++;
}
  glEndList();
  file.close();
  k=1;
  QFile file1("/home/41407/op.txt");
  if (!file1.open(QIODevice::ReadOnly | QIODevice::Text))
    return;
  QTextStream in1(&file1);
  k=1;
  while (!in1.atEnd())
    {
      QString line = in1.readLine();
     // if(k<=125)
        {
          str1= line.section(' ', 1, 1);
             x=str1.toFloat();
          str2=line.section(' ', 2, 2);
             y=str2.toFloat();
          str3=line.section(' ', 3, 3);
              z=str3.toFloat();
          displacement=sqrt(pow( (x-f1[k]),2)+pow((y-f2[k]),2)+pow((z-f3[k]),2));
          //printf("\n %d : %d",k,displacement);
          glBegin(GL_POLYGON);
          //glColor3f(LUT[displacement][0],LUT[displacement][1],LUT[displacement][2]);
            glVertex3f(f1[k],f2[k],f3[k]);
          glEnd();
          a1[k]=x+f1[k];
          a2[k]=y+f2[k];
          a3[k]=z+f3[k];
          //printf("\nc: %f  %f  %f",x,y,z);
          //printf("\nf: %f  %f  %f",f1[k],f2[k],f3[k]);
          //printf("\na: %f  %f  %f",a1[k],a2[k],a3[k]);

        }
     k++;
  glEndList();
 }

} void final1::draw() { glPushAttrib(GL_ALL_ATTRIB_BITS);

      glMatrixMode(GL_PROJECTION);
      glPushMatrix();
      glLoadIdentity();
      GLfloat x = 3.0 * GLfloat(width()) / height();
      glOrtho(-x, +x, -3.0, +3.0, 4.0, 15.0);

      glMatrixMode(GL_MODELVIEW);
      glPushMatrix();
      glLoadIdentity();
      glTranslatef(0.0, 0.0, -10.0);
      glScalef(scaling, scaling, scaling);

      glRotatef(rotationX, 1.0, 0.0, 0.0);
      glRotatef(rotationY, 0.0, 1.0, 0.0);
      glRotatef(rotationZ, 0.0, 0.0, 1.0);

      glEnable(GL_MULTISAMPLE);

      glCallList(glObject);


      glMatrixMode(GL_MODELVIEW);
      glPopMatrix();

      glMatrixMode(GL_PROJECTION);
      glPopMatrix();

      glPopAttrib();
  }
  /*uint final1::colorAt(int x)
   {
       generateShade();

       QPolygonF pts = m_hoverPoints->points();
       for (int i=1; i < pts.size(); ++i) {
           if (pts.at(i-1).x() <= x && pts.at(i).x() >= x) {
               QLineF l(pts.at(i-1), pts.at(i));
               l.setLength(l.length() * ((x - l.x1()) / l.dx()));
               return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))),
                                    qRound(qMin(l.y2(), qreal(m_shade.height() - 1))));
           }
       }
       return 0;*/
  //final1::

//} /*void final1::createGLObject() { makeCurrent(); //QPainter painter; QPixmap pm(20, 20); QPainter pmp(&pm); pmp.fillRect(0, 0, 10, 10, Qt::blue); pmp.fillRect(10, 10, 10, 10, Qt::lightGray); pmp.fillRect(0, 10, 10, 10, Qt::darkGray); pmp.fillRect(10, 0, 10, 10, Qt::darkGray); pmp.end(); QPalette pal = palette(); pal.setBrush(backgroundRole(), QBrush(pm)); //setAutoFillBackground(true); setPalette(pal); //GLfloat f1[150],f2[150],f3[150],a1[150],a2[150],a3[150]; int k=1,a,b,c,d,e,f,g,h; //int p=0; GLfloat x,y,z; int displacement; QString str1,str2,str3,str4,str5,str6,str7,str8; int red,green,blue,index=1; int LUT[8000][3]; for(red=0;red

//glShadeModel(GL_LINE);

glObject = glGenLists(1);
glNewList(glObject, GL_COMPILE);
    //qglColor(QColor(120,255,210));
glLineWidth(1.0);

//glColor3f(1,0,0);
QFile file("/home/41407/input.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
  return;
QTextStream in(&file);
while (!in.atEnd())
{
    //glColor3f(LUT[k][0],LUT[k][1],LUT[k][2]);
QString line = in.readLine();
 if(k<=125)
 {
     //printf("\nline :%c",line);
 str1= line.section(',', 1, 1);
 str2=line.section(',', 2, 2);
 str3=line.section(',', 3, 3);
 x=str1.toFloat();
 y=str2.toFloat();
 z=str3.toFloat();
 f1[k]=x;
 f2[k]=y;
 f3[k]=z;
  //printf("\nf: %f  %f  %f",f1[k],f2[k],f3[k]);
}

else if(k>125) //for(p=0;p<6;p++) { //glColor3f(LUT[k][0],LUT[k][1],LUT[k][2]);

update();
str1= line.section(',', 1, 1);
str2=line.section(',', 2, 2);
str3=line.section(',', 3, 3);
str4= line.section(',', 4, 4);
str5=line.section(',', 5, 5);
str6=line.section(',', 6, 6);
str7= line.section(',', 7, 7);
str8=line.section(',', 8, 8);
a=str1.toInt();
b=str2.toInt();
c=str3.toInt();
d=str4.toInt();
e=str5.toInt();
f=str6.toInt();
g=str7.toInt();
h=str8.toInt();


//for (p = 0; p < 6; p++)
{

   // glBegin(GL_LINE_WIDTH);
    //glColor3f(LUT[126][0],LUT[126][1],LUT[126][2]);
    //update();
  //glNormal3fv(&n[p][0]);
  //glVertex3f(f1[i],f2[i],f3[i]);
  glVertex3fv(&v[faces[i][1]][0]);
  glVertex3fv(&v[faces[i][2]][0]);
  glVertex3fv(&v[faces[i][3]][0]);
  //glEnd();
//}
  glBegin(GL_LINE_LOOP);

  //glColor3f(p*20,p*20,p);

glColor3f(1,0,0); glVertex3f(f1[a],f2[a] ,f3[a]); //painter.fillRect(QRectF(f1[a],f2[a] ,f3[a], 2), Qt::magenta); glVertex3f(f1[b],f2[b] ,f3[b]); glVertex3f(f1[c],f2[c] ,f3[c]); glVertex3f(f1[d],f2[d] ,f3[d]); glVertex3f(f1[a],f2[a] ,f3[a]); glVertex3f(f1[e],f2[e] ,f3[e]); glVertex3f(f1[f],f2[f] ,f3[f]); glVertex3f(f1[g],f2[g], f3[g]); glVertex3f(f1[h],f2[h], f3[h]); glVertex3f(f1[d],f2[d] ,f3[d]); glVertex3f(f1[a],f2[a] ,f3[a]); //glColor3f(1,0,0); //QLinearGradient ( f1[a], f2[a], f1[b], f2[b] ); glEnd(); glBegin(GL_LINES); //glNormal3fv(&n[p][0]); //glColor3f(LUT[k][0],LUT[k][1],LUT[k][2]); glVertex3f(f1[e],f2[e] ,f3[e]); glVertex3f(f1[h],f2[h], f3[h]); glVertex3f(f1[g],f2[g], f3[g]); glVertex3f(f1[c],f2[c] ,f3[c]); glVertex3f(f1[f],f2[f] ,f3[f]); glVertex3f(f1[b],f2[b] ,f3[b]);

glEnd();

} } k++; } glEndList(); qglColor(QColor(239, 255, 191)); glLineWidth(1.0); glColor3f(0,1,0); k=1; QFile file1("/home/41407/op.txt"); if (!file1.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream in1(&file1); k=1; while (!in1.atEnd()) { QString line = in1.readLine(); // if(k<=125) { str1= line.section(' ', 1, 1); x=str1.toFloat(); str2=line.section(' ', 2, 2); y=str2.toFloat(); str3=line.section(' ', 3, 3); z=str3.toFloat(); displacement=sqrt(pow( (x-f1[k]),2)+pow((y-f2[k]),2)+pow((z-f3[k]),2)); printf("\n %d : %d",k,displacement); glBegin(GL_POINT); glColor3f(LUT[displacement][0],LUT[displacement][1],LUT[displacement][2]); glVertex3f(x,y,z); glLoadIdentity(); glEnd(); a1[k]=x+f1[k]; a2[k]=y+f2[k]; a3[k]=z+f3[k]; //printf("\nc: %f %f %f",x,y,z); //printf("\nf: %f %f %f",f1[k],f2[k],f3[k]); //printf("\na: %f %f %f",a1[k],a2[k],a3[k]);

      }
   k++;
glEndList();

} }*/ /*void final1::draw() { glPushAttrib(GL_ALL_ATTRIB_BITS);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
GLfloat x = 3.0 * GLfloat(width()) / height();
glOrtho(-x, +x, -3.0, +3.0, 4.0, 15.0);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.0, 0.0, -10.0);
glScalef(scaling, scaling, scaling);

glRotatef(rotationX, 1.0, 0.0, 0.0);
glRotatef(rotationY, 0.0, 1.0, 0.0);
glRotatef(rotationZ, 0.0, 0.0, 1.0);

glEnable(GL_MULTISAMPLE);

glCallList(glObject);


glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPopMatrix();

glPopAttrib();

}*/

I need to change the color of a portion of beam where pressure is applied.But I am not able to color the front end back phase.

© Stack Overflow or respective owner

Related posts about c++