13 #ifndef __mitkDecisionForestIO__cpp 14 #define __mitkDecisionForestIO__cpp 17 #include "itksys/SystemTools.hxx" 20 #include "vigra/random_forest_hdf5_impex.hxx" 28 #define GetAttribute(name,type)\ 30 hdf5_file.readAttribute(".",name,name); 34 std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->
GetLocalFileName().c_str());
54 std::string category =
"Vigra Random Forest File";
55 customReaderMimeType.
SetComment(
"Vigra Random Forest");
80 std::vector<itk::SmartPointer<mitk::BaseData> >
85 std::vector<itk::SmartPointer<mitk::BaseData> > result;
89 MITK_ERROR <<
"Sorry, filename has not been set!";
94 const std::string& locale =
"C";
95 const std::string& currLocale = setlocale( LC_ALL,
nullptr );
97 if ( locale.compare(currLocale)!=0 )
101 setlocale(LC_ALL, locale.c_str());
105 MITK_INFO <<
"Could not set locale " << locale;
109 output->SetRandomForest(
m_rf);
110 result.push_back(output.GetPointer());
111 vigra::HDF5File hdf5_file(this->
GetInputLocation() , vigra::HDF5File::Open);
114 hdf5_file.cd_mk(
"/_mitkOptions");
118 if(hdf5_file.existsDataset(
"treeWeights"))
120 auto treeWeight = output->GetTreeWeights();
121 treeWeight.resize(
m_rf.tree_count(),1);
122 vigra::MultiArrayView<2, double> W(vigra::Shape2(treeWeight.rows(),treeWeight.cols()),treeWeight.data());
123 hdf5_file.read(
"treeWeights",W);
124 output->SetTreeWeights(treeWeight);
130 if(hdf5_file.existsDataset(
"itemList")){
131 std::string items_string;
132 hdf5_file.read(
"itemList",items_string);
133 auto itemlist = output->GetItemList();
135 std::string current_item =
"";
136 for(
auto character : items_string)
138 if(character ==
';'){
140 itemlist.push_back(current_item);
141 current_item.clear();
143 current_item = current_item + character;
146 output->SetItemList(itemlist);
161 MITK_ERROR <<
"Sorry, input to NrrdDiffusionImageWriter is nullptr!";
166 MITK_ERROR <<
"Sorry, filename has not been set!";
169 const std::string& locale =
"C";
170 const std::string& currLocale = setlocale( LC_ALL,
nullptr );
172 if ( locale.compare(currLocale)!=0 )
176 setlocale(LC_ALL, locale.c_str());
180 MITK_INFO <<
"Could not set locale " << locale;
190 hdf5_file.cd_mk(
"/_mitkOptions");
194 auto treeWeight = mitkDC->GetTreeWeights();
195 vigra::MultiArrayView<2, double> W(vigra::Shape2(treeWeight.rows(),treeWeight.cols()),treeWeight.data());
196 hdf5_file.write(
"treeWeights",W);
201 auto items = mitkDC->GetItemList();
202 std::string item_stringlist;
203 for(
auto entry : items)
204 item_stringlist = item_stringlist + entry +
";";
206 hdf5_file.write(
"itemList",item_stringlist);
~RandomForestFileIO() override
ConfidenceLevel GetWriterConfidenceLevel() const override
DataCollection - Class to facilitate loading/accessing structured data.
void SetComment(const std::string &comment)
void SetMimeType(const CustomMimeType &mimeType)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
std::string GetLocalFileName() const
Get a local file name for reading.
void SetMimeTypePrefix(const std::string &prefix)
static std::string DEFAULT_BASE_NAME()
vigra::RandomForest< int > m_rf
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService(us::ModuleContext *context=us::GetModuleContext())
const BaseData * GetInput() const override
Get the input data set via SetInput().
void SetReaderDescription(const std::string &description)
void AddExtension(const std::string &extension)
void Write() override
Write the base data to the specified location or output stream.
void SetWriterDescription(const std::string &description)
std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
void SetCategory(const std::string &category)
void SetMimeType(const CustomMimeType &mimeType)
std::string GetOutputLocation() const override
Get the current output location.
std::string GetInputLocation() const override
Get the current input location.
void SetMimeTypePrefix(const std::string &prefix)
Abstract class for implementing a reader and writer.
ConfidenceLevel GetReaderConfidenceLevel() const override