Hi Miri,
as your example code provides no other namespaces or class names I will just
assume everything you are doing happens in one class (thus, I do assume, that
MyFunction is in fact not a global function, but MyClass::MyFunction ).
Probably the way that is the easiest to understand would be something similar
to this (this is assuming, you do know the data type):
----- header ---
Class MyClass
{
//stuff
void GenerateData();
void MyFunction( someParameter a, someParameter b );
Mitk::Image::ConstPointer m_InputImage1;
Mitk::Image::ConstPointer m_InputImage2;
Mitk::Image::ConstPointer m_InputImage3;
Mitk::Image::ConstPointer m_InputImage4;
}
---- source ---
void MyClass::GenerateData()
{
mitk::Image::ConstPointer m_InputImage1= this->GetInput(0);
mitk::Image::ConstPointer m_InputImage2= this->GetInput(1);
mitk::Image::ConstPointer m_InputImage3= this->GetInput(2);
mitk::Image::ConstPointer m_InputImage4= this->GetInput(3);
MyFunction( x, y );
}
void MyClass::MyFunction( someParameter a, someParameter b )
{
// this for N = 1,2,3,4
Itk::Image< KnownDataType, KnownDimension>::Pointer itkImageN;
mitk::CastToItkImage(m_InputImageN, itkImageN);
//from here on you can do whatever you want with the itk images. Please note,
that CastToITKImage takes a const pointer to an mitk image and a non const itk
Image
}
------------------------------
If you do not know your image data type/dimension , but all of the images
either have a fixed type/dimension or one that depends on one unkown type (e.g.
your function should work for both float and double, but all the images are
either float or double (or one is int in any case, but the others are float or
double...) You can template and use the AccesByItk macros for one image and
then handle the subsequent ones as in the example above.
If you can not say anything about the different types/dimension (e.g. one might
be float or int, the other string, double, or long and the last char or bool,
but in any combination) you would have to write your own access macros which is
not that easy.
----------------------
Concerning your first question: Because the function getInput(0) can return
only a constPointer- (I get errors if I don't manipulate in this way) so I must
send the inputImage to my Function as I did (with a const pointer) and then,
how can I manipulate my filters on the that image?
You can not manipulate a const image, that is the point of returning a const.
So if you want to work in the actual image, you would have to copy it and work
on the non-const copy of the image. (You might want to read up on the idea
behind and the use of const. There are ways to get rid of it, but in general
you do *not* want to modify something some code passes to you as const, because
this way lies data corruption and madness.)
I hope this helps,
Caspar
Von: Miri Trope [mailto:[email protected]]
Gesendet: Montag, 7. November 2011 14:25
An: Goch, Caspar Jonas
Cc: mitk-users
Betreff: Re: [mitk-users] Insert multiple input images to a method in my module
Hi Casper,
sorry if It sounds daft question, but I'm a new mitk's user.
I have two functions. One of them generates data (input and output images) and
the other gets that data and manipulates some filters on them like this:
void myClass::GenerateData()
{
Mitk::Image::ConstPointer inputImage = this->GetOutput(0);
Mitk::Image::Pointer outputImage = this->GetOutput();
MyFunction( inputImage, m_inputVal1, outputImage);
}
void myFunction(const mitk::Image* inputMitkImage, int val1,
mitk::Image::Pointer outputImage)
{
vtkImageData* vtkImage = mitkImage->GetVtkImage(); // this returns error
regarding the const pointer //which can't change the image
}
So, I have two questions:
1) Because the function getInput(0) can return only a constPointer- (I get
errors if I don't manipulate in this way) so I must send the inputImage to my
Function as I did (with a const pointer) and then, how can I manipulate my
filters on the that image?
2) How can I send to myFunc a multiple number of images?
Is my intuition right that it should be something like this?
void myClass::GenerateData()
{
Mitk::Image::ConstPointer inputImage_1 = this->GetOutput(0); //to insert the
first selected image
Mitk::Image::ConstPointer inputImage_2 = this->GetOutput(1); //to insert the
second selected image
Mitk::Image::ConstPointer inputImage_3 = this->GetOutput(2); //to insert the
third selected image
Mitk::Image::Pointer outputImage = this->GetOutput();
MyFunction( inputImage_1, inputImage_2, inputImage_3, m_inputVal1, outputImage);
}
and how should myFunction signature look like (the const pointer is a very
sensitive issue for me :-), how can I avoid from writing him at the first
place)?
A lot of thanks,
Miri
On Mon, Nov 7, 2011 at 2:50 PM, Miri Trope
<[email protected]<mailto:[email protected]>> wrote:
Hi Casper, sorry if It sounds daft question, but I'm a mitk's new user.
I have two functions. One of them generates data (input and output images) and
the other gets that data and manipulates some filters on them like this:
void generat
void myFunction
So, I have two questions:
1) because the function getInput(0) can return only constPointer (I got errors
if I didn't manipulate that in this way) I must sent the image to my Function
as I did and then, how can I manipulate my filter How am I using mitk's image
which has a const pointer
On Mon, Nov 7, 2011 at 2:23 PM, Goch, Caspar Jonas
<[email protected]<mailto:[email protected]>> wrote:
Hi Miri,
the AccessByITK macros are designed for one generic image class only, as the
need to instantiate (number of data types)^(number of images) different classes
at compile time would lead to extremely long compiles. If you really do need a
completely generic way you would need to implement this yourself, but if you
either know the data type of your images directly, or in relation to the one
generic one (as in, e.g. the same) you might want to take a look at
mitk::CastToItkImage (see http://docs.mitk.org/nightly-qt4/group__Adaptor.html
the detailed description for more info).
So I would suggest either handing your function a vector of image pointers, or
just storing and accessing the images using class members via CastToItkImage .
Regards,
Caspar
Von: Miri Trope [mailto:[email protected]<mailto:[email protected]>]
Gesendet: Sonntag, 6. November 2011 09:03
An: mitk-users
Betreff: [mitk-users] Insert multiple input images to a method in my module
Hi all,
How should I insert/manage multiple input images to a method in my module?
Until now, I inserted only one input image by accessIntegralPixelTypeByItk and
simply insert that image in my method like this:
//=======================
void myFilter::GenerateData()
{
mitk::Image::ConstPointer image = this->GetInput(0);
try
{
AccessInterslPixelTypeByItk_n(image, myMethod, (some_Inputs...))
}
}
//=======================
template<typename TPixel, unsigned int VImageDimension>
void myMethod (itk::Image<TPixel, VImageDimension>* image, some_Inputs)
{...}
//========================
Now, I'd like to insert multiple images (actually, four images) to my method.
How should I do this?
Thanks.
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users