35 #include "WMTriangleMeshRenderer.h"
36 #include "WMTriangleMeshRenderer.xpm"
37 #include "core/common/WLimits.h"
38 #include "core/common/math/WMath.h"
39 #include "core/graphicsEngine/WGEColormapping.h"
40 #include "core/graphicsEngine/WGEGeodeUtils.h"
41 #include "core/graphicsEngine/WGEUtils.h"
42 #include "core/graphicsEngine/WTriangleMesh.h"
43 #include "core/graphicsEngine/postprocessing/WGEPostprocessingNode.h"
44 #include "core/graphicsEngine/shaders/WGEPropertyUniform.h"
45 #include "core/graphicsEngine/shaders/WGEShader.h"
46 #include "core/graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h"
47 #include "core/kernel/WKernel.h"
71 return WMTriangleMeshRenderer_xpm;
77 return "Triangle Mesh Renderer";
82 return "Takes a triangle mesh as input and renders it as a shaded surface.";
86 double& minY,
double& maxY,
87 double& minZ,
double& maxZ,
const osg::Vec3d& vector )
const
89 minX = std::min( minX, vector.x() );
90 minY = std::min( minY, vector.y() );
91 minZ = std::min( minZ, vector.z() );
93 maxX = std::max( maxX, vector.x() );
94 maxY = std::max( maxY, vector.y() );
95 maxZ = std::max( maxZ, vector.z() );
100 if( ( y < x && z > x ) || ( z < x && y > x ) )
105 if( ( x < y && z > y ) || ( x < y && z > y ) )
110 if( ( y < z && x > z ) || ( x < z && y > z ) )
127 if( x == y && y == z && x == z )
137 return min + ( max - min ) / 2;
159 m_nbVertices->setMax( std::numeric_limits< int >::max() );
167 std::shared_ptr< WItemSelection > renderingModes( std::shared_ptr< WItemSelection >(
new WItemSelection() ) );
168 renderingModes->addItem(
"Smooth Shading",
"Smooth shading with Phong illumination model." );
169 renderingModes->addItem(
"Flat Shading",
"Each triangle has one constant color for shading." );
170 renderingModes->addItem(
"Outline",
"The surface is represented by lines only." );
171 m_renderingMode =
m_properties->addProperty(
"Rendering mode",
"Choose one of the available rendering modes.", renderingModes->getSelectorFirst(),
175 const bool hideProperty =
true;
188 std::shared_ptr< WItemSelection > colorModes( std::shared_ptr< WItemSelection >(
new WItemSelection() ) );
189 colorModes->addItem(
"Single Color",
"The whole surface is colored using the default color." );
190 colorModes->addItem(
"From Mesh",
"The surface is colored according to the mesh." );
191 colorModes->addItem(
"From colormap connector",
"The surface is colored using the colormap on colorMap connector." );
192 m_colorMode =
m_coloringGroup->addProperty(
"Color mode",
"Choose one of the available colorings.", colorModes->getSelectorFirst(),
269 bool operator()(
const std::shared_ptr< WTriangleMesh >& m,
const std::shared_ptr< WTriangleMesh >& n )
const
271 return m->vertSize() < n->vertSize();
296 osg::StateSet* moduleNodeState =
m_moduleNode->getOrCreateStateSet();
302 m_moduleNode->addUpdateCallback( transformationCallback );
340 std::shared_ptr< WTriangleMesh > mesh =
m_meshInput->getData();
343 debugLog() <<
"Invalid Data. Disabling.";
356 std::shared_ptr< WColoredVertices > colorMap =
m_colorMapInput->getData();
362 debugLog() <<
"Start rendering Mesh";
363 osg::ref_ptr< osg::Geometry > geometry;
364 osg::ref_ptr< osg::Geode > geode(
new osg::Geode );
365 geode->setName(
"Triangle Mesh Renderer Geode" );
373 std::vector< size_t >triangles = mesh->getTriangles();
374 std::vector< size_t >::const_iterator trianglesIterator;
383 for( trianglesIterator = triangles.begin();
384 trianglesIterator != triangles.end();
385 trianglesIterator++ )
387 osg::Vec3d vectorX = mesh->getVertex( *trianglesIterator );
388 updateMinMax( minX, maxX, minY, maxY, minZ, maxZ, vectorX );
396 std::shared_ptr< WProgress > progress(
new WProgress(
"Rendering", 3 ) );
402 debugLog() <<
"Start mesh decomposition";
404 mesh = *std::max_element( m_components->begin(), m_components->end(),
WMeshSizeComp() );
405 debugLog() <<
"Decomposing mesh done";
418 bool useColorFromMesh =
m_colorMode->get(
true ).getItemIndexOfSelected( 0 ) == 1;
442 warnLog() <<
"External colormap not connected. Using default color.";
451 geode->addDrawable( geometry );
463 debugLog() <<
"Rendering Mesh done";
496 osg::Matrixd matrixTranslateTo0 = osg::Matrixd::translate(
static_cast< osg::Vec3f
>(
m_meshCenter ) * -1.0 );
497 osg::Matrixd matrixTranslateFrom0 = osg::Matrixd::translate(
static_cast< osg::Vec3f
>(
m_meshCenter ) );
499 osg::Matrixd matrixRotateX = osg::Matrixd::rotate(
m_rotateX->get() * pi() / 180, osg::Vec3f( 1, 0, 0 ) );
500 osg::Matrixd matrixRotateY = osg::Matrixd::rotate(
m_rotateY->get() * pi() / 180, osg::Vec3f( 0, 1, 0 ) );
501 osg::Matrixd matrixRotateZ = osg::Matrixd::rotate(
m_rotateZ->get() * pi() / 180, osg::Vec3f( 0, 0, 1 ) );
502 osg::Matrixd matrixRotate = matrixRotateX * matrixRotateY * matrixRotateZ;
504 osg::Matrixd matrixComplete =
507 matrixTranslateFrom0 *
510 matrixTranslateFrom0 *
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.
static void apply(osg::ref_ptr< osg::Node > node, WMatrix4d preTransform=WMatrix4d::identity(), osg::ref_ptr< WGEShader > shader=osg::ref_ptr< WGEShader >(), size_t startTexUnit=0)
Apply the colormapping to the specified node.
This callback allows you a simple usage of callbacks in your module.
osg::ref_ptr< WGEFunctorCallback > SPtr
Shared pointer.
This class adds some convenience methods to WGEGroupNode.
This class enables you to add arbitrary nodes that get post-processed in screen space.
std::shared_ptr< WGEShaderPreprocessor > SPtr
Shared pointer for this class.
This is a WGEShaderDefineOptions class which additionally uses a property to automatically control th...
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
A class containing a list of named items.
This class represents a subset of a WItemSelection.
virtual size_t getItemIndexOfSelected(size_t index) const
Helps to get the index of an selected item in the WItemSelection.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
This module renders the triangle mesh given at its input connector as a surface.
WPropBool m_mainComponentOnly
En/Disable display of only the main component (biggest vertices number)
void renderMesh(std::shared_ptr< WTriangleMesh > mesh)
Render the mesh.
WPropInt m_nbTriangles
Info-property showing the number of triangles in the mesh.
osg::ref_ptr< osg::Uniform > m_colorMapTransformation
OSG Uniform for the transformation matrix which transforms the mesh.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropBool m_showOutline
Toggle showing outline instead fo surface.
virtual const std::string getDescription() const
Gives back a description of this module.
double getIntervallCenterMiddle(double min, double max) const
Calculates the center point of a given interval.
WPropBool m_showCoordinateSystem
Enables mesh's coordinate system.
WPropDouble m_scaleY
The mesh's scale value in Y direction.
WPropGroup m_groupTransformation
A group wich contains all transformation tools.
void setToDefault()
Set the transformation tool to default.
WPropGroup m_coloringGroup
Group for all color and colormapping options.
WPropDouble m_scaleZ
The mesh's scale value in Z direction.
virtual void connectors()
Initialize the connectors this module is using.
WPropDouble m_rotateY
The mesh's rotate value around Y.
void updateTransformation()
Updates the transformation matrix of the main node.
virtual const std::string getName() const
Gives back the name of this module.
WPropDouble m_translateY
The mesh's translate value along X.
WPropDouble m_opacity
The mesh's opacity value.
void updateMinMax(double &minX, double &maxX, double &minY, double &maxY, double &minZ, double &maxZ, const osg::Vec3d &vector) const
Calculates the bounding box of a vector and increases the specified one if needed.
WPropDouble m_translateX
The mesh's translate value along X.
WPropDouble m_scaleX
The mesh's scale value in X direction.
WPropDouble m_colormapRatio
Set Colormap Ratio.
WGEManagedGroupNode::SPtr m_moduleNode
The node containing all geometry nodes.
WPropBool m_colormap
Turn Colormapping on/off.
osg::ref_ptr< WGEShader > m_shader
The shader for the mesh.
std::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshInput
An input connector used to get meshes from other modules.
std::shared_ptr< WModuleInputData< WColoredVertices > > m_colorMapInput
A map for mapping each vertex to a color.
virtual ~WMTriangleMeshRenderer()
Destructor.
WPropDouble m_translateZ
The mesh's translate value along X.
WPropInt m_nbVertices
Info-property showing the number of vertices in the mesh.
WVector3d m_meshCenter
Center of the mesh.
WMTriangleMeshRenderer()
Constructor.
WPropColor m_color
The color of the mesh to be rendered.
virtual void properties()
Initialize the properties for this module.
double getMedian(double x, double y, double z) const
Gets the median of three values.
WPropSelection m_renderingMode
Which rendering mode should be used?
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...
WPropSelection m_colorMode
Which color mode should be used?
WPropBool m_scale
If true, the mesh scale properties are linked.
WPropTrigger m_setDefault
Set the transformation tool to default.
WPropDouble m_rotateX
The mesh's rotate value around X.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void moduleMain()
Entry point after loading the module.
WPropDouble m_rotateZ
The mesh's rotate value around Z.
Class representing a single module of OpenWalnut.
boost::filesystem::path m_localPath
The path where the module binary resides in.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
wlog::WStreamedLogger warnLog() const
Logger instance for comfortable warning- logs.
std::shared_ptr< WProperties > m_properties
The property object for the module.
std::shared_ptr< WProperties > m_infoProperties
The property object for the module containing only module whose purpose is "PV_PURPOSE_INFORMNATION".
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
WPropBool m_active
True whenever the module should be active.
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.
@ PV_TRIGGER_TRIGGERED
Trigger property: got triggered.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
std::shared_ptr< std::list< std::shared_ptr< WTriangleMesh > > > componentDecomposition(const WTriangleMesh &mesh)
Decompose the given mesh into connected components.
osg::ref_ptr< osg::Geometry > convertToOsgGeometryLines(WTriangleMesh::SPtr mesh, const WColor &defaultColor=WColor(1.0, 1.0, 1.0, 1.0), bool useMeshColor=true)
Convert triangle mesh to lines representing it.
osg::ref_ptr< osg::Geometry > convertToOsgGeometry(WTriangleMesh::SPtr mesh, const WColor &defaultColor=WColor(1.0, 1.0, 1.0, 1.0), bool includeNormals=false, bool lighting=false, bool useMeshColor=true)
Extract the vertices and triangles from a WTriangleMesh and save them into an osg::Geometry.
osg::ref_ptr< osg::Group > creatCoordinateSystem(osg::Vec3 middle, double sizeX, double sizeY, double sizeZ)
Create a coordinate system.
osg::ref_ptr< osg::Geometry > convertToOsgGeometryFlatShaded(WTriangleMesh::SPtr mesh, const WColor &defaultColor=WColor(1.0, 1.0, 1.0, 1.0), bool includeNormals=false, bool lighting=false, bool useMeshColor=true)
Extract the vertices and triangles from a WTriangleMesh and save them into an osg::Geometry in order ...
const double MAX_DOUBLE
Maximum double value.
const double MIN_DOUBLE
Positive minimum double value.
Compares two WTrianglesMeshes on their size of vertices.
bool operator()(const std::shared_ptr< WTriangleMesh > &m, const std::shared_ptr< WTriangleMesh > &n) const
Comparator on num vertex of two WTriangleMeshes.