OpenWalnut  1.5.0dev
WMReadAmiraMesh.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMREADAMIRAMESH_H
26 #define WMREADAMIRAMESH_H
27 
28 #include <memory>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 #include <osg/Geode>
34 
35 #include "core/dataHandler/WDataSetFibers.h"
36 #include "core/kernel/WModule.h"
37 #include "core/kernel/WModuleInputData.h"
38 #include "core/kernel/WModuleOutputData.h"
39 
40 /**
41  * Reader for amiraMesh (.am) files.
42  *
43  * \ingroup modules
44  */
45 class WMReadAmiraMesh: public WModule
46 {
47 /**
48  * Only UnitTests may be friends.
49  */
50 friend class WMReadAmiraMeshTest;
51 
52 public:
53  /**
54  * Standard constructor
55  */
57 
58  /**
59  * Destructor for cleaning up resources.
60  */
61  virtual ~WMReadAmiraMesh();
62 
63  /**
64  * Gives back the name of this module.
65  * \return the module's name.
66  */
67  virtual const std::string getName() const;
68 
69  /**
70  * Gives back a description of this module.
71  * \return description to module.
72  */
73  virtual const std::string getDescription() const;
74 
75  /**
76  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
77  * should never be initialized or modified in some other way. A simple new instance is required.
78  *
79  * \return the prototype used to create every module in OpenWalnut.
80  */
81  virtual std::shared_ptr< WModule > factory() const;
82 
83  /**
84  * Get the icon for this module in XPM format.
85  *
86  * \return The icon.
87  */
88  virtual const char** getXPMIcon() const;
89 
90 protected:
91  /**
92  * Entry point after loading the module. Runs in separate thread.
93  */
94  virtual void moduleMain();
95 
96  /**
97  * Initialize the connectors this module is using.
98  */
99  virtual void connectors();
100 
101  /**
102  * Initialize the properties for this module.
103  */
104  virtual void properties();
105 
106  /**
107  * Initialize requirements for this module.
108  */
109  virtual void requirements();
110 
111 private:
112  /**
113  * Very prelimiary and specialized way of reading a spatial graph from an amira mesh
114  *
115  * \param fileName The name of the file containing the data that wil be read.
116  * \return Indicates whether reading has been successful.
117  */
118  bool readAmiraMesh( std::string fileName );
119 
120  /**
121  * Function for reading coordinates of vertices.
122  * It searches for the startLabel and starts reading from there
123  *
124  * \param startLabel This label marks the location in the file where the data starts.
125  * \param numVertices The number of vertices that are being read.
126  * \param fileName File containing the data to be read.
127  */
128  void findAndReadVertices( std::string startLabel, size_t numVertices, std::string fileName );
129 
130  /**
131  * Function for reading connectivity of edges.
132  * It searches for the startLabel and starts reading from there
133  *
134  * \param startLabel This label marks the location in the file where the data starts.
135  * \param numConnections The number of connections that are being read.
136  * \param fileName File containing the data to be read.
137  */
138  void findAndReadEdgeConnectivity( std::string startLabel, size_t numConnections, std::string fileName );
139 
140  /**
141  * Function for reading number of edgepoints per edge.
142  * It searches for the startLabel and starts reading from there
143  *
144  * \param startLabel This label marks the location in the file where the data starts.
145  * \param numEdges The number of edges for which number of points are being read.
146  * \param fileName File containing the data to be read.
147  */
148  void findAndReadNumEdgePoints( std::string startLabel, size_t numEdges, std::string fileName );
149 
150  /**
151  * Function for reading edgepoints.
152  * It searches for the startLabel and starts reading from there
153  *
154  * \param startLabel This label marks the location in the file where the data starts.
155  * \param numPoints The number of points for which coordinates are being read.
156  * \param fileName File containing the data to be read.
157  */
158  void findAndReadEdgePoints( std::string startLabel, size_t numPoints, std::string fileName );
159 
160  /**
161  * This function prepares the resulting dataset for being provided
162  * at the connector by construting it from the basic data that has been read.
163  */
164  void prepareResult();
165 
166  WPropFilename m_dataFile; //!< The data will be read from this file.
167  std::shared_ptr< WCondition > m_propCondition; //!< A condition used to notify about changes in several properties.
168 
169  std::vector< WPosition > m_vertices; //!< vertices of the spatial graph
170  std::vector< std::pair< size_t, size_t > > m_edges; //!< Edge connectivity of the spatial graph.
171  std::vector< size_t > m_numEdgePoints; //!< Number "points" per edge.
172  std::vector< WPosition > m_edgePoints; //!< The positions of the points building the edges between the vertices.
173 
174  std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_output; //!< The only output of this data module.
175  std::shared_ptr< WDataSetFibers > m_graph; //!< The resulting fiber dataset respresenting the spatial graph
176 };
177 
178 #endif // WMREADAMIRAMESH_H
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.
friend class WMReadAmiraMeshTest
Only UnitTests may be friends.
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 representing a single module of OpenWalnut.
Definition: WModule.h:72