KiCad PCB EDA Suite
cobject.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2020 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef _COBJECT_H_
31 #define _COBJECT_H_
32 
33 #include "cbbox.h"
34 #include "../hitinfo.h"
35 #include "../cmaterial.h"
36 
37 
38 enum class OBJECT3D_TYPE
39 {
40  CYLINDER,
41  DUMMYBLOCK,
42  LAYERITEM,
43  XYPLANE,
44  ROUNDSEG,
45  TRIANGLE,
46  MAX
47 };
48 
49 
50 class COBJECT
51 {
52 protected:
57 
58  // m_modelTransparency combines the material and model opacity
59  // 0.0 full opaque, 1.0 full transparent.
61 
62 public:
63 
64  explicit COBJECT( OBJECT3D_TYPE aObjType );
65 
66  void SetMaterial( const CMATERIAL *aMaterial )
67  {
68  m_material = aMaterial;
69  m_modelTransparency = aMaterial->GetTransparency(); // Default transparency is from material
70  }
71 
72  const CMATERIAL *GetMaterial() const { return m_material; }
73  float GetModelTransparency() const { return m_modelTransparency; }
74  void SetModelTransparency( float aModelTransparency ) { m_modelTransparency = aModelTransparency; }
75 
76  virtual SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const = 0;
77 
78  virtual ~COBJECT() {}
79 
86  virtual bool Intersects( const CBBOX &aBBox ) const = 0;
87 
88 
95  virtual bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const = 0;
96 
103  virtual bool IntersectP( const RAY &aRay, float aMaxDistance ) const = 0;
104 
105  const CBBOX &GetBBox() const { return m_bbox; }
106 
107  const SFVEC3F &GetCentroid() const { return m_centroid; }
108 };
109 
110 
114 {
115 public:
116  void ResetStats()
117  {
118  memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT3D_TYPE::MAX ) );
119  }
120 
121  unsigned int GetCountOf( OBJECT3D_TYPE aObjType ) const
122  {
123  return m_counter[static_cast<int>( aObjType )];
124  }
125 
126  void AddOne( OBJECT3D_TYPE aObjType )
127  {
128  m_counter[static_cast<int>( aObjType )]++;
129  }
130 
131  void PrintStats();
132 
134  {
135  if( !s_instance )
137 
138  return *s_instance;
139  }
140 
141 private:
143  COBJECT3D_STATS( const COBJECT3D_STATS &old );
144  const COBJECT3D_STATS &operator=( const COBJECT3D_STATS &old );
146 
147 private:
148  unsigned int m_counter[static_cast<int>( OBJECT3D_TYPE::MAX )];
149 
151 };
152 
153 
154 #endif // _COBJECT_H_
OBJECT3D_TYPE m_obj_type
Definition: cobject.h:55
virtual ~COBJECT()
Definition: cobject.h:78
SFVEC3F m_centroid
Definition: cobject.h:54
A base material class that can be used to derive a material implementation.
Definition: cmaterial.h:195
void SetMaterial(const CMATERIAL *aMaterial)
Definition: cobject.h:66
const COBJECT3D_STATS & operator=(const COBJECT3D_STATS &old)
CBBOX m_bbox
Definition: cobject.h:53
const CMATERIAL * m_material
Definition: cobject.h:56
Definition: ray.h:67
void PrintStats()
Definition: cobject.cpp:64
const SFVEC3F & GetCentroid() const
Definition: cobject.h:107
void AddOne(OBJECT3D_TYPE aObjType)
Definition: cobject.h:126
COBJECT(OBJECT3D_TYPE aObjType)
Definition: cobject.cpp:39
void SetModelTransparency(float aModelTransparency)
Definition: cobject.h:74
unsigned int m_counter[static_cast< int >(OBJECT3D_TYPE::MAX)]
Definition: cobject.h:148
const CMATERIAL * GetMaterial() const
Definition: cobject.h:72
virtual bool IntersectP(const RAY &aRay, float aMaxDistance) const =0
Functions Intersect for shadow test.
float m_modelTransparency
Definition: cobject.h:60
virtual bool Intersects(const CBBOX &aBBox) const =0
Function Intersects.
float GetTransparency() const
Definition: cmaterial.h:213
void ResetStats()
Definition: cobject.h:116
static COBJECT3D_STATS * s_instance
Definition: cobject.h:150
OBJECT3D_TYPE
Definition: cobject.h:38
unsigned int GetCountOf(OBJECT3D_TYPE aObjType) const
Definition: cobject.h:121
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
Functions Intersect.
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
static COBJECT3D_STATS & Instance()
Definition: cobject.h:133
Implements a class for object statistics using Singleton pattern.
Definition: cobject.h:113
float GetModelTransparency() const
Definition: cobject.h:73
CBBOX manages a bounding box defined by two SFVEC3F min max points.
Definition: cbbox.h:40
const CBBOX & GetBBox() const
Definition: cobject.h:105
Bounding Box class definition.
virtual SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const =0