AGX Dynamics  2.37.2.0
SplineRenderer.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx 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 
27 #include <agx/agx_vector_types.h>
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 
33 namespace agxCollide
34 {
35  class Geometry;
36 }
37 
38 namespace 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 
74  void resetCounters();
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 
102  void setUseRedShiftScale(bool);
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 
195  agx::Vec4f getColor() const;
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;
213  SplineShaderRef m_splineGeometry;
214 
219  };
220 
222 }
223 
SplineShaderRef m_splineGeometry
agx::Real getRadius() const
const osg::Uniform * getCircleResolutionUniform() const
agxUtil::SplineRef m_spline
osg::Vec4Array * m_quatsInColorArray
osg::ref_ptr< osg::Uniform > m_cylinderColorUniform
osg::FloatArray * m_radiusArray
#define AGXOSG_EXPORT
Derive from this class to implement a listener for simulation step events.
agx::Real getNumSegmentsPerUnitLength() const
void setSplineModel(agxUtil::Spline *spline)
Assign spline model.
This namespace consists of a set of classes for handling geometric intersection tests including boole...
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
osg::ref_ptr< osg::Group > m_node
agxUtil::Spline * getSplineModel()
agx::Real TimeStamp
Definition: TimeStamp.h:26
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...
osg::FloatArray * getRadiusArray()
osg::Program * m_program
Class to encapsulate reading shader files and setting up rendering of a Spline.
agx::RealVector m_redShiftScales
Values from 0 to 1 how red the color of the node is (0 default color, 1 red color, redShiftScale.size == spline->getNumPoints())
osg::DrawArrays * m_primitiveSet
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
osg::ref_ptr< SplineShader > SplineShaderRef
osg::Uniform * getCircleResolutionUniform()
osg::Uniform * getCylinderColorUniform()
osg::FloatArray * m_xTexCoordArray
const osg::Program * getProgram() const
agx::ref_ptr< SplineRenderer > SplineRendererRef
const agx::RealVector & getRedShiftScales() const
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
osg::ref_ptr< osg::Uniform > m_circleResolutionUniform
Class for rendering a spline model.
agx::RealVector & getRedShiftScales()
osg::Vec3Array * m_vertexArray
void setNumActiveElements(size_t numActiveElements)
osg::Vec4Array * getQuatsInColorArray()
const agxUtil::Spline * getSplineModel() const
osg::Vec3Array * getVertexArray()
void setRadius(agx::Real radius)
Assign new radius of the cylinder segments.
const osg::Uniform * getCylinderColorUniform() const
agx::Real m_numSegmentsPerUnitLength
osg::Program * getProgram()
void setNumSegmentsPerUnitLength(agx::Real segmentsPerUnitLength)
Assign how many cylinder segments that should be used per unit length.
double Real
Definition: Real.h:42
AGXCORE_EXPORT Component * root()
osg::Uniform * getCircleNormalUniform()
const osg::Uniform * getCircleNormalUniform() const
Base class for splines.
Definition: Spline.h:31
osg::ref_ptr< osg::Uniform > m_circleNormalUniform
osg::ref_ptr< osg::Uniform > m_useRedShiftUniform
osg::FloatArray * m_redShiftArray