コード例 #1
0
void TransferFunctionTest::shallowAndDeepCopyTest()
{
    const ::fwData::TransferFunction::sptr tf = this->createTFColor();
    this->checkTFColor(tf);

    const ::fwData::TransferFunction::sptr deepCopyTf = ::fwData::Object::copy( tf );
    this->checkTFColor(deepCopyTf);

    const ::fwData::TransferFunction::sptr shallowCopyTf = ::fwData::TransferFunction::New();
    shallowCopyTf->shallowCopy( tf );
    this->checkTFColor(shallowCopyTf);
}
コード例 #2
0
void TransferFunction::toVtkLookupTable(
        ::fwData::TransferFunction::sptr tf,
         vtkSmartPointer<vtkLookupTable> lt,
        bool allowTransparency,
        unsigned int size )
{
    SLM_WARN_IF( "Sorry, This transfer function conversion not managed clamped TF.", tf->getIsClamped() );

    // Configures basic parameters
    lt->SetNumberOfTableValues( size );
    lt->SetScaleToLinear();


    ::fwData::TransferFunction::TFValuePairType minMax = tf->getMinMaxTFValues();

    lt->SetTableRange( minMax.first, minMax.second );

    double delta = ( minMax.second - minMax.first ) / (double) (size - 1);
    ::fwData::TransferFunction::TFColor interpolatedColor;

    if ( allowTransparency )
    {
        for( unsigned int k=0; k<size; ++k )
        {
            interpolatedColor = tf->getInterpolatedColor( k*delta + minMax.first );
            lt->SetTableValue(k, interpolatedColor.r, interpolatedColor.g, interpolatedColor.b, interpolatedColor.a);
        }
    }
    else
    {
        for( unsigned int k=0; k<size; ++k )
        {
            interpolatedColor = tf->getInterpolatedColor( k*delta + minMax.first );
            lt->SetTableValue(k, interpolatedColor.r, interpolatedColor.g, interpolatedColor.b, 1.0);
        }
    }

    lt->Modified();
}
コード例 #3
0
void TransferFunctionTest::checkTFColor( ::fwData::TransferFunction::sptr tf )
{

    CPPUNIT_ASSERT( ::fwData::TransferFunction::TFColor( 1.0, 0.3, 0.6, 0.1) == tf->getBackgroundColor() );
    CPPUNIT_ASSERT_EQUAL( ::fwData::TransferFunction::NEAREST, tf->getInterpolationMode() );
    CPPUNIT_ASSERT_EQUAL( false, tf->getIsClamped() );
    CPPUNIT_ASSERT_EQUAL( 900.6, tf->getLevel() );
    CPPUNIT_ASSERT_EQUAL( std::string("TFColor"), tf->getName() );
    CPPUNIT_ASSERT_EQUAL( -200.02, tf->getWindow() );

    CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(4), tf->getTFData().size() );
    CPPUNIT_ASSERT_EQUAL( -40.33, tf->getMinMaxTFValues().first );
    CPPUNIT_ASSERT_EQUAL( 150.0, tf->getMinMaxTFValues().second );

    const TransferFunction::TFValueVectorType& values = tf->getTFValues();
    CPPUNIT_ASSERT_EQUAL( values[0], -40.33  );
    CPPUNIT_ASSERT_EQUAL( values[1], -0.2    );
    CPPUNIT_ASSERT_EQUAL( values[2], 3.0      );
    CPPUNIT_ASSERT_EQUAL( values[3], 150.0     );

    CPPUNIT_ASSERT( ::fwData::TransferFunction::TFColor( 0.9, 0.2, 0.3, 0.4) == tf->getTFColor( -40.33 ) );
    CPPUNIT_ASSERT( ::fwData::TransferFunction::TFColor( 0.1, 0.9, 0.3, 0.4) == tf->getTFColor( -0.2   ) );
    CPPUNIT_ASSERT( ::fwData::TransferFunction::TFColor( 0.1, 0.2, 0.9, 0.4) == tf->getTFColor( 3      ) );
    CPPUNIT_ASSERT( ::fwData::TransferFunction::TFColor( 0.1, 0.2, 0.3, 0.9) == tf->getTFColor( 150    ) );

    CPPUNIT_ASSERT_EQUAL( std::string("fieldStringValue"),
                          ::fwData::String::dynamicCast( tf->getField( "fieldStringKey" ) )->value() );
}