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 
42 class vtkCellArray;
44 class vtkMatrix4x4;
45 class vtkMatrix3x3;
48 class vtkOpenGLTexture;
52 class vtkPoints;
53 class vtkTexture;
54 class vtkTextureObject;
55 class vtkTransform;
57 
58 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
59 {
60 public:
61  static vtkOpenGLPolyDataMapper* New();
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 
84  void ReleaseGraphicsResources(vtkWindow*) override;
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 
142  void ShallowCopy(vtkAbstractMapper* m) override;
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 
212  void RemoveAllVertexAttributeMappings() override;
213 
219  vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
220 
221 protected:
223  ~vtkOpenGLPolyDataMapper() override;
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 
257  virtual bool GetNeedToRebuildShaders(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
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 
274  virtual void ReplaceShaderValues(
275  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
276 
278 
282  virtual void ReplaceShaderRenderPass(
283  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act, bool prePass);
284  virtual void ReplaceShaderCustomUniforms(
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);
292  virtual void ReplaceShaderTCoord(
293  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
294  virtual void ReplaceShaderPicking(
295  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
296  virtual void ReplaceShaderPrimID(
297  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
298  virtual void ReplaceShaderNormal(
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);
302  virtual void ReplaceShaderPositionVC(
303  std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* act);
304  virtual void ReplaceShaderCoincidentOffset(
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 
318  virtual void SetMapperShaderParameters(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
319 
323  virtual void SetLightingShaderParameters(
324  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
325 
329  virtual void SetCameraShaderParameters(vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
330 
334  virtual void SetPropertyShaderParameters(
335  vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* act);
336 
340  virtual void UpdateBufferObjects(vtkRenderer* ren, vtkActor* act);
341 
345  virtual bool GetNeedToRebuildBufferObjects(vtkRenderer* ren, vtkActor* act);
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
388  virtual bool HaveWideLines(vtkRenderer*, vtkActor*);
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:
430  vtkMTimeType GetRenderPassStageMTime(vtkActor* actor, const vtkOpenGLHelper* cellBO);
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;
473  virtual bool DrawingEdges(vtkRenderer*, vtkActor*);
474 
475  // additional picking indirection
480 
482  {
483  public:
488  };
489  std::map<std::string, ExtraAttributeValue> ExtraAttributes;
490 
492 
493  // are we currently drawing spheres/tubes
494  bool DrawingSpheres(vtkOpenGLHelper& cellBO, vtkActor* actor);
495  bool DrawingTubes(vtkOpenGLHelper& cellBO, vtkActor* actor);
496  bool DrawingTubesOrSpheres(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
503  int GetPointPickingPrimitiveSize(int primType);
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
512  virtual void UpdateMaximumPointCellIds(vtkRenderer* ren, vtkActor* actor);
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 
521 private:
523  void operator=(const vtkOpenGLPolyDataMapper&) = delete;
524 };
525 
526 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:56
PolyDataMapper using OpenGL to render.
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:51
vtkOpenGLBufferObject * CellScalarBuffer
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
virtual void MapDataArrayToMultiTextureAttribute(const char *textureName, const char *dataArrayName, int fieldAssociation, int componentno=-1)
virtual void RemoveAllVertexAttributeMappings()
Remove all vertex attributes.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkNew< vtkOpenGLCellToVTKCellMap > CellCellMap
vtkTextureObject * CellScalarTexture
vtkOpenGLBufferObject * CellNormalBuffer
vtkTextureObject * CellNormalTexture
OpenGL rendering utility functions.
abstract specification for renderers
Definition: vtkRenderer.h:72
virtual void RenderPiece(vtkRenderer *, vtkActor *)
Implemented by sub classes.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
virtual void ProcessSelectorPixelBuffers(vtkHardwareSelector *, std::vector< unsigned int > &, vtkProp *)
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
Definition: vtkMapper.h:477
int vtkIdType
Definition: vtkType.h:332
represent GPU shader properties
std::map< std::string, ExtraAttributeValue > ExtraAttributes
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:90
vtkOpenGLBufferObject * EdgeBuffer
virtual void RemoveVertexAttributeMapping(const char *vertexAttributeName)
Remove a vertex attribute mapping.
bool GetSupportsSelection() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
OpenGL texture map.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
std::map< std::tuple< unsigned int, unsigned int, vtkIdType >, std::vector< vtkIdType > > SelectionCache
vtkOpenGLVertexBufferObjectGroup * VBOs
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual void SetPauseShiftScale(bool pauseShiftScale)
Pause per-render updates to VBO shift+scale parameters.
vtkNew< vtkMatrix4x4 > VBOShiftScale
handles properties associated with a texture map
Definition: vtkTexture.h:68
vtkOpenGLRenderTimer * TimerQuery
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void ComputeBounds()
Called in GetBounds().
abstract class specifies interface to map data
abstracts an OpenGL texture object.
virtual void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1)
Select a data array from the point/cell data and map it to a generic vertex attribute.
map vtkPolyData to graphics primitives
object to represent cell connectivity
Definition: vtkCellArray.h:186
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
vtkNew< vtkTransform > VBOInverseTransform
std::vector< unsigned char > EdgeValues
static vtkPolyDataMapper * New()
OpenGL buffer object.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:36
manage vertex buffer objects shared within a mapper
std::map< const vtkOpenGLHelper *, primitiveInfo > PrimitiveInfo
vtkOpenGLTexture * InternalColorTexture
Asynchronously measures GPU execution time for a single event.
Class to make storing and comparing state quick and easy.
represent and manipulate 3D points
Definition: vtkPoints.h:39
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
Definition: vtkMapper.h:115