30 #include "WMMeshToPoints.h"
31 #include "core/common/WPropertyHelper.h"
32 #include "core/common/math/WMath.h"
33 #include "core/dataHandler/WDataHandler.h"
34 #include "core/kernel/WKernel.h"
61 return "Mesh To Points";
66 return "This module converts mesh data to points by using the mesh vertex points and colors.";
72 m_meshInput = std::shared_ptr< WModuleInputData < WTriangleMesh > >(
80 m_pointsOutput = std::shared_ptr< WModuleOutputData < WDataSetPoints > >(
97 "Minimal distance between two samples. If reached, iteration will stop.", 1.0,
106 size_t c,
const size_t& maxCount,
const double& minDistance )
111 points->push_back( v1.x() );
112 points->push_back( v1.y() );
113 points->push_back( v1.z() );
114 points->push_back( v2.x() );
115 points->push_back( v2.y() );
116 points->push_back( v2.z() );
117 points->push_back( v3.x() );
118 points->push_back( v3.y() );
119 points->push_back( v3.z() );
129 osg::Vec3 v12 = v1 + ( ( v2 - v1 ) * 0.5 );
130 osg::Vec3 v23 = v2 + ( ( v3 - v2 ) * 0.5 );
131 osg::Vec3 v31 = v3 + ( ( v1 - v3 ) * 0.5 );
133 bool l12 = ( ( v2 - v1 ).length() < minDistance );
134 bool l23 = ( ( v3 - v2 ).length() < minDistance );
135 bool l31 = ( ( v1 - v3 ).length() < minDistance );
136 if( l12 + l23 + l31 >= 2 )
141 points->push_back( v12.x() );
142 points->push_back( v12.y() );
143 points->push_back( v12.z() );
144 points->push_back( v23.x() );
145 points->push_back( v23.y() );
146 points->push_back( v23.z() );
147 points->push_back( v31.x() );
148 points->push_back( v31.y() );
149 points->push_back( v31.z() );
152 refine( v1, v12, v31, points, c + 1, maxCount, minDistance );
153 refine( v2, v23, v12, points, c + 1, maxCount, minDistance );
154 refine( v3, v31, v23, points, c + 1, maxCount, minDistance );
155 refine( v12, v23, v31, points, c + 1, maxCount, minDistance );
182 std::shared_ptr< WTriangleMesh > dataSet =
m_meshInput->getData();
183 bool dataValid = ( dataSet != NULL );
194 if( dataValid && !dataUpdated && !propsChanged )
203 osg::ref_ptr< osg::Vec3Array > verts = dataSet->getVertexArray();
204 osg::ref_ptr< osg::Vec4Array > colors = dataSet->getVertexColorArray();
205 std::vector< size_t > faces = dataSet->getTriangles();
207 debugLog() <<
"Creating point data. Num Points = " << verts->size() / 3 <<
".";
213 WAssert( verts->size() == colors->size(),
"Not enough colors for all vertices." );
214 for(
size_t i = 0; i < faces.size(); i += 3 )
216 osg::Vec3 v1 = verts->operator[]( faces[ i + 0 ] );
217 osg::Vec3 v2 = verts->operator[]( faces[ i + 1 ] );
218 osg::Vec3 v3 = verts->operator[]( faces[ i + 2 ] );
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.
Dataset to store a bunch of points without order or topology.
std::shared_ptr< WDataSetPoints > SPtr
Pointer to dataset.
std::shared_ptr< std::vector< float > > ColorArray
Colors for each vertex in VertexArray.
std::shared_ptr< std::vector< float > > VertexArray
List of vertex coordinates in term of components of vertices.
This modules takes a mesh and extracts its vertices to build a point dataset.
virtual const std::string getDescription() const
Gives back a description of this module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual const std::string getName() const
Gives back the name of this module.
virtual void connectors()
Initialize the connectors this module is using.
virtual ~WMMeshToPoints()
Destructor.
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.
std::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshInput
The fiber dataset which is going to be used.
WPropBool m_doRefinement
If true, refinement is applied.
WMMeshToPoints()
Default constructor.
virtual void properties()
Initialize the properties for this module.
WPropDouble m_minDistance
Maximum number of iterations for refinement.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropInt m_maxIterations
Maximum number of iterations for refinement.
std::shared_ptr< WModuleOutputData< WDataSetPoints > > m_pointsOutput
The output connector used to provide the calculated point data to other modules.
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.
std::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.