VTK  9.2.6
vtkOpenGLPolyDataMapper.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4
5 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6 All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13=========================================================================*/
27#ifndef vtkOpenGLPolyDataMapper_h
28#define vtkOpenGLPolyDataMapper_h
29
30#include "vtkInformation.h" // for prim struct
31#include "vtkNew.h" // For vtkNew
32#include "vtkOpenGLHelper.h" // used for ivars
33#include "vtkPolyDataMapper.h"
34#include "vtkRenderingOpenGL2Module.h" // For export macro
35#include "vtkShader.h" // for methods
36#include "vtkStateStorage.h" // used for ivars
37
38#include <map> // for map
39#include <tuple> // for tuple
40#include <vector> // for vector
41
42class vtkCellArray;
44class vtkMatrix4x4;
45class vtkMatrix3x3;
52class vtkPoints;
53class vtkTexture;
55class vtkTransform;
57
58class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
59{
60public:
63 void PrintSelf(ostream& os, vtkIndent indent) override;
64
68 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
69
71
74 virtual void RenderPieceStart(vtkRenderer* ren, vtkActor* act);
75 virtual void RenderPieceDraw(vtkRenderer* ren, vtkActor* act);
76 virtual void RenderPieceFinish(vtkRenderer* ren, vtkActor* act);
78
85
86 vtkGetMacro(PopulateSelectionSettings, int);
87 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }
88
95 bool GetSupportsSelection() override { return true; }
96
97 // used by RenderPiece and functions it calls to reduce
98 // calls to get the input and allow for rendering of
99 // other polydata (not the input)
101
103
109 vtkSetStringMacro(PointIdArrayName);
110 vtkGetStringMacro(PointIdArrayName);
111 vtkSetStringMacro(CellIdArrayName);
112 vtkGetStringMacro(CellIdArrayName);
114
116
121 vtkSetStringMacro(ProcessIdArrayName);
122 vtkGetStringMacro(ProcessIdArrayName);
124
126
135 vtkSetStringMacro(CompositeIdArrayName);
136 vtkGetStringMacro(CompositeIdArrayName);
138
143
145 vtkGetObjectMacro(VBOs, vtkOpenGLVertexBufferObjectGroup);
146
150 virtual void SetVBOShiftScaleMethod(int m);
151 virtual int GetVBOShiftScaleMethod() { return this->ShiftScaleMethod; }
152
167 virtual void SetPauseShiftScale(bool pauseShiftScale) { this->PauseShiftScale = pauseShiftScale; }
168 vtkGetMacro(PauseShiftScale, bool);
169 vtkBooleanMacro(PauseShiftScale, bool);
170
172 {
173 PrimitiveStart = 0,
174 PrimitivePoints = 0,
179 PrimitiveEnd
180 };
181
193 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
194 int fieldAssociation, int componentno = -1) override;
195
196 // This method will Map the specified data array for use as
197 // a texture coordinate for texture tname. The actual
198 // attribute will be named tname_coord so as to not
199 // conflict with the texture sampler definition which will
200 // be tname.
201 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
202 int fieldAssociation, int componentno = -1) override;
203
207 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
208
213
219 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
220
221protected:
224
226
227 void MapDataArray(const char* vertexAttributeName, const char* dataArrayName,
228 const char* texturename, int fieldAssociation, int componentno);
229
230 // what coordinate should be used for this texture
231 std::string GetTextureCoordinateName(const char* tname);
232
233 // handle updating shift scale based on pose changes
234 virtual void UpdateCameraShiftScale(vtkRenderer* ren, vtkActor* actor);
235
239 void GetCoincidentParameters(vtkRenderer* ren, vtkActor* actor, float& factor, float& offset);
240
246 void ComputeBounds() override;
247
252 virtual void UpdateShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
253
258
262 virtual void BuildShaders(
263 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
264
268 virtual void GetShaderTemplate(
269 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
270
275 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
276
278
283 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
285 std::map<vtkShader::Type, vtkShader*> shaders, vtkActor* act);
286 virtual void ReplaceShaderColor(
287 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
288 virtual void ReplaceShaderEdges(
289 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
290 virtual void ReplaceShaderLight(
291 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
293 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
295 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
297 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
299 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
300 virtual void ReplaceShaderClip(
301 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
303 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
305 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
306 virtual void ReplaceShaderDepth(
307 std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
309
313 virtual void SetCustomUniforms(vtkOpenGLHelper& cellBO, vtkActor* actor);
314
319
324 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
325
330
335 vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
336
340 virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
341
346
350 virtual void BuildBufferObjects(vtkRenderer* ren, vtkActor* act);
351
355 virtual void BuildIBO(vtkRenderer* ren, vtkActor* act, vtkPolyData* poly);
356
360 virtual void BuildSelectionIBO(
361 vtkPolyData* poly, std::vector<unsigned int> (&indices)[4], vtkIdType offset);
362
366 virtual void BuildSelectionCache(const char* arrayName, bool selectingPoints, vtkPolyData* poly);
367
368 // The VBO and its layout.
370
371 // Structures for the various cell types we render.
372 vtkOpenGLHelper Primitives[PrimitiveEnd];
373 vtkOpenGLHelper SelectionPrimitives[PrimitiveEnd];
376 bool DrawingSelection = false;
378 vtkMTimeType SelectionTime = 0;
379
380 std::map<std::tuple<unsigned int, unsigned int, vtkIdType>, std::vector<vtkIdType>>
383 bool SelectionCacheForPoints = false;
384 vtkMTimeType SelectionCacheTime = 0;
385 vtkPolyData* SelectionPolyData = nullptr;
386
387 // do we have wide lines that require special handling
389
390 // do we have textures that require special handling
391 virtual bool HaveTextures(vtkActor* actor);
392
393 // how many textures do we have
394 virtual unsigned int GetNumberOfTextures(vtkActor* actor);
395
396 // populate a vector with the textures we have
397 // the order is always
398 // ColorInternalTexture
399 // Actors texture
400 // Properties textures
401 virtual std::vector<std::pair<vtkTexture*, std::string>> GetTextures(vtkActor* actor);
402
403 // do we have textures coordinates that require special handling
404 virtual bool HaveTCoords(vtkPolyData* poly);
405
406 // values we use to determine if we need to rebuild shaders
407 // stored in a map keyed on the vtkOpenGLHelper, so one
408 // typically entry per type of primitive we render which
409 // matches the shader programs we use
411 {
412 public:
416
417 // Caches the vtkOpenGLRenderPass::RenderPasses() information.
418 // Note: Do not dereference the pointers held by this object. There is no
419 // guarantee that they are still valid!
421 };
422 std::map<const vtkOpenGLHelper*, primitiveInfo> PrimitiveInfo;
423
427
428 // Check the renderpasses in actor's property keys to see if they've changed
429 // render stages:
431
433 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated?
434 vtkStateStorage VBOBuildState; // used for determining when to rebuild the VBO
435 vtkStateStorage IBOBuildState; // used for determining whento rebuild the IBOs
437 vtkStateStorage TempState; // can be used to avoid constant allocs/deallocs
439
442
447 int ShiftScaleMethod; // for points
449
450 // if set to true, tcoords will be passed to the
451 // VBO even if the mapper knows of no texture maps
452 // normally tcoords are only added to the VBO if the
453 // mapper has identified a texture map as well.
455
456 virtual void BuildCellTextures(
457 vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation);
458
459 void AppendCellTextures(vtkRenderer* ren, vtkActor*, vtkCellArray* prims[4], int representation,
460 std::vector<unsigned char>& colors, std::vector<float>& normals, vtkPolyData* pd,
462
469
472 std::vector<unsigned char> EdgeValues;
474
475 // additional picking indirection
480
482 {
483 public:
484 std::string DataArrayName;
487 std::string TextureName;
488 };
489 std::map<std::string, ExtraAttributeValue> ExtraAttributes;
490
492
493 // are we currently drawing spheres/tubes
495 bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
497
498 // get which opengl mode to use to draw the primitive
499 int GetOpenGLMode(int representation, int primType);
500
501 // get how big to make the points when doing point picking
502 // typically 2 for points, 4 for lines, 6 for surface
504
505 // used to occasionally invoke timers
506 unsigned int TimerQueryCounter;
507
508 // stores the mapping from vtk cells to gl_PrimitiveId
510
511 // compute and set the maximum point and cell ID used in selection
513
514 virtual void AddPointIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
515 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
516 virtual void AddCellIdsToSelectionPrimitives(vtkPolyData* poly, const char* arrayName,
517 unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId);
518
519 vtkNew<vtkCellArray> SelectionArrays[4];
520
521private:
523 void operator=(const vtkOpenGLPolyDataMapper&) = delete;
524};
525
526#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:52
object to represent cell connectivity
a simple class to control print indentation
Definition vtkIndent.h:40
represent and manipulate 3x3 transformation matrices
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:62
OpenGL buffer object.
OpenGL rendering utility functions.
PolyDataMapper using OpenGL to render.
virtual void BuildSelectionCache(const char *arrayName, bool selectingPoints, vtkPolyData *poly)
Build the selection cache, used to map value ids to indices values.
void MapDataArrayToMultiTextureAttribute(const char *tname, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
virtual void ReplaceShaderRenderPass(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act, bool prePass)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void SetLightingShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to lighting, called by UpdateShader.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
virtual void ReplaceShaderPrimID(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void AddCellIdsToSelectionPrimitives(vtkPolyData *poly, const char *arrayName, unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId)
virtual void GetShaderTemplate(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Create the basic shaders before replacement.
std::map< const vtkOpenGLHelper *, primitiveInfo > PrimitiveInfo
virtual bool GetNeedToRebuildShaders(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Does the shader source need to be recomputed.
bool DrawingTubes(vtkOpenGLHelper &cellBO, vtkActor *actor)
vtkOpenGLBufferObject * CellScalarBuffer
virtual void RenderPieceStart(vtkRenderer *ren, vtkActor *act)
Implemented by sub classes.
virtual void SetPauseShiftScale(bool pauseShiftScale)
Pause per-render updates to VBO shift+scale parameters.
void RenderPiece(vtkRenderer *ren, vtkActor *act) override
Implemented by sub classes.
virtual std::vector< std::pair< vtkTexture *, std::string > > GetTextures(vtkActor *actor)
void ComputeBounds() override
Called in GetBounds().
std::string GetTextureCoordinateName(const char *tname)
vtkOpenGLRenderTimer * TimerQuery
virtual void BuildIBO(vtkRenderer *ren, vtkActor *act, vtkPolyData *poly)
Build the IBO, called by BuildBufferObjects.
virtual void AddPointIdsToSelectionPrimitives(vtkPolyData *poly, const char *arrayName, unsigned int processId, unsigned int compositeIndex, vtkIdType selectedId)
virtual void ReplaceShaderCustomUniforms(std::map< vtkShader::Type, vtkShader * > shaders, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
bool DrawingTubesOrSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor)
virtual void ReplaceShaderTCoord(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void UpdateShaders(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Make sure appropriate shaders are defined, compiled and bound.
virtual void ReplaceShaderLight(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void ReplaceShaderCoincidentOffset(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void SetCustomUniforms(vtkOpenGLHelper &cellBO, vtkActor *actor)
Set the value of user-defined uniform variables, called by UpdateShader.
virtual void SetCameraShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to the Camera, called by UpdateShader.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void ReplaceShaderValues(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates.
virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act)
Does the VBO/IBO need to be rebuilt.
virtual void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to the property, called by UpdateShader.
virtual void ReplaceShaderEdges(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual bool HaveWideLines(vtkRenderer *, vtkActor *)
virtual void BuildShaders(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Build the shader source code, called by UpdateShader.
void AppendCellTextures(vtkRenderer *ren, vtkActor *, vtkCellArray *prims[4], int representation, std::vector< unsigned char > &colors, std::vector< float > &normals, vtkPolyData *pd, vtkOpenGLCellToVTKCellMap *ccmap)
virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
Set the shader parameters related to the mapper/input data, called by UpdateShader.
vtkMTimeType GetRenderPassStageMTime(vtkActor *actor, const vtkOpenGLHelper *cellBO)
virtual void UpdateMaximumPointCellIds(vtkRenderer *ren, vtkActor *actor)
bool GetSupportsSelection() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
bool DrawingSpheres(vtkOpenGLHelper &cellBO, vtkActor *actor)
vtkNew< vtkOpenGLCellToVTKCellMap > CellCellMap
virtual void RenderPieceFinish(vtkRenderer *ren, vtkActor *act)
Implemented by sub classes.
virtual void ReplaceShaderDepth(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
vtkOpenGLTexture * InternalColorTexture
virtual void ReplaceShaderClip(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
int GetPointPickingPrimitiveSize(int primType)
vtkOpenGLBufferObject * CellNormalBuffer
virtual void BuildSelectionIBO(vtkPolyData *poly, std::vector< unsigned int >(&indices)[4], vtkIdType offset)
Build the selection IBO, called by UpdateBufferObjects.
std::vector< unsigned char > EdgeValues
std::map< std::string, ExtraAttributeValue > ExtraAttributes
virtual void RenderPieceDraw(vtkRenderer *ren, vtkActor *act)
Implemented by sub classes.
vtkOpenGLBufferObject * EdgeBuffer
virtual void UpdateCameraShiftScale(vtkRenderer *ren, vtkActor *actor)
virtual unsigned int GetNumberOfTextures(vtkActor *actor)
void ProcessSelectorPixelBuffers(vtkHardwareSelector *sel, std::vector< unsigned int > &pixeloffsets, vtkProp *prop) override
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
virtual void ReplaceShaderPositionVC(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
virtual void ReplaceShaderNormal(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
vtkNew< vtkTransform > VBOInverseTransform
vtkOpenGLVertexBufferObjectGroup * VBOs
void MapDataArray(const char *vertexAttributeName, const char *dataArrayName, const char *texturename, int fieldAssociation, int componentno)
virtual bool DrawingEdges(vtkRenderer *, vtkActor *)
vtkNew< vtkMatrix4x4 > VBOShiftScale
virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act)
Build the VBO/IBO, called by UpdateBufferObjects.
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
void RemoveVertexAttributeMapping(const char *vertexAttributeName) override
Remove a vertex attribute mapping.
static vtkOpenGLPolyDataMapper * New()
void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
Select a data array from the point/cell data and map it to a generic vertex attribute.
virtual void ReplaceShaderPicking(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
void GetCoincidentParameters(vtkRenderer *ren, vtkActor *actor, float &factor, float &offset)
helper function to get the appropriate coincident params
virtual void SetVBOShiftScaleMethod(int m)
A convenience method for enabling/disabling the VBO's shift+scale transform.
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
virtual bool HaveTCoords(vtkPolyData *poly)
int GetOpenGLMode(int representation, int primType)
virtual void ReplaceShaderColor(std::map< vtkShader::Type, vtkShader * > shaders, vtkRenderer *ren, vtkActor *act)
Perform string replacements on the shader templates, called from ReplaceShaderValues.
void RemoveAllVertexAttributeMappings() override
Remove all vertex attributes.
~vtkOpenGLPolyDataMapper() override
std::map< std::tuple< unsigned int, unsigned int, vtkIdType >, std::vector< vtkIdType > > SelectionCache
virtual bool HaveTextures(vtkActor *actor)
virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act)
Update the VBO/IBO to be current.
virtual void BuildCellTextures(vtkRenderer *ren, vtkActor *, vtkCellArray *prims[4], int representation)
Asynchronously measures GPU execution time for a single event.
represent GPU shader properties
OpenGL texture map.
manage vertex buffer objects shared within a mapper
represent and manipulate 3D points
Definition vtkPoints.h:40
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:91
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:57
abstract specification for renderers
Definition vtkRenderer.h:73
Class to make storing and comparing state quick and easy.
abstracts an OpenGL texture object.
handles properties associated with a texture map
Definition vtkTexture.h:69
record modification and/or execution time
describes linear transformations via a 4x4 matrix
window superclass for vtkRenderWindow
Definition vtkWindow.h:39
int vtkIdType
Definition vtkType.h:332
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:287