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-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 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 
39 {
47 };
48 
49 
50 class COBJECT
51 {
52 protected:
57 
58 public:
59 
60  explicit COBJECT( OBJECT3D_TYPE aObjType );
61 
62  void SetMaterial( const CMATERIAL *aMaterial ) { m_material = aMaterial; }
63  const CMATERIAL *GetMaterial() const { return m_material; }
64 
65  virtual SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const = 0;
66 
67  virtual ~COBJECT() {}
68 
75  virtual bool Intersects( const CBBOX &aBBox ) const = 0;
76 
77 
84  virtual bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const = 0;
85 
92  virtual bool IntersectP( const RAY &aRay, float aMaxDistance ) const = 0;
93 
94  const CBBOX &GetBBox() const { return m_bbox; }
95 
96  const SFVEC3F &GetCentroid() const { return m_centroid; }
97 };
98 
99 
103 {
104 public:
105 
106  void ResetStats() { memset( m_counter,
107  0,
108  sizeof( unsigned int ) * OBJ3D_MAX ); }
109 
110  unsigned int GetCountOf( OBJECT3D_TYPE aObjType ) const { return m_counter[aObjType]; }
111 
112  void AddOne( OBJECT3D_TYPE aObjType ) { m_counter[aObjType]++; }
113 
114  void PrintStats();
115 
117  {
118  if( !s_instance )
120 
121  return *s_instance;
122  }
123 
124 private:
126  COBJECT3D_STATS( const COBJECT3D_STATS &old );
127  const COBJECT3D_STATS &operator=( const COBJECT3D_STATS &old );
129 
130 private:
131  unsigned int m_counter[OBJ3D_MAX];
132 
134 };
135 
136 
137 #endif // _COBJECT_H_
OBJECT3D_TYPE m_obj_type
Definition: cobject.h:55
virtual ~COBJECT()
Definition: cobject.h:67
SFVEC3F m_centroid
Definition: cobject.h:54
A base material class that can be used to derive a material implementation.
Definition: cmaterial.h:167
void SetMaterial(const CMATERIAL *aMaterial)
Definition: cobject.h:62
const CMATERIAL * GetMaterial() const
Definition: cobject.h:63
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:43
void PrintStats()
Definition: cobject.cpp:57
const SFVEC3F & GetCentroid() const
Definition: cobject.h:96
void AddOne(OBJECT3D_TYPE aObjType)
Definition: cobject.h:112
COBJECT(OBJECT3D_TYPE aObjType)
Definition: cobject.cpp:38
const CBBOX & GetBBox() const
Definition: cobject.h:94
virtual bool IntersectP(const RAY &aRay, float aMaxDistance) const =0
Functions Intersect for shadow test.
virtual bool Intersects(const CBBOX &aBBox) const =0
Function Intersects.
void ResetStats()
Definition: cobject.h:106
unsigned int m_counter[OBJ3D_MAX]
Definition: cobject.h:131
static COBJECT3D_STATS * s_instance
Definition: cobject.h:133
OBJECT3D_TYPE
Definition: cobject.h:38
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:116
unsigned int GetCountOf(OBJECT3D_TYPE aObjType) const
Definition: cobject.h:110
Implements a class for object statistics using Singleton pattern.
Definition: cobject.h:102
Class CBBOX manages a bounding box defined by two SFVEC3F min max points.
Definition: cbbox.h:40
Bounding Box class definition.
virtual SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const =0