OpenWalnut  1.5.0dev
WCsvConverter.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 WCSVCONVERTER_H
26 #define WCSVCONVERTER_H
27 
28 #include <iostream>
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 #include <boost/lexical_cast.hpp>
34 
35 #include "WConverterIndexes.h"
36 #include "WConverterVectors.h"
37 #include "WPropertyStatus.h"
38 #include "WProtonData.h"
39 #include "WSingleSelectorName.h"
40 #include "core/common/WLogger.h"
41 #include "core/common/WTransferFunction.h"
42 #include "core/dataHandler/WDataSetFibers.h"
43 #include "core/dataHandler/WDataSetPoints.h"
44 #include "core/dataHandler/WGrid.h"
45 #include "core/dataHandler/WGridRegular3D.h"
46 #include "core/dataHandler/WValueSet.h"
47 #include "core/dataHandler/WValueSetBase.h"
48 
49 
50 /**
51  * Converts the csv data to points and fibers.
52  */
54 {
55  /**
56  * only test classes may be friend
57  */
58  friend class WCsvConverterTest;
59 public:
60  /**
61  * Initializes the vectors, indices and transfer function color bar
62  * Calls setOutputFromCSV.
63  * \param protonData The proton data to use.
64  * \param propertyStatus The status of the properties.
65  * \param colorBar Reference to the transfer function color bar module
66  */
67  WCsvConverter( WProtonData::SPtr protonData, std::shared_ptr< WPropertyStatus > propertyStatus, WModule::SPtr colorBar );
68 
69  /**
70  * represents a std::shared_ptr to a vector containing a vector of floats.
71  */
72  typedef std::shared_ptr< std::vector< float > > SPFloatVector;
73 
74  /**
75  * represents a std::shared_ptr to a vector containing a vector of size_t.
76  */
77  typedef std::shared_ptr< std::vector< size_t > > SPSizeVector;
78 
79  /**
80  * Getter
81  *
82  * \return shared_ptr of generated fibers from the CSV file
83  */
84  std::shared_ptr< WDataSetFibers > getFibers();
85 
86  /**
87  * Getter
88  *
89  * \return shared_ptr of generated Points from the CSV file
90  */
91  std::shared_ptr< WDataSetPoints > getPoints();
92 
93  /**
94  * Getter
95  * \return shared_ptr of generated transfer function
96  */
97  std::shared_ptr< WDataSetSingle > getTransferFunction();
98 
99  /**
100  * Getter
101  * \return shared_ptr of generated selected event ID
102  */
103  std::shared_ptr< WDataSetPoints > getPointsAndData();
104 
105 private:
106  /**
107  * Stores information form csv content. Content object containing data
108  */
110 
111  /**
112  * Stores reference to the given transfer function color bar module
113  */
115 
116  /**
117  * Stores information for the fiber display
118  */
119  std::shared_ptr< WDataSetFibers > m_fibers;
120 
121  /**
122  * Stores information for the point renderer
123  */
124  std::shared_ptr< WDataSetPoints > m_points;
125 
126  /**
127  * Stores information for the point Conncetor
128  */
129  std::shared_ptr< WDataSetPoints > m_pointsAndData;
130 
131  /**
132  * Stores the currently mapped transfer function
133  */
134  std::shared_ptr< WDataSetSingle > m_transferFunction;
135 
136  /**
137  * Stores points for point and fiber renderer
138  */
140 
141  /**
142  * Stores indexes for fiber renderer
143  */
145 
146  /**
147  * includes all property groups
148  */
150 
151  /**
152  * Computes gradient vector from transfer function specified in visualization properties.
153  * \return shared_ptr of mapped gradim_plainColorent from transfer function in RGBA format
154  */
155  std::shared_ptr< std::vector<unsigned char> > sampleTransferFunction();
156 
157  /**
158  * Normalize energy deposition values to use as RGB values
159  * \param edeps vector containing energy deposition values
160  * \param colorArray vector containing colors per vertex
161  * \param maxEdep maximum energy deposition
162  * \param minEdep minimum energy deposition
163  */
164  void normalizeEdeps( SPFloatVector edeps, SPFloatVector colorArray, float maxEdep, float minEdep );
165 
166 
167  /**
168  * checks whether the requirements are fulfilled.
169  * \param dataRow the row to check.
170  * \return true The row can be displayed.
171  * \return false The row can not be displayed.
172  */
173  bool checkConditionToPass( WDataSetCSV::Content::iterator dataRow );
174 
175  /**
176  * Create vertex for point/fiber renderer
177  *
178  * \param dataRow each row of the csv file (content of row)
179  */
180  void addVertex( WDataSetCSV::Content::iterator dataRow );
181 
182  /**
183  * Create color for point/Fiber renderer
184  *
185  * \param plainColor The color to create
186  */
187  void addColor( WColor plainColor );
188 
189  /**
190  * Create edep and sizes for point/fiber renderer
191  *
192  * \param dataRow each row of the csv file (content of row)
193  * \param maxEdep a pointer to the current maximum of the edep
194  * \param minEdep a pointer to the current minimum of the edep
195  */
196  void addEdepAndSize( WDataSetCSV::Content::iterator dataRow, float* maxEdep, float* minEdep );
197 
198  /**
199  * Create eventID for Fiber renderer
200  *
201  * \param dataRow each row of the csv file (content of row)
202  */
203  void addEventID( WDataSetCSV::Content::iterator dataRow );
204 
205  /**
206  * calculate the property of WDataSetFiber (index, length, verticesReverse)
207  */
208  void calculateFibers();
209 
210  /**
211  * Create the fibers for fiber renderer
212  */
213  void createOutputFibers();
214 
215  /**
216  * Create the points for points renderer
217  */
218  void createOutputPoints();
219 
220  /**
221  * Create the points and selected data for Point Connector
222  */
224 
225  /**
226  * Create outputs, so it can be displayed by the fiber display and the point renderer.
227  */
228  void setOutputFromCSV( );
229 
230  /**
231  * Creates output for transfer function
232  * \param data shared_ptr of mapped gradient from transfer function in RGBA format
233  */
234  void setTransferFunction( std::shared_ptr< std::vector<unsigned char> > data );
235 
236  /**
237  * the cast value from string to float
238  * \return returns the cast value from string to float
239  */
240  bool checkIfOutputIsNull();
241 
242  /**
243  * Computes the cluster size
244  * \param edep energy deposition
245  * \return float cluster size
246  */
247  float getClusterSize( float edep );
248 
249  /**
250  * checks whether the string is a number (double)
251  * \param str The string to cast
252  * \return return the casted double value
253  */
254  float stringToDouble( std::string str );
255 
256  /**
257  * checks whether the string is a number (int)
258  * \param str The string to cast
259  * \return return the casted int value
260  */
261  int stringToInt( std::string str );
262 };
263 
264 #endif // WCSVCONVERTER_H
std::shared_ptr< WConverterIndexes > SPtr
A shared_ptr to this class.
std::shared_ptr< WConverterVectors > SPtr
A shared_ptr to this class.
Test class of WCsvConverter class.
Converts the csv data to points and fibers.
Definition: WCsvConverter.h:54
WPropertyStatus::SPtr m_propertyStatus
includes all property groups
std::shared_ptr< WDataSetPoints > getPoints()
Getter.
WModule::SPtr m_colorBar
Stores reference to the given transfer function color bar module.
void addEdepAndSize(WDataSetCSV::Content::iterator dataRow, float *maxEdep, float *minEdep)
Create edep and sizes for point/fiber renderer.
void setTransferFunction(std::shared_ptr< std::vector< unsigned char > > data)
Creates output for transfer function.
void normalizeEdeps(SPFloatVector edeps, SPFloatVector colorArray, float maxEdep, float minEdep)
Normalize energy deposition values to use as RGB values.
std::shared_ptr< std::vector< float > > SPFloatVector
represents a std::shared_ptr to a vector containing a vector of floats.
Definition: WCsvConverter.h:72
void addVertex(WDataSetCSV::Content::iterator dataRow)
Create vertex for point/fiber renderer.
std::shared_ptr< std::vector< size_t > > SPSizeVector
represents a std::shared_ptr to a vector containing a vector of size_t.
Definition: WCsvConverter.h:77
void addEventID(WDataSetCSV::Content::iterator dataRow)
Create eventID for Fiber renderer.
std::shared_ptr< WDataSetSingle > m_transferFunction
Stores the currently mapped transfer function.
void createOutputPointsAndData()
Create the points and selected data for Point Connector.
std::shared_ptr< WDataSetFibers > m_fibers
Stores information for the fiber display.
WCsvConverter(WProtonData::SPtr protonData, std::shared_ptr< WPropertyStatus > propertyStatus, WModule::SPtr colorBar)
Initializes the vectors, indices and transfer function color bar Calls setOutputFromCSV.
std::shared_ptr< WDataSetPoints > m_points
Stores information for the point renderer.
WProtonData::SPtr m_protonData
Stores information form csv content.
float stringToDouble(std::string str)
checks whether the string is a number (double)
bool checkConditionToPass(WDataSetCSV::Content::iterator dataRow)
checks whether the requirements are fulfilled.
void calculateFibers()
calculate the property of WDataSetFiber (index, length, verticesReverse)
std::shared_ptr< WDataSetPoints > m_pointsAndData
Stores information for the point Conncetor.
int stringToInt(std::string str)
checks whether the string is a number (int)
void setOutputFromCSV()
Create outputs, so it can be displayed by the fiber display and the point renderer.
float getClusterSize(float edep)
Computes the cluster size.
void addColor(WColor plainColor)
Create color for point/Fiber renderer.
bool checkIfOutputIsNull()
the cast value from string to float
std::shared_ptr< WDataSetSingle > getTransferFunction()
Getter.
std::shared_ptr< WDataSetPoints > getPointsAndData()
Getter.
void createOutputPoints()
Create the points for points renderer.
WConverterVectors::SPtr m_vectors
Stores points for point and fiber renderer.
WConverterIndexes::SPtr m_indexes
Stores indexes for fiber renderer.
std::shared_ptr< std::vector< unsigned char > > sampleTransferFunction()
Computes gradient vector from transfer function specified in visualization properties.
void createOutputFibers()
Create the fibers for fiber renderer.
std::shared_ptr< WDataSetFibers > getFibers()
Getter.
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
Definition: WModule.h:106
std::shared_ptr< WPropertyStatus > SPtr
A shared_ptr to this class.
std::shared_ptr< WProtonData > SPtr
shared_ptr that points to itself
Definition: WProtonData.h:52