31 #include "WMReadAmiraMesh.h"
32 #include "WMReadAmiraMesh.xpm"
33 #include "core/common/WIOTools.h"
34 #include "core/common/WPathHelper.h"
35 #include "core/dataHandler/WDataSetFiberVector.h"
36 #include "core/dataHandler/WDataSetFibers.h"
37 #include "core/kernel/WKernel.h"
59 return WMReadAmiraMesh_xpm;
63 return "Read Amira Mesh";
68 return "Read AmiraMesh file format. At the moment only spatial graphs are supported.";
74 shared_from_this(),
"out",
"A loaded dataset." ) );
108 if( readingSuccessful )
117 std::shared_ptr< std::vector< WFiber > > fibs(
new std::vector< WFiber > );
118 size_t globalPointId = 0;
119 for(
size_t edgeId = 0; edgeId <
m_edges.size(); ++edgeId )
121 std::vector< WPosition > fiberPoints;
122 for(
size_t localPointId = 0; localPointId <
m_numEdgePoints[edgeId]; ++localPointId )
128 fibs->push_back(
WFiber( fiberPoints ) );
135 bool checkVersionString( std::string line )
137 return line ==
"# AmiraMesh 3D ASCII 2.0";
140 size_t parseDefine( std::string line )
143 return string_utils::fromString< double >( tokens[2] );
146 void skipEmptyAndCommentLines( std::ifstream* data, std::string* line )
148 getline( *data, *line );
149 while( *line == std::string(
"") || (*line)[0] ==
'#' )
151 getline( *data, *line );
155 bool parseParameters( std::ifstream* data, std::string* line )
157 bool contenTypeIsHxSpatialGraph =
false;
158 while( *line != std::string(
"}" ) )
160 if( line->find(
"ContentType" ) != std::string::npos
161 && line->find(
"HxSpatialGraph" ) != std::string::npos )
163 contenTypeIsHxSpatialGraph =
true;
166 getline( *data, *line );
168 return contenTypeIsHxSpatialGraph;
171 void findStartLabel(
const std::string& startLabel, std::ifstream* dataStream )
174 while( tmp.find( startLabel ) != 0 )
176 getline( *dataStream, tmp );
182 std::ifstream dataStream( fileName.c_str() );
183 findStartLabel( startLabel, &dataStream );
186 for(
size_t pointId = 0; pointId < numPoints; ++pointId )
194 std::ifstream dataStream( fileName.c_str() );
195 findStartLabel( startLabel, &dataStream );
198 for(
size_t edgeId = 0; edgeId < numEdges; ++edgeId )
207 std::ifstream dataStream( fileName.c_str() );
208 findStartLabel( startLabel, &dataStream );
210 std::pair< size_t, size_t > edge;
212 for(
size_t edgeId = 0; edgeId < numConnections; ++edgeId )
214 dataStream >> edge.first >> edge.second;
221 std::ifstream dataStream( fileName.c_str() );
222 findStartLabel( startLabel, &dataStream );
226 for(
size_t vertexId = 0; vertexId < numVertices; ++vertexId )
228 dataStream >> vertex[0] >> vertex[1] >> vertex[2];
236 std::ifstream dataFile( fileName.c_str() );
238 if( dataFile && fileExists( fileName ) )
249 getline( dataFile, tmp );
250 if( !checkVersionString( tmp ) )
255 skipEmptyAndCommentLines( &dataFile, &tmp );
257 std::vector< size_t > dimensions;
258 while( tmp.find(
"define " ) == 0 )
260 dimensions.push_back( parseDefine( tmp ) );
261 getline( dataFile, tmp );
264 skipEmptyAndCommentLines( &dataFile, &tmp );
266 if( tmp.find(
"Parameters {" ) == 0 )
268 if( !parseParameters( &dataFile, &tmp ) )
279 std::string startLabelVertices =
"@1";
283 std::string startLabelEdgeConnectivity =
"@2";
287 std::string startLabelNumEdgePoints =
"@3";
291 std::string startLabelEdgePoints =
"@4";
virtual void wait() const
Wait for the condition.
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.
Represents a simple set of WFibers.
std::shared_ptr< WDataSetFibers > toWDataSetFibers() const
Convert this dataset into WDataSetFibers format for other purposes if needed.
Represents a neural pathway.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
Reader for amiraMesh (.am) files.
std::vector< size_t > m_numEdgePoints
Number "points" per edge.
void findAndReadNumEdgePoints(std::string startLabel, size_t numEdges, std::string fileName)
Function for reading number of edgepoints per edge.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropFilename m_dataFile
The data will be read from this file.
std::vector< WPosition > m_vertices
vertices of the spatial graph
std::shared_ptr< WDataSetFibers > m_graph
The resulting fiber dataset respresenting the spatial graph.
std::vector< WPosition > m_edgePoints
The positions of the points building the edges between the vertices.
virtual ~WMReadAmiraMesh()
Destructor for cleaning up resources.
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...
virtual const std::string getName() const
Gives back the name of this module.
virtual void moduleMain()
Entry point after loading the module.
bool readAmiraMesh(std::string fileName)
Very prelimiary and specialized way of reading a spatial graph from an amira mesh.
virtual void requirements()
Initialize requirements for this module.
void findAndReadEdgeConnectivity(std::string startLabel, size_t numConnections, std::string fileName)
Function for reading connectivity of edges.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
void prepareResult()
This function prepares the resulting dataset for being provided at the connector by construting it fr...
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
std::vector< std::pair< size_t, size_t > > m_edges
Edge connectivity of the spatial graph.
virtual void properties()
Initialize the properties for this module.
WMReadAmiraMesh()
Standard constructor.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_output
The only output of this data module.
void findAndReadEdgePoints(std::string startLabel, size_t numPoints, std::string fileName)
Function for reading edgepoints.
void findAndReadVertices(std::string startLabel, size_t numVertices, std::string fileName)
Function for reading coordinates of vertices.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
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.
virtual void connectors()
Initialize connectors in this function.
static boost::filesystem::path getAppPath()
The path where the binary file resides in.
This only is a 3d double vector.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
std::vector< std::string > tokenize(const std::string &source, const std::string &delim=WHITESPACE, bool compress=true)
Splits the given string into a vector of strings (so called tokens).