YafaRay Core  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
object3d.h
Go to the documentation of this file.
1 
2 #ifndef Y_OBJECT3D_H
3 #define Y_OBJECT3D_H
4 
5 #include <yafray_config.h>
6 
7 //#include "primitive.h"
8 #include "matrix4.h"
9 
10 #include <vector>
11 #include <map>
12 #include "color.h"
13 
15 
16 class light_t;
17 class primitive_t;
18 class surfacePoint_t;
19 
21 {
22  public:
23  object3d_t(): light(nullptr), visible(true), is_base_mesh(false), objectIndex(0.f)
24  {
25  objectIndexAuto++;
26  srand(objectIndexAuto);
27  float R,G,B;
28  do
29  {
30  R = (float) (rand() % 8) / 8.f;
31  G = (float) (rand() % 8) / 8.f;
32  B = (float) (rand() % 8) / 8.f;
33  }
34  while (R+G+B < 0.5f);
35  objectIndexAutoColor = color_t(R,G,B);
36  objectIndexAutoNumber = objectIndexAuto;
37  }
40  virtual int numPrimitives() const = 0;
43  virtual int getPrimitives(const primitive_t **prims) const { return 0; }
45  virtual void setLight(const light_t *l){ light=l; }
47  virtual bool canSample() { return false; }
49  virtual bool enableSampling() { return false; }
51  virtual void sample(float s1, float s2, point3d_t &p, vector3d_t &n) const {};
53  void setVisibility(bool v) { visible = v; }
55  void useAsBaseObject(bool v) { is_base_mesh = v; }
57  bool isVisible() const { return visible; }
59  bool isBaseObject() const { return is_base_mesh; }
60  virtual ~object3d_t(){ resetObjectIndex(); }
61  void setObjectIndex(const float &newObjIndex)
62  {
63  objectIndex = newObjIndex;
64  if(highestObjectIndex < objectIndex) highestObjectIndex = objectIndex;
65  }
66  void resetObjectIndex() { highestObjectIndex = 1.f; objectIndexAuto = 0; }
67  void setObjectIndex(const int &newObjIndex) { setObjectIndex((float) newObjIndex); }
68  float getAbsObjectIndex() const { return objectIndex; }
69  float getNormObjectIndex() const { return (objectIndex / highestObjectIndex); }
71  {
72  return color_t(objectIndex);
73  }
75  {
76  float normalizedObjectIndex = getNormObjectIndex();
77  return color_t(normalizedObjectIndex);
78  }
80  {
81  return objectIndexAutoColor;
82  }
84  {
85  return objectIndexAutoNumber;
86  }
87 
88  protected:
89  const light_t *light;
90  bool visible;
92  float objectIndex;
93  static unsigned int objectIndexAuto;
95  color_t objectIndexAutoNumber = 0.f;
96  static float highestObjectIndex;
97 };
98 
99 
100 
103 class primObject_t : public object3d_t
104 {
105  public:
106  primObject_t(primitive_t *p): prim(p) { };
107  virtual int numPrimitives() const { return 1; }
108  virtual int getPrimitives(const primitive_t **prims) const{ *prims = prim; return 1; }
109  private:
110  primitive_t *prim;
111 };
112 
114 
115 #endif // Y_OBJECT3D_H
bool isVisible() const
Definition: object3d.h:57
color_t objectIndexAutoColor
Object Index color automatically generated for the object-index-auto color render pass...
Definition: object3d.h:94
float objectIndex
Object Index for the object-index render pass.
Definition: object3d.h:92
color_t getNormObjectIndexColor() const
Definition: object3d.h:74
void useAsBaseObject(bool v)
Definition: object3d.h:55
object3d_t()
Definition: object3d.h:23
bool isBaseObject() const
Definition: object3d.h:59
virtual bool enableSampling()
Definition: object3d.h:49
#define __BEGIN_YAFRAY
bool visible
toggle whether geometry is visible or only guidance for other stuff
Definition: object3d.h:90
float getAbsObjectIndex() const
Definition: object3d.h:68
color_t getAutoObjectIndexColor() const
Definition: object3d.h:79
virtual bool canSample()
Definition: object3d.h:47
virtual int getPrimitives(const primitive_t **prims) const
Definition: object3d.h:108
static unsigned int objectIndexAuto
Object Index automatically generated for the object-index-auto render pass.
Definition: object3d.h:93
void setVisibility(bool v)
Definition: object3d.h:53
float getNormObjectIndex() const
Definition: object3d.h:69
const light_t * light
Definition: object3d.h:89
virtual ~object3d_t()
Definition: object3d.h:60
virtual int numPrimitives() const
Definition: object3d.h:107
Definition: color.h:49
virtual int getPrimitives(const primitive_t **prims) const
Definition: object3d.h:43
Definition: light.h:29
void setObjectIndex(const int &newObjIndex)
Definition: object3d.h:67
primObject_t(primitive_t *p)
Definition: object3d.h:106
static float highestObjectIndex
Class shared variable containing the highest object index used for the Normalized Object Index pass...
Definition: object3d.h:96
void setObjectIndex(const float &newObjIndex)
Definition: object3d.h:61
#define YAFRAYCORE_EXPORT
virtual void setLight(const light_t *l)
Definition: object3d.h:45
__BEGIN_YAFRAY const int prims[50]
Definition: scr_halton.h:11
color_t getAutoObjectIndexNumber() const
Definition: object3d.h:83
virtual void sample(float s1, float s2, point3d_t &p, vector3d_t &n) const
Definition: object3d.h:51
void resetObjectIndex()
Definition: object3d.h:66
bool is_base_mesh
Definition: object3d.h:91
color_t getAbsObjectIndexColor() const
Definition: object3d.h:70
#define __END_YAFRAY