Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLSequenceBrowserNode.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  This file was originally developed by Csaba Pinter, PerkLab, Queen's University
17  and was supported through the Applied Cancer Research Unit program of Cancer Care
18  Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
19 
20 ==============================================================================*/
21 
22 #ifndef __vtkMRMLSequenceBrowserNode_h
23 #define __vtkMRMLSequenceBrowserNode_h
24 
25 #include "vtkSlicerSequencesModuleMRMLExport.h"
26 
27 // MRML includes
28 #include <vtkMRML.h>
29 #include <vtkMRMLNode.h>
30 #include <vtkNew.h>
31 
32 // STD includes
33 #include <set>
34 #include <map>
35 
36 class vtkCollection;
38 class vtkIntArray;
39 
40 class VTK_SLICER_SEQUENCES_MODULE_MRML_EXPORT vtkMRMLSequenceBrowserNode : public vtkMRMLNode
41 {
42 public:
43  static vtkMRMLSequenceBrowserNode *New();
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
48  enum
49  {
50  ProxyNodeModifiedEvent = 21001,
51  IndexDisplayFormatModifiedEvent
52  };
53 
55  // Enum is used so that in the future more modes can be added (e.g., fixed frame rate,
56  // fixed frame rate matching playback frame rate, etc).
58  {
59  SamplingAll = 0,
61  NumberOfRecordingSamplingModes // this line must be the last one
62  };
63 
66  {
67  IndexDisplayAsIndex = 0,
69  NumberOfIndexDisplayModes // this line must be the last one
70  };
71 
73  vtkMRMLNode* CreateNodeInstance() override;
74 
76  void ReadXMLAttributes( const char** atts) override;
77 
79  void WriteXML(ostream& of, int indent) override;
80 
82  void Copy(vtkMRMLNode *node) override;
83 
85  const char* GetNodeTagName() override {return "SequenceBrowser";};
86 
89  std::string SetAndObserveMasterSequenceNodeID(const char *sequenceNodeID);
91  vtkMRMLSequenceNode* GetMasterSequenceNode();
92 
94  std::string AddSynchronizedSequenceNode(const char* synchronizedSequenceNodeId);
95 
97  std::string AddSynchronizedSequenceNodeID(const char* synchronizedSequenceNodeId);
98 
100  std::string AddSynchronizedSequenceNode(vtkMRMLSequenceNode* synchronizedSequenceNode);
101 
103  void RemoveSynchronizedSequenceNode(const char* nodeId);
104 
106  void RemoveAllSequenceNodes();
107 
109  void GetSynchronizedSequenceNodes(std::vector< vtkMRMLSequenceNode* > &synchronizedDataNodes, bool includeMasterNode=false);
110  void GetSynchronizedSequenceNodes(vtkCollection* synchronizedDataNodes, bool includeMasterNode=false);
111 
113  int GetNumberOfSynchronizedSequenceNodes(bool includeMasterNode = false);
114 
116  bool IsSynchronizedSequenceNode(const char* sequenceNodeId, bool includeMasterNode = false);
117 
119  bool IsSynchronizedSequenceNodeID(const char* sequenceNodeId, bool includeMasterNode = false);
120  bool IsSynchronizedSequenceNode(vtkMRMLSequenceNode* sequenceNode, bool includeMasterNode = false);
121 
123  vtkGetMacro(PlaybackActive, bool);
124  vtkSetMacro(PlaybackActive, bool);
125  vtkBooleanMacro(PlaybackActive, bool);
126 
128  vtkGetMacro(PlaybackRateFps, double);
129  vtkSetMacro(PlaybackRateFps, double);
130 
132  vtkGetMacro(PlaybackItemSkippingEnabled, bool);
133  vtkSetMacro(PlaybackItemSkippingEnabled, bool);
134  vtkBooleanMacro(PlaybackItemSkippingEnabled, bool);
135 
137  vtkGetMacro(PlaybackLooped, bool);
138  vtkSetMacro(PlaybackLooped, bool);
139  vtkBooleanMacro(PlaybackLooped, bool);
140 
142  vtkGetMacro(SelectedItemNumber, int);
143  vtkSetMacro(SelectedItemNumber, int);
144 
146  vtkGetMacro(RecordingActive, bool);
147  void SetRecordingActive(bool recording);
148  vtkBooleanMacro(RecordingActive, bool);
149 
151  vtkGetMacro(RecordMasterOnly, bool);
152  vtkSetMacro(RecordMasterOnly, bool);
153  vtkBooleanMacro(RecordMasterOnly, bool);
154 
156  vtkSetMacro(RecordingSamplingMode, int);
157  void SetRecordingSamplingModeFromString(const char *recordingSamplingModeString);
159  vtkGetMacro(RecordingSamplingMode, int);
160  virtual std::string GetRecordingSamplingModeAsString();
161 
163  static std::string GetRecordingSamplingModeAsString(int recordingSamplingMode);
164  static int GetRecordingSamplingModeFromString(const std::string &recordingSamplingModeString);
165 
167  vtkSetMacro(IndexDisplayMode, int);
168  void SetIndexDisplayModeFromString(const char *indexDisplayModeString);
170  vtkGetMacro(IndexDisplayMode, int);
171  virtual std::string GetIndexDisplayModeAsString();
172 
174  void SetIndexDisplayFormat(std::string displayFormat);
176  vtkGetMacro(IndexDisplayFormat, std::string);
177 
179  static std::string GetIndexDisplayModeAsString(int indexDisplayMode);
180  static int GetIndexDisplayModeFromString(const std::string &indexDisplayModeString);
181 
183  int SelectNextItem(int selectionIncrement=1);
184 
186  int SelectFirstItem();
187 
189  int SelectLastItem();
190 
192  int GetNumberOfItems();
193 
195  vtkMRMLNode* AddProxyNode(vtkMRMLNode* sourceProxyNode, vtkMRMLSequenceNode* sequenceNode, bool copy=true);
196 
198  vtkMRMLNode* GetProxyNode(vtkMRMLSequenceNode* sequenceNode);
199 
202  {
203  static bool warningLogged = false;
204  if (!warningLogged)
205  {
206  vtkWarningMacro("vtkMRMLSequenceBrowserNode::GetVirtualOutputDataNode is deprecated, use vtkMRMLSequenceBrowserNode::GetProxyNode method instead");
207  warningLogged = true;
208  }
209  return this->GetProxyNode(sequenceNode);
210  }
211 
213  void SetOverwriteTargetNodeName(bool overwrite)
214  {
215  static bool warningLogged = false;
216  if (!warningLogged)
217  {
218  vtkWarningMacro("vtkMRMLSequenceBrowserNode::SetOverwriteTargetNodeName is deprecated,"
219  << " use vtkMRMLSequenceBrowserNode::SetOverwriteProxyName method instead");
220  warningLogged = true;
221  }
222  this->SetOverwriteProxyName(nullptr, overwrite);
223  }
224 
226  void SetDeepCopyVirtualNodes(bool deepcopy)
227  {
228  static bool warningLogged = false;
229  if (!warningLogged)
230  {
231  vtkWarningMacro("vtkMRMLSequenceBrowserNode::SetDeepCopyVirtualNodes is deprecated, use vtkMRMLSequenceBrowserNode::SetSaveChanges method instead");
232  warningLogged = true;
233  }
234  this->SetSaveChanges(nullptr, !deepcopy);
235  }
236 
238  vtkMRMLSequenceNode* GetSequenceNode(vtkMRMLNode* proxyNode);
239 
240  void GetAllProxyNodes(std::vector< vtkMRMLNode* > &nodes);
241  void GetAllProxyNodes(vtkCollection* nodes);
242 
243 
245  void GetAllVirtualOutputDataNodes(vtkCollection* nodes)
246  {
247  static bool warningLogged = false;
248  if (!warningLogged)
249  {
250  vtkWarningMacro("vtkMRMLSequenceBrowserNode::GetAllVirtualOutputDataNodes is deprecated,"
251  << " use vtkMRMLSequenceBrowserNode::GetAllProxyNodes method instead");
252  warningLogged = true;
253  }
254  this->GetAllProxyNodes(nodes);
255  }
256 
258  bool IsProxyNode(const char* nodeId);
259 
261  bool IsProxyNodeID(const char* nodeId);
262 
263  // TODO: Should these methods be protected? Probably the "world" shouldn't need to know about the postfixes.
264  void RemoveProxyNode(const std::string& postfix);
265 
266  void RemoveAllProxyNodes();
267 
269  bool IsAnySequenceNodeRecording();
270 
272  bool GetRecording(vtkMRMLSequenceNode* sequenceNode);
273  bool GetPlayback(vtkMRMLSequenceNode* sequenceNode);
275  bool GetOverwriteProxyName(vtkMRMLSequenceNode* sequenceNode);
281  bool GetSaveChanges(vtkMRMLSequenceNode* sequenceNode);
282 
284  void SetRecording(vtkMRMLSequenceNode* sequenceNode, bool recording);
285  void SetPlayback(vtkMRMLSequenceNode* sequenceNode, bool playback);
286  void SetOverwriteProxyName(vtkMRMLSequenceNode* sequenceNode, bool overwrite);
287  void SetSaveChanges(vtkMRMLSequenceNode* sequenceNode, bool save);
288 
290  void ProcessMRMLEvents( vtkObject *caller, unsigned long event, void *callData ) override;
291 
293  virtual void SaveProxyNodesState();
294 
297  std::string GetFormattedIndexValue(int index);
298 
302  static bool ValidateFormatString(std::string& validatedFormat, std::string& prefix, std::string& suffix,
303  const std::string& requestedFormat, const std::string& typeString);
304 
305 protected:
307  ~vtkMRMLSequenceBrowserNode() override;
310 
313  void FixSequenceNodeReferenceRoleName();
314 
316  void OnNodeReferenceAdded(vtkMRMLNodeReference* nodeReference) override;
317 
319  void OnNodeReferenceRemoved(vtkMRMLNodeReference* nodeReference) override;
320 
321  std::string GenerateSynchronizationPostfix();
322  std::string GetSynchronizationPostfixFromSequence(vtkMRMLSequenceNode* sequenceNode);
323  std::string GetSynchronizationPostfixFromSequenceID(const char* sequenceNodeID);
324 
325 protected:
326  bool PlaybackActive{false};
327  double PlaybackRateFps{10.0};
328  bool PlaybackItemSkippingEnabled{true};
329  bool PlaybackLooped{true};
330  int SelectedItemNumber{-1};
331 
332  bool RecordingActive{false};
333  double RecordingTimeOffsetSec; // difference between universal time and index value
335  bool RecordMasterOnly{false};
338  std::string IndexDisplayFormat;
339 
340  // Unique postfixes for storing references to sequence nodes, proxy nodes, and properties
341  // For example, a sequence node reference role name is SEQUENCE_NODE_REFERENCE_ROLE_BASE+synchronizationPostfix
342  std::vector< std::string > SynchronizationPostfixes;
343 
344  // Counter that is used for generating the unique (only for this class) proxy node postfix strings
345  int LastPostfixIndex{0};
346 
347 private:
348  struct SynchronizationProperties;
349  std::map< std::string, SynchronizationProperties* > SynchronizationPropertiesMap;
350  SynchronizationProperties* GetSynchronizationPropertiesForSequence(vtkMRMLSequenceNode* sequenceNode);
351  SynchronizationProperties* GetSynchronizationPropertiesForPostfix(const std::string& rolePostfix);
352 };
353 
354 #endif
RecordingSamplingModeType
Modes for determining recording frame rate.
vtkMRMLNode * GetVirtualOutputDataNode(vtkMRMLSequenceNode *sequenceNode)
Deprecated method!
void SetDeepCopyVirtualNodes(bool deepcopy)
Deprecated method!
std::vector< std::string > SynchronizationPostfixes
const char * GetNodeTagName() override
Get unique node XML tag name (like Volume, Model)
virtual void ReadXMLAttributes(const char **atts)
void operator=(const vtkMRMLNode &)
virtual vtkMRMLNode * CreateNodeInstance()=0
Create instance of the default node. Like New only virtual.
MRML node for representing a sequence of MRML nodes.
virtual void ProcessMRMLEvents(vtkObject *caller, unsigned long event, void *callData)
Propagate events generated in mrml.
virtual void Copy(vtkMRMLNode *node)
Copy node contents from another node of the same type. Does not copy node ID and Scene. Performs deep copy - an independent copy is created from all data, including bulk data.
virtual void OnNodeReferenceRemoved(vtkMRMLNodeReference *reference)
Called when a referenced node pointer is removed (set to nullptr).
Definition: vtkMRMLNode.h:942
void GetAllVirtualOutputDataNodes(vtkCollection *nodes)
Deprecated method!
virtual void WriteXML(ostream &of, int indent)
IndexDisplayModeType
Modes displaying index for the user.
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void OnNodeReferenceAdded(vtkMRMLNodeReference *reference)
Definition: vtkMRMLNode.h:930
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
void SetOverwriteTargetNodeName(bool overwrite)
Deprecated method!