Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_shape.cpp

    r8592c9 r27888f  
    8080  std::vector<Vector> points = shape.getHomogeneousPointsOnSurface(NumPointsonSurface);
    8181
     82  // Fill the points into a tesselate-able container.
     83  TesselPointSTLList Corners;
     84  for (size_t i=0;i<points.size();++i){
     85    TesselPoint *Walker = new TesselPoint;
     86    Walker->setPosition(points[i]);
     87    Walker->setName(toString(i));
     88    Walker->setNr(i);
     89    Corners.push_back(Walker);
     90  }
     91
     92  // Tesselate the points.
     93  Tesselation *T = new Tesselation;
     94  PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
     95  (*T)(cloud, minradius);
     96
     97  // Fill the points into a Qt geometry.
    8298  QGeometryData geo;
    83   // we need at least three points for tesselation
    84   if (points.size() >= 3) {
    85     // Fill the points into a tesselate-able container.
    86     TesselPointSTLList Corners;
    87     for (size_t i=0;i<points.size();++i){
    88       TesselPoint *Walker = new TesselPoint;
    89       Walker->setPosition(points[i]);
    90       Walker->setName(toString(i));
    91       Walker->setNr(i);
    92       Corners.push_back(Walker);
    93     }
    94  
    95     // Tesselate the points.
    96     Tesselation T;
    97     PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
    98     T(cloud, minradius);
    99  
    100     // Fill the points into a Qt geometry.
    101     LinkedCell_deprecated LinkedList(cloud, minradius);
    102     std::vector<Vector> normals;
    103     normals.resize(points.size(), zeroVec);
    104     for(size_t i=0;i<points.size();++i){
    105       // add data to the primitive
    106       geo.appendVertex(QVector3D(points[i][0], points[i][1], points[i][2]));
    107       if (ShapeFactory::getInstance().isSimpleShape(shape.getType()))
    108         normals[i] = shape.getNormal(points[i]);
    109       else
    110         normals[i] = T.getNormal(points[i], &LinkedList);
    111       geo.appendNormal(QVector3D(normals[i][0], normals[i][1], normals[i][2]));
    112       geo.appendColor(QColor(1, 1, 1, 1));
    113       geo.appendTexCoord(QVector2D(0, 0));
    114     }
    115  
    116     // Fill the tesselated triangles into the geometry.
    117     for (TriangleMap::const_iterator runner = T.TrianglesOnBoundary.begin(); runner != T.TrianglesOnBoundary.end(); runner++) {
    118       int v[3];
    119       for (size_t i=0; i<3; ++i)
    120         v[i] = runner->second->endpoints[i]->node->getNr();
    121  
    122       // Sort the vertices so the triangle is clockwise (relative to the normal vector).
    123       Vector cross = points[v[1]] - points[v[0]];
    124       cross.VectorProduct(points[v[2]] - points[v[0]]);
    125       if (cross.ScalarProduct(normals[v[0]] + normals[v[1]] + normals[v[2]]) > 0)
    126         geo.appendIndices(v[0], v[1], v[2]);
    127       else
    128         geo.appendIndices(v[0], v[2], v[1]);
    129     }
     99  LinkedCell_deprecated LinkedList(cloud, minradius);
     100  std::vector<Vector> normals;
     101  normals.resize(points.size(), zeroVec);
     102  for(size_t i=0;i<points.size();++i){
     103    // add data to the primitive
     104    geo.appendVertex(QVector3D(points[i][0], points[i][1], points[i][2]));
     105    if (ShapeFactory::getInstance().isSimpleShape(shape.getType()))
     106      normals[i] = shape.getNormal(points[i]);
     107    else
     108      normals[i] = T->getNormal(points[i], &LinkedList);
     109    geo.appendNormal(QVector3D(normals[i][0], normals[i][1], normals[i][2]));
     110    geo.appendColor(QColor(1, 1, 1, 1));
     111    geo.appendTexCoord(QVector2D(0, 0));
     112  }
     113
     114  // Fill the tesselated triangles into the geometry.
     115  for (TriangleMap::const_iterator runner = T->TrianglesOnBoundary.begin(); runner != T->TrianglesOnBoundary.end(); runner++) {
     116    int v[3];
     117    for (size_t i=0; i<3; ++i)
     118      v[i] = runner->second->endpoints[i]->node->getNr();
     119
     120    // Sort the vertices so the triangle is clockwise (relative to the normal vector).
     121    Vector cross = points[v[1]] - points[v[0]];
     122    cross.VectorProduct(points[v[2]] - points[v[0]]);
     123    if (cross.ScalarProduct(normals[v[0]] + normals[v[1]] + normals[v[2]]) > 0)
     124      geo.appendIndices(v[0], v[1], v[2]);
     125    else
     126      geo.appendIndices(v[0], v[2], v[1]);
    130127  }
    131128
Note: See TracChangeset for help on using the changeset viewer.