Slicer  4.10
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkSegmentation.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
4  Queen's University, Kingston, ON, Canada. All Rights Reserved.
5 
6  See COPYRIGHT.txt
7  or http://www.slicer.org/copyright/copyright.txt for details.
8 
9  Unless required by applicable law or agreed to in writing, software
10  distributed under the License is distributed on an "AS IS" BASIS,
11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  See the License for the specific language governing permissions and
13  limitations under the License.
14 
15  This file was originally developed by Csaba Pinter, PerkLab, Queen's University
16  and was supported through the Applied Cancer Research Unit program of Cancer Care
17  Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
18 
19 ==============================================================================*/
20 
21 #ifndef __vtkSegmentation_h
22 #define __vtkSegmentation_h
23 
24 // VTK includes
25 #include <vtkObject.h>
26 #include <vtkSmartPointer.h>
27 
28 // STD includes
29 #include <map>
30 #include <deque>
31 
32 // SegmentationCore includes
33 #include "vtkSegment.h"
36 
37 #include "vtkSegmentationCoreConfigure.h"
38 
39 class vtkAbstractTransform;
40 class vtkCallbackCommand;
41 class vtkStringArray;
42 
89 class vtkSegmentationCore_EXPORT vtkSegmentation : public vtkObject
90 {
91 public:
92  enum
93  {
95  MasterRepresentationModified = 62100,
108  SegmentsOrderModified
109  };
110 
111  enum
112  {
122  EXTENT_UNION_OF_EFFECTIVE_SEGMENTS_PADDED
123  };
124 
126  typedef std::map<std::string, vtkSmartPointer<vtkSegment> > SegmentMap;
127 
128 public:
129  static vtkSegmentation* New();
130  vtkTypeMacro(vtkSegmentation, vtkObject);
131  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
132 
134  virtual void ReadXMLAttributes(const char** atts);
135 
137  virtual void WriteXML(ostream& of, int indent);
138 
140  virtual void DeepCopy(vtkSegmentation* aSegmentation);
141 
143  virtual void CopyConversionParameters(vtkSegmentation* aSegmentation);
144 
146  virtual void GetBounds(double bounds[6]);
147 
150  virtual void ApplyLinearTransform(vtkAbstractTransform* transform);
151 
154  virtual void ApplyNonLinearTransform(vtkAbstractTransform* transform);
155 
156 #ifndef __VTK_WRAP__
157 //BTX
166  std::string DetermineCommonLabelmapGeometry(int extentComputationMode = EXTENT_UNION_OF_SEGMENTS, const std::vector<std::string>& segmentIDs = std::vector<std::string>());
167 
173  void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
174  const std::vector<std::string>& segmentIDs = std::vector<std::string>(), bool computeEffectiveExtent=false, bool addPadding=false);
175 //ETX
176 #endif // __VTK_WRAP__
177 
179  std::string DetermineCommonLabelmapGeometry(int extentComputationMode, vtkStringArray* segmentIds);
180 
182  void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
183  vtkStringArray* segmentIds, bool computeEffectiveExtent=false, bool addPadding=false);
184 
187  bool SetImageGeometryFromCommonLabelmapGeometry(vtkOrientedImageData* imageData, vtkStringArray* segmentIDs = NULL,
188  int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS);
189 
190 // Segment related methods
191 
204  bool AddSegment(vtkSegment* segment, std::string segmentId = "", std::string insertBeforeSegmentId = "");
205 
209  std::string GenerateUniqueSegmentID(std::string id);
210 
213  void RemoveSegment(std::string segmentId);
214 
217  void RemoveSegment(vtkSegment* segment);
218 
220  void RemoveAllSegments();
221 
224  vtkSegment* GetSegment(std::string segmentId);
225 
227  void GetSegmentIDs(std::vector<std::string> &segmentIds);
228 
230  void GetSegmentIDs(vtkStringArray* segmentIds);
231 
233  int GetNumberOfSegments() const;
234 
236  vtkSegment* GetNthSegment(unsigned int index) const;
237 
239  std::string GetNthSegmentID(unsigned int index) const;
240 
244  int GetSegmentIndex(const std::string& segmentId);
245 
249  bool SetSegmentIndex(const std::string& segmentId, unsigned int newIndex);
250 
255  void ReorderSegments(std::vector<std::string> segmentIdsToMove, std::string insertBeforeSegmentId = "");
256 
259  std::string GetSegmentIdBySegment(vtkSegment* segment);
260 
264  std::string GetSegmentIdBySegmentName(std::string name);
265 
270  std::vector<vtkSegment*> GetSegmentsByTag(std::string tag, std::string value="");
271 
273  vtkDataObject* GetSegmentRepresentation(std::string segmentId, std::string representationName);
274 
281  bool CopySegmentFromSegmentation(vtkSegmentation* fromSegmentation, std::string segmentId, bool removeFromSource=false);
282 
283 // Representation related methods
284 
288  void GetContainedRepresentationNames(std::vector<std::string>& representationNames);
289 
293  bool ContainsRepresentation(std::string representationName);
294 
296  bool IsMasterRepresentationPolyData();
297 
299  bool IsMasterRepresentationImageData();
300 
302  void GetAvailableRepresentationNames(std::set<std::string>& representationNames) { this->Converter->GetAvailableRepresentationNames(representationNames); };
303 
305  void InvalidateNonMasterRepresentations();
306 
307 // Conversion related methods
308 
319  bool CreateRepresentation(const std::string& targetRepresentationName, bool alwaysConvert=false);
320 
326  bool CreateRepresentation(vtkSegmentationConverter::ConversionPathType path,
328 
330  void RemoveRepresentation(const std::string& representationName);
331 
336  bool CanAcceptRepresentation(std::string representationName);
337 
340  bool CanAcceptSegment(vtkSegment* segment);
341 
347  std::string AddEmptySegment(std::string segmentId="", std::string segmentName="", double color[3]=NULL);
348 
350  void GetPossibleConversions(const std::string& targetRepresentationName,
352 
354  void SetConversionParameter(const std::string& name, const std::string& value) { this->Converter->SetConversionParameter(name, value); };
355 
358  std::string GetConversionParameter(const std::string& name) { return this->Converter->GetConversionParameter(name); };
359 
362  const vtkSegmentationConverter::ConversionPathType& path) { this->Converter->GetConversionParametersForPath(conversionParameters, path); };
363 
366  std::string SerializeAllConversionParameters();
367 
370  void DeserializeConversionParameters(std::string conversionParametersString);
371 
372 // Get/set methods
373 
375  vtkGetMacro(MasterRepresentationName, std::string);
379  virtual void SetMasterRepresentationName(const std::string& representationName);
380 
381 protected:
388  bool ConvertSegmentUsingPath(vtkSegment* segment, vtkSegmentationConverter::ConversionPathType path, bool overwriteExisting=false);
389 
391  bool ConvertSingleSegment(std::string segmentId, std::string targetRepresentationName);
392 
395  void RemoveSegment(SegmentMap::iterator segmentIt);
396 
401  bool SetMasterRepresentationModifiedEnabled(bool enabled);
402 
407  bool SetSegmentModifiedEnabled(bool enabled);
408 
409 protected:
412  static void OnSegmentModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
413 
416  static void OnMasterRepresentationModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
417 
418 protected:
419  vtkSegmentation();
420  ~vtkSegmentation();
421  void operator=(const vtkSegmentation&);
422 
423 protected:
426 
432 
435 
437  vtkCallbackCommand* SegmentCallbackCommand;
438 
441 
444 
447 
451 
455  std::deque< std::string > SegmentIds;
456 
459  friend class qMRMLSegmentEditorWidgetPrivate;
460 };
461 
462 #endif // __vtkSegmentation_h
Invoked if a segment is removed.
This class encapsulates a segment that is part of a segmentation.
Definition: vtkSegment.h:45
void GetAvailableRepresentationNames(std::set< std::string > &representationNames)
Get all representations supported by the converter.
std::vector< ConversionPathAndCostType > ConversionPathAndCostListType
Invoked if a representation is created or removed in the segments (e.g., created by conversion from m...
bool MasterRepresentationModifiedEnabled
Modified events of master representations are observed.
Extent is computed as union of extent of all segments, with a single-voxel padding added on each side...
Invoked if new segment is added.
Extent is computed as union of extent of all segments.
void GetConversionParametersForPath(vtkSegmentationConverterRule::ConversionParameterListType &conversionParameters, const vtkSegmentationConverter::ConversionPathType &path)
Get names of all conversion parameters used by the selected conversion path.
Image data containing orientation information.
Extent of common geometry is used as extent.
vtkCallbackCommand * MasterRepresentationCallbackCommand
Command handling master representation modified events.
std::deque< std::string > SegmentIds
std::vector< vtkSegmentationConverterRule * > ConversionPathType
vtkCallbackCommand * SegmentCallbackCommand
Command handling segment modified events.
bool SegmentModifiedEnabled
Modified events of segments are observed.
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
std::map< std::string, std::pair< std::string, std::string > > ConversionParameterListType
std::string MasterRepresentationName
std::string GetConversionParameter(const std::string &name)
Extent is computed as union of effective extent of all segments.
void SetConversionParameter(const std::string &name, const std::string &value)
Set a conversion parameter to all rules having this parameter.
vtkSegmentationConverter * Converter
Converter instance.
Invoked when content of any representation (including the master representation) in a segment is chan...
std::map< std::string, vtkSmartPointer< vtkSegment > > SegmentMap
Container type for segments. Maps segment IDs to segment objects.
SegmentMap Segments
Container of segments that belong to this segmentation.
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...
Class that can convert between different representations of a segment.