<commit_before>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/


#ifndef DATATREEHELPER_H_HEADER_INCLUDED_C1C7797C
#define DATATREEHELPER_H_HEADER_INCLUDED_C1C7797C

#include "mitkCommon.h"
#include "mitkDataTree.h"

#include "mitkImageCast.h"
#include "mitkStringProperty.h"
#include "mitkLevelWindowProperty.h"
#include "mitkDataTreeNodeFactory.h"

namespace mitk 
{

//##Documentation
//## @brief Convenience methods for common tasks concerning the data tree
//## @ingroup DataTree
namespace DataTreeHelper
{
  //##Documentation
  //## @brief Search a data tree for (the first) iterator to a given node
  static DataTreeIteratorClone FindIteratorToNode(mitk::DataTreeBase* tree, const DataTreeNode* node, const DataTreeIteratorBase* startPosition = NULL );

  //##Documentation
  //## @brief Add itk-image to data tree
  //##
  //## The itk-image is converted into an mitk::Image.
  //## @param itkImage the itk-image to be added
  //## @param iterator the iterator used for adding the node, containing the image
  //## @param name string with the name of the image, stored in the property "name"
  //## @param replaceByName if @a true, the tree is searched starting at 
  //##   @a iterator for a node called @a name, which data is replaced with 
  //##   @a itkImage
  template < typename TImageType >
  mitk::DataTreeNode::Pointer 
  AddItkImageToDataTree(TImageType* itkImage, mitk::DataTreeIteratorBase* iterator, const char* name=NULL, bool replaceByName=false)
  {
    itkImage->Update();

    mitk::Image::Pointer mitkImage = mitk::Image::New();
    mitk::CastToMitkImage(itkImage, mitkImage);

    mitk::DataTreeNode::Pointer node = NULL;
    bool done=false;
    if((replaceByName) && (name != NULL))
    {
      mitk::DataTreeIteratorClone it=iterator;
      mitk::DataTreeIteratorClone itByName = ((mitk::DataTree *) it->GetTree())->GetNext("name", new mitk::StringProperty( name ));

      if( (itByName->IsAtEnd() == false) && (itByName->Get().IsNotNull()) )
      {
        node = itByName->Get();
        node->SetData(mitkImage);
        done = true;
      }
    }
    if(done==false)
    {
      node=mitk::DataTreeNode::New();
      node->SetData(mitkImage);
      if(name!=NULL)
        node->SetProperty("name", new mitk::StringProperty(name));
      mitk::DataTreeNodeFactory::SetDefaultImageProperties(node);
      iterator->Add(node);
    }

    mitk::LevelWindowProperty::Pointer levWinProp = new mitk::LevelWindowProperty();
    mitk::LevelWindow levelwindow;
    levelwindow.SetAuto( mitkImage );
    levWinProp->SetLevelWindow( levelwindow );
    node->SetProperty( "levelwindow", levWinProp );

    return node;
  }
};

} // namespace mitk

#endif /* DATATREEHELPER_H_HEADER_INCLUDED_C1C7797C */

<commit_msg>FIX: removed 'static' attribute of FindIterator<commit_after>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/


#ifndef DATATREEHELPER_H_HEADER_INCLUDED_C1C7797C
#define DATATREEHELPER_H_HEADER_INCLUDED_C1C7797C

#include "mitkCommon.h"
#include "mitkDataTree.h"

#include "mitkImageCast.h"
#include "mitkStringProperty.h"
#include "mitkLevelWindowProperty.h"
#include "mitkDataTreeNodeFactory.h"

namespace mitk 
{

//##Documentation
//## @brief Convenience methods for common tasks concerning the data tree
//## @ingroup DataTree
namespace DataTreeHelper
{
  //##Documentation
  //## @brief Search a data tree for (the first) iterator to a given node
  DataTreeIteratorClone FindIteratorToNode(mitk::DataTreeBase* tree, const DataTreeNode* node, const DataTreeIteratorBase* startPosition = NULL );

  //##Documentation
  //## @brief Add itk-image to data tree
  //##
  //## The itk-image is converted into an mitk::Image.
  //## @param itkImage the itk-image to be added
  //## @param iterator the iterator used for adding the node, containing the image
  //## @param name string with the name of the image, stored in the property "name"
  //## @param replaceByName if @a true, the tree is searched starting at 
  //##   @a iterator for a node called @a name, which data is replaced with 
  //##   @a itkImage
  template < typename TImageType >
  mitk::DataTreeNode::Pointer 
  AddItkImageToDataTree(TImageType* itkImage, mitk::DataTreeIteratorBase* iterator, const char* name=NULL, bool replaceByName=false)
  {
    itkImage->Update();

    mitk::Image::Pointer mitkImage = mitk::Image::New();
    mitk::CastToMitkImage(itkImage, mitkImage);

    mitk::DataTreeNode::Pointer node = NULL;
    bool done=false;
    if((replaceByName) && (name != NULL))
    {
      mitk::DataTreeIteratorClone it=iterator;
      mitk::DataTreeIteratorClone itByName = ((mitk::DataTree *) it->GetTree())->GetNext("name", new mitk::StringProperty( name ));

      if( (itByName->IsAtEnd() == false) && (itByName->Get().IsNotNull()) )
      {
        node = itByName->Get();
        node->SetData(mitkImage);
        done = true;
      }
    }
    if(done==false)
    {
      node=mitk::DataTreeNode::New();
      node->SetData(mitkImage);
      if(name!=NULL)
        node->SetProperty("name", new mitk::StringProperty(name));
      mitk::DataTreeNodeFactory::SetDefaultImageProperties(node);
      iterator->Add(node);
    }

    mitk::LevelWindowProperty::Pointer levWinProp = new mitk::LevelWindowProperty();
    mitk::LevelWindow levelwindow;
    levelwindow.SetAuto( mitkImage );
    levWinProp->SetLevelWindow( levelwindow );
    node->SetProperty( "levelwindow", levWinProp );

    return node;
  }
};

} // namespace mitk

#endif /* DATATREEHELPER_H_HEADER_INCLUDED_C1C7797C */


{'fraction_non_alphanumeric': 0.15650496958908175, 'fraction_numerical': 0.004450378282153983, 'mean_word_length': 4.372111553784861, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6425538', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1995, 'n_words': 538}