Esempio n. 1
0
void mitk::LevelWindowManager::Update(const itk::EventObject&)  // visible property of a image has changed
{
  if (m_AutoTopMost)
  {
    SetAutoTopMostImage(true);
    return;
  }
  mitk::DataStorage::SetOfObjects::ConstPointer all = this->GetRelevantNodes();
  for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin();
       it != all->End();
       ++it)
  {
    mitk::DataNode::Pointer node = it->Value();
    if (node.IsNull())
      continue;

    node->SetBoolProperty( "imageForLevelWindow", false );

    if (node->IsVisible(NULL) == false)
      continue;

    mitk::LevelWindowProperty::Pointer levelWindowProperty = dynamic_cast<mitk::LevelWindowProperty*>(node->GetProperty("levelwindow"));
    if (levelWindowProperty.IsNull())
      continue;

    m_LevelWindowProperty = levelWindowProperty;
    m_CurrentImage = dynamic_cast<mitk::Image*>(node->GetData());
    node->SetBoolProperty( "imageForLevelWindow", true );
    if (m_LevelWindowProperty.IsNull() && m_LevelWindowProperty.GetPointer() == levelWindowProperty) // we found our m_LevelWindowProperty
    {
      return;
    }
  }
  Modified();
}
Esempio n. 2
0
void mitk::LevelWindowManager::DataStorageRemovedNode( const mitk::DataNode* removedNode )
{
  //first: check if deleted node is part of relevant nodes. If not, abort method because there is no need change anything.
  if ((this->GetRelevantNodes()->size() == 0)) return;
  bool removedNodeIsRelevant = false;
  /* Iterator code: is crashing, don't know why... so using for loop
  for (mitk::DataStorage::SetOfObjects::ConstIterator it = this->GetRelevantNodes()->Begin();
       it != this->GetRelevantNodes()->End();
       ++it)
  {if (it->Value() == removedNode) {removedNodeIsRelevant=true;}}*/
  for (unsigned int i=0; i<this->GetRelevantNodes()->size(); i++)
    {
    if (this->GetRelevantNodes()->at(i) == removedNode) {removedNodeIsRelevant=true;}
    }
  if (!removedNodeIsRelevant) return;

  //remember node which will be removed
  m_NodeMarkedToDelete = removedNode;

  //update observers
  UpdateObservers();

  /* search image than belongs to the property */
  if (m_LevelWindowProperty.IsNull())
  {
    SetAutoTopMostImage(true, removedNode);
  }
  else
  {
    mitk::NodePredicateProperty::Pointer p2 = mitk::NodePredicateProperty::New("levelwindow", m_LevelWindowProperty);
    mitk::DataNode* n = m_DataStorage->GetNode(p2);
    if (n == NULL || m_AutoTopMost) // if node was deleted, change our behaviour to AutoTopMost, if AutoTopMost is true change level window to topmost node
    {
      SetAutoTopMostImage(true, removedNode);
    }
  }

  //reset variable
  m_NodeMarkedToDelete = NULL;

  //check if everything is still ok
  if ((m_PropObserverToNode.size() != m_PropObserverToNode2.size()) || (m_PropObserverToNode2.size() != (this->GetRelevantNodes()->size()-1)))
     {mitkThrow() << "Wrong number of observers in Level Window Manager!";}
}
Esempio n. 3
0
void mitk::LevelWindowManager::DataStorageAddedNode( const mitk::DataNode* )
{

  //update observers with new data storage
  UpdateObservers();

  //Initialize LevelWindowsManager to new image
  SetAutoTopMostImage(true);

  //check if everything is still ok
  if ((m_PropObserverToNode.size() != m_PropObserverToNode2.size()) || (m_PropObserverToNode2.size() != this->GetRelevantNodes()->size()))
     {mitkThrow() << "Wrong number of observers in Level Window Manager!";}

}
Esempio n. 4
0
void mitk::LevelWindowManager::Update(const itk::EventObject&)  // visible property of a image has changed
{
  if ( m_SettingImgForLvlWinProp )//no mutex, should still help
  {
    return;
  }

  if (m_AutoTopMost)
  {
    SetAutoTopMostImage(true);
    return;
  }

  int maxVisibleLayer = itk::NumericTraits<int>::min();
  mitk::DataNode::Pointer highestVisible = NULL;
  std::vector< mitk::DataNode::Pointer > visProbNodes;

  mitk::DataStorage::SetOfObjects::ConstPointer all = this->GetRelevantNodes();
  for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin();
       it != all->End();
       ++it)
  {
    mitk::DataNode::Pointer node = it->Value();

    if ( node.IsNull() )
    {
      continue;
    }

    bool visible = node->IsVisible(NULL);

    if ( node->IsVisible(NULL) )
    {
      int layer = -1;
      node->GetIntProperty( "layer", layer );
      if ( layer > maxVisibleLayer )
      {
        maxVisibleLayer = layer;
        highestVisible = node;
      }
    }

    bool prop = false;
    node->GetBoolProperty( "imageForLevelWindow", prop );

    if ( prop && visible )
    {
      visProbNodes.push_back( node );
    }
  }

  int numVisProbNodes = visProbNodes.size();
  if ( numVisProbNodes > 2 )
  {
    MITK_ERROR << "Error: not more than two visible nodes are expected to have the imageForLevelWindow property set at any point.";
  }
  else if ( numVisProbNodes == 2 )
  {
    for ( std::vector< mitk::DataNode::Pointer >::const_iterator it = visProbNodes.begin(); it != visProbNodes.end(); ++it )
    {
      mitk::LevelWindowProperty::Pointer newProp = dynamic_cast< mitk::LevelWindowProperty* >( (*it)->GetProperty( "levelwindow" ) );
      if ( newProp != m_LevelWindowProperty )
      {
        this->SetLevelWindowProperty( newProp );
        return;
      }
    }
  }
  else if (numVisProbNodes == 1 )
  {
    mitk::LevelWindowProperty::Pointer newProp = dynamic_cast< mitk::LevelWindowProperty* >( visProbNodes[0]->GetProperty( "levelwindow" ) );
    if ( newProp != m_LevelWindowProperty )
    {
      this->SetLevelWindowProperty( newProp );
      return;
    }
  }
  else if ( highestVisible )
  {
    mitk::LevelWindowProperty::Pointer lvlProp = dynamic_cast< mitk::LevelWindowProperty* >( highestVisible->GetProperty( "levelwindow" ) );

    this->SetLevelWindowProperty( lvlProp );
  }
  else
  {
    Modified();
  }
}