[Insight-users] HELP! A "magic" bug bites me.

Michael Xanadu xanadu.michael at googlemail.com
Tue Aug 18 09:26:08 EDT 2009


Hi Luis,

actually, I found the Gremlin. He sat on my shoulder all the time and told
me not to set the third index for the seed point, even though I use 3-dim
data (). After I discovered his true intentions, I took him and squeezed him
under my foot, so he can never make me angry again. :-)
Thank you for your help.

Regards, Michael





2009/8/17 Luis Ibanez <luis.ibanez at kitware.com>

>
> Hi Michael,
> Thanks for the update.
>
> When you installed the Gremlin detectors,
> I assume that you found that the
>
> * Size (in pixels)
> * Origin
> * Spacing
>
> of both the read Dicom image and the processed threshold image
> were the same.
>
> Can you confirm this ?
>
>
>
> Gremlins are very vicious creatures, and if they know that you are
> a C# or Java developer who is adventuring into the C++ heaven,
> they will do whatever it takes to hold you back and force you to
> live in darkness.
>
> Here are some simple C++ rules:
>
> 1) Leave no variables uninitialized
>
> 2) Use ITK Smart Pointers
>
> 3) Use defensive programming techniques
>     (e.g. check for everything, even what seems to be obvious,
>     Gremlins love to fiddle with the aspects of your code that
>     you trust the most).
>
>
> The main suspect here is the m_DicomReader class....
>
>
> Tell us more about it....
>
>
> Are you , by any chance, using the vtkKWImageIO classes ?
>
>
> if so, are you using a smart pointer for holding this variable ?
>
>
> Also,  typical trace of Gremlin wizardry is that your code may
> do the right thing when run in Debug, and then fail, when run
> in Release. (particularly when you have uninitialized variables).
>
>
>         Be brave and stick to your C++ aspirations.
>
>
> The path may be hard,
> but the rewards are proportional to the suffering.
>
>
>      Regards,
>
>
>            Luis
>
>
> -------------------------------
>
> On Mon, Aug 17, 2009 at 12:07 PM, Michael Xanadu <
> xanadu.michael at googlemail.com> wrote:
>
>> Hi Luis,
>>
>> thank you for your quick reply. You're right, usually I'm a C# & Java
>> programmer and I'm into C++/VTK/ITK for just a few weeks. Do you really
>> think my problems lies in uninitialized variables?
>> I already used your "gremlin detectors" earlier, the m_Dicomreader works
>> fine and the thresholder always produces a black output (all pixels are
>> zero). But I think the problem really is C++ (not ITK), too. What do you
>> think should I do? Are there special rules, when using ITK in C++ (for
>> example, should I initialize my pipelines in a special way or something?)
>> Are there some important C++ topics I should know about?
>>
>> Regards, Michael
>>
>>
>>
>> 2009/8/17 Luis Ibanez <luis.ibanez at kitware.com>
>>
>>
>>> Hi Michael,
>>>
>>>                             This is clearly the work of Gremlins!
>>>
>>>
>>> Here are some of the typical mechanisms used by Gremlins to exasperate
>>> C++ developers
>>> with the evil hope of making adopt C# or Java:
>>>
>>>
>>>    - Distract the C++ developer to make her/him leave some uninitialized
>>>    variables
>>>    (You can check for uninitialized variables by using Valgrind)
>>>
>>>    - Gremlins may have removed from your m_DicomReader class the code
>>>    that
>>>    triggers the read of the DICOM image, so that when you call
>>>    GetITKImage()
>>>    you get an empty image.
>>>
>>>
>>> You can install Gremlin detectors by adding a couple of lines:
>>>
>>>
>>>    - m_Dicomreader->GetITKOutput()->Print( std::cout );
>>>    before you set the image to the threshold filter
>>>
>>>    - thresholder->GetOutput()->Print( std::cout )
>>>    after you call Update in the connected threshold filter.
>>>
>>>
>>>
>>>    Regards,
>>>
>>>
>>>          Luis
>>>
>>> ---------------------------
>>> On Mon, Aug 17, 2009 at 5:26 AM, Michael Xanadu <
>>> xanadu.michael at googlemail.com> wrote:
>>>
>>>> Hallo itk users,
>>>>
>>>> now take a look at some real strange bug. I programmed a
>>>> ConnectedThresholdImageFilter, which works (surprisingly).
>>>> But if add add some lines of QT code into the method (which don't mess
>>>> with the filter) - all I get is a black output!
>>>> This kind of bug has happened to me a lot lately. Sometimes a filter
>>>> doesn't seem to work, I tinker around with it for a day and after the SAME
>>>> code works!
>>>> I even have a fast marching filter which only works, if I add some lines
>>>> in which I create some itk::ImageFileWriter objects (BUT I DON'T USE THEM!).
>>>> And once I get a code to work, it only works in the current
>>>> method/class/project. If I copy and paste the code -> black ouput!
>>>> Do Someone know, what went wrong?
>>>>
>>>> Thanx in advance, Michael
>>>>
>>>>
>>>>
>>>> void MyMainWindow::connectedThresholdFilter()
>>>> {
>>>>     typedef itk::ConnectedThresholdImageFilter<ImageType, ImageType>
>>>> ThresholderType;
>>>>     ThresholderType::Pointer thresholder = ThresholderType::New();
>>>>     thresholder->SetInput( m_Dicomreader->GetITKOutput() );
>>>>
>>>>     // if I uncomment following line, I get a black output !!!!
>>>>     //QString s1 = this->qlineedit1->text();
>>>>
>>>>     thresholder->SetLower(0);
>>>>     thresholder->SetUpper(800);
>>>>     ImageType::IndexType  index;
>>>>     index[0] = 250;
>>>>     index[1] = 250;
>>>>     thresholder->SetSeed(index);
>>>>     thresholder->SetReplaceValue(255);
>>>>
>>>>     try
>>>>     {
>>>>         thresholder->Update();
>>>>     }
>>>>     catch( itk::ExceptionObject & excep )
>>>>     {
>>>>         std::cerr << "Exception caught !" << std::endl;
>>>>         std::cerr << excep << std::endl;
>>>>     }
>>>>
>>>>     // Here I use a vtkImageViewer2 to show the output
>>>>     Utility::popUpImage(thresholder->GetOutput());
>>>> }
>>>>
>>>> _____________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at
>>>> http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090818/266c75af/attachment-0001.htm>


More information about the Insight-users mailing list