Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include "mitkContourModelWriter.h"
15 #include <fstream>
16 #include <iostream>
17 #include <mitkCustomMimeType.h>
18 
20 {
21  std::string category = "ContourModelSet File";
22  mitk::CustomMimeType customMimeType;
23  customMimeType.SetCategory(category);
24  customMimeType.AddExtension("cnt_set");
25 
26  this->SetDescription(category);
27  this->SetMimeType(customMimeType);
28 
30 }
31 
33 {
34 }
35 
37 {
38 }
39 
41 {
42  std::ostream *out;
43  std::ofstream outStream;
44 
45  if (this->GetOutputStream())
46  {
47  out = this->GetOutputStream();
48  }
49  else
50  {
51  outStream.open(this->GetOutputLocation().c_str());
52  out = &outStream;
53  }
54 
55  if (!out->good())
56  {
57  mitkThrow() << "Stream not good.";
58  }
59 
60  // Use regular ContourModel writer to write each contour of the set to a single file.
61  // Just use a different file extension .cnt_set
62 
64 
65  mitk::ContourModelSet::ConstPointer contourModelSet = dynamic_cast<const mitk::ContourModelSet *>(this->GetInput());
66 
67  //
68  // for each contour object set input of writer
69  //
70  for (int i = 0; i < contourModelSet->GetSize(); ++i)
71  {
72  const mitk::ContourModel *contour = contourModelSet->GetContourModelAt(i);
73  writer.SetInput(contour);
74  writer.SetOutputStream(this->GetOutputLocation(), out);
75  writer.Write();
76  }
77 }
78 
80 {
81  return new ContourModelSetWriter(*this);
82 }
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
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...
void SetOutputStream(const std::string &location, std::ostream *os) override
Set an output stream for writing.
#define mitkThrow()
void Write() override
Write the base data to the specified location or output stream.
const BaseData * GetInput() const override
Get the input data set via SetInput().
void AddExtension(const std::string &extension)
mitk::ContourModelSetWriter * Clone() const override
void SetCategory(const std::string &category)
std::ostream * GetOutputStream() const override
Get the output stream.
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)
std::string GetOutputLocation() const override
Get the current output location.
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.