1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 */
16
17 /** \file
18 * \ingroup freestyle
19 * \brief Class to display textual information about a scene graph.
20 */
21
22 #include <iomanip>
23
24 #include "IndexedFaceSet.h"
25 #include "ScenePrettyPrinter.h"
26
27 namespace Freestyle {
28
29 #define VISIT(CLASS) \
30 void ScenePrettyPrinter::visit##CLASS(CLASS &) \
31 { \
32 _ofs << _space << #CLASS << endl; \
33 }
34
35 VISIT(Node)
VISIT(NodeShape)36 VISIT(NodeShape)
37 VISIT(NodeGroup)
38 VISIT(NodeLight)
39 VISIT(NodeDrawingStyle)
40 VISIT(NodeTransform)
41
42 void ScenePrettyPrinter::visitNodeShapeBefore(NodeShape &UNUSED(shape))
43 {
44 increaseSpace();
45 }
46
visitNodeShapeAfter(NodeShape & UNUSED (shape))47 void ScenePrettyPrinter::visitNodeShapeAfter(NodeShape &UNUSED(shape))
48 {
49 decreaseSpace();
50 }
51
visitNodeGroupBefore(NodeGroup & UNUSED (group))52 void ScenePrettyPrinter::visitNodeGroupBefore(NodeGroup &UNUSED(group))
53 {
54 increaseSpace();
55 }
56
visitNodeGroupAfter(NodeGroup & UNUSED (group))57 void ScenePrettyPrinter::visitNodeGroupAfter(NodeGroup &UNUSED(group))
58 {
59 decreaseSpace();
60 }
61
visitNodeDrawingStyleBefore(NodeDrawingStyle & UNUSED (style))62 void ScenePrettyPrinter::visitNodeDrawingStyleBefore(NodeDrawingStyle &UNUSED(style))
63 {
64 increaseSpace();
65 }
66
visitNodeDrawingStyleAfter(NodeDrawingStyle & UNUSED (style))67 void ScenePrettyPrinter::visitNodeDrawingStyleAfter(NodeDrawingStyle &UNUSED(style))
68 {
69 decreaseSpace();
70 }
71
visitNodeTransformBefore(NodeTransform & UNUSED (transform))72 void ScenePrettyPrinter::visitNodeTransformBefore(NodeTransform &UNUSED(transform))
73 {
74 increaseSpace();
75 }
76
visitNodeTransformAfter(NodeTransform & UNUSED (transform))77 void ScenePrettyPrinter::visitNodeTransformAfter(NodeTransform &UNUSED(transform))
78 {
79 decreaseSpace();
80 }
81
82 VISIT(LineRep)
VISIT(OrientedLineRep)83 VISIT(OrientedLineRep)
84 VISIT(TriangleRep)
85 VISIT(VertexRep)
86
87 void ScenePrettyPrinter::visitIndexedFaceSet(IndexedFaceSet &ifs)
88 {
89 const float *vertices = ifs.vertices();
90 unsigned vsize = ifs.vsize();
91
92 _ofs << _space << "IndexedFaceSet" << endl;
93 const float *p = vertices;
94 for (unsigned int i = 0; i < vsize / 3; i++) {
95 _ofs << _space << " " << setw(3) << setfill('0') << i << ": " << p[0] << ", " << p[1] << ", "
96 << p[2] << endl;
97 p += 3;
98 }
99 }
100
101 } /* namespace Freestyle */
102