File: OniDebug.h

package info (click to toggle)
openni2 2.2.0.33%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 22,216 kB
  • sloc: cpp: 111,197; ansic: 35,511; sh: 10,542; python: 1,313; java: 952; makefile: 575; xml: 12
file content (170 lines) | stat: -rw-r--r-- 4,398 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*****************************************************************************
*                                                                            *
*  OpenNI 2.x Alpha                                                          *
*  Copyright (C) 2012 PrimeSense Ltd.                                        *
*                                                                            *
*  This file is part of OpenNI.                                              *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
*****************************************************************************/
#ifndef _ONI_DEBUG_H_
#define _ONI_DEBUG_H_

namespace oni
{
namespace implementation
{
enum DebugObjectType
{
	DEBUG_OBJECT_POINT,
	DEBUG_OBJECT_LINE,
	DEBUG_OBJECT_CIRCLE
};

class DebugObject
{
public:
	DebugObject(DebugObjectType type) : m_type(type)
	{
		m_color.r = m_color.g = m_color.b = 255;
	}

	void SetColor(OniRGBPixel color)
	{
		m_color = color;
	}
	void SetColor(OniUInt8 r, OniUInt8 g, OniUInt8 b)
	{
		m_color.r = r;
		m_color.g = g;
		m_color.b = b;
	}

	void GetColor(OniRGBPixel& color) const
	{
		color = m_color;
	}

	DebugObjectType GetType() const
	{
		return m_type;
	}
protected:
	OniRGBPixel m_color;
	DebugObjectType m_type;
};

class DebugPoint : public DebugObject
{
public:
	DebugPoint(pscommon::Point3D point, DebugObjectType type = DEBUG_OBJECT_POINT) :
	  DebugObject(type),
		m_point(point)
	{}
	DebugPoint(OniUInt16 x, OniUInt16 y, DebugObjectType type = DEBUG_OBJECT_POINT) :
	  DebugObject(type)
	  {
		  m_point.x = x;
		  m_point.y = y;
	  }

	pscommon::Point3D GetPoint() const {return m_point;}
protected:
	pscommon::Point3D m_point;
};

class DebugLine : public DebugPoint
{
public:
	DebugLine(pscommon::Point3D point1, pscommon::Point3D point2) :
	  DebugPoint(point1, DEBUG_OBJECT_LINE)
	  {
		  m_point2 = point2;
	  }

	  pscommon::Point3D GetPoint2() const {return m_point2;}
protected:
	pscommon::Point3D m_point2;
};

class DebugCircle : public DebugPoint
{
public:
	DebugCircle(pscommon::Point3D center, OniFloat radius) :
	  DebugPoint(center, DEBUG_OBJECT_CIRCLE),
		  m_radius(radius)
	  {}
	  OniFloat GetRadius() const {return m_radius;}
protected:
	OniFloat m_radius;
};

class Debug
{
public:
	class TimedDebugObject
	{
	public:
		TimedDebugObject(DebugObject* pObject, OniUInt32 ttl) :
		  m_pObject(pObject), m_ttl(ttl)
		  {}
		void Tick()
		{
			if (m_ttl != 0) --m_ttl;
		}
		OniUInt32 GetTTL() const {return m_ttl;}
		DebugObject* GetObject() const {return m_pObject;}
	protected:
		DebugObject* m_pObject;
		OniUInt32 m_ttl;
	};

	typedef pscommon::List<pscommon::SmartPointer<TimedDebugObject> > DebugObjectList;

	Debug()
	{}

	void Tick()
	{
		for (pscommon::Hash<OniUInt16, DebugObjectList>::Iterator iter = m_objectsByDepth.Begin(); iter != m_objectsByDepth.End(); ++iter)
		{
			for (DebugObjectList::Iterator objectIter = (*iter).Value().Begin(); objectIter != (*iter).Value().End(); ++objectIter)
			{
				(*objectIter)->Tick();
				if ((*objectIter)->GetTTL() == 0)
				{
					DebugObjectList::Iterator toErase = objectIter;
					--objectIter;
					(*iter).Value().Remove(toErase);
				}
			}
		}
	}
	void AddDebugObject(DebugObject* pObject, OniUInt16 layer, OniUInt16 ttl)
	{
		m_objectsByDepth[layer].AddLast(new TimedDebugObject(pObject, ttl));
	}

private:
	pscommon::Hash<OniUInt16, DebugObjectList> m_objectsByDepth;
};
}
}






#endif