[prev in list] [next in list] [prev in thread] [next in thread] 

List:       vtkusers
Subject:    Re: [vtkusers] Set ImageData to zero
From:       Dominique Töpfer <dominique () toepfer-web ! de>
Date:       2011-09-28 14:47:37
Message-ID: 4E833389.10206 () toepfer-web ! de
[Download RAW message or body]

The best way I can think of, is writing a templated method SetToZero<T> 
and then perform the check for all possible types:

switch(pixelType)
{
case VTK_DOUBLE:
     SetToZero<double>(Image);
     break;
     ...
};

But maybe someone has a better idea...

On 28.09.2011 16:37, speedy wrote:
> I see. Do I have to check for every pixel type or is there a way to use the
> string directly?
> Something like:
> 
> /const char* PixelType = Image->GetScalarTypeAsString();
> (PixelType)* PixelArray;
> PixelArray = ((PixelType)*)m_UserLabels->GetScalarPointer();
> /
> 
> which obviously doesn't work.
> 
> 
> Dominique Töpfer wrote:
> > There are macros like VTK_DOUBLE defined in vtkTypes.h (
> > http://www.vtk.org/doc/nightly/html/vtkType_8h_source.html ). So you can
> > check the scalar type using
> > 
> > if(Image->GetScalarType() == VTK_DOUBLE)
> > // cast to double
> > 
> > Of course, you can also GetScalarTypeAsString() as suggested by Jothy.
> > 
> > HTH
> > Dominique
> > 
> > 
> > On 28.09.2011 15:21, speedy wrote:
> > > Thanks a lot for your reply Dominique!
> > > It is much faster indeed to use GetScalarPointer() instead of iterating
> > > through the pixels. I still have a problem though: My class doesn't know
> > > the
> > > pixeltype of the image beforehand, but I have to cast the pointer to it.
> > > How
> > > can I achieve this? I know there's the method
> > > 
> > > Image->GetScalarType(),
> > > 
> > > but it returns an integer value and I don't know how to proceed with it..
> > > 
> > > 
> > > Dominique Töpfer wrote:
> > > > Hi,
> > > > 
> > > > a similar question was discussed here:
> > > > http://vtk.1045678.n5.nabble.com/Fast-element-access-of-vtkImageData-td4640137.html#none
> > > >  
> > > > HTH
> > > > Dominique
> > > > 
> > > > On 27.09.2011 15:47, speedy wrote:
> > > > > Sorry if this question actually has a simple answer, but what is the
> > > > > fastest
> > > > > way to set every pixel of a vtkImageData to zero (or any other value
> > > > > fitting
> > > > > in its pixeltype)?
> > > > > I've tried vtkImageThreshold, but it doesn't seem to do anything or
> > > > > maybe
> > > > > I
> > > > > am using it wrong:
> > > > > 
> > > > > threshold = vtkSmartPointer<vtkImageThreshold>::New();
> > > > > threshold->SetInput(Image);
> > > > > threshold->ReplaceOutOn();
> > > > > threshold->SetOutValue(Value);
> > > > > threshold->ThresholdByLower(maximum_image_value);
> > > > > threshold->Update();
> > > > > 
> > > > > --
> > > > > View this message in context:
> > > > > http://vtk.1045678.n5.nabble.com/Set-ImageData-to-zero-tp4845442p4845442.html
> > > > >  Sent from the VTK - Users mailing list archive at Nabble.com.
> > > > > _______________________________________________
> > > > > 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 VTK FAQ at:
> > > > > http://www.vtk.org/Wiki/VTK_FAQ
> > > > > 
> > > > > Follow this link to subscribe/unsubscribe:
> > > > > http://www.vtk.org/mailman/listinfo/vtkusers
> > > > -- 
> > > > Thus spake the master programmer:
> > > > "After three days without programming, life becomes meaningless."
> > > > 
> > > > -- The Tao of Programming by Geoffry James
> > > > 
> > > > Dominique Töpfer, Dipl.-Inform.
> > > > Institute of Medical Physics
> > > > University of Erlangen
> > > > 
> > > > _______________________________________________
> > > > 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 VTK FAQ at:
> > > > http://www.vtk.org/Wiki/VTK_FAQ
> > > > 
> > > > Follow this link to subscribe/unsubscribe:
> > > > http://www.vtk.org/mailman/listinfo/vtkusers
> > > > 
> > > --
> > > View this message in context:
> > > http://vtk.1045678.n5.nabble.com/Set-ImageData-to-zero-tp4845442p4849109.html
> > > Sent from the VTK - Users mailing list archive at Nabble.com.
> > > _______________________________________________
> > > 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 VTK FAQ at:
> > > http://www.vtk.org/Wiki/VTK_FAQ
> > > 
> > > Follow this link to subscribe/unsubscribe:
> > > http://www.vtk.org/mailman/listinfo/vtkusers
> > 
> > -- 
> > Thus spake the master programmer:
> > "After three days without programming, life becomes meaningless."
> > 
> > -- The Tao of Programming by Geoffry James
> > 
> > Dominique Töpfer, Dipl.-Inform.
> > Institute of Medical Physics
> > University of Erlangen
> > 
> > _______________________________________________
> > 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 VTK FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> > 
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> > 
> 
> --
> View this message in context: \
> http://vtk.1045678.n5.nabble.com/Set-ImageData-to-zero-tp4845442p4849412.html Sent \
> from the VTK - Users mailing list archive at Nabble.com. \
> _______________________________________________ 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 VTK FAQ at: \
> http://www.vtk.org/Wiki/VTK_FAQ 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers


-- 
Thus spake the master programmer:
     "After three days without programming, life becomes meaningless."

-- The Tao of Programming by Geoffry James

Dominique Töpfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen

_______________________________________________
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 VTK FAQ at: \
http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic