Hi Li,

So far your code seems to be good, give us a little more time to check it. I 
assume it's some issue with the plane and the geometry of the image. Have you 
made sure your plane is inside the geometry of the image? Consider that the 
origin of the plane in your example is (40,0,0) and the axis vectors are 
(0,0,1) and (0,1,0). You can check this in the header of the .mhd file. Can you 
please send me the geometry information(extent, spacing, origin etc).
I suggest to use InitializeStandardPlane (const Geometry3D *geometry3D, 
PlaneOrientation planeorientation=Transversal, ScalarType zPosition=0, bool 
frontside=true, bool rotated=false) where geometry3D is the geometry of the 
image.

By the way, to transform index coordinates to world coordinates you can use 
IndexToWorld(source, destination) on the geometry you desire.

At least the line m_planeGeo->Initialize() is not needed.

Regards,

Tobi

-----Ursprüngliche Nachricht-----
Von: Liu, Li [mailto:[email protected]] 
Gesendet: Samstag, 10. März 2012 02:53
An: Schröder, Tobias; [email protected]
Betreff: 答复: [mitk-users] extract 2D slice from a 3D image volume along 
arbitrary directions

 Hi Tobi,

I tried the code, but get nothing in rendering window.

I am not sure what is going wrong. The data source is in raw format, 
309*547*478 (load it through opening mhd file). I read the Geometry Overview in 
MITK docs and your last mail, it seems I have to convert the index coordinate 
(I think my data are in index coordinate) to world coordinate for reslice.

Here are my code.

QString fileName = QFileDialog::getOpenFileName(this, "Open File", "",
        mitk::CoreObjectFactory::GetInstance()->GetFileExtensions());

    if (fileName != "")
{

mitk::DataNodeFactory::Pointer nodeReader = mitk::DataNodeFactory::New();

nodeReader->SetFileName(fileName.toUtf8().constData());
        nodeReader->Update();

        mitk::DataNode::Pointer m_node = nodeReader->GetOutput();

if ( m_node->GetData() = NULL )
{
QMessageBox::critical(this, "Error", "Could not open file"); return; }

QmitkRenderWindow* m_renderWindow = new QmitkRenderWindow(this); // this 
pointer is QMainWindow

mitk::StandaloneDataStorage::Pointer m_DataStorage = 
mitk::StandaloneDataStorage::New();



mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(m_node->GetData());

if(!image->IsVolumeSet())
{
QMessageBox::critical(this, "Error", "Fail to get vol"); return; }


mitk::Vector3D spacing;
spacing[0]=spacing[1]=spacing[2]=1.0;

mitk::PlaneGeometry::Pointer m_planeGeo = mitk::PlaneGeometry::New(); 
m_planeGeo->Initialize();

m_planeGeo->InitializeStandardPlane(500.0, 500.0, spacing, 
mitk::PlaneGeometry::Sagittal, 40, true, false); 
m_planeGeo->ChangeImageGeometryConsideringOriginOffset(true);


// I delete your rotation code for test only

mitk::ExtractDirectedPlaneImageFilterNew::Pointer m_extractFilter = 
mitk::ExtractDirectedPlaneImageFilterNew::New();

m_extractFilter->SetInput(image);
m_extractFilter->SetCurrentWorldGeometry2D(m_planeGeo);
m_extractFilter->Update();

mitk::Image::Pointer slice = m_extractFilter->GetOutput();
if(!slice->IsValidSlice())
{
QMessageBox::critical(this, "Error", "fail to get slice"); return; }

mitk::DataNode::Pointer m_node_slice = mitk::DataNode::New();

m_node_slice->SetData(slice);
m_DataStorage->Add(m_node_slice);
m_renderWindow->GetRenderer()->SetDataStorage(m_DataStorage);

mitk::RenderingManager::GetInstance()->RequestUpdateAll();

Thanks and have a good weekend

Li

________________________________
发件人: Schröder, Tobias [[email protected]]
发送时间: 2012年3月7日 6:49
收件人: Liu, Li; [email protected]
主题: Re: [mitk-users] extract 2D slice from a 3D image volume along arbitrary 
directions


Hi Li,



mitk::PlaneGeometry::InitializePlane is right, but you have to make sure that 
it actually is a worldGeometry. As these have some special characteristic you 
have do something like this:





mitk::PlaneGeometry::Pointer obliquePlane = mitk::PlaneGeometry::New();

obliquePlane->InitializeStandardPlane(planeSizeX, planeSizeY, spacing, 
obliquePlane->mitk::PlaneGeometry::Sagittal, zPosition, true, 
obliquePlane->false);//or one of the other initialize mehtods

obliquePlane->ChangeImageGeometryConsideringOriginOffset(true);



origin = obliquePlane->GetOrigin();

normal = obliquePlane->GetNormal();





normal.Normalize();



origin += normal * spacingInDerectionOfNormal  * 0.5;



obliquePlane->SetOrigin(origin);

//that’s the thing about the worldGeometries, they are surrounding the pixel in 
two directions but are located in center of the third.

//you have to do this after the initialization, if you are constructing one 
from scratch, as an plane is not worldGeometry.



mitk::Vector3D rotationVector;

rotationVector[0] = 0.2;

rotationVector[1] = 0.4;

rotationVector[2] = 0.62;



float degree = 37.0;

//here you have calculate the rotation you need, to define the oblique plane



mitk::RotationOperation* op = new mitk::RotationOperation(mitk::OpROTATE, 
obliquePlane->GetCenter(), rotationVector, degree);

obliquePlane->ExecuteOperation(op);

delete op;





Also the origin, the spacing and the size/bounding box should be considered to 
be right (proper).



But instead if want to reslice at what the display is showing you can also 
retrieve a worldGeometry from the renderer.

I recommend the second version.





The workflow with the filter is:



mitk::ExtractDirectedPlaneImageFilterNew::Pointer extractFilter = 
mitk::ExtractDirectedPlaneImageFilterNew::New();

extractFilter::SetInput(yourVolume);

extractFilter::SetCurrentWorldGeometry(yourPlane);

extractFilter:: SetActualInputTimestep(yourTimeStep); //if you are dealing with 
4D images



extractFilter::Update();



Image::Pointer slice = newExtractor->GetOutput();





That’s it. Now You can use the slice.

I hope it helps.





Best Regards



Tobi







>-----Ursprüngliche Nachricht-----

>Von: Liu, Li [mailto:[email protected]]<mailto:[mailto:[email protected]]>

>Gesendet: Mittwoch, 7. März 2012 05:54

>An: Schröder, Tobias

>Cc: 
>[email protected]<mailto:[email protected]
>t>

>Betreff: 答复: [mitk-users] extract 2D slice from a 3D image volume along 
>arbitrary directions



>Hi Tobi,



>Thanks for your quick reply. Here are some questions about your answer.



>What is a proper initialization for PlaneGeometry? I think you mean 
>mitk::PlaneGeometry::InitializePlane, right?



>Setting the position of plane is through 
>mitk::BaseRenderer::SetCurrentWorldGeometry2D or 
>mitk::ExtractDirectedPlaneImageFilterNew::SetCurrentWorldGeometry2D?



>Now, I load the volume data into mitk::StandaloneDataStorage, but how can I 
>set volume data as the input of ExtractDirectedPlaneImageFilterNew.



>Thanks



Li



________________________________________

发件人: Schröder, Tobias [[email protected]]

发送时间: 2012年3月6日 2:11

收件人: Liu, Li; 
[email protected]<mailto:[email protected]>

主题: Re: [mitk-users] extract 2D slice from a 3D image volume along arbitrary 
directions



Hi Li,



there is a mitk class called ExtractDirectedPlaneImageFilterNew which meets 
your needs.

A PlaneGeometry specifies the axes where to reslice at. The plane can be 
arbitrary oriented and is set via SetCurrentWorldGeometry2D.

So just initialize a proper PlaneGeometry and set it together with your volume 
as the input for the filter.



If this won't help provide me some further infos.



Regards



Tobi







>Von: Liu, Li [mailto:[email protected]]<mailto:[mailto:[email protected]]>

>Gesendet: Montag, 5. März 2012 20:14

>An: 
>[email protected]<mailto:[email protected]
>t>

>Betreff: [mitk-users] extract 2D slice from a 3D image volume along 
>arbitrary directions



>Hi,



> I am new to MITK and got a problem. Currently, I am using MITK to construct a 
> platform to implement extract arbitrary 2D slice from a 3D image volume (raw 
> data format). I looked at the tutorial examples and ext app and all of them 
> are only to extract 2D slice along transversal, sagittal and coronal 
> direction. For me, they are x,y,z axes. If I want to extract 2D slices along 
> other directions than transversal, sagittal and coronal direction, how can I 
> do that?



>Thanks



>Li





------------------------------------------------------------------------------

>Try before you buy = See our experts in action!

>The most comprehensive online learning library for Microsoft developers is 
>just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro 
>Style Apps, more. Free future >releases when you subscribe now!

>http://p.sf.net/sfu/learndevnow-dev2

_______________________________________________

>mitk-users mailing list

>[email protected]<mailto:[email protected]
>t>

>https://lists.sourceforge.net/lists/listinfo/mitk-users

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to