Ocean
Loading...
Searching...
No Matches
scenedescription/sdx/x3d/Utilities.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_SCENEDESCRIPTION_SDX_X3D_UTILITIES_H
9#define META_OCEAN_SCENEDESCRIPTION_SDX_X3D_UTILITIES_H
10
12
15#include "ocean/math/Vector3.h"
16
18
19namespace Ocean
20{
21
22namespace SceneDescription
23{
24
25namespace SDX
26{
27
28namespace X3D
29{
30
31/**
32 * This class implements utility functions.
33 * @ingroup scenedescriptionsdxx3d
34 */
35class OCEAN_SCENEDESCRIPTION_SDX_X3D_EXPORT Utilities
36{
37 public:
38
39 /**
40 * Writes the header of a X3D file.
41 * @param stream The output stream to which the header will be written, must be valid
42 * @return True, if succeeded
43 */
44 static bool writeHeader(std::ostream& stream);
45
46 /**
47 * Writes a shape with a PointSet geometry to an output stream.
48 * @param stream The output stream to which the shape will be written, must be valid
49 * @param vertices The 3D vertices for the PointSet, at least one
50 * @param emissiveColor Optional emissive color of the point's material, invalid otherwise
51 * @param colors Optional per-vertex colors, one for each vertex or empty
52 * @param indentation Optional indentation
53 * @param vertexPrecision The precision of the vertices, with range [0, infinity)
54 * @param name Optional name of the shape
55 * @return True, if succeeded
56 */
57 static bool writePointSet(std::ostream& stream, const Vectors3& vertices, const RGBAColor& emissiveColor = RGBAColor(false), const RGBAColors& colors = RGBAColors(), const std::string& indentation = std::string(), const unsigned int vertexPrecision = 6u, const std::string& name = std::string());
58
59 /**
60 * Writes a shape with an IndexdFaceSet geometry to an output stream.
61 * @param stream The output stream to which the shape will be written, must be valid
62 * @param vertices The 3D vertices for the IndexdFaceSet, at least three
63 * @param triangleFaces The triangle faces to write, at least one
64 * @param color Optional per-mesh color, invalid to not define a mesh color
65 * @param perVertexNormals Optional per-vertex normals, one for each vertex or empty
66 * @param perVertexColors Optional per-vertex colors, one for each vertex or empty
67 * @param perVertexTextureCoordinates Optional per-vertex texture coordinates, one for each vertex or empty
68 * @param textureUrl The URL of the image texture, empty otherwise
69 * @param indentation Optional indentation
70 * @param vertexPrecision The precision of the vertices, with range [0, infinity)
71 * @param name Optional name of the shape
72 * @return True, if succeeded
73 */
74 static bool writeIndexedFaceSet(std::ostream& stream, const Vectors3& vertices, const Rendering::TriangleFaces& triangleFaces, const RGBAColor& color = RGBAColor(false), const Vectors3& perVertexNormals = Vectors3(), const RGBAColors& perVertexColors = RGBAColors(), const Vectors2& perVertexTextureCoordinates = Vectors2(), const std::string& textureUrl = std::string(), const std::string& indentation = std::string(), const unsigned int vertexPrecision = 6u, const std::string& name = std::string());
75
76 /**
77 * Writes a coordinate system to an output stream.
78 * This function actually writes a Group node containing several shapes likes Cylinders and Cones.<br>
79 * The length of each axis is one unit.
80 * @param stream The output stream to which the coordinate system will be written, must be valid
81 * @param world_T_coordinateSystem The transformation between coordinate system and world, must be valid
82 * @param xAxisColor The color of the x-axis
83 * @param yAxisColor The color of the y-axis
84 * @param zAxisColor The color of the z-axis
85 * @param indentation Optional indentation
86 * @param name The optional name of the Group node
87 * @return True, if succeeded
88 */
89 static bool writeCoordinateSystem(std::ostream& stream, const HomogenousMatrix4& world_T_coordinateSystem, const RGBAColor& xAxisColor = RGBAColor(1.0f, 0.0f, 0.0f), const RGBAColor& yAxisColor = RGBAColor(0.0f, 1.0f, 0.0f), const RGBAColor& zAxisColor = RGBAColor(0.0f, 0.0f, 1.0f), const std::string& indentation = std::string(), const std::string& name = std::string());
90
91 /**
92 * Writes coordinate systems to an output stream.
93 * @param stream The output stream to which the coordinate system will be written, must be valid
94 * @param world_T_coordinateSystems The transformations between coordinate systems and world, at least one
95 * @param xAxisColor The color of the x-axis
96 * @param yAxisColor The color of the y-axis
97 * @param zAxisColor The color of the z-axis
98 * @param indentation Optional indentation
99 * @param name A unique name which can be used to define & reference coordinate systems, must be valid
100 * @return True, if succeeded
101 */
102 static bool writeCoordinateSystems(std::ostream& stream, const HomogenousMatrices4& world_T_coordinateSystems, const RGBAColor& xAxisColor = RGBAColor(1.0f, 0.0f, 0.0f), const RGBAColor& yAxisColor = RGBAColor(0.0f, 1.0f, 0.0f), const RGBAColor& zAxisColor = RGBAColor(0.0f, 0.0f, 1.0f), const std::string& indentation = std::string(), const std::string& name = "OCEAN_COORDINATE_SYSTEM");
103
104 /**
105 * Writes a Cylinder to an output stream.
106 * This function actually writes a Transform node containing the Cylinder.
107 * @param stream The output stream to which the cylinder will be written, must be valid
108 * @param world_T_cylinder The transformation between cylinder and world, must be valid
109 * @param height The height of the cylinder, with range [0, infinity)
110 * @param radius The radius of the cylinder, with range [0, infinity)
111 * @param color The color of the cylinder
112 * @param indentation Optional indentation
113 * @param name The optional name of the Transform node
114 * @return True, if succeeded
115 */
116 static bool writeCylinder(std::ostream& stream, const HomogenousMatrix4& world_T_cylinder, const Scalar height, const Scalar radius, const RGBAColor& color, const std::string& indentation = std::string(), const std::string& name = std::string());
117
118 /**
119 * Writes a Cone to an output stream.
120 * This function actually writes a Transform node containing the Cone.
121 * @param stream The output stream to which the cone will be written, must be valid
122 * @param world_T_cone The transformation between cone and world, must be valid
123 * @param height The height of the cone, with range [0, infinity)
124 * @param bottomRadius The bottom radius of the cone, with range [0, infinity)
125 * @param color The color of the cone
126 * @param indentation Optional indentation
127 * @param name The optional name of the Transform node
128 * @return True, if succeeded
129 */
130 static bool writeCone(std::ostream& stream, const HomogenousMatrix4& world_T_cone, const Scalar height, const Scalar bottomRadius, const RGBAColor& color, const std::string& indentation = std::string(), const std::string& name = std::string());
131
132 /**
133 * Writes a Text to an output stream.
134 * This function actually writes a Transform node containing the Text.
135 * @param stream The output stream to which the text will be written, must be valid
136 * @param world_T_text The transformation between text and world, must be valid
137 * @param text The text string, must be valid
138 * @param size The text size, with range (0, infinity)
139 * @param indentation Optional indentation
140 * @param name The optional name of the Transform node
141 * @return True, if succeeded
142 */
143 static bool writeText(std::ostream& stream, const HomogenousMatrix4& world_T_text, const std::string& text, const Scalar size, const std::string& indentation = std::string(), const std::string& name = std::string());
144
145 protected:
146
147 /**
148 * Writes the start of a Transform node to an output stream.
149 * Afterwards the 'children' field as to be written followed by a closing bracket for the Transform node.
150 * @param stream The output stream to which the node will be written, must be valid
151 * @param world_T_transform The transformation between the Transform node and the world, must be valid
152 * @param indentation Optional indentation
153 * @param name The optional name of the Transform node
154 * @return True, if succeeded
155 */
156 static bool writeTransformNodeStart(std::ostream& stream, const HomogenousMatrix4& world_T_transform, const std::string& indentation = std::string(), const std::string& name = std::string());
157};
158
159}
160
161}
162
163}
164
165}
166
167#endif // META_OCEAN_SCENEDESCRIPTION_SDX_X3D_UTILITIES_H
This class implements a color defined by red, green, blue and alpha parameters.
Definition RGBAColor.h:41
This class implements utility functions.
Definition scenedescription/sdx/x3d/Utilities.h:36
static bool writeCoordinateSystems(std::ostream &stream, const HomogenousMatrices4 &world_T_coordinateSystems, const RGBAColor &xAxisColor=RGBAColor(1.0f, 0.0f, 0.0f), const RGBAColor &yAxisColor=RGBAColor(0.0f, 1.0f, 0.0f), const RGBAColor &zAxisColor=RGBAColor(0.0f, 0.0f, 1.0f), const std::string &indentation=std::string(), const std::string &name="OCEAN_COORDINATE_SYSTEM")
Writes coordinate systems to an output stream.
static bool writeCone(std::ostream &stream, const HomogenousMatrix4 &world_T_cone, const Scalar height, const Scalar bottomRadius, const RGBAColor &color, const std::string &indentation=std::string(), const std::string &name=std::string())
Writes a Cone to an output stream.
static bool writePointSet(std::ostream &stream, const Vectors3 &vertices, const RGBAColor &emissiveColor=RGBAColor(false), const RGBAColors &colors=RGBAColors(), const std::string &indentation=std::string(), const unsigned int vertexPrecision=6u, const std::string &name=std::string())
Writes a shape with a PointSet geometry to an output stream.
static bool writeCoordinateSystem(std::ostream &stream, const HomogenousMatrix4 &world_T_coordinateSystem, const RGBAColor &xAxisColor=RGBAColor(1.0f, 0.0f, 0.0f), const RGBAColor &yAxisColor=RGBAColor(0.0f, 1.0f, 0.0f), const RGBAColor &zAxisColor=RGBAColor(0.0f, 0.0f, 1.0f), const std::string &indentation=std::string(), const std::string &name=std::string())
Writes a coordinate system to an output stream.
static bool writeCylinder(std::ostream &stream, const HomogenousMatrix4 &world_T_cylinder, const Scalar height, const Scalar radius, const RGBAColor &color, const std::string &indentation=std::string(), const std::string &name=std::string())
Writes a Cylinder to an output stream.
static bool writeTransformNodeStart(std::ostream &stream, const HomogenousMatrix4 &world_T_transform, const std::string &indentation=std::string(), const std::string &name=std::string())
Writes the start of a Transform node to an output stream.
static bool writeText(std::ostream &stream, const HomogenousMatrix4 &world_T_text, const std::string &text, const Scalar size, const std::string &indentation=std::string(), const std::string &name=std::string())
Writes a Text to an output stream.
static bool writeIndexedFaceSet(std::ostream &stream, const Vectors3 &vertices, const Rendering::TriangleFaces &triangleFaces, const RGBAColor &color=RGBAColor(false), const Vectors3 &perVertexNormals=Vectors3(), const RGBAColors &perVertexColors=RGBAColors(), const Vectors2 &perVertexTextureCoordinates=Vectors2(), const std::string &textureUrl=std::string(), const std::string &indentation=std::string(), const unsigned int vertexPrecision=6u, const std::string &name=std::string())
Writes a shape with an IndexdFaceSet geometry to an output stream.
static bool writeHeader(std::ostream &stream)
Writes the header of a X3D file.
std::vector< RGBAColor > RGBAColors
Definition of a vector holding rgba color objects.
Definition RGBAColor.h:27
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition HomogenousMatrix4.h:73
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
std::vector< TriangleFace > TriangleFaces
Definition of a vector holding triangle faces.
Definition TriangleFace.h:30
The namespace covering the entire Ocean framework.
Definition Accessor.h:15