{"id":531,"date":"2014-10-03T09:51:31","date_gmt":"2014-10-03T12:51:31","guid":{"rendered":"http:\/\/hemolab.lncc.br\/web\/?p=531"},"modified":"2017-05-23T15:41:59","modified_gmt":"2017-05-23T18:41:59","slug":"tutorials-adding-external-funcionalities-to-imagelab","status":"publish","type":"post","link":"http:\/\/hemolab.lncc.br\/?p=531","title":{"rendered":"TUTORIALS > ADDING EXTERNAL FUNCIONALITIES TO IMAGELAB"},"content":{"rendered":"<p>The language development of plugins for ImageLab is the C + + and ambinete suggested for developing \/ using custom filters is Linux.<\/p>\n<p>To follow this tutorial, you will need to have installed the following packages:<\/p>\n<blockquote><p><em>cmake<br \/>\nccmake<br \/>\ng++<br \/>\ngcc<br \/>\nlibqt4-dev<br \/>\nlibqt4-gui<br \/>\nlibqtcore4<\/em><\/p><\/blockquote>\n<p><strong>VTK:<\/strong><\/p>\n<p>To develop a filter plugin, you must have a version of VTK is compiled and source code available.<\/p>\n<p>Install the package libvtk5-dev (Ubuntu: Go to &#8220;System-Administration&#8221; and start &#8220;Synaptic&#8221; and select the package) or download the source and compile VTK (do not use version 5.6.1):<\/p>\n<blockquote><p><em>http:\/\/www.vtk.org\/files\/release\/5.4\/vtkdata-5.4.2.tar.gz<br \/>\ntar -zxvf vtk-5.4.2.tar.gz<br \/>\nmkdir VTK_build<br \/>\ncd VTK_build<br \/>\nccmake ..\/VTK<\/em><\/p><\/blockquote>\n<p align=\"center\"><img decoding=\"async\" loading=\"lazy\" src=\"..\/wp-content\/uploads\/2014\/10\/plugin_1.jpg\" alt=\"\" width=\"520\" height=\"370\" \/><\/p>\n<p>Press the letter C (&#8220;Press [c] to configure&#8221;) until the following screen options appear:<\/p>\n<p align=\"center\"><img decoding=\"async\" loading=\"lazy\" src=\"..\/wp-content\/uploads\/2014\/10\/plugin_2.jpg\" alt=\"\" width=\"520\" height=\"370\" \/><\/p>\n<p>After, you need to change the value of some compilation variables: place the cursor over the option and enable editing of the value by pressing &#8220;enter&#8221;:<\/p>\n<blockquote><p><em>BUILD_EXAMPLES OFF<br \/>\nBUILD_SHARED_LIBS ON<br \/>\nBUILD_TESTING OFF<\/em><\/p><\/blockquote>\n<p>After, you need to change the value of some compilation variables: place the cursor over the option and enable editing of the value by pressing &#8220;enter&#8221;.<\/p>\n<p>Then, press the letter &#8220;g&#8221; to generate makefiles (the control will return to the terminal command)<\/p>\n<p>To compile the VTK: make or make-j2 (compilation generates two threads &#8211; the optimal number of threads is based on the number of process colors).<\/p>\n<p>Depending on the configuration of the machine, the compilation may take a while.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Programming the filter Plugin<\/strong><\/p>\n<p>Download the package with the auxiliary files to build the filter plugin:<\/p>\n<p><a href=\"http:\/\/hemo01a.lncc.br\/software\/ImageLab_dev\/imPluginFilter.tar.gz\" target=\"_blank\" rel=\"noopener noreferrer\"><em>http:\/\/hemo01a.lncc.br\/software\/ImageLab_dev\/imPluginFilter.tar.gz<\/em><\/a><\/p>\n<p>In this file there are implementations of the following classes:<\/p>\n<p><strong>imPluginBaseFilter<\/strong>: class &#8220;father&#8221; of the class that implements the filter plugin;<\/p>\n<p><strong>imPluginFilter<\/strong>: class in which the code that manipulates the pixels to be described &#8211; Update method.<\/p>\n<p>This class contains a reference to an object of type vtkImageData (this-&gt; image) that is the image itself.<\/p>\n<p>Other class methods vtkImageData:<br \/>\n<a href=\"http:\/\/www.vtk.org\/doc\/nightly\/html\/classvtkImageData.html\">http:\/\/www.vtk.org\/doc\/nightly\/html\/classvtkImageData.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Commands to compile the filter plugin:<\/strong><\/p>\n<blockquote><p><em>cd imPluginFilter<br \/>\nmkdir build<br \/>\ncd build<br \/>\nccmake ..\/<\/em><\/p><\/blockquote>\n<p>Within the environment of the CCMAKE, manually point the directory path where the compiled VTK (example: home \/ user \/ VTK \/ BUILD) VTK_DIR the variable &#8211; if the VTK has been installed packet, the path will be filled automatically.<\/p>\n<p>Generate the\u00a0makefiles\u00a0(using\u00a0the &#8220;g&#8221;).<\/p>\n<p>Compile the library containing the objects of the filter plugin with the command make.<\/p>\n<p>A library is generated with the following name:\u00a0<strong>libImageLabPluginFilter.so<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>To incorporate the library in ImageLab plugin, type the following command before starting the ImageLab<\/p>\n<p>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:\/path<\/p>\n<p>Path is the path where the generated file. Is located so.<\/p>\n<p><strong>Methods to be used in programming the filter:<\/strong><\/p>\n<p>Basically, the parameters are passed in vectors of integers and real values for the filter.<\/p>\n<p>Inside the filter class, access to parameters is done through the following methods:<\/p>\n<p>Returns reference to an array of type double with three positions (x, y, z) containing the coordinates of a given seed &#8211; returns NULL if the seed is not found:<br \/>\n<strong>double *GetSeed(int seedNumber);<\/strong><\/p>\n<p>Returns the value of a pixel assigned to a particular seed:<br \/>\n<strong>double GetSeedPixelValue(int seedNumber);<\/strong><\/p>\n<p>Returns the integer parameter (defined in the filter plugin interface) with index given by the parameter paramNumber:<br \/>\n<strong>int GetIntParam(int paramNumber);<\/strong><\/p>\n<p>Returns the actual parameter (defined in the filter plugin interface) with index given by the parameter paramNumber:<br \/>\n<strong>double GetDoubleParam(int paramNumber);<\/strong><\/p>\n<p><strong>Interface filter plugin:<\/strong><\/p>\n<p>The interface is pretty generic and it is intended that in future versions, in addition to the code, the user can also specify interfaces.<br \/>\nIn the figure below, one can see that there are basically three parameter fields:<br \/>\nThe first field is for integer parameters (these must be separated by a semicolon);<br \/>\nThe second field is for real and these parameters should also be separated by a semicolon;<br \/>\nThe last field specifies the seeds (seeds) &#8220;placed&#8221; in the image.<\/p>\n<p align=\"center\"><strong><img decoding=\"async\" loading=\"lazy\" src=\"..\/wp-content\/uploads\/2014\/10\/plugin_3.jpg\" alt=\"\" width=\"339\" height=\"477\" \/><\/strong><\/p>\n<p><strong>Examples of codes<\/strong><\/p>\n<p><strong>Example 1:&#8221;Hello World&#8221;<\/strong><\/p>\n<pre>cout &lt;&lt; \"Image with the following characteristics: \" &lt;&lt; endl; \r\ncout &lt;&lt; \"Number of dimensions of the image \"&lt;&lt; image-&gt;GetDataDimension() &lt;&lt; endl;\r\n\r\ndouble* spacing = image-&gt;GetSpacing();\r\n\r\ncout &lt;&lt; \"width -x: \"&lt;&lt; spacing[0] &lt;&lt; endl;\r\ncout &lt;&lt; \"height -y: \"&lt;&lt; spacing[1] &lt;&lt; endl;\r\ncout &lt;&lt; \"length -z: \"&lt;&lt; spacing[2] &lt;&lt; endl;\r\n\r\nint* dims = image-&gt;GetDimensions(); \/\/ get the size of the image array, x, y, z\r\n\r\ncout &lt;&lt; \"planos em x: \"&lt;&lt; dims[0] &lt;&lt; endl;\r\ncout &lt;&lt; \"planos em y: \"&lt;&lt; dims[1] &lt;&lt; endl;\r\ncout &lt;&lt; \"planos em z: \"&lt;&lt; dims[2] &lt;&lt; endl;<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Example 2: Threshold in terms of pixel value obtained from a seed<\/strong><\/p>\n<p><span class=\"type\">double<\/span> PixelValue<span class=\"operator\"> =<\/span><span class=\"keyword\"> this<\/span><span class=\"operator\">-&gt;<\/span>GetSeedPixelValue<span class=\"operator\">(<\/span><span class=\"int\">0<\/span><span class=\"operator\">);<\/span><\/p>\n<p>cout<span class=\"operator\"> &lt;&lt;<\/span><span class=\"string\"> &#8220;Value associated with pixel Seed 0 &#8220;<\/span><span class=\"operator\">&lt;&lt;<\/span> PixelValue<span class=\"operator\"> &lt;&lt;<\/span> endl<span class=\"operator\">;<\/span><\/p>\n<p>double limiteInf<span class=\"operator\">=<\/span> PixelValue<span class=\"operator\">;<\/span> <span class=\"comment\">\/\/ value obtained from the interface &#8211; that lower values are reset<\/span><\/p>\n<p>cout<span class=\"operator\"> &lt;&lt;<\/span><span class=\"string\"> &#8220;Pixel values that are less than &#8220;<\/span><span class=\"operator\"> &lt;&lt;<\/span> limiteInf<span class=\"operator\"> &lt;&lt;<\/span><span class=\"string\"> &#8221; will be cleared &#8221; &lt;<\/span><span class=\"operator\">&lt;&lt;<\/span> endl<span class=\"operator\">;<\/span><\/p>\n<blockquote><p><span class=\"flow\">for<\/span><span class=\"operator\"> (<\/span><span class=\"type\">int<\/span> y<span class=\"operator\">=<\/span><span class=\"int\">0<\/span><span class=\"operator\">;<\/span> y<span class=\"operator\">&lt;<\/span>dims<span class=\"operator\">[<\/span><span class=\"int\">1<\/span><span class=\"operator\">];<\/span> y<span class=\"operator\">++)<\/span><\/p>\n<p>{<\/p>\n<p><span class=\"flow\"> for<\/span><span class=\"operator\"> (<\/span><span class=\"type\">int<\/span> x<span class=\"operator\">=<\/span><span class=\"int\">0<\/span><span class=\"operator\">;<\/span> x<span class=\"operator\">&lt;<\/span>dims<span class=\"operator\">[<\/span><span class=\"int\">0<\/span><span class=\"operator\">];<\/span> x<span class=\"operator\">++)<\/span><\/p>\n<p>{<\/p>\n<p><span class=\"flow\">for<\/span><span class=\"operator\"> (<\/span><span class=\"type\">int<\/span> z<span class=\"operator\">=<\/span><span class=\"int\">0<\/span><span class=\"operator\">;<\/span> z<span class=\"operator\">&lt;<\/span>dims<span class=\"operator\">[<\/span><span class=\"int\">2<\/span><span class=\"operator\">];<\/span> z<span class=\"operator\">++)<\/span><\/p>\n<p>{<\/p>\n<p><span class=\"type\">double<\/span> CurrentPixelValue<span class=\"operator\"> =<\/span> image<span class=\"operator\">-&gt;<\/span>GetScalarComponentAsDouble<span class=\"operator\">(<\/span>x<span class=\"operator\">,<\/span>y<span class=\"operator\">,<\/span>z<span class=\"operator\">,<\/span><span class=\"int\">0<\/span><span class=\"operator\">);<\/span><\/p>\n<p>\/\/ Comparing the current pixel with the first real value<\/p>\n<p>\/\/ Placed at the interface of real parameters<\/p>\n<p><span class=\"flow\">if<\/span><span class=\"operator\"> (<\/span>CurrentPixelValue<span class=\"operator\"> &gt;<\/span> limiteInf<span class=\"operator\">)<\/span><\/p>\n<p>image<span class=\"operator\">-&gt;<\/span>SetScalarComponentFromDouble<span class=\"operator\">(<\/span>x<span class=\"operator\">,<\/span>y<span class=\"operator\">,<\/span>z<span class=\"operator\">,<\/span><span class=\"int\">0<\/span><span class=\"operator\">,<\/span>CurrentPixelValue<span class=\"operator\">);<\/span><\/p>\n<p>else<\/p>\n<p>image<span class=\"operator\">-&gt;<\/span>SetScalarComponentFromDouble<span class=\"operator\">(<\/span>x<span class=\"operator\">,<\/span>y<span class=\"operator\">,<\/span>z<span class=\"operator\">,<\/span><span class=\"int\">0<\/span><span class=\"operator\">,<\/span><span class=\"float\">0.0<\/span><span class=\"operator\">);<\/span><\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p><\/blockquote>\n<p align=\"left\"><a href=\"..\/wp-content\/uploads\/2014\/10\/Tutorial_Filtro_Plugin_ING.pdf\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" loading=\"lazy\" src=\"..\/wp-content\/uploads\/2014\/10\/TUT_PDF1.png\" alt=\"\" width=\"350\" height=\"20\" border=\"0\" \/><\/a><\/p>\n<p><a href=\"..\/?page_id=464\"><img decoding=\"async\" loading=\"lazy\" src=\"..\/wp-content\/uploads\/2014\/08\/back.gif\" alt=\"\" width=\"50\" height=\"14\" border=\"0\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The language development of plugins for ImageLab is the C + + and ambinete suggested for developing \/ using custom filters is Linux. To follow this tutorial, you will need to have installed the following packages: cmake ccmake g++ gcc libqt4-dev libqt4-gui libqtcore4 VTK: To develop a filter plugin, you must have a version of [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=\/wp\/v2\/posts\/531"}],"collection":[{"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=531"}],"version-history":[{"count":9,"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=\/wp\/v2\/posts\/531\/revisions"}],"predecessor-version":[{"id":1276,"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=\/wp\/v2\/posts\/531\/revisions\/1276"}],"wp:attachment":[{"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hemolab.lncc.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}