示例#1
0
// This is not useful as the tubes take too long to render in POV-Ray
void PovRayGen::writeMesh(QList<qglviewer::Vec> const& edges, 
   QColor const& color, bool clip)
{
   QString id("Mesh_");
   id += QString::number(m_meshCount);
   ++m_meshCount;
   
   m_stream << "#declare " << id << "=\n";
   m_stream << "union {\n";

   for (int i = 0; i < edges.size(); i += 2) {
      m_stream << "   cylinder {" << formatVector(edges[i]) << ", " 
               << formatVector(edges[i+1]) << ", 0.01}\n";
   }

   m_stream << "}\n\n";

   m_stream << "object {\n";
   m_stream << "   " << id << "\n";
   m_stream << "   texture {\n";
   m_stream << "      pigment {\n";
   m_stream << "         color rgbt " << formatColor(color) << "\n";
   m_stream << "      }   \n";
   m_stream << "   }\n";
   if (clip) m_stream << "   clipped_by { Clipping_Plane }\n";
   m_stream << "}\n";
}
示例#2
0
void PovRayGen::writeMesh(QList<qglviewer::Vec> const& vertices, 
   QList<qglviewer::Vec> const& normals, QList<int> const& faces, 
   QColor const& color, bool clip)
{
   unsigned nVertices(vertices.size());
   unsigned nFaces(faces.size()/3);

   QString id("Mesh_");
   id += QString::number(m_meshCount);
   ++m_meshCount;
   
   m_stream << "#declare " << id << "=\n";
   m_stream << "mesh2 {\n";

   m_stream << "   vertex_vectors {\n";
   m_stream << "      " << nVertices;
   for (unsigned i = 0; i < nVertices; ++i) {
       m_stream << ",\n   " << formatVector(vertices.at(i));
   }
   m_stream << "\n   }\n\n";

   m_stream << "   normal_vectors {\n";
   m_stream << "      " << nVertices;
   for (unsigned i = 0; i < nVertices; ++i) {
       Vec n(normals.at(i));
       //m_stream << ",\n   " << formatVector(normals.at(i));
       m_stream << ",\n   " << formatVector(Vec(n.x, n.y, -n.z));
   }
   m_stream << "\n   }\n\n";

   m_stream << "   face_indices{\n";
   m_stream << "      " << nFaces;
   for (int i = 0; i < faces.size(); i += 3) {
       m_stream << ",\n   <" << faces.at(i) << ", " << faces.at(i+1) << ", " 
                << faces.at(i+2) << ">";
   }
   m_stream << "\n   }\n\n";
   m_stream << "\n}\n\n";

   if (clip) {
      m_stream << "ClippedSurface(" << id << ", " << formatColor(color) << ")\n";
   }else {
      m_stream << "Surface(" << id << ", " << formatColor(color) << ")\n";
   }
            
}
示例#3
0
void PovRayGen::writeAtom(Vec const& pos, QColor const& col, double const rad)
{
   m_stream << "Atom(" << formatVector(pos)  << ", " << formatColor(col) <<  ", " 
           << rad << ")\n";
}
示例#4
0
void PovRayGen::writeBond(qglviewer::Vec const& begin, qglviewer::Vec const& end, 
            QColor const& col, double const radius)
{
   m_stream << "Bond(" << formatVector(begin) << ", " << formatVector(end) << ", "
            << formatColor(col) << ", " << radius << ")\n";
}
示例#5
0
void PovRayGen::setCamera(qglviewer::Camera* camera)
{
   Vec pos(camera->position());
   double angle(camera->fieldOfView());
   angle *= 180/M_PI;
   
   //angle += 15;  // The angle seem to come out different for POVRay

   // The camera coordinate system
   Vec x(camera->rightVector());
   Vec y(camera->upVector());
   //Vec z(camera->viewDirection());
   double r(camera->sceneRadius());

   //qDebug() << "Camera position " << pos.x << pos.y << pos.z;
   //qDebug() << "Camera direction" << z.x << z.y << z.z;
   //qDebug() << "Camera up       " << y.x << y.y << y.z;
   //qDebug() << "Camera right    " << x.x << x.y << x.z;

   m_stream << "camera {\n";
   m_stream << "   location " << formatVector(pos) << "\n";
   m_stream << "   sky      " << formatVector(y)   << "\n";
   m_stream << "   look_at  <0, 0, 0>\n";
   m_stream << "   angle " << Util::round(angle) <<  "\n";
   m_stream << "}\n\n";

   r *= 100.0;

   pos.normalize();
   pos.z *= -1.0;
   y.z   *= -1.0;
   x.z   *= -1.0;

   // Light directions are taken from the phong.vert shader
   Vec light;

   if (m_lightFront) {
      //const vec4 lightDirection0 = vec4( 0.4,  0.0,  1.0);  
      light = 0.4*x + 0.0*y + 1.0*pos;
      light = r * light.unit();
      m_stream << "// Light: front\n";
      writeLight(light, Qt::lightGray);
   }

   if (m_lightHighlight) {
      //const vec4 lightDirection1 = vec4( 0.3,  0.8, -0.5);  // highlight
      light = 0.3*x + 0.8*y - 0.5*pos;
      light = r * light.unit();
      m_stream << "// Light: highlight\n";
      writeLight(light, Qt::lightGray);
   }

   if (m_lightLeft) {
      //const vec4 lightDirection2 = vec4(-0.5,  0.0,  0.0);  // left
      light = -0.5*x + 0.0*y + 0.0*pos;
      light = r * light.unit();
      m_stream << "// Light: left\n";
      writeLight(light, Qt::lightGray);
   }

   if (m_lightLower) {
      //const vec4 lightDirection3 = vec4( 0.0, -1.0,  0.2);  // lower
      light = 0.0*x - 1.0*y + 0.2*pos;
      light = r * light.unit();
      m_stream << "// Light: lower\n";
      writeLight(light, Qt::lightGray);
   }
}
示例#6
0
void MainWindow::updatePredicateInformation()
{
    // changed
    m_currentChanged = true;
    updateWindowTitle();

    // predicate g
    struct predg3f_s pred =
        {
            { sliderToParamValue(ui->verticalSliderKX), sliderToParamValue(ui->verticalSliderKY), sliderToParamValue(ui->verticalSliderKZ) },
            { sliderToParamValue(ui->verticalSliderLX), sliderToParamValue(ui->verticalSliderLY), sliderToParamValue(ui->verticalSliderLZ) },
            { sliderToParamValue(ui->verticalSliderAX), sliderToParamValue(ui->verticalSliderAY), sliderToParamValue(ui->verticalSliderAZ) },
            { sliderToParamValue(ui->verticalSliderBX), sliderToParamValue(ui->verticalSliderBY), sliderToParamValue(ui->verticalSliderBZ) },
            sliderToParamValue(ui->verticalSliderC)
        };

    // param g
    struct predgparam3f_s param;
    predg3f_param(&param, &pred);

    double a = param.a;
    double b = param.b;
    double c = param.c;

    double mi = std::min(a - b, b - a);
    double ma = std::max(a - b, b - a);

    // information -> parameters
    ui->labelKval->setText(formatVector(&pred.k));
    ui->labelLval->setText(formatVector(&pred.l));
    ui->labelAval->setText(formatVector(&pred.a));
    ui->labelBval->setText(formatVector(&pred.b));
    ui->labelCval->setText(QString::number(c, 'f', 2));

    // information -> base variables
    struct vec3f_s p, q, u, v;
    predg3f_pquv(&p, &q, &u, &v, &pred);

    ui->labelPval->setText(formatVector(&p));
    ui->labelQval->setText(formatVector(&q));
    ui->labelUval->setText(formatVector(&u));
    ui->labelVval->setText(formatVector(&v));
    ui->labelC2val->setText(QString::number(c, 'f', 2));

    // information -> type
    enum predgtype3f_e type = predg3f_type(&pred);

    ui->labelproperval->setText(type == predgtype3f_inproper ? "no" : "yes");
    ui->labeltypeval->setText(predgtype3f_str(type));

    // information -> parametrization variables
    ui->labelaval->setText(QString::number(a, 'f', 4));
    ui->labelbval->setText(QString::number(b, 'f', 4));
    ui->labelcval->setText(QString::number(c, 'f', 4));
    ui->labelminval->setText(QString::number(mi, 'f', 4));
    ui->labelmaxval->setText(QString::number(ma, 'f', 4));

    ui->labelcaseval->setText(predgparamtype3f_str(param.t));
    ui->labeldimval->setText(QString::number(predgparamtype3f_dim(param.t)));
    ui->labelcompval->setText(QString::number(predgparamtype3f_components(param.t)));

    // information -> eigen decomposition
    struct mat44f_s eigenvec;
    struct vec4f_s eigenval;
    predg3f_eigen(&eigenvec, &eigenval, &pred);

    double l1 = eigenval.x;
    double l2 = eigenval.y;
    double l3 = eigenval.z;
    double l4 = eigenval.w;

    double det = l1 * l2 * l3 * l4;

    struct vec4f_s w1 = { eigenvec.m[0][0], eigenvec.m[1][0], eigenvec.m[2][0], eigenvec.m[3][0] };
    struct vec4f_s w2 = { eigenvec.m[0][1], eigenvec.m[1][1], eigenvec.m[2][1], eigenvec.m[3][1] };
    struct vec4f_s w3 = { eigenvec.m[0][2], eigenvec.m[1][2], eigenvec.m[2][2], eigenvec.m[3][2] };
    struct vec4f_s w4 = { eigenvec.m[0][3], eigenvec.m[1][3], eigenvec.m[2][3], eigenvec.m[3][3] };

    ui->labeldetval->setText(QString::number(det, 'f', 8));

    ui->labell1val->setText(QString::number(l1, 'f', 4));
    ui->labell2val->setText(QString::number(l2, 'f', 4));
    ui->labell3val->setText(QString::number(l3, 'f', 4));
    ui->labell4val->setText(QString::number(l4, 'f', 4));

    ui->labelw1val->setText(formatVector(&w1));
    ui->labelw2val->setText(formatVector(&w2));
    ui->labelw3val->setText(formatVector(&w3));
    ui->labelw4val->setText(formatVector(&w4));

    // visual
    m_rv->removeAllObjects();

    // only 2-dimensional
    if (predgparamtype3f_dim(param.t) == 2)
    {
        TriangleListPtr trianglesFront(new TriangleList());
        TriangleListPtr trianglesBack(new TriangleList());

        if (ui->actionAutoMesh->isChecked())
            autoMesh(trianglesFront, trianglesBack, &param, 0.1, 0.5, 10);
        else
            simpleMesh(trianglesFront, trianglesBack, &param, 0.01);

        m_rv->addTriangleList(trianglesFront, Qt::green);
        m_rv->addTriangleList(trianglesBack, Qt::red);
    }
}