29 #include <itkCommand.h>
33 m_LevelWindowProperty(NULL),
35 m_IsObserverTagSet(false),
37 m_IsPropertyModifiedTagSet(false),
38 m_SettingImgForLvlWinProp(false)
53 if (m_IsPropertyModifiedTagSet && m_LevelWindowProperty.IsNotNull())
55 m_LevelWindowProperty->RemoveObserver(m_PropertyModifiedTag);
56 m_IsPropertyModifiedTagSet =
false;
60 this->ClearPropObserverLists();
84 this->DataStorageAddedNode();
94 m_AutoTopMost = autoTopMost;
95 if (m_AutoTopMost ==
false)
98 if (m_IsPropertyModifiedTagSet && m_LevelWindowProperty.IsNotNull())
100 m_LevelWindowProperty->RemoveObserver(m_PropertyModifiedTag);
101 m_IsPropertyModifiedTagSet =
false;
107 itkExceptionMacro(
"DataStorage not set");
111 m_LevelWindowProperty = NULL;
116 for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin(); it != all->End(); ++it)
119 if (node.IsNull() || (removedNode != NULL && node == removedNode))
122 m_SettingImgForLvlWinProp =
true;
123 node->SetBoolProperty(
"imageForLevelWindow",
false);
124 m_SettingImgForLvlWinProp =
false;
126 if (node->IsVisible(NULL) ==
false)
130 node->GetIntProperty(
"layer", layer);
131 if (layer < maxLayer)
136 if (levelWindowProperty.IsNull())
145 if (mode.IsNotNull())
147 int currMode = mode->GetRenderingMode();
148 if (currMode == nonLvlWinMode1 || currMode == nonLvlWinMode2)
156 m_LevelWindowProperty = levelWindowProperty;
157 m_CurrentImage =
dynamic_cast<mitk::Image *
>(node->GetData());
163 if (topLevelNode.IsNotNull())
165 m_SettingImgForLvlWinProp =
true;
166 topLevelNode->SetBoolProperty(
"imageForLevelWindow",
true);
167 m_SettingImgForLvlWinProp =
false;
170 this->SetLevelWindowProperty(m_LevelWindowProperty);
172 if (m_LevelWindowProperty.IsNull())
182 if (levelWindowProperty.IsNull())
188 NodeSetType::ConstIterator it = nodes->Begin();
190 while (it != nodes->End())
195 if (prop == levelWindowProperty)
201 m_SettingImgForLvlWinProp =
true;
202 node->SetBoolProperty(
"imageForLevelWindow",
false);
203 m_SettingImgForLvlWinProp =
false;
209 if (propNode.IsNull())
211 mitkThrow() <<
"No Image in DataStorage that belongs to LevelWindow property" << m_LevelWindowProperty;
214 if (m_IsPropertyModifiedTagSet)
216 m_LevelWindowProperty->RemoveObserver(m_PropertyModifiedTag);
217 m_IsPropertyModifiedTagSet =
false;
220 m_LevelWindowProperty = levelWindowProperty;
225 m_PropertyModifiedTag = m_LevelWindowProperty->AddObserver(itk::ModifiedEvent(), command);
226 m_IsPropertyModifiedTagSet =
true;
228 m_CurrentImage =
dynamic_cast<mitk::Image *
>(propNode->GetData());
230 m_SettingImgForLvlWinProp =
true;
231 propNode->SetBoolProperty(
"imageForLevelWindow",
true);
232 m_SettingImgForLvlWinProp =
false;
240 return m_LevelWindowProperty;
246 if (m_LevelWindowProperty.IsNotNull())
248 return m_LevelWindowProperty->GetLevelWindow();
252 itkExceptionMacro(
"No LevelWindow available!");
259 if (m_LevelWindowProperty.IsNotNull())
261 m_LevelWindowProperty->SetLevelWindow(levelWindow);
272 SetAutoTopMostImage(
true);
275 if ((m_PropObserverToNode.size() != m_PropObserverToNode2.size()) ||
276 (m_PropObserverToNode2.size() != this->GetRelevantNodes()->size()))
278 mitkThrow() <<
"Wrong number of observers in Level Window Manager!";
286 if ((this->GetRelevantNodes()->size() == 0))
288 bool removedNodeIsRelevant =
false;
294 for (
unsigned int i = 0; i < this->GetRelevantNodes()->size(); i++)
296 if (this->GetRelevantNodes()->at(i) == removedNode)
298 removedNodeIsRelevant =
true;
301 if (!removedNodeIsRelevant)
305 m_NodeMarkedToDelete = removedNode;
311 if (m_LevelWindowProperty.IsNull())
313 SetAutoTopMostImage(
true, removedNode);
319 if (n == NULL || m_AutoTopMost)
322 SetAutoTopMostImage(
true, removedNode);
327 m_NodeMarkedToDelete = NULL;
330 if ((m_PropObserverToNode.size() != m_PropObserverToNode2.size()) ||
331 (m_PropObserverToNode2.size() != (this->GetRelevantNodes()->size() - 1)))
333 mitkThrow() <<
"Wrong number of observers in Level Window Manager!";
339 this->ClearPropObserverLists();
340 CreatePropObserverLists();
345 return m_PropObserverToNode.size();
356 return m_AutoTopMost;
362 for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin(); it != all->End(); ++it)
368 bool isSelected =
false;
369 node->GetBoolProperty(
"selected", isSelected);
373 node->GetLevelWindow(selectedLevelWindow);
376 int displayedComponent = 0;
377 if (image && (node->GetIntProperty(
"Image.Displayed Component", displayedComponent)))
380 selectedLevelWindow.
SetAuto(image,
true,
true, static_cast<unsigned>(displayedComponent));
381 node->SetLevelWindow(selectedLevelWindow);
386 node->GetLevelWindow(levelWindow);
394 if (m_SettingImgForLvlWinProp)
401 SetAutoTopMostImage(
true);
407 std::vector<mitk::DataNode::Pointer> visProbNodes;
410 for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin(); it != all->End(); ++it)
419 bool visible = node->IsVisible(NULL);
421 if (node->IsVisible(NULL))
424 node->GetIntProperty(
"layer", layer);
425 if (layer > maxVisibleLayer)
427 maxVisibleLayer = layer;
428 highestVisible = node;
433 node->GetBoolProperty(
"imageForLevelWindow", prop);
437 visProbNodes.push_back(node);
441 int numVisProbNodes = visProbNodes.size();
442 if (numVisProbNodes > 2)
444 MITK_ERROR <<
"Error: not more than two visible nodes are expected to have the imageForLevelWindow property set at "
447 else if (numVisProbNodes == 2)
449 for (std::vector<mitk::DataNode::Pointer>::const_iterator it = visProbNodes.begin(); it != visProbNodes.end(); ++it)
453 if (newProp != m_LevelWindowProperty)
455 this->SetLevelWindowProperty(newProp);
460 else if (numVisProbNodes == 1)
464 if (newProp != m_LevelWindowProperty)
466 this->SetLevelWindowProperty(newProp);
470 else if (highestVisible)
475 this->SetLevelWindowProperty(lvlProp);
497 predicateTypes->AddPredicate(isImage);
498 predicateTypes->AddPredicate(isDImage);
499 predicateTypes->AddPredicate(isTImage);
500 predicateTypes->AddPredicate(isQImage);
503 predicate->AddPredicate(notBinary);
504 predicate->AddPredicate(hasLevelWindow);
505 predicate->AddPredicate(predicateTypes);
509 return relevantNodes;
514 return m_CurrentImage;
519 for (ObserverToPropertyMap::iterator iter = m_PropObserverToNode.begin(); iter != m_PropObserverToNode.end(); ++iter)
521 (*iter).second->RemoveObserver((*iter).first.first);
524 m_PropObserverToNode.clear();
526 for (ObserverToPropertyMap::iterator iter = m_PropObserverToNode2.begin(); iter != m_PropObserverToNode2.end();
529 (*iter).second->RemoveObserver((*iter).first.first);
532 m_PropObserverToNode2.clear();
534 for (ObserverToPropertyMap::iterator iter = m_PropObserverToNode3.begin(); iter != m_PropObserverToNode3.end();
537 (*iter).second->RemoveObserver((*iter).first.first);
540 m_PropObserverToNode3.clear();
542 for (ObserverToPropertyMap::iterator iter = m_PropObserverToNode4.begin(); iter != m_PropObserverToNode4.end();
545 (*iter).second->RemoveObserver((*iter).first.first);
548 m_PropObserverToNode4.clear();
550 for (ObserverToPropertyMap::iterator iter = m_PropObserverToNode5.begin(); iter != m_PropObserverToNode5.end();
553 (*iter).second->RemoveObserver((*iter).first.first);
556 m_PropObserverToNode5.clear();
563 itkExceptionMacro(
"DataStorage not set");
568 for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin(); it != all->End(); ++it)
570 if ((it->Value().IsNull()) || (it->Value() == m_NodeMarkedToDelete))
579 unsigned long visIdx = it->Value()->GetProperty(
"visible")->AddObserver(itk::ModifiedEvent(), command);
580 m_PropObserverToNode[
PropDataPair(visIdx, it->Value())] = it->Value()->GetProperty(
"visible");
586 unsigned long layerIdx = it->Value()->GetProperty(
"layer")->AddObserver(itk::ModifiedEvent(), command2);
587 m_PropObserverToNode2[
PropDataPair(layerIdx, it->Value())] = it->Value()->GetProperty(
"layer");
594 if (imageRenderingMode.IsNotNull())
596 unsigned long rendIdx = imageRenderingMode->AddObserver(itk::ModifiedEvent(), command3);
597 m_PropObserverToNode3[
PropDataPair(rendIdx, it->Value())] = imageRenderingMode.GetPointer();
604 if (displayedImageComponent.IsNotNull())
606 unsigned long dispIdx = displayedImageComponent->AddObserver(itk::ModifiedEvent(), command4);
607 m_PropObserverToNode4[
PropDataPair(dispIdx, it->Value())] = displayedImageComponent.GetPointer();
614 if (imgForLvlWin.IsNull())
616 it->Value()->SetBoolProperty(
"imageForLevelWindow",
false);
617 imgForLvlWin = it->Value()->GetProperty(
"imageForLevelWindow");
619 unsigned long lvlWinIdx = imgForLvlWin->AddObserver(itk::ModifiedEvent(), command5);
620 m_PropObserverToNode5[
PropDataPair(lvlWinIdx, it->Value())] = it->Value()->GetProperty(
"imageForLevelWindow");
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
void DataStorageRemovedNode(const DataNode *removedNode=nullptr)
This method is called when a node is removed to the data storage. A listener on the data storage is u...
The LevelWindowProperty class Property for the mitk::LevelWindow.
itk::VectorContainer< unsigned int, mitk::DataNode::Pointer > SetOfObjects
A Container of objects that is used as a result set of GetSubset() query operations (Set of...
void SetLevelWindow(const LevelWindow &levelWindow)
Sets new Level/Window values and informs all listeners about changes.
void ClearPropObserverLists()
internal help method to clear both lists/maps.
int GetNumberOfObservers()
static void Update(vtkPolyData *)
const LevelWindow & GetLevelWindow()
void Update(const itk::EventObject &e)
gets called if a visible property changes
itk::SmartPointer< const Self > ConstPointer
DataStorage::SetOfObjects::ConstPointer GetRelevantNodes()
std::pair< unsigned long, DataNode::Pointer > PropDataPair
The LevelWindow class Class to store level/window values.
mitk::DataStorage::Pointer m_DataStorage
void OnPropertyModified(const itk::EventObject &e)
change notifications from mitkLevelWindowProperty
LevelWindowProperty::Pointer GetLevelWindowProperty()
void DataStorageAddedNode(const DataNode *n=nullptr)
This method is called when a node is added to the data storage. A listener on the data storage is use...
void CreatePropObserverLists()
internal help method to create both lists/maps.
Image class for storing images.
void SetAuto(const Image *image, bool tryPicTags=true, bool guessByCentralSlice=true, unsigned selectedComponent=0)
sets level/window to optimize the contrast of the given Image
void SetLevelWindowProperty(LevelWindowProperty::Pointer levelWindowProperty)
Sets an specific LevelWindowProperty, all changes will affect the image belonging to this property...
static Pointer New(const char *_arg)
DataStorage * GetDataStorage()
returns the datastorage
static Pointer New(const char *_arg)
void SetAutoTopMostImage(bool autoTopMost, const DataNode *removedNode=nullptr)
(Re-)Initializes the LevelWindowManager by setting the topmost image. Use the removedNode parameter i...
void RecaluclateLevelWindowForSelectedComponent(const itk::EventObject &)
void SetDataStorage(DataStorage *ds)
Image * GetCurrentImage()
return the currently active image
Class for nodes of the DataTree.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.