iMSTK
Interactive Medical Simulation Toolkit
imstkRenderParticles.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkRenderParticles.h"
8 #include "imstkLogger.h"
9 
10 namespace imstk
11 {
12 RenderParticles::RenderParticles(const unsigned int maxNumParticles)
13 {
14  if (maxNumParticles <= 128)
15  {
16  m_maxNumParticles = maxNumParticles;
17  }
18  else
19  {
20  m_maxNumParticles = 128;
21  LOG(WARNING) << "The maximum number of decals is 128";
22  }
23 
24  m_vertexPositions[0] = Vec3d(0.5, 0.5, 0);
25  m_vertexPositions[1] = Vec3d(0.5, -0.5, 0);
26  m_vertexPositions[2] = Vec3d(-0.5, 0.5, 0);
27  m_vertexPositions[3] = Vec3d(-0.5, -0.5, 0);
28 
29  m_vertexNormals[0] = Vec3d(0.0, 0.0, 1.0);
30  m_vertexNormals[1] = Vec3d(0.0, 0.0, 1.0);
31  m_vertexNormals[2] = Vec3d(0.0, 0.0, 1.0);
32  m_vertexNormals[3] = Vec3d(0.0, 0.0, 1.0);
33 
34  m_vertexUVs[0] = Vec2d(1.0, 1.0);
35  m_vertexUVs[1] = Vec2d(1.0, 0);
36  m_vertexUVs[2] = Vec2d(0, 1.0);
37  m_vertexUVs[3] = Vec2d(0, 0);
38 
39  m_triangles[0] = Vec3i(1, 0, 3);
40  m_triangles[1] = Vec3i(0, 2, 3);
41 }
42 
43 void
45 {
46  m_particleSize = size;
47 }
48 
49 std::vector<std::unique_ptr<RenderParticle>>&
51 {
52  return m_particles;
53 }
54 
55 void
57 {
58  m_numParticles = 0;
59 }
60 
61 void
63 {
64  m_numParticles++;
65 }
66 
67 unsigned int
69 {
70  return m_numParticles;
71 }
72 
73 unsigned int
75 {
76  return m_maxNumParticles;
77 }
78 
79 void
80 RenderParticles::applyTransform(const Mat4d& imstkNotUsed(m))
81 {
82  LOG(WARNING) << "applyTransform Not implemented!";
83 }
84 
86 RenderParticles::cloneImplementation() const
87 {
88  RenderParticles* geom = new RenderParticles();
89  // Because of unique ptr in particle copy must be reimplemented
91  geom->m_particleSize = m_particleSize;
92  geom->m_particles.resize(m_particles.size());
93  for (int i = 0; i < m_particles.size(); i++)
94  {
95  geom->m_particles[i] = std::make_unique<RenderParticle>(*m_particles[i]);
96  }
97  for (int i = 0; i < 4; i++)
98  {
99  geom->m_vertexPositions[i] = m_vertexPositions[i];
100  geom->m_vertexNormals[i] = m_vertexNormals[i];
101  geom->m_vertexTangents[i] = m_vertexTangents[i];
102  geom->m_vertexUVs[i] = m_vertexUVs[i];
103  }
104  geom->m_triangles[0] = m_triangles[0];
105  geom->m_triangles[1] = m_triangles[1];
106  return geom;
107 }
108 } // namespace imstk
void reset()
Reset number of particles.
std::vector< std::unique_ptr< RenderParticle > > m_particles
Particle objects.
std::vector< std::unique_ptr< RenderParticle > > & getParticles()
Get particles.
Compound Geometry.
unsigned int m_maxNumParticles
Maximum particles.
RenderParticles(const unsigned int maxNumParticles=128)
Constructor.
Particles for rendering.
void setParticleSize(const float size)
Set size of particle.
void incrementNumOfParticles()
Increment number of particles.
void applyTransform(const Mat4d &m) override
Directly apply transform to data.
unsigned int getMaxNumParticles()
Get maximum number of particles.
unsigned int getNumParticles()
Get number of particles.