Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkContourModelSetWriter.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "mitkContourModelWriter.h"
19 #include <fstream>
20 #include <iostream>
21 #include <mitkCustomMimeType.h>
22 
24 {
25  std::string category = "ContourModelSet File";
26  mitk::CustomMimeType customMimeType;
27  customMimeType.SetCategory(category);
28  customMimeType.AddExtension("cnt_set");
29 
30  this->SetDescription(category);
31  this->SetMimeType(customMimeType);
32 
34 }
35 
37 {
38 }
39 
41 {
42 }
43 
45 {
46  std::ostream *out;
47  std::ofstream outStream;
48 
49  if (this->GetOutputStream())
50  {
51  out = this->GetOutputStream();
52  }
53  else
54  {
55  outStream.open(this->GetOutputLocation().c_str());
56  out = &outStream;
57  }
58 
59  if (!out->good())
60  {
61  mitkThrow() << "Stream not good.";
62  }
63 
64  // Use regular ContourModel writer to write each contour of the set to a single file.
65  // Just use a different file extension .cnt_set
66 
68 
69  mitk::ContourModelSet::ConstPointer contourModelSet = dynamic_cast<const mitk::ContourModelSet *>(this->GetInput());
70 
71  //
72  // for each contour object set input of writer
73  //
74  for (int i = 0; i < contourModelSet->GetSize(); ++i)
75  {
76  const mitk::ContourModel *contour = contourModelSet->GetContourModelAt(i);
77  writer.SetInput(contour);
78  writer.SetOutputStream(this->GetOutputLocation(), out);
79  writer.Write();
80  }
81 }
82 
84 {
85  return new ContourModelSetWriter(*this);
86 }
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
virtual void SetInput(const BaseData *data) override
Set the input data for writing.
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
virtual void SetOutputStream(const std::string &location, std::ostream *os) override
Set an output stream for writing.
#define mitkThrow()
virtual void Write() override
Write the base data to the specified location or output stream.
static const char * GetStaticNameOfClass()
void AddExtension(const std::string &extension)
virtual mitk::ContourModelSetWriter * Clone() const override
void SetCategory(const std::string &category)
virtual void Write() override
Write the base data to the specified location or output stream.
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
XML-based writer for mitk::ContourModelSet.
void SetMimeType(const CustomMimeType &mimeType)
Base class for writing mitk::BaseData objects to files or streams.
void SetDescription(const std::string &description)
Sets a human readable description of this writer.