31 #include "WMFiberParameterColoring.h"
32 #include "WMFiberParameterColoring.xpm"
33 #include "core/common/WPropertyHelper.h"
34 #include "core/common/math/WMath.h"
35 #include "core/dataHandler/WDataHandler.h"
36 #include "core/kernel/WKernel.h"
58 return WMFiberParameterColoring_xpm;
63 return "Fiber Parameter Coloring";
68 return "This module can color fibers according to different parameters and schemes.";
74 m_fiberInput = std::shared_ptr< WModuleInputData < WDataSetFibers > >(
82 m_fiberOutput = std::shared_ptr< WModuleOutputData < WDataSetFibers > >(
84 "out",
"The fiber dataset colored by this module." )
98 m_baseColor =
m_properties->addProperty(
"Base Color",
"The base color. Some kind of color offset.", WColor( 1.0, 1.0, 1.0, 0.0 ),
100 m_scaleColor =
m_properties->addProperty(
"Scale Color",
"The color which gets scaled with the calculated value and added to the base color.",
107 inline double getSegmentVector(
size_t segment,
size_t offset, std::shared_ptr< std::vector< float > > verts,
double* vec )
110 double x = verts->at( ( 3 * segment ) + offset + 0 ) - verts->at( ( 3 * ( segment + 1 ) ) + offset + 0 );
111 double y = verts->at( ( 3 * segment ) + offset + 1 ) - verts->at( ( 3 * ( segment + 1 ) ) + offset + 1 );
112 double z = verts->at( ( 3 * segment ) + offset + 2 ) - verts->at( ( 3 * ( segment + 1 ) ) + offset + 2 );
115 double len = std::sqrt( x * x + y * y + z * z );
152 std::shared_ptr< WDataSetFibers > dataSet =
m_fiberInput->getData();
153 bool dataValid = ( dataSet != NULL );
164 if( dataValid && !( dataUpdated || propUpdated ) )
174 std::shared_ptr< std::vector< size_t > > fibStart = dataSet->getLineStartIndexes();
175 std::shared_ptr< std::vector< size_t > > fibLen = dataSet->getLineLengths();
176 std::shared_ptr< std::vector< float > > fibVerts = dataSet->getVertices();
184 std::shared_ptr< WProgress > progress1(
new WProgress(
"Coloring fibers.", fibStart->size() ) );
185 std::shared_ptr< WProgress > progress2(
new WProgress(
"Scaling Colors.", fibStart->size() ) );
191 double baseColorR = baseColor[0];
192 double baseColorG = baseColor[1];
193 double baseColorB = baseColor[2];
194 double baseColorA = baseColor[3];
196 double scaleColorR = scaleColor[0];
197 double scaleColorG = scaleColor[1];
198 double scaleColorB = scaleColor[2];
199 double scaleColorA = scaleColor[3];
202 debugLog() <<
"Iterating over all fibers.";
203 std::vector< double > maxSegLengths;
204 maxSegLengths.resize( fibStart->size(), 0.0 );
205 for(
size_t fidx = 0; fidx < fibStart->size() ; ++fidx )
210 size_t sidx = fibStart->at( fidx ) * 3;
211 size_t cidx = fibStart->at( fidx ) * colorMode;
214 size_t len = fibLen->at( fidx );
223 if( getSegmentVector( 0, sidx, fibVerts, &prev[0] ) == 0.0 )
229 double lenLast = 0.0;
231 for(
size_t k = 1; k < len - 1; ++k )
236 double segLen = getSegmentVector( k, sidx, fibVerts, ¤t[0] );
257 double x = ( 2.0 / ( lenLast + segLen ) ) * ( current[0] - prev[0] );
258 double y = ( 2.0 / ( lenLast + segLen ) ) * ( current[1] - prev[1] );
259 double z = ( 2.0 / ( lenLast + segLen ) ) * ( current[2] - prev[2] );
260 double curvature = std::sqrt( x*x + y*y + z*z );
262 ( *m_fibCurvatureColors )[ ( colorMode * k ) + cidx + 0 ] = baseColorR + ( 1.5 * scaleColorR * curvature );
263 ( *m_fibCurvatureColors )[ ( colorMode * k ) + cidx + 1 ] = baseColorG + ( 1.5 * scaleColorG * curvature );
264 ( *m_fibCurvatureColors )[ ( colorMode * k ) + cidx + 2 ] = baseColorB + ( 1.5 * scaleColorB * curvature );
265 ( *m_fibCurvatureColors )[ ( colorMode * k ) + cidx + 3 ] = baseColorA + ( 1.5 * scaleColorA * curvature );
267 ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 0 ] = segLen;
268 ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 1 ] = 0.0;
269 ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 2 ] = 0.0;
270 ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 3 ] = 1.0;
272 prev[0] = current[0];
273 prev[1] = current[1];
274 prev[2] = current[2];
276 lenMax = std::max( segLen, lenMax );
278 maxSegLengths[ fidx ] = lenMax;
283 debugLog() <<
"Iterating over all fibers for scaling per fiber.";
284 for(
size_t fidx = 0; fidx < fibStart->size() ; ++fidx )
289 size_t cidx = fibStart->at( fidx ) * colorMode;
290 size_t len = fibLen->at( fidx );
297 for(
size_t k = 1; k < len - 1; ++k )
299 double relSegLen = ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 0 ] / maxSegLengths[ fidx ];
300 ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 0 ] = baseColorR + ( scaleColorR * relSegLen );
301 ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 1 ] = baseColorG + ( scaleColorG * relSegLen );
302 ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 2 ] = baseColorB + ( scaleColorB * relSegLen );
303 ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 3 ] = baseColorA + ( scaleColorA * relSegLen );
310 "The speed of changing angles between consecutive segments represents the color." );
312 "The length of a segment in relation to the longest segment in the fiber." );
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.
Class to encapsulate boost::condition_variable_any.
ColorMode
different kinds of color arrays can be used in this class.
std::shared_ptr< std::vector< float > > ColorArray
Colors for each vertex in VertexArray.
This modules takes a dataset and equalizes its histogram.
virtual ~WMFiberParameterColoring()
Destructor.
std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_fiberOutput
The output connector used to provide the calculated data to other modules.
virtual const std::string getDescription() const
Gives back a description of this module.
WMFiberParameterColoring()
Default constructor.
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 void moduleMain()
Entry point after loading the module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
std::shared_ptr< WModuleInputData< WDataSetFibers > > m_fiberInput
The fiber dataset which is going to be filtered.
WPropColor m_scaleColor
The color gets scaled by the calculated color (i.e.
virtual void properties()
Initialize the properties for this module.
virtual void connectors()
Initialize the connectors this module is using.
WDataSetFibers::ColorArray m_fibLengthColors
The colors encoding the segment length.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropColor m_baseColor
The offset color.
WDataSetFibers::ColorArray m_fibCurvatureColors
The colors encoding the curvature.
virtual const std::string getName() const
Gives back the name of this module.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
virtual void connectors()
Initialize connectors in this function.
Class managing progress inside of modules.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.