Ejemplo n.º 1
0
QVector<Eigen::AlignedBox3d> splitBox( const Eigen::AlignedBox3d & box, Vector3 axis )
{
	Eigen::AlignedBox3d b1 = box, b2 = box;
	Vector3 delta = axis.array() * ((box.sizes() * 0.5).array());
	return QVector<Eigen::AlignedBox3d>() << box.intersection(b1.translate(-delta)) <<
		box.intersection(b2.translate(delta));
}
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;
}
Ejemplo n.º 3
0
 void render(){
     /// Set line width
     /// @todo this should become a parameter
     glLineWidth(1.0f);
     
     /// Setup BBOX color
     Eigen::AlignedBox3d bbox = model()->bbox();
     QColor& c = model()->color;
     glColor3f(c.redF(),c.greenF(),c.blueF());
     
     float min[3]; 
     min[0] = bbox.min().x();
     min[1] = bbox.min().y();
     min[2] = bbox.min().z();
 
     float max[3]; 
     max[0] = bbox.max().x();
     max[1] = bbox.max().y();
     max[2] = bbox.max().z();
         
     /// --- Inherited from VCG ---
     glPushAttrib(GL_ENABLE_BIT);
     glDisable(GL_LIGHTING);
     glBegin(GL_LINE_STRIP);
     glVertex3f((float)min[0],(float)min[1],(float)min[2]);
     glVertex3f((float)max[0],(float)min[1],(float)min[2]);
     glVertex3f((float)max[0],(float)max[1],(float)min[2]);
     glVertex3f((float)min[0],(float)max[1],(float)min[2]);
     glVertex3f((float)min[0],(float)min[1],(float)min[2]);
     glEnd();
     glBegin(GL_LINE_STRIP);
     glVertex3f((float)min[0],(float)min[1],(float)max[2]);
     glVertex3f((float)max[0],(float)min[1],(float)max[2]);
     glVertex3f((float)max[0],(float)max[1],(float)max[2]);
     glVertex3f((float)min[0],(float)max[1],(float)max[2]);
     glVertex3f((float)min[0],(float)min[1],(float)max[2]);
     glEnd();
     glBegin(GL_LINES);
     glVertex3f((float)min[0],(float)min[1],(float)min[2]);
     glVertex3f((float)min[0],(float)min[1],(float)max[2]);
     glVertex3f((float)max[0],(float)min[1],(float)min[2]);
     glVertex3f((float)max[0],(float)min[1],(float)max[2]);
     glVertex3f((float)max[0],(float)max[1],(float)min[2]);
     glVertex3f((float)max[0],(float)max[1],(float)max[2]);
     glVertex3f((float)min[0],(float)max[1],(float)min[2]);
     glVertex3f((float)min[0],(float)max[1],(float)max[2]);
     glEnd();
     glPopAttrib();    
 }
Ejemplo n.º 4
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;
    }
Ejemplo n.º 6
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();
    }
}