TuttleOFX  1
TuttleOFX/libraries/tuttle/tests/graph/graph.cpp
Go to the documentation of this file.
00001 #include <tuttle/test/unit_test.hpp>
00002 
00003 #include <tuttle/host/Graph.hpp>
00004 #include <tuttle/host/Node.hpp>
00005 
00006 #include <iostream>
00007 
00008 using namespace boost::unit_test;
00009 using namespace tuttle::host;
00010 
00011 BOOST_AUTO_TEST_SUITE( tuttle_graph )
00012 
00013 BOOST_AUTO_TEST_CASE( create_node )
00014 {
00015         TUTTLE_LOG_INFO( "--> PLUGINS CREATION" );
00016         Graph g;
00017         BOOST_CHECK_NO_THROW( g.createNode( "tuttle.invert" ) );
00018         TUTTLE_LOG_INFO( "----------------- DONE -----------------" );
00019 }
00020 
00021 BOOST_AUTO_TEST_CASE( graph_copy )
00022 {
00023         TUTTLE_LOG_INFO( "--> PLUGINS CREATION" );
00024         Graph g;
00025         Graph::Node& read1  = g.createNode( "tuttle.pngreader" );
00026         Graph::Node& invert1 = g.createNode( "tuttle.invert" );
00027         Graph::Node& invert2 = g.createNode( "tuttle.invert" );
00028         Graph::Node& write1 = g.createNode( "tuttle.pngwriter" );
00029 
00030         TUTTLE_LOG_INFO( "-------- GRAPH CONNECTION --------" );
00031         g.connect( read1, invert1 );
00032         g.connect( invert1, invert2 );
00033         g.connect( invert2, write1 );
00034 
00035         TUTTLE_LOG_INFO( "-------- GRAPH COPY --------" );
00036         Graph g2(g);
00037         
00038         BOOST_CHECK_NE( &g2.getNode( read1.getName() ), &read1 );
00039         BOOST_CHECK_EQUAL( g2.getNode( read1.getName() ).getName(), read1.getName() );
00040         TUTTLE_LOG_INFO( "----------------- DONE -----------------" );
00041 }
00042 
00043 BOOST_AUTO_TEST_CASE( graph_NodeInit )
00044 {
00045         TUTTLE_LOG_INFO( "--> PLUGINS NodeInit" );
00046         
00047         BOOST_CHECK(
00048                 compute(
00049                         list_of
00050                         ( NodeInit("tuttle.pngreader")
00051                                 .setParam("filename", "TuttleOFX-data/image/png/color-chart.png")
00052                                 .setParamExp("bitDepth", "32f") )
00053                         ( NodeInit("tuttle.pngwriter")
00054                                 .setParam("filename", ".tests/graph/output.png") )
00055                         ) );
00056         
00057         TUTTLE_LOG_INFO( "----------------- DONE -----------------" );
00058 }
00059 
00060 BOOST_AUTO_TEST_CASE( graph_unconnect )
00061 {
00062         TUTTLE_LOG_INFO( "--> PLUGINS unconnect" );
00063         Graph g;
00064         g.addConnectedNodes(
00065                 list_of
00066                 ( NodeInit("tuttle.pngreader")
00067                         .setParam("filename", "TuttleOFX-data/image/png/color-chart.png")
00068                         .setParamExp("bitDepth", "32f") )
00069                 ( NodeInit("tuttle.invert") )
00070                 ( NodeInit("tuttle.invert") )
00071                 ( NodeInit("tuttle.invert") )
00072                 ( NodeInit("tuttle.pngwriter")
00073                         .setParam("filename", ".tests/graph/output.png") )
00074                 );
00075         
00076         std::vector<Graph::Node*> invNodes = g.getNodesByPlugin( "tuttle.invert" );
00077         
00078         BOOST_FOREACH( Graph::Node* n, invNodes )
00079         {
00080                 BOOST_CHECK_EQUAL( g.getNbInputConnections(*n), 1 );
00081                 BOOST_CHECK_EQUAL( g.getNbOutputConnections(*n), 1 );
00082         }
00083         g.unconnect( *invNodes[1] );
00084         
00085         BOOST_CHECK_EQUAL( g.getNbInputConnections(*invNodes[0]), 1 );
00086         BOOST_CHECK_EQUAL( g.getNbOutputConnections(*invNodes[0]), 0 );
00087         
00088         BOOST_CHECK_EQUAL( g.getNbInputConnections(*invNodes[1]), 0 );
00089         BOOST_CHECK_EQUAL( g.getNbOutputConnections(*invNodes[1]), 0 );
00090         
00091         BOOST_CHECK_EQUAL( g.getNbInputConnections(*invNodes[2]), 0 );
00092         BOOST_CHECK_EQUAL( g.getNbOutputConnections(*invNodes[2]), 1 );
00093         
00094         TUTTLE_LOG_INFO( "----------------- DONE -----------------" );
00095 }
00096 
00097 BOOST_AUTO_TEST_CASE( graph_replaceNodeConnections )
00098 {
00099         TUTTLE_LOG_INFO( "--> PLUGINS replace node connections" );
00100         Graph g;
00101         g.addConnectedNodes(
00102                 list_of
00103                 ( NodeInit("tuttle.pngreader")
00104                         .setParam("filename", "TuttleOFX-data/image/png/color-chart.png")
00105                         .setParamExp("bitDepth", "32f") )
00106                 ( NodeInit("tuttle.invert") )
00107                 ( NodeInit("tuttle.pngwriter")
00108                         .setParam("filename", ".tests/graph/output.png") )
00109                 );
00110         
00111         Graph::Node& inv = *g.getNodesByPlugin( "tuttle.invert" ).front();
00112         
00113         Graph::Node& blur = g.addNode( NodeInit("tuttle.blur").setParam( "size", 0.01, 0.02 ) );
00114         
00115         BOOST_CHECK_EQUAL( blur.getParam( "size" ).getDoubleValueAtIndex(0), 0.01 );
00116         BOOST_CHECK_EQUAL( blur.getParam( "size" ).getDoubleValueAtIndex(1), 0.02 );
00117         
00118         BOOST_CHECK_EQUAL( g.getNbInputConnections(inv), 1 );
00119         BOOST_CHECK_EQUAL( g.getNbOutputConnections(inv), 1 );
00120         
00121         BOOST_CHECK_EQUAL( g.getNbInputConnections(blur), 0 );
00122         BOOST_CHECK_EQUAL( g.getNbOutputConnections(blur), 0 );
00123         
00124         g.replaceNodeConnections( inv, blur );
00125         
00126         BOOST_CHECK_EQUAL( g.getNbInputConnections(inv), 0 );
00127         BOOST_CHECK_EQUAL( g.getNbOutputConnections(inv), 0 );
00128         
00129         BOOST_CHECK_EQUAL( g.getNbInputConnections(blur), 1 );
00130         BOOST_CHECK_EQUAL( g.getNbOutputConnections(blur), 1 );
00131         
00132         BOOST_CHECK( g.compute( *g.getNodesByPlugin( "tuttle.pngwriter" ).front() ) );
00133         TUTTLE_LOG_INFO( "----------------- DONE -----------------" );
00134 }
00135 
00136 BOOST_AUTO_TEST_CASE( create_processGraph )
00137 {
00138         TUTTLE_LOG_INFO( "--> PLUGINS CREATION" );
00139         Graph g;
00140         Graph::Node& read1 = g.createNode( "tuttle.jpegreader" );
00141         Graph::Node& read2 = g.createNode( "tuttle.jpegreader" );
00142         Graph::Node& invert1 = g.createNode( "tuttle.invert" );
00143         Graph::Node& invert2 = g.createNode( "tuttle.invert" );
00144         Graph::Node& invert3 = g.createNode( "tuttle.invert" );
00145         Graph::Node& invert4 = g.createNode( "tuttle.invert" );
00146         /*Graph::Node& crop1   = */ g.createNode( "tuttle.crop" ); // add unused node
00147         Graph::Node& merge1 = g.createNode( "tuttle.merge" );
00148         Graph::Node& write1 = g.createNode( "tuttle.pngwriter" );
00149         Graph::Node& write4 = g.createNode( "tuttle.pngwriter" );
00150         Graph::Node& write2 = g.createNode( "tuttle.jpegwriter" );
00151         Graph::Node& write3 = g.createNode( "tuttle.exrwriter" );
00152 
00153         TUTTLE_LOG_INFO( "--> PLUGINS CONFIGURATION" );
00154         // Setup parameters
00155         read1.getParam( "filename" ).setValue( "TuttleOFX-data/image/jpeg/GRN.JPG" );
00156         read1.getParam( "bitDepth" ).setValue( 3 );
00157         read2.getParam( "filename" ).setValue( "TuttleOFX-data/image/jpeg/RED.JPG" );
00158         read2.getParam( "bitDepth" ).setValue( 3 );
00159         //bitdepth.getParam( "outputBitDepth" ).setValue( 3 );
00160         //      crop1.getParam( "Down" ).setValue( 400 );
00161         write1.getParam( "filename" ).setValue( ".tests/processGraph/output1.png" );
00162         write2.getParam( "filename" ).setValue( ".tests/processGraph/output2.jpg" );
00163         write3.getParam( "filename" ).setValue( ".tests/processGraph/output3.exr" );
00164         write4.getParam( "filename" ).setValue( ".tests/processGraph/output4.png" );
00165 
00166         TUTTLE_LOG_INFO( "-------- GRAPH CONNECTION --------" );
00167         TUTTLE_TLOG( TUTTLE_TRACE, "connect" );
00168         g.connect( read1, invert1 );
00169         TUTTLE_TLOG( TUTTLE_TRACE, "connect" );
00170         //              g.connect( invert1, bitdepth );
00171         TUTTLE_TLOG( TUTTLE_TRACE, "connect" );
00172         g.connect( invert1, invert2 );
00173         TUTTLE_TLOG( TUTTLE_TRACE, "connect" );
00174         g.connect( invert2, invert3 );
00175         TUTTLE_TLOG( TUTTLE_TRACE, "connect" );
00176         g.connect( invert3, write1 );
00177         TUTTLE_TLOG( TUTTLE_TRACE, "connect" );
00178         g.connect( invert1, invert4 );
00179         TUTTLE_TLOG( TUTTLE_TRACE, "connect" );
00180         g.connect( invert4, write2 );
00181         TUTTLE_TLOG( TUTTLE_TRACE, "connect" );
00182         g.connect( invert1, write3 );
00183 
00184         TUTTLE_LOG_INFO( "-------- GRAPH CONNECT CLIPS --------" );
00185         g.connect( invert1, merge1.getAttribute( "A" ) );
00186         g.connect( read2, merge1.getAttribute( "B" ) );
00187         g.connect( merge1, write4 );
00188 
00189         TUTTLE_LOG_INFO( "-------- SET GRAPH OUTPUTS --------" );
00190         std::list<std::string> outputs;
00191         outputs.push_back( write1.getName() );
00192         outputs.push_back( write2.getName() );
00193         outputs.push_back( write3.getName() );
00194         outputs.push_back( write4.getName() );
00195         
00196         TUTTLE_LOG_INFO( "-------- GRAPH PROCESSING --------" );
00197 //      BOOST_CHECK_NO_THROW( g.compute( outputs ) ); /// @todo Bug: error with merge
00198 
00199         TUTTLE_LOG_INFO( "----------------- DONE -----------------" );
00200 }
00201 
00202 BOOST_AUTO_TEST_CASE( graph_compute )
00203 {
00204         TUTTLE_LOG_INFO( "--> PLUGINS CREATION" );
00205         Graph g;
00206         Graph::Node& read1  = g.createNode( "tuttle.pngreader" );
00207         Graph::Node& read2  = g.createNode( "tuttle.pngreader" );
00208         Graph::Node& invert1 = g.createNode( "tuttle.invert" );
00209         Graph::Node& merge1 = g.createNode( "tuttle.merge" );
00210         Graph::Node& write1 = g.createNode( "tuttle.pngwriter" );
00211 
00212         TUTTLE_LOG_INFO( "--> PLUGINS CONFIGURATION" );
00213         read1.getParam( "filename" ).setValue( "TuttleOFX-data/image/png/RGB16Million.png" );
00214         read1.getParam( "bitDepth" ).setValue( 3 );
00215         
00216         read2.getParam( "filename" ).setValue( "TuttleOFX-data/image/png/RGB16Million.png" );
00217         read2.getParam( "bitDepth" ).setValue( 3 );
00218         
00219         write1.getParam( "filename" ).setValue( ".tests/computeGraph/output.png" );
00220         
00221         TUTTLE_LOG_INFO( "-------- GRAPH CONNECTION --------" );
00222         g.connect( read1, invert1 );
00223         g.connect( read2, merge1.getClip("A") );
00224         g.connect( invert1, merge1.getClip("B") );
00225         g.connect( merge1, write1 );
00226 
00227 //      BOOST_CHECK_NO_THROW( g.compute( write1 ) ); /// @toto
00228         TUTTLE_LOG_INFO( "----------------- DONE -----------------" );
00229 }
00230 
00231 BOOST_AUTO_TEST_SUITE_END()
00232