AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
SplineRenderer.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19
20#include <agxOSG/export.h>
21#include <agxOSG/Node.h>
22
23#include <agxUtil/Spline.h>
24
26
28
29#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
30#include <osg/Geometry>
31#include <agx/PopDisableWarnings.h> // End of disabled warnings.
32
33namespace agxCollide
34{
35 class Geometry;
36}
37
38namespace agxOSG
39{
43 class AGXOSG_EXPORT SplineShader : public osg::Geometry
44 {
45 public:
46 SplineShader(size_t initialBufferSize = 256);
47
51 void add(const agx::Vec3& startPoint, const agx::Vec3& endPoint, agx::Real radius, agx::Vec2 redShift = agx::Vec2(0, 0));
52
56 void add(const agx::Vec3& point, const agx::Quat& zToDir, agx::Real radius, agx::Real redShift = agx::Real(0));
57
58 void add2(const agx::Vec3& point, const agx::Quat& quat, agx::Real radius, agx::Real xTexCoord, agx::Real redShift);
59
64 void add(const agxCollide::Geometry* geometry);
65
69 void update();
70
75
79 osg::Program* getProgram() { return m_program; }
80 const osg::Program* getProgram() const { return m_program; }
81
85 osg::Uniform* getCircleResolutionUniform() { return m_circleResolutionUniform; }
86 const osg::Uniform* getCircleResolutionUniform() const { return m_circleResolutionUniform; }
87
91 osg::Uniform* getCylinderColorUniform() { return m_cylinderColorUniform; }
92 const osg::Uniform* getCylinderColorUniform() const { return m_cylinderColorUniform; }
93
94 osg::Uniform* getCircleNormalUniform() { return m_circleNormalUniform; }
95 const osg::Uniform* getCircleNormalUniform() const { return m_circleNormalUniform; }
96
97 osg::Vec3Array* getVertexArray() { return m_vertexArray; }
98 osg::Vec4Array* getQuatsInColorArray() { return m_quatsInColorArray; }
99 osg::FloatArray* getRadiusArray() { return m_radiusArray; }
100 void setNumActiveElements(size_t numActiveElements) { m_numActiveElements = numActiveElements; }
101
103
104 protected:
105 virtual ~SplineShader();
106
107 protected:
109
110 osg::DrawArrays* m_primitiveSet;
111 osg::Vec3Array* m_vertexArray;
112 osg::FloatArray* m_xTexCoordArray;
113 osg::Vec4Array* m_quatsInColorArray;
114 osg::FloatArray* m_radiusArray;
115 osg::FloatArray* m_redShiftArray;
116 osg::Program* m_program;
117 osg::ref_ptr<osg::Uniform> m_circleNormalUniform;
118 osg::ref_ptr<osg::Uniform> m_circleResolutionUniform;
119 osg::ref_ptr<osg::Uniform> m_cylinderColorUniform;
120 osg::ref_ptr<osg::Uniform> m_useRedShiftUniform;
121 };
122
123 typedef osg::ref_ptr< SplineShader > SplineShaderRef;
124
129 {
130 public:
138 SplineRenderer( agxUtil::Spline* spline, osg::Group* root );
139
143 virtual void update();
144
150 virtual void update( const agx::RealVector& radiiVector );
151
156 void setSplineModel( agxUtil::Spline* spline ) { m_spline = spline; }
157
161 agxUtil::Spline* getSplineModel() { return m_spline; }
162 const agxUtil::Spline* getSplineModel() const { return m_spline; }
163
168 void setRadius( agx::Real radius ) { m_radius = radius; }
169
173 agx::Real getRadius() const { return m_radius; }
174
179 void setNumSegmentsPerUnitLength( agx::Real segmentsPerUnitLength ) { m_numSegmentsPerUnitLength = segmentsPerUnitLength; }
180
184 agx::Real getNumSegmentsPerUnitLength() const { return m_numSegmentsPerUnitLength; }
185
190 void setColor( const agx::Vec4f& color );
191
196
197 virtual void removeNotification();
198
199 protected:
200 virtual ~SplineRenderer() {}
201
202 virtual void addNotification();
203
204 void initialize(osg::Group* root);
205 virtual void last(const agx::TimeStamp&) { update(); }
206
207 agx::RealVector& getRedShiftScales() { return m_redShiftScales; }
208 const agx::RealVector& getRedShiftScales() const { return m_redShiftScales; }
209
210 protected:
211 osg::ref_ptr< osg::Group > m_node;
214
219 };
220
222}
223
#define AGXOSG_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Class for rendering a spline model.
agx::Vec4f getColor() const
agx::Real m_numSegmentsPerUnitLength
void initialize(osg::Group *root)
virtual void update(const agx::RealVector &radiiVector)
Use this update if this spline has variable radii.
agx::Real getNumSegmentsPerUnitLength() const
const agxUtil::Spline * getSplineModel() const
agx::Real getRadius() const
agxUtil::Spline * getSplineModel()
osg::ref_ptr< osg::Group > m_node
void setSplineModel(agxUtil::Spline *spline)
Assign spline model.
virtual void last(const agx::TimeStamp &)
Called after a step is taken in the simulation Implement this method in the derived class to get call...
agx::RealVector m_redShiftScales
Values from 0 to 1 how red the color of the node is (0 default color, 1 red color,...
void setColor(const agx::Vec4f &color)
Assign color to this spline.
virtual void update()
Given the current spline control points, data will be pushed for new update.
SplineRenderer(agxUtil::Spline *spline, osg::Group *root)
Construct spline (geometry shader) renderer.
virtual void removeNotification()
Called when this listener is removed from the simulation.
agx::RealVector & getRedShiftScales()
agxUtil::SplineRef m_spline
void setNumSegmentsPerUnitLength(agx::Real segmentsPerUnitLength)
Assign how many cylinder segments that should be used per unit length.
virtual void addNotification()
Called when this listener is added to the simulation.
void setRadius(agx::Real radius)
Assign new radius of the cylinder segments.
const agx::RealVector & getRedShiftScales() const
SplineShaderRef m_splineGeometry
Class to encapsulate reading shader files and setting up rendering of a Spline.
osg::Uniform * getCircleResolutionUniform()
void add(const agx::Vec3 &point, const agx::Quat &zToDir, agx::Real radius, agx::Real redShift=agx::Real(0))
Continuous mesh, for splines.
osg::ref_ptr< osg::Uniform > m_circleNormalUniform
osg::ref_ptr< osg::Uniform > m_circleResolutionUniform
osg::FloatArray * m_radiusArray
osg::Vec4Array * m_quatsInColorArray
osg::Program * m_program
void add(const agxCollide::Geometry *geometry)
All compatible shapes in geometry will be rendered.
void setUseRedShiftScale(bool)
osg::Vec4Array * getQuatsInColorArray()
osg::FloatArray * m_xTexCoordArray
osg::Uniform * getCircleNormalUniform()
void update()
Push the data to the graphics card.
const osg::Uniform * getCircleResolutionUniform() const
osg::Vec3Array * getVertexArray()
osg::FloatArray * getRadiusArray()
void resetCounters()
Resets all internal counters.
const osg::Uniform * getCircleNormalUniform() const
void add(const agx::Vec3 &startPoint, const agx::Vec3 &endPoint, agx::Real radius, agx::Vec2 redShift=agx::Vec2(0, 0))
Add cylinder given world start- and end point, and radius.
void setNumActiveElements(size_t numActiveElements)
osg::ref_ptr< osg::Uniform > m_cylinderColorUniform
SplineShader(size_t initialBufferSize=256)
osg::Uniform * getCylinderColorUniform()
osg::Program * getProgram()
osg::DrawArrays * m_primitiveSet
const osg::Uniform * getCylinderColorUniform() const
const osg::Program * getProgram() const
osg::ref_ptr< osg::Uniform > m_useRedShiftUniform
osg::FloatArray * m_redShiftArray
void add2(const agx::Vec3 &point, const agx::Quat &quat, agx::Real radius, agx::Real xTexCoord, agx::Real redShift)
osg::Vec3Array * m_vertexArray
Derive from this class to implement a listener for simulation step events.
Base class for splines.
Definition: Spline.h:32
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
osg::ref_ptr< SplineShader > SplineShaderRef
agx::ref_ptr< SplineRenderer > SplineRendererRef
double Real
Definition: Real.h:41
agx::Real TimeStamp
Definition: TimeStamp.h:26