Announcement

Collapse
No announcement yet.

about SoVolumeClippingGroup

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • about SoVolumeClippingGroup

    Hi, mike,

    I want to create a cylinder with SoVolumeClippingGroup. But it remains a cube, no matter I use SoCylinder, SoSphere or SoExtrusion. Why?

    My Codes:


    SoSeparator createCylinder( float centerX, float centerY, float radius, float minz, float maxz, SbBox3f extent, SDoubl2D coordnormal, int numSides )
    {
    if ( numSides < 3 || radius <= 0 ) return NULL;

    float xmin, xmax, ymin, ymax, zmin, zmax;
    extent.getBounds( xmin, ymin, zmin, xmax, ymax, zmax );

    float theta = 0.0f;
    float dTheta = (float)(2.0 * M_PI / (double)numSides);

    SoShapeHints *shapehint = new SoShapeHints;
    shapehint->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
    shapehint->shapeType = SoShapeHints::SOLID;
    shapehint->creaseAngle = (float)(SR3D_MPI/2.1);

    SbVec3f vecxyz[2];
    vecxyz[0].setValue( minz, centerY - coordnormal.y, centerX - coordnormal.x );
    vecxyz[1].setValue( maxz, centerY - coordnormal.y, centerX - coordnormal.x );

    SoExtrusion *extrusion = new SoExtrusion;
    extrusion->crossSection.setNum( numSides + 1 );

    float xx, zz;
    for ( int idx = 0; idx < numSides; idx ++ )
    {
    xx = sin( theta );
    zz = cos( theta );
    extrusion->crossSection.set1Value( idx, SbVec2f( xx,zz ) );

    /* ptpos[idx][0] = minz;
    ptpos[idx][1] = centerY - (float)cos(theta) * radius - coordnormal.y;
    ptpos[idx][2] = centerX + (float)sin(theta) * radius - coordnormal.x;

    if ( ptpos[idx][1] < ymin ) ptpos[idx][1] = ymin;
    if ( ptpos[idx][1] > ymax ) ptpos[idx][1] = ymax;

    if ( ptpos[idx][2] < zmin ) ptpos[idx][2] = zmin;
    if ( ptpos[idx][2] > zmax ) ptpos[idx][2] = zmax;

    ptpos[idx+numFaces][0] = maxz;
    ptpos[idx+numFaces][1] = centerY - (float)cos(theta) * radius - coordnormal.y;
    ptpos[idx+numFaces][2] = centerX + (float)sin(theta) * radius - coordnormal.x;

    if ( ptpos[idx+numFaces][1] < ymin ) ptpos[idx+numFaces][1] = ymin;
    if ( ptpos[idx+numFaces][1] > ymax ) ptpos[idx+numFaces][1] = ymax;

    if ( ptpos[idx+numFaces][2] < zmin ) ptpos[idx+numFaces][2] = zmin;
    if ( ptpos[idx+numFaces][2] > zmax ) ptpos[idx+numFaces][2] = zmax;*/

    theta += dTheta;
    }

    extrusion->crossSection.set1Value( numSides, SbVec2f(0,1.0f) );
    extrusion->spine.setValues( 0, 2, vecxyz );
    extrusion->scale.setValue ( SbVec2f(500, 500) );

    SoSeparator *cylinderSep = new SoSeparator;
    cylinderSep->addChild( shapehint );
    cylinderSep->addChild( extrusion );

    return cylinderSep;
    }


    void MakeVolumeCropCylinderCube( QString volumedataname, float centerX, float centerY, float radius, float minz, float maxz, SbBox3f extent, int resolution, SoTransferFunction*transfunction, double transformcenter[3], double transformangle,SDoubl2D coordnormal )
    {
    if ( volumedataname.isEmpty() || !transfunction ) return;

    SoVolumeRendering::init();

    SoSwitch * m_pRootSwitch = new SoSwitch;
    m_pRootSwitch->removeAllChildren();
    m_pRootSwitch->ref();
    m_pRootSwitch->whichChild = SO_SWITCH_ALL;

    SoSeparator *objseparator = new SoSeparator;
    objseparator->renderCaching = SoSeparator::OFF;
    m_pRootSwitch->addChild( objseparator );

    ////////////////////////////////////////////////////
    QByteArray ba = volumedataname.toLocal8Bit();
    SoVolumeData *pvolumedata = new SoVolumeData;
    pvolumedata->fileName.setValue( ba.data() );

    #ifdef DATA_LDM_ORI
    pvolumedata->extent.setValue( extent );
    #endif

    pvolumedata->setLDM( true );
    pvolumedata->usePalettedTexture = TRUE;
    pvolumedata->storageHint=SoVolumeData::TEX2D;
    pvolumedata->ldmResourceParameters.getValue()->loadPolicy.setValue(SoVolumeData::LDMResourcePara meter::NO_USER_INTERACTION);
    pvolumedata->ldmResourceParameters.getValue()->maxResolutionThreshold.setValue(resolution);
    pvolumedata->ldmResourceParameters.getValue()->tex2LoadRate = 2;
    pvolumedata->ldmResourceParameters.getValue()->tex3LoadRate = 2;

    ////////////////////////////////////////////////////////////////////////////////
    SoTransform *transform = new SoTransform;
    transform->translation.setValue( coordnormal.x, coordnormal.y, 0 );

    transform->center.setValue( transformcenter[0]-coordnormal.x, transformcenter[1]-coordnormal.y, 0 );
    if ( fabs(transformangle) > 0.001 )
    {
    transform->rotation.setValue( SbVec3f(0, 0, 1), transformangle );
    }

    SbMatrix matri;
    SbRotation q( SbVec3f( 0, 1, 0 ), SR3D_PIO2*transformangle/fabs(transformangle) );
    matri.setRotate( q );
    transform->multLeft( matri );

    /////////////////////////////////////////////////////////////////////////////////////////////////

    SoTransferFunction *trans = new SoTransferFunction;
    trans->colorMap.deleteValues( 0, -1 );
    trans->predefColorMap = transfunction->predefColorMap;
    trans->colorMap = transfunction->colorMap;

    // Node in charge of drawing the volume
    SoVolumeRender *pVolRender = new SoVolumeRender;
    pVolRender->numSlicesControl = SoVolumeRender::AUTOMATIC;
    pVolRender->viewAlignedSlices = TRUE;
    //pVolRender->lowResMode = SoVolumeRender:ECREASE_SCREEN_RESOLUTION;
    //pVolRender->lowScreenResolutionScale = 2;
    //pVolRender->subdivideTile = TRUE;

    SoVolumeRenderingQuality *quality = new SoVolumeRenderingQuality;
    quality->preIntegrated = TRUE;
    quality->jittering = TRUE;

    SoTransform *transform1 = new SoTransform;
    transform1->translation.setValue( centerY - coordnormal.y, centerX - coordnormal.x, 0 );

    SoVolumeClippingGroup *volClip = new SoVolumeClippingGroup;
    SoSeparator *cylinder = createCylinder( centerX, centerY, radius, minz, maxz, extent, coordnormal, 16 );
    volClip->addChild(cylinder);

    objseparator->insertChild( transform, 0 );
    objseparator->insertChild( pvolumedata, 1 );
    objseparator->insertChild( trans, 2 );
    objseparator->insertChild( quality, 3 );
    objseparator->insertChild( volClip, 4 );
    objseparator->insertChild( pVolRender, 5 );
    }
Working...
X