MeVisLab Toolbox Reference
CSOList.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 
17 
18 #pragma once
19 
20 #include "MLCSOIncludes.h"
21 
22 #include "CSO.h"
23 #include "CSOScopeEvents.h"
24 #include "CSOEvent.h"
25 #include "CSORules/CSOListRules.h"
26 
27 ML_START_NAMESPACE
28 
30 
32 typedef void csoNotificationCB(void* data, int notificationFlag);
33 
35 
37 class CSOUndoRedoManager;
38 class CSOManager;
39 class CSOGroup;
40 
41 class CSOLoad;
43 
44 // Define that can be used to detect if the CSOList is ref counted:
45 #define ML_CSOLIST_REFCOUNTED 1
46 
47 // Declare CSOListPtr smart pointer
48 ML_REFCOUNTED_PTR(CSOList)
49 
50 
61 {
62 
63 public:
64 
67  CSOList(bool shouldRegisterCSOList);
69  CSOList(const CSOList& csoList);
70 
71 protected:
77  ~CSOList() override;
78 
79  void setupCSOList();
80 
81 public:
82 
83  /* DATA STRUCTURES */
84 
88  {
90  {
91  notificationCB = nullptr;
92  notificationCBData = nullptr;
93  notificationFlag = NOTIFICATION_NONE;
94  }
98  };
99 
100  /* METHODS */
101 
103 
105  void clone(const CSOList& csoList, bool useUndoRedo=false);
107  void merge(const CSOList& csoList, bool mergeGroupWithSameLabel, CSOIdToCSOIdMap& origToThisGroupIdMap, CSOIdToCSOIdMap& origToThisCSOIdMap, bool useUndoRedo=false);
109  void merge(const CSOList& csoList, const CSOGroupMergeHandling mergeMode, CSOIdToCSOIdMap& origToThisGroupIdMap, CSOIdToCSOIdMap& origToThisCSOIdMap, bool useUndoRedo = false);
110 
112 
115  bool saveTo(std::string& filename, bool binary, std::string& message, ModuleBackgroundTask* task=nullptr) const;
118  bool saveTo(std::ostream& outStream, bool binary, ModuleBackgroundTask* task=nullptr) const;
121  bool loadFrom(std::string& filename, std::string& message, ModuleBackgroundTask* task=nullptr);
124  bool loadFrom(std::istream& inStream, bool binary, std::string& message, ModuleBackgroundTask* task = nullptr);
125 
127 
129  void addNotificationObserver(csoNotificationCB* callback, void* userData);
131  void removeNotificationObserver(csoNotificationCB* callback, void* userData);
133  void notifyObservers(int notificationFlag);
135  static void removeNotificationObserverFromAllCSOLists(csoNotificationCB* callback, void* userData);
138 
140 
143 
145 
147  inline CSOUndoRedoManager* getUndoRedoManager() { return _csoUndoRedoManager; }
149  inline CSOManager* getManager() { return _csoManager; }
150 
152  inline void setUndoRedoManager(CSOUndoRedoManager* undoRedoManager) { _csoUndoRedoManager = undoRedoManager; }
154  void setManager(CSOManager* manager);
155 
157 
160  unsigned int getCurrentCSOId();
161 
163  void updateCurrentCSOId(unsigned int newId);
164 
167  unsigned int getCurrentGroupId();
169  inline void setCurrentCSOId(unsigned int id) { _currentLastCSOId = id; }
171  inline void setCurrentGroupId(unsigned int id) { _currentLastGroupId = id; }
172 
174  void updateCurrentGroupId(const unsigned int newId);
175 
177 
180  bool isSelected(const CSO* cso) const;
182  bool isSelected(const CSOGroup* group) const;
183 
185  void addSelected(CSO* cso);
187  void addSelected(CSOGroup* group);
188 
193  bool setSelected(CSO* cso);
198  bool setSelected(CSOGroup* group);
199 
206 
210  void removeFromSelection(const std::vector<CSO*> &csos);
214  void removeFromSelection(const std::vector<CSOGroup*> &groups);
215 
217  inline unsigned int numSelectedCSOs() const { return static_cast<unsigned int>(_selectedCSOs.size()); }
219  inline unsigned int numSelectedGroups() const { return static_cast<unsigned int>(_selectedGroups.size()); }
220 
222  inline CSO* getSelectedCSOAt(unsigned int index) const
223  {
224  if (_selectedCSOs.size() > 0) {
225  return _selectedCSOs[index];
226  } else {
227  return nullptr;
228  }
229  }
231  inline CSOGroup* getSelectedGroupAt(unsigned int index) const
232  {
233  if (_selectedGroups.size() > 0) {
234  return _selectedGroups[index];
235  } else {
236  return nullptr;
237  }
238  }
241 
244 
247  Vector3 getCenterOfSelectedCSOs(bool& resultIsValid) const;
250  Vector3 getCenterOfSelectedGroups(bool& resultIsValid) const;
251 
253  inline CSO* getCSOCurrentlyUnderMouse() const { return _currentlyUnderMouseCSO; }
256  void setCSOCurrentlyUnderMouse(CSO* csoUnderMouse);
257 
261  {
262  CSO_DEBUG("Using the deprecated method 'CSOList::getCenterOfSelectedCSOs()'; use 'CSOList::getCenterOfSelectedCSOs(bool& resultIsValid)' instead!");
263  bool dummy;
264  return getCenterOfSelectedCSOs(dummy);
265  }
269  {
270  CSO_DEBUG("Using the deprecated method 'CSOList::getCenterOfSelectedGroups()'; use 'CSOList::getCenterOfSelectedGroups(bool& resultIsValid)' instead!");
271  bool dummy;
272  return getCenterOfSelectedGroups(dummy);
273  }
274 
276 
278  CSO* addCSO(bool useUndoRedo=true);
280  CSO* addCSONoEvent(bool useUndoRedo = true);
283  CSO* addCSO(const std::vector<Vector3>& seedPositions, bool closed, bool useUndoRedo);
286  CSO* addCSO(unsigned int numSeedPoints, bool closed, bool useUndoRedo);
288  CSO* addCSOCopy(CSO* cso, bool useUndoRedo=true, unsigned int csoId = INVALID_CSO_ID);
290  CSOGroup* addGroup(bool useUndoRedo=true);
292  CSOGroup* addGroup(const std::string& label, bool useUndoRedo=true);
295  CSOGroup* addGroupCopy(CSOGroup* group, bool useUndoRedo=true, unsigned int groupId=INVALID_CSO_ID);
296 
298  CSO* addPoint(const Vector3& position, const std::string& subtype="point");
301  CSO* addCircle(const Vector3& midPoint, const Vector3& normal, double radius, double pointDistanceInMM = 1., const std::string& subtype="circle");
303  CSO* addArrow(const Vector3& pointAt, const Vector3& direction, double length, double pointDistanceInMM = 1., const std::string& subtype="arrow");
305  CSO* addPolygon(const std::vector<Vector3>& points, double pointDistanceInMM = 1., const std::string& subtype="polygon");
307  CSO* addPolyline(const std::vector<Vector3>& points, double pointDistanceInMM = 1., const std::string& subtype="polyline");
310  CSO* addClosedSpline(const std::vector<Vector3>& points, bool useInterpolation=true, double pointDistanceInMM = 1., const std::string& subtype="spline");
313  CSO* addOpenSpline(const std::vector<Vector3>& points, bool useInterpolation=true, double pointDistanceInMM = 1., const std::string& subtype="spline");
314 
317  bool removeCSO(CSO* cso, bool useUndoRedo=true);
320  bool removeCSO(unsigned int id, bool useUndoRedo=true);
323  bool removeAllCSO(bool useUndoRedo=true);
326  bool removeGroup(CSOGroup* group, bool useUndoRedo=true);
329  bool removeGroup(unsigned int id, bool useUndoRedo=true);
332  bool removeAllGroups(bool useUndoRedo);
335  bool removeGroups(const std::vector<CSOGroup *> &groupsToRemove, bool useUndoRedo=true);
336 
339  bool removeAll(bool useUndoRedo=true);
340 
342 
344  CSO* getCSOAt(unsigned int index) const;
347  CSO* getCSOById(unsigned int id) const;
350  CSO* getCSOByLabel(const std::string& label) const;
352  unsigned int getCSOIndex(CSO* cso) const;
354  unsigned int getCSOIndex(unsigned int id) const;
356  bool hasCSO(CSO* cso) const;
357 
359 
361  CSOGroup* getGroupById(unsigned int id) const;
363  CSOGroup* getGroupByLabel(const std::string& label) const;
365  CSOGroup* getGroupAt(unsigned int index) const;
367  unsigned int getGroupIndex(CSOGroup* group) const;
369  unsigned int getGroupIndex(unsigned int id) const;
371  bool hasGroup(CSOGroup* group) const;
372 
374 
378  std::string getUniqueCSOLabel(std::string label, std::string format, bool addIdAlways);
379 
383  std::string getUniqueGroupLabel(std::string label, std::string format, bool addIdAlways);
384 
389  inline void resetUniqueCSOLabelIdMap() { _csoLabelUniqueIdMap.clear(); }
390 
395  inline void resetUniqueGroupLabelIdMap() { _groupLabelUniqueIdMap.clear(); }
396 
398 
400  bool combineCSOandGroup(CSO* cso, CSOGroup* group, bool useUndoRedo=true);
402  void breakCSOandGroup(CSO* cso, CSOGroup* group, bool useUndoRedo=true);
404  void breakCSOfromAllGroups(CSO* cso, bool useUndoRedo=true);
406  void breakAllCSOsFromGroup(CSOGroup* group, bool useUndoRedo=true);
409 
411 
413  unsigned int numCSOs() const;
415  unsigned int numGroups() const;
416 
418 
423 
425 
427  void undo();
429  void redo();
430 
432 
434  inline void enableUndoRedoManager() { _csoUndoRedoManagerEnabled = true; }
437 
439 
444 
447 
451  void sendPreEvent(CSOEvent::CSOEventType eventType, unsigned int csoId);
454  void sendPreEvent(CSOEvent::CSOEventType eventType, unsigned int csoId, const CSOIdVector& groupIds);
457  void sendPreEvent(CSOEvent::CSOEventType eventType, unsigned int csoId, unsigned int groupId);
459  void sendPreEvent(CSOEvent::CSOEventType eventType, const CSOIdVector& csoIds);
461  void sendPreEvent(CSOEvent::CSOEventType eventType, const CSOIdVector& csoIds, const CSOIdVector& groupIds);
462 
463 
467  void sendPostEvent(CSOEvent::CSOEventType eventType, unsigned int csoId);
470  void sendPostEvent(CSOEvent::CSOEventType eventType, unsigned int csoId, unsigned int groupId);
472  void sendPostEvent(CSOEvent::CSOEventType eventType, const CSOIdVector& csoIds);
475  void sendPostEvent(CSOEvent::CSOEventType eventType, unsigned int csoId, const CSOIdVector& groupIds);
477  void sendPostEvent(CSOEvent::CSOEventType eventType, const CSOIdVector& csoIds, const CSOIdVector& groupIds);
478 
480  void muteEvents();
483  void unmuteEvents();
486 
488 
490  MLuint64 getListChangeId() const { return _listChangeId; }
492  MLuint64 getGeometryChangeId() const { return _geometryChangeId; }
494  void listChanged();
497 
499 
501  inline void enableRepaintObserver() { _enableRepaintObserver = true; }
503  inline void disableRepaintObserver() { _enableRepaintObserver = false; }
504 
506  inline void enableFinishedObserver() { _enableFinishedObserver = true; }
508  inline void disableFinishedObserver() { _enableFinishedObserver = false; }
509 
511  inline void enableInteractionObserver() { _enableInteractionObserver = true; }
513  inline void disableInteractionObserver() { _enableInteractionObserver = false; }
514 
516  inline void enableSelectionObserver() { _enableSelectionObserver = true; }
518  inline void disableSelectionObserver() { _enableSelectionObserver = false; }
519 
521  inline void enableStartNewCSOObserver() { _enableStartNewCSOObserver = true; }
523  inline void disableStartNewCSOObserver() { _enableStartNewCSOObserver = false; }
524 
526  inline void enableCSOMovedObserver() { _enableCSOMovedObserver = true; }
528  inline void disableCSOMovedObserver() { _enableCSOMovedObserver = false; }
529 
531  inline void enableCSOCurrentlyUnderMouseObserver() { _enableCSOCurrentlyUnderMouseObserver = true; }
533  inline void disableCSOCurrentlyUnderMouseObserver() { _enableCSOCurrentlyUnderMouseObserver = false; }
534 
536 
538  inline bool isUndoRedoManagerEnabled() const { return _csoUndoRedoManagerEnabled; }
540  void openUndoRedoGroup(const std::string& description = "Contour Operation");
543 
545 
547  inline bool isRepaintNotificationEnabled() const { return _enableRepaintObserver; }
549  inline bool isFinishedNotificationEnabled() const { return _enableFinishedObserver; }
551  inline bool isInteractionInitNotificationEnabled() const { return _enableInteractionObserver; }
553  inline bool isSelectionNotificationEnabled() const { return _enableSelectionObserver; }
555  inline bool isStartNewCSONotificationEnabled() const { return _enableStartNewCSOObserver; }
557  inline bool isCSOMovedNotificationEnabled() const { return _enableCSOMovedObserver; }
559  inline bool isCSOCurrentlyUnderMouseNotificationEnabled() const { return _enableCSOCurrentlyUnderMouseObserver; }
560 
562 
564  static void alignSeedPathLinks(CSO* cso);
565 
567 
571 
573  {
575  NOTIFICATION_NONE = 0,
577  NOTIFICATION_CSO_SELECTION = 1,
579  NOTIFICATION_GROUP_SELECTION = 2,
581  NOTIFICATION_CSO_FINISHED = 4,
583  NOTIFICATION_GROUP_FINISHED = 8,
585  NOTIFICATION_REPAINT = 16,
587  NOTIFICATION_INTERACTION_INIT = 32,
589  NOTIFICATION_START_NEW_CSO = 64,
591  NOTIFICATION_CSO_MOVED = 128,
593  NOTIFICATION_CSO_UNDER_MOUSE_CHANGED = 256,
595  NOTIFICATION_UNDO_REDO_STATE_CHANGED = 512
596  };
597 
599 
601  inline CSOListRules& getRules() { return _rules; }
602 
604  void addStateToTree(TreeNode* /*parent*/) const override;
605 
607  void readStateFromTree(TreeNode* /*parent*/) override;
608 
609  // set current version number
611 
613  CSOList* deepCopy() const override { return new CSOList(*this); };
614 
615 #if ML_DEPRECATED_SINCE(3,5,0)
618  inline ML_DEPRECATED unsigned int numCSO() const { return numCSOs(); }
619 #endif
620 
621  protected:
622 
623  // nothing so far
624 
625 private:
626 
627  /* DATA STRUCTURES */
628 
630  struct IndexPair {
631  IndexPair() {
632  index0 = index1 = -1;
633  }
634  int index0, index1;
635  };
636 
637 
638  /* MEMBER VARIABLES */
639 
641  CSOListRules _rules;
642 
644  std::vector<CSO*>_csoList;
646  std::vector<CSOGroup*>_groupList;
647 
649  std::vector<CSO*>_selectedCSOs;
651  std::vector<CSOGroup*>_selectedGroups;
652 
654  CSO* _currentlyUnderMouseCSO;
655 
657  bool _csoUndoRedoManagerEnabled;
659  CSOUndoRedoManager* _csoUndoRedoManager;
661  CSOManager* _csoManager;
662 
663 
666  unsigned int _currentLastCSOId;
669  unsigned int _currentLastGroupId;
670 
671 
673  static std::vector<CSOList*> _registeredCSOLists;
674 
676  std::vector<CSONotificationCBData>_notificationObservers;
677 
679  std::map<std::string, int>_csoLabelUniqueIdMap;
680 
682  std::map<std::string, int>_groupLabelUniqueIdMap;
683 
684  MLuint64 _listChangeId;
685  MLuint64 _geometryChangeId;
686  static MLuint64 _uniqueListChangeId;
687 
689  bool _enableRepaintObserver;
691  bool _enableFinishedObserver;
693  bool _enableInteractionObserver;
695  bool _enableSelectionObserver;
697  bool _enableStartNewCSOObserver;
699  bool _enableCSOMovedObserver;
701  bool _enableCSOCurrentlyUnderMouseObserver;
702 
704  int _numberOfEventMuteRequests;
705 
706 
707  /* METHODS */
708 
710  inline bool _canUseUndoRedo(bool shouldUseUndoRedo) const { return shouldUseUndoRedo && _csoUndoRedoManagerEnabled && _csoUndoRedoManager; }
712  void _setDefaultValues(CSO* cso);
714  void _setDefaultValues(CSOGroup* group);
716  void _setDefaultRules(CSOGroup* group);
717 
719  void _emptyInternalListOfCSOs();
721  void _emptyInternalListOfGroups();
722 
724  CSOIdVector _filterContainedGroups(const std::vector<CSOGroup*> &groups, const std::vector<CSOGroup*>& container);
725  CSOIdVector _filterContainedCSOs(const std::vector<CSO*> &csos, const std::vector<CSO*>& container);
726 
728  bool pathPointListIndexIsInRange(CSO* cso, int index) const;
730  bool seedPointIndexIsRange(CSO* cso, int index) const;
731 
733  void killAll();
734 
737  bool _fromStreamV1(std::istream& inStream, std::string& message);
740  bool _fromStreamV3(std::istream& inStream, std::string& message);
743  bool _fromStreamV4(std::istream& inStream, std::string& message);
746  bool _fromStreamV5(std::istream& inStream, bool asBinary, std::string& message);
748  bool loadFromVersionBefore5(std::istream& inStream, bool binary, short version, bool swapBytes, std::string& message);
751  bool _fromStreamV6(std::istream& inStream, bool asBinary, std::string& message, ModuleBackgroundTask* task=nullptr);
752 
754  void reconstructPathPointListToSeedPointLinks( CSO* cso, std::vector<IndexPair>& pathIndexPairs, std::vector<IndexPair>& seedIndexPairs, const std::string& version, std::string& message);
755 
758  bool _checkLine(const std::string& line, const std::string& name, std::string& errorMessage);
759 
761  inline std::string spaces(unsigned int numSpaces) const
762  {
763  std::stringstream result;
764  for (unsigned int i = 0; i < numSpaces; ++i)
765  {
766  result << " ";
767  }
768  return result.str();
769  }
770 
772  std::string buildLabel(std::string label, std::string format, int id)
773  {
774  //Example: buildLabel("cso", " (%i)", 9) returns "cso (0)"
775  size_t p = format.find("%i");
776  if (p == std::string::npos)
777  {
778  format.append("%i");
779  p = format.find("%i");
780  }
781  std::stringstream ss;
782  ss << id;
783  std::string tmp = format.replace(p, 2, ss.str());
784  return label.append(tmp);
785  }
786 
788  static void registerCSOList(CSOList* csoList);
790  static void deregisterCSOList(CSOList* csoList);
791 
792  friend class CSOLoad;
793 
795 };
796 
798 
799 ML_END_NAMESPACE
#define ML_DEPRECATED
Definition: CSOGroup.h:371
#define CSO_DEBUG(msg)
Output macro for debug output.
Definition: MLCSOIncludes.h:44
std::map< unsigned int, unsigned int > CSOIdToCSOIdMap
Defines a map type to map old CSOIds to new CSOIds when merging CSOLists.
Definition: MLCSOIncludes.h:61
const unsigned int INVALID_CSO_ID
Defines a CSO/CSOGroup id that is invalid.
Definition: MLCSOIncludes.h:65
std::vector< unsigned int > CSOIdVector
Defines a vector to hold CSO and CSOGroup ids.
Definition: MLCSOIncludes.h:63
#define MLCSO_EXPORT
Defines export symbols for classes, so they can be used in other DLLs.
Definition: MLCSOSystem.h:23
Class for all CSO events.
Definition: CSOEvent.h:39
CSOEventType
Enumeration for specifying the exact type of event.
Definition: CSOEvent.h:49
A CSOGroup comprises a number of CSOs, which themselves can be in a number of different CSOGroups.
Definition: CSOGroup.h:38
The CSOListRules class controls how the CSOList should treat CSOGroups if their CSOs are removed.
Definition: CSOListRules.h:42
A CSOList comprises a number of CSOs and CSOGroups and is the central object for contour segmentation...
Definition: CSOList.h:61
void setupCSOList()
CSOUndoRedoManager * getUndoRedoManager()
Returns a pointer to the undo/redo manager of this CSOList.
Definition: CSOList.h:147
void updateCurrentGroupId(const unsigned int newId)
Updates the current group id if the new id is bigger than the current id.
CSOListRules & getRules()
Return the rules for this CSOList.
Definition: CSOList.h:601
~CSOList() override
The CSOList destructor is protected since the CSOList ownership is managed by the CSOListPtr intrusiv...
void sendModuleEventGroup(CSOEvent *event)
Sends a module group event.
void enableFinishedObserver()
Enables the finished observer mechanism.
Definition: CSOList.h:506
Vector3 getCenterOfSelectedCSOs(bool &resultIsValid) const
Returns the center position of all bounding boxes of all selected CSOs.
MLuint64 getListChangeId() const
Get the list change id, which changes whenever a CSO is added or removed (unique accross all CSOLists...
Definition: CSOList.h:490
unsigned int getCSOIndex(CSO *cso) const
Returns the index of the given CSO in its list.
CSO * getCSOByLabel(const std::string &label) const
Returns a pointer to the first CSO with the given label.
CSOGroup * getSelectedGroupAt(unsigned int index) const
Returns a pointer to the selected CSOGroup at the given index; no checking!
Definition: CSOList.h:231
static EnumValues< CSOVoxelWriteModes > getVoxelWriteModes()
bool isStartNewCSONotificationEnabled() const
Returns whether the 'start new CSO' notification is enabled.
Definition: CSOList.h:555
void breakCSOfromAllGroups(CSO *cso, bool useUndoRedo=true)
Breaks all combinations of the given CSO and any Group.
CSOIdVector getSelectedCSOIds()
Returns a vector with ids of the selected CSOs.
unsigned int getGroupIndex(unsigned int id) const
Returns the index of the Group with the given id in its list.
CSO * addCSOCopy(CSO *cso, bool useUndoRedo=true, unsigned int csoId=INVALID_CSO_ID)
Adds a copy of the given CSO to the list and returns a pointer to it.
void disableCSOMovedObserver()
Disables the 'CSO moved' observer mechanism.
Definition: CSOList.h:528
bool saveTo(std::string &filename, bool binary, std::string &message, ModuleBackgroundTask *task=nullptr) const
Pipes the internal structure of a this list (CSOs and Groups) into the given file.
bool setSelected(CSO *cso)
Sets the given CSO as being selected and deselects all other CSOs.
CSOList(const CSOList &csoList)
Copy constructor.
void sendPreEvent(CSOEvent::CSOEventType eventType, unsigned int csoId, unsigned int groupId)
Sends a pre-event with the given type, CSO id, and Group id.
void enableInteractionObserver()
Enables the interaction observer mechanism.
Definition: CSOList.h:511
bool isSelected(const CSOGroup *group) const
Returns whether the given CSOGroup is currently selected.
void resetUniqueGroupLabelIdMap()
Resets the data structure that is used to determine unique ids for getUniqueCSOLabel Afterwards,...
Definition: CSOList.h:395
CSO * addCSO(unsigned int numSeedPoints, bool closed, bool useUndoRedo)
Adds a new CSO to the list and returns its pointer.
CSOList(bool shouldRegisterCSOList)
void sendPreEvent(CSOEvent::CSOEventType eventType, const CSOIdVector &csoIds)
Sends a pre-event with the given event type and the CSO ids.
bool hasCSO(CSO *cso) const
Returns whether there is the given CSO in the list.
bool removeGroups(const std::vector< CSOGroup * > &groupsToRemove, bool useUndoRedo=true)
Removes all Groups with given ids and removes them from CSOs Returns whether the operation was succes...
bool removeCSO(unsigned int id, bool useUndoRedo=true)
Removes a CSO by its id and removes it from all Groups.
std::string getUniqueCSOLabel(std::string label, std::string format, bool addIdAlways)
Returns a unique cso label that includes the given label and combines it with a unique id using the g...
unsigned int getCurrentGroupId()
Returns the current last id (incremented each call) for CSOGroups.
CSO * addCircle(const Vector3 &midPoint, const Vector3 &normal, double radius, double pointDistanceInMM=1., const std::string &subtype="circle")
Adds a circle CSO with its midPoint at the given position and a given radius.
static EnumValues< CSOSeedPointStyle > getSeedPointStyles()
unsigned int numCSOs() const
Returns the number of CSOs in the list.
void disableFinishedObserver()
Disables the finished observer mechanism.
Definition: CSOList.h:508
void listChanged()
Called whenever the list has changed to generate a new id. This also changes the geometry id.
CSOIdVector getAllCSOIds() const
Returns a vector with the ids of the CSOs contained in the list.
void removeFromSelection(CSO *cso)
Removes the given CSO from the list of selected CSOs.
void addSelected(CSOGroup *group)
Adds the given CSOGroup to the list of selected CSOGroups (no double entry).
void addSelected(CSO *cso)
Adds the given CSO to the list of selected CSOs (no double entry).
void breakAllCSOsFromGroup(CSOGroup *group, bool useUndoRedo=true)
Breaks all combinations of the given Group and any CSO.
CSO * addPolygon(const std::vector< Vector3 > &points, double pointDistanceInMM=1., const std::string &subtype="polygon")
Adds a linearly interpolated closed polygon with the given points as seed points.
void sendPostEvent(CSOEvent::CSOEventType eventType, unsigned int csoId, const CSOIdVector &groupIds)
Sends a post-event with the given type, CSO id, and Group ids.
void sendPostEvent(CSOEvent::CSOEventType eventType, const CSOIdVector &csoIds, const CSOIdVector &groupIds)
Sends a post-event with the given type, CSO ids, and Group ids.
void registerCSOListForNotificationObservers()
Registers this CSOList in the static list of CSOLists for handling observers.
void sendPostEvent(CSOEvent::CSOEventType eventType, const CSOIdVector &csoIds)
Sends a post-event with the given type and CSO ids.
void setManager(CSOManager *manager)
Sets the pointer to the internal manager and sets the group default rules.
void undo()
Performs an undo of the last modification.
void setCurrentCSOId(unsigned int id)
Sets the current last id for CSOs. Do not mess with it.
Definition: CSOList.h:169
CSO * addOpenSpline(const std::vector< Vector3 > &points, bool useInterpolation=true, double pointDistanceInMM=1., const std::string &subtype="spline")
Adds a spline interpolated open polygon with the given points as seed points.
void removeNotificationObserver(csoNotificationCB *callback, void *userData)
Removes a notification observer from this CSOList.
bool isNotMutingEvents()
whether CSOEvents are currently emitted
void sendCloseEventGroup()
Sends a CSOLIST_EVENT_GROUP_CLOSE event to let listeners combine preceding events....
void clearSelectedCSOs()
Clears all selected CSOs.
CSO * addArrow(const Vector3 &pointAt, const Vector3 &direction, double length, double pointDistanceInMM=1., const std::string &subtype="arrow")
Adds an arrow pointing to pointAt from direction with a length.
void enableSelectionObserver()
Enables the selection observer mechanism.
Definition: CSOList.h:516
CSOManager * getManager()
Returns a pointer to the manager of this CSOList.
Definition: CSOList.h:149
CSOList()
Standard constructor.
CSO * addCSO(const std::vector< Vector3 > &seedPositions, bool closed, bool useUndoRedo)
Adds a new CSO to the list and returns its pointer.
bool removeGroup(CSOGroup *group, bool useUndoRedo=true)
Removes the given Group and removes the group from all CSOs.
CSOIdVector getAllGroupIds() const
Returns a vector with the ids of the groups contained in the list.
static EnumValues< CSOPathPointsStyle > getLineStyleModes()
CSO * getCSOById(unsigned int id) const
Returns a pointer to the CSO with the given unique id.
CSOGroup * addGroup(const std::string &label, bool useUndoRedo=true)
Adds a new Group with given label to the list and returns a pointer to it.
void enableStartNewCSOObserver()
Enables the 'start new CSO' observer mechanism.
Definition: CSOList.h:521
void enableUndoRedoManager()
Enables the undo/redo mechanism.
Definition: CSOList.h:434
bool removeAll(bool useUndoRedo=true)
Removes all CSOs and Groups and resets all else.
CSO * addPoint(const Vector3 &position, const std::string &subtype="point")
Adds a point CSO at the given position.
void clone(const CSOList &csoList, bool useUndoRedo=false)
Clones the internal CSOs and CSOGroups of the given CSOList to this one.
void notifyObservers(int notificationFlag)
Notifies all observers.
bool isInteractionInitNotificationEnabled() const
Returns whether the interaction init notification is enabled.
Definition: CSOList.h:551
unsigned int numSelectedCSOs() const
Returns the number of selected CSOs.
Definition: CSOList.h:217
void merge(const CSOList &csoList, const CSOGroupMergeHandling mergeMode, CSOIdToCSOIdMap &origToThisGroupIdMap, CSOIdToCSOIdMap &origToThisCSOIdMap, bool useUndoRedo=false)
Merges the internal CSOs and CSOGroups of the given CSOList to this one with the given merge mode.
void updateCurrentCSOId(unsigned int newId)
Updates the current id if the new id is bigger than the current id.
bool isFinishedNotificationEnabled() const
Returns whether the finished notification is enabled.
Definition: CSOList.h:549
void merge(const CSOList &csoList, bool mergeGroupWithSameLabel, CSOIdToCSOIdMap &origToThisGroupIdMap, CSOIdToCSOIdMap &origToThisCSOIdMap, bool useUndoRedo=false)
Merges the internal CSOs and CSOGroups of the given CSOList to this one.
bool removeCSO(CSO *cso, bool useUndoRedo=true)
Removes a given CSO from the list and from Groups it is in.
CSOGroup * addGroupCopy(CSOGroup *group, bool useUndoRedo=true, unsigned int groupId=INVALID_CSO_ID)
Adds a copy of the given Group to this list and returns a pointer to it.
bool isSelectionNotificationEnabled() const
Returns whether the selection notification is enabled.
Definition: CSOList.h:553
void sendPreEvent(CSOEvent::CSOEventType eventType, const CSOIdVector &csoIds, const CSOIdVector &groupIds)
Sends a pre-event with the given event type, CSO ids, and Group ids.
MLuint64 getGeometryChangeId() const
Get the geometry change id, which changes on any CSO geometry change or list change (unique accross a...
Definition: CSOList.h:492
bool saveTo(std::ostream &outStream, bool binary, ModuleBackgroundTask *task=nullptr) const
Pipes the internal structure of a this list (CSOs and Groups) into the given stream.
void sendOpenEventGroup()
Sends a CSOLIST_EVENT_GROUP_OPEN event to let listeners combine following events.
CSOGroup * getGroupAt(unsigned int index) const
Returns Group at the given index position.
unsigned int numSelectedGroups() const
Returns the number of selected CSOGroups.
Definition: CSOList.h:219
CSO * getCSOAt(unsigned int index) const
Returns a pointer to the CSO at the given position in the internal list.
void removeFromSelection(const std::vector< CSO * > &csos)
Removes the given CSOs from the list of selected CSOs.
unsigned int getCSOIndex(unsigned int id) const
Returns the index of the CSO with the given id in its list.
bool isUndoRedoManagerEnabled() const
Returns 'true' if the undo/redo mechanism is enabled, 'false' otherwise.
Definition: CSOList.h:538
void sendPreEvent(CSOEvent::CSOEventType eventType, unsigned int csoId)
Sends a pre-event with the given event type and the CSO id.
ML_SET_ADDSTATE_VERSION(1)
void addStateToTree(TreeNode *) const override
Attaches the object state as children of the given parent node.
bool isCSOMovedNotificationEnabled() const
Returns whether the 'CSO moved' notification is enabled.
Definition: CSOList.h:557
CSOList * deepCopy() const override
Create a deep copy of the CSOList.
Definition: CSOList.h:613
bool removeAllCSO(bool useUndoRedo=true)
Removes all CSOs from the list and from all Groups they are in.
void resetUniqueCSOLabelIdMap()
Resets the data structure that is used to determine unique ids for getUniqueCSOLabel.
Definition: CSOList.h:389
void disableSelectionObserver()
Disables the selection observer mechanism.
Definition: CSOList.h:518
void removeFromSelection(const std::vector< CSOGroup * > &groups)
Removes the given CSOGroups from the list of selected CSOGroups.
void sendPostEvent(CSOEvent::CSOEventType eventType, unsigned int csoId, unsigned int groupId)
Sends a post-event with the given type, CSO id, and Group id.
void setCurrentGroupId(unsigned int id)
Sets the current last id for Groups. Do not mess with it.
Definition: CSOList.h:171
CSO * getSelectedCSOAt(unsigned int index) const
Returns a pointer to the selected CSO at the given index; no checking!
Definition: CSOList.h:222
void muteEvents()
Prevent the CSOList from sending any CSOEvents until unmuteEvents is called.
unsigned int getCurrentCSOId()
Returns the current last id (incremented each call) for CSOs.
void sendPostEvent(CSOEvent::CSOEventType eventType, unsigned int csoId)
Sends a post-event with the given type and CSO id.
void _addGroupRelationCommand(CSO *cso, CSOGroup *group)
helper method to be used only inside MLCSO
bool isRepaintNotificationEnabled() const
Returns whether the repaint notification is enabled.
Definition: CSOList.h:547
void setUndoRedoManager(CSOUndoRedoManager *undoRedoManager)
Sets the internal undo/redo manager.
Definition: CSOList.h:152
CSOGroup * getGroupByLabel(const std::string &label) const
Returns a pointer to a Group with the given label.
void addNotificationObserver(csoNotificationCB *callback, void *userData)
Adds a notification observer to this CSOList.
void closeUndoRedoGroup()
Closes a undo/redo group. All undoable commands before this are grouped together.
void disableUndoRedoManager()
Enables the undo/redo mechanism.
bool isCSOCurrentlyUnderMouseNotificationEnabled() const
Returns whether the 'CSO currently under mouse' notification is enabled.
Definition: CSOList.h:559
Vector3 getCenterOfSelectedGroups(bool &resultIsValid) const
Returns the center position of all bounding boxes of all CSOs of all selected CSOGroups.
void enableCSOCurrentlyUnderMouseObserver()
Enables the 'CSO currently under mouse' observer mechanism.
Definition: CSOList.h:531
void clearSelectedGroups()
Clears all selected CSOGroups.
Vector3 getCenterOfSelectedCSOs() const
/deprecated Returns the center position of all bounding boxes of all selected CSOs.
Definition: CSOList.h:260
void unmuteEvents()
Revokes a mute request.
void sendPreEvent(CSOEvent::CSOEventType eventType, unsigned int csoId, const CSOIdVector &groupIds)
Sends a post-event with the given type, CSO id, and Group ids.
CSO * addCSONoEvent(bool useUndoRedo=true)
Adds a new CSO to the list and returns its pointer. (Without sending any events).
bool isSelected(const CSO *cso) const
Returns whether the given CSO is currently selected.
void disableCSOCurrentlyUnderMouseObserver()
Disables the 'CSO currently under mouse' observer mechanism.
Definition: CSOList.h:533
void disableRepaintObserver()
Disables the repaint observer mechanism.
Definition: CSOList.h:503
bool setSelected(CSOGroup *group)
Set the given CSOGroup as being selected and deselects all other Groups.
bool loadFrom(std::string &filename, std::string &message, ModuleBackgroundTask *task=nullptr)
Reads out the internal structure for this list (CSOs and Groups) from the given file.
void disableStartNewCSOObserver()
Disables the 'start new CSO' observer mechanism.
Definition: CSOList.h:523
static void removeNotificationObserverFromAllCSOLists(csoNotificationCB *callback, void *userData)
Removes a certain notification observer from all CSOLists.
void removeFromSelection(CSOGroup *group)
Removes the given CSOGroup from the list of selected CSOGroups.
CSO * addClosedSpline(const std::vector< Vector3 > &points, bool useInterpolation=true, double pointDistanceInMM=1., const std::string &subtype="spline")
Adds a spline interpolated closed polygon with the given points as seed points.
void enableRepaintObserver()
Enables the repaint observer mechanism.
Definition: CSOList.h:501
bool removeGroup(unsigned int id, bool useUndoRedo=true)
Removes a Group by its id and removes it from all CSOs.
void setCSOCurrentlyUnderMouse(CSO *csoUnderMouse)
Sets the pointer to the CSO currently under the mouse cursor.
void updateDisplays()
Updates all connected information/managing modules (not the renderers!).
void openUndoRedoGroup(const std::string &description="Contour Operation")
Opens a undo/redo group. All undoable commands after this are grouped together.
CSO * addPolyline(const std::vector< Vector3 > &points, double pointDistanceInMM=1., const std::string &subtype="polyline")
Adds a linearly interpolated open polyline with the given points as seed points.
void geometryChanged()
Called whenever the geometry of a CSO has changed.
void readStateFromTree(TreeNode *) override
Reads the object state from the children of the given parent node.
NotificationType
Definition: CSOList.h:573
CSOIdVector getSelectedGroupIds()
Returns a vector with ids of the selected groups.
void disableInteractionObserver()
Disables the interaction observer mechanism.
Definition: CSOList.h:513
CSO * addCSO(bool useUndoRedo=true)
Adds a new CSO to the list and returns its pointer.
Vector3 getCenterOfSelectedGroups() const
/deprecated Returns the center position of all bounding boxes of all CSOs of all selected CSOGroups.
Definition: CSOList.h:268
unsigned int getGroupIndex(CSOGroup *group) const
Returns the index of the given Group in its list.
bool loadFrom(std::istream &inStream, bool binary, std::string &message, ModuleBackgroundTask *task=nullptr)
Reads out the internal structure for this list (CSOs and Groups) from the given stream.
bool hasGroup(CSOGroup *group) const
Returns whether there is the given CSOGroup in the list.
static void alignSeedPathLinks(CSO *cso)
Aligns seed point positions with path point lists of a given CSO by a squared distance sum criterion.
CSO * getCSOCurrentlyUnderMouse() const
Returns the pointer to the CSO currently under the mouse cursor.
Definition: CSOList.h:253
CSOGroup * getGroupById(unsigned int id) const
Returns a pointer to a Group with the given id.
CSOGroup * addGroup(bool useUndoRedo=true)
Adds a new Group to the list and returns a pointer to it.
void redo()
Performs a redo of the last undone modification.
void enableCSOMovedObserver()
Enables the 'CSO moved' observer mechanism.
Definition: CSOList.h:526
bool combineCSOandGroup(CSO *cso, CSOGroup *group, bool useUndoRedo=true)
Combines the given CSO with the given Group.
std::string getUniqueGroupLabel(std::string label, std::string format, bool addIdAlways)
Returns a unique group label that includes the given label and combines it with a unique id using the...
void sendPreEvent(CSOEvent::CSOEventType eventType)
Sends a pre-event with the given event type.
bool removeAllGroups(bool useUndoRedo)
Removes all Groups and all groups from all CSOs.
void breakCSOandGroup(CSO *cso, CSOGroup *group, bool useUndoRedo=true)
Breaks the combination of the given CSO and the given Group.
void sendPostEvent(CSOEvent::CSOEventType eventType)
Sends a post-event with the given event type.
void clearSelectedSeedPoints()
Clears all selected seed points in all CSOs.
unsigned int numGroups() const
Returns the number of CSOGroups.
The CSOManager allows for storing and iterating CSOs, and implements an undo/redo mechanism.
Definition: CSOManager.h:33
Manager class for maintaining the undo and the redo stacks.
The CSO represents a contour segmentation object.
Definition: CSO.h:44
Helper class that stores a list of typed enum values and their string names.
Definition: mlFields.h:531
ModuleBackgroundTask extends the ImagingBackgroundTask with a number of useful methods that allow asy...
RefCountedBase class adds intrusive reference counting support to the Base class.
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition: mlTreeNode.h:170
#define ML_REFCOUNTED_PTR(CLASSNAME)
Macro that defines convenience Ptr/ConstPtr typedefs to be used instead of intrusive_ptr templates.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non existing export symbol.
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition: mlTypeDefs.h:513
void csoNotificationCB(void *data, int notificationFlag)
Defines the function signature for the callback methods that is to be touched by a CSOList notificati...
Definition: CSOList.h:32
This struct combines a function pointer, a user data pointer and a flag for the notification observer...
Definition: CSOList.h:88
int notificationFlag
The notification flag encodes which notifications are sent.
Definition: CSOList.h:97
csoNotificationCB * notificationCB
The callback function that is triggered by the notification.
Definition: CSOList.h:95
void * notificationCBData
The callback data that is a pointer to the observer object.
Definition: CSOList.h:96