void HxGLSLVertexView::compute()
{
    // data has changed ?
    if (portData.isNew())
    {
        HxVertexSet* data = hxconnection_cast<HxVertexSet>(portData);
        
        if (data)
        {
            m_p_vertexProperty->vertex.setValuesPointer(data->getNumPoints(), (SbVec3f*)data->getCoords());

            showGeom(m_p_root);
        }
        else
        {
            m_p_vertexProperty->vertex.setNum(0);

            hideGeom(m_p_root);
        }
    }

    if (portSphereScale.isNew())
    {
        m_p_sphereSizeParameter->value = portSphereScale.getValue();
    }
}
示例#2
0
void MyDisplayVertices1::compute()
{
    int i;

    // Access input object (portData is inherited from HxModule):
    HxSurface* surface = (HxSurface*) portData.source();

    if (!surface) { // Check if input object is available
        hideGeom(scene);
	return;
    }

    // Get value from input port, query size of surface:
    int numTriPerVertex = portNumTriangles.getValue();
    int nVertices = surface->points.size();
    int nTriangles = surface->triangles.size();

    // We need a triangle counter for every vertex: 
    McDArray<unsigned short> triCount(nVertices);
    triCount.fill(0);
    
    // Loop through all triangles and increase counter of the vertices:
    for (i=0; i<nTriangles; i++)
        for (int j=0; j<3; j++)
            triCount[surface->triangles[i].points[j]]++;

    // Now create the scene graph. First remove all previous childs:
    scene->removeAllChildren();
    
    // Cube size should be 1% of the diagonal of the bounding box.
    float size = surface->getBoundingBoxSize().length() * 0.01;

    // Pointer to surface coordinates casted from McVec3f to SbVec3f.
    SbVec3f* p = (SbVec3f*) surface->points.dataPtr();

    SbVec3f q(0,0,0); // position of last point
    int count = 0; // vertex counter

    for (i=0; i<nVertices; i++) {
        if (triCount[i] == numTriPerVertex) {
            SoTranslation* trans = new SoTranslation;
            trans->translation.setValue(p[i]-q);

            SoCube* cube = new SoCube;
            cube->width = cube->height = cube->depth = size;

            scene->addChild(trans);
            scene->addChild(cube);

            count++;
            q=p[i];
        }
    }

    theMsg->printf("Found %d vertices belonging to %d triangles",
        count, numTriPerVertex);

    showGeom(scene); // finally show scene in viewer
}