34 #include <osg/LightModel>
36 #include "WMSurfaceIllustrator.h"
37 #include "WMSurfaceIllustrator.xpm"
38 #include "core/common/WLimits.h"
39 #include "core/common/math/WMath.h"
40 #include "core/graphicsEngine/WGEColormapping.h"
41 #include "core/graphicsEngine/WGEGeodeUtils.h"
42 #include "core/graphicsEngine/WGEUtils.h"
43 #include "core/graphicsEngine/WTriangleMesh.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"
70 return WMSurfaceIllustrator_xpm;
75 return "Surface Illustrator";
80 return "Takes a (parameterized) triangle mesh as input and renders it as a shaded surface with serverall illustration options.";
84 double& minY,
double& maxY,
85 double& minZ,
double& maxZ,
const osg::Vec3d& vector )
const
87 minX = std::min( minX, vector.x() );
88 minY = std::min( minY, vector.y() );
89 minZ = std::min( minZ, vector.z() );
91 maxX = std::max( maxX, vector.x() );
92 maxY = std::max( maxY, vector.y() );
93 maxZ = std::max( maxZ, vector.z() );
98 if( ( y < x && z > x ) || ( z < x && y > x ) )
103 if( ( x < y && z > y ) || ( x < y && z > y ) )
108 if( ( y < z && x > z ) || ( x < z && y > z ) )
125 if( x == y && y == z && x == z )
152 m_nbVertices->setMax( std::numeric_limits< int >::max() );
167 std::shared_ptr< WItemSelection > colorModes( std::shared_ptr< WItemSelection >(
new WItemSelection() ) );
168 colorModes->addItem(
"Single Color",
"The whole surface is colored using the default color." );
169 colorModes->addItem(
"From Mesh",
"The surface is colored according to the mesh." );
170 colorModes->addItem(
"From colormap connector",
"The surface is colored using the colormap on colorMap connector." );
171 m_colorMode =
m_coloringGroup->addProperty(
"Color mode",
"Choose one of the available colorings.", colorModes->getSelectorFirst(),
188 std::shared_ptr< WItemSelection > illustrationModes( std::shared_ptr< WItemSelection >(
new WItemSelection() ) );
189 illustrationModes->addItem(
"None",
"Standard rendering." );
190 illustrationModes->addItem(
"X-slab",
"Slab normal to x-axis." );
191 illustrationModes->addItem(
"Stream ribbon",
"A range of streamlines (if red color represents s-parameter of surface)." );
192 illustrationModes->addItem(
"Time ribbon",
"A range timelines (if green color represents t-parameter of surface)." );
193 illustrationModes->addItem(
"View-dependent opacity",
"Less opaque where surface normal parallel to view direction." );
194 illustrationModes->addItem(
"View-dependent opacity (inverted)",
"More opqaue where surface normal parallel to view direction." );
196 "Choose one of the types of illustrating the surface.",
197 illustrationModes->getSelectorFirst(),
224 osg::ref_ptr<osg::LightModel> lightModel(
new osg::LightModel() );
225 osg::ref_ptr<osg::StateSet> moduleNodeState =
m_moduleNode->getOrCreateStateSet();
226 lightModel->setTwoSided(
true );
227 moduleNodeState->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
257 std::shared_ptr< WTriangleMesh > mesh =
m_meshInput->getData();
260 debugLog() <<
"Invalid Data. Disabling.";
275 std::shared_ptr< WColoredVertices > colorMap =
m_colorMapInput->getData();
281 debugLog() <<
"Start rendering Mesh";
282 osg::ref_ptr< osg::Geometry > geometry;
283 osg::ref_ptr< osg::Geode > geode(
new osg::Geode );
289 geode->getOrCreateStateSet()->addUniform(
new osg::Uniform(
"u_renderingType", illustrationTypeId ) );
295 std::vector< size_t >triangles = mesh->getTriangles();
296 std::vector< size_t >::const_iterator trianglesIterator;
306 for( trianglesIterator = triangles.begin();
307 trianglesIterator != triangles.end();
308 trianglesIterator++ )
310 osg::Vec3d vectorX = mesh->getVertex( *trianglesIterator );
311 updateMinMax( minX, maxX, minY, maxY, minZ, maxZ, vectorX );
315 std::shared_ptr< WProgress > progress(
new WProgress(
"Rendering", 3 ) );
347 warnLog() <<
"External colormap not connected. Using default color.";
357 geode->addDrawable( geometry );
358 geode->setName(
"Surface Illustrator Geode" );
361 debugLog() <<
"Rendering Mesh done";
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 class adds some convenience methods to WGEGroupNode.
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_colormap
Turn Colormapping on/off.
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.
WPropInt m_nbTriangles
Info-property showing the number of triangles in the mesh.
WPropSelection m_colorMode
Which colormode should be used?
osg::ref_ptr< osg::Uniform > m_colorMapTransformation
OSG Uniform for the transformation matrix which transforms the mesh.
std::shared_ptr< WModuleInputData< WColoredVertices > > m_colorMapInput
A map for mapping each vertex to a color.
WGEManagedGroupNode::SPtr m_moduleNode
The node containing all geometry nodes.
WPropInt m_nbVertices
Info-property showing the number of vertices in the mesh.
virtual void properties()
Initialize the properties for this module.
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.
void renderMesh(std::shared_ptr< WTriangleMesh > mesh)
Render the mesh.
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.
WPropColor m_color
The color of the mesh to be rendered.
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 connectors()
Initialize the connectors this module is using.
WMSurfaceIllustrator()
Constructor.
WPropDouble m_parameterWidth
Set width of selected surface parameter interval.
WPropDouble m_parameterCenter
Set center of selected surface parameter.
virtual void moduleMain()
Entry point after loading the module.
WPropDouble m_opacity
The mesh's opacity value.
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.
double getMedian(double x, double y, double z) const
Gets the median of three values.
WPropSelection m_illustrationMode
Select the type of illustration applied in the shader.
virtual ~WMSurfaceIllustrator()
Destructor.
WPropGroup m_coloringGroup
Group for all color and colormapping options.
virtual const std::string getName() const
Gives back the name of this module.
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.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
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.
const double MAX_DOUBLE
Maximum double value.
const double MIN_DOUBLE
Positive minimum double value.