33 #include <osg/Geometry>
34 #include <osg/LightModel>
35 #include <osg/Material>
36 #include <osg/PolygonMode>
37 #include <osg/StateAttribute>
38 #include <osg/StateSet>
39 #include <osgDB/WriteFile>
41 #include "WMSplineSurface.h"
42 #include "WMSplineSurface.xpm"
44 #include "core/common/WAssert.h"
45 #include "core/common/WLimits.h"
46 #include "core/common/WPathHelper.h"
47 #include "core/common/WProgress.h"
48 #include "core/common/math/WLinearAlgebraFunctions.h"
49 #include "core/common/math/linearAlgebra/WPosition.h"
50 #include "core/common/math/linearAlgebra/WVectorFixed.h"
51 #include "core/dataHandler/WDataHandler.h"
52 #include "core/dataHandler/WSubject.h"
53 #include "core/graphicsEngine/WGEColormapping.h"
54 #include "core/graphicsEngine/WGEUtils.h"
55 #include "core/graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h"
56 #include "core/kernel/WKernel.h"
82 return spline_surface_xpm;
87 return "Spline Surface";
92 return "<font color=\"#0000ff\"><b>[Unfinished Status]</b></font> This module implements the marching cubes"
93 " algorithm with a consistent triangulation. It allows one to compute isosurfaces"
94 " for a given isovalue on data given on a grid only consisting of cubes. It yields"
95 " the surface as triangle soup.";
111 debugLog() <<
"Computing surface ...";
116 std::vector< WVector3d > givenPoints;
117 for(
int y = 0; y < 11; ++y )
119 for(
int z = 0; z < 11; ++z )
121 float pi = 3.14159265;
123 float yy = pi2 * y / 10.;
124 float zz = pi2 * z / 10.;
127 p[0] = 60. + sin( yy ) * 10 + cos( zz ) * 10;
130 givenPoints.push_back( p );
139 debugLog() <<
"Rendering surface ...";
159 m_input = std::shared_ptr< InputType >(
new InputType( shared_from_this(),
"Tracts",
"A cluster of tracts." ) );
163 "The mesh representing the spline surface." ) );
194 osg::Geometry* surfaceGeometry =
new osg::Geometry();
199 surfaceGeometry->setVertexArray(
m_triMesh->getVertexArray() );
201 osg::DrawElementsUInt* surfaceElement;
203 surfaceElement =
new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
205 std::vector< size_t > tris =
m_triMesh->getTriangles();
206 surfaceElement->reserve( tris.size() );
208 for(
unsigned int vertId = 0; vertId < tris.size(); ++vertId )
210 surfaceElement->push_back( tris[vertId] );
212 surfaceGeometry->addPrimitiveSet( surfaceElement );
216 surfaceGeometry->setNormalArray(
m_triMesh->getVertexNormalArray() );
217 surfaceGeometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
224 osg::Vec4Array* colors =
new osg::Vec4Array;
226 surfaceGeometry->setColorArray( colors );
227 surfaceGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
229 osg::ref_ptr< osg::LightModel > lightModel =
new osg::LightModel();
230 lightModel->setTwoSided(
true );
231 state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
232 state->setMode( GL_BLEND, osg::StateAttribute::ON );
234 osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >(
new WGEShader(
"WMSplineSurface",
m_localPath ) );
337 osg::Vec4Array* colors =
new osg::Vec4Array;
339 m_surfaceGeode->getDrawable( 0 )->asGeometry()->setColorArray( colors );
340 m_surfaceGeode->getDrawable( 0 )->asGeometry()->setColorBinding( osg::Geometry::BIND_OVERALL );
Adapter object for realizing callbacks of the node representing the isosurface in the osg.
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.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
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.
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.
Module implementing the marching cubes algorithm with consistent triangulation for data given on regu...
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropBool m_useTextureProp
Property indicating whether to use texturing with scalar data sets.
osg::ref_ptr< osg::Geode > m_surfaceGeode
Pointer to geode containing the surface.
WPropColor m_surfaceColor
Property determining the color for the surface if no textures are displayed.
virtual const std::string getName() const
Gives back the name of this module.
void updateGraphics()
updates textures and shader parameters
virtual void moduleMain()
Entry point after loading the module.
bool save() const
Store the mesh in legacy vtk file format.
osg::ref_ptr< WGEGroupNode > m_moduleNode
Pointer to the modules group node. We need it to be able to update it when callback is invoked.
virtual void properties()
Initialize the properties for this module.
virtual const std::string getDescription() const
Gives back a description of this module.
~WMSplineSurface()
Destructor.
WMSplineSurface()
Standard constructor.
WPropInt m_opacityProp
Property holding the opacity valueassigned to the surface.
std::shared_ptr< WTriangleMesh > m_triMesh
This triangle mesh is provided as output through the connector.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_output
Input connector required by this module.
WPropGroup m_savePropGroup
Property group containing properties needed for saving the mesh.
void renderMesh()
Prepares and commits everything for rendering with the OSG.
WPropFilename m_meshFile
The mesh will be written to this file.
std::shared_ptr< WModuleInputData< const WFiberCluster > > m_input
Input connector for a fiber cluster.
WPropTrigger m_saveTriggerProp
This property triggers the actual writing,.
std::shared_ptr< WCondition > m_recompute
This condition denotes whether we need to recompute the surface.
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...
Class offering an instantiate-able data connection between modules.
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.
void removeConnectors()
Removes all connectors properly.
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.
WPropBool m_active
True whenever the module should be active.
virtual void connectors()
Initialize connectors in this function.
static boost::filesystem::path getAppPath()
The path where the binary file resides in.
Constructs a triangle mesh representation of a spline surface from a given number of input points.
void setSupportPoints(std::vector< WVector3d > supportPoints, bool forceUpdate=false)
sets the vector of support points the surface is calculated from
void execute()
Runs the algo and constructs a spine surface from the given input points.
std::shared_ptr< WTriangleMesh > getTriangleMesh()
getter
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)