OpenWalnut  1.5.0dev
WMReadMesh.cpp
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 #include <fstream>
26 #include <limits>
27 #include <memory>
28 #include <string>
29 #include <vector>
30 
31 #include "WMReadMesh.h"
32 #include "WMReadMesh.xpm"
33 #include "WMeshReaderBrainVISA.h"
34 #include "WMeshReaderDIP.h"
35 #include "WMeshReaderFiberNavigator.h"
36 #include "WMeshReaderFreesurfer.h"
37 #include "WMeshReaderOBJ.h"
38 #include "WMeshReaderVTK.h"
39 #include "core/common/WIOTools.h"
40 #include "core/common/WPathHelper.h"
41 #include "core/common/WPropertyHelper.h"
42 #include "core/common/WStringUtils.h"
43 #include "core/graphicsEngine/WTriangleMesh.h"
44 #include "core/kernel/WKernel.h"
45 
46 // This line is needed by the module loader to actually find your module.
47 W_LOADABLE_MODULE( WMReadMesh )
48 
49 WMReadMesh::WMReadMesh():
50  WModule(),
51  m_strategy( "Mesh Type", "Select one of the mesh types and configure it to your needs.", NULL,
52  "Loader", "A list of all known mesh loader." )
53 {
54  // add some strategies here
55  m_strategy.addStrategy( WMeshReaderVTK::SPtr( new WMeshReaderVTK() ) );
56  m_strategy.addStrategy( WMeshReaderFiberNavigator::SPtr( new WMeshReaderFiberNavigator() ) );
57  m_strategy.addStrategy( WMeshReaderDIP::SPtr( new WMeshReaderDIP() ) );
58  m_strategy.addStrategy( WMeshReaderBrainVISA::SPtr( new WMeshReaderBrainVISA() ) );
59  m_strategy.addStrategy( WMeshReaderFreesurfer::SPtr( new WMeshReaderFreesurfer() ) );
60  m_strategy.addStrategy( WMeshReaderOBJ::SPtr( new WMeshReaderOBJ() ) );
61 }
62 
63 WMReadMesh::~WMReadMesh()
64 {
65  // cleanup
67 }
68 
69 std::shared_ptr< WModule > WMReadMesh::factory() const
70 {
71  // See "src/modules/template/" for an extensively documented example.
72  return std::shared_ptr< WModule >( new WMReadMesh() );
73 }
74 
75 const char** WMReadMesh::getXPMIcon() const
76 {
77  return WMReadMesh_xpm;
78 }
79 
80 const std::string WMReadMesh::getName() const
81 {
82  return "Read Mesh";
83 }
84 
85 const std::string WMReadMesh::getDescription() const
86 {
87  // Specify your module description here. Be detailed. This text is read by the user.
88  // See "src/modules/template/" for an extensively documented example.
89  return "Loads a triangle mesh from several types of files.";
90 }
91 
93 {
94  m_output = std::shared_ptr< WModuleOutputData< WTriangleMesh > >(
95  new WModuleOutputData< WTriangleMesh >( shared_from_this(), "mesh", "The loaded mesh." ) );
96 
98 
99  // call WModules initialization
101 }
102 
104 {
105  m_propCondition = std::shared_ptr< WCondition >( new WCondition() );
106  m_meshFile = m_properties->addProperty( "Mesh file", "", WPathHelper::getAppPath() );
108 
109  // now, setup the strategy helper.
110  m_properties->addProperty( m_strategy.getProperties() );
111 
112  m_readTriggerProp = m_properties->addProperty( "Do read", "Press!", WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );
113 
114  m_nbTriangles = m_infoProperties->addProperty( "Triangles", "The number of triangles in the loaded mesh.", 0 );
115  m_nbTriangles->setMax( std::numeric_limits< int >::max() );
116 
117  m_nbVertices = m_infoProperties->addProperty( "Vertices", "The number of vertices in the loaded mesh.", 0 );
118  m_nbVertices->setMax( std::numeric_limits< int >::max() );
119 
121 }
122 
124 {
126 
127  ready();
128  while( !m_shutdownFlag() )
129  {
131  if( m_shutdownFlag() )
132  {
133  break;
134  }
135 
137 
138  // issue the current strategy
139  m_triMesh = m_strategy()->operator()( m_progress, m_meshFile->get() );
140 
141  // update the info
142  m_nbTriangles->set( m_triMesh->triangleSize() );
143  m_nbVertices->set( m_triMesh->vertSize() );
144 
145  // update the output
146  m_output->updateData( m_triMesh );
147 
148  // ready to be triggered again
150  }
151 }
152 
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.
Definition: WCondition.h:42
This module reads a file containing mesh data (several formats supported) and creates a mesh (or tria...
Definition: WMReadMesh.h:49
virtual void connectors()
Initialize the connectors this module is using.
Definition: WMReadMesh.cpp:92
WPropTrigger m_readTriggerProp
This property triggers the actual reading,.
Definition: WMReadMesh.h:108
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
Definition: WMReadMesh.cpp:75
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
Definition: WMReadMesh.h:106
virtual void properties()
Initialize the properties for this module.
Definition: WMReadMesh.cpp:103
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: WMReadMesh.cpp:69
WPropFilename m_meshFile
The mesh will be read from this file.
Definition: WMReadMesh.h:109
std::shared_ptr< WTriangleMesh > m_triMesh
This triangle mesh is provided as output through the connector.
Definition: WMReadMesh.h:104
virtual const std::string getDescription() const
Gives back a description of this module.
Definition: WMReadMesh.cpp:85
WStrategyHelper< WObjectNDIP< WMeshReaderInterface > > m_strategy
Handle each loader as strategy.
Definition: WMReadMesh.h:127
WPropInt m_nbVertices
Info-property showing the number of vertices in the mesh.
Definition: WMReadMesh.h:122
virtual void moduleMain()
Entry point after loading the module.
Definition: WMReadMesh.cpp:123
WPropInt m_nbTriangles
Info-property showing the number of triangles in the mesh.
Definition: WMReadMesh.h:121
virtual const std::string getName() const
Gives back the name of this module.
Definition: WMReadMesh.cpp:80
std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_output
Output connector provided by this module.
Definition: WMReadMesh.h:105
Load BrainVISA meshes.
Load DIP meshes.
Load FiberNavigator meshes.
Load Freesurfer meshes.
Load OBJ meshes.
Load VTK meshes.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
virtual void properties()
Initialize properties in this function.
Definition: WModule.cpp:212
void removeConnectors()
Removes all connectors properly.
Definition: WModule.cpp:194
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
Definition: WModule.cpp:108
std::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WModule.h:640
std::shared_ptr< WProperties > m_infoProperties
The property object for the module containing only module whose purpose is "PV_PURPOSE_INFORMNATION".
Definition: WModule.h:647
void ready()
Call this whenever your module is ready and can react on property changes.
Definition: WModule.cpp:505
WConditionSet m_moduleState
The internal state of the module.
Definition: WModule.h:703
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
Definition: WModule.h:652
virtual void connectors()
Initialize connectors in this function.
Definition: WModule.cpp:208
std::shared_ptr< WObjectNDIP > SPtr
Shared ptr to an instance.
Definition: WObjectNDIP.h:47
static boost::filesystem::path getAppPath()
The path where the binary file resides in.
Definition: WPathHelper.cpp:93
WProperties::SPtr getProperties() const
Get this strategy selectors properties.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
void addTo(WPropFilename prop)
Add the PC_PATHEXISTS constraint to the property.