30 #include "WMFiberTranslator.h"
31 #include "WMFiberTranslator.xpm"
32 #include "core/dataHandler/WFiberAccumulator.h"
33 #include "core/kernel/WKernel.h"
55 return WMFiberTranslator_xpm;
59 return "Fiber translator";
64 return "Creates a fiber dataset from various data sources.";
69 m_output = std::shared_ptr< WModuleOutputData< WDataSetFibers > >(
82 " contains the coordinates of one fiber (e.g. produced by mrtrix).",
142 if( !boost::filesystem::exists( dir ) || !boost::filesystem::is_directory( dir ) )
144 errorLog() <<
"Directory " << dir.string() <<
" does not exist!";
145 return std::shared_ptr< WDataSetFibers >();
150 boost::filesystem::directory_iterator it( dir );
151 boost::filesystem::directory_iterator end;
154 std::vector< WVector3d > fiber;
156 if( boost::filesystem::is_directory( it->path() ) || it->path().extension() !=
".txt" )
158 debugLog() <<
"Ignoring file " << it->path();
162 std::fstream f( it->path().string().c_str(), std::ios::in );
165 while( f >> v[ 0 ] >> v[ 1 ] >> v[ 2 ] )
167 fiber.push_back( v );
184 debugLog() <<
"Merging fibers (binary).";
186 if( !boost::filesystem::exists( dir ) || !boost::filesystem::is_directory( dir ) )
188 errorLog() <<
"Directory " << dir.string() <<
" does not exist!";
189 return std::shared_ptr< WDataSetFibers >();
194 boost::filesystem::directory_iterator it( dir );
195 boost::filesystem::directory_iterator end;
198 std::vector< WVector3d > fiber;
200 if( boost::filesystem::is_directory( it->path() ) )
202 debugLog() <<
"Ignoring file " << it->path();
206 std::fstream f( it->path().string().c_str(), std::ios::in | std::ios::binary );
209 while( f >> v[ 0 ] >> v[ 1 ] >> v[ 2 ] )
211 fiber.push_back( v );
216 infoLog() <<
"Fiber with " << fiber.size() <<
" points.";
230 debugLog() <<
"Loading fibers from ExploreDTI text format.";
232 if( !boost::filesystem::exists( file ) || boost::filesystem::is_directory( file ) )
234 errorLog() <<
"File " << file.string() <<
" does not exist!";
235 return std::shared_ptr< WDataSetFibers >();
239 if( file.string().length() < 16 || file.string().find(
"_coordinates.txt" ) != file.string().length() - 16 )
241 errorLog() <<
"File " << file <<
" does not end in _coordinates.txt. Ignoring.";
242 return std::shared_ptr< WDataSetFibers >();
246 std::string lengthFile = file.string();
247 lengthFile.resize( lengthFile.length() - 16 );
248 lengthFile +=
"_lengths.txt";
253 std::fstream coords( file.string().c_str(), std::ios::in );
254 std::fstream lengths( lengthFile.c_str(), std::ios::in );
256 while( !lengths.eof() && !lengths.bad() )
263 errorLog() <<
"Lengths file contains an invalid length of " << l <<
", aborting.";
264 return std::shared_ptr< WDataSetFibers >();
267 std::vector< WVector3d > fiber;
268 for(
int i = 0; i < static_cast< int >( l ); ++i )
271 coords >> v[ 0 ] >> v[ 1 ] >> v[ 2 ];
272 fiber.push_back( v );
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
A class that encapsulates the data needed to construct a WDataSetFibers.
void add(std::vector< WVector3d > const &in)
Add a fiber to the dataset.
std::shared_ptr< WDataSetFibers > buildDataSet()
Return the dataset that has been accumulated to this point and start a new dataset.
Creates a fiber dataset from various data sources.
std::shared_ptr< WDataSetFibers > mergeFibers(boost::filesystem::path dir)
Merge the fibers in the given directory.
virtual const std::string getName() const
Gives back the name of this module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void moduleMain()
Entry point after loading the module.
std::shared_ptr< WCondition > m_propCondition
A condition for property updates.
std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_output
The output connector.
WPropFilename m_propInputFile
A property for choosing a file that contains the fiber coordinates.
virtual void properties()
Initialize the properties for this module.
WMFiberTranslator()
Constructor.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropFilename m_propInputDirectory
A property for choosing the directory that contains the fiber text files.
virtual ~WMFiberTranslator()
Destructor.
virtual void connectors()
Initialize the connectors this module is using.
virtual void requirements()
Initialize requirements for this module.
std::shared_ptr< WDataSetFibers > loadExploreDTIFibers(boost::filesystem::path file)
Load fibers from an ExploreDTI .txt file.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
std::shared_ptr< WDataSetFibers > mergeFibersNrrd(boost::filesystem::path dir)
Merge the fibers from given directory.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
virtual void connectors()
Initialize connectors in this function.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
void addTo(WPropFilename prop)
Add the PC_PATHEXISTS constraint to the property.
void addTo(WPropFilename prop)
Add the PC_PATHEXISTS constraint to the property.