OpenWalnut  1.5.0dev
WMFilterProtonData.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 <memory>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 #include "WMFilterProtonData.h"
31 
32 
33 W_LOADABLE_MODULE( WMFilterProtonData )
34 
37 {
38 }
39 
41 {
42 }
43 
44 const std::string WMFilterProtonData::getName() const
45 {
46  return "Filter Proton Data";
47 }
48 
49 const std::string WMFilterProtonData::getDescription() const
50 {
51  return "";
52 }
53 
54 std::shared_ptr< WModule > WMFilterProtonData::factory() const
55 {
56  return std::shared_ptr< WModule >( new WMFilterProtonData() );
57 }
58 
59 const char** WMFilterProtonData::getXPMIcon() const
60 {
61  return NULL;
62 }
63 
65 {
66  m_moduleState.setResetable( true, true );
67  m_moduleState.add( m_input->getDataChangedCondition() );
68 
69  ready();
70 
71  m_propertyStatus = std::shared_ptr< WPropertyStatus >( new WPropertyStatus() );
72 
73  while( !m_shutdownFlag() )
74  {
76 
77  if( m_input->updated() )
78  {
79  if( m_input->getData() == NULL )
80  {
81  continue;
82  }
83 
84  std::shared_ptr< WProgress > progressBar( new WProgress( "Preparing..." ) );
85  m_progress->addSubProgress( progressBar );
86 
87  if( m_protonData == NULL )
88  {
89  m_protonData = WProtonData::SPtr( new WProtonData( m_input->getData()->getHeader(), m_input->getData()->getData() ) );
90 
92  boost::bind( &WConditionSet::notify, &m_moduleState ) ) ) );
93 
95  boost::bind( &WConditionSet::notify, &m_moduleState ) ) ) );
96 
97  m_propertyStatus->setVisualizationPropertyHandler( WVisualizationPropertyHandler::SPtr(
99 
100  m_propertyStatus->setEventIDLimitationPropertyHandler( WEventIDLimitationPropertyHandler::SPtr(
102 
103  m_propertyStatus->getColumnPropertyHandler()->setSelectionEventMethod( boost::bind( &WMFilterProtonData::updateProperty, this ) );
104 
106  boost::bind( &WConditionSet::notify, &m_moduleState ) ) ) );
107  }
108  else
109  {
110  m_protonData->setCSVHeader( m_input->getData()->getHeader() );
111  m_protonData->setCSVData( m_input->getData()->getData() );
112  }
113  m_propertyStatus->getFilterPropertyHandler()->createPDGMap(
114  ( m_localPath / getMetaInformation()->query< std::string >( "common/pdgnames" , "NoFile" ) ).string() );
115 
116  clearProperties();
117  m_propertyStatus->getColumnPropertyHandler()->createProperties();
118  m_propertyStatus->getFilterPropertyHandler()->createProperties();
119  m_propertyStatus->getVisualizationPropertyHandler()->createProperties();
120  m_propertyStatus->getEventIDLimitationPropertyHandler()->createProperties();
121  m_propertyStatus->getOutputPropertyHandler()->createProperties();
122 
123  if( m_colorBar == NULL )
124  {
125  createColorBar();
126  }
128 
130 
131  progressBar->finish();
132  }
133  else
134  {
135  if( m_input->getData() == NULL )
136  {
137  continue;
138  }
139 
140  std::shared_ptr< WProgress > progressBar( new WProgress( "Updating output..." ) );
141  m_progress->addSubProgress( progressBar );
142 
144 
145  progressBar->finish();
146  }
147  }
148  stop();
149 }
150 
152 {
153  m_input = WModuleInputData< WDataSetCSV >::createAndAdd( shared_from_this(), "in", "CSV_input" );
154 
155  m_output_points = WModuleOutputData< WDataSetPoints >::createAndAdd( shared_from_this(), "output points", "Output CSV data as Point data" );
156  m_output_fibers = WModuleOutputData< WDataSetFibers >::createAndAdd( shared_from_this(), "output fibers", "Output CSV data as Fiber data" );
158  "output transferfunction", "Output transfer function" );
160  "output points and data", "Output CSV data as points and additional data for PointConnector" );
161 
163 }
164 
166 {
167  m_properties->removeProperty( m_properties->getProperty( "Select columns" ) );
168  m_properties->removeProperty( m_properties->getProperty( "Filtering" ) );
169  m_properties->removeProperty( m_properties->getProperty( "Visualization" ) );
170  m_properties->removeProperty( m_properties->getProperty( "Event Id Limitation" ) );
171  m_properties->removeProperty( m_properties->getProperty( "Output" ) );
172 }
173 
175 {
176  // Creating dummy properties for loading of projects
177  // TODO(eschbach) This is only a hotfix until property buffer is implemented
178  // When changing property names they also have to be changed here, so the loading works.
179  WPropertyGroup::SPtr groupColumn = m_properties->addPropertyGroup( "Select columns", "Select the columns which should be used", false );
180  WPropertyGroup::SPtr groupFilter = m_properties->addPropertyGroup( "Filtering", "Filter primaries, secondaries and particle types", false );
181  WPropertyGroup::SPtr groupVisual = m_properties->addPropertyGroup( "Visualization", "Visualization options", false );
182  WPropertyGroup::SPtr groupEventID = m_properties->addPropertyGroup( "Event Id Limitation", "Adjust the range of eventIDs to be shown.", false );
183  WPropertyGroup::SPtr groupRename = groupFilter->addPropertyGroup( "Rename Particle Types", "Filtering/Rename Particle Types", false );
184  WPropertyGroup::SPtr groupOutput = m_properties->addPropertyGroup( "Output", "Configures the third output", false );
185 
187  this, groupColumn, boost::placeholders::_1 );
189  this, groupFilter, boost::placeholders::_1 );
191  this, groupVisual, boost::placeholders::_1 );
193  this, groupEventID, boost::placeholders::_1 );
195  this, groupRename, boost::placeholders::_1 );
197  this, groupOutput, boost::placeholders::_1 );
198 
199  groupColumn->addProperty( "X", "Choose the column which should be used to determine the x coordinate.",
200  std::string( "" ), columnNotifier, false );
201  groupColumn->addProperty( "Y", "Choose the column which should be used to determine the y coordinate.",
202  std::string( "" ), columnNotifier, false );
203  groupColumn->addProperty( "Z", "Choose the column which should be used to determine the z coordinate.",
204  std::string( "" ), columnNotifier, false );
205  groupColumn->addProperty( "Particle Data Group", "Choose the column which should be used to determine the particle data group.",
206  std::string( "" ), columnNotifier, false );
207  groupColumn->addProperty( "Energy deposition", "Choose the column which should be used to determine the energy deposition.",
208  std::string( "" ), columnNotifier, false );
209  groupColumn->addProperty( "Event id",
210  "Choose the column which should be used to determine the event id. Tracks will be drawn based on the the event id, all "
211  "particles with the same event id will be connected.", std::string( "" ), columnNotifier, false );
212  groupColumn->addProperty( "Parent id", "Choose the column which should be used to determine the parent id."
213  "Primaries and secondaries filtering is based on that id,"
214  " if a particle has the parent id 0 it is a primary otherwise it is a secondary.",
215  std::string( "" ), columnNotifier, false );
216  groupFilter->addProperty( "Show primaries", "Show or hide primaries. One can either hide primaries or secondaries,"
217  "but not both at the same time.", std::string( "" ), filterNotifier, false );
218  groupFilter->addProperty( "Show secondaries", "Show or hide secondaries. One can either hide primaries or secondaries,"
219  "but not both at the same time.", std::string( "" ), filterNotifier, false );
220  groupFilter->addProperty( "Show particles", "Choose particle type(s) to be shown.", std::string( "" ), filterNotifier, false );
221 
222  groupRename->addProperty( "New name (press enter)", "Type in a new name for the selected particle type."
223  "To submit your entry press enter while you are in the textbox.", std::string( "" ), renameNotifier, false );
224  groupRename->addProperty( "Select particle", "Select the particle type to be renamed.", std::string( "" ), renameNotifier, false );
225  groupRename->addProperty( "Apply Changes", "Save", std::string( "" ), renameNotifier, false );
226 
227  groupVisual->addProperty( "Enable cluster size", "Enables the edep to clustersize conversion", std::string( "" ), visualNotifier, false );
228  groupVisual->addProperty( "Size by energy deposition", "Scale track and point sizes based on energy deposition.", std::string( "" ),
229  visualNotifier, false );
230  groupVisual->addProperty( "Color by energy deposition", "Colorize tracks and points based on energy deposition.", std::string( "" ),
231  visualNotifier, false );
232  groupVisual->addProperty( "Point color", "Points colorized in the chosen color when \"Color by energy deposition\" is disabled.",
233  std::string( "" ), visualNotifier, false );
234  groupVisual->addProperty( "Gradient color", "Colorize tracks and points based on energy deposition with the configured gradient.",
235  std::string( "" ), visualNotifier, false );
236  groupVisual->addProperty( "Set gradient", "Apply", std::string( "" ), visualNotifier, false );
237 
238  groupEventID->addProperty( "Minimum event id", "Filters out every event id which is lower than the set value.", std::string( "" ),
239  eventIDNotifier, false );
240  groupEventID->addProperty( "Maximum event id", "Filters out every event id which is higher than the set value.", std::string( "" ),
241  eventIDNotifier, false );
242  groupEventID->addProperty( "Set selection", "Apply", std::string( "" ), eventIDNotifier, false );
243 
244  groupOutput->addProperty( "Energy deposition", "Enables the energy deposition output", std::string( "" ), outputNotifier, false );
245  groupOutput->addProperty( "Event id", "Enables the event id output", std::string( "" ), outputNotifier, false );
246 
248 }
249 
251 {
252  std::string name = group->getDescription() + "/" + property->getName();
253  std::string value = property->getAsString();
254  m_loadedProperties.push_back( std::pair< std::string, std::string >( name, value ) );
255 }
256 
258 {
259  for( auto iter = m_loadedProperties.begin(); iter != m_loadedProperties.end(); iter++ )
260  {
261  WPropertyBase::SPtr prop = m_properties->findProperty( ( *iter ).first );
262  if( prop )
263  {
264  prop->setAsString( ( *iter ).second );
265  }
266  }
267 }
268 
270 {
271  m_converter = std::shared_ptr< WCsvConverter >( new WCsvConverter( m_protonData, m_propertyStatus, m_colorBar ) );
272 
273  m_output_points->updateData( m_converter->getPoints() );
274  m_output_fibers->updateData( m_converter->getFibers() );
275  m_output_points_eventIds->updateData( m_converter->getPointsAndData() );
276  m_output_transferFunction->updateData( m_converter->getTransferFunction() );
277 }
278 
280 {
281  m_propertyStatus->getColumnPropertyHandler()->updateProperty();
282  m_propertyStatus->getFilterPropertyHandler()->updateProperty();
283  m_propertyStatus->getVisualizationPropertyHandler()->updateProperty();
284  m_propertyStatus->getEventIDLimitationPropertyHandler()->updateProperty();
285 }
286 
288 {
289  m_colorBar = createAndAdd( "Transfer Function Color Bar" );
290  m_colorBar->isReady().wait();
291  m_output_transferFunction->connect( m_colorBar->getInputConnector( "transfer function" ) );
292 }
293 
295 {
296  m_colorBar->getProperties()->getProperty( "active" )->toPropBool()->set( m_active->get() );
297 }
Creates, updates and handles the column properties.
std::shared_ptr< WColumnPropertyHandler > SPtr
shared_ptr that points to itself
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.
virtual void notify()
Notifies all waiting threads.
Converts the csv data to points and fibers.
Definition: WCsvConverter.h:54
Creates, updates and handles the EventID properties.
std::shared_ptr< WEventIDLimitationPropertyHandler > SPtr
shared_ptr that points to itself
Creates, updates and handles the filter properties.
std::shared_ptr< WFilterPropertyHandler > SPtr
Function variables for updating the data.
This module simply registers a given csv dataset to the csv handling mechanism.
void setToLoadedProperties()
Sets the current properties to the state of the loaded properties.
std::shared_ptr< WModuleOutputData< WDataSetSingle > > m_output_transferFunction
WDataSetSingle output connector to output current transfer function.
virtual ~WMFilterProtonData()
Standard destructor.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
std::shared_ptr< WCsvConverter > m_converter
Contains the algorithm that converts the raw CSV file into compatible WDataSets (Points,...
std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_output_fibers
WDataSetFibers output connector (required for this module).
virtual const std::string getName() const
Returns the name of this module.
void createColorBar()
Creates the transfer function color bar module within this module container.
WModule::SPtr m_colorBar
Reference to the transfer function color bar module within this module container.
WProtonData::SPtr m_protonData
Pointer that points to the Proton data from the CSV file
std::shared_ptr< WPropertyStatus > m_propertyStatus
Contains all property-groups and the subproperties.
virtual void activate()
Toggles activation for inner module based on activation of this module.
virtual const std::string getDescription() const
Retruns the description of this module.
std::shared_ptr< WModuleOutputData< WDataSetPoints > > m_output_points_eventIds
WDataSetPointsAndEventIDs output connector to output points and eventIDs for PointConn.
virtual void connectors()
Initialize the connectors this module is using.
void clearProperties()
Removes the property groups.
void loadNotifier(WPropertyGroup::SPtr group, WPropertyBase::SPtr property)
Notifier for the dummy properties.
virtual void properties()
Initialize the properties for this module.
std::vector< std::pair< std::string, std::string > > m_loadedProperties
Contains the loaded properties.
WMFilterProtonData()
Standard constructor.
void updateProperty()
update added group property and subproperty
virtual void moduleMain()
Entry point after loading the module.
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< WModuleInputData< WDataSetCSV > > m_input
Input connector (required for this module).
std::shared_ptr< WModuleOutputData< WDataSetPoints > > m_output_points
WDataSetPoints output connector (required for this module).
void setOutputFromCSV()
Create outputs, so it can be displayed by the fiber display and the point renderer.
Class able to contain other modules.
virtual WModule::SPtr createAndAdd(std::string name)
Convenience method to create a module instance with a given name and automatically add it to the cont...
virtual void stop()
Stops all modules inside this container.
static PtrType createAndAdd(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Convenience method to create a new instance of this in data connector with proper type and add it to ...
static PtrType createAndAdd(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Convenience method to create a new instance of this out data connector with proper type and add it to...
static PtrType create(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Convenience method to create a new instance of this out data connector with proper type.
boost::filesystem::path m_localPath
The path where the module binary resides in.
Definition: WModule.h:734
virtual void properties()
Initialize properties in this function.
Definition: WModule.cpp:212
virtual WModuleMetaInformation::ConstSPtr getMetaInformation() const
The meta information of this module.
Definition: WModule.cpp:229
std::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WModule.h:640
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
WPropBool m_active
True whenever the module should be active.
Definition: WModule.h:723
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
Creates, updates and handles the output properties.
std::shared_ptr< WOutputPropertyHandler > SPtr
shared_ptr that points to itself.
Class managing progress inside of modules.
Definition: WProgress.h:42
boost::function< void(std::shared_ptr< WPropertyBase >)> PropertyChangeNotifierType
Signal signature emitted during set operations.
std::shared_ptr< WPropertyBase > SPtr
Convenience typedef for a std::shared_ptr< WPropertyBase >
Definition: WPropertyBase.h:53
std::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type
Holds references to all the property handlers.
Holds the csv data.
Definition: WProtonData.h:43
std::shared_ptr< WProtonData > SPtr
shared_ptr that points to itself
Definition: WProtonData.h:52
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Creates, updates and handles the visualization properties.
std::shared_ptr< WVisualizationPropertyHandler > SPtr
shared_ptr that points to itself