gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
InternalOrganMesh.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2017, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4 http://www.fpvidal.net/
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 3. Neither the name of the Bangor University nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 
34 
35 #ifndef __InternalOrganMesh_h
36 #define __InternalOrganMesh_h
37 
55 //******************************************************************************
56 // Include
57 //******************************************************************************
58 #ifndef __AnatomicalMesh_h
60 #endif
61 
62 #ifndef __Shader_h
63 #include "gVirtualXRay/Shader.h"
64 #endif
65 
66 
67 //******************************************************************************
68 // namespace
69 //******************************************************************************
70 namespace gVirtualXRay {
71 
72 //==============================================================================
78 //==============================================================================
80 //------------------------------------------------------------------------------
81 {
82 //******************************************************************************
83 public:
84  //--------------------------------------------------------------------------
86  /*
87  * @param texture_2D_size: Size of the side of the buffer
88  * of the 2D texture
89  * (default: 1024)
90  * @param texture_3D_size: Size of the side of the buffer
91  * of the 3D texture (default: 64)
92  * @param optimize_texture_coordinates: To know if the texture
93  * coordinates need to be optimized
94  * (default: true)
95  */
96  //--------------------------------------------------------------------------
97  InternalOrganMesh(bool optimize_texture_coordinates = true,
98  unsigned int texture_2D_size = 1024,
99  unsigned int texture_3D_size = 64);
100 
101  //--------------------------------------------------------------------------
103  //--------------------------------------------------------------------------
104  virtual ~InternalOrganMesh();
105 
106 
107  //--------------------------------------------------------------------------
109  //--------------------------------------------------------------------------
110  virtual bool isTransparent() const;
111 
112 
113  //--------------------------------------------------------------------------
115  //--------------------------------------------------------------------------
116  virtual bool isSoftTissue() const = 0;
117 
118 
119  //--------------------------------------------------------------------------
121  /*
122  * @param aShaderID: The GLSL shader used to display the anatomical mesh
123  */
124  //-------------------------------------------------------------------------
125  virtual void defineDisplayShaderInput(int shader_id);
126 
127 
128  //--------------------------------------------------------------------------
132  //--------------------------------------------------------------------------
133  virtual void initialize() = 0;
134 
135 
136  //--------------------------------------------------------------------------
138  //--------------------------------------------------------------------------
139  virtual void splitFaces();
140 
141 
142  virtual void copyFrom(const InternalOrganMesh& aPolygonMesh);
143 
144 
145  virtual InternalOrganMesh& operator=(const InternalOrganMesh& aPolygonMesh);
146 
147 
148 //******************************************************************************
149 protected:
151  enum ToCreate
152  {
155  };
156 
157 
158  //--------------------------------------------------------------------------
160  //--------------------------------------------------------------------------
161  virtual void generateTextures() = 0;
162 
163 
164  //--------------------------------------------------------------------------
166  /*
167  * @param shader: The GLSL shader
168  * @param frame_buffer: The frame buffer the texture will be rendered to
169  * @param to_create: To know if a bump map or a colour texture has to
170  * be created
171  */
172  //--------------------------------------------------------------------------
173  virtual void generate2DTexture(Shader const& shader,
174  unsigned int& frame_buffer,
175  ToCreate to_create);
176 
177 
178  //--------------------------------------------------------------------------
180  /*
181  * @param shader: The GLSL shader
182  * @param frame_buffer: The frame buffer the texture will be rendered to
183  * @param texture: the texture storing the data
184  * @param to_create: To know if a bump map or a colour texture has to
185  * be created
186  */
187  //--------------------------------------------------------------------------
188  virtual void generate3DTexture(Shader const& shader,
189  unsigned int& frame_buffer,
190  unsigned int& texture, ToCreate to_create);
191 
192 
193  //--------------------------------------------------------------------------
195  /*
196  * @param shader_id: The GLSL shader
197  */
198  //--------------------------------------------------------------------------
199  virtual void defineBumpMapShaderInput(int shader_id);
200 
201 
202  //--------------------------------------------------------------------------
205  /*
206  * @param shader_id: The GLSL shader
207  */
208  //-------------------------------------------------------------------------
209  virtual void defineColourTextureShaderInput(int shader_id) = 0;
210 
211 
212  //--------------------------------------------------------------------------
214  /*
215  * @param aTexture: the texture to be generated
216  * @param aFrameBuffer: the framebuffer
217  */
218  //-------------------------------------------------------------------------
219  virtual void initialize2DBuffer(unsigned int& aTexture,
220  unsigned int& aFrameBuffer);
221 
222 
223  //--------------------------------------------------------------------------
225  /*
226  * @param aTexture: the texture to be generated
227  * @param aFrameBuffer: the framebuffer
228  */
229  //-------------------------------------------------------------------------
230  virtual void initialize3DBuffer(unsigned int& aTexture,
231  unsigned int& aFrameBuffer,
232  bool has_colours);
233 
234 
235  //--------------------------------------------------------------------------
237  //--------------------------------------------------------------------------
238  virtual void load2DBumpShader();
239 
240 
241  //--------------------------------------------------------------------------
243  //--------------------------------------------------------------------------
244  virtual void load3DBumpShader();
245 
246 
247  //--------------------------------------------------------------------------
250  //--------------------------------------------------------------------------
251  virtual void initialize2DTextureCoordinates();
252 
253 
254  //--------------------------------------------------------------------------
256  //--------------------------------------------------------------------------
257  virtual void initialize3DTextureCoordinates();
258 
259 
260  //--------------------------------------------------------------------------
262  //--------------------------------------------------------------------------
263  virtual void shareNormalVectors();
264 
265 
266  //--------------------------------------------------------------------------
268  //--------------------------------------------------------------------------
269  virtual void deleteIndices();
270 
271 
272  //--------------------------------------------------------------------------
274  //--------------------------------------------------------------------------
275  virtual void initGradientTab();
276 
277 
278  //--------------------------------------------------------------------------
280  //--------------------------------------------------------------------------
281  virtual void initPermutation();
282 
283 
284  // Gradient tab for gnoise
285  std::vector<VEC3> m_gradient_tab;
286 
287 
288  // Permutation tab for noises
289  std::vector<int> m_permutation;
290 
291 
292  // Coordinates for texture sampling in 2D
293  std::vector<VEC2> m_texture_coordinates_2d;
294 
295 
296  // Coordinates for texture sampling in 3D
297  std::vector<VEC3> m_texture_coordinates_3d;
298 
299 
300  // Direction of the margin to add between triangles in the 2D texture
301  std::vector<VEC2> m_margin_direction;
302 
303 
304  // Buffers for the bump map
305  unsigned int m_bump_map_texture;
306 
307 
309 
310 
311  // GLSL shader to create the bump map
313 
314 
315  // To know if the internal organ is a muscle with a tendon for texturing and
316  // bump mapping, 0 by default
318 
319 
320  // To know if the internal organ is a lung with two colors and a line
321  // for texturing and bump mapping, 0 by default
323 
324 
325  // To know if the internal organ has thin bumps for bump mapping,
326  // 0 by default
328 
329 
331 
332 
333  // Size of the side of the buffer in 2D
334  unsigned int m_texture_size_2d;
335 
336 
337  // Size of the side of the buffer in 3D
338  unsigned int m_texture_size_3d;
339 
340 
341  // To know if the textured has been initialized
343 
344 
345  // To know if the generation texture coordinates has been set
347 
348 
349  // To know if the texture coordinates need to be optimized
351 };
352 
353 
354 } // namespace gVirtualXRay
355 
356 
357 #endif // INTERNALORGANMESH_H
InternalOrganMesh is a class to handle a polygon mesh for an internal organ. Internal organs use bump...
virtual void defineDisplayShaderInput(int shader_id)
Link the attributes to their id in the shader.
virtual InternalOrganMesh & operator=(const InternalOrganMesh &aPolygonMesh)
virtual ~InternalOrganMesh()
Destructor.
Class to handle GLSL shaders.
ToCreate
To know if a bump map or a colour texture has to be created.
virtual void shareNormalVectors()
Compute a normal vector per vertex for a smoother display.
virtual void generateTextures()=0
generates the textures
virtual void load2DBumpShader()
Load the shader to create the 2D bump map.
std::vector< VEC2 > m_margin_direction
virtual void generate2DTexture(Shader const &shader, unsigned int &frame_buffer, ToCreate to_create)
generates a 2D texture
virtual void load3DBumpShader()
Load the shader to create the 3D bump map.
std::vector< VEC3 > m_texture_coordinates_3d
virtual void deleteIndices()
delete the indices and calculate new normal vectors
AnatomicalMesh is a class to handle a polygon mesh for tissue.
virtual void generate3DTexture(Shader const &shader, unsigned int &frame_buffer, unsigned int &texture, ToCreate to_create)
generates a 3D texture
Shader is a class to handle shaders written in GLSL.
Definition: Shader.h:87
virtual void initialize2DBuffer(unsigned int &aTexture, unsigned int &aFrameBuffer)
initialize a 2D frame buffer and bind a texture to it
virtual void initPermutation()
initialize permutation tab for all noises
InternalOrganMesh(bool optimize_texture_coordinates=true, unsigned int texture_2D_size=1024, unsigned int texture_3D_size=64)
Default Constructor.
virtual void initialize2DTextureCoordinates()
virtual void initialize3DTextureCoordinates()
Initialise 3D texture coordinates.
Class to handle a polygon mesh for tissue.
virtual void defineBumpMapShaderInput(int shader_id)
Link the attributes to their id in the shader bump map generation.
virtual bool isTransparent() const
return true if the mesh has to be displayed with transparency
virtual void initialize3DBuffer(unsigned int &aTexture, unsigned int &aFrameBuffer, bool has_colours)
initialize a 3D frame buffer and bind a texture to its layer 0
virtual void splitFaces()
Split each face into four faces.
virtual void initGradientTab()
initialize gradient tab for gnoise
virtual void defineColourTextureShaderInput(int shader_id)=0
std::vector< VEC2 > m_texture_coordinates_2d
virtual void copyFrom(const InternalOrganMesh &aPolygonMesh)
virtual bool isSoftTissue() const =0
return true if the mesh represent a soft tissue