QString printBounding(const Eigen::AlignedBox3d& box){
    QString retval;
    QTextStream sout(&retval);
    Vector3 c = box.center();
    Vector3 s = box.diagonal();
    sout << "Center[" << c.x() << " " << c.y() << " " << c.z() << "]" 
         << "  Size[" << s.x() << " " << s.y() << " " << s.z() << "]";
    return retval;
}
Example #2
0
Eigen::AlignedBox3d Sheet::bbox(double scaling)
{
    Eigen::AlignedBox3d box;

    foreach(std::vector<Vector3d> cps, surface.mCtrlPoint)
        foreach(Vector3d cp, cps)
            box = box.merged( Eigen::AlignedBox3d(cp, cp) );

	// Scaling
	Eigen::Vector3d diagonal = box.diagonal() * 0.5;
	Eigen::Vector3d a = box.center() + (diagonal * scaling);
	Eigen::Vector3d b = box.center() - (diagonal * scaling);

	box = box.merged( Eigen::AlignedBox3d(a,a) );
	box = box.merged( Eigen::AlignedBox3d(b,b) );

    return box;
}
void surfacemesh_filter_normalize::applyFilter(RichParameterSet*){
    qDebug() << "Old bounding box: " << printBounding(mesh()->bbox());
    
    /// Just to be sure... update it
    mesh()->updateBoundingBox();        
    Eigen::AlignedBox3d bbox = mesh()->bbox();
    Vector3 offset = bbox.center();
    
    /// Normalize to have longest side size = 1
    Vector3 s = bbox.diagonal();
    Scalar scale = qMax(s.x(),qMax(s.y(),s.z()));
 
    Vector3VertexProperty points = mesh()->vertex_coordinates();
    foreach(Vertex v, mesh()->vertices()){
        Point& p = points[v];
        p.x() -= offset.x();
        p.y() -= offset.y();
        p.z() -= offset.z();
        p.x() /= scale;
        p.y() /= scale;
        p.z() /= scale;
    }
Example #4
0
void Viewer::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if(false)
    {
        // Default camera:
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glFrustum(-2, 2, -1.5, 1.5, 1, 40);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0, 0, -3);
        glRotatef(50, 1, 0, 0);
        glRotatef(70, 0, 1, 0);

        // Draw a white grid "floor" for the tetrahedron to sit on.
        glColor3d(0.8, 0.8, 0.7);
        glBegin(GL_LINES);
        for (GLfloat i = -2.5; i <= 2.5; i += 0.25) {
            glVertex3f(i, 2.5, 0); glVertex3f(i, -2.5, 0);
            glVertex3f(2.5, i, 0); glVertex3f(-2.5, i, 0);
        }
        glEnd();

        // Draw the tetrahedron.
        if(false)
        {
            glBegin(GL_TRIANGLE_STRIP);
            glColor3f(1, 1, 1); glVertex3f(0, 0, 2);
            glColor3f(1, 0, 0); glVertex3f(-1, 1, 0);
            glColor3f(0, 1, 0); glVertex3f(1, 1, 0);
            glColor3f(0, 0, 1); glVertex3f(0, -1.4f, 0);
            glColor3f(1, 1, 1); glVertex3f(0, 0, 2);
            glColor3f(1, 0, 0); glVertex3f(-1, 1, 0);
            glEnd();
        }
    }

    if( !isReady ) return;

    // Setup camera
    Eigen::Vector3d center, eye;
    {
        // Bounding volume
        {
            Eigen::Vector3d dir( cos(t), sin(t), 0.25);

            Eigen::AlignedBox3d bbox; for(auto v : vertices) bbox.extend(v);
            double radius = bbox.sizes().norm() * 2.75;
            center = bbox.center();

            eye = center + (dir.normalized() * radius);
        }

        auto projectionMatrix = perspective<double>(20, 1.0, 0.01, 1000);
        auto cameraMatrix = lookAt< Eigen::Vector3d >(eye, center, Eigen::Vector3d(0,0,1));

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glLoadMatrixd( projectionMatrix.data() );
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glLoadMatrixd( cameraMatrix.data() );
    }

    // Added user rotation
    {
        glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
        glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
        glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
    }

    glColor3d(1,0,0);

    // Render geometry
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glColor3d(0,0,0);
        glDisable(GL_LIGHTING);
        glLineWidth(6);
        //RenderMesh();
        glClear(GL_DEPTH_BUFFER_BIT);

        //glEnable(GL_LIGHTING);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        glColor3d(0,0,0);
        RenderMesh();
    }
}