2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-04-25 14:38:41 +00:00
|
|
|
* Copyright (C) 2015-2020 Mario Luzeiro <mrluzeiro@ua.pt>
|
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file cobject.h
|
|
|
|
* @brief
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _COBJECT_H_
|
|
|
|
#define _COBJECT_H_
|
|
|
|
|
|
|
|
#include "cbbox.h"
|
|
|
|
#include "../hitinfo.h"
|
|
|
|
#include "../cmaterial.h"
|
|
|
|
|
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
enum class OBJECT3D_TYPE
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2019-12-30 13:01:06 +00:00
|
|
|
CYLINDER,
|
|
|
|
DUMMYBLOCK,
|
|
|
|
LAYERITEM,
|
|
|
|
XYPLANE,
|
|
|
|
ROUNDSEG,
|
|
|
|
TRIANGLE,
|
|
|
|
MAX
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
class COBJECT
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
CBBOX m_bbox;
|
|
|
|
SFVEC3F m_centroid;
|
|
|
|
OBJECT3D_TYPE m_obj_type;
|
|
|
|
const CMATERIAL *m_material;
|
|
|
|
|
2020-04-25 14:38:41 +00:00
|
|
|
// m_modelTransparency combines the material and model opacity
|
|
|
|
// 0.0 full opaque, 1.0 full transparent.
|
|
|
|
float m_modelTransparency;
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
public:
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
explicit COBJECT( OBJECT3D_TYPE aObjType );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-05-22 13:28:04 +00:00
|
|
|
void SetMaterial( const CMATERIAL *aMaterial )
|
|
|
|
{
|
|
|
|
m_material = aMaterial;
|
|
|
|
m_modelTransparency = aMaterial->GetTransparency(); // Default transparency is from material
|
|
|
|
}
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
const CMATERIAL *GetMaterial() const { return m_material; }
|
2020-04-25 14:38:41 +00:00
|
|
|
float GetModelTransparency() const { return m_modelTransparency; }
|
|
|
|
void SetModelTransparency( float aModelTransparency ) { m_modelTransparency = aModelTransparency; }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
virtual SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const = 0;
|
|
|
|
|
|
|
|
virtual ~COBJECT() {}
|
|
|
|
|
|
|
|
/** Function Intersects
|
|
|
|
* @brief Intersects - a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)
|
|
|
|
* It intersects if the result intersection is not null
|
|
|
|
* @param aBBox
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
virtual bool Intersects( const CBBOX &aBBox ) const = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/** Functions Intersect
|
|
|
|
* @brief Intersect
|
|
|
|
* @param aRay
|
|
|
|
* @param aHitInfo
|
2017-06-25 09:26:04 +00:00
|
|
|
* @return true if the aRay intersects the object
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
virtual bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const = 0;
|
|
|
|
|
|
|
|
/** Functions Intersect for shadow test
|
|
|
|
* @brief Intersect
|
|
|
|
* @param aRay
|
2017-06-25 09:26:04 +00:00
|
|
|
* @param aMaxDistance - max distance of the test
|
|
|
|
* @return true if the aRay intersects the object
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
virtual bool IntersectP( const RAY &aRay, float aMaxDistance ) const = 0;
|
|
|
|
|
|
|
|
const CBBOX &GetBBox() const { return m_bbox; }
|
|
|
|
|
|
|
|
const SFVEC3F &GetCentroid() const { return m_centroid; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Implements a class for object statistics
|
|
|
|
/// using Singleton pattern
|
|
|
|
class COBJECT3D_STATS
|
|
|
|
{
|
|
|
|
public:
|
2019-12-30 13:01:06 +00:00
|
|
|
void ResetStats()
|
|
|
|
{
|
|
|
|
memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT3D_TYPE::MAX ) );
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
unsigned int GetCountOf( OBJECT3D_TYPE aObjType ) const
|
|
|
|
{
|
|
|
|
return m_counter[static_cast<int>( aObjType )];
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
void AddOne( OBJECT3D_TYPE aObjType )
|
|
|
|
{
|
|
|
|
m_counter[static_cast<int>( aObjType )]++;
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
void PrintStats();
|
|
|
|
|
|
|
|
static COBJECT3D_STATS &Instance()
|
|
|
|
{
|
|
|
|
if( !s_instance )
|
|
|
|
s_instance = new COBJECT3D_STATS;
|
|
|
|
|
|
|
|
return *s_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
COBJECT3D_STATS(){ ResetStats(); }
|
|
|
|
COBJECT3D_STATS( const COBJECT3D_STATS &old );
|
|
|
|
const COBJECT3D_STATS &operator=( const COBJECT3D_STATS &old );
|
|
|
|
~COBJECT3D_STATS(){}
|
|
|
|
|
|
|
|
private:
|
2019-12-30 13:01:06 +00:00
|
|
|
unsigned int m_counter[static_cast<int>( OBJECT3D_TYPE::MAX )];
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
static COBJECT3D_STATS *s_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _COBJECT_H_
|