Slicer  4.8
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 
87 class vtkSegmentationCore_EXPORT vtkSegmentation : public vtkObject
88 {
89 public:
90  enum
91  {
93  MasterRepresentationModified = 62100,
106  SegmentsOrderModified
107  };
108 
109  enum
110  {
120  EXTENT_UNION_OF_EFFECTIVE_SEGMENTS_PADDED
121  };
122 
124  typedef std::map<std::string, vtkSmartPointer<vtkSegment> > SegmentMap;
125 
126 public:
127  static vtkSegmentation* New();
128  vtkTypeMacro(vtkSegmentation, vtkObject);
129  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
130 
132  virtual void ReadXMLAttributes(const char** atts);
133 
135  virtual void WriteXML(ostream& of, int indent);
136 
138  virtual void DeepCopy(vtkSegmentation* aSegmentation);
139 
141  virtual void CopyConversionParameters(vtkSegmentation* aSegmentation);
142 
144  virtual void GetBounds(double bounds[6]);
145 
148  virtual void ApplyLinearTransform(vtkAbstractTransform* transform);
149 
152  virtual void ApplyNonLinearTransform(vtkAbstractTransform* transform);
153 
154 #ifndef __VTK_WRAP__
155 //BTX
164  std::string DetermineCommonLabelmapGeometry(int extentComputationMode = EXTENT_UNION_OF_SEGMENTS, const std::vector<std::string>& segmentIDs = std::vector<std::string>());
165 
171  void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
172  const std::vector<std::string>& segmentIDs = std::vector<std::string>(), bool computeEffectiveExtent=false, bool addPadding=false);
173 //ETX
174 #endif // __VTK_WRAP__
175 
177  std::string DetermineCommonLabelmapGeometry(int extentComputationMode, vtkStringArray* segmentIds);
178 
180  void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
181  vtkStringArray* segmentIds, bool computeEffectiveExtent=false, bool addPadding=false);
182 
185  bool SetImageGeometryFromCommonLabelmapGeometry(vtkOrientedImageData* imageData, vtkStringArray* segmentIDs = NULL,
186  int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS);
187 
188 // Segment related methods
189 
202  bool AddSegment(vtkSegment* segment, std::string segmentId = "", std::string insertBeforeSegmentId = "");
203 
207  std::string GenerateUniqueSegmentID(std::string id);
208 
211  void RemoveSegment(std::string segmentId);
212 
215  void RemoveSegment(vtkSegment* segment);
216 
218  void RemoveAllSegments();
219 
222  vtkSegment* GetSegment(std::string segmentId);
223 
225  void GetSegmentIDs(std::vector<std::string> &segmentIds);
226 
228  void GetSegmentIDs(vtkStringArray* segmentIds);
229 
231  int GetNumberOfSegments() const;
232 
234  vtkSegment* GetNthSegment(unsigned int index) const;
235 
237  std::string GetNthSegmentID(unsigned int index) const;
238 
242  int GetSegmentIndex(const std::string& segmentId);
243 
247  bool SetSegmentIndex(const std::string& segmentId, unsigned int newIndex);
248 
253  void ReorderSegments(std::vector<std::string> segmentIdsToMove, std::string insertBeforeSegmentId = "");
254 
257  std::string GetSegmentIdBySegment(vtkSegment* segment);
258 
262  std::string GetSegmentIdBySegmentName(std::string name);
263 
268  std::vector<vtkSegment*> GetSegmentsByTag(std::string tag, std::string value="");
269 
271  vtkDataObject* GetSegmentRepresentation(std::string segmentId, std::string representationName);
272 
279  bool CopySegmentFromSegmentation(vtkSegmentation* fromSegmentation, std::string segmentId, bool removeFromSource=false);
280 
281 // Representation related methods
282 
286  void GetContainedRepresentationNames(std::vector<std::string>& representationNames);
287 
291  bool ContainsRepresentation(std::string representationName);
292 
294  bool IsMasterRepresentationPolyData();
295 
297  bool IsMasterRepresentationImageData();
298 
300  void GetAvailableRepresentationNames(std::set<std::string>& representationNames) { this->Converter->GetAvailableRepresentationNames(representationNames); };
301 
303  void InvalidateNonMasterRepresentations();
304 
305 // Conversion related methods
306 
317  bool CreateRepresentation(const std::string& targetRepresentationName, bool alwaysConvert=false);
318 
324  bool CreateRepresentation(vtkSegmentationConverter::ConversionPathType path,
326 
328  void RemoveRepresentation(const std::string& representationName);
329 
334  bool CanAcceptRepresentation(std::string representationName);
335 
338  bool CanAcceptSegment(vtkSegment* segment);
339 
345  std::string AddEmptySegment(std::string segmentId="", std::string segmentName="", double color[3]=NULL);
346 
348  void GetPossibleConversions(const std::string& targetRepresentationName,
350 
352  void SetConversionParameter(const std::string& name, const std::string& value) { this->Converter->SetConversionParameter(name, value); };
353 
356  std::string GetConversionParameter(const std::string& name) { return this->Converter->GetConversionParameter(name); };
357 
360  const vtkSegmentationConverter::ConversionPathType& path) { this->Converter->GetConversionParametersForPath(conversionParameters, path); };
361 
364  std::string SerializeAllConversionParameters();
365 
368  void DeserializeConversionParameters(std::string conversionParametersString);
369 
370 // Get/set methods
371 
373  vtkGetMacro(MasterRepresentationName, std::string);
377  virtual void SetMasterRepresentationName(const std::string& representationName);
378 
379 protected:
386  bool ConvertSegmentUsingPath(vtkSegment* segment, vtkSegmentationConverter::ConversionPathType path, bool overwriteExisting=false);
387 
389  bool ConvertSingleSegment(std::string segmentId, std::string targetRepresentationName);
390 
393  void RemoveSegment(SegmentMap::iterator segmentIt);
394 
399  bool SetMasterRepresentationModifiedEnabled(bool enabled);
400 
401 protected:
404  static void OnSegmentModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
405 
408  static void OnMasterRepresentationModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
409 
410 protected:
411  vtkSegmentation();
412  ~vtkSegmentation();
413  void operator=(const vtkSegmentation&);
414 
415 protected:
417  SegmentMap Segments;
418 
424 
427 
429  vtkCallbackCommand* SegmentCallbackCommand;
430 
433 
436 
440 
444  std::deque< std::string > SegmentIds;
445 
447  friend class qMRMLSegmentEditorWidgetPrivate;
448 };
449 
450 #endif // __vtkSegmentation_h
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.
Invoked when content of any representation (including the master representation) in a segment is chan...
Extent is computed as union of extent of all segments.
Invoked if a segment is removed.
std::vector< ConversionPathAndCostType > ConversionPathAndCostListType
Extent is computed as union of effective extent of all segments.
Extent is computed as union of extent of all segments, with a single-voxel padding added on each side...
bool MasterRepresentationModifiedEnabled
Modified events of master representations are observed.
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.
vtkCallbackCommand * MasterRepresentationCallbackCommand
Command handling master representation modified events.
Invoked if a representation is created or removed in the segments (e.g., created by conversion from m...
std::deque< std::string > SegmentIds
std::vector< vtkSegmentationConverterRule * > ConversionPathType
vtkCallbackCommand * SegmentCallbackCommand
Command handling segment modified events.
Invoked if new segment is added.
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 of common geometry is used as extent.
void SetConversionParameter(const std::string &name, const std::string &value)
Set a conversion parameter to all rules having this parameter.
vtkSegmentationConverter * Converter
Converter instance.
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.
Class that can convert between different representations of a segment.