17 #ifndef __mitkDecisionForestIO__cpp
18 #define __mitkDecisionForestIO__cpp
21 #include "itksys/SystemTools.hxx"
24 #include "vigra/random_forest_hdf5_impex.hxx"
32 #define GetAttribute(name,type)\
34 hdf5_file.readAttribute(".",name,name);
38 std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->
GetLocalFileName().c_str());
58 std::string category =
"Vigra Random Forest File";
59 customReaderMimeType.
SetComment(
"Vigra Random Forest");
84 std::vector<itk::SmartPointer<mitk::BaseData> >
89 std::vector<itk::SmartPointer<mitk::BaseData> > result;
91 if ( this->GetInputLocation().empty())
93 MITK_ERROR <<
"Sorry, filename has not been set!";
98 const std::string& locale =
"C";
99 const std::string& currLocale = setlocale( LC_ALL, NULL );
101 if ( locale.compare(currLocale)!=0 )
105 setlocale(LC_ALL, locale.c_str());
109 MITK_INFO <<
"Could not set locale " << locale;
113 output->SetRandomForest(m_rf);
114 result.push_back(output.GetPointer());
115 vigra::HDF5File hdf5_file(this->GetInputLocation() , vigra::HDF5File::Open);
118 hdf5_file.cd_mk(
"/_mitkOptions");
122 if(hdf5_file.existsDataset(
"treeWeights"))
124 auto treeWeight = output->GetTreeWeights();
125 treeWeight.resize(m_rf.tree_count(),1);
126 vigra::MultiArrayView<2, double> W(vigra::Shape2(treeWeight.rows(),treeWeight.cols()),treeWeight.data());
127 hdf5_file.read(
"treeWeights",W);
128 output->SetTreeWeights(treeWeight);
134 if(hdf5_file.existsDataset(
"itemList")){
135 std::string items_string;
136 hdf5_file.read(
"itemList",items_string);
137 auto itemlist = output->GetItemList();
139 std::string current_item =
"";
140 for(
auto character : items_string)
142 if(character ==
';'){
144 itemlist.push_back(current_item);
145 current_item.clear();
147 current_item = current_item + character;
150 output->SetItemList(itemlist);
165 MITK_ERROR <<
"Sorry, input to NrrdDiffusionImageWriter is NULL!";
168 if ( this->GetOutputLocation().empty() )
170 MITK_ERROR <<
"Sorry, filename has not been set!";
173 const std::string& locale =
"C";
174 const std::string& currLocale = setlocale( LC_ALL, NULL );
176 if ( locale.compare(currLocale)!=0 )
180 setlocale(LC_ALL, locale.c_str());
184 MITK_INFO <<
"Could not set locale " << locale;
190 vigra::rf_export_HDF5(mitkDC->GetRandomForest(), this->GetOutputLocation());
192 vigra::HDF5File hdf5_file(this->GetOutputLocation() , vigra::HDF5File::Open);
194 hdf5_file.cd_mk(
"/_mitkOptions");
198 auto treeWeight = mitkDC->GetTreeWeights();
199 vigra::MultiArrayView<2, double> W(vigra::Shape2(treeWeight.rows(),treeWeight.cols()),treeWeight.data());
200 hdf5_file.write(
"treeWeights",W);
205 auto items = mitkDC->GetItemList();
206 std::string item_stringlist;
207 for(
auto entry : items)
208 item_stringlist = item_stringlist + entry +
";";
210 hdf5_file.write(
"itemList",item_stringlist);
DataCollection - Class to facilitate loading/accessing structured data.
std::string GetLocalFileName() const
Get a local file name for reading.
void SetComment(const std::string &comment)
virtual ~RandomForestFileIO()
void SetMimeType(const CustomMimeType &mimeType)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
void SetMimeTypePrefix(const std::string &prefix)
virtual void Write()
Write the base data to the specified location or output stream.
virtual std::vector< itk::SmartPointer< BaseData > > Read()
Reads a path or stream and creates a list of BaseData objects.
static std::string DEFAULT_BASE_NAME()
vigra::RandomForest< int > m_rf
virtual ConfidenceLevel GetReaderConfidenceLevel() const
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService(us::ModuleContext *context=us::GetModuleContext())
void SetReaderDescription(const std::string &description)
static const char * GetStaticNameOfClass()
void AddExtension(const std::string &extension)
void SetWriterDescription(const std::string &description)
void SetCategory(const std::string &category)
virtual ConfidenceLevel GetWriterConfidenceLevel() const
void SetMimeType(const CustomMimeType &mimeType)
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
virtual std::string GetInputLocation() const override
Get the current input location.
void SetMimeTypePrefix(const std::string &prefix)
Abstract class for implementing a reader and writer.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.