OpenCOVER
MultiChannelDrawer.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef MULTICHANNELDRAWER_H
9#define MULTICHANNELDRAWER_H
10
11#include <osg/Matrix>
12#include <osg/Array>
13#include <osg/Geode>
14#include <osg/Camera>
15#include <osg/TextureRectangle>
16
17#include <util/coExport.h>
18
19#include <memory>
20#include <vector>
21
22namespace opencover
23{
24
25class MultiChannelDrawer;
26struct ViewChannelData;
27
28enum ViewEye {
33};
34
35// Store data associated with one view (image rendered for a viewport)
36struct ViewData {
37 static const int NumImages = 1;
38
40 int viewNum = -1;
41 int geoWidth = 0, geoHeight = 0;
45 osg::Matrix imgProj, imgView, imgModel;
46 osg::Matrix newProj, newView, newModel;
47
48 // geometry for mapping depth image
49 osg::ref_ptr<osg::TextureRectangle> colorTex;
50 osg::ref_ptr<osg::TextureRectangle> depthTex;
51 osg::ref_ptr<osg::Image> colorImg[NumImages];
52 osg::ref_ptr<osg::Image> depthImg[NumImages];
53 osg::ref_ptr<osg::Vec2Array> texcoord;
54 osg::ref_ptr<osg::Geometry> fixedGeo;
55 osg::ref_ptr<osg::Geometry> reprojGeo;
56 osg::ref_ptr<osg::Vec2Array> pointCoord, quadCoord;
57 osg::ref_ptr<osg::DrawArrays> pointArr, quadArr;
58 osg::ref_ptr<osg::Uniform> size;
59 osg::ref_ptr<osg::Uniform> pixelOffset;
60 osg::ref_ptr<osg::Uniform> withNeighbors;
61 osg::ref_ptr<osg::Uniform> withHoles;
62 osg::ref_ptr<osg::Program> reprojConstProgram;
63 osg::ref_ptr<osg::Program> reprojAdaptProgram;
64 osg::ref_ptr<osg::Program> reprojMeshProgram;
65
66 std::vector<ViewChannelData *> viewChan;
67
68 ViewData(int view=-1)
69 : viewNum(view)
70 {
71 for (int i=0; i<NumImages; ++i) {
72 width[i] = 0;
73 height[i] = 0;
74 depthWidth[i] = 0;
75 depthHeight[i] = 0;
76 colorFormat[i] = 0;
77 depthFormat[i] = 0;
78 }
79 }
80
82};
83
87 int channelNum = -1;
89 bool second;
90 int width;
91 int height;
92 osg::Matrix curProj, curView, curModel;
93
94 // geometry for mapping depth image
95 osg::ref_ptr<osg::Camera> camera;
96 osg::ref_ptr<osg::Group> scene;
97
98 std::vector<std::shared_ptr<ViewChannelData>> viewChan;
99
101 : drawer(drawer)
102 , channelNum(channel)
103 , eye(Middle)
104 , second(false)
105 , width(0)
106 , height(0)
107 {
108 }
109
111
112 void addView(std::shared_ptr<ViewData> vd);
113 void enableView(std::shared_ptr<ViewData> vd, bool enable);
116};
117
120
121 ViewChannelData(std::shared_ptr<ViewData> view, ChannelData *chan);
123 void setThis(std::shared_ptr<ViewChannelData> vcd);
124
125 osg::ref_ptr<osg::Geometry> fixedGeo;
126 osg::ref_ptr<osg::Geometry> reprojGeo;
127 osg::ref_ptr<osg::Uniform> reprojMat;
128 osg::ref_ptr<osg::StateSet> state;
129 osg::ref_ptr<osg::Geode> geode;
130 osg::ref_ptr<osg::Drawable::DrawCallback> drawCallback;
131
132 ChannelData *chan = nullptr;
133 std::shared_ptr<ViewData> view;
134
135 void update();
136
137};
138
139class PLUGIN_UTILEXPORT MultiChannelDrawer: public osg::Camera {
140 friend struct SingleScreenCB;
141public:
145
146 MultiChannelDrawer(bool flipped=false, bool useCuda=false);
148 int numViews() const;
149 void update();
150 const osg::Matrix &modelMatrix(int idx) const;
151 const osg::Matrix &viewMatrix(int idx) const;
152 const osg::Matrix &projectionMatrix(int idx) const;
153
155 enum Mode {
156 AsIs, //< as is, without reprojection
157 Reproject, //< reproject every pixel as single pixel-sized point
158 ReprojectAdaptive, //< reproject pixels and adapt their size based on viewer distance and reprojection matrix
159 ReprojectAdaptiveWithNeighbors, //< reproject pixels and adapt their size so that gaps to neighbor pixels are filled
160 ReprojectMesh, //< reproject as rectilinear mesh
161 ReprojectMeshWithHoles //< reprjoct as rectilinear mesh, but keep holes where pixels become heavily deformed
162 };
163 Mode mode() const;
164 void setMode(Mode mode);
165
167 Same, //< only render the view created for this viewport
168 MatchingEye, //< render all views for the same (left/right) eye
169 All, //< render all views
170 };
171
177 void setNumViews(int nv=-1);
179 void setViewEye(int view, ViewEye eye);
180
182 void swapFrame();
184 void updateMatrices(int idx, const osg::Matrix &model, const osg::Matrix &view, const osg::Matrix &proj);
186 void resizeView(int idx, int w, int h, GLenum depthFormat=0, GLenum colorFormat=GL_UNSIGNED_BYTE);
188 std::shared_ptr<ViewData> getViewData(int idx);
190 unsigned char *rgba(int idx) const;
192 unsigned char *depth(int idx) const;
194 void clearColor(int idx);
196 void clearDepth(int idx);
197
198private:
199 void initViewData(ViewData &cd);
200 void initChannelData(ChannelData &cd);
201 void createGeometry(ViewData &cd);
202 void createGeometry(ChannelData &cd);
203 void clearViewData();
204 std::vector<std::shared_ptr<ViewData>> m_viewData;
205 std::vector<std::shared_ptr<ChannelData>> m_channelData;
206 bool m_flipped;
207 Mode m_mode;
208 ViewSelection m_viewsToRender = Same;
209 int renderTex=0, writeTex=0;
210 struct AvailableEyes {
211 bool middle=false;
212 bool left=false;
213 bool right=false;
214 };
215 AvailableEyes m_availableEyes;
216 bool haveEye(ViewEye eye);
217
218 const bool m_useCuda;
219 void updateGeoForView(ViewData &vd);
220 int m_numViews = 0;
221};
222
223}
224#endif
Definition: ARToolKit.h:33
ViewEye
Definition: MultiChannelDrawer.h:28
@ Invalid
Definition: MultiChannelDrawer.h:32
@ Right
Definition: MultiChannelDrawer.h:31
@ Middle
Definition: MultiChannelDrawer.h:29
@ Left
Definition: MultiChannelDrawer.h:30
Definition: MultiChannelDrawer.h:36
int depthWidth[NumImages]
Definition: MultiChannelDrawer.h:43
osg::Matrix imgProj
Definition: MultiChannelDrawer.h:45
int height[NumImages]
Definition: MultiChannelDrawer.h:42
osg::ref_ptr< osg::Uniform > pixelOffset
Definition: MultiChannelDrawer.h:59
osg::Matrix imgView
Definition: MultiChannelDrawer.h:45
osg::ref_ptr< osg::TextureRectangle > depthTex
Definition: MultiChannelDrawer.h:50
std::vector< ViewChannelData * > viewChan
Definition: MultiChannelDrawer.h:66
osg::ref_ptr< osg::Geometry > reprojGeo
Definition: MultiChannelDrawer.h:55
int depthHeight[NumImages]
Definition: MultiChannelDrawer.h:43
osg::ref_ptr< osg::Geometry > fixedGeo
Definition: MultiChannelDrawer.h:54
ViewData(int view=-1)
Definition: MultiChannelDrawer.h:68
osg::ref_ptr< osg::Uniform > withNeighbors
Definition: MultiChannelDrawer.h:60
GLenum depthFormat[NumImages]
Definition: MultiChannelDrawer.h:44
int viewNum
Definition: MultiChannelDrawer.h:40
osg::ref_ptr< osg::Program > reprojAdaptProgram
Definition: MultiChannelDrawer.h:63
osg::ref_ptr< osg::Vec2Array > texcoord
Definition: MultiChannelDrawer.h:53
osg::ref_ptr< osg::Program > reprojMeshProgram
Definition: MultiChannelDrawer.h:64
GLenum colorFormat[NumImages]
Definition: MultiChannelDrawer.h:44
osg::ref_ptr< osg::Vec2Array > quadCoord
Definition: MultiChannelDrawer.h:56
osg::ref_ptr< osg::Program > reprojConstProgram
Definition: MultiChannelDrawer.h:62
osg::ref_ptr< osg::Image > colorImg[NumImages]
Definition: MultiChannelDrawer.h:51
osg::ref_ptr< osg::TextureRectangle > colorTex
Definition: MultiChannelDrawer.h:49
int width[NumImages]
Definition: MultiChannelDrawer.h:42
osg::ref_ptr< osg::Vec2Array > pointCoord
Definition: MultiChannelDrawer.h:56
osg::Matrix newModel
Definition: MultiChannelDrawer.h:46
int geoWidth
Definition: MultiChannelDrawer.h:41
osg::ref_ptr< osg::Uniform > withHoles
Definition: MultiChannelDrawer.h:61
osg::ref_ptr< osg::DrawArrays > quadArr
Definition: MultiChannelDrawer.h:57
osg::Matrix imgModel
Definition: MultiChannelDrawer.h:45
osg::ref_ptr< osg::DrawArrays > pointArr
Definition: MultiChannelDrawer.h:57
osg::ref_ptr< osg::Image > depthImg[NumImages]
Definition: MultiChannelDrawer.h:52
static const int NumImages
Definition: MultiChannelDrawer.h:37
int geoHeight
Definition: MultiChannelDrawer.h:41
osg::ref_ptr< osg::Uniform > size
Definition: MultiChannelDrawer.h:58
osg::Matrix newView
Definition: MultiChannelDrawer.h:46
ViewEye eye
Definition: MultiChannelDrawer.h:39
osg::Matrix newProj
Definition: MultiChannelDrawer.h:46
store data associated with one channel (output viewport)
Definition: MultiChannelDrawer.h:85
void addView(std::shared_ptr< ViewData > vd)
ChannelData(MultiChannelDrawer *drawer, int channel)
Definition: MultiChannelDrawer.h:100
std::vector< std::shared_ptr< ViewChannelData > > viewChan
Definition: MultiChannelDrawer.h:98
osg::ref_ptr< osg::Group > scene
Definition: MultiChannelDrawer.h:96
int width
Definition: MultiChannelDrawer.h:90
osg::Matrix curView
Definition: MultiChannelDrawer.h:92
osg::Matrix curModel
Definition: MultiChannelDrawer.h:92
int height
Definition: MultiChannelDrawer.h:91
bool second
Definition: MultiChannelDrawer.h:89
ViewEye eye
Definition: MultiChannelDrawer.h:88
osg::ref_ptr< osg::Camera > camera
Definition: MultiChannelDrawer.h:95
MultiChannelDrawer * drawer
Definition: MultiChannelDrawer.h:86
int channelNum
Definition: MultiChannelDrawer.h:87
osg::Matrix curProj
Definition: MultiChannelDrawer.h:92
void enableView(std::shared_ptr< ViewData > vd, bool enable)
data for rendering a View into a Channel
Definition: MultiChannelDrawer.h:119
std::shared_ptr< ViewData > view
Definition: MultiChannelDrawer.h:133
void setThis(std::shared_ptr< ViewChannelData > vcd)
osg::ref_ptr< osg::Geode > geode
Definition: MultiChannelDrawer.h:129
osg::ref_ptr< osg::Uniform > reprojMat
Definition: MultiChannelDrawer.h:127
ChannelData * chan
Definition: MultiChannelDrawer.h:132
osg::ref_ptr< osg::StateSet > state
Definition: MultiChannelDrawer.h:128
osg::ref_ptr< osg::Geometry > fixedGeo
Definition: MultiChannelDrawer.h:125
osg::ref_ptr< osg::Drawable::DrawCallback > drawCallback
Definition: MultiChannelDrawer.h:130
ViewChannelData(std::shared_ptr< ViewData > view, ChannelData *chan)
osg::ref_ptr< osg::Geometry > reprojGeo
Definition: MultiChannelDrawer.h:126
Definition: MultiChannelDrawer.h:139
ViewSelection viewsToRender() const
whether all available views should be rendered
void clearColor(int idx)
fill color array with all zeros
void resizeView(int idx, int w, int h, GLenum depthFormat=0, GLenum colorFormat=GL_UNSIGNED_BYTE)
resize view idx
opencover::ViewEye ViewEye
Definition: MultiChannelDrawer.h:144
void setNumViews(int nv=-1)
set number of views to render, -1: one view/channel/stereo eye
const osg::Matrix & modelMatrix(int idx) const
to be called each frame, updates current matrices
void updateMatrices(int idx, const osg::Matrix &model, const osg::Matrix &view, const osg::Matrix &proj)
set matrices corresponding to RGBA and depth data for view idx
opencover::ViewData ViewData
Definition: MultiChannelDrawer.h:143
MultiChannelDrawer(bool flipped=false, bool useCuda=false)
Mode
reprojection mode
Definition: MultiChannelDrawer.h:155
@ Reproject
Definition: MultiChannelDrawer.h:157
@ ReprojectAdaptive
Definition: MultiChannelDrawer.h:158
@ ReprojectAdaptiveWithNeighbors
Definition: MultiChannelDrawer.h:159
@ ReprojectMesh
Definition: MultiChannelDrawer.h:160
@ AsIs
Definition: MultiChannelDrawer.h:156
const osg::Matrix & viewMatrix(int idx) const
std::shared_ptr< ViewData > getViewData(int idx)
get a pointer that can be retained
const osg::Matrix & projectionMatrix(int idx) const
void setViewsToRender(ViewSelection views)
return whether all available views should be rendered
unsigned char * rgba(int idx) const
access RGBA data for view idx
void setViewEye(int view, ViewEye eye)
configure for which eye this a view is intended
void swapFrame()
from now on, draw with current RGBA and depth data for all views
unsigned char * depth(int idx) const
access depth data for view idx
ViewSelection
Definition: MultiChannelDrawer.h:166
@ MatchingEye
Definition: MultiChannelDrawer.h:168
@ Same
Definition: MultiChannelDrawer.h:167
@ All
Definition: MultiChannelDrawer.h:169
opencover::ChannelData ChannelData
Definition: MultiChannelDrawer.h:142
void clearDepth(int idx)
fill depth array with all ones