Hello Luis,<br><br><div class="gmail_quote">On Fri, May 28, 2010 at 5:35 PM, Luis Ibanez <span dir="ltr"><<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>Hi Frederic,<br><br>The function:<div class="im"><br><span style="font-family: courier new,monospace;">
template<typename TITKImgType></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bool</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> WriteFile(</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const
std::string& a_fullFilename,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
typename TITKImgType::<span style="background-color: rgb(255, 255, 153);">ConstPointer</span>);</span><br>
<br></div>will be better written as<div class="im"><br><span style="font-family: courier new,monospace;">
template<typename TITKImgType></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bool</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> WriteFile(</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const
std::string& a_fullFilename,</span><br style="font-family: courier new,monospace;"></div><span style="font-family: courier new,monospace;">
const TITKImgType * );</span><br>
<br><br>and you will be able to call it as<br><br> ImgType::Pointer image = filter->GetOutput();<br><br> WriteFile<ImgType>("out.mhd", image<span style="background-color: rgb(255, 255, 153);"> </span>);<br>
<br><br>(not need to use "GetPointer()" in this case)<br><br>Normally you don't need to call GetPointer() in ITK.<br></blockquote><div><br>Thank you very much, that works fine.<br><br>Following your indications, I've just checked it works as expected with this simple code, for completeness:<br>
<br><div style="margin-left: 40px; font-family: courier new,monospace;">#include <itkImage.h><br>#include <itkImageFileReader.h><br>#include <itkImageRegionIterator.h><br><br>typedef short PxlType;<br>typedef itk::Image<PxlType, 3> ImgType;<br>
<br>void<br>TryInspectors(<span style="background-color: rgb(255, 255, 153);">const ImgType* a_img</span>) {<br> const ImgType::IndexType idx = { 0, 0, 0 };<br> <span style="background-color: rgb(153, 255, 153);">a_img->GetPixel(idx);</span><br>
<br> const ImgType::RegionType region = a_img->GetLargestPossibleRegion();<br> <span style="background-color: rgb(153, 255, 153);">itk::ImageRegionConstIterator<ImgType> it(a_img, region);</span><br><br> <span style="background-color: rgb(255, 204, 204);">// The following mutating methods cause compiler error, as expected:</span><br style="background-color: rgb(255, 204, 204);">
<span style="background-color: rgb(255, 204, 204);"><span style="background-color: rgb(255, 255, 255);"> </span>a_img->SetPixel(idx, 666); // <- discards qualifiers</span><br style="background-color: rgb(255, 204, 204);">
<span style="background-color: rgb(255, 204, 204);"><span style="background-color: rgb(255, 255, 255);"> </span>itk::ImageRegionIterator<ImgType> it(a_img, region); // <- invalid conversion</span><br>}<br><br>int main(int argc, char** argv) {<br>
if (argc < 2)<br> return -1;<br><br> typedef itk::ImageFileReader<ImgType> ReaderType;<br> ReaderType::Pointer reader = ReaderType::New();<br> reader->SetFileName(argv[1]);<br> reader->Update();<br>
<br> <span style="background-color: rgb(255, 255, 153);">ImgType::ConstPointer image = reader->GetOutput();</span><br> TryInspectors(image);<br><br> return 0;<br>}<br></div><br>Time to get rid of <span style="font-family: courier new,monospace;">GetPointer() </span>calls in our code!<br>
<br>Kind regards,<br><br>Frederic Perez<br></div></div><div style="visibility: hidden; display: inline;" id="avg_ls_inline_popup"></div><style type="text/css">#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}</style>