Maybe I just don't see it... where are you incrementing the "objIt" iterator?

- Sascha

On 10/05/2012 01:19 PM, Stefan Dänzer wrote:
Hi all,

I've been trying to write a console application to extract all images (as .mhd) and surfaces (as plain text .vtk) contained in a .mitk scene file. However I have trouble to extract the corresponding files.

I have linked my application against MITK 2012-09 compiled from source. I can open the scene in the mitkWorkbench, so I guess I must be missing something.

The scene layout is as follows:

someImage
|-someSegmentation1
 |-someSurface1
|-someSegmentation2
 |-someSurface2
|-someSegmentation3
 |-someSurface3

where someSurface1 is the child of someSegmentation1 and someSegmentation1 is the child of someSegmentation

Here is the snippet from the console app to extract the nodes as vtk-surface or mhd-image:

//  check  if  output  folder  exists,  if  not  create  the  folder.
   boost::filesystem::path  dir(  outputFolder);
   if  (boost::filesystem::create_directory(dir))
     std::cout  <<  "Created  "  <<  outputFolder  <<  "\n";
   else
     std::cout  <<  "Warning  could  not  create  "  <<  outputFolder  <<  "\n";
   mitk::SceneIO::Pointer  sceneIO  =  mitk::SceneIO::New();
   mitk::DataStorage::Pointer  dataStorage  =  sceneIO->LoadScene(  
inputFilename);
   mitk::DataStorage::SetOfObjects::ConstPointer  sceneObjs  =  
dataStorage->GetAll();
   mitk::DataStorage::SetOfObjects::ConstIterator  objIt  =  sceneObjs->Begin();
   while(objIt  !=  sceneObjs->End())
   {
     mitk::DataNode::Pointer  node  =   objIt->Value();
     std::cout  <<  node->GetName()  <<  std::endl;
     std::string  name  =  node->GetName();
     std::string  path;
     path.append(  outputFolder);
     path.append(  name);
     //  test  dynamic_cast  to  image  and  to  surface.
     if(  dynamic_cast<mitk::Image*>(  node->GetData()))
     {
       mitk::Image::Pointer  image  =  
dynamic_cast<mitk::Image*>(node->GetData());
       mitk::ImageWriter::Pointer  imWriter  =  mitk::ImageWriter::New();
       path.append(  ".mhd");
       imWriter->SetInput(  image);
       imWriter->SetFileName(  path);
       imWriter->Write();
     }
     else  if(  dynamic_cast<mitk::Surface*>(  node->GetData()))
     {
       mitk::Surface::Pointer  surface  =  dynamic_cast<mitk::Surface*>(  
node->GetData());
       mitk::SurfaceVtkWriter<vtkPolyDataWriter>::Pointer  surfWriter  =  
mitk::SurfaceVtkWriter<vtkPolyDataWriter>::New();
       path.append(  ".vtk");
       surfWriter->SetInput(  surface);
       surfWriter->SetFileName(  path);
       surfWriter->Write();
     }
   }

Thanks for any advice in advance,

Stefan


--
Stefan Daenzer
Körnerplatz 8
04107 Leipzig

Tel.: +49-157-84993879

"Work like you don't need the money, love like you've never been hurt and dance like no one is watching." - Randall G Leighton

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to