Example #1
0
bool
NBNetBuilder::transformCoordinates(PositionVector& from, bool includeInBoundary, GeoConvHelper* from_srs) {
    const SUMOReal maxLength = OptionsCont::getOptions().getFloat("geometry.max-segment-length");
    if (maxLength > 0 && from.size() > 1) {
        // transformation to cartesian coordinates must happen before we can check segment length
        PositionVector copy = from;
        for (int i = 0; i < (int) from.size(); i++) {
            transformCoordinates(copy[i], false);
        }
        // check lengths and insert new points where needed (in the original
        // coordinate system)
        int inserted = 0;
        for (int i = 0; i < (int)copy.size() - 1; i++) {
            Position start = from[i + inserted];
            Position end = from[i + inserted + 1];
            SUMOReal length = copy[i].distanceTo(copy[i + 1]);
            const Position step = (end - start) * (maxLength / length);
            int steps = 0;
            while (length > maxLength) {
                length -= maxLength;
                steps++;
                from.insert(from.begin() + i + inserted + 1, start + (step * steps));
                inserted++;
            }
        }
        // now perform the transformation again so that height mapping can be
        // performed for the new points
    }
    bool ok = true;
    for (int i = 0; i < (int) from.size(); i++) {
        ok = ok && transformCoordinates(from[i], includeInBoundary, from_srs);
    }
    return ok;
}
void Viewport::drawPolygon(Object* obj){
    auto coords = obj->getNCoords();
    Coordinates nCoords;
    if(coords.size() == 1){// Usuario quer um ponto?
        drawPoint(obj);
        return;
    }else if(coords.size() == 2){// Usuario quer uma linha?
        drawLine(obj);
        return;
    }

    transformCoordinates(coords, nCoords);
    prepareContext(obj);

    cairo_move_to(m_cairo, nCoords[0].x, nCoords[0].y);
    for(unsigned int i = 0; i<nCoords.size(); i++)
        cairo_line_to(m_cairo, nCoords[i].x, nCoords[i].y);

    cairo_close_path(m_cairo);

    Polygon* p = (Polygon*) obj;
    if(p->filled()){
        cairo_stroke_preserve(m_cairo);
        cairo_fill(m_cairo);
    }else
        cairo_stroke(m_cairo);
}
Example #3
0
//------------------------------
void MolState::rotate(const double alpha_x, const double alpha_y, const double alpha_z)
{
  // three rotation matrices (instead of making one matrix) arouns x, y, z axes
  KMatrix R(CARTDIM,CARTDIM), Rx(CARTDIM,CARTDIM), Ry(CARTDIM,CARTDIM), Rz(CARTDIM,CARTDIM);

  Rx.Set(0);
  Rx.Elem2(0,0)=1;
  Rx.Elem2(1,1)=cos(alpha_x);
  Rx.Elem2(2,2)=cos(alpha_x);
  Rx.Elem2(2,1)=-sin(alpha_x);
  Rx.Elem2(1,2)=sin(alpha_x);

  Ry.Set(0);
  Ry.Elem2(1,1)=1;
  Ry.Elem2(0,0)=cos(alpha_y);
  Ry.Elem2(2,2)=cos(alpha_y);
  Ry.Elem2(2,0)=sin(alpha_y);
  Ry.Elem2(0,2)=-sin(alpha_y);

  Rz.Set(0);
  Rz.Elem2(2,2)=1;
  Rz.Elem2(0,0)=cos(alpha_z);
  Rz.Elem2(1,1)=cos(alpha_z);
  Rz.Elem2(1,0)=-sin(alpha_z);
  Rz.Elem2(0,1)=sin(alpha_z);

  // overall rotation R=Rx*Ry*Rz
  R.SetDiagonal(1);
  R*=Rx;
  R*=Ry;
  R*=Rz;
  
  // and now rotates using matix R:
  transformCoordinates(R);
}
void Viewport::drawCurve(Object* obj){
    auto coords = obj->getNCoords();
    Coordinates nCoords;

    transformCoordinates(coords, nCoords);
    prepareContext(obj);

    cairo_move_to(m_cairo, nCoords[0].x, nCoords[0].y);
    for(unsigned int i = 0; i<nCoords.size(); i++)
        cairo_line_to(m_cairo, nCoords[i].x, nCoords[i].y);

    cairo_stroke(m_cairo);
}
void Viewport::drawLine(Object* obj){
    auto coords = obj->getCoords();
    if(coords[0] == coords[1]){// Usuario quer um ponto?
        drawPoint(obj);
        return;
    }
    coords = transformCoordinates(coords);
    prepareContext();

    cairo_move_to(_cairo, coords[0].x, coords[0].y);
    cairo_line_to(_cairo, coords[1].x, coords[1].y);
    cairo_stroke(_cairo);
}
void OpenGLMethods::paintCubeToOpenGLList(int xLow, int yLow, int zLow, int xHigh, int yHigh, int zHigh,
    int listID, bool paintFullCube, int scale, int offsetX, int offsetY, int offsetZ,
    int r, int g, int b, bool beginList, bool endList)
{
  GLUquadricObj* pQuadric = gluNewQuadric();

  if(beginList)
    glNewList(listID, GL_COMPILE_AND_EXECUTE);

  float xH = transformCoordinates(scale, offsetX, xHigh);
  float yH = transformCoordinates(scale, offsetY, yHigh);
  float zH = transformCoordinates(scale, offsetZ, zHigh);
  float xL = transformCoordinates(scale, offsetX, xLow);
  float yL = transformCoordinates(scale, offsetY, yLow);
  float zL = transformCoordinates(scale, offsetZ, zLow);

  glBegin(GL_LINE_LOOP);
  glColor3ub((unsigned char)r, (unsigned char)g, (unsigned char)b);
  glVertex3d(xL, yL, zL);
  glVertex3d(xH, yL, zL);
  glVertex3d(xH, yH, zL);
  glVertex3d(xL, yH, zL);
  glEnd();

  if(paintFullCube)
  {
    glBegin(GL_LINE_LOOP);
    glVertex3d(xL, yL, zH);
    glVertex3d(xH, yL, zH);
    glVertex3d(xH, yH, zH);
    glVertex3d(xL, yH, zH);
    glEnd();

    glBegin(GL_LINES);

    glVertex3d(xL, yL, zL);
    glVertex3d(xL, yL, zH);
    glVertex3d(xH, yL, zL);
    glVertex3d(xH, yL, zH);
    glVertex3d(xH, yH, zL);
    glVertex3d(xH, yH, zH);
    glVertex3d(xL, yH, zL);
    glVertex3d(xL, yH, zH);

    glEnd();
  }
  if(endList)
    glEndList();

  gluDeleteQuadric(pQuadric);
}
Example #7
0
//------------------------------
void MolState::align()
{
  // Shift center of mass to the origin:
  shiftCoordinates( getCenterOfMass() );

  // Aligh moment of inertia principal axes:
  KMatrix MOI_tensor(3,3), MOI_eigenValues(3,1), MOI_eigenVectors(3,3);
  MOI_tensor = getMomentOfInertiaTensor();
  //MOI_tensor.Print("Moment of inertia tensor");
  MOI_eigenVectors=MOI_tensor.Herm_Diag(MOI_eigenValues, true); // true=>eigen vals in the descending order; eigen vectors in ROWS.
  // MOI_eigenVectors.Print("MOI eigen vectors");
  // MOI_eigenValues.Print("MOI eigen values");
  
  // compute the determinant of MOI matrix:
  double det_tmp =  MOI_eigenVectors.Determinant();
  // if determinant is = 1 than it is a proper rotation; 
  // if it is = -1 than it is rotation+reflection (switch from left handed to the right handed coord.system); swap x&y axes:
  if (det_tmp < 0)
    MOI_eigenVectors.SwapRows(0,1);

  transformCoordinates(MOI_eigenVectors); // rotate coordinates using matrix of the MOI eigen vectors 

  std::cout << "Coordinate axes were aligned with MOI principal axes; center mass was shifted to the origin.\n";
}