OpenWalnut  1.5.0dev
WMWriteMesh.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 WMWRITEMESH_H
26 #define WMWRITEMESH_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <osg/Geode>
33 
34 #include "core/graphicsEngine/WTriangleMesh.h"
35 #include "core/kernel/WModule.h"
36 #include "core/kernel/WModuleInputData.h"
37 #include "core/kernel/WModuleOutputData.h"
38 
39 /**
40  * This module writes the triangle mesh given at its input connector
41  * as a VTK ASCII file or .json file or STL file
42  *
43  * \ingroup modules
44  */
45 class WMWriteMesh: public WModule
46 {
47 /**
48  * Only UnitTests may be friends.
49  */
50 friend class WMWriteMeshTest;
51 
52 public:
53  /**
54  *
55  */
56  WMWriteMesh();
57 
58  /**
59  *
60  */
61  virtual ~WMWriteMesh();
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  * \return The icon.
86  */
87  virtual const char** getXPMIcon() const;
88 
89 protected:
90  /**
91  * Entry point after loading the module. Runs in separate thread.
92  */
93  virtual void moduleMain();
94 
95  /**
96  * Initialize the connectors this module is using.
97  */
98  virtual void connectors();
99 
100  /**
101  * Initialize the properties for this module.
102  */
103  virtual void properties();
104 
105 
106 private:
107  /**
108  * Store the mesh in legacy vtk file format.
109  *
110  * \return true if successful.
111  */
112  bool saveVTKASCII() const;
113 
114  /**
115  * Write STL format.
116  *
117  * \return true if successful.
118  */
119  bool saveSTL();
120 
121  /**
122  * Store the mesh in a json (javascript object notation) file.
123  *
124  * \return true if successful.
125  */
126  bool saveJson();
127 
128  /**
129  * Splits the mesh in several mesh files (to solve maximum mesh limits in BrainGlL).
130  *
131  * \param triMesh mesh object to be divided
132  * \param targetSize maximum resulting mesh size
133  * \return vector of resulting meshes
134  */
135  std::vector< std::shared_ptr< WTriangleMesh > >splitMesh( std::shared_ptr< WTriangleMesh > triMesh, size_t targetSize );
136 
137  std::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshInput; //!< Input connector for a mesh
138  std::shared_ptr< WTriangleMesh > m_triMesh; //!< A pointer to the currently processed tri mesh
139  std::shared_ptr< WCondition > m_propCondition; //!< A condition used to notify about changes in several properties.
140  WPropGroup m_savePropGroup; //!< Property group containing properties needed for saving the mesh.
141  WPropTrigger m_saveTriggerProp; //!< This property triggers the actual writing,
142  WPropFilename m_meshFile; //!< The mesh will be written to this file.
143 
144  /**
145  * A list of file type selection types
146  */
147  std::shared_ptr< WItemSelection > m_fileTypeSelectionsList;
148 
149  /**
150  * Selection property for file types
151  */
152  WPropSelection m_fileTypeSelection;
153 
154  /**
155  * If true, colors get exported too.
156  */
157  WPropBool m_writeColors;
158 };
159 
160 #endif // WMWRITEMESH_H
Test for WMWriteMesh.
This module writes the triangle mesh given at its input connector as a VTK ASCII file or ....
Definition: WMWriteMesh.h:46
virtual void moduleMain()
Entry point after loading the module.
bool saveSTL()
Write STL format.
WPropSelection m_fileTypeSelection
Selection property for file types.
Definition: WMWriteMesh.h:152
bool saveVTKASCII() const
Store the mesh in legacy vtk file format.
virtual const std::string getName() const
Gives back the name of this module.
Definition: WMWriteMesh.cpp:61
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
Definition: WMWriteMesh.h:139
bool saveJson()
Store the mesh in a json (javascript object notation) file.
virtual const std::string getDescription() const
Gives back a description of this module.
Definition: WMWriteMesh.cpp:66
std::shared_ptr< WItemSelection > m_fileTypeSelectionsList
A list of file type selection types.
Definition: WMWriteMesh.h:147
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
Definition: WMWriteMesh.cpp:57
WPropBool m_writeColors
If true, colors get exported too.
Definition: WMWriteMesh.h:157
WPropFilename m_meshFile
The mesh will be written to this file.
Definition: WMWriteMesh.h:142
std::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshInput
Input connector for a mesh.
Definition: WMWriteMesh.h:137
virtual void properties()
Initialize the properties for this module.
Definition: WMWriteMesh.cpp:84
std::shared_ptr< WTriangleMesh > m_triMesh
A pointer to the currently processed tri mesh.
Definition: WMWriteMesh.h:138
WPropTrigger m_saveTriggerProp
This property triggers the actual writing,.
Definition: WMWriteMesh.h:141
virtual void connectors()
Initialize the connectors this module is using.
Definition: WMWriteMesh.cpp:73
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...
Definition: WMWriteMesh.cpp:51
std::vector< std::shared_ptr< WTriangleMesh > > splitMesh(std::shared_ptr< WTriangleMesh > triMesh, size_t targetSize)
Splits the mesh in several mesh files (to solve maximum mesh limits in BrainGlL).
WPropGroup m_savePropGroup
Property group containing properties needed for saving the mesh.
Definition: WMWriteMesh.h:140
Class representing a single module of OpenWalnut.
Definition: WModule.h:72