OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
exporter.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_GFX_EXPORTER_HH
20 #define OST_GFX_EXPORTER_HH
21 
22 #include <ost/geom/vec3.hh>
23 #include <ost/geom/vec4.hh>
24 #include <ost/geom/mat3.hh>
25 #include <ost/geom/mat4.hh>
26 
27 #include <ost/gfx/module_config.hh>
28 
29 namespace ost { namespace gfx {
30 
31 class Scene;
32 
34 {
35 public:
36  enum NodeType {
37  ROOT=1,
38  GROUP=2,
39  OBJ=3
40  };
41 
43  scale_(1.0),
44  to_origin_(true)
45  {}
46  virtual ~Exporter() {}
47  virtual void SceneStart(const Scene* scene) {}
48  virtual void SceneEnd(const Scene* scene) {}
49 
50  virtual void NodeStart(const std::string& name, NodeType t) {}
51  virtual void NodeEnd(const std::string& name) {}
52 
53  // this indicates beginning of new data, including a reset of the indices
54  // may occur more than once for a given node
55  virtual void WriteVertexData(const float* v, const float* n, const float* c, const float* t,
56  size_t stride, size_t count) {}
57  virtual void WritePointData(const unsigned int* i, size_t count) {}
58  virtual void WriteLineData(const unsigned int* ij, size_t count) {}
59  virtual void WriteTriData(const unsigned int* ijk, size_t count) {}
60  virtual void WriteQuadData(const unsigned int* ijkl, size_t count) {}
61 
62  // scale positions for absolute data formats (like dae)
63  void SetScale(float s) {scale_=s;}
64  float GetScale() const {return scale_;}
65  // if true (default), re-orient so that center is at (0,0,0)
66  // and viewing direction is along z
67  // (basically apply modelview matrix)
68  void SetToOrigin(bool b) {to_origin_=b;}
69  bool GetToOrigin() const {return to_origin_;}
70 
71  // used by Scene::Export
72  void SetupTransform(const Scene* scene);
73  // used by WriteVertexData in derived classes
74  // modifies input arg!!
75  void TransformPosition(float* p) const;
76  void TransformNormal(float* n) const;
77 
78 private:
79  float scale_;
80  bool to_origin_;
81  geom::Mat4 vertex_tf_;
82  geom::Mat3 normal_tf_;
83 };
84 
85 
86 
87 }} // ns
88 
89 #endif
virtual void WriteLineData(const unsigned int *ij, size_t count)
Definition: exporter.hh:58
virtual void WriteVertexData(const float *v, const float *n, const float *c, const float *t, size_t stride, size_t count)
Definition: exporter.hh:55
main class for organization and root for the graphical display
Definition: scene.hh:81
virtual void WritePointData(const unsigned int *i, size_t count)
Definition: exporter.hh:57
bool GetToOrigin() const
Definition: exporter.hh:69
#define DLLEXPORT_OST_GFX
virtual void SceneEnd(const Scene *scene)
Definition: exporter.hh:48
virtual void SceneStart(const Scene *scene)
Definition: exporter.hh:47
virtual void NodeStart(const std::string &name, NodeType t)
Definition: exporter.hh:50
virtual void WriteTriData(const unsigned int *ijk, size_t count)
Definition: exporter.hh:59
virtual ~Exporter()
Definition: exporter.hh:46
void SetToOrigin(bool b)
Definition: exporter.hh:68
virtual void NodeEnd(const std::string &name)
Definition: exporter.hh:51
float GetScale() const
Definition: exporter.hh:64
virtual void WriteQuadData(const unsigned int *ijkl, size_t count)
Definition: exporter.hh:60
void SetScale(float s)
Definition: exporter.hh:63