MeVisLab Resolution Independence API
Toggle main menu visibility
Loading...
Searching...
No Matches
SoSceneWriter.h
Go to the documentation of this file.
1
/*************************************************************************************
2
**
3
** Copyright 2007, MeVis Medical Solutions AG
4
**
5
** The user may use this file in accordance with the license agreement provided with
6
** the Software or, alternatively, in accordance with the terms contained in a
7
** written agreement between the user and MeVis Medical Solutions AG.
8
**
9
** For further information use the contact form at https://www.mevislab.de/contact
10
**
11
**************************************************************************************/
12
13
#ifndef SO_SCENE_WRITER_H
14
#define SO_SCENE_WRITER_H
15
16
18
19
#include "
SoUtilsSystem.h
"
20
#include <ThirdPartyWarningsDisable.h>
21
#include <Inventor/SoPrimitiveVertex.h>
22
#include <Inventor/nodes/SoNode.h>
23
#include <Inventor/nodes/SoShape.h>
24
#include <Inventor/fields/SoFields.h>
25
#include <Inventor/fields/SoSFEnum.h>
26
#include <Inventor/engines/SoSubEngine.h>
27
#include <Inventor/sensors/SoFieldSensor.h>
28
#include <Inventor/sensors/SoNodeSensor.h>
29
#include <boost/unordered_map.hpp>
30
#include <ThirdPartyWarningsRestore.h>
31
//--------------------------------------------------------------------------------------
33
//--------------------------------------------------------------------------------------
34
#ifdef WIN32
36
#pragma warning(disable : 4018)
37
38
#endif
40
41
#include <vector>
42
#include <algorithm>
43
44
45
//--------------------------------------------------------------------------------------------------------------
47
52
//--------------------------------------------------------------------------------------------------------------
53
class
SoSceneWriter
:
public
SoEngine
54
{
55
SO_ENGINE_HEADER(
SoSceneWriter
);
56
57
public
:
59
#ifdef TGSOIV
60
enum
Format
{
61
INVENTOR_ASCII
= 0,
62
INVENTOR_BINARY
,
63
VRML_1,
64
VRML_2,
65
STL_ASCII
,
66
STL_BINARY
,
67
Z3D
68
};
69
#else
70
enum
Format
{
71
INVENTOR_ASCII
= 0,
72
INVENTOR_BINARY
,
73
STL_ASCII
,
74
STL_BINARY
,
75
VRML_97
76
};
77
78
enum
SoPrimitive
{
79
LINE
= 2,
80
TRIANGLE
= 3
81
};
82
#endif
83
84
SoSceneWriter
();
85
87
struct
COLORED_POINT
88
{
89
SbVec3f
coord
;
90
SbVec3f
normal
;
// normal is only used if collecting / writing triangle information
91
SbColor
color
;
92
float
shininess
;
93
float
transparency
;
94
bool
operator==
(
const
COLORED_POINT
& cp)
const
95
{
96
return
(cp.
coord
==
coord
) && (cp.
color
==
color
) && (cp.
normal
==
normal
) && (cp.
shininess
==
shininess
) &&
97
(cp.
transparency
==
transparency
);
98
}
99
};
100
101
103
struct
hashColoredPoint
104
{
105
inline
size_t
operator()
(
const
COLORED_POINT
& cp)
const
106
{
107
size_t
seed = 0;
108
109
for
(
int
i = 0; i < 3; ++i) {
110
boost::hash_combine(seed, cp.
coord
[i]);
111
boost::hash_combine(seed, cp.
normal
[i]);
112
boost::hash_combine(seed, cp.
color
[i]);
113
}
114
boost::hash_combine(seed, cp.
shininess
);
115
boost::hash_combine(seed, cp.
transparency
);
116
117
return
seed;
118
}
119
};
120
121
123
125
SoSFNode
sceneGraph
;
127
SoSFTrigger
save
;
129
SoSFString
filename
;
131
SoSFEnum
format
;
132
133
#ifndef TGSOIV
135
137
SoSFBool
bColorPerVertex
;
138
140
SoSFBool
bUseGlobalColor
;
141
143
SoSFBool
bNormalPerVertex
;
144
146
SoSFBool
bSaveNormals
;
147
#endif
148
150
152
static
void
initClass
();
153
155
void
saveChanged
();
157
static
void
saveChangedCB
(
void
* data, SoSensor* a);
158
160
void
inputChanged
(SoField*
/*whichField*/
)
override
{};
162
void
evaluate
()
override
{};
163
164
protected
:
165
~SoSceneWriter
()
override
;
166
168
void
formatFileExtension
();
169
170
#ifndef TGSOIV
172
void
writeSimpleVRML2
();
173
#endif
174
175
177
179
void
writeVecToStlFile
(SoMFVec3f* pMVec3f);
180
181
183
SbVec3f
const
getNormal
(
const
SbVec3f* pVec,
const
int
nIdx);
184
185
public
:
187
static
void
getTriIn
(
void
* pData, SoCallbackAction* pAct,
const
SoPrimitiveVertex* pV1,
const
SoPrimitiveVertex* pV2,
188
const
SoPrimitiveVertex* pV3);
189
191
192
private
:
194
SoFieldSensor* _saveSensor;
195
196
197
#ifndef TGSOIV
199
SbMatrix _wTransMat;
201
SbMatrix _wInverseTransposedMat;
203
unsigned
int
_currentDrawStyle;
205
unsigned
int
_currentVertexOrdering;
206
207
209
void
_writeVRML2Header(std::ofstream& outFile);
211
void
_writeVRML2PointSet(std::ofstream& outFile);
213
void
_writeVRML2LineSet(std::ofstream& outFile);
215
void
_writeVRML2FaceSet(std::ofstream& outFile);
216
218
int
_vecToStr(
const
SbVec3f& vec,
char
* buf,
size_t
numEntries = 0,
size_t
currNum = 0);
220
int
_vecToStr(
const
SbColor& col,
char
* buf,
size_t
numEntries = 0,
size_t
currNum = 0);
223
void
_writeIndices(std::ofstream& outFile,
size_t
numIndices,
size_t
posDelim);
224
void
_writeIndices(std::ofstream& outFile, std::vector<size_t>& indexList,
size_t
posDelim);
225
227
SoCallbackAction* _callbackAction;
228
230
static
SoCallbackAction::Response preCB(
void
* userData, SoCallbackAction* action,
const
SoNode* node);
231
233
static
void
pointCB(
void
* userData, SoCallbackAction* action,
const
SoPrimitiveVertex* v);
235
static
void
lineCB(
void
* userData, SoCallbackAction* action,
const
SoPrimitiveVertex* v1,
236
const
SoPrimitiveVertex* v2);
238
static
void
triangleCB(
void
* userData, SoCallbackAction* action,
const
SoPrimitiveVertex* v1,
239
const
SoPrimitiveVertex* v2,
const
SoPrimitiveVertex* v3);
240
242
typedef
std::vector<COLORED_POINT> pointsVec;
244
typedef
std::vector<COLORED_POINT> linesVec;
246
typedef
std::vector<COLORED_POINT> trianglesVec;
247
248
250
std::vector<pointsVec> _points;
252
std::vector<linesVec> _lines;
254
std::vector<trianglesVec> _triangles;
255
258
boost::unordered_map<COLORED_POINT, int, hashColoredPoint> _distinctColoredVertices;
259
#endif
260
};
261
262
#endif
SoUtilsSystem.h
SoSceneWriter::format
SoSFEnum format
format that should be written
Definition
SoSceneWriter.h:131
SoSceneWriter::bSaveNormals
SoSFBool bSaveNormals
save or suppress saving of normals
Definition
SoSceneWriter.h:146
SoSceneWriter::Format
Format
Save formats.
Definition
SoSceneWriter.h:70
SoSceneWriter::INVENTOR_BINARY
@ INVENTOR_BINARY
Definition
SoSceneWriter.h:72
SoSceneWriter::STL_ASCII
@ STL_ASCII
Definition
SoSceneWriter.h:73
SoSceneWriter::STL_BINARY
@ STL_BINARY
Definition
SoSceneWriter.h:74
SoSceneWriter::INVENTOR_ASCII
@ INVENTOR_ASCII
Definition
SoSceneWriter.h:71
SoSceneWriter::VRML_97
@ VRML_97
Definition
SoSceneWriter.h:75
SoSceneWriter::inputChanged
void inputChanged(SoField *) override
Engine dummy implementation.
Definition
SoSceneWriter.h:160
SoSceneWriter::writeSimpleVRML2
void writeSimpleVRML2()
write simple VRML 2 format (oko)
SoSceneWriter::SoPrimitive
SoPrimitive
Definition
SoSceneWriter.h:78
SoSceneWriter::LINE
@ LINE
Definition
SoSceneWriter.h:79
SoSceneWriter::TRIANGLE
@ TRIANGLE
Definition
SoSceneWriter.h:80
SoSceneWriter::getNormal
SbVec3f const getNormal(const SbVec3f *pVec, const int nIdx)
compute the normal of the given triangle
SoSceneWriter::initClass
static void initClass()
initializes this class
SoSceneWriter::saveChangedCB
static void saveChangedCB(void *data, SoSensor *a)
forward sensor CB to saveChanged()
SoSceneWriter::sceneGraph
SoSFNode sceneGraph
Fields.
Definition
SoSceneWriter.h:125
SoSceneWriter::~SoSceneWriter
~SoSceneWriter() override
SoSceneWriter::formatFileExtension
void formatFileExtension()
set filename field's extension according to format
SoSceneWriter::filename
SoSFString filename
absolute filename of the output file
Definition
SoSceneWriter.h:129
SoSceneWriter::bNormalPerVertex
SoSFBool bNormalPerVertex
save normal per vertex (or only one per facet)
Definition
SoSceneWriter.h:143
SoSceneWriter::getTriIn
static void getTriIn(void *pData, SoCallbackAction *pAct, const SoPrimitiveVertex *pV1, const SoPrimitiveVertex *pV2, const SoPrimitiveVertex *pV3)
callback function for extracting triangulation from the scene
SoSceneWriter::writeVecToStlFile
void writeVecToStlFile(SoMFVec3f *pMVec3f)
STL File format (Stefan Zidowitz).
SoSceneWriter::bUseGlobalColor
SoSFBool bUseGlobalColor
save only one color per object
Definition
SoSceneWriter.h:140
SoSceneWriter::SoSceneWriter
SoSceneWriter()
SoSceneWriter::saveChanged
void saveChanged()
save the scene
SoSceneWriter::bColorPerVertex
SoSFBool bColorPerVertex
Format Options for self-coded VRML 2.0.
Definition
SoSceneWriter.h:137
SoSceneWriter::evaluate
void evaluate() override
Engine dummy implementation.
Definition
SoSceneWriter.h:162
SoSceneWriter::save
SoSFTrigger save
save the scene
Definition
SoSceneWriter.h:127
SoSceneWriter::COLORED_POINT
struct holds point information when VRML_2 output is applied on SGI Inventor scenes
Definition
SoSceneWriter.h:88
SoSceneWriter::COLORED_POINT::transparency
float transparency
Definition
SoSceneWriter.h:93
SoSceneWriter::COLORED_POINT::shininess
float shininess
Definition
SoSceneWriter.h:92
SoSceneWriter::COLORED_POINT::coord
SbVec3f coord
Definition
SoSceneWriter.h:89
SoSceneWriter::COLORED_POINT::normal
SbVec3f normal
Definition
SoSceneWriter.h:90
SoSceneWriter::COLORED_POINT::operator==
bool operator==(const COLORED_POINT &cp) const
Definition
SoSceneWriter.h:94
SoSceneWriter::COLORED_POINT::color
SbColor color
Definition
SoSceneWriter.h:91
SoSceneWriter::hashColoredPoint
For computing a hash value for a colored point.
Definition
SoSceneWriter.h:104
SoSceneWriter::hashColoredPoint::operator()
size_t operator()(const COLORED_POINT &cp) const
Definition
SoSceneWriter.h:105
MeVisLab
Standard
Sources
Inventor
SoUtils
SoSceneWriter.h
Generated by
1.18.0